mysql rank function like implementation

5 views
Skip to first unread message

Lei

unread,
Apr 23, 2013, 3:45:49 PM4/23/13
to programmin...@googlegroups.com
in a mysql database, how to achieve rank() function like implementation?
for example there is a table 
name  time                 description
A        aa/bb/cccc            desc1
A        aa/bb/nnnn            desc2
c         aa/bb/mmm          desc3
d        aa/bb/ llll                desc4
c         aa/bb/qqq             desc5


how to get unique data of A, c, d based on their most updated time?
A          aa/bb/nnnn          desc1
c          aa/bb/qqq            desc4
d          aa/bb/llll              desc3

Lei

unread,
Apr 23, 2013, 3:46:03 PM4/23/13
to programmin...@googlegroups.com
SELECT t1.mrn, t1.patient, t1.s_time
FROM visit_history AS t1
JOIN (

SELECT t2.mrn, MAX( s_time ) AS sd
FROM visit_history AS t2
GROUP BY t2.mrn
)t ON t1.mrn = t.mrn
AND t1.s_time = t.sd
Reply all
Reply to author
Forward
0 new messages