qq_35649402
你们让我起个名啊
采纳率42.3%
2017-09-07 01:16 阅读 1.9k

关于mysql触发器根据条件更新的问题!

3

a表:

id (key)
deviceid
devicename
brand 

b表:

 id (key)
deviceid(key)联合主键
devicename
brand 

请问如何才能做到到b表插入deviceid时,如果a.deviceid=b.deviceid则更新b.devicename and b.brand
我的写法是

BEGIN
UPDATE b SET 
devicename = new.devicename,
brand = new.brand
WHERE deviceid  = (SELECT deviceid FROM a WHERE  brand = new.brand and devicename = new.devicename and brand = new.brand );

但是这样不对,请问大神改怎么做?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • devmiao devmiao 2017-09-07 01:32
  • jiangop jiangop 2017-09-07 05:47

    WHERE deviceid = () “等号绝对出错”

    点赞 评论 复制链接分享
  • qq_35649402 你们让我起个名啊 2017-09-07 07:17

    关闭问题提高C币悬赏

    点赞 评论 复制链接分享

相关推荐