汇总数据,帮解答下

jaway 2008-03-11 10:35:26
有一个表A 字段就一个info 如下

info
A
B
A
C
ff
ss
tg
ff
saf
tgg
dd
..
..
..


我想得到 表B
info信息 出现的次数
A 2
B 1
C 1
ff 2
............

info 表的字段信息是不定的
...全文
58 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzy_love_sly 2008-03-11
  • 打赏
  • 举报
回复
create table a (info varchar(20))
insert into a select 'A'
insert into a select 'B'
insert into a select 'A'
insert into a select 'C'
insert into a select 'ff'
insert into a select 'ss'
insert into a select 'tg'
insert into a select 'ff'
insert into a select 'saf'
insert into a select 'tgg'
insert into a select 'dd'

select * into b from (
select info as 'info信息',count(1) as '出现的次数' from a group by info)tp

select * from b


info信息 出现的次数
A 2
B 1
C 1
dd 1
ff 2
saf 1
ss 1
tg 1
tgg 1
wzy_love_sly 2008-03-11
  • 打赏
  • 举报
回复
select * into 表b select info as 'info信息',count(1) as '出现的次数' from tb group by info
wzy_love_sly 2008-03-11
  • 打赏
  • 举报
回复
select info,count(1) from tb
group by info

27,579

社区成员

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

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