반응형
You have arrived at the Celadon Gym to battle Erika for the Rainbow Badge.
She will be using Grass-type Pokemon. Any fire pokemon you have will be strong against grass, but your water types will be weakened. The multipliers table within your Pokedex will take care of that.
Using the following tables, return the pokemon_name, modifiedStrength and element of the Pokemon whose strength, after taking these changes into account, is greater than or equal to 40, ordered from strongest to weakest.
pokemon schema
- id
- pokemon_name
- element_id
- str
multipliers schema
- id
- element
- multiplier
Solution:
SELECT
p.pokemon_name,
p.str*m.multiplier AS modifiedstrength,
m.element
FROM
pokemon AS p
JOIN
multipliers AS m
ON p.element_id = m.id
WHERE
p.str*m.multiplier >= 40
ORDER BY modifiedstrength DESC
Result:
pokemon_name | modifiedstrength | element |
Vulpix | 51.25 | Fire |
Weezing | 48.75 | Fire |
Clefairy | 47.5 | Fire |
Dratini | 45 | Fire |
Venomoth | 43.75 | Fire |
Magneton | 43.75 | Fire |
Koffing | 43 | Grass |
Tentacool | 43 | Normal |
Electrode | 42 | Grass |
Kangaskhan | 40 | Normal |
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
GROCERY STORE: Support Local Products (0) | 2022.07.07 |
---|---|
SQL with Sailor Moon: Thinking about JOINs... (0) | 2022.07.06 |
SQL: Concatenating Columns (0) | 2022.07.04 |
SQL easy regex extraction (0) | 2022.07.03 |
SQL: Regex String to Table (0) | 2022.07.03 |