我有这样的数据:
CONCERT_ID EVENT_ID ATTENDANCE AVG_ATTENDANCE_EACH_CONCERT
---------- ---------- ---------- ---------------------------
1 1 1 1,5
1 2 2 1,5
3 5 2 2
3 6 2 2
5 11 4 2
5 12 1 2
5 13 1 2
从查询中得知:
select concert_id, event_id, count(customer_id) attendance,
avg(count(*)) over (partition by concert_id) avg_attendance_each_concert
from booking
group by concert_id, event_id
order by event_id;
如何对该查询进行限制。我想做的是
如果出勤率低于平均出勤率显示结果
我已经尝试过将avg(count(*))替换为(由concert_id划分)具有having子句,但是给了我一个错误组功能太深
只需套用一个嵌套即可轻松获得所需的结果:
select * from
(
select concert_id, event_id, count(customer_id) attendance,
avg(count(*)) over (partition by concert_id) avg_attendance_each_concert
from booking
group by concert_id, event_id
order by event_id
)
where attendance < avg_attendance_each_concert
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句