sql - Group by date and count specific values -


i'm trying create report there 1 row each date, , separate counter each color customers has chosen.

the input data consists of 2 columns, 1 date, , 1 color. this:

2014-04-11  blue  2014-04-11  green  2014-04-11  blue  2014-04-10  red  2014-04-10  green  2014-04-09  red  2014-04-09  red 

this report like:

| date | blue | green | red |  | 2014-04-11 | 2 | 1 | 0 |  | 2014-04-10 | 0 | 1 | 1 |  | 2014-04-09 | 0 | 0 | 2 | 

i guess need group date, problem cannot "sum" or "count" blue colors etc. possible? if so, can please me?

please try:

select      "date",     sum(case when color='blue' 1 else 0 end) blue,     sum(case when color='green' 1 else 0 end) green,     sum(case when color='red' 1 else 0 end) red     yourtable group "date" 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -