Tuesday, 15 June 2010

sql - Get Data From Database According Two dates -



sql - Get Data From Database According Two dates -

sql query:

select type, sum(a), sum(b) tablea store_date between '"+date1+"' , '"+date2+"'group type date1="16/06/2014" date2="18/06/2014"

by query getting sum of column , column b according dates. want info column b date1 date2 each type,but column want info date1, don't want include date2 in sum(a)

**example(expected result):** type sum(a) sum(b) ------------------------------- | fruit | 10 | 20 | | | | | | | | | | | | | | | | | -------------------------------

10 representing sum tablea column date 16/06/2014.

20 representing sum tablea column b date 16/06/2014 18/06/2014.

try this

select type, sum(case when date = date1 else 0 end) 'a', sum(case when date between date1 , date2 b else 0 end) 'b' table grouping type

sql

No comments:

Post a Comment