Skip to content

Commit b74b43d

Browse files
committed
refactor : 시간 타입 변경 + 100위 조회
1 parent e0c8e29 commit b74b43d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/java/com/gpt/geumpumtabackend/study/repository/StudySessionRepository.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Long sumCompletedStudySessionByUserId(
4242
@Query(value = """
4343
SELECT u.id as userId,
4444
u.name as username,
45-
SUM(
45+
CAST(SUM(
4646
TIMESTAMPDIFF(SECOND,
4747
GREATEST(s.start_time, :periodStart),
4848
CASE
@@ -51,7 +51,7 @@ Long sumCompletedStudySessionByUserId(
5151
ELSE s.end_time
5252
END
5353
) * 1000
54-
) as totalMillis,
54+
)AS SIGNED) as totalMillis,
5555
RANK() OVER (ORDER BY SUM(
5656
TIMESTAMPDIFF(SECOND,
5757
GREATEST(s.start_time, :periodStart),
@@ -75,6 +75,7 @@ ORDER BY SUM(TIMESTAMPDIFF(SECOND,
7575
ELSE s.end_time
7676
END
7777
) * 1000) DESC
78+
LIMIT 100
7879
""", nativeQuery = true)
7980
List<PersonalRankingTemp> calculateCurrentPeriodRanking(
8081
@Param("periodStart") LocalDateTime periodStart,
@@ -91,7 +92,7 @@ List<PersonalRankingTemp> calculateCurrentPeriodRanking(
9192
@Query(value = """
9293
SELECT u.id as userId,
9394
u.name as username,
94-
SUM(
95+
CAST(SUM(
9596
TIMESTAMPDIFF(SECOND,
9697
GREATEST(s.start_time, :periodStart),
9798
CASE
@@ -100,7 +101,7 @@ List<PersonalRankingTemp> calculateCurrentPeriodRanking(
100101
ELSE s.end_time
101102
END
102103
) * 1000
103-
) as totalMillis,
104+
) AS SIGNED) as totalMillis,
104105
RANK() OVER (ORDER BY SUM(
105106
TIMESTAMPDIFF(SECOND,
106107
GREATEST(s.start_time, :periodStart),
@@ -126,6 +127,7 @@ ORDER BY SUM(
126127
END
127128
) * 1000
128129
) DESC
130+
LIMIT 100
129131
""", nativeQuery = true)
130132
List<PersonalRankingTemp> calculateFinalizedPeriodRanking(
131133
@Param("periodStart") LocalDateTime periodStart,
@@ -134,7 +136,7 @@ List<PersonalRankingTemp> calculateFinalizedPeriodRanking(
134136

135137
@Query(value = """
136138
SELECT u.department as departmentName,
137-
SUM(
139+
CAST(SUM(
138140
TIMESTAMPDIFF(SECOND,
139141
GREATEST(s.start_time, :periodStart),
140142
CASE
@@ -143,7 +145,7 @@ List<PersonalRankingTemp> calculateFinalizedPeriodRanking(
143145
ELSE s.end_time
144146
END
145147
) * 1000
146-
) as totalMillis,
148+
) AS SIGNED) as totalMillis,
147149
RANK() OVER (ORDER BY SUM(
148150
TIMESTAMPDIFF(SECOND,
149151
GREATEST(s.start_time, :periodStart),
@@ -175,7 +177,7 @@ List<DepartmentRankingTemp> calculateCurrentDepartmentRanking(
175177

176178
@Query(value = """
177179
SELECT u.department as departmentName,
178-
SUM(
180+
CAST(SUM(
179181
TIMESTAMPDIFF(SECOND,
180182
GREATEST(s.start_time, :periodStart),
181183
CASE
@@ -184,7 +186,7 @@ List<DepartmentRankingTemp> calculateCurrentDepartmentRanking(
184186
ELSE s.end_time
185187
END
186188
) * 1000
187-
) as totalMillis,
189+
) AS SIGNED) as totalMillis,
188190
RANK() OVER (ORDER BY SUM(
189191
TIMESTAMPDIFF(SECOND,
190192
GREATEST(s.start_time, :periodStart),

0 commit comments

Comments
 (0)