martes, enero 24, 2006

Me pareció un lindo Query PostgreSQL en PHP:


Select
f.idfondo,
f.meses,
t.texto as fondo,
sum(m.monto) as monto,
m.memo_idmemo as memo,
(case when (f.meses = 1) then
(case when ((to_char (m.fecha, 'MM')) = 12) then '00' else to_char(m.fecha, 'MM') end)
else
'Q' end) as mes,
(case when m.act_idactividad is not null then 'D' else 'A' end) as tipo
from
traducciones t,
fondos f,
movimientos m
where
t.identidad = f.identidad and
m.fecha >= to_date('01/" . $aQActual['inicio']['mes'] . '/' . $aQActual['inicio']['anio'] . "' , 'DD/MM/YYYY') and
m.fecha <= to_date('" . $aQActual['fin']['dia'] . '/' . $aQActual['fin']['mes'] . '/' . $aQActual['fin']['anio'] . "' , 'DD/MM/YYYY') and
f.activado = true and
f.fondo_distribuidor = true and
f.idfondo = m.fon_idfondo and
m.pd_idpais_distribuidor = $sIdPD and
t.idi_ididioma = " . $_COOKIE["IDIDIOMA"] ."
group by
tipo, idfondo, meses, t.texto, memo_idmemo, mes
order by
idfondo, tipo, mes