select distinct * from tablename a
where cre_date=(select max(cre_date) from tablename where unitid=a.unitid)
order by cre_date desc
where cre_date=(select max(cre_date) from tablename where unitid=a.unitid)
order by cre_date desc
如表是这样:
unitid cre_date
aa 2000-03-22
aa 2000-03-12
bb 2000-03-20
bb 2000-03-18
cc 2000-03-23
cc 2000-03-22
结果是这样:
unitid cre_date
cc 2000-03-23
cc 2000-03-22
aa 2000-03-22
aa 2000-03-12
bb 2000-03-20
bb 2000-03-18
怎么写呢?
aa 2000-03-22
aa 2000-03-22
aa 2000-03-12
bb 2000-03-20
bb 2000-03-18
cc 2000-03-23
cc 2000-03-22显示:
unitid cre_date
cc 2000-03-23
cc 2000-03-22
aa 2000-03-22
aa 2000-03-22
aa 2000-03-12
bb 2000-03-20
bb 2000-03-18
就可以列出全部了。