I retrieve each player's first five transactions data on one line with GROUP_CONCAT but since my final goal is to export this data in csv format I want to have an exact number of columns at the end. How to concat a specific number of occurences of a pattern to always obtain 5 columns ? In my case I need 5 columns for the amounts, 5 for the issue dates, and so on.
Here is the original query :
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