MYSQL - 不能在其中使用join和count

时间:2015-11-03 14:38:21

标签: mysql sql

我想使用此查询

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'

任何建议如何解决?

0 个答案:

没有答案