Group query in subquery to get column value as column name

The data i've in my database:

| some_id|  status|
| 1      | SUCCESS|
| 2      | SUCCESS| 
| 1      | SUCCESS| 
| 3      | SUCCESS| 
| 1      | SUCCESS| 
| 4      | FAILED | 
| 1      | SUCCESS|
| 1      | FAILED |
| 4      | FAILED |
| 1      | FAILED |
....... 

I ran a query to group by id and status to get the below result:

| some_id| count|  status|
| 1      |    20| SUCCESS| 
| 2      |    5 | SUCCESS| 
| 3      |    10| SUCCESS| 
| 2      |    15| FAILED | 
| 3      |    12| FAILED | 
| 4      |   25 | FAILED | 

I want to use the above query as subquery to get the result below, where the distinct status are column name.

| some_id| SUCCESS|  FAILED|
| 1      |    20  |  null/0| 
| 2      |    5   |  15    | 
| 3      |    10  |  12    | 
| 4      |  null/0|  25    | 

Any other approach to get the final data is also appreciated. Let me know if need more info.

Thanks



Read more here: https://stackoverflow.com/questions/65713896/group-query-in-subquery-to-get-column-value-as-column-name

Content Attribution

This content was originally published by user3344521 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: