Get question on Sum function in TD

Database

Get question on Sum function in TD

hi, I am a layman in TD, and come across a Sum function issue.

sel

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?

thank u

2 REPLIES

Re: Get question on Sum function in TD

Following query can be used -

SEL

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

FROM table1

GROUP BY 1

-Shilpa

Re: Get question on Sum function in TD

thank u Shilpa

will try later

-Peter