求大佬支招,这sql怎么写?
sql吧
全部回复
仅看楼主
level 1
古三叶º 楼主
[泪] [泪]
这样一张表
id neme start_time end_time
1 a 2018-01-01 2018-05-06
2 b 2018-02-01 2018-06-01
3 c 2018-03-01 2019-11-06
start_time开始时间,end_time 结束时间,在这两个时间范围内 则为有效人员
想要得到某一年的有效人员数目数据 比如
time num
2018-01-01 1
2018-01-02 1
2018-01-03 1
.。。。
2018-03-25 3
2018-03-26 3
2018-03-27 3
.。。。
2018-05-30 2
2018-06-01 2
2018-06-02 1
.。。
这样 谢过大佬
2019年02月12日 12点02分 1
level 3
这不是个分组统计么,根据时间分组,再加你的有效条件
2019年02月13日 09点02分 2
level 2
select count(*) from 表 a where a.start_time >= ? and a.end_time <= ?
2019年02月25日 06点02分 3
我需要一年365天 每一天的统计 这样
2019年02月25日 08点02分
你这个time num 与 tart_time、 end_time 有关系么?
2019年02月25日 08点02分
@二楼爱你 我需要这两个字段 日期time 2018-01-01 数量num 1,如果日期time 在start_time和end_time 区间里 则数量num+1
2019年02月25日 08点02分
-- 表year是我新建的时间表,是一年的所有天 select count(*) sl, ye.shijian sj from 表 xi, year ye where xi.start_time >= ye.shijian and a.end_time <= ye.shijian group by ye.shijian
2019年02月26日 01点02分
1