Group employees by company in query

0

I'm making a report, where I need to follow the following layout:

Withthequerybelow,youhavecreatedmorerows,ratherthangroupingemployeesbycompany:

selecte.cnpjascnpj,e.nome_completoasempresa,li.codassolicitacao,''funcionariosfromliberacoesli,empresaewhereli.cnpj=e.cnpjandli.dt_acesso_ini=curdate()unionallselect''ascnpj,''asempresa,''assolicitacao,f.nome_completoasfuncionariofromfuncionariosf,empresaewheref.cnpj=e.cnpjorderby1desc;

Bringingmethisresult:

Inaquery,canIjustmaketheoutputlayoutlooklikeIneedtofollow?

UPDATE

Itriedthequerybelow,buttheresultisstilloutofthewayIneed:

selectli.cod,e.cnpj,e.nome_completoasempresa,coalesce(f.nome_completo,'X')asfuncionariofromempresaeleftouterjoinfuncionariosfonf.cnpj=e.cnpjleftouterjoinliberacoeslionli.cnpj=e.cnpj

Result:

    
asked by anonymous 15.07.2017 / 19:22

1 answer

0

You do not need the union in this case:

   select distinct
       e.cnpj,
       e.nome_completo as empresa,
       coalesce(f.nome_completo,'X') as funcionario
   from empresa e
   left outer join funcionario f on f.cnpj = e.cnpj
    
15.07.2017 / 19:28