커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4-4 with절 다음 줄바꿈이 있을 때, 오류가 나는 이유가 궁금합니다.
[왕초보] 엑셀보다 쉬운, SQL
4주차
북마크
이*기
댓글
3
추천
0
조회수
20
조회수
20
답변 완료


with table1 as (

select course_id, count(distinct(user_id)) as cnt_checkins from checkins

group by course_id

), table2 as (

select course_id, count(*) as cnt_total from orders

group by course_id

)


select c.title,

    a.cnt_checkins,

    b.cnt_total,

    (a.cnt_checkins/b.cnt_total) as ratio

from table1 a inner join table2 b on a.course_id = b.course_id

inner join courses c on a.course_id = c.course_id


위에 코드는 동영상에선 오류가 나지 않은 정답코드입니다. 하지만 제꺼에선 syntax 에러가 나더라구요

그래서 밑의 문장으로 해결했습니다.


with table1 as (

select course_id, COUNT(DISTINCT(user_id)) as cnt_checkins from checkins c 

group by course_id

), table2 as (

select course_id, COUNT(*) as cnt_total from orders

group by course_id

)

select c2.title ,

 a.course_id

 a.cnt_checkins

 b.cnt_total

 (a.cnt_checkins / b.cnt_total) as radio 

from  table1 a

inner join table2 b on a.course_id = b.course_id

inner join courses c2 on a.course_id = c2.course_id 


with 절과 select 문을 붙여주었더니 정상 작동합니다.

SQL 도 파이썬의 들여쓰기와 같이 줄바꿈이 큰 영향을 끼치는지 궁금합니다.

취소
 공유
취소
댓글 0
댓글 알림
나의얼굴