문제링크 : [8 kyu]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:
time = 3 —-> litres = 1
time = 6.7—> litres = 3
time = 11.8–> litres = 5
You have to return 3 columns: id, hours and liters (not litres, it’s a difference from the kata description)
SELECT id, hours, trunc(hours* 0.5) AS liters FROM cycling
구글링해서 trunc이 소수점 버림이라는 것을 알고 해결했다.
SELECT *, floor(hours / 2) as liters FROM cycling
정수값만 나오게 해서 소수점을 제거 했다.
ALTER TABLE cyclingADD COLUMN liters INTEGER;UPDATE cyclingSET liters=FLOOR(hours*0.5);SELECT * FROM cycling;
codewars SQL 문제는 테이블 수정해서 할 수가 있구나…