select * from T a where (select count(*) from T where a.col1 = col1) = 1select count(*) from T a where (select count(*) from T where a.col1 = col1) = 1 select col1 from T group by col1 having count(*) = 1
to:klan 假如表table1数据为 id col1 col2 1 a aaaa 2 b advad 3 c adad 4 a dddd用你写的语句能得到的结果为3嘛?
select count(distinct col1) from table --得到数目 select distinct col1 from table --得到详单
select count(*) from ( select col1 from T group by col1 having count(*) = 1 ) emp
select count(*) from table1 group by col1
xiaoliaoyun(流浪的云) 的语句就很经典了。
select count(*) from table where (select count(*) from table where coll=table.coll)=1
from T a
where (select count(*) from T where a.col1 = col1) = 1select count(*)
from T a
where (select count(*) from T where a.col1 = col1) = 1
select col1
from T
group by col1
having count(*) = 1
假如表table1数据为
id col1 col2
1 a aaaa
2 b advad
3 c adad
4 a dddd用你写的语句能得到的结果为3嘛?
--得到数目
select distinct col1 from table
--得到详单
(
select col1
from T
group by col1
having count(*) = 1
) emp