I have a table comprising a list of artists added to a playlist during specific years (2018 – 2022). I want to pivot the data into five "year" columns with corresponding artist names added in those years. I used the ‘case’ statements. However, it shows one record per row and gives a null value for all other years.
Expected output:
So I tried the ‘crosstab’ function, but it still doesn’t output data as expected which is in different columns, corresponding to years without any blank fields with null values.
2
Answers
Gives output:
By piecing the screenshots together, it seems that you have a table with three columns: (
year_added
,track
,artist
) and you want the output looks like below:If so, the query below may work for you: