免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2393 | 回复: 11
打印 上一主题 下一主题

下面这句sql是否还可以优化? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-12-08 14:44 |只看该作者 |倒序浏览
select count(distinct ly1802) from lyplibs/lyf18 where           
ly1840 = '10500016' and ly1809 >;= 20041101 and ly1809<=20041115  
and ly1816 >;= '2' and ly1802 in                                 
  (select ly1802 from lyplibs/lyf18,lyplibs/lyf11                 
   where ly1840 = '10500016' and ly1809 >;= 20041101 and ly1809   
   <=20041115 and ly1816 >;= '2' and  ly1840 = ly1120              
    and ly1806 = ly1101                                          
    group by ly1802                                               
    having (sum(ly1823/ly1112)<=5))        

论坛徽章:
0
2 [报告]
发表于 2004-12-08 15:06 |只看该作者

下面这句sql是否还可以优化?

自己用db2advise先看看吧~!

论坛徽章:
0
3 [报告]
发表于 2004-12-08 15:21 |只看该作者

下面这句sql是否还可以优化?

不好意思,db2advise是本书?
可否提供一下。

论坛徽章:
0
4 [报告]
发表于 2004-12-08 15:35 |只看该作者

下面这句sql是否还可以优化?

db2advis is a DB2 command which will advise you what index should create. Besides, you may use explain sql to view which part of your sql cause it become slow...

论坛徽章:
0
5 [报告]
发表于 2004-12-08 15:44 |只看该作者

下面这句sql是否还可以优化?

i c
but could anyone give some advise on my current sql sentence?

论坛徽章:
0
6 [报告]
发表于 2004-12-08 16:10 |只看该作者

下面这句sql是否还可以优化?

frankly speaking, it is very difficult to give any comment on your sql becuase I do not know what you trying to do with the sql. Anyway for my opinion, whenever your sql have to link more than 1 table then use join rather than tranditional method.

论坛徽章:
0
7 [报告]
发表于 2004-12-08 16:20 |只看该作者

下面这句sql是否还可以优化?

I used join yet.

I could describe what I want to do:

比如A表是一张明细表,包括编号,地区,数量,那么我先将A表按编号group一下,求出每一个编号的sum(数量),而我要求的是sum(数量)>;5的那些编号,这个就是我现在用子查询做到的。
最终要求的是sum(数量)>;5的那些编号的总数。

论坛徽章:
0
8 [报告]
发表于 2004-12-11 13:36 |只看该作者

下面这句sql是否还可以优化?

可以使用公共表表达式简化你的查询,但具体有没有提高性能,你自己再用存取计划看一下,要不只能从建索引上面下功夫了。
写法如下:
with temp as
(select ly1802 from lyplibs/lyf18,lyplibs/lyf11
where ly1840 = '10500016' and ly1809 >;= 20041101 and ly1809
<=20041115 and ly1816 >;= '2' and ly1840 = ly1120
and ly1806 = ly1101
group by ly1802
having (sum(ly1823/ly1112)<=5))
select count(*) from temp;

论坛徽章:
0
9 [报告]
发表于 2004-12-11 13:38 |只看该作者

下面这句sql是否还可以优化?

呵~~
性能应该提高了很多了,你可以试一下。

论坛徽章:
0
10 [报告]
发表于 2004-12-29 13:15 |只看该作者

下面这句sql是否还可以优化?

daliwa
很厉害
PFPF!
谢谢谢谢:)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP