这个sql语句该怎么写?

qinamao 2003-02-19 02:50:54
将a表中的字段 a2,a3 及起内容 组建一个新表 c
用一句话表示
...全文
58 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
cym7808 2003-02-19
  • 打赏
  • 举报
回复
select distinct
(select count(*) from a where a2='A') as a2n,
(select count(*) from a where a3='B') as a3n
into c from a
qinamao 2003-02-19
  • 打赏
  • 举报
回复
谢谢,接分!
cym7808 2003-02-19
  • 打赏
  • 举报
回复
无法用一条语句表达,因为条件不唯一,可以使用临时表然后UPDATE
alexwoowf 2003-02-19
  • 打赏
  • 举报
回复
select sum(case when a2='A' then 1 else o end ) as a2n,sum(case when a3='B' then 1 else 0 end)as a3n into tab_c from tab_a
Rewiah 2003-02-19
  • 打赏
  • 举报
回复
select sum(case when a2='A' then 1 else 0 end) as a2n,
sum(case when a3='B' then 1 else 0 end) as a3n
into c from a

or:
select
(select count(*) from a where a2='A') as a2n,
(select count(*) from a where a3='b') as a3n
into c from a
qinamao 2003-02-19
  • 打赏
  • 举报
回复
楼上的明显在乱写,
难道没人能写出来吗?
jerryvicky 2003-02-19
  • 打赏
  • 举报
回复
select a2 'a2n',a3 'a3n' into c from a
qinamao 2003-02-19
  • 打赏
  • 举报
回复
现在我要将表a中的a2='A' 的记录总数和a3='B' 的记录总数分别以字段名a2n、a3n存到新表c中。同样表c原来不存在!咋办?
pengdali 2003-02-19
  • 打赏
  • 举报
回复
select a2,a3 into c from a
xiaocong1980 2003-02-19
  • 打赏
  • 举报
回复
表c存在
insert into c select * from a
表c不存在
select * into c from a
weitao999 2003-02-19
  • 打赏
  • 举报
回复
insert into c select a2,a3 from a
cym7808 2003-02-19
  • 打赏
  • 举报
回复
select a2,a3 into c from a
qinamao 2003-02-19
  • 打赏
  • 举报
回复
注意:
1、c 原来并不存在
2、a 中除“a2”“a3”外,还有其他字段

?
Rewiah 2003-02-19
  • 打赏
  • 举报
回复
select * into c from a

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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