Pivoting in MS SQL Server
March 20, 2021
SELECT
*
FROM
(
SELECT
p.product_name,
g.tx_id,
g.transmonth
FROM
[DataAnalytics].[dbo].[tbla_
INNER JOIN
[DataAnalytics].[dbo].[tbld_
ON
g.product_code = p.product_code and transmonth>='202101'
) t
PIVOT
(
COUNT(polnum)
FOR product_name
IN ([Product 1],[Product 2],[Product 3],[Product 4],[Product 5],
) AS pvt;