这是您最好在数据库中解决的任务(或 Crystal Reports 中的查询/命令)。作为草图:
- 为您想查看的每一天设置一行(也许使用date table)
- 每天从该表中选择符合您条件的票数 (
count)
这样您将获得一个始终包含 365 行的结果集,因此您的报告中不会出现任何问题。如果当天没有票,则某些行可能包含 0。
下面是一个例子。它使用日期表。它显示了两种获取给定日期的机票信息的方法:
- 子选择:提供每个日期的开放票数,不多不少
- 加入日期的票证。使用这种方式,所有票证信息都可以/在您的结果集中可用。可以在 SQL 或您的报告中进行计数和分组(按严重性、分配的用户等对未结工单进行分组)
查看 where/join 条件(opened <= adate 和 (closed is null or closed >= adate))是否准确代表您想要的(如果在日期关闭的票证算作当天开放,票证是否会在同一个日期被视为开放,....
create table #dates (adate date);
insert into #dates (adate) values
('2017-06-23'),
('2017-06-22'),
('2017-06-21'),
('2017-06-20'),
('2017-06-19')
create table #tickets (id int, opened date, closed date);
insert into #tickets (id, opened, closed) values
(1, '20170620', null),
(2, '20170620', '20170622'),
(3, '20170621', '20170622'),
(4, '20170624', null)
-- just the open tickets per day
select
adate
,(select count(id) from #tickets where opened <= adate and (closed is null or closed >= adate)) open_tickets
from #dates
left outer join #tickets on opened <= adate and (closed is null or closed >= adate)
-- tickets joined to date, all ticket information available
select
adate
,#tickets.*
from #dates
left outer join #tickets on opened <= adate and (closed is null or closed >= adate)
drop table #tickets
drop table #dates