Solved

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

Posted on 2016-11-15
5
22 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 48

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 17

Expert Comment

by:Pawan Kumar Khowal
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 1

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 17

Accepted Solution

by:
Pawan Kumar Khowal 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 17

Expert Comment

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

Regards,
Pawan
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now