Conditional Sum SQL -
i new sql , have been presented with, seems me, complex task. have table generating number of various fruit purchased on given day. thus:
g. g.b 2016-06-01 banana 45 0 2016-06-01 pear 158 0 2016-06-01 apple 0 23 .... dates continue
i need develop kind of conditional sum count how many types of fruit bought specific grade on specific date. in above case on given date (2016-06-01) there 203 grade (g.a) bits of fruit , 23 grade b (g.b) pieces of fruit.
naturally kind of
sum(case when date=date grade else 0 ).
but, baffled here. please, appreciated!!!!
a simple group clause should job here (note: untested code)
select date, sum(grade_a) grade_a_sum, sum(grade_b) grade_b_sum sales group date;
this give grades every date. individual dates can selected if necessary.
Comments
Post a Comment