문제

My table data

LOCATION GROUP  FUNCTION STATUS
L1         G1       F1   0
L1         G1       F1   1
L1         G1       F1   1
L1         G1       F2   1
L1         G1       F2   0
L1         G1       F2   0
L1         G1       F3   1
L1         G1       F3   0
L1         G1       F3   1

Output that I want

LOCATION GROUP F1   F2  F3
L1        G1   0    1   1
L1        G1   1    0   0
L1        G1   1    0   1

I try to use Select CASE but it don't work

Thanks you.

올바른 솔루션이 없습니다

다른 팁

it is not giving exact result but we can go through like this

DECLARE @amount TABLE (LOCATION  VARCHAR(10),GROUPS VARCHAR(10),FUNCTIONS VARCHAR(10),Status INT)

INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F1',0)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F1',1)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F1',1)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F2',1)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F2',0)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F2',0)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F3',0)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F3',0)
INSERT INTo @amount (LOCATION,GROUPS,FUNCTIONS,Status)VALUES ('L1','G1','F3',1)

select LOCATION,GROUPS,Function1,Function2,Function3   from
(Select location,GROUPS,Status,FUNCTIONS from @amount) t
PIVOT (MAX(Status)FOR FUNCTIONS IN ([Function1],[Function2],[Function3]))AS p
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top