x=0.623
k_p            ze_01         ze_02         ze_03     ......     
1              0.072         0.115          0.216     ......
2              0.207         0.297          0.711     ......
3              0.676         0.872          1.237     ......
4              0.989         1.239          1.695     ......
5              1.344         1.646          2.187     ......
...            ...            ...            ...求与X值最相近的值所在列,最后返回列名!!!各位大侠帮忙!!!

解决方案 »

  1.   

    呵呵,看到X值第一反应就想到了牛X!写存储过程吧。可能要用到ORACLE的自带函数:SIGN和ABS还有冒泡排序比较值。
      

  2.   

    with s1 as
    (select min(ze_01-0.623) a,'ze_01' col_name from t 
    union all
    select min(ze_02-0.623) a,'ze_02' col_name from t
    union all
    select min(ze_03-0.623) a,'ze_03' col_name from t
    )
    select col_name from s1
    where a =(select min(a) from s1)
      

  3.   

    up
    一个sql会死人的,用存储过程
      

  4.   

    按2楼改的
    with s1 as
    (select abs(ze_01-0.623) a,'ze_01' col_name from t 
    union all 
    select abs(ze_02-0.623) a,'ze_02' col_name from t 
    union all 
    select abs(ze_03-0.623) a,'ze_03' col_name from t 
    )
    select col_name from s1 
    where a in (select min(a) from s1);
      

  5.   

    有很多列,就写成动态的sql啦。