45. QuadKey To ○○ に落とし込む
● 「各市町村の人口」を求めるなら
○ QuadKey to 人口
○ QuadKey to 市町村
● 「各市町村の傾斜地に住んでいる人口」を求めるなら
○ QuadKey to 人口
○ QuadKey to 市町村
○ QuadKey to 傾斜
JOINで様々な組み合わせの集計ができる!
48. 傾斜度ごとの人口
select q.commune, sum("0-5"), sum("5-10"), sum("10-15"), sum("15-20"), sum("20-25"), sum("25-30"), sum("30-") from
(select * from mesh_population join (select inclination.qkey,
case when inclination.value between 0 and 5 then mesh_population.value else 0 end as "0-5",
case when inclination.value between 5 and 10 then mesh_population.value else 0 end as "5-10",
case when inclination.value between 10 and 15 then mesh_population.value else 0 end as "10-15",
case when inclination.value between 15 and 20 then mesh_population.value else 0 end as "15-20",
case when inclination.value between 20 and 25 then mesh_population.value else 0 end as "20-25",
case when inclination.value between 25 and 30 then mesh_population.value else 0 end as "25-30" ,
case when inclination.value > 30 then mesh_population.value else 0 end as "30-"
from mesh_population join inclination on inclination.qkey = mesh_population.qkey) as inclination
on inclination.qkey = mesh_population.qkey) as mp
inner join (select * from commune_qkey as cq inner join communes as c on c.commune_id = cq.commune_id) as q
on mp.qkey = q.qkey
group by q.commune
53. 計算結果のDBに対するクエリ
select airport_id, sum(value) from (select a.qkey,
p.value, a.hospital_id from airports as a join
mesh_population as p on p.qkey = a.qkey and
ranking = 0) group by airport_id