我有以下查詢其作品...但我需要一些變化:SUM MySQL的
SELECT
p.pid,
p.name,
GROUP_CONCAT(gC.leaguepoints ORDER BY leaguepoints DESC) AS leaguepoints
FROM
golf_player p
LEFT JOIN
golf_card gC ON
p.pid = gC.pid
GROUP BY
p.pid
ORDER BY
p.name
DESC
我真正想要的是另一種屬性返回稱爲totalleaguepoints這是一個SUM我桌上最近的20個聯賽積分。
如何向group_concat添加限制?
這可能是這樣的?
SELECT
p.pid,
p.name,
GROUP_CONCAT(gC.leaguepoints ORDER BY leaguepoints DESC) AS leaguepoints,
SUM(
SELECT
gC2.leaguepoints
FROM
golf_card gC2
WHERE
gC2.pid = p.pid
ORDER BY
leaguepoints
DESC
LIMIT 20
) AS totalleaguepoints
FROM
golf_player p
LEFT JOIN
golf_card gC ON
p.pid = gC.pid
GROUP BY
p.pid
ORDER BY
p.name
DESC
P.S,上面的查詢不會運行
'我如何添加一個限制一個GROUP_CONCAT'你不要在where子句中創建過濾器? – DevZer0
我不明白? – Jimmyt1988