본문 바로가기

SQL

sql 문제 한 번 성공하니까 계속 풀려진다!!

728x90
SET @a = (SELECT x FROM house_locations WHERE owner = 'KHS');
SET @b = (SELECT y FROM house_locations WHERE owner = 'KHS');

SELECT owner, abs(x - @a) + abs(y - @b) as DISTANCE
from house_locations
order by distance desc limit 1

역시 도전의 중요성!!

 

set @a = -1;

SELECT 
    (@a := @a + 1) as 구분,
    sum(if(amount > 0, amount, 0)) as 금액
from card_usages

union all

SELECT 
    (@a := @a + 1) as 구분,
    abs(sum(if(amount < 0, amount, 0))) as 금액
from card_usages

그리고 이 두문제는 나름 해석이 필요한데 추후에 풀이할 것임

728x90