当前位置: 代码迷 >> Sql Server >> 一个 insert 插入 多表关联数据 小疑点,搞了3个小时了
  详细解决方案

一个 insert 插入 多表关联数据 小疑点,搞了3个小时了

热度:430   发布时间:2016-04-27 21:35:57.0
一个 insert 插入 多表关联数据 小问题,搞了3个小时了
A表:

goodsid                 code
1                             100001
2                             100003
3                             100002

B表:
code                         pty
100001                     5
100002                     13
100003                     10

现想在C表中插入数据:
C表:

goodsid                   pty
1                                 5
2                                 10
3                                 13


    俺搜索了   一些贴子,都是两表相关联,没有三表相关联的


    实在搞不明白了


    可否指点一下?

------解决方案--------------------
insert into c(goodsid,pty) select a.goodsid,b.pty from a,b where a.code=b.code;
  相关解决方案