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);
1. 제목에 stories가 포함된 데이터를, 제목만 조회하시오.
select *
from books
where title like '%stories%';
2. 페이지 수가 가장 긴 책을 찾아서, 제목과 페이지 수를 조회하시오.
select title,pages
from books
order by pages desc
limit 1;
3. 가장 최근에 발간된 책 3권을 찾아서, 책의 제목과 발간년도를 조회하되, 다음처럼 하이픈(-)을 붙여서 조회하시오. ( 컬럼 명은 summary )
select concat(title,' - ',released_year) as summary
from books
order by released_year desc
limit 3;
4. author_lname에 공백이 들어있는 사람의, 책제목과 author_lname을 조회
select title,author_lname
from books
where author_lname like '% %';
5. 가장 stock_quantity가 적은 책 3권의 title,year,stock_quantity를 조회하시오.
select title,released_year,stock_quantity
from books
order by stock_quantity
limit 3;
6. author_lname과 title로 정렬한 후, title과 author_lname을 조회하시오.
select title,author_lname
from books
order by author_lname;
7. author_lname으로 정렬하되, 'MY FAVORITE AUTHOR IS'를 붙여서 조회하시오.
select upper(concat('MY FAVORITE AUTHOR IS',' ',author_fname,' ',author_lname,'!')) as yell
from books
order by author_lname;
동작하는 방식을 이해하고,
순서에 맞게 요구사항을 잘 풀어가야합니다.
'MySQL' 카테고리의 다른 글
MySQL - count() 데이터 개수 확인하기,group by 그룹화 하여 데이터를 처리하기 (0) | 2022.12.07 |
---|---|
MySQL - 최대값 max() ,최소값 min() , sub query (0) | 2022.12.07 |
MySQL - like 검색기능 (0) | 2022.12.07 |
MySQL - limit 데이터를 나눠서 가져오는 방법 (0) | 2022.12.07 |
MySQL - 정렬하기(order by) / 오름차순(asc), 내림차순(desc) (0) | 2022.12.07 |