SELECT t.*,
CASE WHEN
t.SaleDealMoney_last IS NULL OR t.SaleDealMoney_last=0 THEN 0
ELSE FORMAT(((t.SaleDealMoney_this-t.SaleDealMoney_last)/t.SaleDealMoney_last)*100,2)
END link_ratio
FROM
(
SELECT
a.my_ym,
FORMAT(a.SaleDealMoney,2) AS SaleDealMoney_this,
FORMAT(b.SaleDealMoney,2) AS SaleDealMoney_last
FROM
(
SELECT
date_format(SaleDealDate,'%Y-%m') AS my_ym,
sum(abs(SaleDealMoney)) AS SaleDealMoney
FROM
salemanage
WHERE
SaleDealProjects like '%天九通航%'
AND
SaleDealDate>='2019-01-01'
AND
SaleDealDate<= '2019-12-20'
GROUP BY my_ym
)as a
LEFT JOIN
(
SELECT
date_format(DATE_ADD(SaleDealDate,INTERVAL 1 MONTH ), '%Y-%m') AS my_ym,
sum(abs(SaleDealMoney)) AS SaleDealMoney
FROM
salemanage
WHERE
SaleDealProjects like '%项目名称%'
AND
SaleDealDate>= '2019-01-01'
AND
SaleDealDate<= '2019-12-20'
GROUP BY my_ym
) as b
ON a.my_ym=b.my_ym
) t