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] 

input

and output i'm trying achieve

select      [nb_departure]    ,[nb_arrival]    ,[headcount] [dbo].[fact_hr] 

output

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

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -