林克大魔王(提问者)SELECT
CASE
WHEN s6.ym = \'目标成本\' THEN 1 ELSE 0 END AS YN,
S6.ym,
S6.hztype,
S6.NAME,
ROUND(nvl(SUM (S6.hz),0)) HZ,
ROUND(SUM(t2.XSQYJE),0) as XSQYJE
FROM
(
select
*
from
s6
order by ym
) s6
INNER JOIN EDW_V_MD_FRAMEWORK t1 ON s6.PHASEID = t1.PHASEID
LEFT JOIN EDW_V_FACT_MKT_24QY t2 ON s6.ym = t2.ym
AND t1.PHASEID = t2.PHASEID
WHERE 1=1
${IF(LEN(phaseid)==0,\"\",\"AND t1.PHASEID IN (\'\"+phaseid+\"\')\")}
GROUP BY
S6.ym,
S6.hztype,
S6.NAME
ORDER BY
YN
desc