File tree Expand file tree Collapse file tree 2 files changed +15
-15
lines changed
main/java/g3501_3600/s3580_find_consistently_improving_employees
test/java/g3501_3600/s3580_find_consistently_improving_employees Expand file tree Collapse file tree 2 files changed +15
-15
lines changed Original file line number Diff line number Diff line change 2
2
# #Medium #Database #2025_06_11_Time_449_ms_(91.67%)_Space_0.0_MB_(100.00%)
3
3
WITH Ranked AS (
4
4
SELECT
5
- employee_id,
6
- name,
7
- review_date,
8
- rating,
5
+ e . employee_id ,
6
+ e . name ,
7
+ pr . review_date ,
8
+ pr . rating ,
9
9
RANK() OVER (
10
- PARTITION BY employee_id
11
- ORDER BY review_date DESC
10
+ PARTITION BY e . employee_id
11
+ ORDER BY pr . review_date DESC
12
12
) AS rnk,
13
- LAG(rating) OVER (
14
- PARTITION BY employee_id
15
- ORDER BY review_date DESC
16
- ) AS lag_rating
17
- FROM employees
18
- LEFT JOIN performance_reviews
19
- USING ( employee_id)
13
+ LAG(pr . rating ) OVER (
14
+ PARTITION BY e . employee_id
15
+ ORDER BY pr . review_date DESC
16
+ ) AS lag_rating
17
+ FROM employees e
18
+ LEFT JOIN performance_reviews pr
19
+ ON e . employee_id = pr . employee_id
20
20
)
21
21
SELECT
22
22
employee_id,
@@ -29,7 +29,7 @@ GROUP BY
29
29
name
30
30
HAVING
31
31
COUNT (* ) = 3
32
- AND SUM (lag_rating > rating) = 2
32
+ AND SUM (CASE WHEN lag_rating > rating THEN 1 ELSE 0 END ) = 2
33
33
ORDER BY
34
34
improvement_score DESC ,
35
35
name ASC ;
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ void testScript(@EmbeddedDatabase DataSource dataSource)
73
73
assertThat (resultSet .getNString (3 ), equalTo ("2" ));
74
74
assertThat (resultSet .next (), equalTo (true ));
75
75
assertThat (resultSet .getNString (1 ), equalTo ("3" ));
76
- assertThat (resultSet .getNString (2 ), equalTo ("Alice Johnson " ));
76
+ assertThat (resultSet .getNString (2 ), equalTo ("Carol Davis " ));
77
77
assertThat (resultSet .getNString (3 ), equalTo ("2" ));
78
78
assertThat (resultSet .next (), equalTo (false ));
79
79
}
You can’t perform that action at this time.
0 commit comments