SQL - 如何将2个查询合并在一起以获得我想要的结果

时间:2015-11-29 10:38:20

标签: sql oracle join

我有2张桌子' Climber' &安培; ' YearResults' enter image description here enter image description here

我希望的结果是显示总和(moneyWon),按国籍排序'。

我已完成查询以加入两个表格&总结钱但是我应该如何加入这两个查询,它将显示每个国家赢得的总金额。

select sum(moneyWon) from yearResults

(SELECT C.NATIONALITY, Y.MONEYWON, Y.YEAR
FROM CLIMBER c JOIN YEARRESULTS y
ON C.CLIMBERID = Y.CLIMBERID)

1 个答案:

答案 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