如何在mysql中实现这个结果
我有这张桌子如何在mysql中实现这个结果,mysql,sql,string,where-clause,Mysql,Sql,String,Where Clause,我有这张桌子 transaction_id payment_type status_code 1 CASH NULL 2 DEBIT 200 3 DEBIT 201 我想用这个条件选择上面的数据 付款类型=现金 如果付款类型非现金,则选择状态为的数据=200 所以结果是 transaction_id payment_t
transaction_id payment_type status_code
1 CASH NULL
2 DEBIT 200
3 DEBIT 201
我想用这个条件选择上面的数据
=现金付款类型
- 如果
非现金,则选择状态为的数据=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) )
通过这个查询,我得到了这个错误
您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,了解第2行“现金”和状态(代码=200)限制0,25'附近使用的正确语法
我怎样才能修好它?提前感谢这是您的
where
条款:
where payment_type = 'cash' or (payment_type IS NOT 'cash' and status_code = 200)
运算符IS[NOT]NULL
中支持IS
,但不支持againts文本值。您希望使用不等式运算符:
where payment_type = 'cash' or (payment_type <> 'cash' and status_code = 200)
transaction
是一个MySQL关键字,不要将其用作表/列名。更改不是
where payment_type = 'cash' or status_code = 200