我有一张测验答案的表格。以下查询总结了给定游戏中每个参与者的总数。
SELECT @prev := @curr,
@curr := totalscore,
@rank := IF(@prev = @curr, @rank, @rank + @i) AS rank,
IF(@prev <> totalscore, @i:=1, @i:=@i+1) AS counter,
user_id, name, totalscore
FROM
(
SELECT scoringtable.user_id, scoringtable.name, sum(scoringtable.score) AS totalscore
FROM
scoringtable
WHERE game='B'
GROUP BY scoringtable.user_id ORDER BY totalscore DESC
)as scoringtable,(SELECT @curr := null, @prev := null, @rank := 1, @i := 0) tmp_tbl
参见工作示例:http://www.sqlfiddle.com/#!9/dd097/2
但是,在我显示总计的表格中,我还希望通过为每个月创建一个列来显示每月获得的积分。我知道我可以使用如下查询获取数据:
SELECT score AS 'january' FROM `scoringtable` WHERE month=1
但是如何在所有12个月内在现有查询中加入类似内容?
答案 0 :(得分:0)
您可以使用以下行中的案例:
SELECT(月份= 1然后得分结束时的情况)
AS'january'
(当月= 2然后得分结束时的情况)
AS'2月'
来自ArticleAPIManager