
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
연습문제 과정에서 합치고 싶은 코드 두개를 '(괄호)'로 묶어주는 기능인데
(괄호)안에 완성된 코드의 완료 표시의 ';' 이 있으면 에러가 표시되는데
(괄호안에 있는 완료되었다는 표시로 ; 를 사용하게 되면 에러가 왜 생기는지 궁금합니다.)
순서상 문제라면 마지막에 ';'을 넣으면 나와야 하지만 () 안에서 ';'이 있으면 안된다는 에러가 나오기에
괄호 안에서의 ';'이 작성되면 안되는 건가요?
작성한 코드 및 에러 메세지
(
select '7월' as moth, c1.title, c2.week, count(*) as cnt from courses c1
inner join checkins c2 on c1.course_id = c2.course_id
inner join orders o on c2.user_id = o.user_id
where o.created_at < '2020-08-01'
group by c1.title, c2.week
order by c1.title, c2.week
)
UNION ALL
(
select '8월' as moth, c1.title, c2.week, count(*) as cnt from courses c1
inner join checkins c2 on c1.course_id = c2.course_id
inner join orders o on c2.user_id = o.user_id
where o.created_at >= '2020-08-01'
group by c1.title, c2.week
order by c1.title, c2.week
)
<문제 에러>
SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
)
UNION ALL
(
select '8월' as moth, c1.title, c2.week, count(*) as cnt ' at line 7
Error position: line: 6
