我想检查一个值是否与另一个值匹配,但仅在该值不为零时才检查。前两个例子将在where语句中考虑,但不在第三个例子中考虑。我试图看看if语句是否有效,但我不知道从哪里开始。
SELECT `books`.* FROM `books`
LEFT JOIN issues ON issues.id = books.issue_id
LEFT JOIN titles ON titles.id = issues.title_id
LEFT JOIN lists ON books.id = lists.book_id
WHERE ( lists.customer_id = '900001'
AND lists.volume = issues.volume AND `books`.`status_id` = '3'
AND `books`.`deleted` = "0" )
GROUP BY `books`.`id`
以下是mysql查询的示例:
{{1}}
因此,如果lists.volume = 0,我不希望在where语句中检查它。
答案 0 :(得分:0)
select column1, column2, if (column1 = column2, 'match', 'not matched') matched
from x
where column1 <> 0 and column2 <> 0