Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.45 KB | None | 0 0
  1. SELECT temp2.customer_id, it_temp2.product_id, temp2.order_date
  2. FROM SALES_ORDER temp2, ITEM it_temp2
  3. WHERE (
  4.     SELECT COUNT(temp.order_id)
  5.     FROM SALES_ORDER temp, ITEM it_temp
  6.     WHERE temp.customer_id = temp2.customer_id
  7.     AND ABS(DATEDIFF(DAY, temp.order_date, temp2.order_date)) <= 7
  8.     AND temp.order_id != temp2.order_id
  9.     AND it_temp.order_id = temp.order_id
  10.     AND it_temp.product_id = it_temp2.product_id
  11.     ) > 0
  12. AND it_temp2.order_id = temp2.order_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement