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
Similar Messages
-
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 -
"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 -
Problem with different resultset with same data and same query in Oracle 8.1.7 and 9i
Hello,
I have been using this query in oracle 8.1.7
SELECT
ID,
AREA_NO
FROM MANAGER_AREA MGR
WHERE COMPANY_ID = :id AND
(:value < (SELECT COUNT(ROWID)
FROM MANAGER_WORK MW
WHERE MW.AREA_ID = MGR.ID AND
(MW.END_WORK IS NULL OR MW.END_WORK >= SYSDATE)))
order by AREA_NO;
In the above query I want to see rows from MANAGER_AREA table depending upon date criteria in the table MANAGER_WORK and also upon the parameter :value i.e if I pass a value as 0 I get to see records for which their is atleast 1 record in MANAGER_WORK with the date criteria and if I pass -1 then I get all the records because minimum value that count(*) would give is 0. The resultset was as expected in 8.1.7.
A couple of days back I installed PERSONAL 9i to test for testing the basic functionality of our program with the same data. This query fails and irrespective whether I pass -1 or 0 it returns me same dataset which I would have got in case if I pass 0.
I do not know whether this is a bug that has got introduced in 9i. Can anybody help me with this problem. It would be difficult for me to change the parameter send to this query as the Query is called from many different places.
Thanks in advance
Amol.I cannot use a Group by and a having statement over here. The problem with 'Group by' and 'having' clause is If I have to make a join between the two tables. When I use join then I get only rows that are linked to each other in the table.
If I use outer join to solve that problem then I have to take in consideration the other date condition. My previous query use to virtually discard the corelated query result by using -1 as the value. This will not happen in the join query.
Amol. -
How to aggregate data in SQL Query
Hi,
I have Table1 field1 and field2. Combination of these fields form the key of this table.
Next I have Table2 with field3 and field4. field1 is the unique key for this table.
My query is:
select T2.field4||','||T1.field2 from T1 inner join T2 on T1.field1 = T2.field3;
In the result I want to aggregate the data by T2.field4
How do I that? Please help
Thanks in advance,
RajaHow to aggregate data in SQL Query By using aggregate functions and group by:
SQL> select object_type, count(*), sum(decode(status,'VALID',0,1)) inv_obs
2 from all_objects
3 group by object_type;
OBJECT_TYPE COUNT(*) INV_OBS
CONSUMER GROUP 2 0
INDEX PARTITION 970 0
TABLE SUBPARTITION 14 0
SEQUENCE 226 0
SCHEDULE 1 0
TABLE PARTITION 349 0
PROCEDURE 21 0
OPERATOR 57 0
WINDOW 2 0
PACKAGE 313 0
PACKAGE BODY 13 0
LIBRARY 12 0
PROGRAM 9 0
INDEX SUBPARTITION 406 0
LOB 1 0
JAVA RESOURCE 771 0
XML SCHEMA 24 0
JOB CLASS 1 0
TRIGGER 1 0
TABLE 2880 0
INDEX 4102 0
SYNONYM 20755 140
VIEW 3807 72
FUNCTION 226 0
WINDOW GROUP 1 0
JAVA CLASS 16393 0
INDEXTYPE 10 0
CLUSTER 10 0
TYPE 1246 0
EVALUATION CONTEXT 1 0 -
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. -
Converting Crystal Date Group to SQL Command
When selecting the option to group on the server, I found that there are requirements in addition to selecting the option.
I have a date grouping in Crystal like the following:
dateadd("d", - weekday({table.date}, crMonday)+1,{table.date})
Can this be converted to a SQL command?Hi Mark,
Jyothi had given an excellent query for you, Congrats Jyothy!!
But she didnt mantioned 'From clouse' on that.
Let me correct that query with an example,
My TableName: Invoice
Primary Key: InvoicePID
Date field:InvoiceDate
Here the query will be
select InvoicePID, Dateadd(d,-(CASE WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Monday' THEN 1
WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Tuesday' THEN 2
WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Wednesday' THEN 3
WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Thursday' THEN 4
WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Friday' THEN 5
WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Saturday' THEN 6
WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Sunday' THEN 7
END
)+1 ,Invoice.InvoiceDate)
from Invoice
You can change the tablename and field with respect to your DB.
regards,
Salah. -
Get the latest date record in Query
Hi, Expert:
Please help on this:
The requirement is to get the the latest date record in Query. For example:
Data in provider:
Plant date amount
A01 2007/04/08 30
A01 2007/06/09 70
A01 2007/12/08 30
we only want the query display:
A01 2007/12/08 30
I have tried exception aggregation, but it does not work. Any ideas are highly appreciated.Or you can model the date as a key figure after 0date_kyf and set aggregation to max, you'll get something like
select plant, amount, max(date) from ... group by plant, amount
used it for inventory reporting (materials and their last movement date, days from the last movement etc.) and worked well. -
Relation between Application and Data Group
Hello All,
Can someone please help me to get a query which tells me which Application is associated with which Data Group?
Thanks,
MooreMoore,
Query FND_DATA_GROUP_UNITS_V -- http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_DATA_GROUP_UNITS_V&c_owner=APPS&c_type=VIEW
If the view doesn't satisfy your requirements, then write your own query using the following tables:
APPLSYS.FND_DATA_GROUPS
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_DATA_GROUPS&c_owner=APPLSYS&c_type=TABLE
APPLSYS.FND_DATA_GROUP_UNITS
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_DATA_GROUP_UNITS&c_owner=APPLSYS&c_type=TABLE
APPLSYS.FND_APPLICATION
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_APPLICATION&c_owner=APPLSYS&c_type=TABLE
Thanks,
Hussein -
Unable to access the data from Data Management Gateway: Query timeout expired
Hi,
Since 2-3 days the data refresh is failing on our PowerBI site. I checked below:
1. The gateway is in running status.
2. Data source is also in ready status and test connection worked fine too.
3. Below is the error in System Health -
Failed to refresh the data source. An internal service error has occurred. Retry the operation at a later time. If the problem persists, contact Microsoft support for further assistance.
Error code: 4025
4. Below is the error in Event Viewer.
Unable to access the data from Data Management Gateway: Query timeout expired. Please check 1) whether the data source is available 2) whether the gateway on-premises service is running using Windows Event Logs.
5. This is the correlational id for latest refresh failure
is
f9030dd8-af4c-4225-8674-50ce85a770d0
6.
Refresh History error is –
Errors in the high-level relational engine. The following exception occurred while the managed IDataReader interface was being used: The operation has timed out. Errors in the high-level relational engine. The following exception occurred while the
managed IDataReader interface was being used: Query timeout expired.
Any idea what could have went wrong suddenly, everything was working fine from last 1 month.
Thanks,
RichaNever mind, figured out there was a lock on SQL table which caused all the problems. Once I released the lock it PowerPivot refresh started working fine.
Thanks. -
Can we use session variables in BI publisher's Data Model SQL Query?
Hi Experts,
We need to implement Data level security in BI Publisher 11g.
In OBIEE we do so by using session variables, so just wanted to ask if we can use the same session variables in BI Publisher as well
ie can we include the where clause in the Data Models SQL Query like
Where ORG_ID = @{biServer.variables['NQ_SESSION.INV_ORG']}
Let me know your views on this.
PS: We are implementing EBS r12 security in BI Publisher.
ThanksRead this -> OBIEE 11g: Error: "[nQSError: 23006] The session variable, NQ_SESSION.LAN_INT, has no value definition." when Creating a SQL Query using the session variable NQ_SESSION.LAN_INT in BI Publisher [ID 1511676.1]
Follow the ER - BUG:13607750 - NEED TO BE ABLE TO SET A SESSION VARIABLE IN OBIEE AND USE IT IN BI PUBLISHER
HTH,
SVS -
Hi,
I am in version R12.1.3 . I have a requirement to create a user who must have access only to create payments in AP module.So when i try to define a responsibility for this payment user
there is a data group to be assigned. In this data group block for application there are 2 options i.e Payables & Payments? What should I select & what is the difference of selection one over the other?
Appreciate your help.
ThanksHi,
i did not see any difference .... I performed a test case, where i created a payment using the new responsibility i have created having data group application as Payments, the payment was successful ... Later i have modified the data group for this new responsibility from payments to payables, then the test payment i have made was also successful....
Not sure about its impact, may be i am having responsibilities which has full access, hence i cannot see the difference in my environment ....
Regards,
Ivruksha -
Hello All,
We are using a two tier architecture.
Our Corp server calls the refinery server.
Our CORP MII server uses user id abc_user to connect to the refinery data server.
The user id abc_user has the SAP_xMII_Dynamic_Query role.
The data server also has the checkbox for allow dynamic query enabled.
But we are still getting the following error
Error has occurred while processing data stream
Dynamic Query role is not assigned to the Data Server; Use query template
Once we add the SAP_xMII_Dynamic_Query role to the data server everything works fine. Is this feature by design ?
Thanks,
KiranThanks Anushree !!
I thought that just adding the role to the user and enabling the dynamic query checkbox on the data server should work.
But we even needed to add the role to the data server.
Thanks,
Kiran -
No data from BW-Query in BO-tools
Hello all
On a newly installed BO XI 3.1 with the SAP integration kit I cannot get data from my existing BW queries.
For example, if I start Xcelsius and add my BW-system as connection I can get the structure of the query (headings) but no data is displayed, neither in the connection's preview tab nor in the web preview.
The same happens if I create a QaaWS on this BW-query - I see the query headings, but not the actual data.
The query shows data if I open it directly in my web browser and it's a really simple one: no variables, no extras, only a few columns and rows.
I use SAP BW 7.01 SP6, XI 3.1 12.3.3 and XCelsius 2008 5.3.4
In SAP BW my user has SAP_ALL as well as BOE Admin & Content producer roles.
I'm relatively new to BO products so I have no idea where to start looking for the cause. Please help!
BR
KananHi
After I found the document "Using Xcelsius 2008 with SAP NetWeaver BW" (http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10ad2489-8956-2d10-f8ab-ed4cce2766da?quicklink=index&overridelayout=true) and followed the steps it works.
It seems as if the error was not in the system but in front of it - a typical case of RTFM, although the manuals are not always easy to find.
sorry & thanks.
BR
Kanan -
Dear All,
I have created a customer exit variable on key date of a query.
With this input variable i am first asking user to input one particular date say he enters 31.12.2010 then i am trying to add 1 more day to it and making it 01.01.2011.
I have put a break point in the code but it does not stop the processing there.. report executes directly taking the first user input.
I want to add 1 more day to the user entered date and this modifiied date should be the input date for key date field.
Below is my code.
WHEN 'ZCAL_DAY_EXT'.
IF I_STEP = 2. "after the popup
LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
WHERE VNAM = 'ZCAL_DAY_EXT'.
CLEAR L_S_RANGE.
ENDLOOP.
DATA: v_temp like sy-datum.
v_temp = loc_var_range-low.
v_temp = v_temp + 1.
L_S_RANGE-LOW = v_temp.
L_S_RANGE-SIGN = 'I'.
L_S_RANGE-OPT = 'EQ'.
APPEND L_S_RANGE TO E_T_RANGE.
ENDIF.
Do let me know where am i going wrong? Or is it we cannot use customer exit with Key date.
Thanks & Regards,
Anup
Edited by: Anup Chaudhari on Aug 2, 2011 7:16 AMHi Anup,
Basically I_STEP = 1 is used for populating the default value which will be shown on selection screen and I_STEP = 2 is the step in which you does the processing on variable values which are entered on selection screen.
I am surprised that your internal table is empty, actually it is supposed to contain all the variable values which are entered in I_STEP = 1.
Can you try to add some more variables along with the current variable and check whether their value is coming in the internal table or not?
Finally what you can try is get the user input date in one variable and then create another customer exit variable in which you will calculate the new value and use this variable in Key date, the problem might be that we are trying to modify the same variable, actually it should not be the problem but I have no clue what is happening and you can just try this alternative.
Regards,
Durgesh.
Maybe you are looking for
-
I am using a Mac and when I save my files as a jpeg, the files become much smaller, and consequently darker and blurrier. What can I do to fix this? I have tried to figure out how to chat with someone at Adobe, but they certainly don't make it easy
-
Macbook to studio display, which lead?
what lead do i need to run my old apple 17" studio display from my macbook? mini-dvi vga female to male blah blah blah....spell it out for an idiot! thanks in advance.
-
Help changing AS3 -- AS2 please
I was following a tutorial in AS3 with a MouseEvent but really want to use it in AS2. There is an Input Text box named boxOne that a user enters their name You click on myButton and in then in boxTwo should appear the test "Welcome to our class" and
-
Can I delete the "last import" in iphoto after I have transferrd photos from pictures on my imac to the iphoto library? If I delete the pics, will it undo them? Wll it remove the pics from the iphoto library?
-
How do you change your phone number in your iPad messages and replace it with another number. In order to send and receive messages to the correct phone number?