Ir para conteúdo
Fórum Script Brasil

odlandeuna

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Tudo que odlandeuna postou

  1. Bom dia, pessoal.Gostaria trazer o resultado da consulta de forma NÃO CLASSIFICADA, e sim, na ordem em que foram entrados os parâmetros em destaque. Conforme imagem em anexo o resultado está ficando na ordem alfabética, como não tenho familiaridade com Postgress peço ajuda dos companheiros.select DISTINCTnome_grupo,coalesce (sum( evento_402) , 0 ) as evento_402,coalesce (sum( evento_606) , 0 ) as evento_606,coalesce (sum( evento_608) , 0 ) as evento_608,coalesce (sum( evento_611) , 0 ) as evento_611,coalesce (sum( evento_612) , 0 ) as evento_612,coalesce (sum( evento_614) , 0 ) as evento_614,coalesce (sum( evento_619) , 0 ) as evento_619,coalesce (sum( evento_601) , 0 ) as evento_601,coalesce (sum( evento_599) , 0 ) as evento_599,coalesce (sum( evento_621) , 0 ) as evento_621,coalesce (sum( evento_622) , 0 ) as evento_622,coalesce (sum( evento_1005) , 0 ) as evento_1005,coalesce (sum( evento_1007) , 0 ) as evento_1007,coalesce (sum( evento_1017) , 0 ) as evento_1017,coalesce (sum( evento_1011) , 0 ) as evento_1011,coalesce (sum( evento_1043) , 0 ) as evento_1043,coalesce (sum( evento_1045) , 0 ) as evento_1045,coalesce (sum( evento_1051) , 0 ) as evento_1051,coalesce (sum( evento_620) , 0 ) as evento_620,coalesce (sum( evento_623) , 0 ) as evento_623from(SELECT distinctnome_grupo,case when codigo_vende = '00402' then sum(total) else 0 end as evento_402,case when codigo_vende = '00606' then sum(total) else 0 end as evento_606,case when codigo_vende = '00608' then sum(total) else 0 end as evento_608,case when codigo_vende = '00611' then sum(total) else 0 end as evento_611,case when codigo_vende = '00612' then sum(total) else 0 end as evento_612,case when codigo_vende = '00614' then sum(total) else 0 end as evento_614,case when codigo_vende = '00619' then sum(total) else 0 end as evento_619,case when codigo_vende = '00601' then sum(total) else 0 end as evento_601,case when codigo_vende = '00599' then sum(total) else 0 end as evento_599,case when codigo_vende = '00621' then sum(total) else 0 end as evento_621,case when codigo_vende = '00622' then sum(total) else 0 end as evento_622,case when codigo_vende = '01005' then sum(total) else 0 end as evento_1005,case when codigo_vende = '01007' then sum(total) else 0 end as evento_1007,case when codigo_vende = '01017' then sum(total) else 0 end as evento_1017,case when codigo_vende = '01011' then sum(total) else 0 end as evento_1011,case when codigo_vende = '01043' then sum(total) else 0 end as evento_1043,case when codigo_vende = '01045' then sum(total) else 0 end as evento_1045,case when codigo_vende = '01051' then sum(total) else 0 end as evento_1051,case when codigo_vende = '00620' then sum(total) else 0 end as evento_620,case when codigo_vende = '00623' then sum(total) else 0 end as evento_623from(select c.codigo_custo, case when c.codigo_custo in ('038') then 'CAPS (38)' when c.codigo_custo in ('010','050','074','076') then 'APOIO MDE GERAL (10,50,74,76)' when c.codigo_custo in ('11','048','75','77') then 'FUNDEB 40 GERAL (11,48,75,77)' when c.codigo_custo in ('012','047','051','054','069','071','073','078') then 'FUNDEB 60 (12,47,51,54,69,71,73,78)' when c.codigo_custo in ('031','060') then 'C. PART. (31 e 60)' when c.codigo_custo in ('039') then 'HOSPITAL 14889-X (39)' when c.codigo_custo in ('028') then 'PAB 159995-6 (28)' when c.codigo_custo in ('027') then 'PACS 16076-8 (27)' when c.codigo_custo in ('032') then 'PSF 16077-6 (32)' when c.codigo_custo in ('025') then 'ENDEMIAS 15997-2 (25)' when c.codigo_custo in ('016','036') then 'SOCIAL E C.TUT.(16 e 36)' when c.codigo_custo in ('029') then 'GAB.DO PREF.(29)' when c.codigo_custo in ('007') then 'APOIO A ADM GERAL (7)' when c.codigo_custo in ('017') then 'AP.AGRI.GERAL (17)' when c.codigo_custo in ('008') then 'APOIO A FINANÇAS (8)' when c.codigo_custo in ('022') then 'APOIO A OBRAS (22)' when c.codigo_custo in ('020') then 'TURISMO 8049-7 (20)' when c.codigo_custo in ('053') then 'CONTROLE INT.(53)' when c.codigo_custo in ('055') then 'EJA 17781-4 (55)' when c.codigo_custo in ('064') then 'APOIO SOCIAL CRAS (64)' when c.codigo_custo in ('067') then 'APOIO SOCIAL PBV III(67)' when c.codigo_custo in ('070') then 'SAÚDE BUCAL-16087-3(70)' else '' end as nome_grupo,a.codigo_vende,sum(a.valor) as totalfrom fl_acmes ainner join fl_cadfu_histo h onh.codigo_emp = a.codigo_emp andh.codigo_fil = a.codigo_fil andh.codigo_tpf = a.codigo_tpf andh.codigo_cadfu = a.codigo_cadfu andh.ano = a.ano andh.mes = a.mesinner join fl_ccusto c onc.codigo_emp = h.codigo_emp andc.codigo_fil = h.codigo_fil andc.codigo_custo = h.codigo_custowhere a.codigo_emp = '001'and a.codigo_fil = '001'and a.ano = @_pvchAnoand a.mes = @_pvchMesand a.codigo_vende in ('00402','00599','00601','00606','00608','00611','00612', '00613','00614','00615','00619','00620','00621','00622','00623','01005','01007','01011','01017','01043','01045','01051') group by c.codigo_custo, a.codigo_vende) as princgroup by nome_grupo, codigo_vende) as segundagroup by nome_grupo
×
×
  • Criar Novo...