On Mon, 15 Oct 2007 13:23:19 +0400, Игорь Горбонос <[EMAIL PROTECTED]> wrote:

Так что ли?

select gp.group_pays, cp.class_pays, yp.naznachenie_pay,
        sum(case when extract(month from yp.date_pay) = 1 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 2 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 3 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 4 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 5 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 6 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 7 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 8 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 9 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 10 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 11 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end),
        sum(case when extract(month from yp.date_pay) = 12 then 
coalesce(yp.summa_pay, 0.00) else 0.00 end)
   from group_pays gp
        join class_pays cp on gp.id = cp.ref_groups_pays
        left join year_pay yp on yp.group_pays = gp.id and yp.filial = 
'Название филиала'
   group by gp.group_pays, cp.class_pays, yp.naznachenie_pay


Писал из головы, возможно, требуется напильник.

-- 
Сергей Смирнов.

Reply via email to