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);
-- 정렬하는 방법 : order by 키워드
-- author_lname으로 정렬 ( 위치가 중요 )
select *
from books
order by author_lname;
-- full name으로 정렬하세요. (SQL 동작 방식을 이해)
select id,title,concat(author_fname,' ',author_lname) as full_name ,released_year,
stock_quantity,pages
from books
order by full_name;
-- 내림차순으로 정렬 ( desc )
- full name 내림차순으로 정렬
select id,title,concat(author_fname,' ',author_lname) as full_name ,released_year,
stock_quantity,pages
from books
order by full_name desc;
-- 오름차순 정렬 ( 아무것도 쓰지 않거나 , asc )
-- author_lname으로 정렬하되, 이름이 같으면 author_fname으로 정렬하시오.
select *
from books
order by author_lname , author_fname;
위 정렬 방식 두개를 한 번에 사용하는 방법
-- author_lname으로 정렬하되, author_lname은 내림차순
-- author_fname은 오름차순으로 정렬하시오.
select *
from books
order by author_lname desc, author_fname asc;
'MySQL' 카테고리의 다른 글
MySQL - like 검색기능 (0) | 2022.12.07 |
---|---|
MySQL - limit 데이터를 나눠서 가져오는 방법 (0) | 2022.12.07 |
MySQL - distinct 중복 없는 데이터 보기 (0) | 2022.12.07 |
MySQL - 문자열 컬럼의 데이터를 가공하는 여러함수들 예제풀이 (0) | 2022.12.06 |
MySQL - upper( ) , lower( ) / 대소문자 변경하는 함수 (0) | 2022.12.06 |