gpt4 book ai didi

mysql - 如何获取每天的进出时间并在日期范围之间的查询中对其进行计数?

转载 作者:行者123 更新时间:2023-11-29 02:39:01 24 4
gpt4 key购买 nike

这是我现在正在使用的查询:

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')

Sample Database Image

我需要这样的输出。

Sample Output

或者我如何根据示例数据库计算每个日期范围的任何想法

最佳答案

我认为您需要从日期列表开始,然后使用 left join 或相关子查询:

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;

关于mysql - 如何获取每天的进出时间并在日期范围之间的查询中对其进行计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56821681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com