0

tabBuchung のすべての「dblSoll」値の合計と、tabBuchungx のすべての「dblSoll」値の合計を 1 行で取得する必要があります...

ここに私の定義があります:

CREATE TABLE tabBuchung
(strKto char(50), 
 dblSoll int(50),
 dblHaben int(50));

CREATE TABLE tabKonten
(strKtoNr char(50),
strKtoBez char(50),
strKtoTyp char(50));

CREATE TABLE tabBuchungx
(strKto char(50),
dblSoll int(50),
dblHaben int(50));

insert into tabBuchung values ("1500", 50,0);
insert into tabBuchung values ("1600", 70,0);
insert into tabBuchung values ("1600", 130,0);
insert into tabBuchung values ("1700", 0, 800);
insert into tabBuchung values ("1800", 30, 22);
insert into tabBuchung values ("2000", 100, 0);
insert into tabBuchung values ("2000", 140, 0);

insert into tabBuchungx values ("1500", 0, 80);
insert into tabBuchungx values ("1600", 220, 0);
insert into tabBuchungx values ("1600", 80, 0);
insert into tabBuchungx values ("1700", 0, 44);
insert into tabBuchungx values ("1800", 10, 15);
insert into tabBuchungx values ("1900", 30, 0);
insert into tabBuchungx values ("1900", 10, 0);

これが私の声明です。

select tabBuchung.strKto, sum(tabBuchung.dblSoll) as newSaldo, sum(tabBuchungx.dblSoll) as oldSaldo
from tabBuchung
join tabBuchungx on tabBuchung.strKto = tabBuchungx.strKto
where tabBuchung.strKto = '1600'
group by tabBuchung.strKto, tabBuchung.dblSoll, tabBuchungx.dblSoll

それは私がatmを得るものです:

strkto newsaldo oldsaldo
1600     70         80
1600     70        220
1600    130         80
1600    130        220

しかし、私は1つの行が欲しい:

strkto   newsaldo   oldsaldo
1600        200       300

誰でも私を助けてくれますか?

4

2 に答える 2