SQL语句问题,为什么查不出数据?? 10
selectCPBZCB_ZRZXID,CPBZCB_CBXMID,CPBZCB_CPID,CPBZCB_BZCB,SCRK.RKSLfromCPBZCBleftjoin...
select CPBZCB_ZRZXID,CPBZCB_CBXMID , CPBZCB_CPID , CPBZCB_BZCB ,SCRK.RKSL
from CPBZCB
left join ( select KCSW_WLID , sum( KCSW_RKSL) as RKSL
from KCSW , KC
left join BM on BM_BMID = KC_BMID
where KC_KCBH = KCSW_KCBH
and KC_KJDWID = ('01')
and BM_ZRZXID = ('010358')
and KC_YEAR = (2013) and KC_MONTH = (8) and KC_SWLX = 'SCRK'
group by KCSW_WLID
) SCRK on SCRK.KCSW_WLID = CPBZCB_CPID
where CPBZCB_KJDWID = ('01') and CPBZCB_YEAR = (2013) and CPBZCB_MONTH = (8)
可以执行 运行时间01秒即可查出数据
select CPBZCB_ZRZXID,CPBZCB_CBXMID , CPBZCB_CPID , CPBZCB_BZCB ,SCRK.RKSL
from CPBZCB
left join ( select KCSW_WLID , sum( KCSW_RKSL) as RKSL
from KCSW , KC
left join BM on BM_BMID = KC_BMID
where KC_KCBH = KCSW_KCBH
and KC_KJDWID = ('01')
and BM_ZRZXID = ('010358')
and KC_YEAR = (2013) and KC_MONTH = (8) and KC_SWLX = 'SCRK'
group by KCSW_WLID
) SCRK on SCRK.KCSW_WLID = CPBZCB_CPID
where CPBZCB_KJDWID = ('01') and CPBZCB_YEAR = (2013) and CPBZCB_MONTH = (8)
and CPBZCB_ZRZXID = ('010358')
半天查不出数据,至少运行10分钟。
这是为什么??? 展开
from CPBZCB
left join ( select KCSW_WLID , sum( KCSW_RKSL) as RKSL
from KCSW , KC
left join BM on BM_BMID = KC_BMID
where KC_KCBH = KCSW_KCBH
and KC_KJDWID = ('01')
and BM_ZRZXID = ('010358')
and KC_YEAR = (2013) and KC_MONTH = (8) and KC_SWLX = 'SCRK'
group by KCSW_WLID
) SCRK on SCRK.KCSW_WLID = CPBZCB_CPID
where CPBZCB_KJDWID = ('01') and CPBZCB_YEAR = (2013) and CPBZCB_MONTH = (8)
可以执行 运行时间01秒即可查出数据
select CPBZCB_ZRZXID,CPBZCB_CBXMID , CPBZCB_CPID , CPBZCB_BZCB ,SCRK.RKSL
from CPBZCB
left join ( select KCSW_WLID , sum( KCSW_RKSL) as RKSL
from KCSW , KC
left join BM on BM_BMID = KC_BMID
where KC_KCBH = KCSW_KCBH
and KC_KJDWID = ('01')
and BM_ZRZXID = ('010358')
and KC_YEAR = (2013) and KC_MONTH = (8) and KC_SWLX = 'SCRK'
group by KCSW_WLID
) SCRK on SCRK.KCSW_WLID = CPBZCB_CPID
where CPBZCB_KJDWID = ('01') and CPBZCB_YEAR = (2013) and CPBZCB_MONTH = (8)
and CPBZCB_ZRZXID = ('010358')
半天查不出数据,至少运行10分钟。
这是为什么??? 展开
展开全部
1、索引选择算法非常复杂,这个一下子讲不清楚
2、可以利用查询分析器看看各SQL的执行计划,可以看到每一步是否用互索引以及用了什么索引把 BM_ZRZXID = ('010358') 改为它时 BM_ZRZXID = ('010306')
把 CPBZCB_ZRZXID = ('010358') 改为它时 CPBZCB_ZRZXID = ('010306')
分析前后执行计划是否有啥不同
2、可以利用查询分析器看看各SQL的执行计划,可以看到每一步是否用互索引以及用了什么索引把 BM_ZRZXID = ('010358') 改为它时 BM_ZRZXID = ('010306')
把 CPBZCB_ZRZXID = ('010358') 改为它时 CPBZCB_ZRZXID = ('010306')
分析前后执行计划是否有啥不同
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-07
展开全部
CPBZCB_ZRZXID 涉及表结构中缺少对该列增加索引
追问
建有聚集索引
CPBZCB_KJDWID ,CPBZCB_YEAR ,CPBZCB_MONTH ,CPBZCB_ZRZXID ,CPBZCB_CPID
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询