sql查询:让date=max(date)不起作用

twh00eeo  于 2021-06-26  发布在  Impala
关注(0)|答案(1)|浏览(421)

我试图编写一个sql查询,以获取相同id的最新日期。因此我编写:

select id 
from table 
where id = 10
having table.date = MAX(table.date)

但它仍然返回我和刚才一样的结果

select id 
from table 
where id = 10

我不知道为什么,我们不能用这种方式?
谢谢!

vdgimpew

vdgimpew1#

你不能使用 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)

相关问题