Mysql if语句如果一列不为空,则比较另外两列

时间:2011-10-26 01:53:30

标签: mysql if-statement

我在mysql中使用If语句遇到了一些麻烦 - 我对此很陌生。

SELECT c.* FROM cca_coupons c
JOIN cca_owners o ON o.id = c.owner_id
WHERE o.id='1'
  AND IF c.max_redemptions != '0' THEN c.amount_generated >= c.max_redemptions

我似乎无法正常工作 - 我希望SELECT c.* c.amount_generated >= c.max_redemptions只有在c.max_redemption s不等于'0'的情况下才会WHERE active='0' OR expiration_date > now()

我还想在此查询中包含其他条件,包括:{{1}}

1 个答案:

答案 0 :(得分:1)

SELECT c.*
FROM cca_coupons c
JOIN cca_owners o ON o.id=c.owner_id
WHERE c.amount_generated >= c.max_redemptions
AND c.max_redemptions <> '0'

'max_redemptions'是数字还是字符串?