/build/static/layout/Breadcrumb_cap_w.png

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:

 

Users's Tickets,

LOW,3

MEDIUM,8

HIGH,2

CRITICAL,0

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.


1 Comment   [ + ] Show comment
  • Now I am trying to create a query that would give me a output that would look like this:

    Tech Name,Nate,Peter
    High,1,5
    Medium,12,17
    Low,6,28

    Any help would be great. I am trying to create this for a custom Panic Statusboard graph. - nwhistler 10 years ago

Answers (1)

Answer Summary:
Posted by: chucksteel 10 years ago
Red Belt
0

An easy way to get this would be the following query:

 SELECT HD_PRIORITY.NAME, COUNT(HD_PRIORITY.NAME)
FROM HD_TICKET
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. 

 


Comments:
  • Thanks, that's exactly what I needed. - nwhistler 10 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ