oracle语句改写成mysql
select nvl(sum(is_this_month),0) as total,
nvl((sum(is_this_month) - sum(is_last_month)),0) as
month_count,
nvl((sum(is_today) - sum(is_last_day)),0) as day_count
from (select case
when to_char(TRUNC(SYSDATE - 1), 'dd') = to_char(VALID_DATE, 'dd') then 1
else 0 end as
is_last_day,
case
when to_char(sysdate, 'dd') = to_char(VALID_DATE, 'dd') then 1
else 0 end as
is_today,
case
when to_char(sysdate, 'MM') = to_char(VALID_DATE, 'MM') then 1
else 0 end as
is_this_month,
case
when to_char(TRUNC(add_months(trunc(sysdate), -1), 'MM'), 'MM') = to_char(VALID_DATE, 'MM')
then 1
else 0 end as
is_last_month
from (SELECT *
FROM API_SERVICE
WHERE VALID_DATE is not null
and VALID_DATE > TRUNC(ADD_MONTHS(sysdate, -1), 'mm'))) b
如何改写成mysql版本