首页 新闻 会员 周边 捐助

请高手帮忙优化SQL语句

0
悬赏园豆:15 [已关闭问题]

exec FLX_PLATFORM_PAGING_STATISTIC @QueryStr=N'
Select top 100 percent LA0110 as [专家类别],AA0107 as [性别],A0405R03 as [学历],

(select count(LA0106) From
View_LA01_LE01_20090209 as t where 1=1  and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and
View_LA01_LE01_20090209.A0405R03= t.A0405R03
and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' )
and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [来华许可证],

(select count(LA0175) From View_LA01_LE01_20090209 as t where 1=1  and
(View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or
LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as
[外专证],


(select count(LA0110) From View_LA01_LE01_20090209 as t where  t.LA0110=''01'' and (View_LA01_LE01_20090209.LA0110= t.LA0110 and
View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or
LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [经济技术类],

(select count(LA0110) From
View_LA01_LE01_20090209 as t where  t.LA0110=''02'' and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and
View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName =
''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [科教文卫类]

from View_LA01_LE01_20090209  where  (LA0110 = ''01'' or LA0110 = ''02'' or LA0110
= ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111''  group by
LA0110,AA0107,A0405R03',

@PageSize=10,@PageCurrent=1,

@FdShow=N'专家类别,性别,学历,[科教文卫类],[经济技术类],[外专证],[来华许可证]',
@FdOrder=N'专家类别,性别,学历',

@sql=N'
select count(*) as count from(Select top 100 percent LA0110 as [专家类别],AA0107 as [性别],A0405R03 as [学历],(select count(LA0106) From View_LA01_LE01_20090209 as t where
1=1  and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and

( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' )))
as [来华许可证],
(select count(LA0175) From View_LA01_LE01_20090209 as t where 1=1  and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107=
t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and
PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [外专证],

(select count(LA0110) From View_LA01_LE01_20090209 as t where 
t.LA0110=''01'' and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and (
(LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 =
''1111111'' ))) as [经济技术类],

(select count(LA0110) From View_LA01_LE01_20090209 as t where  t.LA0110=''02'' and (View_LA01_LE01_20090209.LA0110= t.LA0110 and
View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or
LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [科教文卫类]

from View_LA01_LE01_20090209  where  (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 =
''1111111''  group by LA0110,AA0107,A0405R03) as temptable',

@getcount=0

问题补充: 只对以下语句进行优化: Select top 100 percent LA0110 as [专家类别],AA0107 as [性别],A0405R03 as [学历], (select count(LA0106) From View_LA01_LE01_20090209 as t where 1=1 and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [来华许可证], (select count(LA0175) From View_LA01_LE01_20090209 as t where 1=1 and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [外专证], (select count(LA0110) From View_LA01_LE01_20090209 as t where t.LA0110=''01'' and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [经济技术类], (select count(LA0110) From View_LA01_LE01_20090209 as t where t.LA0110=''02'' and (View_LA01_LE01_20090209.LA0110= t.LA0110 and View_LA01_LE01_20090209.AA0107= t.AA0107 and View_LA01_LE01_20090209.A0405R03= t.A0405R03 and ( (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' ))) as [科教文卫类] from View_LA01_LE01_20090209 where (LA0110 = ''01'' or LA0110 = ''02'' or LA0110 = ''经济技术类'' or LA0110 = ''科教文卫类'' ) and PersonName = ''AAAA'' and AA0111 = ''2009-03-20'' and LA0159 = ''1111111'' group by LA0110,AA0107,A0405R03'
飛雪飄寒的主页 飛雪飄寒 | 初学一级 | 园豆:30
提问于:2009-03-31 15:29
< >
分享
其他回答(2)
0

同意楼上的回答。

mjgforever | 园豆:335 (菜鸟二级) | 2009-03-31 18:48
0

这个看都没法看,别人怎么帮你呢,建议楼主将你要问的问题抽离出来,在最简单的情景下表达出来,这样别人才能尽量帮你。

生鱼片 | 园豆:5757 (大侠五级) | 2009-03-31 21:14
0

代码太多了……

落葉一飄 | 园豆:2 (初学一级) | 2009-04-09 14:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册