潇湘_夜雨
2018-04-19 15:18
这条语句还能怎么优化?大神们帮帮忙吧!谢谢
SELECT
a.*,
CASE
WHEN a.distno = '01' THEN
concat( DD.distname, '-合计' ) ELSE DD.distname
END distname,
cast( ztyes/zts * 100 AS DECIMAL ( 8, 2 ) ) wcl,
2017 nf,
1 yf,
'' lx
FROM
(
SELECT
ifnull( distno, '01' ) distno,
zts,
ztyes,
czs,
qyzs,
bfh
FROM
(
SELECT
CASE
WHEN
( '01' ) = ( 4+3 ) THEN
a.linkDistId ELSE substring( a.linkDistId, 1, 4 )
END distno,
count( DISTINCT a.acc_set ) zts,
count( DISTINCT b.acc_set ) ztyes,
count( DISTINCT CASE WHEN a.acc_style = '经济帐' THEN b.acc_set END ) czs,
count( DISTINCT CASE WHEN a.acc_style = '企业帐' THEN b.acc_set END ) qyzs,
0 bfh
FROM
gz_acc_set a
LEFT OUTER JOIN gz_balance b ON a.acc_set = b.acc_set
AND b.years = 2017
AND b.months = 1
WHERE
a.dwlx LIKE
CASE
WHEN '' = ''
OR '' = '全部' THEN
'%' ELSE ''
END
AND a.linkDistId LIKE '01%'
GROUP BY
CASE
WHEN ( '01' ) = ( 4+3 ) THEN
a.linkDistId ELSE substring( a.linkDistId, 1, 4 )
END WITH ROLLUP
) a
) a,
( SELECT distno, distname FROM scandist ) DD
WHERE
DD.distno = a.distno
还没有人回答问题,可以看看其他问题
性能优化之MySQL优化
101639 学习 · 221 问题
相似问题