zippo1986 2017-07-20 10:34 采纳率: 0%
浏览 1381

sql根据字段两表怎么匹配修改

表A字段:
类型、一月、二月。。。。十二月
交通费、100、200。。。。1200
电话费、100、200.。。。。1200
表B字段:
月份、类型、金额
1 、交通费、500
2 、电话费、500
最终数据库更改表A字段相同月份下类型相同的金额

  • 写回答

3条回答 默认 最新

  • 张大教主 2017-07-21 02:34
    关注
    //由于你的十个二月份的数据不是放在一列中,单独分了十二列,所以没办法统一更新,只能每列写一个更新语句;
    update A set A.一月=B.金额  from A,B where A.月份=1 and A.类型=B.类型;
    update A set A.二月=B.金额  from A,B where A.月份=2 and A.类型=B.类型;
    update A set A.三月=B.金额  from A,B where A.月份=3 and A.类型=B.类型;
    update A set A.四月=B.金额  from A,B where A.月份=4 and A.类型=B.类型;
    update A set A.五月=B.金额  from A,B where A.月份=5 and A.类型=B.类型;
    update A set A.六月=B.金额  from A,B where A.月份=6  and A.类型=B.类型;
    update A set A.七月=B.金额  from A,B where A.月份=7 and A.类型=B.类型;
    update A set A.八月=B.金额  from A,B where A.月份=8 and A.类型=B.类型;
    update A set A.九月=B.金额  from A,B where A.月份=9 and A.类型=B.类型;
    update A set A.十月=B.金额  from A,B where A.月份=10 and A.类型=B.类型;
    update A set A.十一月=B.金额  from A,B where A.月份=11 and A.类型=B.类型;
    update A set A.十二月=B.金额  from A,B where A.月份=12 and A.类型=B.类型;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题