gpt4 book ai didi

sql - 查找拥有超过 1 个订单的学校

转载 作者:行者123 更新时间:2023-12-01 13:48:53 27 4
gpt4 key购买 nike

我想找出同一所学校有超过 1 个订单的所有学校。在下面的例子中,我想找到 2 号学校

| school_ucn    | order_no  |
-----------------------------
| 1 | 101 |
| 1 | 101 |
| 2 | 102 |
| 2 | 102 |
| 2 | 103 |
| 2 | 103 |

查询应该是这样的:

select 
school_ucn, count(otc_order_number)
from storiacloud.schl_storia_revenue_fact
group by
otc_order_number, school_ucn
having count(otc_order_number) > 1

最佳答案

从你的groupby中取出订单号

select 
school_ucn,count(DISTINCT otc_order_number)
from
storiacloud.schl_storia_revenue_fact
group by
school_ucn
having
count(distinct otc_order_number)>1

关于sql - 查找拥有超过 1 个订单的学校,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33490174/

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