나는 이렇게 학습한다/Algorithm & SQL

Even or Odd

daco2020 2022. 5. 19. 22:29
반응형

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 ~'.

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

SQL Basics: Simple SUM  (0) 2022.05.21
Returning Strings  (0) 2022.05.20
SQL Basics: Simple DISTINCT  (0) 2022.05.18
Easy SQL: Square Root and Log  (0) 2022.05.17
Collect Tuition (SQL for Beginners #4)  (0) 2022.05.16