[SQL문제풀기] 노선별 평균 역 사이 거리 조회하기(GROUP BY)

241213
이나겸's avatar
Dec 13, 2024
[SQL문제풀기] 노선별 평균 역 사이 거리 조회하기(GROUP BY)
Contents
Q.풀이

Q.

notion image
 
 

풀이

  • concat() : 문자열 합치기
  • round(반올림할 대상 숫자, 반올림할 자릿수 ) : 반올림
    • 소수 둘째점 자리에서 반올림 : round(숫자, 1)
    • 소수 셋째점 자리에서 반올림 : round(숫자, 2)
  • sum() : 합
  • avg() : 평균
  • order by ~ desc : 내림차순 정렬
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 sum(d_between_dist) desc;
Share article

Nakyeom's Study