Where 절은, Select 쿼리문으로 가져올 데이터에 조건을 걸어주는 것을 의미해요.
select * from orders
where payment_method = "kakaopay";
select * from point_users
where point > '5000';
select * from orders
where course_title = "앱개발 종합반"
and payment_method = "card";
select * from point_users
where point > 20000;
select * from users
where name = "황**";
select * from orders
where course_title = "웹개발 종합반"
and payment_method = "CARD";
'같지 않음' 조건은 != 로 걸 수 있습니다.
select * from orders
where payment_method != 'CARD';
'범위' 조건은 between 으로 걸 수 있어요.
select * from point_users
where point between 20000 and 30000
'포함' 조건은 in 으로 걸 수 있어요.
select * from checkins
where week in (1, 3);
'패턴' 조건은 like 으로 걸 수 있어요.
예1) email 필드값이 a로 시작하는 모든 데이터
where email like 'a%':
예2) email 필드값이 a로 끝나는 모든 데이터
where email like '%a'
예3) email 필드값에 co를 포함하는 모든 데이터
where email like '%co%'
예4) email 필드값이 a로 시작하고 o로 끝나는 모든 데이터
where email like 'a%o'
select * from users
where email like 's%com';
select * from users
where email like 's%com'
and name = "이**";
일부 데이터만 가져오는 Limit이라는 기능이 있습니다.
select * from orders
where payment_method = "kakaopay"
limit 5;
select distinct(payment_method) from orders;
select count(*) from orders
select distinct(name) from users;
그리고, 여기에 count를 입혀주면 몇 개의 성씨가 있는지 알 수 있습니다.
SELECT count(distinct(name)) from users;
select email from users
where name = "남**";
select * from users
where created_at between "2020-07-12" and "2020-07-14"
and email like "%gmail.com";
select count(*) from users
where created_at between "2020-07-12" and "2020-07-14"
and email like "%gmail.com";
select * from orders
where email like '%naver.com'
and course_title = '웹개발 종합반'
and payment_method = 'kakaopay'