Mysql - 选择多个具有相同值且其他列为零的列 [英] Mysql - select multiple columns with same value and other colums equal to zero

查看:37
本文介绍了Mysql - 选择多个具有相同值且其他列为零的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 mysql 查询,它选择 col1 和 col2 = 4 和 col3 或 col4 = 0 的记录

I have a mysql query that selects the records where col1 and col2 = 4 and col3 or col4 = 0

SELECT * FROM table WHERE 4 IN(col1, col2) && (col3 = 0 || col4 = 0)

或 不起作用.它返回零行,我知道有 4

The or is not working. It returns zero rows and I know that there are 4

推荐答案

&&和 ||在 SQL 中是 AND 和 OR.

&& and || in SQL are AND and OR.

将其重写为:

SELECT * FROM table WHERE (col1 = 4 AND col2 = 4) AND (col3 = 0 OR col4 = 0)

不能将 IN 用于列名.您可以像这样使用 IN:WHERE col3 IN('4','a','another valid value'),这等于 WHERE (col3 = '4' OR col3 = 'a' OR ...)

You can't use IN for column names. You can use IN like this: WHERE col3 IN('4','a','another valid value'), which is equals to WHERE (col3 = '4' OR col3 = 'a' OR ...)

这篇关于Mysql - 选择多个具有相同值且其他列为零的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆