Each row of data in my table has about 8 elements. I want to check to see if any of the elements = NULL in a certain row, something like this:

我表中的每行数据大约有8个元素。我想检查某行中是否有任何元素= NULL,如下所示:

UPDATE item_list SET is_tradable='no' WHERE item_name=:itemname AND element_1 = NULL OR element_2 = NULL or element_3... etc.

Can I do the same thing but check if any of them are NULL without going through each item? Like:

我可以做同样的事情,但检查其中任何一个是否为NULL而不通过每个项目?喜欢:

UPDATE item_list SET is_tradable='no' WHERE item_name=:itemname AND anyElement = NULL;

2 个解决方案

#1


No, you cannot do what you want. You need to list all the columns out.

不,你不能做你想做的事。您需要列出所有列。

However, your query will not do this. You need to use IS NULL rather than = NULL:

但是,您的查询不会这样做。您需要使用IS NULL而不是= NULL:

UPDATE item_list
    SET is_tradable = 'no'
    WHERE item_name = :itemname AND
          (element_1 IS NULL OR element_2 IS NULL or element_3... etc.)

Also, remember the parentheses when mixing AND and OR.

另外,请记住混合AND和OR时的括号。

There are ways to "simplify" the calculation. For instance, concat() will return NULL if any argument is NULL:

有一些方法可以“简化”计算。例如,如果任何参数为NULL,则concat()将返回NULL:

UPDATE item_list
    SET is_tradable = 'no'
    WHERE item_name = :itemname AND
          concat(element_1, element_2, . . . ) IS NULL 

As do the arithmetic operators (but your question does not state the type of the arguments).

和算术运算符一样(但你的问题没有陈述参数的类型)。

更多相关文章

  1. MyBatis排序时使用order by 动态参数时需要注意,用$而不是# 用$传
  2. 解析innodb status各项参数
  3. 使用jQuery排序,删除和追加元素在IE中不起作用
  4. 关于如何更好的监听元素属性的变化(转)
  5. javascript判断数组和对象中是否存在某元素
  6. 获取下一个DOM元素的ID
  7. 如何将对象作为参数传播给函数?
  8. 如何在javascript函数中将URL编码为参数?
  9. 根据循环中的i改变函数中的参数

随机推荐

  1. android 结合源码深入剖析AsyncTask机制
  2. 播放器适配经验总结――Android
  3. 饺子播放器、IjkVideoView播放器的简单使
  4. Android(安卓)-- PullToRefresh应用
  5. Android六大优势
  6. Android流媒体
  7. Android布局优化之TextView、ImageView合
  8. Android中native进程内存泄露的调试技巧
  9. 别再问我Android前景如何
  10. android 中一个工程引用另一个工程