CREATE table #yourtable ([Id] int, [Nama] varchar(6), [Ta...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness

Q&A for physical fitness professionals, athletes, trainers, and those providing health-related needs

CREATE table #yourtable
    ([Id] int, [Nama] varchar(6), [Tahap] varchar(13), [Nilai] int)
;
    
INSERT INTO #yourtable
    ([Id], [Nama], [Tahap], [Nilai])
VALUES
    (1, 'John', 'Satu', 5),
    (2, 'John', 'Dua', 2),
    (3, 'Jon', 'Satu', 4),
    (4, 'Jon', 'Dua', 2)
;


select
  Nama, Tahap1, Tahap2
from
(
  select Tahap, Nilai, Nama
  from #yourtable
) d
pivot
(
  max(Nilai)
  for Tahap in (Tahap1, Tahap2)
) piv;

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results