A Better GROUP BY Query
Is there a better way to rewrite this query:
SELECT t.co, COUNT(*)
FROM (SELECT cd.co, cd.hl
FROM co_dev cd
GROUP BY cd.co, cd.hl) t
GROUP BY t.co
HAVING COUNT(*) > 1
Message was edited by:
mennan
Take a look at this, query provided by cd is better 1 sort comparing with one sort:
[email protected]> set autotrace on
[email protected]> select department_id, count(distinct job_id)
2 from employees
3
[email protected]> select department_id, count(distinct job_id)
2 from hr.employees
3 group by department_id
4 having count(distinct job_id) > 1;
DEPARTMENT_ID COUNT(DISTINCTJOB_ID)
20 2
50 2
80 2
90 2
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=1 Bytes=12)
1 0 FILTER
2 1 SORT (GROUP BY) (Cost=5 Card=1 Bytes=12)
3 2 TABLE ACCESS (FULL) OF 'EMPLOYEES' (Cost=4 Card=25 Byt
es=300)
Statistics
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
534 bytes sent via SQL*Net to client
499 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
4 rows processed
[email protected]> select department_id, count(*)
2 from (select department_id, job_id
3 from hr.employees
4 group by department_id, job_id) t
5 group by department_id
6 having count(*) > 1;
DEPARTMENT_ID COUNT(*)
20 2
50 2
80 2
90 2
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=1 Bytes=4)
1 0 FILTER
2 1 SORT (GROUP BY) (Cost=5 Card=1 Bytes=4)
3 2 VIEW (Cost=5 Card=25 Bytes=100)
4 3 SORT (GROUP BY) (Cost=5 Card=25 Bytes=300)
5 4 TABLE ACCESS (FULL) OF 'EMPLOYEES' (Cost=4 Card=25
Bytes=300)
Statistics
0 recursive calls
0 db block gets
7 consistent gets
0 physical reads
0 redo size
521 bytes sent via SQL*Net to client
499 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
4 rows processed
Best Regards
Krystian Zieja / mob
Similar Messages
-
"median count" in a single group by query
Hallo following problem:
i use a single group by query to analyze a data table.
like "select avg(parameter1), sum(parameter2), count(case when...end) from datatable where ....".
Following problem: I want a median of a count without rewriting the query completely, accessing the table several times or something.
Easy example - in Detail:
Create table and fill with example data
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> CREATE TABLE datatable
2 (
3 SLOT NUMBER
4 , DATA NUMBER
5 );
Table created.
SQL> INSERT INTO datatable VALUES (1,1);
1 row created.
SQL> INSERT INTO datatable VALUES (1,2);
1 row created.
SQL> INSERT INTO datatable VALUES (1,3);
1 row created.
SQL> INSERT INTO datatable VALUES (1,4);
1 row created.
SQL> INSERT INTO datatable VALUES (1,5);
1 row created.
SQL> INSERT INTO datatable VALUES (2,1);
1 row created.
SQL> INSERT INTO datatable VALUES (3,1);
1 row created.
SQL> INSERT INTO datatable VALUES (3,2);
1 row created.
SQL> INSERT INTO datatable VALUES (3,3);
1 row created.
SQL> INSERT INTO datatable VALUES (3,4);
1 row created.
SQL> INSERT INTO datatable VALUES (3,5);
1 row created.
SQL> INSERT INTO datatable VALUES (4,1);
1 row created.
SQL> INSERT INTO datatable VALUES (4,2);
1 row created.
SQL> INSERT INTO datatable VALUES (4,3);
1 row created.
SQL> INSERT INTO datatable VALUES (4,4);
1 row created.
SQL> INSERT INTO datatable VALUES (4,5);
1 row created.
SQL> INSERT INTO datatable VALUES (5,1);
1 row created.
SQL> INSERT INTO datatable VALUES (5,2);
1 row created.
SQL> INSERT INTO datatable VALUES (5,3);
1 row created.
SQL> INSERT INTO datatable VALUES (5,4);
1 row created.
SQL> INSERT INTO datatable VALUES (5,5);
1 row created.In the table there are several items (here slots) with a for each slot unique data-value.
I want to have the median count of data values, to filter out slots with more or less values.
this worked, until there where only slots with less data:
SQL> SELECT FLOOR(COUNT(DISTINCT SLOT||DATA)/COUNT(DISTINCT DATA)) FROM datatabl
e;
FLOOR(COUNT(DISTINCTSLOT||DATA)/COUNT(DISTINCTDATA))
4but when there is a slot having more data - it won't work, the very simple and stupid calculation will give a too little value
SQL>
SQL> INSERT INTO datatable VALUES (4,6);
1 row created.
SQL>
SQL> SELECT FLOOR(COUNT(DISTINCT SLOT||DATA)/COUNT(DISTINCT DATA)) FROM datatabl
e;
FLOOR(COUNT(DISTINCTSLOT||DATA)/COUNT(DISTINCTDATA))
3so what i would need is this:
SQL>
SQL> SELECT MEDIAN(count(DISTINCT SLOT) over (partition by DATA)) FROM datatable
SELECT MEDIAN(count(DISTINCT SLOT) over (partition by DATA)) FROM datatable
ERROR at line 1:
ORA-30483: window functions are not allowed hereIn detail:
the count delivers the distinct count of slots for each data (possible duplicated entrys should not be counted)
And I want the median, which should be 4.
SQL> SELECT count(DISTINCT SLOT) over (partition by DATA) FROM datatable;
COUNT(DISTINCTSLOT)OVER(PARTITIONBYDATA)
5
5
5
5
5
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
COUNT(DISTINCTSLOT)OVER(PARTITIONBYDATA)
1
22 rows selected.Is it -anyhow- possible to do this without rebuilding the whole query?
Thanks a lotok, an example:
CREATE TABLE "DATATABLE"
( "TOOL" CHAR(5 BYTE),
"SLOT" NUMBER,
"LOTID" CHAR(4 BYTE),
"STEP" VARCHAR2(44 BYTE),
"ENDTIME" DATE,
"PARAMETER1" NUMBER,
"PARAMETER6" NUMBER
Insert into DATATABLE values ('TOOL1',-1,'LOT1','STEP1',to_timestamp('02-FEB-12 03.09.42 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',-1,'LOT1','STEP2',to_timestamp('02-FEB-12 03.18.47 PM','DD-MON-RR HH.MI.SS AM'),42,0);
Insert into DATATABLE values ('TOOL1',-1,'LOT1','STEP3',to_timestamp('02-FEB-12 03.09.44 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',-1,'LOT1','STEP4',to_timestamp('02-FEB-12 02.20.38 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',-1,'LOT1','STEP5',to_timestamp('02-FEB-12 02.20.35 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',1,'LOT1','STEP1',to_timestamp('02-FEB-12 01.51.28 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',1,'LOT1','STEP2',to_timestamp('02-FEB-12 01.52.40 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',1,'LOT1','STEP3',to_timestamp('02-FEB-12 01.54.20 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',1,'LOT1','STEP4',to_timestamp('02-FEB-12 01.55.32 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',1,'LOT1','STEP5',to_timestamp('02-FEB-12 01.56.36 PM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',2,'LOT1','STEP1',to_timestamp('02-FEB-12 01.52.41 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',3,'LOT1','STEP1',to_timestamp('02-FEB-12 02.00.29 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',3,'LOT1','STEP2',to_timestamp('02-FEB-12 02.01.43 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',3,'LOT1','STEP3',to_timestamp('02-FEB-12 02.03.23 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',3,'LOT1','STEP4',to_timestamp('02-FEB-12 02.04.34 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',3,'LOT1','STEP5',to_timestamp('02-FEB-12 02.05.40 PM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',4,'LOT1','STEP1',to_timestamp('02-FEB-12 02.02.11 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',4,'LOT1','STEP2',to_timestamp('02-FEB-12 02.03.26 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',4,'LOT1','STEP3',to_timestamp('02-FEB-12 02.05.07 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',4,'LOT1','STEP4',to_timestamp('02-FEB-12 02.06.19 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',4,'LOT1','STEP5',to_timestamp('02-FEB-12 02.07.27 PM','DD-MON-RR HH.MI.SS AM'),20,0);
Insert into DATATABLE values ('TOOL1',5,'LOT1','STEP1',to_timestamp('02-FEB-12 02.03.54 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',5,'LOT1','STEP2',to_timestamp('02-FEB-12 02.05.08 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',5,'LOT1','STEP3',to_timestamp('02-FEB-12 02.06.49 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',5,'LOT1','STEP4',to_timestamp('02-FEB-12 02.08.01 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',5,'LOT1','STEP5',to_timestamp('02-FEB-12 02.14.26 PM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',6,'LOT1','STEP1',to_timestamp('02-FEB-12 02.05.35 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',6,'LOT1','STEP2',to_timestamp('02-FEB-12 02.06.50 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',6,'LOT1','STEP3',to_timestamp('02-FEB-12 02.15.14 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',6,'LOT1','STEP4',to_timestamp('02-FEB-12 02.16.26 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',6,'LOT1','STEP5',to_timestamp('02-FEB-12 02.17.31 PM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',7,'LOT1','STEP1',to_timestamp('02-FEB-12 02.06.42 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',8,'LOT1','STEP1',to_timestamp('02-FEB-12 02.14.14 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',8,'LOT1','STEP2',to_timestamp('02-FEB-12 02.15.29 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',8,'LOT1','STEP3',to_timestamp('02-FEB-12 02.17.09 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',8,'LOT1','STEP4',to_timestamp('02-FEB-12 02.18.22 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',8,'LOT1','STEP5',to_timestamp('02-FEB-12 02.23.31 PM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',9,'LOT1','STEP1',to_timestamp('02-FEB-12 02.58.14 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',9,'LOT1','STEP2',to_timestamp('02-FEB-12 02.15.32 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',9,'LOT1','STEP3',to_timestamp('02-FEB-12 02.59.30 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',9,'LOT1','STEP4',to_timestamp('02-FEB-12 03.01.15 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',9,'LOT1','STEP5',to_timestamp('02-FEB-12 03.07.52 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',10,'LOT1','STEP1',to_timestamp('02-FEB-12 02.23.20 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',10,'LOT1','STEP2',to_timestamp('02-FEB-12 02.24.39 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',10,'LOT1','STEP3',to_timestamp('02-FEB-12 02.26.19 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',10,'LOT1','STEP4',to_timestamp('02-FEB-12 02.27.30 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',10,'LOT1','STEP5',to_timestamp('02-FEB-12 02.28.34 PM','DD-MON-RR HH.MI.SS AM'),17,0);
Insert into DATATABLE values ('TOOL1',11,'LOT1','STEP1',to_timestamp('02-FEB-12 02.59.37 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',11,'LOT1','STEP2',to_timestamp('02-FEB-12 03.10.51 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',11,'LOT1','STEP3',to_timestamp('02-FEB-12 02.24.52 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',11,'LOT1','STEP4',to_timestamp('02-FEB-12 03.12.03 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',11,'LOT1','STEP5',to_timestamp('02-FEB-12 03.13.41 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',12,'LOT1','STEP1',to_timestamp('02-FEB-12 02.32.30 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',12,'LOT1','STEP2',to_timestamp('02-FEB-12 02.33.43 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',12,'LOT1','STEP3',to_timestamp('02-FEB-12 02.35.24 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',12,'LOT1','STEP4',to_timestamp('02-FEB-12 02.36.35 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',12,'LOT1','STEP5',to_timestamp('02-FEB-12 02.37.41 PM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',13,'LOT1','STEP1',to_timestamp('02-FEB-12 02.34.11 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',13,'LOT1','STEP2',to_timestamp('02-FEB-12 02.35.26 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',13,'LOT1','STEP3',to_timestamp('02-FEB-12 02.37.06 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',13,'LOT1','STEP4',to_timestamp('02-FEB-12 02.38.19 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',13,'LOT1','STEP5',to_timestamp('02-FEB-12 02.39.29 PM','DD-MON-RR HH.MI.SS AM'),17,0);
Insert into DATATABLE values ('TOOL1',14,'LOT1','STEP1',to_timestamp('02-FEB-12 02.35.54 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',14,'LOT1','STEP2',to_timestamp('02-FEB-12 02.37.08 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',14,'LOT1','STEP3',to_timestamp('02-FEB-12 02.38.48 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',14,'LOT1','STEP4',to_timestamp('02-FEB-12 02.40.01 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',14,'LOT1','STEP5',to_timestamp('02-FEB-12 02.41.13 PM','DD-MON-RR HH.MI.SS AM'),13,0);
Insert into DATATABLE values ('TOOL1',15,'LOT1','STEP1',to_timestamp('02-FEB-12 02.37.37 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',15,'LOT1','STEP2',to_timestamp('02-FEB-12 02.38.52 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',15,'LOT1','STEP3',to_timestamp('02-FEB-12 02.40.33 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',15,'LOT1','STEP4',to_timestamp('02-FEB-12 02.41.46 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',15,'LOT1','STEP5',to_timestamp('02-FEB-12 02.42.58 PM','DD-MON-RR HH.MI.SS AM'),17,0);
Insert into DATATABLE values ('TOOL1',16,'LOT1','STEP1',to_timestamp('02-FEB-12 02.39.20 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',16,'LOT1','STEP2',to_timestamp('02-FEB-12 02.40.34 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',16,'LOT1','STEP3',to_timestamp('02-FEB-12 02.42.16 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',16,'LOT1','STEP4',to_timestamp('02-FEB-12 02.43.29 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',16,'LOT1','STEP5',to_timestamp('02-FEB-12 02.44.42 PM','DD-MON-RR HH.MI.SS AM'),15,0);
Insert into DATATABLE values ('TOOL1',17,'LOT1','STEP1',to_timestamp('02-FEB-12 02.41.04 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',17,'LOT1','STEP2',to_timestamp('02-FEB-12 02.42.19 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',17,'LOT1','STEP3',to_timestamp('02-FEB-12 02.43.59 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',17,'LOT1','STEP4',to_timestamp('02-FEB-12 02.45.13 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',17,'LOT1','STEP5',to_timestamp('02-FEB-12 02.46.26 PM','DD-MON-RR HH.MI.SS AM'),13,0);
Insert into DATATABLE values ('TOOL1',18,'LOT1','STEP1',to_timestamp('02-FEB-12 02.42.49 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',18,'LOT1','STEP2',to_timestamp('02-FEB-12 02.44.03 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',18,'LOT1','STEP3',to_timestamp('02-FEB-12 02.45.44 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',18,'LOT1','STEP4',to_timestamp('02-FEB-12 02.47.01 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',18,'LOT1','STEP5',to_timestamp('02-FEB-12 02.48.10 PM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',19,'LOT1','STEP1',to_timestamp('02-FEB-12 02.44.33 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',19,'LOT1','STEP2',to_timestamp('02-FEB-12 02.45.47 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',19,'LOT1','STEP3',to_timestamp('02-FEB-12 02.47.31 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',19,'LOT1','STEP4',to_timestamp('02-FEB-12 02.48.45 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',19,'LOT1','STEP5',to_timestamp('02-FEB-12 02.49.58 PM','DD-MON-RR HH.MI.SS AM'),14,0);
Insert into DATATABLE values ('TOOL1',20,'LOT1','STEP1',to_timestamp('02-FEB-12 02.46.17 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',20,'LOT1','STEP2',to_timestamp('02-FEB-12 02.47.31 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',20,'LOT1','STEP3',to_timestamp('02-FEB-12 02.49.16 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',20,'LOT1','STEP4',to_timestamp('02-FEB-12 02.50.31 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',20,'LOT1','STEP5',to_timestamp('02-FEB-12 02.51.42 PM','DD-MON-RR HH.MI.SS AM'),14,0);
Insert into DATATABLE values ('TOOL1',21,'LOT1','STEP1',to_timestamp('02-FEB-12 02.48.01 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',21,'LOT1','STEP2',to_timestamp('02-FEB-12 02.49.16 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',21,'LOT1','STEP3',to_timestamp('02-FEB-12 02.51.02 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',21,'LOT1','STEP4',to_timestamp('02-FEB-12 02.52.16 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',21,'LOT1','STEP5',to_timestamp('02-FEB-12 02.55.04 PM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',22,'LOT1','STEP1',to_timestamp('02-FEB-12 02.49.48 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',22,'LOT1','STEP2',to_timestamp('02-FEB-12 02.51.02 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',22,'LOT1','STEP3',to_timestamp('02-FEB-12 02.52.47 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',22,'LOT1','STEP4',to_timestamp('02-FEB-12 02.55.39 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',22,'LOT1','STEP5',to_timestamp('02-FEB-12 02.56.45 PM','DD-MON-RR HH.MI.SS AM'),15,0);
Insert into DATATABLE values ('TOOL1',23,'LOT1','STEP1',to_timestamp('02-FEB-12 02.51.33 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',23,'LOT1','STEP2',to_timestamp('02-FEB-12 02.52.48 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',23,'LOT1','STEP3',to_timestamp('02-FEB-12 02.56.11 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',23,'LOT1','STEP4',to_timestamp('02-FEB-12 02.57.23 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',23,'LOT1','STEP5',to_timestamp('02-FEB-12 02.58.29 PM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',24,'LOT1','STEP1',to_timestamp('02-FEB-12 02.53.18 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',24,'LOT1','STEP2',to_timestamp('02-FEB-12 02.56.00 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',24,'LOT1','STEP3',to_timestamp('02-FEB-12 02.57.53 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',24,'LOT1','STEP4',to_timestamp('02-FEB-12 02.59.05 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',24,'LOT1','STEP5',to_timestamp('02-FEB-12 03.00.12 PM','DD-MON-RR HH.MI.SS AM'),17,0);
Insert into DATATABLE values ('TOOL1',25,'LOT1','STEP1',to_timestamp('02-FEB-12 02.56.29 PM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',25,'LOT1','STEP2',to_timestamp('02-FEB-12 02.57.44 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',25,'LOT1','STEP3',to_timestamp('02-FEB-12 02.59.35 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',25,'LOT1','STEP4',to_timestamp('02-FEB-12 03.00.46 PM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',25,'LOT1','STEP5',to_timestamp('02-FEB-12 03.07.19 PM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',-1,'LOT2','STEP1',to_timestamp('24-FEB-12 03.19.26 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',1,'LOT2','STEP1',to_timestamp('24-FEB-12 03.00.47 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',1,'LOT2','STEP2',to_timestamp('24-FEB-12 03.02.56 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',1,'LOT2','STEP3',to_timestamp('24-FEB-12 03.03.56 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',2,'LOT2','STEP1',to_timestamp('24-FEB-12 03.02.22 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',2,'LOT2','STEP2',to_timestamp('24-FEB-12 03.05.06 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',2,'LOT2','STEP3',to_timestamp('24-FEB-12 03.06.06 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',3,'LOT2','STEP1',to_timestamp('24-FEB-12 03.03.56 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',3,'LOT2','STEP2',to_timestamp('24-FEB-12 03.07.15 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',3,'LOT2','STEP3',to_timestamp('24-FEB-12 03.13.53 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',4,'LOT2','STEP1',to_timestamp('24-FEB-12 03.05.54 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',4,'LOT2','STEP2',to_timestamp('24-FEB-12 03.15.03 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',4,'LOT2','STEP3',to_timestamp('24-FEB-12 03.16.04 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',5,'LOT2','STEP1',to_timestamp('24-FEB-12 03.05.58 AM','DD-MON-RR HH.MI.SS AM'),0,0);
Insert into DATATABLE values ('TOOL1',5,'LOT2','STEP2',to_timestamp('24-FEB-12 03.25.35 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',5,'LOT2','STEP3',to_timestamp('24-FEB-12 03.29.56 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',5,'LOT2','STEP4',to_timestamp('24-FEB-12 03.30.57 AM','DD-MON-RR HH.MI.SS AM'),16,0);
Insert into DATATABLE values ('TOOL1',6,'LOT2','STEP1',to_timestamp('24-FEB-12 03.14.18 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',6,'LOT2','STEP2',to_timestamp('24-FEB-12 03.17.13 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',6,'LOT2','STEP3',to_timestamp('24-FEB-12 03.19.55 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',7,'LOT2','STEP1',to_timestamp('24-FEB-12 03.15.51 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',7,'LOT2','STEP2',to_timestamp('24-FEB-12 03.21.18 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',7,'LOT2','STEP3',to_timestamp('24-FEB-12 03.22.19 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',8,'LOT2','STEP1',to_timestamp('24-FEB-12 03.17.50 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',8,'LOT2','STEP2',to_timestamp('24-FEB-12 03.23.28 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',8,'LOT2','STEP3',to_timestamp('24-FEB-12 03.24.29 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',9,'LOT2','STEP1',to_timestamp('24-FEB-12 03.21.42 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',9,'LOT2','STEP2',to_timestamp('24-FEB-12 03.25.37 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',9,'LOT2','STEP3',to_timestamp('24-FEB-12 03.26.38 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',10,'LOT2','STEP1',to_timestamp('24-FEB-12 03.23.25 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',10,'LOT2','STEP2',to_timestamp('24-FEB-12 03.27.47 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',10,'LOT2','STEP3',to_timestamp('24-FEB-12 03.28.47 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',11,'LOT2','STEP1',to_timestamp('24-FEB-12 03.27.44 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',11,'LOT2','STEP2',to_timestamp('24-FEB-12 03.32.06 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',11,'LOT2','STEP3',to_timestamp('24-FEB-12 03.33.07 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',12,'LOT2','STEP1',to_timestamp('24-FEB-12 03.29.54 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',12,'LOT2','STEP2',to_timestamp('24-FEB-12 03.34.16 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',12,'LOT2','STEP3',to_timestamp('24-FEB-12 03.35.17 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',13,'LOT2','STEP1',to_timestamp('24-FEB-12 03.32.04 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',13,'LOT2','STEP2',to_timestamp('24-FEB-12 03.36.26 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',13,'LOT2','STEP3',to_timestamp('24-FEB-12 03.37.27 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',14,'LOT2','STEP1',to_timestamp('24-FEB-12 03.34.14 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',14,'LOT2','STEP2',to_timestamp('24-FEB-12 03.38.36 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',14,'LOT2','STEP3',to_timestamp('24-FEB-12 03.39.37 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',15,'LOT2','STEP1',to_timestamp('24-FEB-12 03.36.24 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',15,'LOT2','STEP2',to_timestamp('24-FEB-12 03.40.46 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',15,'LOT2','STEP3',to_timestamp('24-FEB-12 03.41.46 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',16,'LOT2','STEP1',to_timestamp('24-FEB-12 03.38.34 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',16,'LOT2','STEP2',to_timestamp('24-FEB-12 03.42.55 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',16,'LOT2','STEP3',to_timestamp('24-FEB-12 03.43.56 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',17,'LOT2','STEP1',to_timestamp('24-FEB-12 03.40.43 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',17,'LOT2','STEP2',to_timestamp('24-FEB-12 03.45.05 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',17,'LOT2','STEP3',to_timestamp('24-FEB-12 03.46.06 AM','DD-MON-RR HH.MI.SS AM'),17,0);
Insert into DATATABLE values ('TOOL1',18,'LOT2','STEP1',to_timestamp('24-FEB-12 03.42.53 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',18,'LOT2','STEP2',to_timestamp('24-FEB-12 03.47.15 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',18,'LOT2','STEP3',to_timestamp('24-FEB-12 03.48.16 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',19,'LOT2','STEP1',to_timestamp('24-FEB-12 03.45.03 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',19,'LOT2','STEP2',to_timestamp('24-FEB-12 03.49.25 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',19,'LOT2','STEP3',to_timestamp('24-FEB-12 03.50.26 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',20,'LOT2','STEP1',to_timestamp('24-FEB-12 03.47.13 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',20,'LOT2','STEP2',to_timestamp('24-FEB-12 03.51.34 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',20,'LOT2','STEP3',to_timestamp('24-FEB-12 03.52.35 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',21,'LOT2','STEP1',to_timestamp('24-FEB-12 03.49.22 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',21,'LOT2','STEP2',to_timestamp('24-FEB-12 03.53.44 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',21,'LOT2','STEP3',to_timestamp('24-FEB-12 03.54.45 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',22,'LOT2','STEP1',to_timestamp('24-FEB-12 03.51.32 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',22,'LOT2','STEP2',to_timestamp('24-FEB-12 03.55.54 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',22,'LOT2','STEP3',to_timestamp('24-FEB-12 03.56.55 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',23,'LOT2','STEP1',to_timestamp('24-FEB-12 03.53.42 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',23,'LOT2','STEP2',to_timestamp('24-FEB-12 03.58.03 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',23,'LOT2','STEP3',to_timestamp('24-FEB-12 03.59.04 AM','DD-MON-RR HH.MI.SS AM'),19,0);
Insert into DATATABLE values ('TOOL1',24,'LOT2','STEP1',to_timestamp('24-FEB-12 03.55.51 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',24,'LOT2','STEP2',to_timestamp('24-FEB-12 04.00.14 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',24,'LOT2','STEP3',to_timestamp('24-FEB-12 04.01.15 AM','DD-MON-RR HH.MI.SS AM'),18,0);
Insert into DATATABLE values ('TOOL1',25,'LOT2','STEP1',to_timestamp('24-FEB-12 03.58.01 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',25,'LOT2','STEP2',to_timestamp('24-FEB-12 04.02.23 AM','DD-MON-RR HH.MI.SS AM'),1,0);
Insert into DATATABLE values ('TOOL1',25,'LOT2','STEP3',to_timestamp('24-FEB-12 04.03.24 AM','DD-MON-RR HH.MI.SS AM'),18,0);(code generated by sqldeveloper)
In the example:
LOT1 has two slot, with only 1 step instead of 5 --> these slots should not be counted --> result 23
LOT2 has one slot, with 4 instead of 3 --> this slot is ok and should be counted --> result 25
as previously mentioned, i want to count all slots, which got at least the median amount of steps [edit: slot -1 should also not be counted]
LOT1:
SELECT
sum(CASE WHEN SLOT != -1 THEN parameter1 END) parameter1,
min(CASE WHEN SLOT != -1 THEN EndTime END) first_time,
max(CASE WHEN SLOT != -1 THEN EndTime END) last_time,
sum(CASE WHEN SLOT != -1 THEN parameter6 END) parameter6,
CASE WHEN count(DISTINCT CASE WHEN SLOT != -1 THEN SLOT END) > 0 AND ROUND(count(DISTINCT CASE WHEN SLOT != -1 THEN SLOT||STEP END)/count(DISTINCT CASE WHEN SLOT != -1 THEN SLOT END)) > 0 THEN FLOOR(count(DISTINCT CASE WHEN SLOT != -1 THEN SLOT||STEP END)/ROUND(count(DISTINCT CASE WHEN SLOT != -1 THEN SLOT||STEP END)/count(DISTINCT CASE WHEN SLOT != -1 THEN SLOT END))) ELSE NULL END num_slots,
sum(CASE WHEN SLOT = -1 THEN parameter1 END) minusone_parameter1,
min(CASE WHEN SLOT = -1 THEN EndTime END) minusone_first_time,
max(CASE WHEN SLOT = -1 THEN EndTime END) minusone_last_time,
sum(CASE WHEN SLOT = -1 THEN parameter6 END) minusone_parameter6,
count(CASE WHEN SLOT = -1 THEN 1 END) num_minusone
FROM
datatable
WHERE
tool = 'TOOL1'
AND lotid = 'LOT1';
PARAMETER1 FIRST_TIME LAST_TIME PARAMETER6 *NUM_SLOTS* MINUSONE_PARAMETER1 MINUSONE_FIRST_TIME MINUSONE_LAST_TIME MINUSONE_PARAMETER6 NUM_MINUSONE
423 02.02.12 13:51:28 02.02.12 15:13:41 0 *23* 46 02.02.12 14:20:35 02.02.12 15:18:47 0 5 this is the desired result
same query with Lot2:
PARAMETER1 FIRST_TIME LAST_TIME PARAMETER6 *NUM_SLOTS* MINUSONE_PARAMETER1 MINUSONE_FIRST_TIME MINUSONE_LAST_TIME MINUSONE_PARAMETER6 NUM_MINUSONE
506 24.02.12 03:00:47 24.02.12 04:03:24 0 *25* 1 24.02.12 03:19:26 24.02.12 03:19:26 0 1 so right now i get the desired results with this ugly query... but with combinations of several different conditions - e.g. several slots with more steps and a few with less... - it may not work.
Edited by: Paneologist on Feb 24, 2012 7:42 AM -
Hi,
Please help me in the following query.
SELECT
a.bcast_id ,
a.bcast_file_nm ,
a.clickthru_url_cd ,
a.list_id ,
a.prs_id ,
a.resp_cd ,
a.run_seq ,
COUNT(a.resp_cd) ,
c.src_grp_cd ,
b.site_cd
FROM
gca_cbx_response_test a ,
gca_program_run_hist b ,
campaign_master c
WHERE
a.list_id=b.list_id
AND
a.run_seq=b.campaign_run_seq
AND
b.campaign_cd=c.campaign_cd
GROUP BY
a.bcast_id ,
a.bcast_file_nm ,
a.clickthru_url_cd ,
a.list_id ,
a.prs_id ,
a.resp_cd ,
a.run_seq ,
c.src_grp_cd ,
b.site_cd
HAVING
a.resp_ts
BETWEEN
to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS')
AND
to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS');
But the following group by query is throwing error that a.resp_ts is not a group by function.
But i don't want to add a.resp_ts in group by clause.
Please help me in this query.
Thanks,
DilipHow about:
SELECT a.bcast_id ,
a.bcast_file_nm ,
a.clickthru_url_cd ,
a.list_id ,
a.prs_id ,
a.resp_cd ,
a.run_seq ,
COUNT(a.resp_cd) ,
c.src_grp_cd ,
b.site_cd
FROM gca_cbx_response_test a ,
gca_program_run_hist b ,
campaign_master c
WHERE a.list_id=b.list_id
AND a.run_seq=b.campaign_run_seq
AND b.campaign_cd=c.campaign_cd
AND a.resp_ts BETWEEN to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS')
AND to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS');
GROUP BY a.bcast_id ,
a.bcast_file_nm ,
a.clickthru_url_cd ,
a.list_id ,
a.prs_id ,
a.resp_cd ,
a.run_seq ,
c.src_grp_cd ,
b.site_cd; -
How I check in group by query the group change
How I check in group by query the group change
Hi master
Sir I have master detail table
This is my query
select rownum,chartofacc.accid,title,nvl(drbal,0),nvl(crbal,0),
(select case when nvl(sum(debit),0)-nvl(sum(credit),0)>0 then
nvl(sum(debit),0)-nvl(sum(credit),0)
else
0
end mfadrttt
from voudetail where voudetail.accid=chartofacc.accid) as mfadr,
(select case when nvl(sum(credit),0)-nvl(sum(debit),0)>0 then
nvl(sum(credit),0)-nvl(sum(debit),0)
else
0
end mfacrttt
from voudetail where voudetail.accid=chartofacc.accid) as mfacr
,nvl(debit,0),nvl(credit,0),voumaster.entdate,voumaster.vno from chartofacc ,accbal,voudetail,voumaster where chartofacc.accid=accbal.accid(+) and chartofacc.accid=voudetail.accid(+) and voumaster.vno=voudetail.vno order by chartofacc.accid,voumaster.entdate,voudetail.VNO;
Sir I need add opbal from master section to debit in detail section when new group start only after adding I use that column for accumulative total or running balance
If I get any method when group change system give me any key or indication then I use
Please give me idea in both field oracle sql and oracle report 6i
Thank
aamirHi,
Please send tables structures and sample data from that tables. And, of course what should be the output. :) Just sending your query won't help us to find a solution.
Peter D. -
Alert is not working with a group by query
Hello,
I have a group by query. Using that query have created an alarm, but the alarm is not working, though if I execute manually the query, the query is returning records.
I have update the alarm and set another query which has no group by clause. This way the alarm works.
So, my question is the following, do you know if this behaviour is because some SAPs limitation, that is, that alarms with queries containing the group by clause cant work?
Thank you very much for your help!Hi Adrian,
Actually, the query I have post was a simplification of the real one.
The real one is the following, and there I think it is not possible to rewrite it without the group by>
SELECT T1.ItemCode , SUM(T1.OpenQty) , SUM(T2.OnHand) , SUM(T1.OpenQty)- SUM(T2.OnHand)
FROM RDR1 T1 inner JOIN OITW T2 on T1.ItemCode = T2.ItemCode
WHERE T2.WhsCode = '01'
GROUP BY T1.ItemCode
HAVING SUM(T1.OpenQty)- SUM(T2.OnHand) > 0
Anyway, thank you very much for your idea. -
Hi,
I have one group by query which has joins of 2 tables and also the joining columns has indexes.
But the query takes quite time to get the output.
Is there any way to get the output of group by clause faster.
The query is given below
SELECT a.description,a.type_of_item,a.item_type_id ,b.city_code,COUNT(1)
FROM PPBS_ITEM_MASTER a,PPBS_INV_SIM_SERIAL b
WHERE b.item_type_id = a.item_type_id
AND b.status='AA'
GROUP BY a.description,a.type_of_item,a.item_type_id ,b.city_code
KumarDid you do some explain plan and possibly tkprof on the query to see what it is doing?
what is the explan plan?
tkprof output?
what optimizer is in use?
are stats gathered? if yes, how?
how many rows are in base tables?
how many rows do you get from the query?
how many rows are matching the condition b.status = 'AA' ?
you can replace that COUNT(1) with a COUNT(*) without any loss of performance. -
What's coming next? Apple took back our iDisk, now iCloud storage! We'd better raise a query!
What's coming next? Apple took back our iDisk, now iCloud storage! We'd better raise a query!
-
Hi All,
I am using Oracle 11 g.
I have a query which is giving output as
SELECT o.campgn_no , m.lang , COUNT(1)
FROM tg_main m, sp_offer o
WHERE m.offer_id = o.offer_id AND o.campgn_no IN (SELECT campgn_no FROM sp_campgn_cntrl WHERE product_code = 'ONB')
GROUP BY o.campgn_no, m.lang;
Campgn Lang Count
CNB26 F 4
ONB26 E 1065
CNB26 E 316
ONB26 F 96
But i need output as
Campgn E F
ONB26 1065 96
CNB26 316 4
Let me know how to do this.
Thanks in Advance.
Thanks,
lonyMaybe (seems I'd better leave the Forum for a while)
select campgn_no,
max(e) e,
max(f) f
from (SELECT o.campgn_no,
sum(case when m.lang = 'E' then 1 end) e,
sum(case when m.lang = 'F' then 1 end) f
FROM tg_main m,
sp_offer o
WHERE m.offer_id = o.offer_id
AND o.campgn_no IN (SELECT campgn_no
FROM sp_campgn_cntrl
WHERE product_code = 'ONB'
GROUP BY o.campgn_no,m.lang
GROUP BY campgn_noRegards
Etbin -
Complex Group by Query with Example
Hi all,
I am re-posting with a better example. Pls someone help me to solve
this below query.
Below table have 15 rows
FACILITY_TYPE CONTACT_TYPE1 POI
Auto Service and Maintainance Email 53
Auto Service and Maintainance Email 53
Auto Service and Maintainance Email 44
Auto Service and Maintainance Mobile 44
Auto Service and Maintainance Mobile 53
Auto Service and Maintainance Mobile 53
Auto Service and Maintainance Phone 53
Auto Service and Maintainance Phone 44
Auto Service and Maintainance URL 44
Clothing Store URL 51
Clothing Store URL 51
Golf Course Phone 40
Golf Course Phone 40
Golf Course Phone 40
Golf Course URL 40
15 rows selectedThe output should be like below
FACILITY_TYPE CONTACT_TYPE COUNT_GP_POI COUNT_PER_POI
Auto Service and Maintainance Phone 2 1
Auto Service and Maintainance URL 1 1
Auto Service and Maintainance Email 1 1
Auto Service and Maintainance Email 1 2
Auto Service and Maintainance Mobile 1 1
Auto Service and Maintainance Mobile 1 2
Total Auto Service n Maint POI 2
Clothing Store URL 1 2
Total Clothing Store POI 1
Golf Course Phone 1 3
Golf Course URL 1 1
Total Golf Course POI 1
12 rows selectedExplanation is as
COUNT_GP_POI = COUNT of (group by FACILITY_TYPE + POI)
COUNT_PER_POI = COUNT of (group by FACILITY_TYPE + CONTACT_TYPE)
Thanks in Advance
SaazPosting the same thing twice is not a good idea. Please stay in this thread: complex group by query
-
FRM - 40212 / FRM - 40222 error on a radio group during query
Hi all,
This is my first post so please bear with me if I haven't provided sufficient information or am unclear at all.
I'm using Forms Builder (Web) on a 10g Database. I have a number of database and non-database items as part of a data block.
My problem is that, when I enter a value in any field and click the query button, I get a FRM-40212 Invalid value for field error on my radio group (disabled, non-database item that is programatically populated in the post-query and list-changed triggers only). When I click ok, I get a FRM-40222 Disabled Item Failed Validation error on the same radio group.
This does not happen if I click the 'Enter Query' button before entering values into fields, however I don't want my users to encounter this error if they try to query without clicking on 'Enter Query' first.
I'd like to know why exactly does this error happen - what does it mean?
I've read in other forums that setting the item's Required property to false solves this issue. But how can I do this with a radio group? And if it's not possible, does anyone have any suggestions for other workarounds?
Thanks in advance,
AbigailHi,
You can avoid this by setting 'Mapping of other values' to the one fo the radio buttons value.Like if you have to radio button radio1 and radio2 associated with radio group R1 ,then set any radio buttons initial value to this 'Mapping of other values' property of radio button R1.You won't see this error.
This error occurs because your loading a screen without assigning a value to the radio button.
If this helps mark question as answered or helpfull.
Thanks,
Pavan. -
Data Source Groups in Query no reflecting changes in Admin
Version of US used: 1.0.3
I removed some data source groups and add new ones in the Admin Application. But the default Query Application does not reflect these changes. That is, when I go to Advanced Search in the Query Application, the list of Data Source Groups displayed (i.e. the checkboxes) does not include the new ones I added and it still shows the ones I already deleted.
My question: how to update the data groups in the Advanced Query Screen? Do I have to execute all the schedules again before the updates are reflected?
Thanks!Hi,
The caching Cindy was referring to is NOT in the browser. It is in the JSP middle-tier.
The JSP cache the data groups information to avoid fetching from the database everytime,
since data groups change infrequently.
In addition, in 1.0.3 version, this cache does not have any invalidation logic. So once the
search application has started (after first use), the data groups will never change unless
the application server (apache+jserv) is restarted.
Please restart the application server to see your changes take place. If you wish, you can
change the caching logic in the jsp itself. You may implement some trivial invalidation based
on time, or disable it if your server can handle the load.
Note: Ultra Search samples in 9.0.2 or later releases have invalidation of cache every 15 mins
or so.
David -
Indexes for group by query on table with 5million records
Hi,
Here is my query which is taking ages to run :
SELECT approved.budgetReferenceno
, approved.projects
, approved.allocations
, rptgen4
, financialyear
, cashclass
, SUM(nvl(approved.FullYear,0)) as FullYear
FROM approved
JOIN rpt_entity ON rpt_entity.level0 = approved.entity
JOIN cashclasses ON accountcode = approved.account
where budgetreferenceno = refno
and
entity in (
(select Level0 from rpt_entity where
( entityparent in (select * from table(split(userid))) or rptgen5 in (select * from table(split(userid))) ) )
and
ccs in (select level0 from rpt_ccs where rptgen4 in (select * from table(split(userid)))) or
ccs in (select level0 from rpt_ccs where rptgen5 in (select * from table(split(userid)))) or
ccs in (select level0 from rpt_ccs where rptgen6 in (select * from table(split(userid)))) or
ccs in (select level0 from rpt_ccs where rptgen7 in (select * from table(split(userid))) ) or
ccs in (select distinct(substr(column_value,2,length(column_value)-2)) from table(split_comma(userid)) )
GROUP BY approved.budgetReferenceno
, approved.projects
, approved.allocations
, rptgen4
, financialyear
, cashclass
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 4074481161
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 31234 | 3660K| | 86141 (1)| 00:17:14 |
| 1 | HASH GROUP BY | | 31234 | 3660K| 17M| 86141 (1)| 00:17:14 |
|* 2 | FILTER | | | | | | |
|* 3 | HASH JOIN | | 138K| 15M| | 82427 (1)| 00:16:30 |
| 4 | TABLE ACCESS FULL | CASHCLASSES | 2875 | 48875 | | 5 (0)| 00:00:01 |
|* 5 | HASH JOIN | | 138K| 13M| | 82420 (1)| 00:16:30 |
PLAN_TABLE_OUTPUT
| 6 | TABLE ACCESS FULL | RPT_entity | 725 | 10875 | | 11 (0)| 00:00:01 |
|* 7 | HASH JOIN RIGHT SEMI | | 138K| 11M| | 82408 (1)| 00:16:29 |
| 8 | VIEW | VW_NSO_1 | 71 | 568 | | 11 (0)| 00:00:01 |
|* 9 | FILTER | | | | | | |
| 10 | TABLE ACCESS FULL | RPT_entity | 725 | 17400 | | 11 (0)| 00:00:01 |
|* 11 | COLLECTION ITERATOR PICKLER FETCH| SPLIT | | | | | |
|* 12 | COLLECTION ITERATOR PICKLER FETCH| SPLIT | | | | | |
|* 13 | TABLE ACCESS FULL | approved | 1170K| 89M| | 82389 (1)| 00:16:29 |
| 14 | NESTED LOOPS | | 1 | 18 | | 46 (0)| 00:00:01 |
| 15 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
|* 16 | INDEX RANGE SCAN | CC_INDEX1 | 1 | 16 | | 1 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
| 17 | NESTED LOOPS | | 2 | 46 | | 51 (2)| 00:00:01 |
|* 18 | INDEX FAST FULL SCAN | CC_INDEX2 | 1 | 21 | | 46 (3)| 00:00:01 |
|* 19 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
| 20 | NESTED LOOPS | | 1 | 24 | | 52 (0)| 00:00:01 |
| 21 | TABLE ACCESS BY INDEX ROWID | RPT_ccs | 1 | 22 | | 46 (0)| 00:00:01 |
|* 22 | INDEX SKIP SCAN | CC_INDEX1 | 1 | | | 45 (0)| 00:00:01 |
|* 23 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
| 24 | NESTED LOOPS | | 2 | 50 | | 60 (0)| 00:00:01 |
| 25 | TABLE ACCESS BY INDEX ROWID | RPT_ccs | 1 | 23 | | 46 (0)| 00:00:01 |
|* 26 | INDEX SKIP SCAN | CC_INDEX1 | 1 | | | 45 (0)| 00:00:01 |
|* 27 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
PLAN_TABLE_OUTPUT
|* 28 | COLLECTION ITERATOR PICKLER FETCH | SPLIT_COMMA | | | | | |
Predicate Information (identified by operation id):
2 - filter( EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
"LEVEL0"=:B1 AND "RPTGEN4"=VALUE(KOKBF$)) OR EXISTS (SELECT 0 FROM "RPT_ccs"
"RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN5"=VALUE(KOKBF$) AND "LEVEL0"=:B2) OR EXISTS (SELECT 0
FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN6"=VALUE(KOKBF$) AND "LEVEL0"=:B3)
OR EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
PLAN_TABLE_OUTPUT
"RPTGEN7"=VALUE(KOKBF$) AND "LEVEL0"=:B4) OR EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE
SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B5))
3 - access("ACCOUNTCODE"="approved"."ACCOUNT")
5 - access("RPT_entity"."LEVEL0"="approved"."entity")
7 - access("approved"."entity"="LEVEL0")
9 - filter( EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B1) OR EXISTS (SELECT 0 FROM
TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B2))
11 - filter(VALUE(KOKBF$)=:B1)
12 - filter(VALUE(KOKBF$)=:B1)
13 - filter("approved"."BUDGETREFERENCENO"='BASE')
16 - access("RPTGEN4"=VALUE(KOKBF$) AND "LEVEL0"=:B1)
PLAN_TABLE_OUTPUT
18 - filter("LEVEL0"=:B1)
19 - filter("RPTGEN5"=VALUE(KOKBF$))
22 - access("LEVEL0"=:B1)
filter("LEVEL0"=:B1)
23 - filter("RPTGEN6"=VALUE(KOKBF$))
26 - access("LEVEL0"=:B1)
filter("LEVEL0"=:B1)
27 - filter("RPTGEN7"=VALUE(KOKBF$))
28 - filter(SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B1)
64 rows selected.
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for IBM/AIX RISC System/6000: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionThe table has 28 columns none indexed the columns mentioned here have non unique values.
The table approved has more than 10million records and the query is taking a huge time.
The query first tries to restrict the search to only valid entities and cc (already indexed and working fine).
The cardinality of allocations, projects is around 1000, entity is 3000, and cc is around 50,000, reference number = 2000, financialyear = 4
Please suggest which index would be best to use on these columns given that there will no updations but frequent insertions.
If nothing else works than I will need to change it to pre aggregated data for overnight run .
Thanks,
Neetesh
Edited by: user13312817 on Nov 16, 2011 11:05 AM
Edited by: user13312817 on Nov 16, 2011 11:36 AM
Edited by: user13312817 on Nov 16, 2011 11:38 AM
Edited by: user13312817 on Nov 16, 2011 12:02 PMHello Adam,
Tried this but still not much of a difference.
create index test_index on approved (budgetreferenceno,projects,allocations,financialyear,entity,ccs,FullYear) compress 6;
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 2463060356
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 25030 | 4644K| | 70852 (1)| 00:14:11 |
| 1 | TABLE ACCESS BY INDEX ROWID | FEGEN4 | 1 | 13 | | 2 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | INDEX1 | 1 | | | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID | CASHCLASSES | 1 | 17 | | 2 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | CASHCLASSES_PK | 1 | | | 1 (0)| 00:00:01 |
| 5 | HASH GROUP BY | | 25030 | 4644K| 21M| 70852 (1)| 00:14:11 |
PLAN_TABLE_OUTPUT
| 6 | VIEW | | 109K| 19M| | 68578 (1)| 00:13:43 |
|* 7 | FILTER | | | | | | |
|* 8 | HASH JOIN RIGHT SEMI | | 484K| 99M| | 68578 (1)| 00:13:43 |
| 9 | VIEW | VW_NSO_1 | 71 | 7242 | | 11 (0)| 00:00:01 |
|* 10 | FILTER | | | | | | |
| 11 | TABLE ACCESS FULL | RPT_entity | 725 | 17400 | | 11 (0)| 00:00:01 |
|* 12 | COLLECTION ITERATOR PICKLER FETCH| SPLIT | | | | | |
|* 13 | COLLECTION ITERATOR PICKLER FETCH| SPLIT | | | | | |
|* 14 | TABLE ACCESS FULL | approved | 982K| 106M| | 68560 (1)| 00:13:43 |
| 15 | NESTED LOOPS | | 1 | 18 | | 46 (0)| 00:00:01 |
| 16 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
PLAN_TABLE_OUTPUT
|* 17 | INDEX RANGE SCAN | CC_INDEX1 | 1 | 16 | | 1 (0)| 00:00:01 |
| 18 | NESTED LOOPS | | 2 | 46 | | 51 (2)| 00:00:01 |
|* 19 | INDEX FAST FULL SCAN | CC_INDEX2 | 1 | 21 | | 46 (3)| 00:00:01 |
|* 20 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
| 21 | NESTED LOOPS | | 1 | 24 | | 52 (0)| 00:00:01 |
| 22 | TABLE ACCESS BY INDEX ROWID | RPT_ccs | 1 | 22 | | 46 (0)| 00:00:01 |
|* 23 | INDEX SKIP SCAN | CC_INDEX1 | 1 | | | 45 (0)| 00:00:01 |
|* 24 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
| 25 | NESTED LOOPS | | 2 | 50 | | 60 (0)| 00:00:01 |
| 26 | TABLE ACCESS BY INDEX ROWID | RPT_ccs | 1 | 23 | | 46 (0)| 00:00:01 |
|* 27 | INDEX SKIP SCAN | CC_INDEX1 | 1 | | | 45 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
|* 28 | COLLECTION ITERATOR PICKLER FETCH | SPLIT | | | | | |
|* 29 | COLLECTION ITERATOR PICKLER FETCH | SPLIT_COMMA | | | | | |
Predicate Information (identified by operation id):
2 - access("LEVEL0"=:B1)
4 - access("ACCOUNTCODE"=:B1)
7 - filter( EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
"LEVEL0"=:B1 AND "RPTGEN4"=VALUE(KOKBF$)) OR EXISTS (SELECT 0 FROM "RPT_ccs"
PLAN_TABLE_OUTPUT
"RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN5"=VALUE(KOKBF$) AND "LEVEL0"=:B2) OR EXISTS (SELECT 0
FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE "RPTGEN6"=VALUE(KOKBF$) AND "LEVEL0"=:B3)
OR EXISTS (SELECT 0 FROM "RPT_ccs" "RPT_ccs",TABLE() "KOKBF$" WHERE
"RPTGEN7"=VALUE(KOKBF$) AND "LEVEL0"=:B4) OR EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE
SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B5))
8 - access("entity"="LEVEL0")
10 - filter( EXISTS (SELECT 0 FROM TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B1) OR EXISTS (SELECT 0 FROM
TABLE() "KOKBF$" WHERE VALUE(KOKBF$)=:B2))
12 - filter(VALUE(KOKBF$)=:B1)
13 - filter(VALUE(KOKBF$)=:B1)
14 - filter("BUDGETREFERENCENO"='BASE')
PLAN_TABLE_OUTPUT
17 - access("RPTGEN4"=VALUE(KOKBF$) AND "LEVEL0"=:B1)
19 - filter("LEVEL0"=:B1)
20 - filter("RPTGEN5"=VALUE(KOKBF$))
23 - access("LEVEL0"=:B1)
filter("LEVEL0"=:B1)
24 - filter("RPTGEN6"=VALUE(KOKBF$))
27 - access("LEVEL0"=:B1)
filter("LEVEL0"=:B1)
28 - filter("RPTGEN7"=VALUE(KOKBF$))
29 - filter(SUBSTR(VALUE(KOKBF$),2,LENGTH(VALUE(KOKBF$))-2)=:B1)
PLAN_TABLE_OUTPUT
Note
- dynamic sampling used for this statement
69 rows selected.Thanks,
Neetesh
Edited by: user13312817 on Nov 17, 2011 7:04 AM -
Group by query not working after upgrade to 11g
Hi again,
This once is weired.
I had a report base on a seeded view with following query in Install Base.
SELECT
DESCRIPTION item_description,
OWNER_PARTY_ID,
sum(quantity)
FROM CSI_INSTANCE_SEARCH_V
WHERE 1=1
AND serial_number is not null
AND OWNER_PARTY_SOURCE_TABLE = 'HZ_PARTIES'
AND NOT (INSTANCE_STATUS_ID = 1)
AND NVL (ACTIVE_END_DATE, SYSDATE + 1) > SYSDATE
group by OWNER_PARTY_ID
This report was working fine in 10g and stopped pulling records after upgrade.
We are on 11.5.10.2 and 11g.
Does the upgrade changes EBZ views?
I had to rewrite it using base tables and it worked again with the group by clause.
I have verified there are no invalid objects.Hussein,
This turned out to be a bug in 11.2.0.1
As per Oracle SR
Note.8945586.8 Ext/Pub Bug 8945586 - Wrong results using GROUP BY placement:
Description
Wrong results can occur when using GROUP BY placement where the aggregate column gets pruned from select list.
Rediscovery Notes:
Required aggregate columns are missing in the plan in the projection list of operations.
Workaround
set "_optimizer_group_by_placement"=FALSE -
How to add a dynamic where clause for a sql based VO with group by query?
Hi,
Here is my case, I have a sql query based VO with the query like "select status, count(*) StatusCount from my_table group by status". Now I used the following java code trying to dynamically add the where clause to my VO to filter the rows based the type attribute in my DB table.
vo.setWhereClause("type='MyType1' ");
vo.executeQuery();
Then I got the sql syntax error. Looks like the ADF has added the where clause to the end of my sql so my sql becomes "select status, count(*) StatusCount from my_table group by status where type='MyType1' ". But what I expected was the correct syntax "select status, count(*) StatusCount from my_table where type='MyType1' group by status".
Does anyone know if this is an ADF bug? Or is there any other way to achieve my goal?
Thanks,
Chunyang
Edited by: Chunyang on Dec 13, 2012 9:09 PMHi,
When you use setWhereClause on the VO, it is applied on top of the VO query. I.e, assume your VO has the following query.
select empno, ename from empNow, if you apply the where clause programatically, only the two attributes that you are using in the select statement could be used. I.e
select * from (select empno, ename from emp) where ename='KING' - VALID
select * from (select empno, ename from emp) where deptno=10 - INVALID (because the inner query - the one you've defined as query for your vo does not have deptno attribute selected)If you would need to set a dynamic where clause, you need to make them available in your select statement / use bind variables.
-Arun -
How do I put a label in a null field in the result set of a group-by query
I run the query:
select section, count(*) from nparcel group by section
and get the result
section1 100
section2 200
section3 300
400
I would like to modify the query to put a label, perhaps 'BLANK', in the last returned row. Is that possible and if so how.
Thanks in advance for helping.Hi,
In SQL*Plus you have some additional options, that apply to all queries until you override them or end the session.
COLUMN section NULL BLANKapplies only to the column called "section".
SET NULL BLANKApplies to all columns.
Maybe you are looking for
-
I would like to delete a number of podcasts from my iPhone. They do not show up in iTunes and when I pull the arrow on the phone it does not give me a delete option. I am using a Windows 7 PC. Recently I had to restore my computer, when I first recon
-
How can I get java popups to open in tabs
I teach online, and our courseroom software has the unfortunate design of opening everything - student discussion posts, links to online articles, documents and forms, links to our university website or to external sites - in pop-ups via Javascript.
-
Jquery/JavaScript to get current browser's name and its version
Hi, I using sharepoint 2010, Is it possible using Jquery/JavaScript to get current browser's name and its version. when my sharepoint site home page opens i need to display a popup msg of current browser name and its version. can anyone help me on t
-
MacBook Pro 2.33 GHz 4 GB Mac OS X 10.6.8
-
Is there a way to dynamically load the src attribute of an iframe component with a jsf session value? I have a jsf page with an iframe which points to another web site. This website can be different dependand on a session variable. I am currently usi