有人可以解釋我這個。我的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