SQL noob Question
I am trying to generate a very simple report with how many Critical, High, Medium, and Low tickets a person has using a sql query and just don't know enough about SQL to get what I want.
I want the output to be close to this:
Here is what I have:
SELECT HD_PRIORITY.NAME AS "Users's Tickets" FROM HD_TICKET JOIN HD_PRIORITY ON (HD_PRIORITY.ID = HD_TICKET.HD_PRIORITY_ID) JOIN HD_STATUS ON (HD_STATUS.ID = HD_TICKET.HD_STATUS_ID) LEFT JOIN USER O ON (O.ID = HD_TICKET.OWNER_ID) WHERE (HD_TICKET.HD_QUEUE_ID = 21) AND ((HD_STATUS.NAME not like '%Parked%') AND (HD_STATUS.NAME not like '%Closed%') AND (O.FULL_NAME = 'user')) GROUP BY HD_PRIORITY.NAME ORDER BY HD_PRIORITY.ORDINAL
The only thing I am missing is a second column with Count(*).
How do I do that? I feel like an idiot.
Thanks for helping me out.
An easy way to get this would be the following query:
SELECT HD_PRIORITY.NAME, COUNT(HD_PRIORITY.NAME)
JOIN HD_PRIORITY on HD_PRIORITY.ID = HD_TICKET.PRIORITY_ID
JOIN HD_STATUS on HD_STATUS.ID = HD_TICKET.HD_STATUS_ID
JOIN USER O on O.ID = HD_TICKET.OWNER_ID
WHERE (HD_TICKET.HD_QUEUE_ID = 21) AND ((HD_STATUS.NAME not like '%Parked%') AND (HD_STATUS.NAME not like '%Closed%') AND (O.USER_NAME = 'user')) GROUP BY HD_PRIORITY.NAME ORDER BY HD_PRIORITY.ORDINAL
Note that I changed the query to username instead of full name since I find that more reliable.
Whenever you want to get a count of values in a column from MySQL you select the column, the count of that column, and then group by the column.