开发者

SQL Get Top 10 records by date

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 te开发者_如何学JAVAst data only has 1 bug that happens on the same line but that's not showing up with this query. Can anyone help?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜