日期 编号 仓库 数量
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)

 

相关文章:

  • 2022-02-01
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2021-10-16
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2022-02-11
  • 2022-12-23
  • 2022-01-22
  • 2021-10-01
相关资源
相似解决方案