if not object_id('tb') is null drop table tb Go Create table tb([small_id] int) Insert tb select 1 union all select 1 union all select 3 union all select 4 union all select 4 union all select 5 union all select 7 union all select 2 union all select 6 union all select 6 Go select count(small_id) from( select small_id from tb group by small_id having count(*)>1 )t /* ----------- 3(1 個資料列受到影響) */
select top 1 count(1) from A group by small_id having count(small_id)>1
select count(distinct small_id) from tb group by small_id having count(*)>1
(SELECT small_id FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE small_id =T.small_id )AS T
from tb
group by small_id
having count(*)>1
select count(*)as num from
(select small_id from Tb group by small_id having(count(*)>1)
)t
FROM
(SELECT small_id FROM TB T WHERE EXISTS(SELECT 1 FROM TB WHERE small_id =T.small_id )AS T
-->Author:wufeng4552【水族杰纶】
-->Date :2009-08-19 09:42:23
if not object_id('tb') is null
drop table tb
Go
Create table tb([small_id] int)
Insert tb
select 1 union all
select 1 union all
select 3 union all
select 4 union all
select 4 union all
select 5 union all
select 7 union all
select 2 union all
select 6 union all
select 6
Go
select count(small_id) from(
select small_id from tb group by small_id having count(*)>1
)t
/*
-----------
3(1 個資料列受到影響)
*/