Advertisement
alexarcan

lab4_dbd(NOT DONE)

Oct 24th, 2016
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. --a. Show all the products possessing a certain property (along with the
  2. --corresponding categories). The property selection criteria remains
  3. --at your own choice.
  4.  
  5. SELECT prod.ProductName, categ.categoryname, prop.propertyname, prop.propertyvalue
  6. FROM Products prod, Categories categ, Properties prop, bindproductsproperties bind
  7. WHERE categ.categoryid = prod.categoryid
  8. AND bind.productid = prod.productid
  9. AND bind.propertyid = prop.propertyid
  10. AND prop.propertyvalue = 'Black';
  11.  
  12.  
  13. --b. Display a top containing all clients - based on the number of products ordered.
  14.  
  15. SELECT c.clientid, c.clientname, sum(crt.quantity) as nbOfProducts
  16. FROM clients c, ordereditems crt, orders ord
  17. WHERE c.clientid = ord.clientid
  18. AND ord.orderId = crt.orderID
  19. GROUP BY c.clientid,c.clientname
  20. ORDER BY nbOfProducts DESC;
  21.  
  22. --c. Display a top containing all clients - based on the number of categories
  23. --that the ordered products belong to.
  24.  
  25. SELECT c.clientid, c.clientname, count(distinct ct.categoryid) as nbOfCategories
  26. FROM clients c, ordereditems crt, orders ord, categories ct, products prod
  27. WHERE c.clientid = ord.clientid
  28. AND ord.orderId = crt.orderID
  29. AND crt.productid=prod.productid
  30. AND prod.categoryid = ct.categoryid
  31. GROUP BY c.clientid,c.clientname
  32. ORDER BY nbOfCategories DESC;
  33.  
  34. --d. Display a top containing all clients - based on the overall value
  35. --of the ordered products.
  36. SELECT c.CLIENTID, c.CLIENTNAME, SUM(pr.PRICE*crt.QUANTITY) as overallValue
  37. FROM clients c, ordereditems crt, orders ord, prices pr, products prod
  38. WHERE c.clientid = ord.clientid
  39. AND ord.orderId=crt.orderID
  40. AND crt.productid=prod.productid
  41. AND prod.PRODUCTID=pr.PRODUCTID
  42. GROUP BY c.clientid, c.clientname
  43. ORDER BY overallValue DESC;
  44.  
  45. -- e. Show a list of categories containing at least 3 other categories / products
  46. SELECT ct.CATEGORYID, ct.CATEGORYNAME, count(prod.productId) as productnb
  47. FROM categories ct, products prod
  48. WHERE prod.CATEGORYID = ct.CATEGORYID
  49. GROUP BY ct.CATEGORYID, ct.CATEGORYNAME
  50. having count(prod.productId)>=3
  51. UNION
  52. SELECT ct.CATEGORYID, ct.CATEGORYNAME, count(oct.otherCatId) as categNb
  53. FROM categories ct, categories oct
  54. WHERE ct.CATEGORYID = oct.OTHERCATID
  55. GROUP BY ct.CATEGORYID, ct.CATEGORYNAME
  56. having count(oct.OTHERCATID)>=3;
  57.  
  58. -- f. Show a category (or subcat) containing similary named products:
  59. -- (Cat Name 1, Cat Name 2, Product Name)
  60. SELECT DISTINCT ct1.categoryname, ct2.categoryname, prod1.productname
  61. FROM categories ct1, categories ct2, products prod1, products prod2
  62. WHERE ct1.categoryid = prod1.categoryid AND ct2.categoryid = prod2.categoryid
  63. AND ct1.categoryname!=ct2.categoryname
  64. AND prod1.productname = prod2.productname ;
  65.  
  66. --g. Show the total product price (sum) corresponding to the 3 "most recent" orders.
  67.  
  68. CREATE VIEW MOSTRECENTORDERS AS
  69. SELECT ord.requestdate, ord.orderid
  70. FROM orders ord
  71. WHERE ROWNUM <= 3
  72. ORDER BY ord.req;
  73.  
  74. SELECT SUM(price.price) AS TOTAL_PRICE
  75. FROM prices price, mostrecentorders mostrec, orders ord
  76. WHERE ord.orderid=mostrec.orderid
  77.  
  78.  
  79. CREATE VIEW ULTIMELE_COMENZI(data_com, comanda_id) as
  80. SELECT data_com, comanda_id
  81. FROM comenzi
  82. WHERE ROWNUM <= 3
  83. ORDER BY data_com DESC;
  84.  
  85. SELECT SUM(prod.pret) AS pret_total
  86. FROM produs prod, ULTIMELE_COMENZI comenzi, produsecomanda prodcom
  87. WHERE prodcom.com_id = comenzi.comanda_id
  88. AND prodcom.prod_id = prod.prod_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement