Ritesh Fondke
Ritesh Fondke

Reputation: 122

Postion on date in table

My table looks like:

EmiDate    | EmiAmt | PaidDate   | PaidAmt 
-----------+--------+------------+--------
2019-01-05 | 7500   | 2019-01-05 | 7500
2019-01-06 | 7500   | 2019-01-06 | 7500
2019-01-07 | 7500   | null       | null
2019-01-08 | 7500   | 2019-05-08 | 6500
2019-01-09 | 7500   | null       | null
2019-01-10 | 7500   | null       | null

I want to get SUM(EmiAmt) and SUM(PaidAmt) on date "2019-07-31". Result should look like:

22500 | 15000

My try is:

SELECT SUM(EmiAmt)
     , CASE WHEN PaidDate <= '2019-07-01' THEN SUM(PaidAmt) END
  FROM tbl_Emi
 WHERE EMIDate <= '2019-07-31';

which gives me error of 'non-aggregated column'.

Upvotes: 0

Views: 53

Answers (1)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31993

i think you find below

select sum(EmiAmt),  sum(case when PaidDate  <='2019-07-01' then  PaidAmt else 0 end )
from tbl_Emi
where EMIDate <='2019-07-31';

Upvotes: 2

Related Questions