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

Keep Hydrated!

daco2020 2022. 6. 12. 22:26
반응형

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 (not litres, it's a difference from the kata description)

 

 

 

Solution:

SELECT 
  id, hours, FLOOR(hours/2) AS liters 
FROM 
  cycling

 

 

Result:

id hours liters
1 4.46 2
2 58.07 29
3 99.42 49
4 96.11 48
5 92.6 46

 

 

 

반응형

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

SQL with Street Fighter: Total Wins  (0) 2022.06.14
SQL Basics: Simple GROUP BY  (0) 2022.06.13
Opposite number  (0) 2022.06.11
SQL with LOTR: Elven Wildcards  (0) 2022.06.10
SQL Basics: Raise to the Power  (0) 2022.06.09