select b,count(1)as c from 表 group by b
解决方案 »
- SQL面试题 请将上列数据转化成下面的数据,注意每5条一分组,最后一组不够5返回空行,请写书sql语句
- 你好,可以把你的数据库文档工具贡献一个吗?
- 多表查询问题?
- MONTH('2006-02-02')如何返回"02"
- 单MDF文件恢复问题sqlserver2005
- 一个SQL语句的问题,恳请各位帮忙看看!
- 无法为数据库 'tempdb' 中的对象分配空间,因为'PRIMARY' 件组已满
- 我在SQL SERVER创建作业时出现下面错误提示
- 求一分年季月分组存储过程(语句)???
- sqlserver2000,怎样定义常量使每个stored procedure都能引用这些常量。
- 日期形式的字段的check,怎么写?
- 在MSSQL中如何通过SQL语句访问Oracle DB?
from 表
group by b
having count(*)>1
having count(*) > 12: select top 1 * from
(select b,count(*) as c from 表 group by b
having count(*) > 1
) tmp order by c
create table 表(a int,b int)
insert 表 select 1,3
union all select 2,3
union all select 3,4
union all select 4,4
union all select 5,4
union all select 6,5
union all select 7,5
union all select 8,3
union all select 9,3
go--查询
select B,C=count(*)
from 表
group by b
having count(*)>1
go--删除测试
drop table 表/*--测试结果
B C
----------- -----------
3 4
4 3
5 2(所影响的行数为 3 行)
--*/
select b,convert(varchar,count(b))+'次' as c from table1 group by b having count(b)>1
2.
select top 1 * from (select b,count(b)as c from table1 group by b having count(b)>1 order by count(b))