SQL69 Keep Hydrated! Nathan loves cycling. Because Nathan knows it is important to stay hydrated, he drinks 0.5 litres of water per hour of cycling. You get given the time in hours and you need to return the number of litres Nathan will drink, rounded to the smallest value. For example: hours = 3 ----> liters = 1 hours = 6.7---> liters = 3 hours = 11.8--> liters = 5 You have to return 3 columns: id, hours and liters.. 2022. 6. 12. 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. SQL with LOTR: Elven Wildcards Deep within the fair realm of Lothlórien, you have been asked to create a shortlist of candidates for a recently vacated position on the council. Of so many worthy elves, who to choose for such a lofty position? After much thought you decide to select candidates by name, which are often closely aligned to an elf's skill and temperament. Choose those with tegil appearing anywhere in their first n.. 2022. 6. 10. SQL Basics: Raise to the Power Given the following table 'decimals': decimals table schema id number1 number2 Return a table with a single column result which is the output of number1 raised to the power of number2. Solution: SELECT POWER(number1, number2) as result FROM decimals The 'POWER' function returns the value raised to the power of the first argument by the second argument. 2022. 6. 9. BASICS: Length based SELECT with LIKE You will need to create SELECT statement in conjunction with LIKE. Please list people which have first_name with at least 6 character long names table schema id first_name last_name results table schema first_name last_name Solution: SELECT first_name, last_name FROM names WHERE first_name LIKE '______%' Percent Sign (%): represents zero or more unspecified characters Under Score(_) : Represents.. 2022. 6. 8. SQL Basics: Repeat and Reverse Using our monsters table with the following schema: monsters table schema id name legs arms characteristics return the following table: ** output schema** name characteristics Where the name is the original string repeated three times (do not add any spaces), and the characteristics are the original strings in reverse (e.g. 'abc, def, ghi' becomes 'ihg ,fed ,cba'). Solution: SELECT REPEAT(name,3.. 2022. 6. 7. 이전 1 ··· 4 5 6 7 8 9 10 ··· 12 다음