Solved

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

Posted on 2016-11-15
5
53 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 50

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 200 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 28

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 28

Accepted Solution

by:
Pawan Kumar earned 300 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 28

Expert Comment

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

Regards,
Pawan
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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