select 추출할 필드(*은 모든 필드를 추출함) from 테이블
where 필드값 조건
select * from orders
where course_title = "앱개발 종합반" and payment_method = "kakaopay";
필드나 테이블이 아닌 '문자'는 '작은 따옴표'로 묶기
!=
between ~ and '''
in( )
in(1,3,5,7)
like
where email like '%daum.net'
(다음이메일을 사용하는 필드만 추출)limit 5
: 값을 5개만 보여줌)select distinct (추출할 필드) from 테이블
select count(*) from table
where payment_method = 'kakaopay'
select * from users
group by name
order by count(*) asc (생략가능) - 오름차순 정렬
order by count(*) desc - 내림차순 정렬
select * from point_users
inner join users on point_users.user_id = users.user_id
(
......
)
union all
(
...
)
쿼리문 안에 들어가는 쿼리문, 실행순서는 가장 안쪽에 있는 쿼리문 부터
최상단에 사용해야함. 전체 블록해서 실행해야 값을 확인할 수 있음.
with table1 as (subquery1), table2 as (subquery2)
select * from table1 a
table1이라는 이름의 임시 테이블(서브쿼리1의 내용을 가진)을 생성+
table2이라는 이름의 임시 테이블(서브쿼리2의 내용을 가진)을 생성
substring_index(email,'@',-1)
substring(date,1,10)
엑셀의 ifs
함수와 비슷함.
select pu.point_user_id, pu.point,
case
when pu.point > 10000 then '잘 하고 있어요!'
else '조금 더 달려주세요!'
END as '구분'
from point_users pu;