sql优化怎么做的?

来源:-

潇湘_夜雨

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


写回答 关注

0回答

还没有人回答问题,可以看看其他问题

性能优化之MySQL优化

了解MySQL数据库优化的方法和技巧,在课程中共同探讨一起学习吧

101639 学习 · 221 问题

查看课程

相似问题