我有3个表,我想从中创建一个查询:
参赛者:
的 CompetitionID
BandID
BandResult
...
...
ResultPoints:
的 bandResult
点
频段:
的 BandID
BandName
斜体=外键,粗体=主键
这就是我目前所拥有的:
SELECT E.bandID, SUM(RP.points)
FROM entrants E, resultPoints RP
WHERE E.bandResult = RP.bandResult
GROUP BY E.bandID
ORDER BY SUM(RP.points) DESC;
我想也包括bandName但是当我通过停止工作包括这个组时:
SELECT E.bandID, B.bandName, SUM(RP.points)
FROM entrants E, resultPoints RP, band B
WHERE E.bandResult = RP.bandResult
AND B.bandID = E.bandID
GROUP BY E.bandID
ORDER BY SUM(RP.points) DESC;
关于如何使这项工作的任何想法?
答案 0 :(得分:1)
尝试将bandName添加到group by子句中。
答案 1 :(得分:1)
试试这个:
SELECT E.bandID, B.bandName, SUM(RP.points)
FROM entrants E, resultPoints RP, band B
WHERE E.bandResult = RP.bandResult
AND B.bandID = E.bandID
GROUP BY E.bandID, B.bandname
ORDER BY SUM(RP.points) DESC;