我想使用此查询
SELECT `d`.*,COUNT(*) as `used`,`o`.`id`
FROM rs_discount_code as `d`
LEFT JOIN rs_order as `o` ON `d`.`code` = `o`.`voucher_code`
WHERE `d`.`active` = 'yes'
AND `d`.`date_to` >= '2015-11-03 15:27:57'
AND (`o`.`id` IS NULL)
OR (`o`.`id` IS NOT NULL AND `used` < `d`.`use_count`)
GROUP BY `d`.`id`
MYSQL结果是
Unknown column 'used' in 'where clause'
任何建议如何解决?