gpt4 book ai didi

sql - 是否允许在 have 子句中使用 over()?

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

我需要使用 over(partition by ...)having条款。

这是我的代码,它给出了错误:

group function is nested too deeply


select resort, discipline, gender, count(1)
from races
group by resort, discipline, gender
having sum(count(1)) over (partition by resort, discipline) > 10;

有没有办法使用 over()having条款还是有其他选择?

最佳答案

你总是可以嵌套它:

WITH cte AS (
select resort, discipline, gender, count(1) AS cnt
from races
group by resort, discipline, gender
), cte2 AS (
SELECT *, sum(cnt) over (partition by resort, discipline) AS s
FROM cte
)
SELECT *
FROM cte2
WHERE s > 10;

关于sql - 是否允许在 have 子句中使用 over()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48462211/

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