这个sql语句该怎么写?

qinamao 2003-02-19 03:26:57
已知表a中的有字段 a1,a2,a3,a4 及其内容
如何用一句话表示
“将表a中的a2='A' 的记录总数和a3='B' 的记录总数分别以字段名a2n、a3n存到新表c中”?

注意:
1、c 原来并不存在
2、a 中除“a2”“a3”外,还有其他字段


...全文
76 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
老马2008 2003-02-19
  • 打赏
  • 举报
回复
对于MS SQL Server,select .... into 新表,是可以创建一个表。
gangganghao 2003-02-19
  • 打赏
  • 举报
回复
select (select count(*) from a where a2='A') as a2n,(select count(*) from a where a3='B') as a3n into c
lin_x_gang 2003-02-19
  • 打赏
  • 举报
回复
select t1.a2n, t2.a3n
into C
From (
select count(*) as a2n from A where a2='A')
t1,
(select count(*) as a3n from A where a3='B'
) t2
我不知道 'into C'能不能创建一个新表 C ,请指教。
对 JYCheng(Cheng程氏) 的一点修改。
老马2008 2003-02-19
  • 打赏
  • 举报
回复
//如果是Oracle
create table c
as
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
from a;
老马2008 2003-02-19
  • 打赏
  • 举报
回复
是一个联机视图,你用的什么数据库??
muddledman 2003-02-19
  • 打赏
  • 举报
回复
看来只能用存储过程实现了!
qinamao 2003-02-19
  • 打赏
  • 举报
回复
请教 JYCheng(Cheng程氏) :

From (
select count(*) as a2n, 0 as a3n from A where a2='A'
union all
select 0 as a2n, count(*) as a3n from A where a3='B'
) temp
这是什么意思?
JYCheng 2003-02-19
  • 打赏
  • 举报
回复
select sum(a2n) as a2n, sum(a3n) as a3n
into C
From (
select count(*) as a2n, 0 as a3n from A where a2='A'
union all
select 0 as a2n, count(*) as a3n from A where a3='B'
) temp

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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