mysql - Sort all query results in 2 categories -
i have transaction data in mysql table. 1 of fields name of supplier. in number of records supplier not specified (literally 'unspecified').
so data looks :
id date supplier --- 1 1 nov 2013 green supplier 2 3 nov 2013 red supplier 3 15 nov 2013 unspecified 4 2 dec 2013 unspecified 5 6 nov 2013 blue supplier 6 20 nov 2013 unspecified
x 100,000 etc
i can sum , group each month using sum(if(date_format (date, '%b, %y')= 'nov, 2013', 1,0) etc -
nov 2013 dec 2013 unspecified 1 2 green supplier 1 0 red supplier 1 0 blue supplier 0 1 etc
however want simplified version breaks results down (1) unspecified , (2) else totalled. results -
nov 2013 dec 2013 unspecified 1 2 'not unspecified' 2 1 etc
while still retaining sum per month format. sure should simple, can't think of how. can advise?
you add conditional logic group by
in query:
select (case when supplier = 'unspecified' 'unspecified' else 'specified' end), . . . . . . group (case when supplier = 'unspecified' 'unspecified' else 'specified' end);
in mysql, don't have repeat logic in group by
:
group 1
Comments
Post a Comment