Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Tricky SQL Question -- Solved
Okay,
I cracked it ... if you are interested, read on ... it is not very optimal, but close to what I want. To me 8 streams is standard, so you'd see 8 as hardcoded. Also I found that
select sum(obj_last_analyze_time)/8 from statistics_info
/
was about 8425 (i.e. ~ 85 seconds).
So I wrote this not-so-dynamic sql
select group_id, sum(tm1), count(*)
from(
SELECT obj_owner, obj_name, tm1,
case when roll_sum <= 8400*1 then 1 else case when roll_sum <= 8400*2 then 2 else case when roll_sum <= 8400*3 then 3 else case when roll_sum <= 8400*4 then 4 else case when roll_sum <= 8400*5 then 5 else case when roll_sum <= 8400*6 then 6 else case when roll_sum <= 8400*7 then 7 else 8 end end end end end end end group_id FROM (SELECT rnum, obj_owner, obj_name, tm1, SUM (tm1) OVER (ORDER BY rnum RANGE UNBOUNDED PRECEDING) roll_sum FROM (SELECT ROWNUM rnum, obj_owner, obj_name, tm1 FROM (SELECT obj_owner ,obj_name,obj_last_analyze_time tm1 FROM statistics_info ORDER BY obj_last_analyze_time)))) group by group_id
The output is as follows ...
"GROUP_ID" "TOT_TIME" "TOT_TABLES"
---------- ------------ ------------
1 8397 1755 2 8387 667 3 8204 135 4 7984 20 5 8954 7 6 6928 3 7 7113 2 8 11438 1
I'll probably make it dynamic enough ... inside my package ...
Cheers
Raj
-----Original Message-----
Sent: Thursday, March 06, 2003 1:16 PM
To: 'ORACLE-L_at_fatcity.com'
----- Original Message -----
To: "Multiple recipients of list ORACLE-L" <ORACLE-L_at_fatcity.com>
Sent: 06 March 2003 16:49
> Hi all, > > I have a tricky situation ... I have a table > > columns are > owner varchar2(), > name varchar2(), > ana_tm number > > ana_tm represents how much time it took to perform statisticscollection for
> subject to change. and say sum(ana_tm) over the table is say X. > > What I'd like to have is split this data into say N groups (Let'ssay 8),
> example). > > What I need is a way in SQL to splice the table list in eight groupsso that
> assumes a linear distribution, which I do not have. > > Is this possible to do in SQL only? > > Thanks in advance, yes, you can go crazy with syntax, it is 9202. > Raj
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Jamadagni, Rajendra INET: Rajendra.Jamadagni_at_espn.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Thu Mar 06 2003 - 13:38:48 CST
- text/plain attachment: ESPN_Disclaimer.txt
![]() |
![]() |