There are lots of answers to that question depending on where you need the flattened information, where it comes from, whether you have a fixed number of expected statuses, etc, etc
Crosstab requires a “value” field that is transformed into the output column name (e.g. “Status” in the linked SO article), and also has a fixed number of output columns (see https://stackoverflow.com/questions/34502696/postgres-crosstab-dynamic-number-of-columns), so it does have significant limitations which may or not may be ok depending on the OP’s use case.
I need to put “tax”, “purchase_wallet”, “IT_charge” as column name.
May be crosstab is what I need. But how can I implement it in Phoenix Framework with repo.
If you can get the query going in Postgres you can run it at get an array of rows back using Ecto.Adapters.SQL.query!(MyApp.Repo, query_string) where MyApp.Repo is the replaced by your Repo module as per normal Ecto setup, and query_string is the query you got working directly in Postgres. That will return a results structure (see https://hexdocs.pm/postgrex/Postgrex.Result.html) that you can then transform into your required output.
Might be interested in PostgreSQL’s json_object_agg as well, can take the keys and the values and make a json object out of them so you have the mappings as well.