有人可以解释我这个。我的SQL:SQL调试 - 忽略条件
SELECT
`offers`.`id`,
`offers`.`max_available`,
(SELECT COUNT(coupons.id) FROM coupons WHERE coupons.status = 'Y' AND coupons.offer_id = offers.id) AS coupons_sold
FROM
`offers`
WHERE
`offers`.`status` IN ('P', 'S') AND
`offers`.`published_at` < 1341612000 AND
`offers`.`end_at` >1341567914 AND
`coupons_sold` < `offers`.`max_available`
ORDER BY `offers`.`created_at` DESC
LIMIT 4 OFFSET 0
这将返回我这4行:
id max_available coupons_sold
195 19 20
194 9999 0
193 9999 0
159 9999 93
怎么可能与ID 195
行被包括在内,如果我有在coupons_sold < offers.max_available
这种状况呢?我无能为力!
简化测试的情况下抛出'未知列“coupons_sold”中“,其中clause'' http://sqlfiddle.com/#!2/a1b71/2确定没有别的'coupons_sold'的名字呢? – biziclop 2012-07-06 10:22:36
使用别名时出错,不能在where子句中使用http://dev.mysql.com/doc/refman/5.6/en/problems-with-alias.html – Yaroslav 2012-07-06 10:32:19