728x90
INSERT INTO books (title, author_fname, author_lname, released_year, stock_quantity, pages)
VALUES
('The Namesake', 'Jhumpa', 'Lahiri', 2003, 32, 291),
('Norse Mythology', 'Neil', 'Gaiman',2016, 43, 304),
('American Gods', 'Neil', 'Gaiman', 2001, 12, 465),
('Interpreter of Maladies', 'Jhumpa', 'Lahiri', 1996, 97, 198),
('A Hologram for the King: A Novel', 'Dave', 'Eggers', 2012, 154, 352),
('The Circle', 'Dave', 'Eggers', 2013, 26, 504),
('The Amazing Adventures of Kavalier & Clay', 'Michael', 'Chabon', 2000, 68, 634),
('Just Kids', 'Patti', 'Smith', 2010, 55, 304),
('A Heartbreaking Work of Staggering Genius', 'Dave', 'Eggers', 2001, 104, 437),
('Coraline', 'Neil', 'Gaiman', 2003, 100, 208),
('What We Talk About When We Talk About Love: Stories', 'Raymond', 'Carver', 1981, 23, 176),
("Where I'm Calling From: Selected Stories", 'Raymond', 'Carver', 1989, 12, 526),
('White Noise', 'Don', 'DeLillo', 1985, 49, 320),
('Cannery Row', 'John', 'Steinbeck', 1945, 95, 181),
('Oblivion: Stories', 'David', 'Foster Wallace', 2004, 172, 329),
('Consider the Lobster', 'David', 'Foster Wallace', 2005, 92, 343),
('10% Happier', 'Dan', 'Harris', 2014, 29, 256),
('fake_book', 'Freida', 'Harris', 2001, 287, 428),
('Lincoln In the Bardo', 'George', 'Saunders', 2017, 156, 375);
갯수를 세는 conunt() 함수
-- books 테이블의 데이터 갯수는 ??
select count(*)
from books;
-- author_lname의 유니크한 데이터의 갯수는??
select count(distinct author_lname)
from books;
-- 책 제목에 the가 들어간 책은 몇권입니까??
select count(*)
from books
where title like '%the%';
집계하는 함수. ~~ 별로 group by 키워드
-- author_lname 별로 몇권의 책을 썼는지, 작가 이름과 책 권수를 조회하시오.
select author_lname,count(title) as count
from books
group by author_lname;
-- 년도 별로 각각 몇 권의 책이 출간되었는지, 년도와 출간수를 가져오시오.
select released_year, count(title) as count
from books
group by released_year;
'MySQL' 카테고리의 다른 글
MySQL not equal(~가 아닌 것) , not like (~를 포함하지 않은 것) 데이터 가져오기. (0) | 2022.12.07 |
---|---|
MySQL - 값을 모두 더해주는 sum() , 값의 평균을 구해주는 avg() (0) | 2022.12.07 |
MySQL - 최대값 max() ,최소값 min() , sub query (0) | 2022.12.07 |
MySQL - 문자열 컬럼의 여러 키워드들 예제풀이 (0) | 2022.12.07 |
MySQL - like 검색기능 (0) | 2022.12.07 |