--测试数据
if object_id('tempdb..#tb') is not null
drop table #tb
create table #tb(fd1 varchar(10),fd2 varchar(10),fd3 varchar(10))
insert into #tb
select '1', '2', '3' union all
select '1', '2', '3' union all
select '1A','2A','3A' union all
select '1A','2A','3A' union all
select '1A','2B','3A' union all
select '1B','2A','3A' union all
select '1B','2A','3B' union all
select '1B','2A','3C'
--查询语句
select distinct t0.fd1,
case when then t0.fd2 else '...' end as fd2,
case when then t0.fd3 else '...' end as fd3
from (select fd1,max(fd2) as fd2,max(fd3) as fd3 from #tb group by fd1)t0
left join (select fd1,count(fd1) as cnt1 from #tb group by fd1)t1 on t0.fd1=t1.fd1
left join (select fd1,count(fd2) as cnt2 from #tb group by fd1,fd2)t2 on t0.fd1=t2.fd1
left join (select fd1,count(fd3) as cnt3 from #tb group by fd1,fd3)t3 on t0.fd1=t3.fd1