gpt4 book ai didi

sql服务器: How to use an aggregate function like MAX in a WHERE clause

转载 作者:行者123 更新时间:2023-12-01 20:19:25 25 4
gpt4 key购买 nike

我想获得该记录的最大值。请帮助我:

SELECT rest.field1 
FROM mastertable AS m
INNER JOIN (
SELECT t1.field1 field1,
t2.field2
FROM table1 AS T1
INNER JOIN table2 AS t2 ON t2.field = t1.field
WHERE t1.field3=MAX(t1.field3)
-- ^^^^^^^^^^^^^^ Help me here.
) AS rest ON rest.field1 = m.field

最佳答案

正如您所注意到的,WHERE 子句不允许您在其中使用聚合。这就是 HAVING 子句的用途。

HAVING t1.field3=MAX(t1.field3)

关于sql服务器: How to use an aggregate function like MAX in a WHERE clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1475589/

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