求一sql语句

wuenming 2004-09-29 06:11:15
数据表:
table1
id typ name
1 1 ww
2 1 ss
3 1 tt
4 2 rr
5 2 dd
6 3 hh

要求:
得到不同typ的纪录数量,即查询出的
结果为:
1 3

2 2

3 1
...全文
68 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andy__Huang 2004-09-29
  • 打赏
  • 举报
回复
不小心﹐上面稿錯了

create table tb (id int,typ numeric(10),name varchar(10))
Insert into tb
select '1','1','ww'
union all select '2','1','ss'
union all select '3','1','tt'
union all select '4','2','rr'
union all select '5','2','dd'
union all select '6','3','hh'

--刪除表
drop table tb
drop table tt

select id=identity(int,1,1),纪录数量=count(*) into tt from tb group by typ
select * from tt
--結果
id 纪录数量
-----------------------
1 3
2 2
3 1
Andy__Huang 2004-09-29
  • 打赏
  • 举报
回复

create table tb (id int,typ numeric(10),name varchar(10))
Insert into tb
select '1','1','ww'
union all select '2','1','ss'
union all select '3','1','tt'
union all select '4','2','rr'
union all select '5','2','dd'
union all select '6','3','hh'

--刪除表
drop table tb

select id=sum(1),纪录数量=count(*) from tb group by typ
--結果
id 纪录数量
-----------------------
3 3
2 2
1 1
btlxy 2004-09-29
  • 打赏
  • 举报
回复
up
mjhnet 2004-09-29
  • 打赏
  • 举报
回复
select typ,count(*) from table1

group by typ

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧