I have a problem which I try to solve with Local SQL, but I can't find any solution. Can anybody give me a hint?
I have 2 Paradox tables Art.DB and Bet.DB
Art has 4 columns:
Datum, Object, Nr, Summa
Datum Object Nr Summa
------------------------------------
2023-01-01 Tools 100 5000
2023-01-01 Bags 100 1000
2023-02-01 Tyres 101 4000
2023-03-01 Cart 102 5700
Bet has 3 columns:
Nr, Type, Summa
Nr Type Summa
---------------------
100 Card 5000
100 Cash 1000
101 Card 4000
102 Cash 5700
I want to summarize the sales receipts, which is Nr
The SQL I use is
SELECT
a.Nr, SUM(Summa) AS Summa
FROM
Art AS a, Bet AS b
WHERE
a.Nr = b.Nr
GROUP BY
a.nr
ORDER BY
Nr
My problem is that I get double Summa because 2 payments with different methods for Nr = 100
Nr Summa
-----------
100 12000
101 4000
102 5700
I am expecting a sum of 6000 and not 12000 for Nr 100. I understand why I get this result, but how should I write the SQL statement to get the desired result?
You have not mentioned which summa column to be taken from Art or Bet. Change the sum according to your needs
here is the code