hi, I am a layman in TD, and come across a Sum function issue.
created_date (format 'YYYY/MM') (char(7)) as month
,count(*) as overall
,sum(table1. amount) as overall_amount
,sum(case when table1.amount > 300 then 1 else 0 end) as over_300_cnt
that's a part of my SQL,
and result come with 3 columns, but i want to get 4 columns, the 4th is the over_300_amt
how to use SUM function or other query?
Following query can be used -
created_date (FORMAT 'YYYY/MM') (CHAR(7)) AS MONTH
,COUNT(*) AS overall
,SUM(table1. amount) AS overall_amount
,COUNT(CASE WHEN amount>300 THEN 1 END) AS over_300_cnt
,SUM(CASE WHEN amount>300 THEN amount END) AS over_300_amt
GROUP BY 1