Group by query on ...
Thanks in advance to all
As I can get records whose count(COL1) is <= 4 too
that is
SELECT COL1, COL2, count (*)
FROM TABEL Á.
WHERE A.XXX between & data1 AND & DATA2
having count(COL1) >= 4 --
GROUP BY COL1, COL2
ORDER BY 1,2
without writing an inline view
thanks
Message was edited by:
Rosario Vigilante
You mean like this?
SQL> create table tabel
2 as
3 select 'XXXXXXXXXXX' col1, '06 GIU' col2, sysdate xxx from dual union all
4 select 'XXXXXXXXXXX', '06 GIU', sysdate from dual union all
5 select 'XXXXXXXXXXX', '06 GIU', sysdate from dual union all
6 select 'XXXXXXXXXXX', '08 AGO', sysdate from dual union all
7 select 'XXXXXXXXXXX', '08 AGO', sysdate from dual union all
8 select 'XXXXXXXXXXX', '08 AGO', sysdate from dual union all
9 select 'XXXXXXXXXXX', '08 AGO', sysdate from dual union all
10 select 'YYYYYYYYYYY', '06 GIU', sysdate from dual union all
11 select 'YYYYYYYYYYY', '06 GIU', sysdate from dual union all
12 select 'ZZZZZZZZZZZ', '02 FEB', sysdate from dual union all
13 select 'ZZZZZZZZZZZ', '04 APR', sysdate from dual union all
14 select 'ZZZZZZZZZZZ', '05 MAG', sysdate from dual union all
15 select 'ZZZZZZZZZZZ', '09 SET', sysdate from dual union all
16 select 'ZZZZZZZZZZZ', '10 OTT', sysdate from dual union all
17 select 'ZZZZZZZZZZZ', '12 DIC', sysdate from dual
18 /
Tabel is aangemaakt.
SQL> select col1, col2, countall
2 from ( select col1
3 , col2
4 , sum(count(*)) over (partition by col1) countcol1
5 , count(*) countall
6 from tabel
7 where xxx between date '2007-01-01' and date '2007-12-31'
8 group by col1, col2
9 )
10 where countcol1 >= 4
11 order by 1,2
12 /
COL1 COL2 COUNTALL
XXXXXXXXXXX 06 GIU 3
XXXXXXXXXXX 08 AGO 4
ZZZZZZZZZZZ 02 FEB 1
ZZZZZZZZZZZ 04 APR 1
ZZZZZZZZZZZ 05 MAG 1
ZZZZZZZZZZZ 09 SET 1
ZZZZZZZZZZZ 10 OTT 1
ZZZZZZZZZZZ 12 DIC 1
8 rijen zijn geselecteerd.Regards,
Rob.
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. -
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 -
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 -
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. -
create a matrix query to display a job, the salary for that job based on department number, and the total salary for that job, for departments 20,50,80,90 giving each column an appropriate heading. this is the excise query available in oracle in ebook. I have solved it by using inline view.. given below.. Is ther any other way to solve the same quey.. Please help..
SELECT job_id,
CASE
WHEN department_id=20
THEN salary
ELSE NULL
END AS dept20,
CASE WHEN department_id=50 THEN salary ELSE NULL
END AS dept50,
CASE WHEN department_id=80 THEN salary ELSE NULL
END AS dept80,
CASE WHEN department_id=90 THEN salary ELSE NULL
END AS dept90,
salary
FROM
(SELECT job_id,
SUM(salary) salary,
department_id
FROM employees
WHERE department_id IN (20,50,80,90)
GROUP BY job_id,
department_id
) order by job_id;Hi,
you can try something like this:
*not tested
select distinct job_id,
(select nvl(sum(salary), 0) from employees where job_id = e.job_id and department_id = 20) sum_sal_20,
(select nvl(sum(salary), 0) from employees where job_id = e.job_id and department_id = 50) sum_sal_50,
(select nvl(sum(salary), 0) from employees where job_id = e.job_id and department_id = 80) sum_sal_80,
(select nvl(sum(salary), 0) from employees where job_id = e.job_id and department_id = 90) sum_sal_90
from employees e
where department_id IN (20,50,80,90)
group by job_id, department_idRegards
Imran -
Query Group in Query Category different with Authorization's group number
Hi All,
In Authorization screen, it allowed to authorize up to 20 query group
Whereas in Query Category window, it has only max 15 query group.
Anyone has idea on why is the difference?
Thanks in advance,
MHYou have a very good point. I believe something must be for system to use during development. You may post a development request to see if the next version could have matched numbers of query groups. The forum is on this link:
/community [original link is broken]
Thanks,
Gordon
Edited by: Paulo Calado on Jun 19, 2009 3:33 PM -
Need help on group by query problem.
Hi,
I've a table like..
CREATE TABLE DPT(DEPTNO NUMBER(4),HIREDATE DATE);
INSERT INTO DPT VALUES(10,SYSDATE);
INSERT INTO DPT VALUES(10,SYSDATE+1);
INSERT INTO DPT VALUES(10,SYSDATE+2);
INSERT INTO DPT VALUES(10,SYSDATE+3);
INSERT INTO DPT VALUES(10,SYSDATE+4);
INSERT INTO DPT VALUES(10,SYSDATE+5);
INSERT INTO DPT VALUES(20,SYSDATE);
INSERT INTO DPT VALUES(20,SYSDATE+1);
INSERT INTO DPT VALUES(20,SYSDATE+2);
INSERT INTO DPT VALUES(20,SYSDATE+3);
INSERT INTO DPT VALUES(30,SYSDATE);
INSERT INTO DPT VALUES(30,SYSDATE+1);
INSERT INTO DPT VALUES(30,SYSDATE+2);
INSERT INTO DPT VALUES(30,SYSDATE+3);
INSERT INTO DPT VALUES(30,SYSDATE+4);
SELECT DEPTNO,HIREDATE FROM DPT;
DEPTNO HIREDATE
10 30-OCT-09
10 31-OCT-09
10 1-NOV-09
10 2-NOV-09
10 3-NOV-09
10 4-NOV-09
20 30-OCT-09
20 31-OCT-09
20 1-NOV-09
END SO ON..
Actually DPT table having 11 lacs records and Every deptno has got different hiredates.
I want to retrieve the deptno with minimum hiredate i.e deptno having first date.
So i've written a query like this using group by clause , When i use the group by clause
it is taking almost 15 sec to give the result.
SELECT DEPTNO,MIN(HIREDATE) FROM DPT GROUP BY DEPTNO;
DEPTNO HIREDATE
10 30-OCT-09
20 30-OCT-09
30 30-OCT-09
So is there any otherway of achieving the above result without using group by hence it is taking much time.
Am using Oracle 10g, TOAD 8.6.1 version
I've done the analyzing of the table & there are Indexes on both the columns.
Explan result Below:
PLAN_TABLE_OUTPUT
Plan hash value: 682192801
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 231K| 2938K| | 3804 (4)| 00:00:46 |
| 1 | SORT GROUP BY | | 231K| 2938K| 32M| 3804 (4)| 00:00:46 |
| 2 | INDEX FAST FULL SCAN| DPT_NDX1 | 1180K| 14M| | 1019 (1)| 00:00:13 |
Please give the other ways of writing the same query for improving the performance.
Regards,
Arjun.Hi Karhick,
Thanks for the reply. It is giving expected result,but performance not improved.Please find the below Eplan
PLAN_TABLE_OUTPUT
Plan hash value: 1880836313
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1180K| 32M| | 6714 (2)| 00:01:21 |
|* 1 | VIEW | | 1180K| 32M| | 6714 (2)| 00:01:21 |
|* 2 | WINDOW SORT PUSHED RANK| | 1180K| 14M| 54M| 6714 (2)| 00:01:21 |
| 3 | INDEX FAST FULL SCAN | DPT_NDX1 | 1180K| 14M| | 1019 (1)| 00:00:13 |
Predicate Information (identified by operation id):
1 - filter("RNO"=1)
2 - filter(ROW_NUMBER() OVER ( PARTITION BY "DEPTNO" ORDER BY "HIREDATE")<=1)
What i've to do now. Please let me know.
Regards,
Arjun.
Maybe you are looking for
-
Exporting to PDF with Vector/Transparency issues? (huge file)
Hi folks I have a 36 page magazine in Indesign which has a lot of illustrator images placed in, some of which have transparency applied. The images are xmas icons and there are 10 or so on each illustrator file so there are only 3/4 illustrator file
-
How do I add hotmail to mailto in firefox 10 ?
I tried using the old suggested method for firefox 3 http://www.computercorrect.com/2011/desktop-applications/firefox/adding-services-for-mailto-links-in-firefox/ but it no longer works I would rather not have a addon/plugin for this so how can I cha
-
Hi All, I am writing a report to get data related to material master and download it to excel sheet. While downloading I need to use a separate tab in excel sheet for each area of the material master, for example, a tab for Basic 1, Basic 2, MRP1, et
-
Calling a VI in a subpanel with parameters inside an event structure and using an abort button
Hi all, I have a control panel with a tab control and two tabs have a sub panel in them. At runtime I load the VIs I want in to the sub panels. In the control panel event structure I want to start each of the VIs and monitor the execution state so
-
No javaws in AMD64 Linux distribution
Hey everyone! I'm trying to use Java webstart. I just installed jdk-1_5_0_07-linux-amd64-rpm.bin, and there is no javaws command, although it's man page is installed. linux:~ # ls /usr/java/jdk1.5.0_07/bin . jarsigner jdb jstatd