mysql - counting rows only if on both days of a weekend -
i have table this:
id|shift|      date|  1|   s1|2017-08-12|    2|   s2|2017-08-14|  3|   s3|2017-08-20|  4|   s2|2017-08-26|  5|   s3|2017-08-27|  6|   s1|2017-08-28| i'd count number of times shifts worked on both days of weekend (saturday , sunday of same weekend) , on both days.
in example above, full weekend worked 8/26-8/27 answer should 1.
any appreciated.
join table itself. (join sundays the previous day).
select count(*) yourtable sun -- sunday join yourtable sat -- saturday   on  sat.shift = sun.shift   , sat.date  = sun.date - interval 1 day dayofweek(sun.date) = 1 -- sunday 
Comments
Post a Comment