본문 바로가기

When4

SQL Basics - Monsters using CASE You have access to two tables named top_half and bottom_half, as follows: 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 .. 2022. 7. 12.
SQL Basics: Up and Down Given a table of random numbers as follows: numbers table schema id number1 number2 Your job is to return table with similar structure and headings, where if the sum of a column is odd, the column shows the minimum value for that column, and when the sum is even, it shows the max value. You must use a case statement. output table schema number1 number2 Solution: SELECT CASE WHEN MOD(SUM(number1).. 2022. 6. 21.
Opposite number Very simple, given an integer or a floating-point number, find its opposite. Examples: 1: -1 14: -14 -34: 34 You will be given a table: opposite, with a column: number. Return a table with a column: res. Solution: SELECT number * -1 AS res FROM opposite Below is a method to solve uselessly and difficultly using CASE and SIGN. The 'SIGN' function tells whether the number is negative or positive w.. 2022. 6. 11.
Even or Odd SQL Notes: You will be given a table, numbers, with one column number. Return a table with a column is_even containing "Even" or "Odd" depending on number column values. numbers table schema number INT output table schema is_even STRING Solution: SELECT CASE WHEN number%2=0 THEN 'Even' ELSE 'Odd' END AS is_even FROM numbers In psql, 'if' is 'case when ~ then ~ else ~'. 2022. 5. 19.