[TIL] 20220525 캠프 38일차

C____JIN·2022년 5월 25일
1

TIL 1.0

목록 보기
22/78

데이터 베이스 4주차

Subquery

  • 하나의 SQL 쿼리 안에 또다른 SQL 쿼리가 있는 것
    select u.user_id, u.name, u.email from users u
    where u.user_id in (
        select user_id from orders
        where payment_method = 'kakaopay'
    )

with절

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
  • table을 요약해서 생성

Case

select pu.point_user_id, pu.point,
case 
when pu.point > 10000 then '1만 이상'
when pu.point > 5000 then '5천 이상'
else '5천 미만'
END as lv
from point_users pu
  • 조건을 걸어서 처리할 수 있음

서버리스 프론트엔드 Day1

My Velog

마무리

날이 점점 더워진다!

집중력 잃지말고 Daily 계획을 세우고, 시간을 효율적으로 사용해 보자!!

profile
개발 블로그🌐 개발일지💻

1개의 댓글

comment-user-thumbnail
2022년 5월 26일

너무 더워요....

답글 달기