Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. customer(cid,city,name,state)
  2. orders(cid,oid,date)
  3. product(pid,price,productname)
  4. lineitem(lid,pid,oid,totalquantity,totalprice)
  5.  
  6. Oid Pid
  7. 2400 1
  8. 2400 2
  9. 2401 3
  10. 2401 1
  11. 2402 1
  12. 2403 1
  13. 2403 3
  14.  
  15. select t.oid,l.pid
  16. from lineitem l
  17. join (select o.oid,c1.cid
  18. from orders o
  19. join (select c.cid
  20. from customer c
  21. where c.city='X') c1
  22. where o.cid=c1.cid) t on l.oid=t.oid
  23.  
  24. select pid, count(*)
  25. from (select t.oid, l.pid
  26. from lineitem l
  27. join (select o.oid, c1.cid
  28. from orders o
  29. join (select c.cid from customer c where c.city = 'X') c1
  30. where o.cid = c1.cid) t
  31. on l.oid = t.oid) x
  32. group by pid
  33. having count(*) = (select count(*)
  34. from (select distinct oid
  35. from lineitem l
  36. join (select o.oid, c1.cid
  37. from orders o
  38. join (select c.cid
  39. from customer c
  40. where c.city = 'X') c1
  41. where o.cid = c1.cid) t
  42. on l.oid = t.oid) y) z
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement