我有2张桌子' Climber' &安培; ' YearResults'
我希望的结果是显示总和(moneyWon),按国籍排序'。
我已完成查询以加入两个表格&总结钱但是我应该如何加入这两个查询,它将显示每个国家赢得的总金额。
select sum(moneyWon) from yearResults
(SELECT C.NATIONALITY, Y.MONEYWON, Y.YEAR
FROM CLIMBER c JOIN YEARRESULTS y
ON C.CLIMBERID = Y.CLIMBERID)
答案 0 :(得分:1)
您需要加入表格并按国籍分组才能获得所需的结果:
SELECT
Climber.Nationality,
SUM(yearResults.MoneyWon) as MoneyWon
FROM Climber
INNER JOIN yearResult ON Climber.ClimberID = yearResults.ClimberID
GROUP BY Climber.Nationality
ORDER BY Climber.Nationality