tags:

views:

77

answers:

1

I have a table full of bugs. The BugTitle is the page erroring and I also capture the error line. I would like to build an SQL Query that selects the top 10 bugs based on bugtitle and error line. I have this query:

SELECT COUNT(BugTitle) AS BugCount, BugTitle, ErrLine 
FROM Bugs 
WHERE BugDate >= DateAdd(Day, -30, DateDiff(Day, 0, GetDate())) 
GROUP BY BugTitle, ErrLine 
ORDER BY BugCount, ErrLine DESC

But I'm not sure if it's correct. I'm pretty sure that my test data only has 1 bug that happens on the same line but that's not showing up with this query. Can anyone help?

+1  A: 

To get the top 10 most frequent you probably want to order by the count:

SELECT TOP(10) COUNT(BugTitle) AS BugCount, BugTitle, ErrLine
FROM Bugs
WHERE BugDate >= DateAdd(Day, -30, DateDiff(Day, 0, GetDate()))
GROUP BY BugTitle, ErrLine
ORDER BY COUNT(BugTitle) DESC
Mark Byers
ORDER BY BugCount like he did is not enough?
systempuntoout
True.... but the desc is wrong.
Mark Byers
*edit*It appears your query does work as a copy-paste of yours is perfect, I must have mistyped.
Pselus
@Pselus: Heh... it's OK. Happens sometimes. :)
Mark Byers