Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

top_half schema id heads arms bottom_half schema id legs tails You must return a

ID: 3885074 • Letter: T

Question

top_half schema

id

heads

arms

bottom_half schema

id

legs

tails

You must return a table with the format as follows:

output schema

id

heads

legs

arms

tails

species

The IDs on the tables match to make a full monster. For heads, arms, legs and tails you need to draw in the data from each table.

For the species, if the monster has more heads than arms AND/OR more tails than legs, it is a 'BEAST' else it is a 'WEIRDO'. This needs to be captured in the species column.

All rows should be returned (10).

Tests require the use of CASE. Order by species.

Please use pure SQL, only testing is done in Ruby.

please fix the case statement

select *,'example' AS species from top_half inner join bottom_half on top_half.id = bottom_half.id order by heads (CASE
WHEN heads > arms THEN species.example = 'beast'
when tails > legs then species.example = 'beast'
else species.example = 'weirdo'
END);

Explanation / Answer

You have to order by species instead of heads as you wrote in the query,

The correct query is

select *,
       CASE
          WHEN heads > arms THEN 'beast'
          when tails > legs then 'beast'
          else 'weirdo'
       END    As Species
from top_half
inner join bottom_half
on top_half.id = bottom_half.id
ORDER BY species