sqlfiddle:http ://sqlfiddle.com/#!2/9a8b3/1
从小提琴中获取结构、数据和查询,导入我的 MariaDB 5.5.31,我得到不同的结果:
sqlfiddle
PID NAME LEAGUEPOINTS TOTALLEAGUEPOINTS
2 Peter 16,13,9,4,2 44
1 Daniel 3425,543,234,43,29,22,21,21,19,17,13,12,12,12,11,9,9,9,8,7 4476
玛丽亚数据库
pid name leaguepoints totalleaguepoints
2 Peter 16,13,9,4,2 44
1 Daniel 3425,543,234,43,29,22,21,21,19,17,13,12,12,12,11,9,9,9,8,7,7,6,5,5,4,4,4,3,3,2,1 4520
询问:
SELECT
p.pid,
p.name,
GROUP_CONCAT( gC.leaguepoints ORDER BY leaguepoints DESC ) AS leaguepoints,
SUM(gC.leaguepoints) AS totalleaguepoints
FROM test_golf_player p
LEFT JOIN
(
SELECT pid, leaguepoints, @Sequence:=IF(@PrevPid = pid, @Sequence + 1, 0) AS aSequence, @PrevPid := pid
FROM
(
SELECT pid, leaguepoints
FROM test_golf_card
ORDER BY pid, leaguepoints DESC
) Sub1
CROSS JOIN (SELECT @PrevPid := 0, @Sequence := 0) Sub2
) gC
ON p.pid = gC.pid AND aSequence < 20
GROUP BY p.pid
ORDER BY p.name DESC
知道为什么吗?