ITPUB??ì3
12月微软Hyper-V虚拟化沙龙主题征集
ITPUB论坛 » Oracle开发 » SQL语句查询问题

标题: SQL语句查询问题
离线 asdfghjkl1127
初级会员



精华贴数 0
个人空间 0
技术积分 41 (32533)
社区积分 0 (1195614)
注册日期 2006-11-26
论坛徽章:0
      
      

发表于 2008-9-21 09:50 
SQL语句查询问题

create table A as select art_no from article;
create table b as select art_no from tb_fin_art_stock where art_status=1;
上面的两个表是我SELETE的条件

select t.art_no from A,tax t where t.art_no=A.art_no and t.art_no not in (select art_no from B);
问题1:  上面这个SELECT语句可以优化么?怎么优化?
                    
问题2:我想在不建立这两个表的情况下在SELECT语句中直接实现查询:
如:
select t.art_no
from tax t,(select art_no from A) a,(select art_no from B) b
where

这个条件应该怎么写啊??

谢谢各位大大了,祝各位大大心想事成,万事如意!


只看该作者    顶部
离线 sunfly1983
我以出仓,感觉良好!


精华贴数 0
个人空间 0
技术积分 1181 (1552)
社区积分 1695 (710)
注册日期 2006-10-14
论坛徽章:12
生肖徽章2007版:猪生肖徽章2007版:猪生肖徽章2007版:猪2008北京奥运纪念徽章:皮划艇激流回旋生肖徽章2007版:猪生肖徽章2007版:猪
生肖徽章2007版:鸡生肖徽章2007版:猪2008北京奥运纪念徽章:沙滩排球2008北京奥运纪念徽章:排球  

发表于 2008-9-21 10:30 
呵呵!不用这么复杂吧!
select art_no from tb_fin_art_stock where art_status<>1;


只看该作者    顶部
离线 kmpx
VICTORY


精华贴数 0
个人空间 0
技术积分 1078 (1713)
社区积分 1 (43006)
注册日期 2006-10-8
论坛徽章:1
2008北京奥运纪念徽章:铁人三项     
      

发表于 2008-9-21 10:31 
2.
select art_no from article
union
create table b as select art_no from tb_fin_art_stock where art_status=1;
优化走索引还是全表快看查询计划吧,not in和not exists看哪个代价低


__________________
别揣着糊涂装明白
只看该作者    顶部
离线 mychary
高级会员



来自 合肥
精华贴数 0
个人空间 0
技术积分 7116 (186)
社区积分 164 (2687)
注册日期 2003-9-18
论坛徽章:11
ITPUB元老会员2007贡献徽章会员2006贡献徽章授权会员生肖徽章2007版:鼠生肖徽章2007版:马
2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:花样游泳数据库板块每日发贴之星数据库板块每日发贴之星数据库板块每日发贴之星 

发表于 2008-9-21 10:34 
create table A as select art_no from article;
--没有必要建立该表,在 art_no  列上建立索引即可。
create table b as select art_no from tb_fin_art_stock where art_status=1;
-- 建表开销和维护都麻烦,可以考虑建立视图


只看该作者    顶部
离线 asdfghjkl1127
初级会员



精华贴数 0
个人空间 0
技术积分 41 (32533)
社区积分 0 (1195614)
注册日期 2006-11-26
论坛徽章:0
      
      

发表于 2008-9-21 10:37 
不好意思啊,可能我没有说清楚,article和tb_fin_art_stock表中的art_no这个字段的值是不同的

而且我只是打个比方,查询语句太复杂,我就没有全打出来了。

不过还是谢谢了!


只看该作者    顶部
离线 mychary
高级会员



来自 合肥
精华贴数 0
个人空间 0
技术积分 7116 (186)
社区积分 164 (2687)
注册日期 2003-9-18
论坛徽章:11
ITPUB元老会员2007贡献徽章会员2006贡献徽章授权会员生肖徽章2007版:鼠生肖徽章2007版:马
2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:花样游泳数据库板块每日发贴之星数据库板块每日发贴之星数据库板块每日发贴之星 

发表于 2008-9-21 10:38 
select t.art_no from A,tax t where t.art_no=A.art_no and t.art_no not in (select art_no from B);
问题1:  上面这个SELECT语句可以优化么?怎么优化?
--- 如果是我,可能会这样写
select t.art_no from tax t,(select art_no from A minus select art_no from B) c
where t.art_no=c.art_no


只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问