If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > 1000 rows per dbp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-06, 17:39
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
1000 rows per dbp

8.1 fp 5 64 bit aix5.2, 50 dbps
moving to 8.1 fp 10 64 bit on aix 5.2, 70 dbps

Looking for a way to select 1000 rows per dbp for an archive/purge application which will then go across 10+ tables and purge data.

I am trying the following and getting the error shown

select sale_sys_id from xyz.sale where sale_dt < date('2006-03-01') - 70 months group by nodenumber(sale_sys_id) having count(nodenumber(sale_sys_id)) <=1000

SQL0119N An expression starting with " SALE_SYS_ID" specified in a SELECT
clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY
clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a
column function and no GROUP BY clause is specified. SQLSTATE=42803

Any thoughts and recommendations highly appreciated.
Reply With Quote
  #2 (permalink)  
Old 04-17-06, 17:49
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Not sure if this is what you want, but it is the standard syntax for a group by with count:

select nodenumber(sale_sys_id), count(*) from xyz.sale where sale_dt < date('2006-03-01') - 70 months group by nodenumber(sale_sys_id) having count(*) <=1000
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390

Last edited by Marcus_A; 04-17-06 at 18:15.
Reply With Quote
  #3 (permalink)  
Old 04-17-06, 23:08
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
I appreciate the response. I'm really looking to select 1000 (or n) sys_id's per dbp into a staging table and then use the staging table to colocated delete from 10+ base tables.

Also, I'd like to make the number of partitions transparent and jsut make it n rows per dbp across the board regardless of the number of dbps.
Reply With Quote
  #4 (permalink)  
Old 04-18-06, 07:31
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
If you are selecting say, just 1000 records or even a few thousands, then the optimizer should be doing a good job by sending these ids (a small data transfer) and execute the delete without moving large tables ...

If you want to get 1000 rows per dbp, the option may be to use the RANK OLAP Function and partition by the nodenumber ..

select * from
(select c1,c2,rownum() over (partition by nodenumber(id)) as r from xyz ) as temp where r<=1000

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #5 (permalink)  
Old 04-18-06, 10:34
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
This is the SQL I ran

select * from (select sale_sys_id, rownum() over (partition by nodenumber(sale_sys_id))as r from xyz.sale where sale_dt < date('2006-03-01') - 70 months ) as temp where r<=100;

SQL0440N No authorized routine named "ROWNUM" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884

Did you mean to use the row_number function?
Reply With Quote
  #6 (permalink)  
Old 04-18-06, 10:55
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
ok. using row_number() worked. This is wonderful! Thank you very much.
Reply With Quote
  #7 (permalink)  
Old 04-18-06, 12:29
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
I had actually meant RANK ... But if your sale_sys_id is unique, then RANK or ROW_NUMBER should not make any difference

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #8 (permalink)  
Old 04-18-06, 16:46
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
It is unique. But I'll try rank is well. Thanks again.
Reply With Quote
  #9 (permalink)  
Old 04-19-06, 04:31
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
What does "dbp" mean? I searched the on-line DB2 manual, but only found it in dbp[assword].
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #10 (permalink)  
Old 04-19-06, 09:57
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
dbp : database partition
dbpg : database partition group
Reply With Quote
  #11 (permalink)  
Old 04-20-06, 00:40
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
The select works fine as a select. However, when embedded as a subselect of an insert statement, it does not work. Not quite sure how to get around it.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On