SELECT Top_Country, SUM(Top_Country_Earnings) AS TotalEarnings FROM game GROUPBY Top_Country ORDERBY TotalEarnings DESC LIMIT 10;
c.哪个国家人均获得奖金最多
1 2 3 4 5 6
SELECT Top_Country, SUM(Top_Country_Earnings)/SUM(PlayerNo) as Avg_Earnings_Per_Player FROM game GROUPBY Top_Country ORDERBY Avg_Earnings_Per_Player DESC LIMIT 10;
d.计算策略类(Strategy)游戏的趋势,每年增长率
这里计算的是TotalMoney的增长率,其他大同小异
1 2 3 4 5 6 7 8 9 10 11 12 13
#创建一个新表 CREATETABLE game_strategy_yearly AS SELECT ReleaseYear, SUM(TotalMoney) AS TotalMoneySum FROM game WHERE Genre ='Strategy' GROUPBY ReleaseYear;
SELECT t2.ReleaseYear,(t1.TotalMoneySum-t2.TotalMoneySum)/t2.TotalMoneySum FROM game_strategy_yearly t1,game_strategy_yearly t2 WHERE t1.ReleaseYear = t2.ReleaseYear-1;
TEMPORARY CREATETABLE Year_2020 AS SELECT Genre,sum (TotalMoney) AS TotalMoneySum2020 FROM game WHERE ReleaseYear ='2020' GROUPBY Genre;
CREATETABLE Year_2019 AS SELECT Genre,sum (TotalMoney) AS TotalMoneySum2019 FROM game WHERE ReleaseYear ='2019' GROUPBY Genre;
SELECT t1.Genre,(t1.TotalMoneySum2020-t2.TotalMoneySum2019)/t2.TotalMoneySum2019 AS pre FROM Year_2020 t1,Year_2019 t2 WHERE t1.Genre = t2.Genre ORDERBY pre DESC;