SQL Get Top 10 Records by Date

I have a table with errors. BugTitle is the page error, and I also commit the error line. I would like to create an SQL query that selects the top 10 errors based on bugtitle strings and errors. 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 this is correct. I am pretty sure that my test data has only one error, which occurs on one line, but does not appear with this query. Can anyone help?

+4
source share
1 answer

To get the 10 most popular, you probably want to order by invoice:

 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 
+2
source

Source: https://habr.com/ru/post/1305983/


All Articles