I have to write a query in which i have to put condition on two columns and then aggregate the record in third column on the basis of first two columns. you can have an idea from database table. This is my database table
[![Advisers Table][1]][1]
Now, what i want is that, i have to find top financial adviser and aggregate the sum of deal volume, for example suppose nitish is appearing in two times in table one in financial_adviser and and another in target_adviser in different rows, nitish can't be in both financial_adviser and target_adviser in a single row, and the value in deal_volume for nitish is 100 and 200 respectively. so nitish should be a financial adviser with deal_volume as 300.
So for this table the final result after executing query should be like
[![Financial Advisers table][1]][1]
I am using postgresql tried to fetching this result but did not get the right result.
答案 0 :(得分:0)
SELECT advisors,
sum(deal_volume) AS dealVolume from
( SELECT target_adv AS "advisors", deal_volume
FROM ma_global
UNION ALL SELECT acq_adv AS "advisors", deal_volume
FROM ma_global) ma_global
GROUP BY advisors
ORDER BY dealVolume DESC