|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 / |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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% |
|
#5
|
|||
|
|||
|
easy way is to create package with stored procedure...next is to add selects to select statement with correlating where clause.
|
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > GROUP and ROLLUP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|