Reputation: 320
This is the query i'm using right now:
Select *
from attendance
where (in_time BETWEEN '2019-06-20 00:00:01' and '2019-06-20 23:59:59')
and (out_time BETWEEN '2019-06-28 00:00:01' and '2019-06-28 23:59:59')
and i need an a output like this.
or any ideas how do i count each date range base on my sample database
Upvotes: 2
Views: 131
Reputation: 320
I used this query to collect data in_time and count then remove the time using substring.
SELECT substring(in_time,1,10), COUNT(DISTINCT employees_id)
FROM attendance
WHERE (in_time BETWEEN '2019-06-20 00:00:01' and '2019-06-28 23:59:59')
GROUP BY substring(in_time ,1,10)
Upvotes: 0
Reputation: 1270401
I think you need to start with a list of dates and then use left join
or a correlated subquery:
select d.dte,
(select count(*)
from attendance a
where a.in_time <= dte and a.out_time >= dte
) as cnt
from (select date('2019-06-20') as dte union all
select date('2019-06-21') as dte union all
select date('2019-06-22') as dte union all
select date('2019-06-23') as dte union all
select date('2019-06-24') as dte union all
select date('2019-06-25') as dte union all
select date('2019-06-26') as dte union all
select date('2019-06-27') as dte union all
select date('2019-06-28') as dte
) d;
Upvotes: 1