Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT DISTINCT cb.phone
  2. FROM bonus_account ba
  3. INNER JOIN client_buyer cb
  4. ON ba.id = cb.bonus_account_id
  5. INNER JOIN purchase p
  6. ON p.bonus_account_id = ba.id
  7. WHERE
  8.   p.organization_id = :organization_id
  9.   AND p.is_purchase = TRUE
  10.   AND p.status = 2 /* STATUS_APPROVED */
  11.   AND TO_CHAR(p.DATE, 'YYYY-MM') = :date
  12.   AND ba.organization_id = :organization_id
  13.   AND ba.registration_sale_point_id = :registration_sale_point_id
  14.   AND cb.organization_id = :organization_id
  15.   AND NOT cb.deleted
  16.  
  17. EXCEPT (
  18.     SELECT DISTINCT cb.phone
  19.     FROM bonus_account ba
  20.     INNER JOIN client_buyer cb
  21.     ON ba.id = cb.bonus_account_id
  22.     INNER JOIN purchase p
  23.     ON p.bonus_account_id = ba.id
  24.     WHERE
  25.       p.organization_id = :organization_id
  26.       AND p.sale_point_id = :registration_sale_point_id
  27.       AND p.is_purchase = TRUE
  28.       AND p.status = 2 /* STATUS_APPROVED */
  29.       AND TO_CHAR(p.DATE, 'YYYY-MM') = :date
  30.       AND ba.organization_id = :organization_id
  31.       AND ba.registration_sale_point_id = :registration_sale_point_id
  32.       AND cb.organization_id = :organization_id
  33.       AND NOT cb.deleted
  34. ) ORDER BY phone;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement