0

So, we have a table that basically includes most of the ticket details of a ticket, except for stuff that is horribly long (like notes, tech notes, pictures, etc), those are linked elsewhere in other tables, etc.

We want to return metrics about the various tickets in the data table. For example:

SELECT Category, Count(Category) FROM tickets 
WHERE Date_SUB(CURDATE(), Interval 16 Hour) <= Datez GROUP BY Category

Which would return a result listing, for example, each of our categories, and their counts.

However, if we want to adjust this for various intervals, like return the numbers for say 16 hours, 1 day, 30 day, 3 month, 12 month and All time, are we going to have to run that same query that # of times (like for each of those listed minus all time, run that query 5 times?

Ultimately, we want to use the counts in a dashboard of some sort in our C# Winforms application, that will show us various ticket data, so we can see how the department is doing; but, if we have to sit there and run say 5 queries every few minutes, that can tend to bog down the system no?

4

2 回答 2

1

你可以尝试这样的事情:

SELECT
    Category,
    IF(Date_SUB(CURDATE(), Interval 16 Hour) <= Datez, SUM(1), 0) AS c16hours,
    IF(Date_SUB(CURDATE(), Interval 1 day) <= Datez, SUM(1), 0) AS c1day,
    IF(Date_SUB(CURDATE(), Interval 30 days) <= Datez, SUM(1), 0) AS c30days,
    (...)
FROM tickets 
GROUP BY Category

这应该可行(但我没有测试过这个例子,只是给你一些理论)!

祝你好运。

于 2012-07-30T23:57:26.037 回答
-1

我相信你也可以在 WHERE 语句之后添加一个 AND 语句来继续列表。

这将定义。缩短它

于 2012-07-30T23:53:35.780 回答