在此查询中:
select *
from
(
select distinct a.id as 'Id Documento',
b.valor, 'index'+cast(row_number() over(partition by a.id order by b.idIndice) as varchar(10)) rn
from tgpwebged.dbo.sistema_Documentos as a
join tgpwebged.dbo.sistema_Indexacao as b on a.id = b.idDocumento
join tgpwebged.dbo.sistema_DocType as c on a.idDocType = c.id
join tgpwebged.dbo.sistema_DocType_Index as d on c.id = d.docTypeId
where d.docTypeId = 40
and (b.idIndice = 11 AND b.valor = '11111111' OR b.idIndice = 12 AND b.valor = '11111')
) src
pivot
(
max(valor)
for rn in (Index1, Index2)
) piv
我有这个:
id Documento Index1 Index2
我需要
id Documento 11 12
二。我正在
Id Documento Index1 Index2
13 11111111 11111111
14 11111111 11111111
16 11111 11111
混合值......值'11111111'应该在Index1列上,'11111'应该在Index2列上。
我该怎么办?