我想将行分组并将它们移动到同一个表中的新列中。这是我的ilustration:
这是我到目前为止所做的查询:
SELECT
month([date]) as bulan,
[type] as tipe,
SUM([net qty]) total_karton,
CAST(SUM([cm1 (rp)]) as decimal) as total_uang
FROM
tbl_weeklyflash_ID
WHERE
DATEDIFF(month,[date],CURRENT_TIMESTAMP) between 0 and 2
GROUP BY
month([date]),
[type]
ORDER BY
month([date]), [type]
怎么做?
答案 0 :(得分:1)
你想要一个PIVOT
- http://www.mssqltips.com/sqlservertip/1019/crosstab-queries-using-pivot-in-sql-server-2005/