我在旋转结果中得到错误,如下所示:
select tanggal,[1],[2] from
(
SELECT
(CONVERT(DATE, tanggal, 103)) as tanggal,
id_jenis,
(harga * jumlah) as total
FROM
[dbo].[PNL_TP_SISA_PRODUKSI]
WHERE
YEAR (CONVERT(DATE, tanggal)) = 2016
AND MONTH (CONVERT(DATE, tanggal)) = 8
AND id_unit_pengolah = 40)
c
PIVOT (MAX(total) FOR id_jenis IN([1],[2]))
并且此错误显示:
[Err] 42000 - [SQL Server]')'附近的语法不正确。
因为错误
而感到困惑答案 0 :(得分:1)
我认为您需要为pivot
select tanggal,[1],[2] from
(
SELECT
(CONVERT(DATE, tanggal, 103)) as tanggal,
id_jenis,
(harga * jumlah) as total
FROM
[dbo].[PNL_TP_SISA_PRODUKSI]
WHERE
YEAR (CONVERT(DATE, tanggal)) = 2016
AND MONTH (CONVERT(DATE, tanggal)) = 8
AND id_unit_pengolah = 40)
c
PIVOT (MAX(total) FOR id_jenis IN([1],[2])) as pvt