본문 바로가기
💻 하나씩 차곡차곡/프로그래머스 (SQL)

[GROUP BY/LEVEL2] 노선별 평균 역 사이 거리 조회하기 (MySQL)

by 뚜루리 2024. 11. 26.
728x90
320x100

MySQL

SELECT 
      ROUTE
    , CONCAT(ROUND(SUM(D_BETWEEN_DIST), 1), 'km') AS TOTAL_DISTANCE
    , CONCAT(ROUND(AVG(D_BETWEEN_DIST), 2), 'km') AS AVERAGE_DISTANCE
FROM SUBWAY_DISTANCE
GROUP BY ROUTE
ORDER BY ROUND(SUM(D_BETWEEN_DIST), 1) DESC;

 

728x90
320x100