SQL destinct to unique column

Hello,

Using MS SQL and Grafana table, would it be possible to automatically generate new columns per each unique value of a particular column?

Example, data is:

    row | user | tickets | state
    -------------------------------
    1   | 1    | 32      | Closed
    2   | 1    | 2       | Open
    3   | 2    | 5       | On-Hold
    4   | 2    | 10      | Open
    5   | 3    | 4       | Open

I would like it to become:

    row | user | Open | On-Hold | Closed
    ------------------------------------
    1   | 1    | 2    | 0       | 32
    2   | 2    | 10   | 5       | 0
    3   | 3    | 5    | 0       | 0

I could Case the states, but I would like Grafana to be independent of the States the source may create.

Thanks in advance!
Bastiaan

Have you tried it on sql . First way to try to test it on sql or mysql and after that provide same query to grafana it will works.

Yes I’ve tried, but havent found a way to create a dynamic parent select based on a nested query. Or perhaps I’m not researching it with the right words.

Share your sql query or grafana query