把几行数据选成一行显示,不重复

为了让界面显示更多数据,业务需要把一个表的数据,在表格里面,一行显示3条数据。。。。。

 

比如

c1 c2 

1   2

3   4

5   6

7   8

要显示成

c11 c12 c21 c22 c31 c32

1      2    3     4    5     6

7      8

 

 

想了半天,用rownum解决了这个问题,代码如下:

select num1, storage_no1, storage_name1, num2,storage_no2, storage_name2 ,num3,storage_no3, storage_name3  from 

(select * from 

        (select rownum as num1, storage_no as storage_no1, storage_name as storage_name1 from Base_Storage where

                Base_Storage.Area_No='H'

        ) b1

                left join

        (select rownum as num2, storage_no as storage_no2, storage_name as storage_name2 from Base_Storage where

                Base_Storage.Area_No='H'

         ) b2

on (b1.num1+1)=b2.num2) t1

left join

(select rownum as num3, storage_no as storage_no3, storage_name as storage_name3 from Base_Storage where

                Base_Storage.Area_No='H'

         ) b3

on (t1.num2+1)=b3.num3

where  mod( t1.num1,3)=1

 

最后这个mod 3操作会把多于的数据过滤掉

你可能感兴趣的:(数据)