SQL Finding Group,出勤率低于平均水平

时间:2017-05-03 21:50:57

标签: sql oracle

如何让与会者人数低于平均水平?这是我的Oracle查询

SELECT e.event_id EventID,c.concert_name ConcertName, c.concert_date, 
AVG(e.attendance) Attendance

FROM event e INNER JOIN concert c ON c.concert_id = e.concert_id 
WHERE  Attendance - AVG(e.Attendance)
GROUP BY c.concert_id ASC;

2 个答案:

答案 0 :(得分:0)

您可以尝试这种方式:

SELECT e.event_id EventID,c.concert_name ConcertName, c.concert_date, 
AVG(e.attendance) Attendance
FROM event e INNER JOIN concert c ON c.concert_id = e.concert_id 
WHERE  e.attendance < (select AVG(ev.attendance) from event ev)
GROUP BY c.concert_id ASC;

答案 1 :(得分:0)

使用error_log('Getting Result Error: (' . $this->sql->errno . ') ' . $this->sql->error, 0); header('Content-Type: application/json'); $arr = array("status"=>'error'); echo json_encode($arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); 分析函数(并且没有相关的子查询):

AVG(..) OVER ()