PIVOT two tables in SQL server without aggregation -
i have problem converting rows columns.
my structure this:
select [id_kpi] ,[kpi_value] [dbo].[fact_kpi] select id_kpi ,kpi_label [dbo].[dim_kpi]
and output i'm trying achieve
select [nb_departure] ,[nb_arrival] ,[headcount] [dbo].[fact_hr]
you can use pivot below:
select nb_departure, nb_arrival, headcount ( select d.kpi_label, f.kpi_value , rown = row_number() over(order d.id_kpi) dbo.fact_kpi f join dbo.dim_kpi d on f.id_kpi = d.id_kpi ) pivot (max(kpi_value) kpi_label in ([nb_departure],[nb_arrival],[headcount])) p
output below:
+--------------+------------+-----------+ | nb_departure | nb_arrival | headcount | +--------------+------------+-----------+ | 25 | null | null | | 30 | null | null | | null | 15 | null | | null | 7 | null | | null | null | 12 | | null | null | 13 | +--------------+------------+-----------+
Comments
Post a Comment