SQL(2021−06−07)

Hyunjeong Lee·2021년 6월 7일
0

●DBの範囲
select *(全体) または field名 from table名

●検索条件
where field名 ’項目名’ ←数字以外は文字列’’
条件追加 and

●query作成フロー
1) show tables로 어떤 테이블이 있는지 살펴보기
2) 제일 원하는 정보가 있을 것 같은 테이블에 select from 테이블명 쿼리 날려보기
3) 원하는 정보가 없으면 다른 테이블에도 2)를 해보기
4) 테이블을 찾았다! 조건을 걸 필드를 찾기
5) select
from 테이블명 where 조건 이렇게 쿼리 완성!

●whereと一緒に
where !='field名’  除外したい項目
select * from orders
where course_title != "웹개발 종합반";
잠깐 상식!
'!=' 에서 ! (느낌표)는 부정 (not)을 의미합니다. '='는 같음을 의미하니, '!='는 같지 않음이겠죠!

where between 'A' and 'B'  →A~Bの間
select * from orders
where created_at between "2020-07-13" and "2020-07-15";

where field名 in(数字) →含む
select * from checkins
where week in (1, 3);

where like '***%***' →文字列パターン(曖昧な検索)
select * from users
where email like '%daum.net';

limit
一部データーのみ読み込み。検索結果が多い時
select * from orders
where payment_method = "kakaopay"
limit 5;

distinct 
重複データーは除いて持ってくる、どんな種類があるか見たい時
select distinct(payment_method) from orders;

count
検索結果を数える
SELECT count(distinct(name)) from users;

0개의 댓글