Hi Guys,

I'm trying to automate some reporting and I'm looking to get a Top 10 of categories for the month. If I try to use a SELECT TOP 10 command I get an error. Here's my script without the TOP 10 command and this spits out an unsorted count of tickets. How can I get it to just give me the TOP 10 calls?

Thanks

SELECT 
HD_CATEGORY.NAME AS Category,
count(HD_TICKET.TITLE) as Count_Of_Tickets
FROM HD_TICKET, HD_CATEGORY
WHERE
HD_TICKET.HD_CATEGORY_ID = HD_CATEGORY.ID
AND
(HD_TICKET.HD_QUEUE_ID = 1)
AND
(( date(HD_TICKET.TIME_CLOSED) >= date_sub(curdate(), interval dayofmonth(curdate())-1 day) and month(HD_TICKET.TIME_CLOSED) = month(curdate())))
group by CATEGORY

Answer Summary:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answer Chosen by the Author

0

The "TOP 10" syntax is specific to Oracle and does not work in MySQL.  At the bottom of your query (after the "group by CATEGORY" line), add the following.

First, to order the tickets from highest count to lowest:

order by Count_Of_Tickets desc

Second, to get only the first 10 records returned:

limit 10
Answered 02/05/2016 by: grayematter
Fourth Degree Black Belt

  • Thank you, that's exactly what was needed.
Please log in to comment

Answers

Answer this question or Comment on this question for clarity