这个SQL怎么写?

ItOldHorse 2003-12-10 09:37:34
有两个表

table1

编号 价格

1 123
1 234
2 456


table2

编号 价格

1 12.3

2 34.5

如何实现用table2的价格来置换table1的价格
前提是只置换table的同编号的一条记录

执行结果为


table1

编号 价格

1 12.3
1 234
2 34.5



table1

编号 价格

1 12.3
1 123
2 34.5







...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dlpseeyou 2003-12-10
  • 打赏
  • 举报
回复
select a.编号,b.价格 from table1 a left join table2 b on a.编号=b.编号
dlpseeyou 2003-12-10
  • 打赏
  • 举报
回复
select a.编号,b.价格 from table1 a ,table2 b where a.编号 in(select min(编号) from table1 where a.编号=b.编号 group by 编号 )
dlpseeyou 2003-12-10
  • 打赏
  • 举报
回复
select a.编号,b.价格 from table1 a ,table2 b where 价格 in(select min(编号) from table1 )
txlicenhe 2003-12-10
  • 打赏
  • 举报
回复
update a set a.价格 = b.价格
from table1 a
join table2 b on a.编号 = b.编号
join (select 编号,min(价格) as 价格 from table1 group by 编号) c
on a.编号 = c.编号 and a.价格 = c.价格

34,593

社区成员

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

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