Guest User

Untitled

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