Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-11-15
5
Medium Priority
?
72 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
  • 3
5 Comments
 
LVL 53

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 35

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 35

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 35

Expert Comment

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

Regards,
Pawan
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…
Suggested Courses
Course of the Month6 days, 13 hours left to enroll

783 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