结构表Table id,cTime,valueA,valueB,valueC;这样的表有12张,表名Table200601,Table200602,Table200603……
Table200612;给定一个ID,从这12张表中找出ValueA,ValueB,valuesC 的最大值--max(ValueA,ValueB,ValueC),以及cTime,并要知道这个最大值是ValueA,还是ValueB,还是ValueC所对应的?
谢谢

解决方案 »

  1.   

    12张表的结构都一样吗?建一个基于(Union)这12张表的view。问题不是简单多了吗?
      

  2.   

    select cTime,greatest(valueA,valueB,valueC) max_value from table where id = ?
    选出最大值
      

  3.   

    12 张表结构是一样的。 to kingkingkingking 
      但我还要知道 这个最大值是valueA对应的还是valueB, 还是ValueC所对应的
      

  4.   

    select
      cTime,
      greatest(valueA,valueB,valueC) max_value, 
      decode(sign(valueA-valueB),-1,
        decode(sign(valueB-valueC), -1, 'valueC', 'valueB'),
        decode(sign(valueA-valueC),-1,'valueC','valueA')) 
    from 
      table 
    where
      id = ?