2017-08-15 52 views
1

我有一个包含一组地址的地理编码数据的表。问题在于经度和纬度存储在同一列中,但在同一个表中的另一列中通过代码(0或1)进行区分。每个地址都标有一个在列中出现两次的唯一ID(1表示拉特,1表示长)。SQL:将编码行存储为给定ID的单独列

我想在同一行显示纬度和长度作为单独的列以及相应的ID。

+2

显示一些样品数据和期望输出。 –

+0

没有样品很难成像。 –

回答

0
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 
+0

谢谢!我在另一个线程中看到了类似的提示,但我无法使其工作。开始了,这工作,所以我一定有问题的地方。 – themorethelarrier

0
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 
相关问题