![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a huge table and I have the following requirement : Table1 --------- client day_of_sale qty Table2 --------- same ddl Now table2 needs to have the same data except for the first day_of_sale value for each client. So I have the query select client,day_of_sale,qty from table(select client,day_of_sale,qty, row_number() over(partition by client order by day_of_sale) as rownum ) from table1 where rownum>1 This gives me a huge cost since its going to build up the inner table and then select the 'rest' of the columns in the outer table. To stop doing the two scans (use lesser memory to store the whole inner table in buffer and then loop through it), what we did was 1. add the row number column in table 2 2. put in a check constraint in the table 2 that has only >1 3. load to table 2 4. set integrity This eats up the concurrency of our project since the loaded table can't be used while the load happens. So I would be very happy if someone can give me a single sql without CTE to do the above. We are playing with the OLAP and windowing functions, but no joy till now. Any help or suggestions plz |
#3
| |||
| |||
|
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Table1 --------- create table table1(client char(5), day_of_sale date, qty bigint); Table2 --------- Same as table 1 Requirement - table1 is a staging table, gets loaded using an ETL. Table 2 is the production table. Due to a problem with client data, the first record for everymonth, every client,ex. ('Belgium','01/01/2010',-10) This will always have a negative value, and is junk data. |
#6
| |||
| |||
|
|
Table1 --------- create table table1(client char(5), day_of_sale date, qty bigint); Table2 --------- Same as table 1 Requirement - table1 is a staging table, gets loaded using an ETL. Table 2 is the production table. Due to a problem with client data, the first record for everymonth, every client,ex. ('Belgium','01/01/2010',-10) This will always have a negative value, and is junk data. |
#7
| |||
| |||
|
|
On 2010-04-27 13:07, Arun Srini wrote: Table1 --------- create table table1(client char(5), day_of_sale date, qty bigint); Table2 --------- Same as table 1 Requirement - table1 is a staging table, gets loaded using an ETL. Table 2 is the production table. Due to a problem with client data, the first record for everymonth, every client,ex. ('Belgium','01/01/2010',-10) This will always have a negative value, and is junk data. Are these the only ones with a negative value? /Lennart [...] |
#8
| |||
| |||
|
|
On Apr 27, 6:59*pm, Lennart Jonsson <erik.lennart.jons... (AT) gmail (DOT) com wrote: On 2010-04-27 13:07, Arun Srini wrote: Table1 --------- create table table1(client char(5), day_of_sale date, qty bigint); Table2 --------- Same as table 1 Requirement - table1 is a staging table, gets loaded using an ETL. Table 2 is the production table. Due to a problem with client data, the first record for everymonth, every client,ex. ('Belgium','01/01/2010',-10) This will always have a negative value, and is junk data. Are these the only ones with a negative value? /Lennart [...] sorry the data tended to be misleading. The qty can be negative, this is because the company would use negative values to give additional data about the 'returns' of their products from customers. |

![]() |
| Thread Tools | |
| Display Modes | |
| |