Skip to content
Advertisement

postgres sql query to convert group by result in multiple columns

I have two tables

  1. financial_account having columns account_name
  2. financial_transaction having columns transaction_date,transaction_type, transaction_amount

I need data as SUM(transaction_amount) where transaction_type=’A’ under column SUM_A and SUM(transaction_amount) under column SUM_B where transaction_type=’B’

I took reference of this stackoverflow post , wrote query as below :

However, this query is generating data in two rows

enter image description here

I needed data in single row format.

enter image description here

How can i get data in 1 one row format?

Advertisement

Answer

Considering your query is working properly, you can write your query like below:

You can write it like below also:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement