select*fromlogasa,(selectmessagefromloggroupbymessagehavingcount(*)>1)ssage=ssage这么写会比你的写法效率高一些,不过暂时想不出可以大幅度改善性能的写法。我的语句是联接,而楼主的查询是嵌套子查询。SQLSERVER帮助中说的很明白:在一些必须检查存在性的情况中,使用联接会产生更好的性能。否则,为确保消除重复值,必须为外部查询的每个结果都处理嵌套查询。所以在这些情况下,联接方式会产生更好的效果。
select count(id) from table group by id having count(id)>1
直接查出重复--查出表中有重复的id的记录,并计算相同id的数量select id,count(id) from @table group by id having(count(id)>1)其中,group by id,是按id字段分组查询:select id,count(id) from @table group by id可以得到各不同id的数量合计having(count(id)>1)判断数量大于1,也就是有重复id的记录
171 浏览 8 回答
86 浏览 4 回答
149 浏览 6 回答
126 浏览 4 回答
310 浏览 4 回答
340 浏览 4 回答
187 浏览 3 回答
252 浏览 6 回答
338 浏览 3 回答
200 浏览 6 回答
291 浏览 3 回答
338 浏览 5 回答
314 浏览 8 回答
341 浏览 3 回答
242 浏览 3 回答
203 浏览 6 回答
116 浏览 5 回答
285 浏览 8 回答
109 浏览 4 回答