Calculate the total expense of yesterday, use the coalesce function to return 0 if no expense is generated, use the round function to retain three decimal places, and then use the compare function to calculate the month-to-month comparison ratio. The results are displayed in a month-to-month comparison chart, which shows the total consumption of yesterday and the comparison to the same day in the last month.
sql
source :bill |
select
round(diff [1], 2),
round(diff [2], 2),
round(diff [3] * 100 -100, 2)
from(
select
compare("Consumption yesterday", 604800) as diff
from(
select
round(coalesce(sum(PretaxAmount), 0), 3) as "Consumption yesterday"
from
log
)
)