大家帮我看看这条SQL语句怎么写?

cmt123 2003-04-23 07:45:45
table1 结构:a1,a2,a3,Amount1,Time
table2结构:b1,b2,b3,Amount2
以字段b1,b2,b3分组统计字段Amount2 插入table1表对应的字段a1,a2,a3,Amount1.在同一行把系统时间插入Time字段.请问这条SQL语句怎么写为好!
...全文
20 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yoki 2003-04-24
  • 打赏
  • 举报
回复
insert into table1(a1,a2,a3,amount1,time)
select b1,b2,b3,sum(amount2) ,getdate()
from table2
group by b1,b2,b3
joygxd 2003-04-24
  • 打赏
  • 举报
回复
insert into table1(a1,a2,a3,amount1,time)
select b1,b2,b3,sum(amount2) ,getdate() from table2 group by b1,b2,b3
triout 2003-04-24
  • 打赏
  • 举报
回复
Insert Into Table1 (a1,a2,a3,amount1,time)
select b1,b2,b3,sum(amount2) as amount1,getdate() as time from table2 group by b1,b2,b3

如果你要不数据累加到TABLE1中则:
Update Table1 Set table1.Amount1=table1.Amount1+b.amount2,table1.time=getdate()
from (select b1,b2,b3,sum(amount2) as amount2 from table2 group by b1,b2,b3) b
where table1.a1=b.b1 ans table1.a2=b.b2 and table1.a3=b.b3
happydreamer 2003-04-23
  • 打赏
  • 举报
回复
insert table1 (a1,a2,a3,Amount1,Time)
select a1,a2,a3,sum(amount)
from table2
group by a1,a2,a3
pengdali 2003-04-23
  • 打赏
  • 举报
回复
insert table1 (a1,a2,a3,Amount1,Time) select sum(b1),sum(b2),sum(b3),Amount2,getdate() from table2 group by Amount2

34,590

社区成员

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

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