[MariaDB Tutorial 번역 글]
- Select : https://rural-mouse.tistory.com/43
- Order By : https://rural-mouse.tistory.com/44
- Where : https://rural-mouse.tistory.com/45
- Distinct : https://rural-mouse.tistory.com/46
- Between : https://rural-mouse.tistory.com/48
- Like : https://rural-mouse.tistory.com/49
- In : https://rural-mouse.tistory.com/50
- Limit : https://rural-mouse.tistory.com/51
- Is Null : https://rural-mouse.tistory.com/52
- Joins : https://rural-mouse.tistory.com/53
- Inner Join : https://rural-mouse.tistory.com/54
- Left Join : https://rural-mouse.tistory.com/55
- Group By : https://rural-mouse.tistory.com/56
- Having ←←
- Subqueries : https://rural-mouse.tistory.com/60
- Insert : https://rural-mouse.tistory.com/61
- Insert Multiple Rows : https://rural-mouse.tistory.com/62
- Insert Into Select : https://rural-mouse.tistory.com/63
- Update : https://rural-mouse.tistory.com/64
원문 : https://www.mariadbtutorial.com/mariadb-basics/mariadb-having/
MariaDB Having
In this tutorial, you will learn how to use the MariaDB having clause to specify a search condition for groups.
www.mariadbtutorial.com
여기에 있는 모든 예제는 MariaDB sample database인 nation을 가지고 진행됩니다.
만약 읽고 따라 해 보시는 게 목적이라면 다운로드를 받고 읽어보시길 추천합니다.
원본 링크 : https://www.mariadbtutorial.com/getting-started/mariadb-sample-database/
MariaDB Sample Database
In this tutorial, you will learn about a MariaDB sample database nation and how to load the sample database into the MariaDB server.
www.mariadbtutorial.com
MariaDB의 having 절에 대한 소개
where 절은 select 명령문에 의해 반환되는 Row를 특정한 검색 조건에 따라 필터링 할 수 있게 해줍니다. 그러나 그것은 group by 절에 의해 만들어진 요약된 Row에 대해서는 필터링 할 수 없습니다.
group by 절에 의해 생성된 요약된 Row를 지정한 검색 조건에 따라 필터링하기 위해서는 having 절을 사용합니다.
다음은 having 절에 대한 문법 예제입니다.
select
select_list
from
table_name
group by
column1,
column2,
...
having
search_condition;
having 절은 group by 절 뒤에 바로 나타납니다. having 절의 구성하려면 하나 이상의 Boolean 표현식으로 구성되는 search_condition(검색 조건)을 지정합니다. select 명령문은 search_condition에 의해 True가 되는 그룹(혹은 Row)만 반환할 것입니다.
MariaDB의 having 절 예제
샘플 데이터베이스 nation의 countries와 region Table을 사용하도록 하겠습니다.
A) MariaDB의 group을 필터링하는 having 절 예제
다음은 11개 이상의 나라를 가지고 있는 지역을 찾는 having 절 예제입니다.
select
regions.name region,
count(country_id) country_count
from
countries
inner join regions
using (region_id)
group by
(regions.name)
having
count(region_id) > 10
order by
country_count desc;
B) MariaDB의 복합 조건을 사용한 having 절 예제
다음은 having 절이 10개를 넘는 나라를 가지고 크기가 1,000,000 km2이 넘는 지역을 찾는 예제입니다.
select
regions.name region,
count(country_id) country_count,
sum(area) area
from
countries
inner join regions
using (region_id)
group by
(regions.name)
having
count(region_id) > 10 and
area > 1000000
order by
area desc,
country_count desc;
이번 튜토리얼에서는 그룹에 대해 검색 조건을 지정할 수 있는 having 절에 대해 배웠습니다.
다음은 좀더 복잡한 쿼리문을 만들수 있는 Subqueries(서브 쿼리문)에 대해 배워보겠습니다.
'번역 > MariaDB' 카테고리의 다른 글
[MariaDB Tutorial 번역] 16. Insert (0) | 2021.07.11 |
---|---|
[MariaDB Tutorial 번역] 15. Subqueries (0) | 2021.07.09 |
[MariaDB Tutorial 번역] 13. Group By (0) | 2021.07.06 |
[MariaDB Tutorial 번역] 12. Left join (0) | 2021.07.06 |
[MariaDB Tutorial 번역] 11. Inner join (0) | 2021.07.05 |
댓글