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
Medium Priority
69 Views
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
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
• 3

LVL 52

Assisted Solution

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;
``````
Regards
0

LVL 30

Expert Comment

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
``````

Hope it helps!
0

LVL 2

Author Comment

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

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
``````
0

LVL 30

Expert Comment

ID: 41894808
Hi Srikotesh,
Is this done :)

Regards,
Pawan
0

## Featured Post

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…
###### Suggested Courses
Course of the Month6 days, left to enroll