내배캠 사전캠프 TIL 6일차

오병택·2025년 1월 20일

내배캠

목록 보기
5/73

학습 요약

걷기 40번까지, SQL 완강, 웹 4주차 중반까지

SQL

기초 문법

null // 데이터 x
is not null // null이 아님
coalesce(컬럼, 대체값) // 값이 없는 경우 대체값으로 대체
sum(컬럼명) over (partition by 컬럼명 order by 컬럼명 ) // 누적합 계산
date() // 날짜 형식으로 변환
date_format(date, format) // date : 날짜나 시간 값을 포함하는 컬럼 또는 값, format : 아래 그림의 포맷 문자를 사용

pivot view 구조

select age,
       max(if(gender='male', order_count, 0)) male,
       max(if(gender='female', order_count, 0)) female
from 
(
select b.gender,
       case when age between 10 and 19 then 10
            when age between 20 and 29 then 20
            when age between 30 and 39 then 30
            when age between 40 and 49 then 40
            when age between 50 and 59 then 50 end age,
       count(1) order_count
from food_orders a inner join customers b on a.customer_id=b.customer_id
where b.age between 10 and 59
group by 1, 2
) t
group by 1
order by 1 desc

// 서브쿼리에선 분류해주고 메인쿼리에선 pivot view 틀 만듬

WEB

느낀 점

SQL 막 어렵진 않은데 머리 아픈 느낌.. 근데 강의를 다 들어서 나름 뿌듯하다. 공부 습관이 만들어지고 있는 것 같긴 한데 12시간은 음.. 점차 늘리다 보면 괜찮겠지 :)

profile
걱정하지 말고 일단 해봐!

0개의 댓글