目前为止,此查询显示max(hella)

SELECT max(hella)
FROM (
SELECT G.firstname, G.lastname, count(*) as hella
FROM guest G, Timeslot TS, shows H
where G.timeslotnum = TS.timeslotnum
AND TS.shownumber = H.shownumber
AND H.showname = 'Fitness'
Group by g.firstname, G.lastname
ORDER by hella
)
As blabla

我想显示max(hella)entry的名字和姓氏

最佳答案

这很像@maniek或@zfus已经发布的内容:返回一行,如果有关系,则任意选择。
但是有了正确的连接语法和简短的语法:

SELECT g.firstname, g.lastname, count(*) AS hella
FROM   guest    g
JOIN   timeslot t USING (timeslotnum)
JOIN   shows    s USING (shownumber)
WHERE  s.showname = 'Fitness'
GROUP  BY 1,2
ORDER  BY 3 DESC
LIMIT  1;

SQL Fiddle(重复使用@sgeddes'小提琴)。

07-24 19:12