Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7a77344

Browse files
committed
Add a question
1 parent 19226d6 commit 7a77344

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎README.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,3 +1557,37 @@ ON employee.team_id = team.team_id;
15571557
---
15581558

15591559
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**
1560+
1561+
## 46. Monsters using CASE
1562+
1563+
You have access to two tables `top_half` and `bottom_half`. Write a SQL query to return the results as outlined below. The IDs on the tables match to make a full monster. For the `species`, if the monster has more heads than arms or more tails than legs, it is a `BEAST`, else it is a `WEIRDO`. Order your results by `species`.
1564+
1565+
```
1566+
top_half bottom_half output
1567+
-------- ----------- ------
1568+
id id id
1569+
heads legs heads
1570+
arms tails legs
1571+
arms
1572+
tails
1573+
species
1574+
```
1575+
1576+
<details><summary>Solution</summary>
1577+
1578+
```sql
1579+
SELECT T.id, heads, legs, arms, tails,
1580+
CASE
1581+
WHEN heads > arms OR tails > legs THEN 'BEAST'
1582+
ELSE 'WEIRDO'
1583+
END AS species
1584+
FROM top_half T JOIN bottom_half B
1585+
ON T.id = B.id
1586+
ORDER BY species;
1587+
```
1588+
1589+
</details>
1590+
1591+
---
1592+
1593+
**[⬆ Back to Top](#sql-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /