Skip to content

Commit 4e445b8

Browse files
authored
Queries for SQL OVER() Clause (#210)
* Queries for SQL OVER() Clause * Update over-clause-with-rows.sql
1 parent bbf71ef commit 4e445b8

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT enrollment_date,
2+
MAX(gpa) AS highest_gpa,
3+
MIN(gpa) AS lowest_gpa
4+
FROM Student
5+
GROUP BY enrollment_date;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT id, semester, grade,
2+
MAX(grade) OVER (PARTITION BY student_id ORDER BY grade) AS course_highest,
3+
MIN(grade) OVER (PARTITION BY student_id ORDER BY grade) AS course_lowest
4+
FROM Exam
5+
ORDER BY course_id;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SELECT name, position,
2+
COUNT(*) OVER (PARTITION BY name) AS Total_Positions
3+
FROM Faculty;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT id, enrollment_date,
2+
AVG(gpa) OVER (ORDER BY enrollment_date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS Avg3GPAs,
3+
AVG(gpa) OVER (ORDER BY YEAR(enrollment_date) RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS AvgGPAYearOverYear
4+
FROM Student
5+
ORDER BY enrollment_date, id;

0 commit comments

Comments
 (0)