数据等于2个不同值的sql

anauzrmj  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(310)

我有以下疑问:

SELECT b.id, b.created_at, b.updated_at, b.reservation_code, b.reservation_type, b.reservation_date,
                   b.reservation_time, b.party_size, b.customer_code, b.deposit_total,
                   b.payment_code, b.voucher_code, b.reservation_processed, b.payment_status,
                   b.receipt_mailed, b.reservation_status, b.special_requirements, b.email_csv, b.occasion_type, p.name, p.slug
            FROM bookings b
            JOIN premises p ON p.code = b.premises_code WHERE b.premises_code = ? AND b.reservation_processed != 'no-show' OR b.reservation_processed != 'removed'

我要返回除“no show”或“removed”之外的任何保留的行
现在它仍然返回“删除”的行
我直接在sql中运行了命令,遇到了同样的问题:(

kiayqfof

kiayqfof1#

使用 NOT IN :

WHERE b.premises_code = ? AND
      b.reservation_processed NOT IN ('no-show', 'removed')

你似乎不熟悉布尔逻辑的规则。您的逻辑被解释为:

WHERE (b.premises_code = ? AND b.reservation_processed <> 'no-show') OR 
      (b.reservation_processed <> 'removed')

但你真的打算:

WHERE b.premises_code = ? AND
      b.reservation_processed <> 'no-show' AND
      b.reservation_processed <> 'removed'

相关问题