My returned query looks like this
| Name | Type 1 | Type 2 | Type 3 |
|---|---|---|---|
| John | 1 | ||
| John | 3 | ||
| John | 5 | ||
| Ronn | 11 | ||
| Ronn | 9 | ||
| Ronn | 7 |
but I want them to be in a single row that looks like this, what functions should I use?
| Name | Type 1 | Type 2 | Type 3 |
|---|---|---|---|
| John | 1 | 3 | 5 |
| Ronn | 11 | 9 | 7 |
Here's my query
SELECT c.name,
if(t.type = A, SUM(t.amount), "") AS Type 1,
if(t.type = B, SUM(t.amount), "") AS Type 2,
if(t.type = C, SUM(t.amount), "") AS Type 3
FROM
customer AS c,
transaction AS t,
t_detail AS td
WHERE
c.id = td.id
AND t.type IN ("A", "B", "C")
GROUP BY c.id, t.type
customer
id = fk to t_details
transaction
amount
type
t_detail
t_id id = FK. customer id