sqlfiddle:http://sqlfiddle.com/#!2/9a8b3/1不同的結果sqlfiddle.com 30年5月5日和MariaDB的31年5月5日
以結構和數據查詢從小提琴, 導入到我的MariaDB的31年5月5日,我得到不同的結果:
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
MariaDB的
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
任何想法爲什麼?
http://pastebin.com/sF6qnMxR – DanFromGermany
看着這些結果我認爲瑪麗亞可能忽略了內部子選擇中的ORDER BY子句。因此,序列號是隨機的順序,並且在pid更改時也會重置(由於順序不固定,所以它是隨機的)。 – Kickstart
似乎這是MariaDB的故意功能。 SQL標準將一個表定義爲一組無序的行,而一個子選擇被視爲一個表,因此按順序被忽略 - https://kb.askmonty.org/en/why-is-order-by-in - 從子查詢 - 忽略/ – Kickstart