tengo una tabla llamada tblAccInfo, a continuación es la tabla de datos. Necesito resultados como a continuación.Auto unirse tema
Input
PolicyNumber BankAc StorageDate VerNum
400 123 2012-01-01 1
400 164 2012-01-03 2
400 860 2012-01-05 3
6004317654 301 2012-02-05 1
6004317654 615 2012-03-01 2
6004317654 253 2012-03-12 3
6004317654 887 2012-04-03 4
SALIDA
PolicyNumber IntialBankAc IntialSDate VerNum LatestBankAc LatestSDate VerNum
400 123 2012-01-01 1 860 2012-01-05 3
6004317654 301 2012-02-05 1 887 2012-04-03 4
He tratado con uno mismo a continuación se unen, pero no conseguido. Por favor, ayúdame en esto.
Select DISTINCT
P.PolicyNumber,
P.BankAc [IntialBankAc],
P.StorageDate IntialSDate],
P.VerNum,
P1.BankAc [LatestBankAc],
P1.StorageDate [LatestSDate],
P1.VerNum
FROM tblAccInfo P
INNER JOIN tblAccInfo P1
ON P1.PolicyNumber=P.PolicyNumber
AND (P.BankAc<>P1.BankAc AND P.StorageDate<>P1.StorageDate AND P.VerNum<>P1.VerNum)
@ Marcos Byers Muchísimas gracias por el formato. – Simhadri
De nada. Por favor, intente hacerlo usted mismo en el futuro sin embargo. –
Lo intenté varias veces, sugiera la mejor manera de formatear tablas especialmente. – Simhadri