2025.02.24 - [프로그래밍/SQL, Hive, SAS 관련 정보] - [SQL] Table of Contents
CTE는 쿼리 전체에서 재사용이 가능하며, 서브쿼리 내부에서도 참조할 수 있습니다.
select user_id from
(select user_id, count(movie_id) cnt
from MovieRating
group by user_id) t
where cnt = (select max(t.cnt) from t);
는 작동하지 않지만
with temp as
(select user_id, count(movie_id) cnt
from MovieRating
group by user_id)
select user_id
from temp
where cnt = (select max(cnt) from temp);
는 잘 작동하는 이유입니다.
'프로그래밍 > SQL, Hive, SAS 관련 정보' 카테고리의 다른 글
[SQL문제풀이] - Sub query의 활용 (0) | 2025.04.13 |
---|---|
[SQL 기초] Sub-query Scope (0) | 2025.04.13 |
[SQL 기초] Group by와 Window함수의 동시사용 (0) | 2025.04.13 |
[SQL문제풀이-Groupby/Subquery] Movie Rating (0) | 2025.04.13 |
[SQL문제풀이-Union활용] Count Salary Categories (0) | 2025.04.09 |