Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中实现这个结果_Mysql_Sql_String_Where Clause - Fatal编程技术网

如何在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