猫狗jamal 2019-06-14 16:34 采纳率: 0%
浏览 268

请问这句select语句可以怎么用优化?

select null id, cast(a.acc_set as varchar(50)) key1, cast(a.years as varchar(50)) key2,cast(a.months as varchar(50)) key3, a.acc_name key4, '' key5, b.distNo bh, b.distName mc, b.distNo, b.ztid, CAST(12 as numeric) lvalue,cast(isnull(zzny,0)-isnull(fsny,0) as numeric) as rvalue,cast(isnull(zzny,0)-isnull(fsny,0)-12 as numeric) as zvalue, '' writer, '' writeDate from ( select acc_set,acc_name,years,months,(years*12+months) fsny from hd_bjAccountnew..balance where exists( select * from (select acc_set,acc_name,MAX(years*12+months) fsny from hd_bjAccountnew..balance where acc_code like '154%' and (ISNULL(debit_month,0)<>0 or ISNULL(credit_month,0)<>0) and exists(select acc_set,acc_code from hd_bjAccountnew..acc_code where lastflag=1 and acc_code like '154%' and exists(select years,acc_set from hd_bjAccountnew..acc_set where acc_set.years=acc_code.years and acc_set.acc_set=acc_code.acc_set) and acc_code.acc_set=balance.acc_set and acc_code.acc_code=balance.acc_code)and (ISNULL(debit_month,0)<>0 or ISNULL(credit_month,0)<>0) group by acc_set,acc_name )a where a.acc_set=balance.acc_set and a.acc_name=balance.acc_name and a.fsny=(balance.years*12+balance.months) ) )a join (select acc_set,years,months,years*12+months zzny from hd_bjAccountnew..acc_set)c on a.acc_set=c.acc_set join zcjy_hd..zt b on a.acc_set=b.BS_ztNo where zzny-fsny>12

  • 写回答

2条回答 默认 最新

  • Hefei19881002 2019-06-14 16:53
    关注
    你这问的,最起码把涉及到的表结构贴出来啊
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料