We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 65527d8 + 9fe8281 commit 7736930Copy full SHA for 7736930
data-manipulation/window-functions-where-clause/window-functions-in-where-clause.sql
@@ -0,0 +1,22 @@
1
+--using a Common Table Expression
2
+WITH RankedStudents AS (
3
+ SELECT
4
+ id, name, gpa,
5
+ RANK() OVER (ORDER BY gpa DESC) AS r
6
+FROM Student
7
+WHERE gpa IS NOT NULL
8
+)
9
+SELECT id, name, gpa, r
10
+FROM RankedStudents
11
+WHERE r <= 3;
12
+
13
+--using a subquery
14
+SELECT *
15
+FROM (
16
17
18
19
+ FROM Student
20
+ WHERE gpa IS NOT NULL
21
+) AS RankedStudents
22
0 commit comments