PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → SQL SUM both tables
SQL SUM both tables
Iniciado por anahoret3, 22,sep. 2023 10:13 - 2 respuestas
Publicado el 22,septiembre 2023 - 10:13
Greetings,
as I checked the forum, seems this functionality was not supported, but I am in situation, where I would need to sum order details and plus customer monthly payment.

Data file: Orders
Data file: Customers

SUM(Orders.WorkDuration + Order.MaterialPrice) + Customers.MonthlyPayment

So I need to SUM everything what I get from orders, but add to this value additional customers monthly payment.

Sum of orders = 100eur
Customer monthly payment = 150eur
In total from te query I should get 250eur

Could you please suggest how to handle it ?

Thanks a bunch!
Publicado el 22,septiembre 2023 - 11:20
Hello Vlad,
I think you have to work with subqueries

Something like this:
(Not tested)

SELECT MonthlyPayment+OrdSum AS MyTotal
FROM (
SELECT Customers.MonthlyPayment, SUM(Orders.WorkDuration+Orders.MaterialPrice) AS OrdSum
FROM Customers
LEFT OUTER JOIN Orders ON Orders.CustomerCode=Customers.Code
WHERE Customers.Code='123456879'
AND Orders.Date BETWEEN xxx AND yyy
)


Hope this helps
Andrea
Publicado el 25,septiembre 2023 - 06:58
Thanks Andrea, will try.
After regular SQL this one is a bit tricky.