Someone who can help me with this query. I have three tables with different names.
Tabla Ejemplo1
fecha campo1
2017-01-01 0.00
2017-01-01 7.00
2017-01-01 0.00
2017-01-01 1.00
2017-01-01 0.00
2017-01-02 1.00
2017-01-02 43.00
2017-01-02 1.00
2017-01-02 0.00
2017-01-02 0.00
Tabla Ejemplo2
fecha campo2
2017-01-01 0.00
2017-01-01 5.00
2017-01-01 1.00
2017-01-01 3.00
2017-01-01 0.00
2017-01-02 1.00
2017-01-02 3.00
2017-01-02 2.00
2017-01-02 2.00
2017-01-02 0.00
Tabla Ejemplo3
fecha campo3
2017-01-01 0.00
2017-01-01 5.00
2017-01-01 1.00
2017-01-01 3.00
2017-01-01 0.00
2017-01-02 1.00
2017-01-02 1.00
2017-01-02 0.00
2017-01-02 0.00
2017-01-02 0.00
I want to add all the fields with their respective values and then join the dates in a date block. So that way ...
Tabla Final
fecha campoTotal
2017-01-01 26.00
2017-01-02 55.00
I've tried two ways to do it with nested queries and subqueries. And in no way, I've got to do it. Can someone give me a cable?
Queries
SELECT [fecha],
sum([campo1]) AS "campo1"
FROM Ejemplo1
WHERE fecha = '2017-01-01'
GROUP BY fecha
SELECT [fecha],
sum([campo2]) AS "campo2"
FROM Ejemplo2
WHERE fecha = '2017-01-01'
GROUP BY fecha
SELECT [fecha],
sum([campo3]) AS "campo3"
FROM Ejemplo3
WHERE fecha = '2017-01-01'
GROUP BY fecha
Subquerys
select fecha,sum(campo1) total
from
(
select fecha,campo1
from ejemplo1
union all
select fecha,campo2
from ejemplo2
union all
select fecha,campo3
from ejemplo3
) t
group by fecha