SunQuest
           Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old June 4th, 2004, 07:20 PM
hudo hudo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 97 hudo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 19 sec
Reputation Power: 5
GROUP and ROLLUP

Hello,

I got the following table-description:

CREATE TABLE COL_TABLE
(COL1 VARCHAR2(10),
COL2 VARCHAR2(10),
COL3 VARCHAR2(10),
COL4 NUMBER(4),
COL5 NUMBER(4));

with the following entries:

COL1 COL2 COL3 COL4 COL5
AAA STA1 1 10 1
AAA STA1 1 11 60
AAA STA1 1 12 1
AAA STA1 2 19 50
AAA STA1 2 9 1
AAA STA2 1 9 1
AAA STA2 1 9 1
AAA STA2 3 9 40
AAA STA3 2 7 1
AAA STA3 2 17 1
AAA STA3 2 12 1

and I'd like to have the as a result from an sql-statement:

COL1 COL2 TO_COL5 TOTAL
AAA STA1 1 3
AAA STA1 <>1 2
AAA STA2 1 2
AAA STA2 <>1 1
AAA STA3 1 3


This looks similar to the following sql-query:

SELECT COL1, COL2 ,COL5
,COUNT(*) "TOTAL"
FROM COL_TABLE
GROUP BY ROLLUP(COL1,COL2,COL5);

but first: the superordinated rows are deleted
second: the entries in COL5 are divided in two groups: entry = 1 ; entry <>1 (for example software-programms exit-code 1 means everything ok, while a code <>1 indicates an error).
So I want to sum up all "good" programm-exit and all "erroneous" programm-exits.


Thanks in advance

Reply With Quote
  #2  
Old June 4th, 2004, 09:46 PM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
SELECT col1,col2 || ' =' def,sum(col5)
FROM col_table
WHERE col5 =1
GROUP BY col1,col2 || ' ='
UNION
SELECT col1,col2 || ' <>' def,sum(col5)
FROM col_table
WHERE col5<>1
GROUP BY col1,col2 || ' <>'
ORDER BY col1, def
/

Reply With Quote
  #3  
Old June 4th, 2004, 09:50 PM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
plz add 1 also in string as follows:

SELECT col1,col2 || ' =1' def,sum(col5)
FROM col_table
WHERE col5 =1
GROUP BY col1,col2 || ' =1'
UNION
SELECT col1,col2 || ' <>1' def,sum(col5)
FROM col_table
WHERE col5<>1
GROUP BY col1,col2 || ' <>1'
ORDER BY col1, def

Reply With Quote
  #4  
Old June 5th, 2004, 02:10 AM
hudo hudo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 97 hudo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 19 sec
Reputation Power: 5
Sorry,
but I do not want to add up the values of erroneous programm-exits,
I want to know how many erroneous programm-exits have been, and how many good programm-exits have been.
Just looking at the records with COL1=AAA AND COL2=STA1 :
There are 3 good programm-exits, and 2 erroneous programm-exits.
To go a step further, the next think would be a column with the percentage of the result:

COL1 COL2 TO_COL5 TOTAL PERCENTAGE
AAA STA1 GOOD 3 60%
AAA STA1 ERROR 2 40%
AAA STA2 GOOD 2 66.66%
AAA STA2 ERROR 1 33.33%
AAA STA3 GOOD 3 100%

Reply With Quote
  #5  
Old June 16th, 2004, 12:03 PM
astrocanis astrocanis is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 14 astrocanis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to astrocanis
easy way is to create package with stored procedure...next is to add selects to select statement with correlating where clause.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > GROUP and ROLLUP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway