我有15
个级别,每个级别都由2 rounds
组成。现在,我要找到max score
用户在round1 and round2
中获得的总成绩并计算出来。同样的方法,直到他玩了多少级别。最后,通过计算所有级别的分数得出总结果。
任何人都可以帮我找到使用MySQL的总分..!
我尝试了这段代码:
SELECT *, (classifica_score + MAX2) AS TOTAL FROM(
SELECT IFNULL( MAX(XX1.classifica_score), 0) AS classifica_score, XX1.classifica_level, XX1.classifica_round, XX1.fb_id,
(SELECT IFNULL( MAX(TC1.classifica_score), 0) FROM tab_classifica AS TC1 WHERE TC1.classifica_round = 2 AND TC1.fb_id = XX1.fb_id) AS MAX2
FROM tab_classifica AS XX1 WHERE XX1.classifica_round=1
GROUP BY XX1.classifica_level, XX1.classifica_round, XX1.fb_id
UNION ALL
SELECT IFNULL( MAX(XX2.classifica_score),0) AS classifica_score, XX2.classifica_level, XX2.classifica_round, XX2.fb_id,
(SELECT IFNULL( MAX(TC2.classifica_score),0) FROM tab_classifica AS TC2 WHERE TC2.classifica_round = 1 AND TC2.fb_id = XX2.fb_id ) AS MAX1
FROM tab_classifica AS XX2 WHERE XX2.classifica_round=2
GROUP BY XX2.classifica_level, XX2.classifica_round, XX2.fb_id
) AS TAB
我的Db结构如下
classifica_id----- fb_id---classifica_nome----classifica_level----classifica_round---classifica_score