This is my query.Group by query in one table and I wanna get three sum column in select statement
Advertisement
Answer
You can use CASE statement to achieve this result as shown below.
SELECT sales_id, SUM(CASE WHEN type = 'deposit' THEN amount ELSE 0 END) AS deposit, SUM(CASE WHEN type = 'withdrawn' THEN amount ELSE 0 END) AS withdrawn, SUM(CASE WHEN type = 'commission' THEN amount ELSE 0 END) AS commission FROM `ds_wd20_files` GROUP BY sales_id
Please replace sales_id with sales person name