SQL Server 2008에 코드가 있고 다른 행에 조인해야합니다. SQL Server : 한 행에 두 행
이
코드select
usuario.SK_Representative,
sum(devo.NM_Material) as deve
from
DW_DTS_Representative usuario
inner join
DIS_DTS_Sales_Return_Fact devo on devo.SK_Representative = usuario.SK_Representative
inner join
DW_DTS_Operation_Nature cfop on cfop.SK_Operation_Nature = devo.SK_Operation_Nature
inner join
DW_DTS_Emitter cli on cli.SK_Emitter = devo.SK_Emitter
where
devo.CD_Currency = '0'
and devo.CD_Site = '001'
and cli.CD_Customer_Group = '10'
and usuario.SK_Representative != '2'
and usuario.SK_Representative != '3'
and usuario.SK_Representative != '4'
and usuario.SK_Representative != '41'
and usuario.SK_Representative != '48'
and usuario.SK_Representative != '49'
and usuario.SK_Representative != '43'
and devo.DT_Day between DateAdd(yyyy, DateDiff(yyyy,0,GetDate()), 0)
and dateadd([month], datediff([month], '18991231', dateadd(month, -1, getdate())), '18991231')
group by
usuario.SK_Representative
입니다
해당 스크립트의 결과는 다음과 같습니다
하지만 난에 대한 SK_Representative에 숫자 '33'에 대한 SK_Representative 정보를 집계 할 필요가 번호 '47'. SK_Representative 인 기본 키를 잃지 않고이 작업을 수행해야합니다.
현재 결과입니까 아니면 원하는 결과입니까? –
"숫자 33에 대한 SK_ 대표 값 정보를 '47 '에 대한 SK_ 대표 형으로 통합" –
SK_Representative'33 '의'deve '값은 SK_Representative'47 ' –