Thursday, April 21, 2011

SQL Get Top 10 bug records by count but with ID

I asked a question earlier today here. However, what I neglected to check with that question is how can I get AN id of those bug records? So for example, if I have a bug that has happened 3 times, how can I return one of the ID's from those 3 records?

From stackoverflow
  • You could return either the Max or Min Bug Id

    SELECT TOP(10) COUNT([BugTitle]) AS 'BugCount', [BugTitle], [ErrLine], MIN([BugId]) AS 'BugId'
    FROM [Bugs] 
    WHERE [BugDate] >= DateAdd(Day, -30, DateDiff(Day, 0, GetDate())) 
    GROUP BY [BugTitle], [ErrLine]
    ORDER BY COUNT([BugTitle]) DESC 
    

0 comments:

Post a Comment