select a.apnt_no, a.pt_name, a.pt_no, d.mcdp_cd, d.dr_name, a.apnt_ymd
from
(
SELECT a.apnt_ymd, a.apnt_no, a.apnt_cncl_yn, a.apnt_cncl_ymd, p.pt_no, p.pt_name, p.gend_Cd, p.age, p.tlno, a.mcdp_cd, a.mddr_id
from appointment a
left join patient p on a.pt_no = p.pt_no
) a
left join doctor d on a.mddr_id = d.dr_id
where a.apnt_ymd like '2022-04-13%' and
a.apnt_cncl_yn = 'n' and
d.mcdp_Cd = 'cs'
order by 6 ascselect car_id,
case when car_id in (SELECT car_id
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
where start_date <= '2022-10-16' and
end_Date >= '2022-10-16') then '대여중'
else '대여 가능' end as AVAILABILITY
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
group by 1
order by 1 descSELECT year(o.sales_date) as year, month(o.sales_Date) as month, u.gender, count(distinct(u.user_id))
from online_sale o
left join user_info u on o.user_id = u.user_id
where u.gender is not null
group by 1,2,3
order by 1 asc, 2 asc, 3 ascSELECT i.rest_id, i.rest_name, i.food_type, i.favorites, i.address, round(avg(r.review_score), 2)
from rest_review r
left join rest_info i on r.rest_id = i.rest_id
where i.address like '서울%'
group by 1
order by 6 desc, 4 desc스터디를 진행할 강의를 링크해주세요.
강의에서 필수로 사용되는 문법에 대한 개념을 요약해주세요.
Having ≠ Where
# 집계함수, GROUP BY절, HAVING을 함께 사용하는 SQL문 - 실습
select 성별, avg(나이)as avg_age 2️⃣
from basic.theglory
where 나이>=311️⃣
group by 성별 2️⃣
having AVG_AGE>41 3️⃣

중첩(일반) 서브쿼리
# 중첩 서브쿼리 실습
# 문동은의 나이보다 나이가 많은 모든 데이터 반환하기
select *
from basic.theglory
where 나이 > (select 나이 from basic.theglory where 이름='문동은')
; 
스칼라 서브쿼리
# 중첩 서브쿼리 실습
# theglory 의 이름과 theglory2 테이블의 이름이 일치하는 경우를 count 하여
# same_name_cnt 컬럼으로 반환
# theglory 의 이름과 theglory 테이블의 이름이 일치하는 경우의 결제금액을 sum 하여
# same_name_sumamount 컬럼으로 반환
select 이름
, 나이
, (select count(*) from theglory2 where theglory2.이름=theglory.이름) as same_name_cnt
, (select sum(결제금액) from theglory2 where theglory2.이름=theglory.이름)as same_name_sumamount
from basic.theglory
; 
인라인 뷰
From 절
# 중첩 서브쿼리 실습
# 나이가 33세 이상인 모든 데이터 중 나이와 직업 컬럼 반환하기
select x.나이, x.직업
from( select *
from basic.theglory
where 나이>=33
)as x
