WITH A as(SELECt max(a.ordernum) as ordernum,a.orderyear
FROM
(SELECt count(*) as ordernum,EXTRACT (year from orderdate) as orderyear,customerid
FROM orders
GROUP BY orderyear,customerid) a
GROUP BY a.orderyear)
SELECt COUNT(*) as ordernum,EXTRACT (year from orderdate) orderyear,customerid
FROM orders o
GROUP BY orderyear,customerid
HAVINg COUNT(*)=(select ordernum FROM A )
ORDER BY orderyear DESC
跑出来ERROR: more than one row returned by a subquery used as an expression
我感觉是having 条件句有问题
但是不知道怎么改
谢谢!
sql 求和后分组 再取每组最大值
答案:2 悬赏:0 手机版
解决时间 2021-12-25 08:24
- 提问者网友:原来太熟悉了会陌生
- 2021-12-25 03:30
最佳答案
- 五星知识达人网友:罪歌
- 2021-12-25 04:50
不知道你这怎么样才算第一个先用一个rownum列出每一个值的序号,再在外面去取每组的序号为1和最大的那个,并关联求出值来吧
全部回答
- 1楼网友:傲气稳了全场
- 2021-12-25 06:24
select max(时刻值)
,min(时刻值)
from (select 日期 时刻 名称 类型 等级 sum(时刻值)
from to
group by 日期 时刻 名称 类型 等级)
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯