id opt_date bar_code
09FBBAC3AD5E2F4A81550DF968B449BA 2012-04-22 12:55:31 0000777777
4D332D57B7374C439EB66B7DCC1D7FCC 2012-04-23 12:56:51 0000777777
B8CFE31D9512CB4CA0C8E24BC66FA3AD 2012-04-24 12:55:41 0000777777
FF00F2D8A253F243A4DBF3725950348E 2012-04-25 12:56:01 0000777777经过查询,取出opt_date日期值最大的那条完整记录id opt_date bar_code
FF00F2D8A253F243A4DBF3725950348E 2012-04-25 12:56:01 0000777777
09FBBAC3AD5E2F4A81550DF968B449BA 2012-04-22 12:55:31 0000777777
4D332D57B7374C439EB66B7DCC1D7FCC 2012-04-23 12:56:51 0000777777
B8CFE31D9512CB4CA0C8E24BC66FA3AD 2012-04-24 12:55:41 0000777777
FF00F2D8A253F243A4DBF3725950348E 2012-04-25 12:56:01 0000777777经过查询,取出opt_date日期值最大的那条完整记录id opt_date bar_code
FF00F2D8A253F243A4DBF3725950348E 2012-04-25 12:56:01 0000777777
select * from tb b where not exists (select 1 from tb a where a.id=b.id and a.time>b.time)
SELECT TOP 1 * FROM tb ORDER BY opt_date DESC
select top 1 * from table order by opt_date desc
select *from your_table order by opt_date) s where rownum=1
sql server中
SELECT TOP 1 * FROM tb ORDER BY opt_date DESC
三楼正解
--最大值唯一
SELECT TOP 1 * FROM tb ORDER BY opt_date DESC
--最大值不唯一
select * from tb b where not exists (select 1 from tb a where a.id=b.id and a.time>b.time)