我在我的PostgreSQL 9.5數據庫中有一個表(12行),它有兩列ID和幾何。來自PgAdmin3的表格結構是:更新PostgreSQL的下限和上限
CREATE TABLE public.my_table
(
id integer,
geom geometry
)
幾何圖形表示三角形從正北開始,ID爲1等等。每行的ID是唯一的,即1 - 12.基於這個ID,我試圖更新角度及其下限和上限。我的方法是:
Select
id,
Case when id = 1 then 30
when id = 2 then 60
when id = 3 then 90
when id = 4 then 120
when id = 5 then 150
when id = 6 then 180
when id = 7 then 210
when id = 8 then 240
when id = 9 then 270
when id = 10 then 300
when id = 11 then 330
when id = 12 then 360
end as angle,
case when id = 1 then lower(numrange(0, 30))
when id = 2 then lower(numrange(30, 60))
when id = 3 then lower(numrange(60, 90))
when id = 4 then lower(numrange(90, 120))
when id = 5 then lower(numrange(120, 150))
when id = 6 then lower(numrange(150, 180))
when id = 7 then lower(numrange(180, 210))
when id = 8 then lower(numrange(210, 240))
when id = 9 then lower(numrange(240, 270))
when id = 10 then lower(numrange(270, 300))
when id = 11 then lower(numrange(300, 330))
when id = 12 then lower(numrange(330, 360))
end as lb
from my_table
有沒有更好的方法來做到這一點?任何指針將高度讚賞。
請將表格定義添加到帖子 –
@VaoTsun:請參閱編輯。從pgAdmin3添加了表結構。 –