Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/09/2010, 10:04
Avatar de a83
a83
 
Fecha de Ingreso: noviembre-2005
Ubicación: Santiago de chile
Mensajes: 637
Antigüedad: 18 años, 9 meses
Puntos: 1
como puedo traer don años en esta consulta los mismos campos

estimados tengo un problema en esta consulta muestro 1 año y sus 3 miperos meces Diciembre,Enero,Febrero
Código PHP:
select  case when a.mes=12 then 'Diciembre'else 
    case 
when a.mes=1 then'Enero'else 
    case 
when a.mes=2 then'Febrero' end end end as mes,  
    
sum(a.prima_us_PC) as prima_us_PC,sum(a.prima_us_BU) as prima_us_BU from
    
(select  mes ,sum (prima_us) as prima_us_PC,sum (0) as prima_us_BU 
    from produ_comercial 
    where 
    
(manager 'L'and cia ='000169'   and mes 12 and year=2009 )
    or
    (
manager 'L'and mes in ('1','2')and  year =2010 and cia ='000169' 
    
group by mes
    union
    select mes
,sum (0) as prima_us_PC,sum (prima_us) as prima_us_BU 
    from tbl_budget 
    where 
    
(mes 12 and year=2009)
    or 
    (
mes in ('1','2')and  year =2010)
    
group by mes)
    group by a
.mes 

ahora el problema que tengo es cuando quiero mostrar dos años

Código PHP:
    select  case when a.mes=12 then 'Diciembre'else 
        case 
when a.mes=1 then'Enero'else 
        case 
when a.mes=2 then'Febrero' end end end as mes,  
    
    
sum(a.prima_us_PC) as prima_us_PC,sum(a.prima_us_BU) as prima_us_BU,sum(a.prima_us_PC2) as prima_us_PC2,sum(a.prima_us_BU2) as prima_us_BU from
    
(select  mes ,sum (prima_us) as prima_us_PC,sum (0) as prima_us_BU,sum (prima_us) as prima_us_PC2,sum (0) as prima_us_BU2 
    from produ_comercial 
    where 
    
(manager 'L'and cia ='000169' and mes 12  and year=2008 and year=2009)

    or
    (
manager 'L'and mes in ('1','2')and year=2009 and cia ='000169'and year=2010  )
    
    
group by mes
    union
    select mes
,sum (0) as prima_us_PC,sum (prima_us) as prima_us_BU,sum (0) as prima_us_PC2,sum (prima_us) as prima_us_BU2  
    
    from tbl_budget 
    where 
    
    
(mes 12 and year=2008 and year=2009 )
    or 
    (
mes in ('1','2')and year=2009 and  year=2010)
    
group by mes)
    group by a
.mes 

me muestra la tabla desocupada