帮帮我:)

darcychina 2002-09-10 01:50:00
表A 商品编号,价格
表B 销售单号,商品编号,销售价格

我现在想根据A表中的价格更新B表中的销售价格!

A : sp_id price
00001 10
00002 15
00002 16
00003 6
00003 5

B: xs_id sp_id xs_price
xs001 00002 23
xs002 00003 4
xs003 00002 22

所要结果是B: (根据A表中商品的最高价格来更新B表中相应的商品销售价格(xs_price)
xs_id sp_id xs_price
xs001 00002 16
xs002 00003 6
xs003 00002 16

SQL语句该怎么写呢?谢谢!
...全文
68 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
darcychina 2002-09-10
  • 打赏
  • 举报
回复
同志看好题目好不好!以A表更新B表呀,不是查询
newly_ignorant 2002-09-10
  • 打赏
  • 举报
回复
update b set xs_price=isnull(aa.price,xs_price)
from (select sp_id,max(price) price from a group by sp_id) aa
where b.sp_id=aa.sp_id
westbulls 2002-09-10
  • 打赏
  • 举报
回复
select b.xs_id,b.sp_id,isnull(aa.price,0.00) xs_price from b left join (select sp_id,max(price) price from a group by sp_id) aa on b.sp_id=aa.sp_id

34,873

社区成员

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

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