Group [group by] SQL Firebird

0

I would like to know if there's any way I can do a query where I can bring fields that are not in my group by .

I have the following code:

select sum(TAB_FATURAMENTO.vl_item),CLIENTE.insc_cnpj
from TAB_FATURAMENTO
inner join (IMP_PROCESSO
  inner join CLIENTE
  on IMP_PROCESSO.cd_cliente = CLIENTE.codigo)
on TAB_FATURAMENTO.cd_processo = IMP_PROCESSO.cd_processo
where TAB_FATURAMENTO.cd_cliente like '%'
and TAB_FATURAMENTO.pg='S'
group by CLIENTE.insc_cnpj

In my select I would like to bring two more fields, but the grouping I want to be only by the CNPJ of the clients.

    
asked by anonymous 07.08.2017 / 17:09

2 answers

0

Thanks in advance for your help.

In conversation with a co-worker, I explained my problem and he gave me the following suggestion:

  

Make select the way it is, and on the php page itself make another select bringing the other information I need.

It even suggested that I make this second select within a for , so the query becomes faster.

<?php
    $tl_saldo = 0;
    if($_SESSION['saldo'] <> ""){
       $tl_saldo = count($_SESSION['saldo']);
    }
?>
<table width='100%' border='1'>
  <tr align='center' bgcolor='#999'>
    <td>CLIENTE</td>
    <td>CNPJ</td>
    <td>VL DESPESA</td>
  </tr>
<?php
    for($i = 0; $i < $tl_saldo; $i++){
        $obj_cnpj = $obj_pdo->getCnpj($_SESSION['saldo'][$i]->INSC_CNPJ);
        $_SESSION['cnpj'] = $obj_cnpj;
?>
  <tr align='center'>
    <td class='texto' style='text-align:left;text-indent:10px;'> print substr($_SESSION['cnpj'][0]->NOME,0,18); </td>
    <td class='texto'> print $_SESSION['saldo'][$i]->INSC_CNPJ; </td>
    <td class='texto'> print number_format($_SESSION['saldo'][$i]->SUM,"2",",","."); </td>
  </tr>
<?php
    }
?>
</table>
    
07.08.2017 / 22:33
1

    
07.08.2017 / 18:18