我想只显示前2个建筑物及其相应的会话平均价格。 这就是我现在所拥有的
SELECT BUILDINGLANE,SUM(SESSIONPRICE/COUNT(BUILDINGNO))
FROM BUILDING NATURAL JOIN CONFERENCESESSION
GROUP BY BUILDINGLANE
WHERE SUM(SESSIONPRICE/COUNT(BUILDINGNO));
但我得到第3行的错误“SQL命令没有正确结束”,但是如果我用分号结束第3行,我得到第1行的“不是单组组函数”的新错误。我不确定我哪里出错了,我试过这个搜索但我没有运气解决这个问题。
感谢任何帮助!
答案 0 :(得分:0)
您应该使用Order by
代替Where
子句
SELECT *
FROM (SELECT BUILDINGLANE,
Sum(intrPrice) AS avgPrice
FROM (SELECT BUILDINGLANE,
SESSIONPRICE / Count(BUILDINGNO) AS intrPrice
FROM BUILDING
NATURAL JOIN CONFERENCESESSION
GROUP BY BUILDINGLANE,
SESSIONPRICE) a
GROUP BY BUILDINGLANE
ORDER BY avgPrice DESC) b
WHERE ROWNUM <= 2
答案 1 :(得分:0)
尝试:
select * from(
SELECT BUILDINGLANE,SUM(SESSIONPRICE)/COUNT(BUILDINGNO)
FROM BUILDING NATURAL JOIN CONFERENCESESSION
GROUP BY BUILDINGLANE, BUILDINGNO
Order by (SUM(SESSIONPRICE)/COUNT(BUILDINGNO)) desc
)
where rownum <= 2