COALESCE(total.total_turnover_current_month, 0) as all_turnover,
CASE
WHEN COALESCE(total.total_turnover_last_month, 0) = 0 AND COALESCE(total.total_turnover_current_month, 0) = 0 THEN 0
WHEN COALESCE(total.total_turnover_last_month, 0) = 0 AND COALESCE(total.total_turnover_current_month, 0) > 0 THEN 100
WHEN COALESCE(total.total_turnover_last_month, 0) > 0 AND COALESCE(total.total_turnover_current_month, 0) = 0 THEN -100
ELSE ROUND(COALESCE((total.total_turnover_current_month - COALESCE(total.total_turnover_last_month, 0)) / NULLIF(total.total_turnover_last_month, 1), 0) * 100, 2)
END as all_turnover_percent,
COALESCE(averages.avg_sales_rate_current_month, 0) as sales_rate,
CASE
WHEN COALESCE(averages.avg_sales_rate_last_month, 0) = 0 AND COALESCE(averages.avg_sales_rate_current_month, 0) = 0 THEN 0
WHEN COALESCE(averages.avg_sales_rate_last_month, 0) = 0 AND COALESCE(averages.avg_sales_rate_current_month, 0) > 0 THEN 100
WHEN COALESCE(averages.avg_sales_rate_last_month, 0) > 0 AND COALESCE(averages.avg_sales_rate_current_month, 0) = 0 THEN -100
ELSE ROUND(COALESCE((averages.avg_sales_rate_current_month - COALESCE(averages.avg_sales_rate_last_month, 0)) / NULLIF(averages.avg_sales_rate_last_month, 1), 0) * 100, 2)
END as sales_rate_percent,
COALESCE(averages.avg_reduce_rate_current_month, 0) as reduce_rate,
CASE
WHEN COALESCE(averages.avg_reduce_rate_last_month, 0) = 0 AND COALESCE(averages.avg_reduce_rate_current_month, 0) = 0 THEN 0
WHEN COALESCE(averages.avg_reduce_rate_last_month, 0) = 0 AND COALESCE(averages.avg_reduce_rate_current_month, 0) > 0 THEN 100
WHEN COALESCE(averages.avg_reduce_rate_last_month, 0) > 0 AND COALESCE(averages.avg_reduce_rate_current_month, 0) = 0 THEN -100
ELSE ROUND(COALESCE((averages.avg_reduce_rate_current_month - COALESCE(averages.avg_reduce_rate_last_month, 0)) / NULLIF(averages.avg_reduce_rate_last_month, 1), 0) * 100, 2)
END as
coalesce, averages, tal, turnover