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的记录
110 浏览 8 回答
324 浏览 4 回答
266 浏览 6 回答
357 浏览 4 回答
96 浏览 4 回答
220 浏览 4 回答
129 浏览 3 回答
200 浏览 6 回答
293 浏览 3 回答
235 浏览 6 回答
151 浏览 8 回答
153 浏览 10 回答
353 浏览 4 回答
251 浏览 6 回答
147 浏览 8 回答
350 浏览 3 回答
83 浏览 3 回答
330 浏览 11 回答
225 浏览 8 回答
202 浏览 12 回答