我需要进行行列转置并尝试以下查询
select txn_date,
case when remarks is NULL then 'bank' else remarks end as remarks
from nibl
PIVOT
(
count(txn_date)
FOR remarks IN (bank, remit)
) as pivot
上面的查询给出语法错误,如下所示
Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'pivot'.
答案 0 :(得分:2)
pivot
是SQL Server中的保留字,因此) as pivot
在此处失败。
使用其他别名) as p
。
答案 1 :(得分:0)
select * from
(select txn_date,
case when remarks is NULL then 'bank' else remarks end as remarks
from nibl
) srs
PIVOT
(
count(txn_date)
FOR remarks IN (bank, remit)
) as pivot