Solved

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

Posted on 2016-11-15
5
47 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 49

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

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

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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