我有一张满是虫子的桌子. BugTitle是页面错误,我也捕获错误行.
我想构建一个SQL查询,根据bugtitle和错误行选择前10个错误.
我有这个问题:
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
但我不确定它是否正确.我很确定我的测试数据只有1个错误发生在同一行,但是没有出现这个查询.
有人可以帮忙吗?
最佳答案 为了获得最常见的前10名,您可能希望按计数排序:
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