如何合并具有相同ID的两行

时间:2019-06-02 13:55:30

标签: sql

我尝试在同一行中包含1.飞行员名称和2.飞行员名称。 我试图进行分组,但无法成功

SELECT PILOT_INFO.[1. Pilot], PILOT_INFO.[2. Pilot], T_UCUS_KAYIT_PILOT.ID,
	   dbo.T_UCUS_KAYIT_PILOT.BASLAMA_ZAMANI, dbo.T_UCUS_KAYIT_PILOT.BITIS_ZAMANI, dbo.T_UCUS_KAYIT_PILOT.GERCEK_UCUS_MUDDETI, 
       dbo.T_UCUS_KAYIT_PILOT.PILOT_MULAHAZASI
FROM  
 ( SELECT  Pilot1 AS '1. Pilot', Pilot2 AS '2. Pilot', Pilot3 AS 'Öğretmen Pilot', Pilot4 AS 'Test-Te crübe Pilotu', ID
FROM  
 (SELECT  PilotBilgi.PILOT_TIPI_ID, Pilot.ID, 'Pilot' + CAST(PilotBilgi.PILOT_TIPI_ID AS VARCHAR(10)) AS GOREVID, Pilot.ADI + ' ' + Pilot.SOYADI AS AdSoyad
FROM    dbo.T_PILOT AS Pilot CROSS JOIN
        dbo.T_PILOT_TIPI AS PilotTipi CROSS JOIN
        dbo.T_PILOT_PILOT_TIPI AS PilotBilgi
WHERE  (PilotBilgi.PILOT_ID = Pilot.ID AND PilotTipi.ID = PilotBilgi.PILOT_TIPI_ID ) GROUP BY PilotBilgi.PILOT_TIPI_ID, Pilot.ID,PilotBilgi.PILOT_TIPI_ID,Pilot.ADI,Pilot.SOYADI) TMP
        PIVOT (MAX(AdSoyad) FOR GOREVID IN (Pilot1, Pilot2, Pilot3, Pilot4)) PIV)       
	    AS PILOT_INFO CROSS JOIN
        dbo.T_UCUS_KAYIT_PILOT
WHERE PILOT_INFO.ID = dbo.T_UCUS_KAYIT_PILOT.PILOT_ID OR PILOT_INFO.ID = dbo.T_UCUS_KAYIT_PILOT.PILOT_2ID GROUP BY PILOT_INFO.[1. Pilot], PILOT_INFO.[2. Pilot], T_UCUS_KAYIT_PILOT.ID,
	   dbo.T_UCUS_KAYIT_PILOT.BASLAMA_ZAMANI, dbo.T_UCUS_KAYIT_PILOT.BITIS_ZAMANI, dbo.T_UCUS_KAYIT_PILOT.GERCEK_UCUS_MUDDETI,
       dbo.T_UCUS_KAYIT_PILOT.PILOT_MULAHAZASI
[NULL,	          Pilot_2 Soyad_2,	 2]
[NULL,	          Pilot_6 Soyad_6,	 5]
[Pilot_1 Soyad_1,	           NULL,	 2]
[Pilot_5 Soyad_5,	           NULL,	 5] 
this is result of my query.

0 个答案:

没有答案