Savelyev_Vyacheslav

15 dz

Apr 18th, 2022 (edited)
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.14 KB | None | 0 0
  1. ######## 1
  2. SELECT orderNumber, productCode, quantityOrdered*priceEach AS total
  3. FROM orderdetails
  4. ORDER BY total DESC
  5. LIMIT 10
  6.  
  7. ########## 2
  8. SELECT orderNumber, SUM(priceEach*quantityOrdered) AS total
  9. FROM orderdetails
  10. GROUP BY orderNumber
  11. HAVING total  > 10000
  12. ORDER BY total DESC
  13. LIMIT 10
  14.  
  15. ###### 3
  16. SELECT orderdetails.orderNumber, orderDate, STATUS, SUM(quantityOrdered*priceEach) AS total
  17. FROM orderdetails
  18. INNER JOIN orders
  19. ON orderdetails.orderNumber = orders.orderNumber
  20. GROUP BY orderdetails.orderNumber
  21. HAVING total > 59000
  22.  
  23. #############4
  24. SELECT  
  25. customers.contactFirstName, customers.contactLastName , customers.country, t2.customerNumber,
  26. t2.orderNumber,t2.orderDate, t2.STATUS, t2.total
  27. FROM
  28. #######################################################t2
  29. (
  30. SELECT orderdetails.orderNumber, orders.orderDate, orders.STATUS, SUM(orderdetails.priceEach*orderdetails.quantityOrdered) AS total, orders.customerNumber
  31. FROM orderdetails
  32. INNER JOIN orders
  33. ON orderdetails.orderNumber = orders.orderNumber
  34. GROUP BY orderNumber
  35. HAVING total  > 59000
  36. ORDER BY total DESC
  37. )
  38. t2
  39. #######################################################t2
  40. INNER JOIN customers
  41. ON t2.customerNumber = customers.customerNumber
  42.  
  43. ##########5
  44. SELECT  products.productName, MAX(orderdetails.priceEach*orderdetails.quantityOrdered) AS total
  45. FROM orderdetails
  46. INNER JOIN products
  47. ON orderdetails.productCode = products.productCode
  48. GROUP BY orderdetails.productCode
  49. ORDER BY total DESC
  50. LIMIT 10
  51.  
  52.  
  53. #############6
  54. SELECT  employees.firstName, employees.lastName, customers.contactFirstName , customers.contactLastName
  55. FROM employees
  56. CROSS JOIN customers
  57. WHERE employees.employeeNumber =  customers.salesRepEmployeeNumber
  58.  
  59.  
  60. #############7
  61. SELECT employees.lastName, employees.firstName, t2.jobTitle,  t2.subFirstName, t2.sublastName
  62. FROM employees
  63. CROSS JOIN (SELECT t1.reportsTo, t1.employeeNumber,  t1.jobTitle , employees.firstName AS subFirstName, employees.lastName AS sublastName
  64. FROM (SELECT * FROM employees) t1  
  65. LEFT JOIN  employees
  66. ON t1.reportsTo = employees.employeeNumber) t2
  67. WHERE t2.employeeNumber   =   employees.employeeNumber;
  68.  
  69.  
  70.  
Add Comment
Please, Sign In to add comment