select A.*, B.chinese_name,B.singer
from resource_detail A, resource B
where A.resource_id = 2038
and (
 A.filetype_id=43 or
 A.filetype_id=141 or
 A.filetype_id=142 or 
 A.filetype_id= 44......
 153,207,232,306,331,383,408,460,485,537,562,614,639,691 

and B.resource_id = A.resource_id;

解决方案 »

  1.   

    select A.*, B.chinese_name,B.singer
    from resource_detail A, resource B
    where B.resource_id = A.resource_id and A.resource_id = 2038
    and A.filetype_id in (
    43,141,142,144,153,207,232,306,331,383,408,460,485,537,562,614,639,691 ) ;
      

  2.   

    各位大GUO,这个filetype_id是建在另外一张表中的,filetype_id_resource
    查询语句是:select filetype_id from filetype_id_resource where id = ?
    这个id是唯一的。做表关联?就是将resource_detail A表中的filetype_id建外键,关联到filetype_id_resource.filetype_id 吗?
      

  3.   

    --e.g.create table tb as 
    select 43 id from dual union all
    select 141 id from dual union all
    select 142 id from dual union all
    select 144 id from dual union all
    select 153 id from dual union all
    select 207 id from dual union all
    select 232 id from dual union all
    select 306 id from dual union all
    select 331 id from dual union all
    select 383 id from dual union all
    select 408 id from dual union all
    select 460 id from dual union all
    select 485 id from dual union all
    select 537 id from dual union all
    select 562 id from dual union all
    select 614 id from dual union all
    select 639 id from dual union all
    select 691 id from dual;select A.*, B.chinese_name,B.singer
    from resource_detail A, resource B,tb C
    where A.resource_id = 2038
    and A.filetype_id = C.id
    and B.resource_id = A.resource_id;--如果A表中的filetype_id存在空值也就是NULL的时候,上面的and A.filetype_id = C.id
    要改成
    and (A.filetype_id = C.id or A.filetype_id is null)
    当然这个改动完全是你原句写法的要求,因为原句中的in(...)是表示A.filetype_id为空也符合要求。
      

  4.   

    就用in
    因为有些时候是没有办法的.
    in不用影响速度,
    除非索引没有建立好
      

  5.   

    那个字段没有建索引,in里面的数据一般有20几条,本身数据就有几十万,查询一条数据都得花费3s左右的时间,一次要查询几十条数据就得花不少时间啦。
    准备建个事务级的临时表,以为每个查询请求的这些id都是不一样的。
    访问程序一次,这些id是一样的;下次再访问的话,就可能不是这些id了;id的值是根据用户来定的。(转事务级临时表)
        2)事务级临时表是指该临时表与事务相关,当进行事务提交或者事务回滚的时候,临时表中的数据将自行被截断,其他的内容和会话级的临时表的一致(包括退出SESSION的时候,事务级的临时表也会被自动截断)。事务级临时表的创建方法:Create Global Temporary Table Table_Name(Col1 Type1,Col2 Type2...) On Commit Delete Rows;举例:create global temporary table Classes(Class_id Number(5),Class_Name Varchar2(8),Class_Memo varchar2(200)) on Commit delete Rows ;是不是只要一commit,insert到临时表中的数据就全部被删除了?
      

  6.   

    昨天的测试数据:
    1. 联查+IN11:27:17
    11:30:222. 联查和IN分开17:12:35
    17:16:003. 建临时表
    14:37:17
    14:41:48今天再次访问使用临时表的,只需要几秒,。难道是昨天网速太慢的缘由?不得而知,就用临时表了。