Given a demographics table in the following format:
** demographics table schema **
- id
- name
- birthday
- race
you need to return a table that shows a count of each race represented, ordered by the count in descending order as:
** output table schema **
- race
- count
Solution:
SELECT
race,
COUNT(id)
FROM
demographics
GROUP BY race
ORDER BY count DESC
Result:
| race | count |
| American Indian or Alaska Native | 23 |
| Asian | 22 |
| White | 19 |
| Black or African American | 18 |
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
| SQL with Harry Potter: Sorting Hat Comparators (0) | 2022.07.01 |
|---|---|
| SQL Basics: Truncating (0) | 2022.06.30 |
| Countries Capitals for Trivia Night (SQL for Beginners #6) (0) | 2022.06.28 |
| First and last IP in a network (0) | 2022.06.27 |
| SQL Basics - Trimming the Field (0) | 2022.06.26 |