코드잇/데이터베이스

SQL 문법

양상추상츄 2023. 2. 11. 11:33
select category, 
	main_month, 
    count(*) as '영화 수', 
    sum(view_count) as '총 관객 수'
from 2020_movie_report
group by category, main_month
having main_month = 5
and sum(view_count) >= 3000000
;
SELECT SUBSTRING(address, 1, 2) as region,
       gender,
       COUNT(*)
FROM member
GROUP BY SUBSTRING(address, 1, 2), gender WITH ROLLUP
HAVING region IS NOT NULL
ORDER BY region ASC, gender DESC;

* SQL 순서법칙

1. SELECT

2. FROM

3. WHERE

4. GROUP BY

5. HAVING

6. ORDER BY

7. LIMIT

 

* 실제 실행순서

1. FROM

2. WHERE

3. GROUP BY

4. HAVING

5. SELECT

6. ORDER BY

7. LIMIT

 

'코드잇 > 데이터베이스' 카테고리의 다른 글

SQL COALESCE, JOIN, USING, UNION  (0) 2023.02.18
SQL Foreign Key  (0) 2023.02.12
SQL 실용함수들 살펴보기  (0) 2023.02.05
SQL 백문이 불여일타  (0) 2023.02.05
[데이터베이스] 데이터 타입 변경  (0) 2021.10.16