Skip to main content
1 de 2
Ric_hc
  • 887
  • 3
  • 12
  • 27

Les comparto respuesta a la cual llegue: Se utilizo el case, en este caso. Les agrego la solución.

with Transp as (
select Fecha        
       ,sum(Vendidas) as Total_Vendidas
       ,sum(Instaladas) as Total_Instaladas
       ,case when [Responsibility Center] = 'CMEX' then sum(Vendidas) end as Vendidas_CMEX
       ,case when [Responsibility Center] = 'CMTY' then sum(Vendidas) end as Vendidas_CMTY
       ,case when [Responsibility Center] = 'CMEX' then sum(Instaladas) end as Instaladas_CMEX
       ,case when [Responsibility Center] = 'CMTY' then sum(Instaladas) end as Instaladas_CMTY
       from #temp_Temporal  right join #temp_calendar  on date = Fecha
    group by Fecha , [Responsibility Center] 

) select Fecha , sum(Vendidas_CMEX) Vendidas_CMEX, sum(Vendidas_CMTY) Vendidas_CMTY , sum(Instaladas_CMEX) Instaladas_CMEX , sum(Instaladas_CMTY) Instaladas_CMTY , Sum(Total_Vendidas) Total_Vendidas, sum(Total_Instaladas) Total_Instaladas From Transp group by Fecha order by Fecha asc

Ric_hc
  • 887
  • 3
  • 12
  • 27