group by 는 동일한 내용이 있으면 묶어서 이용하는 sql문입니다.
예시)
select concat(author_fname,' ' ,author_lname) as full_name, count(title)
from books
group by author_lname;
books 테이블에 author_lname 이 같은 사람들을 그룹으로 묶어 (group by) 타이틀 의 수를 구하고 (count)
풀 네임으로 보여달라는 뜻입니다.
select count(pages), concat(author_fname,' ' , author_lname)
from books
group by author_lname,author_fname;
이런식으로 그룹 바이 뒤에 2개 이상의 컬럼이 와도 됩니다.
'개발 > SQL' 카테고리의 다른 글
MySQL - subquery (0) | 2022.12.07 |
---|---|
MySQL - count , min , max , avg , sum (0) | 2022.12.07 |
MySQL - distinct , order by , limit , like , __ 언더바 (0) | 2022.12.07 |
MySQL - 함수 concat(), substring(), replace(),reverse(),char_length(),upper(), lower() (0) | 2022.12.06 |
MySQL - select , update , delete , insert (0) | 2022.12.06 |