问题
I'm trying to create a report based on a ticketing system. The goal is to have one graph with multiple lines, one for tickets opened by week, other line is tickets closed by week.
The problem I have is when you group data, a record cannot be in multiple groups. However a ticket can have been opened during one week, and closed during another. In that example, the record would need to be counted twice.
For example. Ticket 123456 Open Date: 1/1/2012 Close Date: 1/12/2012
This ticket was opened during Week 1, and closed during Week 2. The problem is, if you group by Opened Week, then group by closed week, it filters the second group by the first.
Essentially, I need a way to have the data in multiple groups, but the overall goal is to display them in a line graph where the lines show number of opened and closed tickets per week.
Probably not the best description, but it's hard to describe? Anyone have any ideas?
回答1:
If I where you i would modify your SQL statement to include something like the below:
WITH DateTable
AS
(
SELECT CAST((GETDATE() - 180) as Date) AS [DATE]
UNION ALL
SELECT DATEADD(dd, 1, [DATE]) FROM DateTable
WHERE DATEADD(dd, 1, [DATE]) < cast(GETDATE() as Date)
)
The above creates somewhat of a temporary table with all dates in the past 180 days. Then add a new line to select your "DATE" column from that table into you SQL Query:
SELECT "DateTable"."DATE", ....
Then after your SELECT statements use a CROSS JOIN to join the two tables
CROSS JOIN "DateTable"
This takes you from Query Results that look like this:
OrderNum DueDate CompletedDate
1 01/01/01 01/02/01
2 01/01/01 01/01/01
3 01/02/01 01/03/01
4 01/02/01 01/02/01
To Query results that look like this:
OrderNum DueDate CompletedDate Date
1 01/01/01 01/02/01 01/01/01
2 01/01/01 01/01/01 01/01/01
3 01/02/01 01/03/01 01/01/01
4 01/02/01 01/02/01 01/01/01
1 01/01/01 01/02/01 01/02/01
2 01/01/01 01/01/01 01/02/01
3 01/02/01 01/03/01 01/02/01
4 01/02/01 01/02/01 01/02/01
1 01/01/01 01/02/01 01/03/01
2 01/01/01 01/01/01 01/03/01
3 01/02/01 01/03/01 01/03/01
4 01/02/01 01/02/01 01/03/01
Now you can use a simple Crystal Record Select Statement to whittle down the reults to only those open on those given days:
{Ticket Open Date} < {Command.DATE} and
{Ticket Close Date} > {Command.DATE}
Now you have the same detail lines in multiple groups. Hope that helps, P.S. if I had more information about your query or table structure I could possibly be more specific.
来源:https://stackoverflow.com/questions/9083599/one-record-in-multiple-groups-within-crystal-reports-xi