日期:2014-05-18 浏览次数:20712 次
select 姓名 , count(*) 总数 from tb group by 姓名
------解决方案--------------------
create table tb(姓名 varchar(10))
insert into tb values('张三')
insert into tb values('张三')
insert into tb values('张三')
insert into tb values('李四')
insert into tb values('李四')
GO
select 姓名 , count(*) 总数 from tb group by 姓名
drop table tb
/*
姓名 总数
---------- -----------
李四 2
张三 3
(所影响的行数为 2 行)
*/
------解决方案--------------------
create table tb(姓名 varchar(10))
insert into tb values('张三')
insert into tb values('张三')
insert into tb values('张三')
insert into tb values('李四')
insert into tb values('李四')
GO
select distinct 姓名 , (select count(*) from tb where 姓名=a.姓名) 总数 from tb a
drop table tb
------解决方案--------------------
上面都对的 帮顶
------解决方案--------------------
create table tb(username varchar(10))
insert into tb values('张三')
insert into tb values('张三')
insert into tb values('张三')
insert into tb values('李四')
insert into tb values('李四')
GO
select username,count(*) 总数 from tb group by username