有这么一个表:列1             列2
id1              11
id2              12
id3              15
id4              13
id5              7
id6              5
id7              2
id8              1形成下面的表格:
列1       列2         列3(大于等于10)      列4(大于等于5小于10)       列5(大于0小于5)
id1       11              1                        0                       0
id2       12              1                        0                       0
id3       15              1                        0                       0
id4       13              1                        0                       0
id5       7               0                        1                       0
id6       5               0                        1                       0
id7       2               0                        0                       1
id8       1               0                        0                       1

解决方案 »

  1.   


    select 列1,列2,case when 列2 >= 10 then 1 else 0 end as 列3
                  ,case when 列2 >= 5 and 列2 < 10 then 1 else 0 end as 列4
                  ,case when 列2 > 0 and 列2 < 5 then 1 else 0 end as 列5
    from 表
      

  2.   

    with t as (
      select 'id1' col1, 11 col2 from dual union all
      select 'id2' col1, 12 col2 from dual union all
      select 'id3' col1, 15 col2 from dual union all
      select 'id4' col1, 13 col2 from dual union all
      select 'id5' col1, 7  col2 from dual union all
      select 'id6' col1, 5  col2 from dual union all
      select 'id7' col1, 2  col2 from dual union all
      select 'id8' col1, 1  col2 from dual)  
    select col1,col2,
      case when col2>=10 then 1 else 0 end col3, 
      case when col2>=5 and col2<10 then 1 else 0 end col4,
      case when col2>=0 and col2<5  then 1 else 0 end col5
    from t;