我怎样才能在 mysql 中实现这个结果
How can i achieve this result in mysql
所以我有这个table
transaction_id payment_type status_code
1 CASH NULL
2 DEBIT 200
3 DEBIT 201
我想select上面的数据符合这个条件
payment_type
= 现金
- 如果
payment_type
不是现金选择数据status_code
= 200
所以结果是
transaction_id payment_type status_code
1 CASH NULL
2 DEBIT 200
我就是这样做的
SELECT * FROM transaction_tbl where (payment_type = 'cash' or (payment_type IS NOT 'cash' and status_code = 200) )
使用那个查询我得到这个错误
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''cash' and status_code = 200) ) LIMIT 0, 25' at line 2
我该如何解决?提前致谢
这是您的 where
子句:
where payment_type = 'cash' or (payment_type IS NOT 'cash' and status_code = 200)
IS
在运算符 IS [NOT] NULL
中受支持,但不支持文字值。您需要不等式运算符:
where payment_type = 'cash' or (payment_type <> 'cash' and status_code = 200)
但是,您可以简化逻辑。这做同样的事情:
where payment_type = 'cash' or status_code = 200
所以我有这个table
transaction_id payment_type status_code
1 CASH NULL
2 DEBIT 200
3 DEBIT 201
我想select上面的数据符合这个条件
payment_type
= 现金- 如果
payment_type
不是现金选择数据status_code
= 200
所以结果是
transaction_id payment_type status_code
1 CASH NULL
2 DEBIT 200
我就是这样做的
SELECT * FROM transaction_tbl where (payment_type = 'cash' or (payment_type IS NOT 'cash' and status_code = 200) )
使用那个查询我得到这个错误
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''cash' and status_code = 200) ) LIMIT 0, 25' at line 2
我该如何解决?提前致谢
这是您的 where
子句:
where payment_type = 'cash' or (payment_type IS NOT 'cash' and status_code = 200)
IS
在运算符 IS [NOT] NULL
中受支持,但不支持文字值。您需要不等式运算符:
where payment_type = 'cash' or (payment_type <> 'cash' and status_code = 200)
但是,您可以简化逻辑。这做同样的事情:
where payment_type = 'cash' or status_code = 200