我是MySQL的新手,想通过在我玩的游戏中制作排行榜来学习它。
我有一个功能,我想要获得所有季节的准确总平均值。
我已成功将解析后的数据导入数据库。
我每个赛季都有这样一张桌子
season1
------------------------
| name | score | games |
------------------------
| joe | 254 | 25 |
| bob | 200 | 32 |
| jim | 365 | 65 |
------------------------
我需要运行这样的函数
((S1.games*S1.score)+(S2.games*S2.score)+(S3.games*S3.score)+(S4.games*S4.score))
/
((S1.games)+(S2.games)+(S3.games)+(S4.games))
并根据飞行员姓名
计算总数对于我的生活,我无法弄清楚如何在表之间进行复杂的功能。
感谢您的帮助。
答案 0 :(得分:0)
你应该可以做一些像
这样简单的事情SELECT S1.name, ((S1.games*S1.score)+(S2.games*S2.score)+(S3.games*S3.score)+(S4.games*S4.score)) / ((S1.games)+(S2.games)+(S3.games)+(S4.games)) as TOTAL
FROM Season1 as S1, Season2 as S2, Season3 as S3, Season4 as S4 group by S1.name;
虽然效率不高。
答案 1 :(得分:0)
ListView