I'm trying to make a table pivot on a postgresql database but i can't succeed. Here is my original request
SELECT tag_country.label, COUNT(*)
FROM log_event_tracking LEFT JOIN user_account ON log_event_tracking.email = user_account.email LEFT JOIN tag_country ON user_account.country = tag_country.id
WHERE date_time > CURRENT_DATE - INTERVAL '7 days'
GROUP BY tag_country.label;
and here is the result
label | count |
---|---|
<null> | 50 |
Spain | 23 |
France | 99 |
What i'm trying to do is to pivot this table to get this result
<null> | Spain | France |
---|---|---|
50 | 23 | 99 |
Does anyone have a solution ? Thanks for your answers.
EDIT :
Forgot to say that i might have more countries or less countries depending of the database i'm requesting and i need it works with the same query