Firebird - Select to join two or more lines

Asked

Viewed 761 times

0

I have a table with the following structure:

Cliente_id  |  credito  |  debito  |  pedido
     1           100                    1
     1                       150        1
     1            30                    1
     2                       200        2
     2           180                    2

How to make a Select that the result is similar to the below?

Cliente_id  |  credito  |  debito  |  pedido
     1           130         150        1
     2           180         200        2

Thank you for your help

2 answers

2

may be so too:

select t.Cliente_id, CAST(SUM(t.credito) as numeric(15,2)), CAST(SUM(t.debito) as NUMERIC(15,2)), t.pedido,

CAST(SUM(t.credito) as numeric(15,2)) - CAST(SUM(t.debito) as NUMERIC(15,2)) as Saldo

FROM NOMEDATABELA T 

group by
t.Cliente_id, t.pedido

I also inserted a column of balance, already has only 1 more row.

1


I think it would be something like this

select Cliente_id, SUM(credito), SUM(debito), pedido from tabela group by pedido

where this table you change to the name of your table, what I did was to group the instructions of the same orders and add the value

  • worked properly. thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.