Advertisement
Teammasik

laba_1_BD

Sep 23rd, 2023 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 3.00 KB | Pets | 0 0
  1. -- когда проверяли, сказали делать с join'ами, а я делал с помощью where, как я делал делать не надо
  2. -- перепиисать тут легко
  3. --1
  4. SELECT Cooperator.Surname, Cooperator.Name, Cooperator.Bitrhday,
  5. Cooperator.Salary, Cooperator.Phone_number, Cooperator.Category,
  6. Department.Name, Evaluation.STATUS AS 'оценка'
  7.     FROM Cooperator, Department, Evaluation
  8.     WHERE Cooperator.Dept_id = Department.Dept_id AND Cooperator.Cooperator_id = Evaluation.Cooperator_id;
  9.  
  10.  
  11. --2
  12.  
  13. SELECT Surname, Name, Dept_id
  14. FROM Cooperator
  15. WHERE NOT EXISTS (SELECT *
  16.                  FROM Evaluation
  17.                          WHERE Cooperator.Cooperator_id=Evaluation.Cooperator_id)
  18. UNION
  19. SELECT Surname, Name, Dept_id
  20. FROM Cooperator
  21. WHERE NOT EXISTS (SELECT *
  22.                  FROM Evaluation
  23.                          WHERE Cooperator.Cooperator_id=Evaluation.Cooperator_id) AND Cooperator.Dept_id = NULL
  24.  
  25.  
  26. --3
  27. SELECT Cooperator.Surname, Company.Name, Evaluation.STATUS AS 'оценка'
  28.     FROM Cooperator, Department, Evaluation, Company
  29.     WHERE Cooperator.Dept_id = Department.Dept_id AND Cooperator.Cooperator_id = Evaluation.Cooperator_id AND Company.Company_id = Department.Company_id
  30. UNION
  31. SELECT Cooperator.Surname, NULL, Evaluation.STATUS AS 'оценка'
  32.     FROM Cooperator, Department, Evaluation, Company
  33.     WHERE Cooperator.Dept_id IS NULL AND Cooperator.Cooperator_id = Evaluation.Cooperator_id;
  34.  
  35.  
  36. --4
  37. SELECT Cooperator.Surname, Department.Name, Evaluation.STATUS AS 'оценка'
  38.     FROM Cooperator, Department, Evaluation, Company
  39.     WHERE Cooperator.Dept_id = Department.Dept_id AND Cooperator.Cooperator_id = Evaluation.Cooperator_id AND Company.Company_id = Department.Company_id
  40.     AND Evaluation.STATUS >= 4
  41.  
  42.  
  43. --5
  44. SELECT Cooperator.Surname, Department.Name, Evaluation.STATUS AS 'оценка'
  45.     FROM Cooperator, Department, Evaluation, Company
  46.     WHERE Cooperator.Dept_id = Department.Dept_id AND Cooperator.Cooperator_id = Evaluation.Cooperator_id AND Company.Company_id = Department.Company_id
  47.     AND Evaluation.STATUS >= 4 AND Evaluation.Date>='2019-12-01' AND Evaluation.Date<'2020-01-01'
  48.  
  49.  
  50. --6
  51. SELECT Company.Name, MAX(Cooperator.salary) AS 'макс з/п'
  52.     FROM Company JOIN Department ON Company.Company_id = Department.Company_id
  53.     JOIN Cooperator ON Cooperator.Dept_id = Department.Dept_id
  54.     WHERE Company.Coefficent > 8
  55.     GROUP BY Company.Name
  56.  
  57. -- должно было не работать, но работает
  58. SELECT Company.Name, MAX(Cooperator.salary) AS 'макс з/п'
  59.     FROM Company, Cooperator, Department
  60.     WHERE Company.Coefficent > 8 AND Cooperator.Dept_id = Department.Dept_id AND Company.Company_id = Department.Company_id
  61.     GROUP BY Company.Name
  62.  
  63.  
  64. --7
  65. SELECT Cooperator.Surname, Company.Coefficent
  66. FROM Cooperator, Company, Department
  67. WHERE Cooperator.Dept_id = Department.Dept_id AND  Company.Company_id = Department.Company_id
  68. UNION
  69. SELECT Cooperator.Surname, NULL
  70. FROM Cooperator
  71. WHERE Cooperator.Dept_id IS NULL
  72. GROUP BY Cooperator.Surname
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement