0

RSC 通过比较 tab.col1 、 tab.col2 、tab.col3 、tab.col4 到 Result.INTR 的值

选项卡表有 1000 行

如果 col1 到 4 中的任何一个具有 NULL 则返回 1

Col1 will hold values pertaining to RID = 10
Col2 will hold values pertaining to RID = 20
Col3 will hold values pertaining to RID = 30
Col4 will hold values pertaining to RID = 40

例如:

    if tab.col1 is 3 then 4 
    if tab.col2 is 'R' then 3       
    if tab.col3 is 1900 then it query should give 4
    if 1945 then 3
    if 1937 then 3 (lower bound is less than and upper bound is greater than equal to)
    if tab.col4 is 6 then 5

and so on.....


Result table
     RID     INTR       RSC
     -----    -----      ----- 
      10        1         0
      10        2         1
      10        3         4                         
      10        4         2
      20        I         4
      20        R         3
      20        U         1
      30     1900         5
      30     1900-1937    4
      30     1937-1967    3
      30     1967         3
      40      3-4         2
      40      1-3         1
      40      4           5
4

3 回答 3

0

尝试类似:

select t1.RSC, t2.RSC, t3.RSC, t4.RSC
from your_table tab join Result t1 on t1.RID=10 and t1.INTR=tab.col1
     join Result t2 on t2.RID=20 and t2.INTR=tab.col2
     join Result t3 on t3.RID=30 and t3.INTR >= regexp_substr(tab.col3, '^\d*') and t3.INTR <= regexp_substr(tab.col3, '\d*$')
     join Result t4 on t4.RID=40 and t4.INTR >= regexp_substr(tab.col4, '^\d*') and t4.INTR <= regexp_substr(tab.col4, '\d*$')
于 2013-02-17T13:14:16.870 回答
0

你会这样做:

select (case when tab.col1 = 3 then 4
             when tab.col2 = 'R' then 3
             when tab.col3 = 1900 then 4
             when tab.col3 in (1945, 1937) then 3
             when tab.col4 = 6 then 5
        . . .
于 2013-02-15T18:04:42.727 回答
0

检查 Oracle.Google 的 CASE 和 DECODE 函数并检查一些示例。您将能够使用它们实现您的要求。

例如检查这个http://www.club-oracle.com/forums/case-and-decode-two-powerfull-constructs-of-sql-t181/

于 2013-02-15T17:46:57.187 回答