![]() | |
#1
| |||
| |||
|
|
I've got a table with the following layout: create table CUST_HIST ( customer_id int, activity_date datetime col_a int, col_b int, col_c int) I want to delete old data from the table and leave the most recent twenty rows (based on date) for each customer. Is there an efficient way to do this (ie: not using cursors)? We're using ASE 12.5.0.3 Thanks. Howabout: |
#2
| |||
| |||
|
|
On Fri, 05 Dec 2003 04:05:58 +0000, How'd they do that? wrote: [quoted text muted] Howabout: set rowcount 20 select * into #temp from CUST_HIST delete from CUST_HIST insert into CUST_HIST select * from #temp |
#3
| |||
| |||
|
|
I've got a table with the following layout: create table CUST_HIST ( customer_id int, activity_date datetime col_a int, col_b int, col_c int) I want to delete old data from the table and leave the most recent twenty rows (based on date) for each customer. Is there an efficient way to do this (ie: not using cursors)? |
#4
| |||
| |||
|
|
How'd they do that? wrote: I've got a table with the following layout: create table CUST_HIST ( customer_id int, activity_date datetime col_a int, col_b int, col_c int) I want to delete old data from the table and leave the most recent twenty rows (based on date) for each customer. Is there an efficient way to do this (ie: not using cursors)? Here's the basic idea off the top of my head. You'll have to tune this to soemthing that acutally works. delete from cust_hist where customer_id not in ( select customer_id from cust_hist o where 20 < ( select count(*) from cust_hist i where i.activity_date > o.activity_date ) ) IE, select the cust_hist rows where fewer than 20 rows have a later date. These are the latest 20. Delete the rows that are not one of these 20. Larry Coon University of California |
#5
| |||
| |||
|
|
I've got a table with the following layout: create table CUST_HIST ( customer_id int, activity_date datetime col_a int, col_b int, col_c int) I want to delete old data from the table and leave the most recent twenty rows (based on date) for each customer. Is there an efficient way to do this (ie: not using cursors)? We're using ASE 12.5.0.3 Thanks. |
#6
| |||
| |||
|
|
Only keeps last 20 rows, not last 20 per customer. Right? |
![]() |
| Thread Tools | |
| Display Modes | |
| |