Advertisement
Teammasik

lr6_db

Apr 18th, 2023
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.80 KB | None | 0 0
  1. --1
  2. SELECT *
  3. FROM Evaluation
  4. WHERE Cooperator_id IN (
  5.     SELECT Cooperator_id
  6.     FROM Cooperator
  7.     WHERE Surname = 'Иванов');
  8.  
  9.  
  10. --2
  11. SELECT Name
  12. FROM Cooperator
  13. WHERE Cooperator.Dept_id = 5 AND Cooperator_id IN (
  14.     SELECT Cooperator_id
  15.     FROM Evaluation
  16.     WHERE Status > (SELECT AVG(Status)
  17.                    FROM Evaluation))
  18.  
  19.  
  20. --3
  21. SELECT Name
  22. FROM Cooperator
  23. WHERE Dept_id = 7 AND Cooperator_id IN (
  24.         SELECT Cooperator_id
  25.         FROM Evaluation
  26.         WHERE Status < (
  27.             SELECT AVG(Status)
  28.             FROM Evaluation));
  29.  
  30.  
  31. --4
  32. select Dept_id /*count(*)*/ as amount_of_Deps
  33. from Department D
  34. where (select min(Stat_count)
  35.     from (select count(Status) as Stat_count
  36.         from Evaluation Ev
  37.         where Cooperator_id in (select Cooperator_id
  38.                          from Cooperator
  39.                          where Dept_id = D.Dept_id)
  40.         group by Cooperator_id) B) >3;
  41.  
  42.  
  43. --5
  44. SELECT C1.Surname, C1.Name, C1.Dept_id
  45. FROM Cooperator AS C1
  46. WHERE C1.Salary = (
  47.     SELECT MAX(C2.Salary)
  48.     FROM Cooperator AS C2
  49.     WHERE C1.Dept_id = C2.Dept_id);
  50.  
  51.  
  52. --6
  53. SELECT Surname, Name
  54. FROM Cooperator
  55. WHERE City NOT IN (
  56.       SELECT DISTINCT City
  57.       FROM Company)
  58.  
  59.  
  60. --7
  61. SELECT Coop.Cooperator_id, Coop.Name, Coop.Surname, Coop.City, Comn.City as City_of_comp
  62. FROM Cooperator AS Coop, Department AS Dept, Company AS Comn
  63. WHERE Coop.Dept_id = Dept.Dept_id
  64.     AND Comn.Company_id = Dept.Company_id
  65.         AND Coop.City != Comn.City;
  66.  
  67. SELECT Cooperator_id, Name, Surname, City
  68. FROM Cooperator AS C
  69. WHERE C.Dept_id IN (
  70.     SELECT Dept_id
  71.     FROM Department
  72.     WHERE Company_id IN (
  73.         SELECT Company_id
  74.         FROM Company
  75.         WHERE City != C.City));
  76.  
  77.  
  78.  
  79. --------------------------------------------------------------------------------------
  80. --8
  81. SELECT DISTINCT Cooperator.Cooperator_id, Surname, Name, City, Salary
  82. FROM Cooperator
  83. INNER JOIN Evaluation ON Cooperator.Cooperator_id = Evaluation.Cooperator_id
  84. WHERE EXISTS (SELECT Cooperator_id
  85.               FROM Evaluation
  86.               WHERE Cooperator.Cooperator_id = Evaluation.Cooperator_id
  87.               GROUP BY Cooperator_id
  88.               HAVING MIN(Status) > 3);
  89.  
  90. select *
  91. from Evaluation
  92. --9
  93. select distinct Cp.Cooperator_id, Cp.Surname, Cp.Name, City, Salary
  94. from Cooperator Cp, Evaluation Ev
  95. where Cp.Cooperator_id = Ev.Cooperator_id and 3 <
  96.                                             (select min(Status)
  97.                                             from Evaluation
  98.                                             where Cooperator_id = Cp.Cooperator_id);
  99.  
  100.  
  101.  
  102. --10
  103. SELECT *
  104. FROM Cooperator c
  105. WHERE EXISTS (
  106.     SELECT *
  107.     FROM Department d
  108.     WHERE d.Dept_id = c.Dept_id
  109.     AND c.City = (
  110.         SELECT City
  111.         FROM Company
  112.         WHERE d.Company_id = Company_id));
  113.  
  114.  
  115. --11
  116. SELECT d.Full_name
  117. FROM DEPARTMENT d, Cooperator c
  118. WHERE d.Dept_id = c.Dept_id AND EXISTS (
  119.     SELECT *
  120.     FROM Evaluation e
  121.     WHERE e.Cooperator_id = c.Cooperator_id)
  122. GROUP BY d.Full_name
  123. HAVING COUNT(DISTINCT c.Cooperator_id) > 1;
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement