Last active
November 1, 2015 16:13
-
-
Save rashivkp/616bd6bc26ddf24dff7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select distinct student, date, sum(if(ifnull(k1.hour, 0)>0, 1, 0)) as fornoon, | |
sum(if(ifnull(k2.hour, 0)>0, 1, 0)) as afternoon from t1 | |
left join t1 k1 on k1.student=t1.student, k1.date=t1.date and hour between 1, 4 | |
left join t1 k2 on k2.student=t1.student, k2.date=t1.date and hour between 5, 7 | |
; another approach, not tested | |
SELECT student, date | |
count(CASE WHEN t1.hour between 1,4 THEN 1 END ) AS fornoon, | |
count(CASE WHEN t1.hour between 5,7 THEN 1 END ) AS afternoon | |
from t1 | |
group by student, date | |
order by student, date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, let me try