
아래 두 화면처럼,
select문에 필드를 서브쿼리로 작성하던 중 실수로 서브쿼리 안에 from checkins c 라고 alias를 붙였더니
결과(avg_likes)값이 달라졌습니다.
checkins는 하나의 테이블인데 똑같이 alias를 붙여도 결과가 달라지는 이유가 궁금합니다.
SELECT c.checkin_id ,
c.user_id,
c.likes,
(
SELECT avg(likes) from checkins c
where user_id = c.user_id
) as avg_likes
from checkins c

아래는 강의대로 한 결과입니다.
SELECT c.checkin_id ,
c.user_id,
c.likes,
(
SELECT avg(likes) from checkins
where user_id = c.user_id
) as avg_likes
from checkins c

