1
我使用GROUP_CONCAT檢索每個球員的前五個交易數據,但是由於我的最終目標是以csv格式導出此數據,因此我希望獲得確切數量的最後列。如何連接特定數量的模式出現總是獲得5列?在我的情況下,我需要5列的金額,5的發行日期,等等。如何填充一個具有多個模式的varchar
這裏是原始查詢:
SELECT
p.id,
GROUP_CONCAT(t1.amount SEPARATOR "|") as amounts,
GROUP_CONCAT(t1.issueDate SEPARATOR "|") as issueDates,
GROUP_CONCAT((select t2.amountInEuro*100/t1.amountInEuro from Transaction t2 where t2.type = 3 and t2.id = t1.deposit_id) SEPARATOR "|") as bonusAmounts
FROM Transaction t1 join Player p on p.id = t1.player_id
WHERE
t1.type = 0 and
t1.status = 0 and
exists (select 1 from Transaction tr where tr.issueDate between '2010-07-03 00:00:00' and '2013-07-03 23:59:59' and tr.player_id = t1.player_id)
GROUP BY t1.player_id
HAVING count(*) <= 5
你能提供一些樣本數據? – golimar
您的意思是我們使用當前查詢獲得的結果嗎?當然,結果如下: 4 2500 | 1000 | 1000 | 1000 2011-07-18 | 2011-09-19 | 2011-09-19 | 2011-09-19 38.5694 | 95.8188 2011 -02-27 1000 | 1000 \t 2010-09-15 | 2011-01-19 感謝您的幫助 – mordekhai