请高手忙帮一个SQL批量更新的问题。

b249833177 2010-12-08 10:16:56
两张表:
第一张表配置表
usprizedeploy

id(奖品的id) prize_item(奖品名称) prize_worth(奖品价值)
1 儿童车 200元
2 飞鹤奶粉 30元

第二张表是记录表
id prizeid(奖品id) prize_worth(奖品价值)...
1 2 0
2 1 0
3 1 0
4 1 0
5 2 0

记录表中prize_worth字段是后来加的,
请问如何批量的将记录表中的奖品价值更新成与配置表里边对应的奖品价值。
谢谢。
...全文
108 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
b249833177 2010-12-08
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wufeng4552 的回复:]
引用 2 楼 b249833177 的回复:
引用 1 楼 wufeng4552 的回复:
SQL code
update t2 set t2.prize_worth=t1.prize_worth
from 配置表 t1 ,记录表 t2
where t1.prizeid=t2.prizeid

你好,如果我不加奖品价格这个字段的话,想对记录表里边的奖品价值做一个统计,请问怎么做呢?
……
[/Quote]

不好意思,可能是我描述的不太准确。
我的意思是,如果记录表中没有 prize_worth这个字段,
我想求总共的抽奖金额该怎么写SQL语句呢?
就是把记录表里边的所有奖项的价值加起来的值。
水族杰纶 2010-12-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 b249833177 的回复:]
引用 1 楼 wufeng4552 的回复:
SQL code
update t2 set t2.prize_worth=t1.prize_worth
from 配置表 t1 ,记录表 t2
where t1.prizeid=t2.prizeid

你好,如果我不加奖品价格这个字段的话,想对记录表里边的奖品价值做一个统计,请问怎么做呢?
[/Quote]
update t2 set t2.prize_worth=t1.prize_worth
from 配置表 t1 ,(select prizeid,
sum(prize_worth)prize_worth
from 记录表
group by prizeid) t2
where t1.prizeid=t2.prizeid
b249833177 2010-12-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wufeng4552 的回复:]
SQL code
update t2 set t2.prize_worth=t1.prize_worth
from 配置表 t1 ,记录表 t2
where t1.prizeid=t2.prizeid
[/Quote]
你好,如果我不加奖品价格这个字段的话,想对记录表里边的奖品价值做一个统计,请问怎么做呢?
水族杰纶 2010-12-08
  • 打赏
  • 举报
回复
update t2 set t2.prize_worth=t1.prize_worth
from 配置表 t1 ,记录表 t2
where t1.prizeid=t2.prizeid

27,579

社区成员

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

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