SQL란 데이터베이스와 대화하기 위한 '일종의 언어' = Query

데이터베이스는 쉽게 말해 '데이터가 저장되어있는 큰 폴더'이다
(기타 의미)
모든 Query 는 이래의 구조를 갖는다.
select *
from food_orders
데이터 불러오기 단축키
ctrl + enter
본 명령어 한 눈에 보기
- SELECT : 데이터를 가져오는 기본 명령어로, 데이터를 조회하는 모든 Query 에 사용됨
- FROM : 데이터를 가져올 테이블을 특정해주는 문법
- *: 모든 컬럼을 가져와준다는 의미
ex)
select restaurant_name, addr
from food_orders
- 방법1 : 컬럼1 as 별명1
- 방법2 : 컬럼2 별명2
cf. 별명 작성시 유의사항
영문, 언더바 -> 별명만 적음
특수문자, 띄어쓰기, 한글 -> "별명"으로, 큰 따옴표 안에 적음
select *
from customers
where age=21
select *
from customers
where age<21
나이가 10 과 20 사이
where age between 10 and 20
나이가 15, 21, 31 세인 경우
where age in (15, 21, 31)
‘김’ 으로 시작하는 이름
where name like '김%'
‘임’ 으로 끝나는 이름
where name like '%임'**
식당 이름에 ‘Next’ 를 포함하는 경우
where restaurant name like '%Next%'
나이가 20세 이상이거나, 여성
select *
from customers
where age>20 or gender=’female’
select *
from customers
where age>=21
and gender = 'male'

일반적인 SQL의 에러문은 아래와 같이 나온다.
Q. 상품 준비시간이 20~30분 사이인, 한국음식점의 식당명과 고객번호 조회하기
A1. select restaurant_name, customer_id
from food_orders
where food_preparation_time between 20 and 30
(오답)
A2. select restaurant_name, customer_id
from food_orders
where food_preparation_time between 20 and 30 and cuisine_type='korean'
(정답)
오답노트 : 한국음식점을 필터링하는 조건을 적지 않음. 조회한 값에 한국식당인지 여부가 보이지는 않기 때문에, 놓치기 쉽다. 데이터분석가는 진짜 꼼꼼해야 하겠구나...