我有一個包含一組地址的地理編碼數據的表。問題在於經度和緯度存儲在同一列中,但在同一個表中的另一列中通過代碼(0或1)進行區分。每個地址都標有一個在列中出現兩次的唯一ID(1表示拉特,1表示長)。SQL:將編碼行存儲爲給定ID的單獨列
我想在同一行顯示緯度和長度作爲單獨的列以及相應的ID。
我有一個包含一組地址的地理編碼數據的表。問題在於經度和緯度存儲在同一列中,但在同一個表中的另一列中通過代碼(0或1)進行區分。每個地址都標有一個在列中出現兩次的唯一ID(1表示拉特,1表示長)。SQL:將編碼行存儲爲給定ID的單獨列
我想在同一行顯示緯度和長度作爲單獨的列以及相應的ID。
select unique_id,
max(case when code = 0 then geocoded_column end) as lat,
max(case when code = 1 then geocoded_column end) as long
from geocoded_table
group by unique_id
謝謝!我在另一個線程中看到了類似的提示,但我無法使其工作。開始了,這工作,所以我一定有問題的地方。 – themorethelarrier
with ttt as (
select 111 ID, '54.65548' coords, 1 def from dual
union all
select 111 ID, '-34.8456' coords, 0 def from dual
)
select t1.ID, t1.coords, t2.coords
from ttt t1
join ttt t2 ON t1.ID = t2.ID
and t1.def <> t2.def
and t1.def = 1 -- or t1.def = 0 if you want change order of coords
顯示一些樣品數據和期望輸出。 –
沒有樣品很難成像。 –