查询条件中,当表1的id=1时,查询条件是一种情况,当表1的id=2时,查询条件是另外一种情况,请问这个where该如何写?
解决方案 »
- oracle11g 一些服务自动停止,如果它们没有什么可做的,例如“性能日志和警报”服务
- 增量为1的备份:level 1 是什么意思?
- Oracle 9i备份还原ORA-01920错误
- 海量数据查询是如何高效实现的
- 分不多了,请那位大师帮忙看看,解决立刻给分!!
- 问一个SQL语句的写法
- 再问行转列的问题?请大家指教
- 如果对一个占用表空间很大的表增加字段有可能造成这张表的数据丢失吗?应该如何防范这种情况?
- 能改进下吗 求简便点的方法
- PRO*C 动态sql UPDATE语句报1403错误
- 用VC++使用ADO连接Oracle 10g 在XP系统下运行连接不上,在Vista下完全正常!!!
- insert into T_A(id, code, name) select T_B.code, T_B.name, T_C.id
from 表1
where id=1 and ...unionselect ...
from 表1
where id=2 and ...
如果当表1的id=1时,查询条件是一种情况
如果当表1的id=2时,查询条件是另外一种情况
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
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)
???? 这样符合楼主的要求么
---------------
select * from myTable where decode(wa0201,'1',colunm2,'2',colunm3) = decode(id,'1',colunm1_value,'2',colunm3_value);
// 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 ";
or (id=2 AND 条件)