现在我的表结构是这样的
 F1        F2
01Q1       8
01A1       7
01C1       7
01Q1       4
01A1       5
01C1       5
这块表里没有ID这个字段,现在我要搜出这样的结果
 id       F2        BM1        BM2
  1        8       01Q1            
  2        7       01A1        01C1
  3        4       01Q1            
  4        5       01A1        01C1
我现在用的语句是这样的
select  rownum id ,aa.*
from (select 
'' as Xq_Num,a.hh as user_num,a.jh as bur_num
from (helectro.zydnb@dbLink) a,v_comp,(helectro.yhda@dbLink) c 
where a.hh = c.hh and a.hh = v_comp.hh and v_comp.hh = c.hh )aa
union 
select  rownum id ,bb.*
from (select 
'' as Xq_Num,a.hh as user_num,a.jh as bur_num
from (helectro.zydnb@dbLink) a,v_comp,(helectro.yhda@dbLink) c 
where a.hh = c.hh and a.hh = v_comp.hh and v_comp.hh = c.hh ) bb
可得到的结果却是
 id       F2        BM1        BM2
  1        8       01Q1            
  2        7       01A1        01C1
  3        7       01A1        01C1
  4        4       01Q1            
  5        5       01A1        01C1
  6        5       01A1        01C1
这是为什么,应该怎么改?

解决方案 »

  1.   

    try this:select rownum id, x.*
    from (
    select aa.*
    from (select 
    '' as Xq_Num,a.hh as user_num,a.jh as bur_num
    from (helectro.zydnb@dbLink) a,v_comp,(helectro.yhda@dbLink) c 
    where a.hh = c.hh and a.hh = v_comp.hh and v_comp.hh = c.hh )aa
    union all
    select  bb.*
    from (select 
    '' as Xq_Num,a.hh as user_num,a.jh as bur_num
    from (helectro.zydnb@dbLink) a,v_comp,(helectro.yhda@dbLink) c 
    where a.hh = c.hh and a.hh = v_comp.hh and v_comp.hh = c.hh ) bb
    ) x
      

  2.   

    多谢Eric_1999(╙@^@╜) 兄弟,问题已解决,分给你