表a
clbm,clmc 
1     a
2     b
3     c
表b
clbma,clmca,clgg,  jj,    sj,  flbm
545    a1     re   8.0    8.0    1
434    a2     re   15.2   8.0    1
676    a3     re   9.0    8.0    1
21     b4     re   9.0    8.0    2
54     b1     re   9.0    8.0    2
67     b2     as   9.0    8.0    2
54     c1     d    9.0    8.0    3
23     c2     vc   9.0    8.0    3
5      c3     fd   9.0    8.0    3
54     c4     fd   9.0    8.0    3
要得到的结果:
1      a
545    a1     re   8.0    8.0    1
434    a2     re   15.2   8.0    1
676    a3     re   9.0    8.0    1
2      b
21     b4     re   9.0    8.0    2
54     b1     re   9.0    8.0    2
67     b2     as   9.0    8.0    2
3      c
54     c1     d    9.0    8.0    3
23     c2     vc   9.0    8.0    3
5      c3     fd   9.0    8.0    3
54     c4     fd   9.0    8.0    3

解决方案 »

  1.   

    select * from(select clbm as clbma,clmc as clmca,clgg='',  jj='',    sj='',  flbm='' from table1
    union all 
    select * from table2)a
    order by clmca
      

  2.   

    用 FULL JOIN ,根据第2个字段排序
      

  3.   

    说错了。。~-!
    、UNION ALL
      

  4.   

    jj 与sj 字段是money 型
      

  5.   

    select * from(select clbm as clbma,clmc as clmca,clgg=NULL,  jj=NULL,    sj=NULL,  flbm=NULL from table1
    union all 
    select * from table2)a
    order by clmca晕。。
      

  6.   

    select * from(select clbm as clbma,clmc as clmca,clgg='',  jj='',    sj='',  flbm='' from gdyj.pubcwcl
    union all 
    select clbma,clmca,clgg,cast(jj as char),cast(sj as char),flbm from dda)a order by clmca都不是想要的结果
      

  7.   

    不能按clmca字段来排序.会很乱的.
      

  8.   

    select clbma,clmc,clmca,clgg,  jj,    sj,  flbm from(select clbm as clbma,clmc as clmc,'' as clmca,clgg=NULL,  jj=NULL,    sj=NULL,  flbm=NULL,0 as ord from table1
    union all 
    select clbma,'',clmca,clgg,  jj,    sj,  flbm,1 as ord  from table2)a
    order by ord,clmca