我试图运行的许多不同报告都出现了错误。有谁知道为什么/我做错了什么?
SELECT Event.Event_ID, Event.Event_Type, Avg (Rank.Time_InSeconds), Meeting.Meeting_ID
FROM Event, Rank, Meeting
WHERE Event.Event_ID = 7 AND Event.Event_ID = Rank.Event_ID AND Rank.Meeting_ID = Meeting.Meeting_ID
答案 0 :(得分:0)
AVG (Rank.Time_InSeconds)
之间有空白...尝试
SELECT Event.Event_ID, Event.Event_Type, Avg(Rank.Time_InSeconds), Meeting.Meeting_ID
FROM Event, Rank, Meeting
WHERE Event.Event_ID = 7 AND Event.Event_ID = Rank.Event_ID AND Rank.Meeting_ID = Meeting.Meeting_ID
答案 1 :(得分:0)
由于您使用的是avg
聚合,因此您还需要使用group by
子句:
SELECT e.Event_ID, e.Event_Type, m.Meeting_ID,
Avg(r.Time_InSeconds)
FROM Event e
JOIN Rank r ON e.Event_ID = r.Event_ID
JOIN Meeting m ON r.Meeting_ID = m.Meeting_ID
WHERE e.Event_ID = 7
GROUP BY e.Event_ID, e.Event_Type, m.Meeting_ID
另请注意join
语法的用法。一般来说,我不会在from
声明中推荐使用逗号。
答案 2 :(得分:0)
GROUP BY子句通常与五个内置或"聚合"一起使用。功能。这些函数对整个表或行的集合或组执行特殊操作,而不是对每行执行特殊操作,然后为每个组返回一行值。