Split two rows into two columns
2
votes
1
answer
4317
views
I have the following table:
id | name | action | count
------------------------------
1 | Value1 | 0 | 27
1 | Value1 | 1 | 49
2 | Value2 | 0 | 7
2 | Value2 | 1 | 129
3 | Value3 | 0 | 9
3 | Value3 | 1 | 7
I need to make the 'action' column appear twice, with the count value of each line in it, something like this:
id | name | action1 | action2
---------------------------------
1 | Value1 | 27 | 49
2 | Value2 | 7 | 129
3 | Value3 | 9 | 7
How can I do this? Here's my script:
SELECT m.id,
t.name,
m.action,
count(m.id) AS count
FROM table1 m
LEFT JOIN table2 t ON (m.id = t.id)
WHERE m.status != '2'
GROUP BY m.id,
t.name,
m.action
ORDER BY 1, 3
Asked by Renan Lazarotto
(173 rep)
Jul 15, 2014, 12:50 PM
Last activity: Jun 28, 2020, 12:53 AM
Last activity: Jun 28, 2020, 12:53 AM