我想要做的是找出我在接下来的6个月中可能收到的最多任务数。
例如
task 1 runs 1-jan-16 and ends 10-jan-16
Task 2 runs 3-Jan-16 and ends 15-jan-16
task 3 runs 6-Jan-16 and ends 10-Jan-16
Task 4 runs 9-Jan-16 and ends 20-Jan-16
因此,在这个例子中,有4个任务在1月1日到1月1日之间打开,所以我希望在这种情况下结果为4。原因是我在甘特图中显示它们,所以它们都会在彼此之下。
到目前为止,我所有的工作都是:
select schedule_start_date,am.AC,count(wo) as from ac_master am
left outer join wo on wo.ac = am.ac and ac_type = '190'
where wo.status = 'OPEN'
group by am.ac,schedule_start_date
这将显示每天的计数,但其中一些可能会重叠。
无论如何要做我想要完成的事情吗?
答案 0 :(得分:1)
如果您只想在给定时间点对每个预定组进行计数,那么您只需使用BETWEEN
开头和结束日期:
SELECT schedule_start_date,
am.AC,
COUNT(*) AS theCount
FROM ac_master am
LEFT OUTER JOIN wo
ON wo.ac = am.ac AND
ac_type = '190'
WHERE wo.status = 'OPEN' AND
'2016-01-10' BETWEEN schedule_start_date AND schedule_end_date
GROUP BY schedule_start_date,
am.ac