Apa yang ingin Anda lakukan disebut pivot
Coba gunakan kode ini
SELECT employeeid
,case when [2018-10-1] > 0 then '1' else '' end as [2018-10-1]
,case when [2018-10-2] > 0 then '1' else '' end as [2018-10-2]
,case when [2018-10-3] > 0 then '1' else '' end as [2018-10-3]
FROM(
SELECT employeeid
, TranDate
, 1 as num
FROM History
WHERE (CAST(trandate as DATE) = '2018-10-1'
or CAST(trandate as DATE) = '2018-10-2'
or CAST(trandate as DATE) = '2018-10-3' )
)
PIVOT(
COUNT(num)
FOR TranDate IN ([2018-10-1],[2018-10-2],[2018-10-3])
) as pvt
Anda dapat memeriksa dokumentasi sql di PIVOT dan UNPIVOT di PIVOT, UNPIVOT SQL , Juga jika Anda menginginkan sesuatu yang lebih dinamis untuk bidang transdate Anda, Anda dapat memeriksa Pivot Dinamis