Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select StudentId, StudentName, GroupId
  2. from Students
  3.          natural join Marks
  4.          natural join Courses
  5. where CourseName = 'Базы данных'
  6.   and Mark = 4;
  7.  
  8. select StudentId, StudentName, GroupId
  9. from Students
  10.          natural join
  11.      (select StudentId
  12.       from Students
  13.           except
  14.       select StudentId
  15.       from Students
  16.                natural join Marks
  17.                natural join Courses
  18.       where CourseName = 'Базы данных');
  19.  
  20. select StudentId, StudentName, GroupId
  21. from (select StudentId, StudentName, GroupId
  22.       from Students
  23.                natural join Plan
  24.                natural join Courses
  25.       where CourseName = 'Базы данных')
  26.          natural join
  27.      (select StudentId
  28.       from Students
  29.           except
  30.       select StudentId
  31.       from Students
  32.                natural join Marks
  33.                natural join Courses
  34.       where CourseName = 'Базы данных');
  35.  
  36. select StudentId, StudentName, GroupId
  37. from Students
  38.          natural join Marks
  39.          natural join Plan
  40.          natural join Lecturers
  41. where lecturerid = 123;
  42.  
  43. select StudentId
  44. from (select StudentId
  45.       from Students
  46.           except
  47.       select StudentId
  48.       from Students
  49.                natural join Marks
  50.                natural join Plan
  51.                natural join Lecturers
  52.       where LecturerName = 'name');
  53.  
  54. select StudentId
  55. from ((select StudentId
  56.        from Students)
  57.       except
  58.       (select StudentId
  59.        from (select StudentId, CourseId
  60.              from Students
  61.                       natural join Plan
  62.              where LecturerId = 123) except
  63.        select StudentId, CourseId
  64.        from Students
  65.                 natural join Marks));
  66.  
  67. select StudentName, CourseName
  68. from Students
  69.          natural join Plan
  70.          natural join Courses;
  71.  
  72. select StudentId
  73. from Students
  74.          natural join Plan
  75. where LecturerId = 123;
  76.  
  77. with lhs as (select StudentId as StudentId2, CourseId
  78.              from Students
  79.                       natural join Marks
  80.              where Mark != 2),
  81.      rhs as (select StudentId as StudentId1, CourseId
  82.              from Students
  83.                       natural join Marks
  84.              where Mark != 2)
  85. select StudentId1, StudentId1
  86. from ((select StudentId2 from lhs)
  87.          cross join
  88.       (select StudentId1 from rhs))
  89.         except
  90.      (select StudentId1, StudentId2
  91.         from ((select StudentId2 from lhs) cross join rhs)
  92.             except
  93.         (select *
  94.         from lhs natural join rhs));
  95.  
  96. with lhs as (select StudentId, CourseId
  97.              from Students
  98.                       natural join Marks
  99.              where Mark != 2),
  100.      rhs as (select StudentId, GroupId
  101.              from Students)
  102. select CourseId, GroupId
  103. from ((select CourseId from lhs)
  104.          cross join
  105.       (select GroupId from rhs))
  106.         except
  107.      (select CourseId, GroupId
  108.         from ((select CourseId from lhs) cross join rhs)
  109.             except
  110.         (select *
  111.         from lhs natural join rhs));
  112.  
  113. select avg(Mark) as Mark
  114. from Students
  115.          natural join Marks
  116. where StudentId = 123;
  117.  
  118. select StudentId, avg(Mark) as Mark
  119. from Students
  120.          natural join Marks
  121. group by StudentId;
  122.  
  123. select avg(Mark) as Mark
  124. from (select GroupId, avg(Mark) as Mark
  125.       from Students
  126.                natural join Marks
  127.       group by GroupId);
  128.  
  129. select *
  130. from (select StudentId, count(*) as total
  131.       from students
  132.                natural join Plan
  133.       group by StudentId)
  134.          natural join (select StudentId, count(*) as passed
  135.                        from students
  136.                                 natural join Marks
  137.                        where Mark != 2
  138.                        group by StudentId)
  139.          natural join (select StudentId, count(*) as notpassed
  140.                        from students
  141.                                 natural join Marks
  142.                        where Mark = 2
  143.                        group by StudentId);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement