CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  基础类

如何获取具有最多且同名的记录?

楼主pgyssg(breeze)2006-03-03 11:55:14 在 MS-SQL Server / 基础类 提问

如何获取具有最多且同名的记录? 问题点数: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

相关问题

  • 获取记录
  • 如何获取记录号
  • 关于获取新增记录的ID
  • 如何获取第2000-3000条记录
  • 如何获取上一记录的值
  • 获取记录总数的错误
  • net获取数据库记录条数
  • hibernate如何获取总记录数?
  • 怎样获取同名控件的句柄?
  • 裸求~~~~~~~~~获取几个同名控件的值

关键词

  • top
  • union allselect
  • col
  • tb
  • cnt
  • count
  • table
  • select

得分解答快速导航

  • 帖主:pgyssg
  • wgsasd311

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo