多表结合使用SQL PIVOT表

时间:2019-04-07 21:09:20

标签: sql

我的数据集中有多个表。我需要将一个表中的两列绕另一张表中的一列进行旋转。

代码:

  SELECT DISTINCT 

  table1.name,  

  table6.count,
  table6.car_name 


From Master_Table   

Inner Join table1 
        On Master_Table.ID_SEQNO = table1.ID_SEQNO
Inner Join table2 
        On table1.table1_ID_SEQNO = table2.table1_ID_SEQNO

Inner Join table3
        On table2.ID_SEQNO = table3.ID_SEQNO

Inner Join table4
        On table3.ID_SEQNO = table4.ID_SEQNO



Left Outer Join table5
        On table4.CANDIDATE_ID_SEQNO = table5.CANDIDATE_ID_SEQNO

Left Outer Join table6
        On table5.ID_SEQNO = table6.ID_SEQNO


ORDER BY table1.name  

我需要的输出:

enter image description here

我现在拥有的是:

enter image description here

Master_Table : Has names , Date, Time of ownership etc
table1 has info on each name , adress phone number email etc
 table2 has info like cars insurance etc so on... I have used id_seqno to join statements without which the code doesn't work.

每个表都有一个id_seqno,我可以将其映射到其他每个表...我正在修改现有代码,对此非常新。

0 个答案:

没有答案