with the following data in the databaseA01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 C01
A01 B01 our fleet
A01 B01 C03
According to the three fields set pages, the first page, there are three data after the second page has five data,
When the key change, weight 1 began to add pages,
Want to the result of the following data
A01 B01 C01 1
A01 B01 C01 1
A01 B01 C01 1
A01 B01 C01 2
A01 B01 C01 2
A01 B01 C01 2
A01 B01 C01 2
A01 B01 C01 2
A01 B01 C01 3
A01 B01 C01 3
A01 B01 C01 3
A01 B01 C01 3
A01 B01 C01 3
A01 B01 C01 4
1
A01 B01 our fleetA01 B01 C03 1
Refer to the SQL language how to realize!!!!!!!!!!
CodePudding user response:
The second page 5, is how to?
CodePudding user response:
reference 1st floor wmxcn2000 response: 5, the second page of the is how to? The first 3 pages, the second page 5 is a fixed value, CodePudding user response:
with t as ( Select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'our fleet as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C03 as c3 from dual ), T1 as ( Select c1, c2 and c3 from t where rownum<3 Union all The select c1, c2 and c3 from t ) The select c1, c2, c3, ym from (select c1, c2, c3, trunc ((rm + 4)/5) ym, rownum rm1 from (select c1, c2, c3, row_number () over (partition by c3 order by c3) rm The from t1)) Where rm1 & gt;=3 CodePudding user response:
Number in the database is not fixed, CodePudding user response:
The reference 4 floor skypzg reply: the quantity of the database is not fixed, What you mean? CodePudding user response:
As with t ( Select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'our fleet as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C03 as c3 from dual ), T1 as (select t. *, row_number () over (partition by c1 and c2 and c3 order by c1 and c2 and c3) rm from t) Select a t1. *, 1, xh from t1 where rm<=3 union all select t1. *, trunc ((rm + 1)/5) from t1 where rm> 3 the order by 1, 2, 3, 4 CodePudding user response:
I listed the data only, for example, there will be a lot of the real database, not fixed number, CodePudding user response:
The reference 7 floor skypzg response: I only list of data, for example, there will be a lot of the real database, not fixed number, There are a lot of what happened to the data, there will be a problem? CodePudding user response:
Upstairs: that's a good idea, but suggested that modified algorithm, don't need to add in the select c1, c2 and c3 from t where rownum<3 As with t ( Select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual Union all select 'A01 as c1,' B01 as c2, 'C01 as c3 from dual nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull