동일한 범주의 데이터를 묶어주는
정렬 desc 내림차순
테이블명 뒤에 as를 붙여서 별칭 추가
select payment, count(*) as cnt from orders
두 테이블의 공통된 정보를 기준으로 연결


두 테이블 모두 가지고 있는 데이터만 출력
select * from user u
inner join point p on u.user_id=p.user_id
부분적으로 일치하는 칼럼을 찾을때 사용
where email like '%naver.com'
결과물 합치기
(~~
)
union all
(
)
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'
)
where 필드명 in (subquery)
select 필드명, 필드명, (subquery) from..
내가 만든 select와 이미 있는 테이블 join
select pu.user_id, a.avg_like, pu.point from point_users pu
inner join (
select user_id, round(avg(likes),1) as avg_like from checkins
group by user_id
) a on pu.user_id = a.user_id
select * from
( 기준이 되는거
) a
inner join
(
) b on a.키=b.키
깔끔하게 빼준다
with table1 as (------------
), table2 as (-------------
)
select * from table1 a
inner join table2 b on a.키=b.키
select user_id, email, SUBSTRING_INDEX(email,'@',1) from users
@를 기준으로 쪼개고 첫번재 조각 가져오기
select order, created, substring(created,1,10) from orders
문자열, 출력을 하고싶은 첫 글자의 위치, 몇개의 글짜를 출력
when 조건1 then 값
when 조건2 then 값2
else 값3
end