vgrabovets
11/1/2016 - 8:08 AM

promo code

promo code

SELECT
  pc.title,
  DATE(o.date)
, pc.id
, COUNT(pcd.code)
FROM
  billing.orders o
  left join megogo2.service s on s.service_id = o.service_id

  billing.promo_code pc
    inner JOIN billing.promo_code_dict pcd ON pcd.id >= pc.from_code_id
        AND pcd.id <= pc.to_code_id
        AND pcd.is_used = 1
    inner JOIN  ON o.promo_code = pcd.code

where s.type not in (1, 5)