SQL 查询相同记录下日期最大的一条数据

日期 编号 仓库 数量
2012-05-31 C001 A店 136
2012-05-29 C001 A店 139
2012-05-29 C001 B店 5
2012-05-30 C001 B店 6

我只显示最大日期的记录,这个SQL怎么写呀?

日期 编号 仓库 数量
2012-05-31 C001 A店 136
2012-05-30 C001 B店  6

SQL code:

方法一:

select * from tb t where not exists(select 1 from tb where `编号`=t.`编号` and `仓库`=t.`仓库` and `日期`>t.`日期`)

 方法二:

SELECT * FROM tb T, (SELECT `编号`,MAX(`日期`) rq FROM tb GROUP BY `编号`) t2 where t.`编号`=t2.`编号` and t.`日期`>=t2.rq

 方法三:

select * from tb a where a.`日期` in (select max(b.`日期`) from table b where b.id=a.id)
原文地址:https://www.cnblogs.com/47Gamer/p/13652567.html