此查询太重,需要重构。我能怎么做?请帮助
SELECT contract_type , SUM(fte),round(SUM(fte * 100 / t.s ),0) AS "% of total"
FROM design_studio_testing.empfinal_tableau
CROSS JOIN (SELECT SUM(fte) AS s FROM design_studio_testing.empfinal_tableau) t
group by contract_type;
输出应该是这样。
不需要对表达式求和:
fte * 100 / t.s
可能会减慢处理速度。得到SUM(fte)
,然后相乘和相除:
SELECT
contract_type,
SUM(fte),
ROUND(100.0 * SUM(fte) / t.s, 0) AS [% of total]
FROM design_studio_testing.empfinal_tableau
CROSS JOIN (SELECT SUM(fte) AS s FROM design_studio_testing.empfinal_tableau) t
GROUP BY contract_type;