gpt4 book ai didi

mysql - SQL 查询 : HAVING date = MAX(date) doesn't work

转载 作者:行者123 更新时间:2023-11-29 05:16:11 28 4
gpt4 key购买 nike

我尝试编写一个 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)

关于mysql - SQL 查询 : HAVING date = MAX(date) doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32435690/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com