dsafew1231 2016-11-24 00:58
浏览 49

仅当两个字段一次为空时,Mysql更新字段

I re-written the complete question because I was not clear enough the first time.

I am trying to update a given row id in users table and fill only values that are null, like this:

UPDATE USERS SET
address='Main Street' IF current address IS NULL
gender='M' AND full_name='JOHN SMITH' IF both gender and full_name ARE NULL
job='Mechanic' IF current job is NULL
WHERE id=123

I don't know how to do the part with updateing both gender and full_name, I want the other fields to still trigger and update individually regardless of the gender and full_name values

  • 写回答

2条回答 默认 最新

  • doutan5337 2016-11-24 01:01
    关注

    The if in update statement in SQL gets into the WHERE part of the query:

    UPDATE table_name SET gender = $gender WHERE gender IS NULL AND full_name IS NULL
    

    I would add also AND id = $id_you_want_to_update

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line