There is truly no magic in the world; the Hogwarts Sorting Hat is SQL-based, its decision-making powers are common operators and prospectIve students are merely data - names, and two columns of qualities.
students
- id
- name
- quality1
- quality2
Slytherin are being quite strict this year and will only take students who are evil AND cunning.
Gryffindor will take students who are brave but only if their second quality is NOT evil.
Ravenclaw accepts students who are studious OR intelligent.
Hufflepuff will simply take those who have the quality hufflepuff.
(don't worry, for simplicity's sake 'brave' and 'studious' will only appear in quality1, and 'cunning' and 'intelligent' will only appear in quality2.)
Return the id, name, quality1 and quality2 of all the students who'll be accepted, ordered by ascending id.
Solution:
SELECT
*
FROM
students
WHERE
(quality1='brave' OR quality1='studious') OR (quality2='cunning' OR quality2='intelligent')
ORDER BY id
Result:
id | name | quality1 | quality2 |
2 | Boyce Kulas II | brave | daring |
7 | Leilani Roberts | materialistic | cunning |
8 | Rep. Kieth Ankunding | devious | cunning |
27 | Roslyn Kovacek | brave | daring |
28 | Sen. Denis Schneider | evil | cunning |
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
SQL easy regex extraction (0) | 2022.07.03 |
---|---|
SQL: Regex String to Table (0) | 2022.07.03 |
SQL Basics: Truncating (0) | 2022.06.30 |
Easy SQL: Counting and Grouping (0) | 2022.06.29 |
Countries Capitals for Trivia Night (SQL for Beginners #6) (0) | 2022.06.28 |