PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 2024 → SQL SUM both tables
SQL SUM both tables
Iniciado por anahoret3, set., 22 2023 10:13 AM - 2 respostas
Publicado em setembro, 22 2023 - 10:13 AM
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 em setembro, 22 2023 - 11:20 AM
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 em setembro, 25 2023 - 6:58 AM
Thanks Andrea, will try.
After regular SQL this one is a bit tricky.