查询条件中,当表1的id=1时,查询条件是一种情况,当表1的id=2时,查询条件是另外一种情况,请问这个where该如何写?

解决方案 »

  1.   

    select ...
    from 表1
    where id=1 and ...unionselect ...
    from 表1
    where id=2 and ...
      

  2.   

    不是集合的关系,而是条件关系。
      如果当表1的id=1时,查询条件是一种情况
      如果当表1的id=2时,查询条件是另外一种情况
      

  3.   

    表1:
    id name sex mail age
    ----------
     1  ... 
     2  ...
    如上当表1中id =1 时,检索条件是sex =女,即where id  =1 and sex ='女'
    表1中id =2 时,检索条件中是age=12,即where id  =1 and age=12
      

  4.   

    用EXECUTE IMMEDIATE 来执行
      

  5.   

    动态语句实现吧。用条件判断ID值是否为1,2。相对应条件组成检索条件,然后使用EXECUTE IMMEDIATE SQLSTR INTO v1,v2....获取结果值。
      

  6.   

    表1:
    id name sex mail age
    ----------
     1  ... 
     2  ...
    如上当表1中id =1 时,检索条件是sex =女,即where id  =1 and sex ='女'
    表1中id =2 时,检索条件中是age=12,即where id  =1 and age=12========================
    你好像第二个条件写错了吧?即where id  =1 and age=12 >where id  =2 and age=12 
    不是想出下面的记录?
    select ...
    from 表1
    where (id  =1 and sex ='女') or (id  =2 and age=12)
      

  7.   


    ???? 这样符合楼主的要求么
    ---------------
    select * from myTable where decode(wa0201,'1',colunm2,'2',colunm3) = decode(id,'1',colunm1_value,'2',colunm3_value);
      

  8.   

    select * from myTable where decode(id,'1',colunm2,'2',colunm3) = decode(id,'1',colunm1_value,'2',colunm3_value);打错字  哈哈
      

  9.   

    //                this.PaginationDisplay2.Sql = @"select  t.TRAIN_MODEL_ID     ,
    //                                                        t.TRAIN_MODEL_NAME   ,                                              
    //                                                        tc.TRANING_SOURCE_NAME ,
    //                                                        tc.SOURCE_CODE     ,
    //                                                        tc.SOURCE_CREDITS    ,
    //                                                        tc.THEORY_TIME       ,
    //                                                        tc.PRACTICE_TIME     ,
    //                                                        et.EXAMIN_TYPE_NAME 
    //                                                        from training_model t  ,model_source_relations msr,training_courses tc ,examination_type et
    //                                                        where (t.TRAIN_MODEL_ID=msr.MODEL_ID and  msr.SOURCE_ID=tc.TRANING_SOURCE_ID and  tc.EXAMINATION_TYPE_ID= et.examin_type_id)";//                this.PaginationDisplay2.Sql += " and (";
    //                for (int i = 0; i < myList.Count; i++)
    //                {
    //                    if (i == 0)
    //                    { this.PaginationDisplay2.Sql += "t.TRAIN_MODEL_ID='" + myList[i].ToString() + "' "; }
    //                    else
    //                    { this.PaginationDisplay2.Sql += "or t.TRAIN_MODEL_ID='" + myList[i].ToString() + "' "; }
    //                }
    //                this.PaginationDisplay2.Sql += " ) ";//                this.PaginationDisplay2.Sql += " order by t.MODEL_CODE  asc ";
      

  10.   

    是不是这种AND的逻辑?where ((id=1) AND (条件))
       or (id=2 AND 条件)