oracle数据
有一个表如下
用户帐号 选择人1 钱数1 时间1  选择人2 钱数2 时间2 …… 选择人10,钱数10,时间10
 
uerid  eid1 mny1 dt1        eid2 mny2 dt2……eid10 mny10 dt10
0001    a1  100  2007-1-1   a2  100  2007-1-1 ……a7 100 2008-1-1
0002    a2  100  2006-1-1   a5  100  2006-1-1 ……a6 100 2008-1-1
0003    a3  100  2007-1-1   a9  100  2006-1-1 ……a2 100 2008-1-1实现下面的功能将eid1-eid10中a2找出来 显示userid和a2对应的mny和dt 并安装时间正序排列效果如下userid   mny    dt
0002     100   2006-1-1
0001     100   2007-1-1
0003     100   2008-1-1

解决方案 »

  1.   

    SELECT uerid, 
            case    when eid1 = 'a2' then mny1
                    when eid2 = 'a2' then mny2
    when eid3 = 'a2' then mny3
    when eid4 = 'a2' then mny4
    when eid5 = 'a2' then mny5
    when eid6 = 'a2' then mny6
    when eid7 = 'a2' then mny7
    when eid8 = 'a2' then mny8
    when eid9 = 'a2' then mny9
    when eid10 = 'a2' then mny10
                    else null
    end,
    dt
    FROM tab
    where eid1 = 'a2' or eid2 = 'a2' or eid3 = 'a2' or eid4 = 'a2' or eid5 = 'a2' or eid6 = 'a2' or eid7 = 'a2' or eid8 = 'a2' or eid9 = 'a2' or eid10 = 'a2'
    order by dt;
      

  2.   

    楼了dt,应该这样。SELECT uerid, 
            case    when eid1 = 'a2' then mny1
                    when eid2 = 'a2' then mny2
    when eid3 = 'a2' then mny3
    when eid4 = 'a2' then mny4
    when eid5 = 'a2' then mny5
    when eid6 = 'a2' then mny6
    when eid7 = 'a2' then mny7
    when eid8 = 'a2' then mny8
    when eid9 = 'a2' then mny9
    when eid10 = 'a2' then mny10
                    else null
    end as mny,
    case    when eid1 = 'a2' then dt1
                    when eid2 = 'a2' then dt2
    when eid3 = 'a2' then dt3
    when eid4 = 'a2' then dt4
    when eid5 = 'a2' then dt5
    when eid6 = 'a2' then dt6
    when eid7 = 'a2' then dt7
    when eid8 = 'a2' then dt8
    when eid9 = 'a2' then dt9
    when eid10 = 'a2' then dt10
                    else null
    end as dt
    FROM tab
    where eid1 = 'a2' or eid2 = 'a2' or eid3 = 'a2' or eid4 = 'a2' or eid5 = 'a2' or eid6 = 'a2' or eid7 = 'a2' or eid8 = 'a2' or eid9 = 'a2' or eid10 = 'a2'
    order by dt;
      

  3.   

    Eric_1999(╙@^@╜) 真是正解,万分感谢,接分!!!!!!!