개발/SQL
MySQL - group by
웅'jk
2022. 12. 7. 13:17
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개 이상의 컬럼이 와도 됩니다.