1  2  3  4  5
--------------
a
   b
      c
         d
            c
5条记录
查询为
1  2  3  4  5
--------
a  b  c  d  e
sql怎么写

解决方案 »

  1.   

    select tb1.col1,tb2.col2,tb3.col3,tb4.col4,tb5.col5 from
    (select col1 , px = (select count(1) from tb where col1 <> '' and col1 > t.col1) from tb t where col1 <> '') tb1,
    (select col2 , px = (select count(1) from tb where col2 <> '' and col2 > t.col2) from tb t where col2 <> '') tb2,
    (select col3 , px = (select count(1) from tb where col3 <> '' and col3 > t.col3) from tb t where col3 <> '') tb3,
    (select col4 , px = (select count(1) from tb where col4 <> '' and col4 > t.col4) from tb t where col4 <> '') tb4,
    (select col5 , px = (select count(1) from tb where col5 <> '' and col5 > t.col5) from tb t where col5 <> '') tb5
    where tb1.px = tb2.px and tb1.px = tb3.px and tb1.px = tb4.px and tb1.px = tb5.px