Is there a way for me to calculate the sum of two sums? Take the following query (just an example query) how can I get a value for combined_total
? when I run my query it says total1
is an Unknown column. Is there a way to get that value without having to run another sum combining the two sums? That just seems redundant and messy.
select sum(
case when
the_date = date_sub(curdate(), interval 1 year)
then amount else 0 end
) as total1,
sum(
case when
the_date between date_sub(curdate(), interval 1 year)
and date_add(date_sub(curdate(), interval 1 year), interval 1 day)
then amount else 0 end
) as total2,
(total1 + total2) as combined_total