WHERE절 구조
select *
from 테이블
where 필터링 조건 (ex. where age=20 (20살인 사람))
⭐️ 문자일 경우 where gender='female'처럼 '문자' 작은 따옴표 사용
1️⃣ AND 그리고
Ex) where age=20 and gender='female'
2️⃣ OR 또는
Ex) where age=20 or gender='female'
3️⃣ NOT 아닌
Ex) where not age=20
1️⃣ 숫자 연산 기호 +, -, *, /
select food_preparation_time,
delivery_time,
food_preparation_time + delivery_time as total_time
from food_orders
2️⃣ SUM, AVG
select sum(food_preparation_time) total_food_preparation_time, avg(delivery_time) avg_food_delivery_time
from food_orders
3️⃣ COUNT
✔️ 현재 테이블이 몇 개의 데이터/값을(를) 가지고 있는지 확인!
➡️ 데이터 갯수일 경우: COUNT(컬럼)
➡️ 몇개의 값을 가지고 있는지 확인할 경우: COUNT(DISTINCT 컬럼)
✔️ count(컬럼): 컬럼명 대신 1이나 * 사용 가능
➡️ 1이나 *은 테이블 내 모든 갯수 확인할 경우 사용
select count(1) count_of_orders, count(distinct customer_id) count_of_customers
from food_orders
4️⃣ MIN, MAX
select min(price) min_price,
max(price) max_price
from food_orders
Group by 기본 구조
select 카테고리 컬럼, sum(계산 컬럼)
from 테이블
group by 카테고리 컬럼
Order by 기본 구조
select 카테고리 컬럼, sum(계산 컬럼)
from 테이블
group by 카테고리 컬럼
order by 정렬 원하는 컬럼 (카테고리 컬럼), sum(계산 컬럼)
⭐️ 오름차순(숫자가 점점 커지는 순서로 정렬) 기준
⭐️ 내림차순(숫자가 점점 작아지는 순서로 정렬)으로 정렬할 경우: order by sum(계산 컬럼) desc