mysql - How to count value group by date and row value -


i want count evaluation score each month. evaluation ranging 1-5. want show them in table how many score of each evaluation rated each month. data. date column in format : yyyy-mm-dd.

+-----------+---+---+---+---+---+ | date/eval | 5 | 4 | 3 | 2 | 1 | +-----------+---+---+---+---+---+ |2015-06-01 | 10| 15| 2 | 3 | 0 | +-----------+---+---+---+---+---+ |2015-06-02 | 20| 11| 5 | 4 | 1 | +-----------+---+---+---+---+---+ |2015-06-03 | 5 | 10| 5 | 6 | 2 | +-----------+---+---+---+---+---+ . . . +-----------+---+---+---+---+---+ |2015-06-30 | 10| 15| 2 | 3 | 0 | +-----------+---+---+---+---+---+ 

then need display data in table this.

+------------+---+---+---+---+---+ | date/eval  | 5 | 4 | 3 | 2 | 1 | +------------+---+---+---+---+---+ |june 2015   |110|105| 32| 23| 0 | +------------+---+---+---+---+---+ |july 2015   |132| 50| 21| 13| 0 | +------------+---+---+---+---+---+ |august 2015 |151| 55| 42| 30| 0 | +------------+---+---+---+---+---+ 

all sql script can think group by. it's works group date.

here's script:

select * evaluation group year,month(datetime) asc

how count unique value of each evaluation.

create data structure , fill test data:

create table evaluation (   evaldate date not null,   grade1 int(11) not null,   grade2 int(11) not null,   grade3 int(11) not null,   grade4 int(11) not null,   grade5 int(11) not null,   primary key (evaldate) );  insert evaluation values('2015-07-14', 1, 2, 3, 4, 5); insert evaluation values('2015-07-15', 2, 2, 2, 2, 2); insert evaluation values('2015-08-12', 5, 4, 3, 2, 1); insert evaluation values('2015-08-13', 1, 1, 1, 1, 1); 

perform query want do:

select year(evaldate)      , month(evaldate)      , sum(grade1)      , sum(grade2)      , sum(grade3)      , sum(grade4)      , sum(grade5)    evaluation   group      year(evaldate)      , month(evaldate); 

returns:

year(evaldate) month(evaldate) sum(grade1) sum(grade2) sum(grade3) sum(grade4) sum(grade5) 2015           7               3           4           5           6           7 2015           8               6           5           4           3           2   

this seems me result looking for, right?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -