0
I’m making a report, where I need to follow the following layout:
With the query below, we ended up creating more lines, instead of grouping employees per company:
select e.cnpj as cnpj,
e.nome_completo as empresa,
li.cod as solicitacao,
'' funcionarios
from liberacoes li,
empresa e
where
li.cnpj = e.cnpj and
li.dt_acesso_ini = curdate()
union all
select '' as cnpj,
'' as empresa,
'' as solicitacao,
f.nome_completo as funcionario
from funcionarios f,
empresa e
where
f.cnpj = e.cnpj
order by 1 desc;
Bringing me that result:
In a query only I can make the output layout equal to what I need to follow?
UPDATE
I tried the query below, but the result is still outside of what I need:
select
li.cod,
e.cnpj,
e.nome_completo as empresa,
coalesce(f.nome_completo,'X') as funcionario
from empresa e
left outer join funcionarios f on f.cnpj = e.cnpj
left outer join liberacoes li on li.cnpj = e.cnpj
Upshot:
It didn’t work out buddy, the result was the same.
– Diego
I edited the question, see how the result was.
– Diego
puts the table structure, and try using Sqlfiddle
– Rovann Linhalis
I put a distinct there, make a test
– Rovann Linhalis
Obs. The grouping pro company name appear only once, for n employees, is done at the time of display, so for each employee the company name will appear even in the result of the query
– Rovann Linhalis