我试图写一个sql查询来获取相同id的最新日期。所以我写:
select id
from table
where id = 10
having table.date = MAX(table.date)
但是它仍然返回和
相同的结果select id
from table
where id = 10
我不知道为什么,我们不能用这种方式。谢谢!
没有分组就不能使用Having
试试这个:
select id
from table AS A
where id = 10 AND table.date = (select MAX(table.date)
from table as B
where a.id = b.id)