Guest User

Untitled

a guest
Jun 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. SELECT DISTINCT vendors.name AS vendor, rewards.offer AS reward, promotions.price AS points, promotions.discount_price AS discount_points, promotions.discount_start_date AS
  2. discount_start_date, promotions.discount_end_date AS discount_end_date, promotions.id AS id, vendors.id AS vendor_id, rewards.id AS reward_id, clients.id AS client_id, clients.name AS
  3. client, clients.id AS client_id, zipcodes.zipcode AS zipcode, concat(vendors.id, "-", rewards.id) AS unique_key
  4. FROM promotions
  5. INNER JOIN vendors ON promotions.vendor_id = vendors.id
  6. INNER JOIN rewards ON promotions.reward_id = rewards.id
  7. INNER JOIN rewards_vendor_types_jn AS rewards_categories ON rewards.id = rewards_categories.reward_id
  8. INNER JOIN vendor_types AS categories ON rewards_categories.vendor_type_id = categories.id
  9. LEFT OUTER JOIN clients_promotions ON promotions.id = clients_promotions.promotion_id
  10. LEFT OUTER JOIN clients ON clients_promotions.client_id = clients.id
  11. LEFT OUTER JOIN geo_marketings AS marketings ON (promotions.id = marketings.marketable_id AND marketings.marketable_type = 'Promotion')
  12. LEFT OUTER JOIN geo_market_zipcodes AS zipcodes ON marketings.market_id = zipcodes.market_id
  13.  
  14.  
  15. WHERE vendors.status_id = 1
  16. AND promotions.start_date IS NOT NULL
  17. AND promotions.start_date <= CURDATE()
  18. AND ( ( (rewards.quantity > 0 OR rewards.unlimited = 1) AND (promotions.end_date IS NULL OR promotions.end_date > CURDATE()) ) OR promotions.display_out_of_stock = 1)
  19. AND (categories.visible = 1 OR (categories.name = 'Landing' OR categories.name = 'Points Alert' OR categories.name = 'We Suggest' OR categories.name = 'Widget'))
  20. AND promotions.activation_bonus_reward = false
  21. AND ((zipcodes.zipcode = '48306') OR (clients.id = 2627 OR clients.id = 2629 OR clients.id = 2501))
  22.  
  23. GROUP BY unique_key
  24. ORDER BY UPPER(vendors.name) ASC, UPPER(promotions.price) ASC, UPPER(rewards.offer) ASC, UPPER(clients.name) ASC
Add Comment
Please, Sign In to add comment