"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 lot

ok, 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

Similar Messages

  • ORA-01427:single-row sub query returns more than one row (group by)

    Hello every one, I am very new to this field , and Right now I am working with this sql, where BEG_BAL_WKST,WKST_RECEIVED_NUM,WKST_PROCESSED_NUM,WKST_CANCELED_NUM are needs to be grouped by,but I am getting the "single-row sub query returns more than one row".
    This is the query I am using in my source qualifier:
    select
    SUM(tmp.WIP_TO_BILL_LOC_AMT) AS WIP_TO_BILL_LOC_AMT,
    sum(tmp.REALIZATION_LOC_AMT) AS REALIZATION_LOC_AMT,
    SUM(tmp.NEG_REAL_LOC_AMT) AS NEG_REAL_LOC_AMT,
    sum(tmp.POS_REAL_LOC_AMT) AS POS_REAL_LOC_AMT,
    sum(tmp.BILL_IN_ADVANCE_LOC_AMT) AS BILL_IN_ADVANCE_LOC_AMT,
    sum(tmp.CARRY_FORWARD_LOC_AMT) AS CARRY_FORWARD_LOC_AMT,
    sum(tmp.BILL_TO_CLIENT_LOC_AMT) AS BILL_TO_CLIENT_LOC_AMT,
    sum(tmp.REMAIN_WIP_TO_BILL_LOC_AMT) REMAIN_WIP_TO_BILL_LOC_AMT,
    sum(tmp.AR_INV_AMT) AS AR_INV_AMT,
    sum(tmp.AR_TAX_AMT) AS AR_TAX_AMT,
    tmp.BEG_BAL_WKST_NUM AS BEG_BAL_WKST_NUM,
    tmp.WKST_RECEIVED_NUM AS WKST_RECEIVED_NUM,
    tmp.WKST_PROCESSED_NUM AS WKST_PROCESSED_NUM,
    tmp.WKST_CANCELED_NUM AS WKST_CANCELED_NUM,
    tmp.DURATION AS DURATION,
    tmp.NUM_DAYS AS NUM_DAYS,
    tmp.NUM_HOURS AS NUM_HOURS,
    tmp.NUM_MINUTES AS NUM_MINUTES,
    tmp.NUM_SECONDS AS NUM_SECONDS,
    tmp.LEAD_PROJECT_OFFICE_CODE AS LEAD_PROJECT_OFFICE_CODE,
    tmp.LEAD_PROJECT_TEAM_CODE AS LEAD_PROJECT_TEAM_CODE,
    tmp.ORG_ID AS ORG_ID,
    tmp.RPT_DATE AS RPT_DATE,
    tmp.RPT_DATE_WID AS RPT_DATE_WID,
    tmp.LOCAL_CURR_CODE AS LOCAL_CURR_CODE,
    tmp.USD_EXCH_RATE AS USD_EXCH_RATE,
    tmp.EUR_EXCH_RATE AS EUR_EXCH_RATE,
    tmp.GBP_EXCH_RATE AS GBP_EXCH_RATE
    from(
    SELECT
    WIP_TO_BILL_LOC_AMT as WIP_TO_BILL_LOC_AMT ,
    REALIZATION_LOC_AMT AS REALIZATION_LOC_AMT,
    NEG_REAL_LOC_AMT AS NEG_REAL_LOC_AMT ,
    POS_REAL_LOC_AMT AS POS_REAL_LOC_AMT,
    BILL_IN_ADVANCE_LOC_AMT AS BILL_IN_ADVANCE_LOC_AMT ,
    CARRY_FORWARD_loc_AMT AS CARRY_FORWARD_LOC_AMT,
    bill_to_client_LOC_AMT AS BILL_TO_CLIENT_LOC_AMT ,
    REMAIN_WIP_TO_BILL_LOC_AMT AS REMAIN_WIP_TO_BILL_LOC_AMT,
    AR_inv_AMT AS AR_INV_AMT,
    ar_tax_amt AS AR_TAX_AMT,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE ((inv_status_type='FIN'AND inv_status_code NOT IN ('COMPLETE','PROCESSED'))
    OR (inv_status_type='WS' AND inv_status_code NOT IN ('PRC'))) --COMPLETED
    AND to_char((sysdate-5),'YYYYMMDD') between to_char(status_start_dt,'YYYYMMDD') and to_char(status_end_dt,'YYYYMMDD')group by rpad(integration_id,32)) AS BEG_BAL_WKST_NUM ,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE (inv_status_code='NEW')
    AND to_char((sysdate-4),'YYYYMMDD') between to_char(status_start_dt,'YYYYMMDD') and to_char(status_end_dt,'YYYYMMDD')group by rpad(integration_id,32))AS WKST_RECEIVED_NUM ,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE ((inv_status_type='FIN' and inv_status_code IN ('COMPLETE','PROCESSED'))
    OR (inv_status_type='WS' AND inv_status_code IN ('PRC'))) --COMPLETED
    AND to_char((sysdate-4),'YYYYMMDD') between to_char((status_start_dt),'YYYYMMDD') and to_char((status_end_dt),'YYYYMMDD')group by rpad(integration_id,32))AS WKST_PROCESSED_NUM ,
    (SELECT count(distinct(RPAD(INTEGRATION_ID,32)))
    FROM wc_twfs_olb_invoice_history_f
    WHERE (inv_status_type='FIN' AND inv_status_code='CANCELLED')
    AND to_char((sysdate-4),'YYYYMMDD') between to_char((status_start_dt),'YYYYMMDD') and to_char((status_end_dt),'YYYYMMDD')group by rpad(integration_id,32)) AS WKST_CANCELED_NUM,
    DURATION AS DURATION,
    NUM_DAYS AS NUM_DAYS,
    NUM_HOURS AS NUM_HOURS,
    NUM_MINUTES AS NUM_MINUTES,
    NUM_SECONDS AS NUM_SECONDS,
    lead_project_office_code AS LEAD_PROJECT_OFFICE_CODE,
    lead_project_team_code AS LEAD_PROJECT_TEAM_CODE,
    org_id AS ORG_ID,
    trunc(sysdate-1) AS RPT_DATE,
    to_char((sysdate-1),'YYYYMMDD') AS RPT_DATE_WID,
    --last_day(a.report_date) mth_end_dt,
    LOC_CURR_CODE AS LOCAL_CURR_CODE,
    usd_exch_rate AS USD_EXCH_RATE,
    eur_exch_rate AS EUR_EXCH_RATE,
    gbp_exch_rate AS GBP_EXCH_RATE
    FROM Wc_twfs_olb_invoice_history_f
    Where
    RPT_DT_MCAL_PERIOD_WID =(select max(RPT_DT_MCAL_PERIOD_WID)from Wc_twfs_olb_invoice_history_f))tmp
    group by BEG_BAL_WKST_NUM,WKST_RECEIVED_NUM,WKST_PROCESSED_NUM,WKST_CANCELED_NUM,DURATION,NUM_DAYS,NUM_HOURS,NUM_MINUTES,NUM_SECONDS,
    LEAD_PROJECT_OFFICE_CODE,LEAD_PROJECT_TEAM_CODE,ORG_ID,RPT_DATE,RPT_DATE_WID,
    LOCAL_CURR_CODE,USD_EXCH_RATE,EUR_EXCH_RATE,GBP_EXCH_RATE;
    Can you please suggest me what to do next, and what would be the solution to this.
    Thanks a lot in advance. please show me some direction.

    you may want to change it something like
    SELECT SUM(Wip_To_Bill_Loc_Amt) AS Wip_To_Bill_Loc_Amt,
           SUM(Realization_Loc_Amt) AS Realization_Loc_Amt,
           SUM(Neg_Real_Loc_Amt) AS Neg_Real_Loc_Amt,
           SUM(Pos_Real_Loc_Amt) AS Pos_Real_Loc_Amt,
           SUM(Bill_In_Advance_Loc_Amt) AS Bill_In_Advance_Loc_Amt,
           SUM(Carry_Forward_Loc_Amt) AS Carry_Forward_Loc_Amt,
           SUM(Bill_To_Client_Loc_Amt) AS Bill_To_Client_Loc_Amt,
           SUM(Remain_Wip_To_Bill_Loc_Amt) AS Remain_Wip_To_Bill_Loc_Amt,
           SUM(Ar_Inv_Amt) AS Ar_Inv_Amt,
           SUM(Ar_Tax_Amt) AS Ar_Tax_Amt,
           COUNT(DISTINCT CASE
                   WHEN ((Inv_Status_Type = 'FIN' AND
                        Inv_Status_Code NOT IN ('COMPLETE', 'PROCESSED')) OR
                        (Inv_Status_Type = 'WS' AND Inv_Status_Code NOT IN ('PRC'))) --COMPLETED
                        AND To_Char((SYSDATE - 5), 'YYYYMMDD') BETWEEN
                        To_Char(Status_Start_Dt, 'YYYYMMDD') AND
                        To_Char(Status_End_Dt, 'YYYYMMDD') THEN
                    Rpad(Integration_Id, 32)
                 END) AS Beg_Bal_Wkst_Num,
           /*(SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE ((Inv_Status_Type = 'FIN' AND
                   Inv_Status_Code NOT IN ('COMPLETE', 'PROCESSED')) OR
                   (Inv_Status_Type = 'WS' AND Inv_Status_Code NOT IN ('PRC'))) --COMPLETED
               AND To_Char((SYSDATE - 5), 'YYYYMMDD') BETWEEN
                   To_Char(Status_Start_Dt, 'YYYYMMDD') AND
                   To_Char(Status_End_Dt, 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Beg_Bal_Wkst_Num,
           (SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE (Inv_Status_Code = 'NEW')
               AND To_Char((SYSDATE - 4), 'YYYYMMDD') BETWEEN
                   To_Char(Status_Start_Dt, 'YYYYMMDD') AND
                   To_Char(Status_End_Dt, 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Wkst_Received_Num,
           (SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE ((Inv_Status_Type = 'FIN' AND
                   Inv_Status_Code IN ('COMPLETE', 'PROCESSED')) OR
                   (Inv_Status_Type = 'WS' AND Inv_Status_Code IN ('PRC'))) --COMPLETED
               AND To_Char((SYSDATE - 4), 'YYYYMMDD') BETWEEN
                   To_Char((Status_Start_Dt), 'YYYYMMDD') AND
                   To_Char((Status_End_Dt), 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Wkst_Processed_Num,
           (SELECT COUNT(DISTINCT(Rpad(Integration_Id, 32)))
              FROM Wc_Twfs_Olb_Invoice_History_f
             WHERE (Inv_Status_Type = 'FIN' AND Inv_Status_Code = 'CANCELLED')
               AND To_Char((SYSDATE - 4), 'YYYYMMDD') BETWEEN
                   To_Char((Status_Start_Dt), 'YYYYMMDD') AND
                   To_Char((Status_End_Dt), 'YYYYMMDD')
             GROUP BY Rpad(Integration_Id, 32)) AS Wkst_Canceled_Num,*/
           Duration AS Duration,
           Num_Days AS Num_Days,
           Num_Hours AS Num_Hours,
           Num_Minutes AS Num_Minutes,
           Num_Seconds AS Num_Seconds,
           Lead_Project_Office_Code AS Lead_Project_Office_Code,
           Lead_Project_Team_Code AS Lead_Project_Team_Code,
           Org_Id AS Org_Id,
           Trunc(SYSDATE - 1) AS Rpt_Date,
           To_Char((SYSDATE - 1), 'YYYYMMDD') AS Rpt_Date_Wid,
           --last_day(a.report_date) mth_end_dt,
           Loc_Curr_Code AS Local_Curr_Code,
           Usd_Exch_Rate AS Usd_Exch_Rate,
           Eur_Exch_Rate AS Eur_Exch_Rate,
           Gbp_Exch_Rate AS Gbp_Exch_Rate
      FROM Wc_Twfs_Olb_Invoice_History_f
    WHERE Rpt_Dt_Mcal_Period_Wid =
           (SELECT MAX(Rpt_Dt_Mcal_Period_Wid)
              FROM Wc_Twfs_Olb_Invoice_History_f)
    GROUP BY Beg_Bal_Wkst_Num,
              Wkst_Received_Num,
              Wkst_Processed_Num,
              Wkst_Canceled_Num,
              Duration,
              Num_Days,
              Num_Hours,
              Num_Minutes,
              Num_Seconds,
              Lead_Project_Office_Code,
              Lead_Project_Team_Code,
              Org_Id,
              Rpt_Date,
              Rpt_Date_Wid,
              Local_Curr_Code,
              Usd_Exch_Rate,
              Eur_Exch_Rate,
              Gbp_Exch_Rate;Edited by: 986006 on Mar 4, 2013 1:08 PM

  • Help in group by query

    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,
    Dilip

    How 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;

  • Distinct count inside a measure group with other measures

    Hello,
    I have 1 distinct count inside a measure group with other measures, sum, count etc. I know this is not recommended due to poor processing performance and query response time.
    Processing performance I can live with if it means not having another measure group, which increases processing time anyway.
    I have used the recommended approach before and it generated many questions about what this second measure group is for (visible via excel), even though I made the distinct count appear in the main measure group via a calculated measure.
    (it would be nice if you could hide measure groups)
    However my question is: is query response time only effected when the distinct count is used in the query? Or is query response time effected regardless if the distinct count is used or not??
    Below is an extract from the 2005 distinct count optimizer white paper. It’s not completely clear but I assume if effects queries regardless if distinct count is used or not?
    "By adding other measures to the measure group holding a distinct count measure, all of the other measures will be at the same granularity as the distinct count measure, resulting in inefficient data structures and suboptimal
    queries."

    You might also be interested in reading this blog post, which deals with a similar scenario, to get a feeling for some of the things that might be going on behind the scenes:
    http://cwebbbi.wordpress.com/2012/11/27/storage-engine-caching-measures-and-measure-groups/
    Chris
    Check out my MS BI blog I also do
    SSAS, PowerPivot, MDX and DAX consultancy
    and run public SQL Server and BI training courses in the UK

  • 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 PM

    Hi,
    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

  • Grouping Inner Query based on a column.Please help

    I have a strange query.
    I am using Subquery to display the count of rows from the inner query
    depending upon the value of 'Y' or 'N'
    Trade
    id_entity       id_inst_code_type   id_inst_code   dt_trade
    AGL            SE                  5660249        10-Feb-06
    AGL            SE                  5660249        13-Feb-06
    AGL            SE                  5660249        13-Feb'06
    Instrument_xref
    ID_inst      id_inst_xref_type     id_inst_xref  flg_active
    0029010             SE          5660249          Y
    0070789          SE          5660249          Y
    0071190          SE          5660249          Y
    0072385          SE          5660249          Y
    0073215          SE          5660249          Y
    0084797          SE          5660249          Y
    0091375          SE          5660249          Y
    0094690          SE          5660249          Y
    0104438          SE          5660249          Y
    My output:
    id_inst_code_type          id_inst_code   Earliest    Latest       Total    Active
    SE                         5660249       10 Feb 06   13 Feb 06    3        9
    2) If all the 'flg_active' column in Table Instrument_xref is set to 'N'
       the Active should be 0.
    3) Assume that the flg_active could be 3 Y's and 6 N's then what?
    id_inst_code_type          id_inst_code   Earliest    Latest       Total    Active
    SE                         5660249       10 Feb 06   13 Feb 06    3        0
    How do I check for the 'Y' or 'N' value in my code below ?
    Help appreciated as the the functionality changes by the hour...
    select    tie.id_entity             'Entity',
              tie.id_inst_code          'Inst Code',
              min(tie.dt_trade)         'Earliest',
              max(tie.dt_trade)         'Latest',
              count(*)                  'Total',
              dt.InnerTotal             'Active'   
    from     trade_input_event tie,
    (Select  insx.id_inst_xref_type,
                   insx.id_inst_xref,
                   insx.flg_active,
                   count(*) InnerTotal
      from instrument_xref insx
      where insx.id_inst_xref = '5660249'
      ---** Do I need to Check the flg_active here..
      ---** Do I need to use the Having clause here? ie having count(insx.id_inst_xref) = 'N'
       group by insx.id_inst_xref_type,insx.id_inst_xref,insx.flg_active) dt
      where tie.id_inst_code = dt.id_inst_xref
      and tie.id_entity = 'AGL'
      group by tie.id_entity, tie.id_inst_code_type,tie.id_inst_code

    As the flg_active is set to 'Y', I am trying to set it to 'N' in the query
    so that count of 0 is returned, but this displays nothing.
    Please help as to how to display a count(*) of 0 when the flg_active is 'N'??
    Select  insx.id_inst_xref_type,
                   insx.id_inst_xref,
                   insx.flg_active,
                   count(*) InnerTotal
      from instrument_xref insx
      where insx.id_inst_xref = '5660249'
      and insx.flg_active = 'N'
      group by insx.id_inst_xref_type,insx.id_inst_xref,insx.flg_active) dt

  • Count of tokens using group by + SYN operator + Spell Checking + Stemming

    Hi,
    I have a text data on which i have created context index and populated the tokens table using "CTX_DOC.TOKENS" procedure.
    Now i want to find the number of occurences of tokens using count and group by function.
    I am using the foll query on table "INSP_INS_IDX_TOK"
    select token ,count(token)
    from INSP_INS_IDX_TOK
    group by token
    order By 2 desc
    Token count(Token)
    WORK     84
    WORKING     24
    TAKING     14
    TAKE     13
    now i want to use the synonym operator, stemming operator and spelling check to be implemented while finding the count of tokens so that, it would give more insights.
    o/p should be like
    Token count(Token)
    WORK     108
    TAKE     27
    Please suggest me some inputs on the same.
    Thanks in Advance.

    put it in a table, create context index and then query....
    --- As oracle text can be used.
    On the different note, try to create a context index and look at the $I table of that index. You may find something relevant.

  • Not a single-group group function very urgent

    HI,
    select sum(avg(wait_to))+sum(avg(idle))+sum(avg(users))+sum(avg(system)) from system_cpu
    where hostid='DSCP02469' group by cpuid
    this query is working
    but i want cpuid group to be displayed
    so i wrote query like this.
    select cpuid,sum(avg(wait_to))+sum(avg(idle))+sum(avg(users))+sum(avg(system)) from system_cpu
    where hOstid=' ' group by cpuid it is throwing a error
    not a single-group group function.
    how can get sum of avg of colums,column based on some coloum
    group by column
    id,sum(avg( )) i have to get
    please give me solution.
    send me mail to [email protected]

    hi,
    thanku for immediate reply but
    if i do that
    select cpuid, a+b+c+d total_value from (select cpuid,
    sum(avg(wait_to)) a, sum(avg(idle)) b,sum(avg(users)) c,sum(avg(system)) d
    from system_cpu where hostid='DSCP02469' group by cpuid)
    SQL> /
    select cpuid, a+b+c+d total_value from (select cpuid,
    ERROR at line 1:
    ORA-00937: not a single-group group functionelse
    select cpuid, a+b+c+d total_value from (select
    sum(avg(wait_to)) a, sum(avg(idle)) b,sum(avg(users)) c,sum(avg(system)) d
    from system_cpu where hostid='DSCP02469' group by cpuid)
    SQL> /
    select cpuid, a+b+c+d total_value from (select
    ERROR at line 1:
    ORA-00904: "CPUID": invalid identifier2)
    can we use select in select case
    can we use select sal, case when sal then select * from emp like this
    with regards
    shannu sarma

  • ORA-00937:not a single-group group function|ORA-06512:at"schema.procedure n

    ORA-00937:not a single-group group function|ORA-06512:at"schema.procedure name)?
    The details of this procedure are the emp table is used in the emp1 which is shown in line 19
    1 DECLARE
    2 cur_emp sys_refcursor;
    3 TYPE t_tab IS TABLE OF emp%ROWTYPE;
    4 tt t_tab;
    5 cur_emp1 sys_refcursor;
    6 TYPE t1_tab IS TABLE OF emp1%ROWTYPE;
    7 tt1 t1_tab;
    8 BEGIN
    9 OPEN cur_emp FOR
    10 SELECT c1,c2,c3 FROM t1,t2,t3 where t1.c1=t2.c2 and t1.c1=t3.c3;
    11 LOOP
    12 FETCH cur_emp BULK COLLECT INTO tt LIMIT 100000;
    13 EXIT WHEN tt.COUNT=0;
    14 FOR i IN 1..tt.COUNT LOOP
    15 insert in to emp (c1,c2,c3) values (tt(i).c1,tt(i).c2,tt(i).c3;
    16 END LOOP;
    17 END LOOP;
    18 OPEN cur_emp FOR
    19 SELECT c11,c12,c13 FROM emp,t12,t13 where emp.c11=t12.c12 and t11.c11=t13.c13;
    20 LOOP
    21 FETCH cur_emp1 BULK COLLECT INTO tt1 LIMIT 100000;
    22 EXIT WHEN tt1.COUNT=0;
    23 FOR j IN 1..tt1.COUNT LOOP
    24 insert in to emp1 (c11,c12,c13) values (tt1(j).c11,tt1(j).c12,tt1(j).c13;
    25 END LOOP;
    26 END LOOP;
    27 END;
    /

    ORA-00937:not a single-group group function|ORA-06512:at"schema.procedure name)?
    The details of this procedure are the emp table is used in the emp1 which is shown in line 19
    1 DECLARE
    2 cur_emp sys_refcursor;
    3 TYPE t_tab IS TABLE OF emp%ROWTYPE;
    4 tt t_tab;
    5 cur_emp1 sys_refcursor;
    6 TYPE t1_tab IS TABLE OF emp1%ROWTYPE;
    7 tt1 t1_tab;
    8 BEGIN
    9 OPEN cur_emp FOR
    10 SELECT c1,c2,c3 FROM t1,t2,t3 where t1.c1=t2.c2 and t1.c1=t3.c3;
    11 LOOP
    12 FETCH cur_emp BULK COLLECT INTO tt LIMIT 100000;
    13 EXIT WHEN tt.COUNT=0;
    14 FOR i IN 1..tt.COUNT LOOP
    15 insert in to emp (c1,c2,c3) values (tt(i).c1,tt(i).c2,tt(i).c3);
    16 END LOOP;
    17 END LOOP;
    18 OPEN cur_emp FOR
    19 SELECT c11,c12,c13 FROM emp,t12,t13 where emp.c11=t12.c12 and emp.c11=t13.c13;
    20 LOOP
    21 FETCH cur_emp1 BULK COLLECT INTO tt1 LIMIT 100000;
    22 EXIT WHEN tt1.COUNT=0;
    23 FOR j IN 1..tt1.COUNT LOOP
    24 insert in to emp1 (c11,c12,c13) values (tt1(j).c11,tt1(j).c12,tt1(j).c13);
    25 END LOOP;
    26 END LOOP;
    27 END;

  • Trunc(date) group by query

    Hi.
    I have the following queries:
    1) select trunc(fechaalta), count(*) solicitudes from solicitud group by trunc(fechaalta)
    trunc(fechaalta) solicitudes
    30/01/12 14
    29/01/12 28
    28/01/12 205
    2) select trunc(fechaalta), count(*) ots from ot group by trunc(fechaalta);
    trunc(fechaalta) ots
    30/01/12 33
    29/01/12 39
    28/01/12 193
    I need a table merging both queries. It would be like this:
    trunc(fechaalta) solicitudes ots
    30/01/12 14 33
    29/01/12 28 39
    28/01/12 205 193
    How can I do it?.
    Thanks.

    Hi,
    864925 wrote:
    Does "with as" command work in oracle 10g?You mean "with *subquery_name* as", right? You need to give a name to each result set, right before the AS keyword. (It looks like Solomon forgot to name the 2nd subquery, and the 2nd AS keyword.)
    Try this:
    WITH     sulicitud_summary     AS
         SELECT       TRUNC (fechaalta)     AS dt
         ,       COUNT (*)          AS solicitudes
         FROM       solicitud
    --     WHERE       ...          -- If you need any filtering, put it here
         GROUP BY  TRUNC (fechaalta)
    ,     ot_group_summary     AS
         SELECT       TRUNC (fechaalta)     AS dt
         ,       COUNT (*)          AS ots
         FROM       ot_group
    --     WHERE       ...          -- If you need any filtering, put it here
         GROUP BY  TRUNC (fechaalta)
    SELECT       NVL (s.dt,         o.dt)     AS dt
    ,       NVL (s.solicitues, 0)          AS solicitudes
    ,       NVL (o.ots,          0)          AS ots
    FROM                 solicitud_summary  s
    FULL OUTER JOIN      ot_group_summary   o  ON   s.dt  = o.dt
    ;Yes, it works in Oracle 9.1 and higher.
    Solikcitud_summary and ot_summary are defined in the WITH clause. Once they are defined, you can use the result sets from those sub-queries, as if they were tables, anywhere in the query, including in other sub-queries.
    For more, look up "With query_name clause of SELECT" in the SQL language manual:
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9758
    I may have made some typos, too. Unless you post CREATE TABLE and INSERT statements to re-create your tables, I can't actually test it.
    I get "invalid table name" error. It is the first time using this command. Maybe I am missing something.Your message is missing something: your code. Post exactly what you're running. Even if you just copied and pasted it from this site, there may have been an editing error.
    Edited by: Frank Kulash on Jan 30, 2012 10:33 AM

  • Get the group by query faster

    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
    Kumar

    Did 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.

  • Single row sub query error

    Hi All
    I'm having the following query and its giving me "single row sub query returns more than one row". I did some research and all i could come across is using IN,ALL,ANY,NOT IN.... with the WHERE clause but not in the CASE statement so can any one please point me in the right direction?
    SELECT ROW_NUMBER () OVER (PARTITION BY traffic_sample_id ORDER BY bin_data_id)
                                                                  AS row_number_1,
           COUNT (bin_data_id) OVER (PARTITION BY traffic_sample_id) AS count_1,
           (CASE
               WHEN days != 2
                  THEN (SELECT traffic_sample_id
                          FROM (SELECT ROW_NUMBER () OVER (PARTITION BY traffic_sample_id ORDER BY bin_data_id)
                                                                            AS rn,
                                       traffic_sample_id
                                  FROM bin_data)
                         WHERE rn <= 48)
               ELSE (SELECT traffic_sample_id
                       FROM bin_data)
            END
           ) traffic_sample_id
      FROM (SELECT ROW_NUMBER () OVER (PARTITION BY t1.traffic_sample_id ORDER BY t1.bin_data_id)
                                                                    AS ROW_NUMBER,
                   COUNT (t1.bin_data_id) OVER (PARTITION BY t1.traffic_sample_id)
                                                                         AS COUNT,
                   t1.traffic_sample_id, t1.bin_data_id, t1.end_intv_time,
                   (  TO_DATE (t2.end_date, 'mmddyy')
                    - TO_DATE (t2.start_date, 'mmddyy')
                   ) AS days
              FROM bin_data t1, traffic_sample t2
             WHERE t1.traffic_sample_id = t2.traffic_sample_id(+))Thanks

    Hi,
    One of these two SELECT statements must be bringing back more thean one row:
                  THEN (SELECT traffic_sample_id
                          FROM (SELECT ROW_NUMBER () OVER (PARTITION BY traffic_sample_id ORDER BY bin_data_id)
                                                                            AS rn,
                                       traffic_sample_id
                                  FROM bin_data)
                         WHERE rn <= 48)
               ELSE (SELECT traffic_sample_id
                       FROM bin_data)

  • Issue with not a single-group group function error

    Hello PL/SQL Gurus,
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production version and
    Once I am using the following query –
    SELECT s.sym,
    t.tag_trade_method trade_method,
    astd.tag_trade_sector,
    iss.gics_sector_dsc sector,
    d.date_dt trade_date,
    c.wmc_curcy_cd_alpha curcycode,
    amd.brkr_nm,
    SUM(atdf.notional_amt) trd_notional,
    SUM(atdf.trd_qty) trd_qty,
    ard.buy_sell_ind,
    td.person_init
    FROM alloc_tran_det_fact atdf,
    date_dim d,
    alloc_trade_tag_dim t,
    security_dim s,
    currency_dim c,
    person_dim td,
    access_method_dim amd,
    alloc_sec_tag_dim astd,
    alloc_ref_dim ard,
    issuer_dim iss
    where atdf.alloc_trd_tag_dim_key = t.alloc_trade_tag_dim_key AND
    atdf.alloc_sec_tag_dim_key = astd.alloc_sec_tag_dim_key AND
    ard.alloc_ref_dim_key = atdf.alloc_ref_dim_key AND
    atdf.isr_dim_key = iss.isr_dim_key AND
    atdf.trd_dt_key = d.date_dim_key AND
    atdf.sec_dim_key = s.sec_dim_key AND
    t.tag_valid_trade_flg = 'Y' AND
    atdf.locl_curcy_flg = 'Y' AND
    d.date_dim_key BETWEEN 20120405 AND 20120405 AND
    c.curcy_dim_key = atdf.curcy_dim_key AND
    td.person_dim_key = atdf.trdr_dim_key AND
    atdf.exec_brkr_dim_key = amd.access_method_dim_key AND
    amd.level_cd = 'B'
    and t.tag_trade_method in('ALGO','CAPITAL','DMA','NATURAL','WORKING')
    then it throw the error –
    ORA-00937: not a single-group group function
    If I am using something like –
    SELECT s.sym,
    t.tag_trade_method trade_method,
    astd.tag_trade_sector,
    iss.gics_sector_dsc sector,
    d.date_dt trade_date,
    c.wmc_curcy_cd_alpha curcycode,
    amd.brkr_nm,
    SUM(atdf.notional_amt) trd_notional,
    SUM(atdf.trd_qty) trd_qty,
    td.person_init
    FROM alloc_tran_det_fact atdf,
    date_dim d,
    alloc_trade_tag_dim t,
    security_dim s,
    currency_dim c,
    person_dim td,
    access_method_dim amd,
    alloc_sec_tag_dim astd,
    issuer_dim iss
    WHERE atdf.alloc_trd_tag_dim_key = t.alloc_trade_tag_dim_key AND
    atdf.alloc_sec_tag_dim_key = astd.alloc_sec_tag_dim_key AND
    atdf.isr_dim_key = iss.isr_dim_key AND
    atdf.trd_dt_key = d.date_dim_key AND
    atdf.sec_dim_key = s.sec_dim_key AND
    t.tag_valid_trade_flg = 'Y' AND
    atdf.locl_curcy_flg = 'Y' AND
    d.date_dim_key BETWEEN 20120102 AND 20120401 AND
    c.curcy_dim_key = atdf.curcy_dim_key AND
    td.person_dim_key = atdf.trdr_dim_key AND
    atdf.exec_brkr_dim_key = amd.access_method_dim_key AND
    amd.level_cd = 'B'
    and t.tag_trade_method in('ALGO','CAPITAL','DMA','NATURAL','WORKING')
    GROUP BY t.tag_trade_method,
    d.date_dt,
    c.wmc_curcy_cd_alpha,
    td.person_init,
    amd.brkr_nm,
    astd.tag_trade_sector,
    iss.gics_sector_dsc
    then it works fine. I know that due to aggeregate functions we need to use Group By, but why to put Group By on different non aggregate columns,
    As my intension is to fetch the records for defined date range Group By Symbol (s.sym), Kindly help me with this. 
    Thanks to all of you in advance for providing you valuable time and efforts.
    Edited by: user555994 on May 11, 2012 2:20 AM

    You do need to group by these columns
    t.tag_trade_method,
    d.date_dt,
    c.wmc_curcy_cd_alpha,
    td.person_init,
    amd.brkr_nm,
    astd.tag_trade_sector,
    iss.gics_sector_dsc
    as they don't have aggregate functions applied to them.

  • How can I get out on a single group message

    I am in a group text message with 10 people and I only have contact information for one of them. I do probably know everyone in the group but as I said I don't have information for pretty much any of them, which makes it super annoying since I have no idea who is saying what. Also with a group of this size, I get bonbarded with like 15+ messages in like a five minute period. I got added to this group two days ago and I have already received at 100 messages in this group, which is especially annoying when I am at work or this morning when I was sleeping.
    I have an iPhone 5, and I really do not want to go in and disable all of the group message features, because I have several with my family and would to still be able to use those. Please tell me that there is a way to get out of a single group message. Thanks for the help.

    There is, currently, no way to get out of a group iMessage other than asking the person who started such to remove you, or:
    Show up at their house with two enforcers & "politely" ask that you be removed .

  • How to only count parent items in a hierarchical query

    Hello,
    We have a query of Code Review Request and Code Review Responses and also a Query of PBI's and Tasks, each of which are pinned to the home page in TFS Web Access.  For the Code Review query we'd like to only show the count for parent items on the home
    page, and for the PBI/Task query we'd like to only show the count for the Tasks of a certain status.
    Is it possible to specify how the count is calculated, separate from the query filter(s)?

    Hi Burton,  
    Thanks for your post.
    No, there’s no default way to specify a calculated count for work item query in this scenario. If you want to show Code Review Request work items or Task work items in home age, you should try to create the separate queries for
     Code Review Request work items or Task work items, then pin that queries to home page.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Prevent multiple users from editing/approving the same form SPD 2013,SP 2013

    Hello all, I have a workflow with a to do task, the task is assigned to a group so any of the users in that group can go in and do a quality check on form data and approve it.  How do I prevent multiple users from working on the same form? do I just

  • JVM optimization of load driver forName and db getConnection

    I am working on a site that already had these jsp pages. There is very little java code to the site. Almost everything is done through the jsp page plus one main java class to store state data. The site's jsp page may do up to 7 queries on the databa

  • QuickTime Player

    Hi. I've upgraded to Snow Leopard and I thought one of the built in features was a new version of QuickTime that meant we no longer had to buy the "Pro" version. I have QuickTime Player as part of Snow Leopard and I'm trying to transfer movies to my

  • Uploading Data in a User Defined table

    Hello Experts, I have a user defined table YFEED_TABLE_2 as a local object in the System. i want to upload some data from TEXT file to the table using LSMW TCode.. But after selecting  u201CMaintain Object Attributesu201D in LSMW transaction...in the

  • OWB 11g R1 DM Schema Script

    Dear All, I am working on Oracle Warehouse Builder 11g R1 (with Database as 11g R1) on Windows 2003 Server Enterprse Edition. While practicing on Oracle Database 11g-Data Warehousing Fundamentals Training - Activity Guide, Practice 1-1, I came across