Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to get top 5 assets which having more tickets raised using sql

Posted on 2016-11-15
5
Medium Priority
?
69 Views
Last Modified: 2016-11-22
Hi Experts,

ticket table (ticket id,asset id(F.K),created time,customername,categoryid)
asset table (asset id,name,customername,categoryid)


if the asset(let suppose computer) having any issues one ticket will be created based on ticket support people vl give assistance.

i want top 5 assets which have more tickets got created.

can some one guide me form a query to get top 5 assets which having more tickets
0
Comment
Question by:srikotesh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 800 total points
ID: 41889184
HI,

pls try

SELECT top 5 Count(T1.ticket_id) AS CountOfTickets, T2.Name
FROM Ticket_tavble as T1 LEFT JOIN Asset_Table as T2 ON T1.AssetId = T2.AssetId
GROUP BY T2.name;

Open in new window

Regards
0
 
LVL 30

Expert Comment

by:Pawan Kumar
ID: 41889223
Try...

SELECT TOP 5 * FROM 
(
	SELECT COUNT(*) TicketCount , a.AssetId 
	FROM AssetTable a INNER JOIN TicketTable b ON T1.AssetId = T2.AssetId
	GROUP BY a.AssetId
) AS P
INNER JOIN AssetTable b ON p.AssetId = b.AssetId
ORDER BY p.TicketCount DESC

Open in new window


Hope it helps!
0
 
LVL 2

Author Comment

by:srikotesh
ID: 41889272
hi experts,

i don't want to use top command

order by Count(T1.ticket_id) desc limit 5
the above statement is enough?
0
 
LVL 30

Accepted Solution

by:
Pawan Kumar earned 1200 total points
ID: 41889276
Try....

SELECT * FROM 
(
	SELECT COUNT(*) TicketCount , a.AssetId 
	FROM AssetTable a INNER JOIN TicketTable b ON T1.AssetId = T2.AssetId
	GROUP BY a.AssetId
) AS P
INNER JOIN AssetTable b ON p.AssetId = b.AssetId
ORDER BY p.TicketCount DESC LIMIT 5 

Open in new window

0
 
LVL 30

Expert Comment

by:Pawan Kumar
ID: 41894808
Hi Srikotesh,
Is this done :)

Regards,
Pawan
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question