Oracle
計算條件 >=15 的道路百分比(按長度)
我有一張路況表:
CONDITION LENGTH 2 5 4 10 6 15 8 20 10 25 12 30 14 35 16 40 18 45 20 50
狀況為15 或更高(又名)的道路
15_OG
被認為狀況良好。我想計算狀況良好的道路百分比(按長度) 。
LENGTH_15_OG TOTAL_LENGTH PERCENT_15_OG 135 275 49.09%
我該怎麼做這個計算?
只需稍作修改即可保存 1 個表訪問:
select length_15_og, total_length, round(length_15_og/total_length*100, 2) as percent_15_og from ( select sum(case when condition >= 15 then length end) as length_15_og, sum(length) as total_length from road_condition );
會有其他解決方案 - 但如何……
select length_15_og , total_length , round( length_15_og / total_length * 100, 2 ) as percent_15_og from ( select ( select sum( length ) from road_condition where condition >= 15 ) as length_15_og , ( select sum( length ) from road_condition ) as total_length from dual ) ; -- result LENGTH_15_OG TOTAL_LENGTH PERCENT_15_OG 135 275 49.09