Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
Tags
- DataFrame
- matplotlib
- list
- hierarchical_clustering
- append()
- elbow method
- Dictionary
- 분류 결과표
- del
- string
- Python
- numpy
- insert()
- dendrogram
- function
- pandas
- data
- 반복문
- count()
- 최댓값
- analizer
- nan
- 덴드로그램
- 최솟값
- sklearn
- wcss
- DataAccess
- len()
- IN
- Machine Learning
Archives
- Today
- Total
개발공부
[MySQL] 데이터 중복 없이 선택 distinct, 데이터 정렬 order by 본문
books 테이블

중복 없이 선택하기 distinct
author_fname의 이름을 중복없이 가져오기
select distinct author_lname
from books;

작가의 full name을 중복없이 가져오기
select distinct concat(author_fname, ' ', author_lname) as full_name
from books;

데이터 정렬하기 order by
order by 컬럼명
오름차순(디폴트) asc
내림차순 desc
sql문의 제일 마지막에 쓴다.
title로 정렬하기
-- 오름차순
select * from books
order by title;

-- 내림차순
select * from books
order by title desc;

author_lname 으로 정렬을 하고, 이 author_lname 이 같으면
author_fname 으로 정렬하기
asc는 생략가능
select * from books
order by author_lname asc , author_fname desc;

'Database > MySQL' 카테고리의 다른 글
| [MySQL] 데이터 별로 묶기 group by, 데이터의 개수 count(), 합계 sum() 최댓값 max(), 최솟값 min(), 평균 값 avg() (0) | 2022.05.16 |
|---|---|
| [MySQL] 원하는 행 가져오기 limit, 문자열 검색 like (0) | 2022.05.16 |
| [MySQL] 문자열 교체 replace(), 거꾸로 변경 reverse(), 길이 구하기 char_length(), 대소문자 변경 upper(), lower() (0) | 2022.05.16 |
| [MySQL] 문자열의 일부분만 가져오기 substr(), substring() (0) | 2022.05.16 |
| [MYSQL] 컬럼 합치기 concat(), concat_ws() (0) | 2022.05.16 |