(select 'a' as col, sum(a) as Total from x where date <= '2001-01-01'
union
select 'b' as col, sum(b) as Total from x where date <= '2001-01-01'
union
select 'c' as col, sum(c) as Total from x where date < '2001-01-01' ) xyz
SET @a = (select sum(col_a) from x where date <= '2001-01-01');
SET @b = (select sum(col_b) from x where date <= '2001-01-01');
SET @c = (select col_c from x where date <= '2001-01-01' order by date desc limit 1);
SET @total = @a+@b+@c;
SELECT @total;
select sum(Total) as complete_total from (
select colA as col, sum(colA) as Total from x where date <= '2001-01-01' group by colA
UNION
select colB as col, sum(colB) as Total from x where date <= '2001-01-01' group by colB
UNION
select some_other_column as col, max(colC) as Total from x where date <= '2001-01-01' group by some_other_column
) as tbl;
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
22 Experts available now in Live!