--判断有几个a select count(*) from tb where test='a' group by test
--判断有几个a: select count(*) from tb where test='a' --判断哪几个有重复,重复多少: select test,count(*) from tb group by test having count(*)>1
create table tb ( id int, test nvarchar(50) )insert into tb select 1, 'a' union all select 2, 'b' union all select 3, 'c' union all select 4, 'd' union all select 5, 'a' if exists( select 1 from tb where test = 'a' group by test having count(test) = 2 ) begin print 'yes' enddrop table tb 结果: yes
SELECT COUNT(*) FROM TABLE WHERE TEST='A' GROUP BY TEST
select count(*) from tb where test='a' group by test
select count(*) from tb where test='a'
--判断哪几个有重复,重复多少:
select test,count(*) from tb group by test having count(*)>1
(
id int,
test nvarchar(50)
)insert into tb
select 1, 'a' union all
select 2, 'b' union all
select 3, 'c' union all
select 4, 'd' union all
select 5, 'a' if exists(
select 1
from tb
where test = 'a'
group by test
having count(test) = 2
)
begin
print 'yes'
enddrop table tb
结果:
yes