Sort Results Part 1
Coddy SQL 여정의 기초 섹션에 포함된 레슨 — 72개 중 13번째.
데이터베이스를 쿼리할 때, 결과를 의미 있는 순서로 정리하면 데이터 분석이 훨씬 더 효율적일 수 있습니다. 결과를 정렬하기 위해 ORDER BY 키워드를 사용하며, 그 후에 어떤 필드를 기준으로 정렬할지 지정해야 합니다. 기본적으로 오름차순으로 정렬합니다.
예를 들어 다음 <strong>competition</strong> 테이블을 고려해 보세요:
| runner_id | age | avg_speed |
|---|---|---|
| 1 | 47 | 3.65 |
| 2 | 62 | 3.07 |
| 3 | 57 | 6.82 |
| 4 | 56 | 4.34 |
| 5 | 25 | 4.93 |
| 6 | 40 | 3.94 |
| 7 | 23 | 6.58 |
| 8 | 40 | 3.43 |
SELECT *
FROM competition
WHERE age > 50
ORDER BY avg_speed이것은 결과입니다
| runner_id | age | avg_speed |
|---|---|---|
| 2 | 62 | 3.07 |
| 4 | 56 | 4.34 |
| 3 | 57 | 6.82 |
그 데이터를 정렬하는 방법을 지정하려면 열 이름 뒤에 DESC 또는 ASC 키워드를 추가할 수 있습니다.
ORDER BY avg_speed ASC챌린지
쉬움사용 가능한 테이블과 열:
<strong>feathers</strong>:<strong>id</strong>,<strong>weight</strong>
weight를 내림차순으로 정렬한 후 모든 id를 반환하세요
치트 시트
ORDER BY를 사용하여 쿼리 결과를 정렬하세요. 기본적으로 오름차순으로 정렬됩니다:
SELECT *
FROM table_name
ORDER BY column_name정렬 방향을 지정하려면 ASC (오름차순) 또는 DESC (내림차순)을 추가하세요:
ORDER BY column_name DESC
ORDER BY column_name ASC직접 해보기
이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
기초의 모든 레슨
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns