본문 바로가기

SQL69

Beginner Series #2 Clock Clock shows h hours, m minutes and s seconds after midnight. Your task is to write a function which returns the time since midnight in milliseconds. Example: h = 0 m = 1 s = 1 result = 61000 Input constraints: 0 2022. 5. 22.
SQL Basics: Simple SUM For this challenge you need to create a simple SUM statement that will sum all the ages. people table schema id name age select table schema age_sum (sum of ages) Solution: SELECT SUM(age) AS age_sum FROM people; Result: age_sum 5451 2022. 5. 21.
Returning Strings Write a select statement that takes name from person table and return "Hello, how are you doing today?" results in a column named greeting [Make sure you type the exact thing I wrote or the program may not execute properly] Solution: SELECT concat('Hello, ', name, ' how are you doing today?') AS greeting FROM person concat appends string arguments. '||' By using symbols, the same result can be a.. 2022. 5. 20.
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.
SQL Basics: Simple DISTINCT For this challenge you need to create a simple DISTINCT statement, you want to find all the unique ages. people table schema id name age select table schema age (distinct) NOTE: Your solution should use pure SQL. Ruby is used within the test cases to do the actual testing. Solution: SELECT DISTINCT age FROM people; DISTINCT excludes duplicate values ​​of the corresponding column. 2022. 5. 18.
Easy SQL: Square Root and Log Given the following table 'decimals': ** decimals table schema ** id number1 number2 Return a table with two columns (root, log) where the values in root are the square root of those provided in number1 and the values in log are changed to a base 10 logarithm from those in number2. Solution: SELECT SQRT(number1) AS root, LOG(number2) FROM decimals; SQRT is a function that finds the square root. .. 2022. 5. 17.