如何获取具有最多且同名的记录?
如何获取具有最多且同名的记录? 问题点数:20、回复次数:8Top
1 楼wgsasd311(自强不息)回复于 2006-03-03 11:58:28 得分 20
select top 1 col,count(1) from tb a
group by col order by count(1) descTop
2 楼wgsasd311(自强不息)回复于 2006-03-03 12:00:47 得分 0
select col,cnt=count(1) into # from tb a
group by col
select * from # a
where not exists(select 1 from # where cnt>a.cnt)
drop table #Top
3 楼pgyssg(breeze)回复于 2006-03-03 12:57:22 得分 0
大哥你上面写的我看不明白啊.能给点文字说明吗?Top
4 楼fengyaner(风颜儿)回复于 2006-03-03 13:17:06 得分 0
select top 1 x from tb group by x desc having count(x)>0Top
5 楼wgsasd311(自强不息)回复于 2006-03-03 14:41:21 得分 0
create table tb(col1 int,col2 int)
insert into tb
select 2,3 union all
select 2,13 union all
select 2,23 union all
select 1,3 union all
select 1,13 union all
select 1,23 union all
select 1,33 union all
select 1,35 union all
select 3,3 union all
select 3,13 union all
select 3,23 union all
select 3,33
go
select top 1 col1,count(1) from tb group by col1 order by count(*) desc
drop table tbTop
6 楼wgsasd311(自强不息)回复于 2006-03-03 14:42:39 得分 0
create table tb(col1 int,col2 int)
insert into tb
select 2,3 union all
select 2,13 union all
select 2,23 union all
select 1,3 union all
select 1,13 union all
select 1,23 union all
select 1,33 union all
select 1,35 union all
select 3,3 union all
select 3,13 union all
select 3,23 union all
select 3,33
go
select col1,cnt=count(1) into # from tb a
group by col1
select * from # a
where not exists(select 1 from # where cnt>a.cnt)
drop table #,tbTop
7 楼pgyssg(breeze)回复于 2006-03-03 15:39:14 得分 0
谢谢wgsasd311Top
8 楼pgyssg(breeze)回复于 2006-03-03 15:40:19 得分 0
感谢wgsasd311Top




