Answer the question
In order to leave comments, you need to log in
How can I sum columns from 2 tables and display in the summary?
There is a PRIC table and an
AMO table.
How to write a query that displays the following information from the PRIC and AMO tables:
Employee name; The total amount paid (the amount from the first table and the second)
But if there were no payments for one of the employees, then 0 should be indicated in the field with the total amount paid.
Answer the question
In order to leave comments, you need to log in
SELECT a.name
sum(a.zarp)
FROM (SELECT name,
IFNULL(zarp, 0) zarp
FROM PRIC
union all
SELECT name,
IFNULL(amount, 0) zarp
FROM AMO
) A
GROUP BY a.name
SELECT PRIC.Name, PRIC.Zarp + ( SELECT SUM( Amount ) FROM AMO WHERE AMO.Name = PRIC.Name ) FROM PRIC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question