私は何を探していますが合計行と列レベルの両方で起こるべきどのようにSQL Serverで列の賢さと行の合計を合計するには?
あるある
以下をご覧ください
私の試み
declare @t table(aggrementid varchar(20), bom_pos int, bucket int null, paymentstatus varchar(50))
insert into @t
select '1', 3000, null, null
union all
select '2', 3000, 0, 'Non-Delinquient'
union all
select '3', 4000, 0, 'Non-Delinquient'
union all
select '4', 5000, 0, 'Non-Delinquient'
union all
select '5', 7000, 0, 'NPA'
union all
select '6', 8000, 1, 'NPA'
Select
bucket,
[Non-Delinquient], [NPA], [RollBack], [RollForward],
[Stabilized], [Normalized], [PaymentStatusY],
Total = iif([Non-Delinquient] is null, 0, [Non-Delinquient]) +
iif([NPA] is null, 0, [NPA]) +
iif([RollBack] is null, 0, [RollBack]) +
iif([RollForward] is null, 0, [RollForward]) +
iif([Stabilized] is null, 0, [Stabilized]) +
iif([Normalized] is null, 0, [Normalized]) +
iif([PaymentStatusY] is null, 0, [PaymentStatusY])
From
(Select
--aggrementid,
bom_pos,
bucket, paymentstatus
From
@t) as PivotSource
PIVOT
(sum(bom_pos) FOR paymentstatus IN ([Non-Delinquient], [NPA],[RollBack],[RollForward],[Stabilized],[Normalized],[PaymentStatusY])
) as Pvt
Where
bucket is not null
これは、この結果を返します:
私が進めて助けてください。同じ等