能不能实现在select部分根据参数值来选择字段?
select
if x=1 then 字段ca
if x= 2 then 字段cb
if x= 3 then 字段c
from 表
where
if x= 1 then 条件1
if x= 2 then 条件2
if x=3 then 条件3
x为参数
问题点数:10、回复次数:3Top
1 楼cenlmmx(学海无涯苦作舟)回复于 2006-03-09 15:10:12 得分 5
select
decode(x,1,ca,2,cb,3,c,null) as "新字段"
from 表
where
(x= 1 and 条件1) or
(x= 2 and 条件2) or
(x= 3 and 条件3)
Top
2 楼citywanderer2005(流浪狗)回复于 2006-03-09 15:18:09 得分 5
1、select 部分:
decode(x, 1, 字段ca, 2, 字段cb, 3, 字段c) 字段
--------
有一个限制条件:三个字段的类型必须一致
2、where 部分:(举个例子)
假设条件1为:a>b, 条件2为: c>d, 条件3为: e>f
a>(decode(x, 1, b, a-1))
and c>(decode(x, 2, d, d-1))
and e>(decode(x, 3, f, f-1))
----------------
方法很笨,如果可以写存储过程的话最好写存储过程Top
3 楼citywanderer2005(流浪狗)回复于 2006-03-09 15:19:28 得分 0
嗯,楼上的方法好多了Top




