2016-07-13 2 views
-1

첫 번째 스크린 샷과 같은 Oracle보기 (여러 테이블에서 조인 됨)가 있습니다. address_type은 항상 owner 또는 property 여야합니다. 두 번째 스크린 샷과 같은 결과를 얻고 싶습니다. SQL을 사용하여이를 수행하는 방법? 죄송합니다. 저는 SQL 초보자입니다.sql 행을 행으로 조 변경하려면

enter image description here

+2

가능한 여러 개의 [SQL Server 피벗 테이블 여러 열 집계] (http://stackoverflow.com/questions/14694691/sql-server-pivot-table-with-multiple-column-aggregates) –

+0

중복이 아님 왜냐하면 그들은 '피벗 (pivot)'문장을 알지 못했기 때문에, 그렇습니다. –

+1

어떤 DMBS를 사용하고 있습니까? –

답변

1

당신은 내부 사용할 수 있습니다

enter image description here

가입 :

select tab1.address_id, tab1.address as owner_address, 
     tab1.city as owner_city, tab1.state as owner_state, 
     tab1.zip as owner_zip, tab2.address as property_address, 
     tab2.city as property_city, tab2.state as property_state, 
     tab2.zip as property_zip 
from tab1 
full outer join tab2 
on tab1.address_id = tab2.address_id 
where tab1.address_type = 'owner' 
     and tab2.address_type = 'property' 

TAB1 모든 소유자에게 정보, 모든 재산 정보를 포함 TAB2가 포함되어 있습니다. address_id를 사용하여 가입 할 수 있습니다.

죄송합니다. 테스트 할 수 없습니다.

+0

감사합니다. 약간의 사소한 변화. 나는 당신의 코드와 함께 작동시킬 수있었습니다. –

관련 문제