我试图编写一个sql查询,以获取相同id的最新日期。因此我编写:
select id from table where id = 10 having table.date = MAX(table.date)
但它仍然返回我和刚才一样的结果
select id from table where id = 10
我不知道为什么,我们不能用这种方式?谢谢!
vdgimpew1#
你不能使用 Having 没有分组。试试这个:
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)
1条答案
按热度按时间vdgimpew1#
你不能使用
Having
没有分组。试试这个: