Problem in Query with JOIN Function in OCRD CRD1 OCPR tables
Hello Dear Forum Users,
I want to make a query which shows me per business partner from OCRD - Addres; CRD1 - Delivery Address and from OCPR - Contactperson information
Is it possible to show it in one row per Business Partner. Now I get (the classic problem) of several rows and a duplication of the contact persons per (delivery) address.
My query is:
SELECT T0.[CardCode], T0.[CardName], T1.[Address], T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_MobNr], T1.[U_OpenTijd], T1.[U_LosIns_1], T1.[U_LosIns_2],T2.[Title], T2.[Name] as 'Voornaam', T2.[Address] as 'Achternaam', T2.[Position] as 'Functie', T2.[Tel1], T2.[Cellolar], T2.[E_MailL], T2.[BirthDate] FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
Can you help me ?
Jos Dielemans - Maastricht
Edited by: J. Dielemans on Apr 29, 2011 4:28 PM
Changed the query with Left Outer Join
I have found the solution myself:
By using the Union All function I could combine two queries. Here is the result:
SELECT
T0.[CardCode], T0.[CardName], T1.[Address] , T1.[Street], T1.[ZipCode], T1.[City], T1.[Country], T1.[U_TelNr], T1.[U_OpenTijd] , T1.[U_LosIns_1] , T1.[U_LosIns_2]'
FROM OCRD T0 LEFT OUTER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
WHERE T0.[CardCode] >= 'D00000'
Union all
SELECT
T0.[CardCode], T0.[CardName], T2.[Position], T2.[Tel1], T2.[Title], T2.[Name], T2.[Address], T2.[Position], T2.[Tel1], T2.[Cellolar], T2.[E_MailL]
FROM OCRD T0 LEFT OUTER JOIN OCPR T2 ON T0.CardCode = T2.CardCode
WHERE T0.[CardCode] >= 'D00000'
Order by 1
Now i got the result I was looking for.
Similar Messages
-
Need complex query with joins and AGGREGATE functions.
Hello Everyone ;
Good Morning to all ;
I have 3 tables with 2 lakhs record. I need to check query performance.. How CBO rewrites my query in materialized view ?
I want to make complex join with AGGREGATE FUNCTION.
my table details
SQL> select from tab;*
TNAME TABTYPE CLUSTERID
DEPT TABLE
PAYROLL TABLE
EMP TABLE
SQL> desc emp
Name
EID
ENAME
EDOB
EGENDER
EQUAL
EGRADUATION
EDESIGNATION
ELEVEL
EDOMAIN_ID
EMOB_NO
SQL> desc dept
Name
EID
DNAME
DMANAGER
DCONTACT_NO
DPROJ_NAME
SQL> desc payroll
Name
EID
PF_NO
SAL_ACC_NO
SALARY
BONUS
I want to make complex query with joins and AGGREGATE functions.
Dept names are : IT , ITES , Accounts , Mgmt , Hr
GRADUATIONS are : Engineering , Arts , Accounts , business_applications
I want to select records who are working in IT and ITES and graduation should be "Engineering"
salary > 20000 and < = 22800 and bonus > 1000 and <= 1999 with count for males and females Separately ;
Please help me to make a such complex query with joins ..
Thanks in advance ..
Edited by: 969352 on May 25, 2013 11:34 AM969352 wrote:
why do you avoid providing requested & NEEDED details?I do NOT understand what do you expect ?
My Goal is :
1. When executing my own query i need to check expalin plan.please proceed to do so
http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9010.htm#SQLRF01601
2. IF i enable query rewrite option .. i want to check explain plan ( how optimizer rewrites my query ) ? please proceed to do so
http://docs.oracle.com/cd/E11882_01/server.112/e16638/ex_plan.htm#PFGRF009
3. My only aim is QUERY PERFORMANCE with QUERY REWRITE clause in materialized view.It is an admirable goal.
Best Wishes on your quest for performance improvements. -
Problem in query with the u0091Document numberu0092
Hi,
I got problem in query with the Document number
There are three columns in the cube 1) Document number 2) Country 3) Count
In the cube there are multiple entries for same document number as below.
Document number country Count
10000 US 1
10001 US 1
10002 US 1
10002 US 1
10002 US 1
10003 UK 1
10004 IN 1
10004 IN 1
When I ran the query on this cube for country US it shows count as 5 but I want count as 3 (i.e. it has to take count only once for the same document nos)
Similarly for country IN I want count as 1Hi,
You have to create a counter based on the document number (exception aggregation). There is a How-to paper available for this. It is called: How-to...count the occurences of a characteristic.
Regards,
P. -
Need help in optimizing the query with joins and group by clause
I am having problem in executing the query below.. it is taking lot of time. To simplify, I have added the two tables FILE_STATUS = stores the file load details and COMM table that is actual business commission table showing records successfully processed and which records were transmitted to other system. Records with status = T is trasnmitted to other system and traansactions with P is pending.
CREATE TABLE FILE_STATUS
(FILE_ID VARCHAR2(14),
FILE_NAME VARCHAR2(20),
CARR_CD VARCHAR2(5),
TOT_REC NUMBER,
TOT_SUCC NUMBER);
CREATE TABLE COMM
(SRC_FILE_ID VARCHAR2(14),
REC_ID NUMBER,
STATUS CHAR(1));
INSERT INTO FILE_STATUS VALUES ('12345678', 'CM_LIBM.TXT', 'LIBM', 5, 4);
INSERT INTO FILE_STATUS VALUES ('12345679', 'CM_HIPNT.TXT', 'HIPNT', 4, 0);
INSERT INTO COMM VALUES ('12345678', 1, 'T');
INSERT INTO COMM VALUES ('12345678', 3, 'T');
INSERT INTO COMM VALUES ('12345678', 4, 'P');
INSERT INTO COMM VALUES ('12345678', 5, 'P');
COMMIT;Here is the query that I wrote to give me the details of the file that has been loaded into the system. It reads the file status and commission table to show file name, total records loaded, total records successfully loaded to the commission table and number of records that has been finally transmitted (status=T) to other systems.
SELECT
FS.CARR_CD
,FS.FILE_NAME
,FS.FILE_ID
,FS.TOT_REC
,FS.TOT_SUCC
,NVL(C.TOT_TRANS, 0) TOT_TRANS
FROM FILE_STATUS FS
LEFT JOIN
SELECT SRC_FILE_ID, COUNT(*) TOT_TRANS
FROM COMM
WHERE STATUS = 'T'
GROUP BY SRC_FILE_ID
) C ON C.SRC_FILE_ID = FS.FILE_ID
WHERE FILE_ID = '12345678';In production this query has more joins and is taking lot of time to process.. the main culprit for me is the join on COMM table to get the count of number of transactions transmitted. Please can you give me tips to optimize this query to get results faster? Do I need to remove group and use partition or something else. Please help!I get 2 rows if I use my query with your new criteria. Did you commit the record if you are using a second connection to query? Did you remove the criteria for file_id?
select carr_cd, file_name, file_id, tot_rec, tot_succ, tot_trans
from (select fs.carr_cd,
fs.file_name,
fs.file_id,
fs.tot_rec,
fs.tot_succ,
count(case
when c.status = 'T' then
1
else
null
end) over(partition by c.src_file_id) tot_trans,
row_number() over(partition by c.src_file_id order by null) rn
from file_status fs
left join comm c
on c.src_file_id = fs.file_id
where carr_cd = 'LIBM')
where rn = 1;
CARR_CD FILE_NAME FILE_ID TOT_REC TOT_SUCC TOT_TRANS
LIBM CM_LIBM.TXT 12345678 5 4 2
LIBM CM_LIBM.TXT 12345677 10 0 0Using RANK can potentially produce multiple rows to be returned though your data may prevent this. ROW_NUMBER will always prevent duplicates. The ordering of the analytical function is irrelevant in your query if you use ROW_NUMBER. You can remove the outermost query and inspect the data returned by the inner query;
select fs.carr_cd,
fs.file_name,
fs.file_id,
fs.tot_rec,
fs.tot_succ,
count(case
when c.status = 'T' then
1
else
null
end) over(partition by c.src_file_id) tot_trans,
row_number() over(partition by c.src_file_id order by null) rn
from file_status fs
left join comm c
on c.src_file_id = fs.file_id
where carr_cd = 'LIBM';
CARR_CD FILE_NAME FILE_ID TOT_REC TOT_SUCC TOT_TRANS RN
LIBM CM_LIBM.TXT 12345678 5 4 2 1
LIBM CM_LIBM.TXT 12345678 5 4 2 2
LIBM CM_LIBM.TXT 12345678 5 4 2 3
LIBM CM_LIBM.TXT 12345678 5 4 2 4
LIBM CM_LIBM.TXT 12345677 10 0 0 1 -
I have two tables
- Process_Master (EVENT_ID, EVENT_TYP, STATUS)
- Rel_Event( EVENT_ID, USERID, EVENT_DATE, RMKS)
They have one-to-one relationship linked by EVENT_ID.
I would like to create a named query like below joining 2 tables together.
Do I need to create any class descriptor first and how? I want this query to be available from the ADF data control so I can drag and drop this to my JSP page as a ADF table. I have no problem in working with single table. I have read thru the developer guide and try out many things like multitable info, aggregate mapping and couldn't figure out how this can be done. Please help!!!
SELECT A.EVENT_ID,B.EVENT_DATE, A.STATUS, B.RMKS
FROM PROCESS_MASTER A, REL_EVENT B
WHERE A.EVENT_ID = B.EVENT_ID
AND A.STATUS = 'P';
********/I have tried the below but fail to retrieve any rows. Please help!
Expression aid = new ExpressionBuilder(ProcEventMaster.class).get("event_id");
Expression bid = new ExpressionBuilder(RelEvent.class).get("event_id");
ReportQuery reportQuery = new ReportQuery(ProcEventMaster.class,aid.equal(bid));
reportQuery.addAttribute("a_id", aid);
reportQuery.addAttribute("b_id", bid);
reportQuery.addAttribute("eventDate",bid.get("event_date"));
reportQuery.addAttribute("remarks",bid.get("rmks"));
reportQuery.setSelectionCriteria(aid.get("status").equal("P"));
List<RelEvent> results =
(List<RelEvent>)session.executeQuery(reportQuery);session.release();
return results; -
Left join query with join of three tables
I'm trying to build a query which has me stumped. Most of the query is fairly straightforward but I've run into an issue I'm not sure how to solve.
Background:
We have actions stored in i_action.
We have the available attributes for each type of action. The available attributes for each action are described in shared_action_attribute. Each type of action may have up to three attributes or none at all.
We have the values stored for the attributes in i_attribute_value.
A written example:
We have a transfer action (action_code B4). The entry of the B4 action into i_action records the fact that the transfer occurred and the date on which it occurred. The available attributes for a transfer action are the receiving function code, the receiving unit number, and the transfer reason code. These available attribute types and their order are stored in shared_action_attribute. The actual values of the attributes for a specific transfer action are stored in i_attribute_value.
Now i_action and i_attribute_value can be directly linked through action_seq in i_action and ia_action_seq in i_attribute_value. A left join built between these two tables provides results for all actions (including actions which have no attributes) and attribute values (see query 1 below).
There are two issues. First, I only want the first two attributes. In order to specify the first two attributes, I also have to link i_attribute_value to shared_action_attribute (which is where the order is stored). I can build a simple query (without the left join) linking the three tables but then actions with no attributes would be excluded from my result set (see query 2 below).
The second issue is that I would actually like one row returned for each action with first_attribute and second_attribute as columns instead of two rows.
The final query will be used to create a materialized view.
Here are the tables and examples of what's stored in them:
TABLE i_action
Name Type
ACTION_SEQ NUMBER(10)
ACTION_DATE DATE
ACTION_CODE VARCHAR2(3)
DELETED VARCHAR2(1)
EXAMPLE ROWS
ACTION_SEQ ACTION_DATE ACTION_CODE DELETED
45765668 09-OCT-09 B2 A
45765670 09-OCT-09 BA A
45765672 09-OCT-09 B6 A
45765673 09-OCT-09 B4 A
45765674 09-OCT-09 G1 A
45765675 09-OCT-09 M3 A
TABLE i_attribute_value
Name Type
IA_ACTION_SEQ NUMBER(10)
SACTATT_SACT_CODE VARCHAR2(3)
SACTATT_SAT_TYPE VARCHAR2(3)
VALUE VARCHAR2(50)
EXAMPLE ROWS
IA_ACTION_SEQ SACTATT_SACT_CODE SACTATT_SAT_TYPE VALUE
45765668 B2 ACO 37B
45765670 BA ROA D
45765670 BA ROR P
45765672 B6 CAT C
45765673 B4 RFC E
45765673 B4 TRC P
45765673 B4 RUN 7
45765674 G1 SS 23567
45765674 G1 ASG W
TABLE shared_action_attribute
Name Type
SACT_CODE VARCHAR2(3)
SAT_TYPE VARCHAR2(3)
ORDER NUMBER(2)
TITLE VARCHAR2(60)
EXAMPLE ROWS
SACT_CODE SAT_TYPE ORDER TITLE
B2 ACO 1 Office code
BA ROR 1 Reason for reopen
BA ROA 2 Reopen authority
B6 CAT 1 Category
B4 RFC 1 Receiving function code
B4 RUN 2 Receiving unit code
B4 TRC 3 Transfer reason code
G1 SS 1 Staff sequence
G1 ASG 2 Assignment reason
QUERY 1:
This is my current query along with its results. Most of it is straightforward select but one column is populated using the last_value analytical function (thanks to you guys). The last column in the below view stores the attribute value. What I want is to replace that single column with two columns named first_attribute and second_attribute and to eliminate any other attributes.
SELECT ia.action_seq, ia.action_date, ia.action_code cod,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = 'G1'
AND iav.sactatt_sat_type = 'SS'
THEN VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
ia.serial_number, ia.action_seq),
'67089'
) staff_seq,
value
FROM i_action ia LEFT JOIN i_attribute_value iav
ON iav.ia_action_seq = ia.action_seq
WHERE ia.deleted = 'A';
ACTION_SEQ ACTION_DA COD STAFF_SEQ VALUE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 D
45765670 09-OCT-09 BA 67089 P
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E
45765673 09-OCT-09 B4 67089 P
45765673 09-OCT-09 B4 67089 7
45765674 09-OCT-09 G1 23567 23567
45765674 09-OCT-09 G1 23567 W
45765675 09-OCT-09 M3 23567
QUERY 2:
This query limits to the first two attributes but it also drops actions which have no attributes and it still creates multiple rows for each action instead of a single row with two columns for the attributes.
SELECT ia.action_seq, ia.action_date, ia.action_code cod,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = 'G1'
AND iav.sactatt_sat_type = 'SS'
THEN VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
ia.serial_number, ia.action_seq),
'67089'
) staff_seq,
value
FROM shared_action_attribute saa, ims_action ia, ims_attribute_value iav
WHERE iav.ia_action_seq = ia.action_seq
AND iav.sactatt_sact_code = saa.sact_code
AND iav.sactatt_sat_type = saa.sat_type
AND saa.display_order IN ('1','2')
AND ia.deleted = 'A';
ACTION_SEQ ACTION_DA COD VALUE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 D
45765670 09-OCT-09 BA 67089 P
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E
45765673 09-OCT-09 B4 67089 7
45765674 09-OCT-09 G1 23567 23567
45765674 09-OCT-09 G1 23567 W
I found this pretty complex to try to write out - I hope I've been clear.
Thanks so much!Ok, here's more information with a simplified question. I figured out the syntax for building my query with the three tables. My final query returns multiple rows (multiple attributes per action). Instead of multiple rows, I'd like two columns (first_attribute, and second_attribute) in a single row (I only need the first two attributes).
Here's the action table:
CREATE TABLE I_ACTION
ACTION_SEQ NUMBER(10) NOT NULL,
ACTION_DATE DATE,
ACTION_CODE VARCHAR2(3 BYTE) NOT NULL,
DELETED VARCHAR2(1 BYTE),
);With the following rows added:
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765668, '09-oct-2009', 'B2', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765670, '09-oct-2009', 'BA', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765672, '09-oct-2009', 'B6', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765673, '09-oct-2009', 'B4', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765674, '09-oct-2009', 'G1', 'A');
Insert into I_ACTION (ACTION_SEQ, ACTION_DATE, ACTION_CODE, DELETED)
Values (45765675, '09-oct-2009', 'M3', 'A');
COMMIT;The attribute table is:
CREATE TABLE I_ATTRIBUTE_VALUE
IA_ACTION_SEQ NUMBER(10) NOT NULL,
SACTATT_SACT_CODE VARCHAR2(3 BYTE) NOT NULL,
SACTATT_SAT_TYPE VARCHAR2(3 BYTE) NOT NULL,
VALUE VARCHAR2(50 BYTE),
);With the following rows:
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765668, 'B2', 'ACO', '37B');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765670, 'BA', 'ROR', 'P');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765670, 'BA', 'ROA', 'D');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765672, 'B6', 'CAT', 'C');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765673, 'B4', 'RFC', 'E');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765673, 'B4', 'RUN', '7');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765673, 'B4', 'TRC', 'P');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765674, 'G1', 'SS', '23567');
Insert into I_ATTRIBUTE_VALUE (IA_ACTION_SEQ, SACTATT_SACT_CODE, SACTATT_SAT_TYPE, VALUE)
Values (45765674, 'G1', 'ASG', 'W');
COMMIT;And finally, the shared table:
CREATE TABLE SHARED_ACTION_ATTRIBUTE
SACT_CODE VARCHAR2(3 BYTE) NOT NULL,
SAT_TYPE VARCHAR2(3 BYTE) NOT NULL,
TITLE VARCHAR2(25 BYTE) NOT NULL,
DISPLAY_ORDER NUMBER(2) NOT NULL
);With the following rows:
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B4', 'RFC', 'Y', 'Rcv. Function Code', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B6', 'CAT', 'Y', 'Category', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('G1', 'SS', 'Y', 'Staff Name', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B2', 'ACO', 'Y', '"Other" Office Code', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B4', 'RUN', 'Y', 'Receiving Unit Number', 2);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B6', 'LEP', 'N', 'LEP Issue/Sub Category', 2);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B4', 'TRC', 'Y', 'Transfer Reason Code', 3);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B6', 'NEP', 'N', 'NEP Issue', 3);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('G1', 'ASG', 'Y', 'Assignment Reason', 2);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('B2', 'MSN', 'S', 'Machine Serial Number', 3);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('BA', 'ROR', 'Y', 'Reopen Reason', 1);
Insert into SHARED_ACTION_ATTRIBUTE (SACT_CODE, SAT_TYPE, TITLE, DISPLAY_ORDER)
Values ('BA', 'ROA', 'Y', 'Reopen Authority', 2);
COMMIT;Now, this is my current query (it's changed from my first post):
SELECT ia.action_seq, ia.ici_charge_inquiry_seq, ia.action_date,
ia.serial_number, ia.reporting_office, ia.reporting_function,
ia.reporting_unit, ia.action_code, ia.machine_serial_number,
NVL
(LAST_VALUE (CASE
WHEN ia.action_code = 'G1'
THEN VALUE
WHEN ia.action_code IN ('A0', 'A1')
THEN '67089'
END IGNORE NULLS
) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
ia.serial_number, ia.action_seq),
'67089'
) staff_seq,
(CASE
WHEN display_order = '1'
THEN VALUE
END) first_attribute,
(CASE
WHEN display_order = '2'
THEN VALUE
END) second_attribute
FROM ims_action ia
LEFT JOIN ims_attribute_value iav
ON iav.ia_action_seq = ia.action_seq
LEFT JOIN shared_action_attribute
ON sactatt_sact_code = sact_code
AND sactatt_sat_type = sat_type
WHERE ia.deleted = 'A';Which gives me the following results:
ACTION_SEQ ACTION_DA ACT STAFF_SEQ FIRST_ATTRIBUTE SECOND_ATTRIBUTE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 D
45765670 09-OCT-09 BA 67089 P
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E
45765673 09-OCT-09 B4 67089 7
45765673 09-OCT-09 B4 67089
45765674 09-OCT-09 G1 23567 W
45765674 09-OCT-09 G1 23567 23567
45765675 09-OCT-09 M3 23567 The result I WANT is similar but I want the two separate attribute columns on one row as such:
ACTION_SEQ ACTION_DA ACT STAFF_SEQ FIRST_ATTRIBUTE SECOND_ATTRIBUTE
45765668 09-OCT-09 B2 67089 37B
45765670 09-OCT-09 BA 67089 P D
45765672 09-OCT-09 B6 67089 C
45765673 09-OCT-09 B4 67089 E 7
45765674 09-OCT-09 G1 23567 23567 W
45765675 09-OCT-09 M3 23567 Thanks so much! -
Hi Experts,
I have tried the below query with sub select function. could any one help me to fix this ?
SELECT T0.[ItemCode], T0.[Dscription], T1.[OnHand],
(Select distinct sum(T0.InQty) from OINM where T0.ItemCode = OINM.ItemCode and T0.DocDate = '2012/08/18' ) as 'OB Stock'
FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
WHERE T1.[OnHand] > 0 GROUP BY T0.[ItemCode], T0.[Dscription], T1.[OnHand]
thanks in advance,
Regards,
DwarakHi,
This is for your Query.
SELECT T0.[ItemCode], T0.[Dscription], T1.[OnHand],
(Select distinct sum(T0.InQty) from OINM t0 where T0.ItemCode = T0.ItemCode and T0.DocDate = '2012/08/18' ) as 'OB Stock'
FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
WHERE T1.[OnHand] > 0 GROUP BY T0.[ItemCode], T0.[Dscription], T1.[OnHand]
Regards,
Kalaiyarasan.v -
Is that important column order in a query with row_number function
Hi folks,
I am using Oracle 11g R2 on HP-UX machine.
I have 2 types of query with row_number and I think they are same but output of each of them are different. I changed only column order in query2.
Query 1 :
(SELECT
"LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
"LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
FROM (
SELECT row_number ()
OVER (
PARTITION BY "R_CON_SUBS_SIMCARD_LK".
"CONTRACT_SK"
ORDER BY
"R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
"R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
"SIRA",
"R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
"R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK"
FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
"LOOKUP_INPUT_SUBQUERY"
WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
Output of this like that :
CONTRACT_SK SIMCARD_SK
1 1
1 3
1 4
1 5
1 6
1 11
1 12
1 14
1 15
1 16
Query 2 :
(SELECT
"LOOKUP_INPUT_SUBQUERY"."CONTRACT_SK" "CONTRACT_SK",
"LOOKUP_INPUT_SUBQUERY"."SIMCARD_SK" "SIMCARD_SK"
FROM (
SELECT
"R_CON_SUBS_SIMCARD_LK"."CONTRACT_SK" "CONTRACT_SK",
"R_CON_SUBS_SIMCARD_LK"."SIMCARD_SK" "SIMCARD_SK",
row_number ()
OVER (
PARTITION BY "R_CON_SUBS_SIMCARD_LK".
"CONTRACT_SK"
ORDER BY
"R_CON_SUBS_SIMCARD_LK"."START_DATE" DESC,
"R_CON_SUBS_SIMCARD_LK"."SEQ_NUM" DESC NULLS LAST) /* EXPRESSION_3.OUTGRP1.SIRA */
"SIRA"
FROM "SRC_OZRDS"."R_CON_SUBS_SIMCARD_LK" "R_CON_SUBS_SIMCARD_LK")
"LOOKUP_INPUT_SUBQUERY"
WHERE ("LOOKUP_INPUT_SUBQUERY"."SIRA" = 1))
Output of this like that:
2 874812
7 70097256
8 18734091
9 158024
10 815397739
13 22657919
19 83177779
20 82579529
22 5829949
23 35348926
25 3865978
I expected the second output, because there are lots of contract sk but there is one contract_sk in first query result. i did not get the point. What is the problem ?user8649469 wrote:
I changed only column order in query2.So what else do you expect? If you order, for example, by last name, fist name don't you think rows will be returned in a different order (and therefore same row will have different row number) than ordering by first name, last name?
SY. -
SQL Query With analytical function
Hi
Below is the scenario which i am looking for in sql query using analytical functions
I/p
Col1
50
0
-150
-200
300
-100
-300
500
-100
O/p
Col1 col2
50 0
0 0
-150 -100
-200 -200
300 0
-100 0
-300 -100
500 400
-100 0Any help really appreciated
Thanks in advance
Edited by: unique on Aug 10, 2010 4:53 AM
Edited by: unique on Aug 10, 2010 4:55 AM
Edited by: unique on Aug 10, 2010 4:55 AMOh,In this case,There is OLAP solution ;-)
OLAP samples of my homepage http://www.geocities.jp/oraclesqlpuzzle/oracle-sql1-olap.html
with work(SK,Val) as(
select 1, 50 from dual union
select 2, 0 from dual union
select 3,-150 from dual union
select 4,-200 from dual union
select 5, 300 from dual union
select 6,-100 from dual union
select 7,-300 from dual union
select 8, 500 from dual union
select 9,-100 from dual)
select SK,Val,GID,
case when Val > 0
then greatest(0,sum(Val) over(partition by GID))
else Least(0,Val+greatest(0,sum(Val) over(partition by GID
order by SK rows between unbounded preceding
and 1 preceding)))
end as COL3
from (select SK,Val,
sum(greatest(0,sign(Val))) over(order by SK) as GID
from work)
order by SK;
SK VAL GID COL3
1 50 1 0
2 0 1 0
3 -150 1 -100
4 -200 1 -200
5 300 2 0
6 -100 2 0
7 -300 2 -100
8 500 3 400
9 -100 3 0 -
Error in update query with join
hi all,
im using oracle 10g in windows.
im not able to use this update query having join......
UPDATE
b
SET
b.is_stud = 1
FROM
boy b
INNER JOIN
relationship r
ON
b.id = r.boy_id;
thanks a lot..................887268 wrote:
hi, thanks,,,,,,,,,
create table emp ( id,name,date,empno);
create table emp_status(slno,ename,empno);
i need to update "emp.name" in "emp" table from "emp_status.ename"
where emp.empno=emp_status.empno;
i.e) for all matched "empno" from both table, update "emp.name" from "emp_status.ename"Whats the relationship between emp and emp_status tables? If there exists one to one mapping for empno in both tables, then try
update emp e
set e.name = (select es.ename
from emp_status es
where e.empno = es.empno) -
SE80 problem in ECC with custom function groups
We are in the process of upgrading from 4.64 to ECC 6 and have encountered an unusual situation.
When we bring up a custom function group in SE80, we can no longer see the custom includes in the include section. We can see all other sections. We can still use SE38 to look at an include. The automatically-generated includes are there, such as the TOP, F01 and UXX, but see none of the ones that go with the function modules we've created. When we look at the UXX include, we can see each of the function modules with the include it belongs to. These are function groups that existed in the 4.64 system; they are not new to the ECC system.
We've tried rebuilding the object list at the function group and package levels. We receive no errors and the processes work fine.
Maybe there is a setting somewhere that needs to be updated?See the solution that Srini has suggested in this thread
OA Framework & JTT Request Parameters
you need to use jtfcrmchrome.jsp to navigate between JTF and OA pages.
Thanks
Tapash -
Update of a table from a select query with aggregate functions.
Hello All,
I have problem here:
I have 2 tables A(a1, a2, a3, a4, a4....... ) and B( a1, a2, b1, b2, b3). I need to calculate the avg(a4-a3), Max(a4-a3) and Min(a4-a3) and insert it into table B. If the foreign keys a1, a2 already exist in table B, I need to do an update of the computed values into column b1, b2 and b3 respectively, for a1, a2.
Q1. Is it possible to do this with a single query ? I would prefer not to join A with B because the table A is very large. Also columns b1, b2 and b3 are non-nullable.
Q2. Also if a4 and a3 are timestamps what is the best way to find the average? A difference of timestamps yields INTERVAL DAY TO SECOND over which the avg function doesn't seem to work. The averages, max and min in my case would be less than a day and hence all I need is to get the data in the hh:mm:ss format.
As of now I'm using :
TO_CHAR(TO_DATE(ABS(MOD(TRUNC(AVG(extract(hour FROM (last_modified_date - created_date))*3600 +
extract( minute FROM (last_modified_date - created_date))*60 +
extract( second FROM (last_modified_date - created_date)))
),86400)),'sssss'),'hh24":"mi":"ss') AS avg_time,
But this is very long drawn. Something more compact and efficient would be nice.
Thanks in advance for your inputs.
Edited by: 847764 on Mar 27, 2011 5:35 PM847764 wrote:
Hi,
Thanks everyone for such fast replies. Malakshinov's example worked fine for me as far as updating the table goes. As for the timestamp computations, I'm posting additional info: Sorry, I don't understand.
If Malakshinov's example worked for updating the table, but you still have problems, does that mean you have to do something else besides update the table? If so, what?
Oracle version : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Here are the table details :
DESC Table A
Name Null Type
ID NOT NULL NUMBER
A1 NOT NULL VARCHAR2(4)
A2 NOT NULL VARCHAR2(40)
A3 NOT NULL VARCHAR2(40)
CREATED_DATE NOT NULL TIMESTAMP(6)
LAST_MODIFIED_DATE TIMESTAMP(6) DESCribing the tables can help clarify some things, but it's no substitute for posting CREATE TABLE and INSERT statements. With only a description of the table, nobody can re-create the problem or test their ideas. Please post CREATE TABLE and INSERT statements for both tables as they exist before the MERGE. If table b doen't contain any rows before the MERGE, then just say so, but you still need to post a CREATE TABLE statement for both tables, and INSERT statements for table a.
The objective is to compute the response times : avg (LAST_MODIFIED_DATE - CREATED_DATE), max (LAST_MODIFIED_DATE - CREATED_DATE) and min (LAST_MODIFIED_DATE - CREATED_DATE) grouped by A1 and A2 and store it in table B under AVG_T, MAX_T and MIN_T. Since AVG_T, MAX_T and MIN_T are only used for reporting purposes we have kept it as Varchar (though I think keeping it as timestamp would make more sense). I think a NUMBER would make more sense (the number of minutes, for example), or perhaps an INTERVAL DAY TO SECOND. If you stored a NUMBER, it would be easy to compute averages.
In table B the times are stored in the format : hh:mm:ss. We don't need milliseconds precision. If you don;'t need milliseconds, then you should use DATE instead of TIMESTAMP. The functions for manipulating DATEs are much better.
Hence I was calculating is as follows:
-- Avg Time
TO_CHAR(TO_DATE(ABS(MOD(TRUNC(AVG(extract(hour FROM (last_modified_date - created_date))*3600 +
extract( minute FROM (last_modified_date - created_date))*60 +
extract( second FROM (last_modified_date - created_date)))
),86400)),'sssss'),'hh24":"mi":"ss') AS avg_time,
--Max Time
extract (hour FROM MAX(last_modified_date - created_date))||':'||extract (minute FROM MAX(last_modified_date - created_date))||':'||TRUNC(extract (second FROM MAX(last_modified_date - created_date))) AS max_time,
--Min Time
extract (hour FROM MIN(last_modified_date - created_date))||':'||extract (minute FROM MIN(last_modified_date - created_date))||':'||TRUNC(extract (second FROM MIN(last_modified_date - created_date))) AS min_timeIs this something that has to be done before or after the MERGE?
Post the complete statement.
Is this part of a query? Where's the SELECT keyword?
Is this part of a DML operation? Where's the INSERT, or UPDATE, or MERGE keyword?
What are the exact results you want from this? Explain how you get those results.
Is the code above getting the right results? Are you just asking if there's a better way to get the same results?
You have to explain things very carefully. None of the people who want to help you are familiar with your application, or your needs.
I just noticed that my reply is horribly formatted - apologies! I'm just getting the hang of it.Whenever you post formatted text (such as query results) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
Problem in discoverer with analytic function created non-additive YTD
I have problem with discoverer desktop which show me wrong ytdact, ytdbgt figure after i rollup/pivoting
on custom folder i did in discoverer admin:
SELECT a.year, a.month, c.deptno, b.glaccount, bgt.mthbgt, bgt.ytdbgt, bgt.fullbgt, bgt.lastyr_fullbgt,
act.mthact, act.ytdact
FROM (
SELECT
a.amount mthbgt,
SUM(a.amount) OVER (PARTITION BY ...) fullbgt,
SUM(a.amount) OVER (PARTITION BY ...) ytdbgt,
LAG(SUM(a.amount),1) OVER (PARTITION BY...) lstyr_fullbgt
FROM gltrans_bgt a, gl_master b, dept c
WHERE a.glaccount=b.glaccount AND a.deptno=c.deptno GROUP BY a.year, a.month, c.deptno, b.glaccount
) bgt
FULL OUTER JOIN
SELECT a.year, a.month, c.deptno, b.glaccount,
a.amount mthact,
SUM(a.amount) OVER (PARTITION BY...) ytdact,
LAG(SUM(a.amount),1) OVER (PARTITION BY...) lstyr_ytdact
FROM gltrans_act a, gl_master b, dept c
WHERE a.glaccount=b.glaccount AND a.deptno=c.deptno
GROUP BY a.year, a.month, c.deptno, b.glaccount
) act
ON
bgt.year=act.year AND
bgt.month=bgt.month AND
bgt.deptno=act.deptno AND
bgt.glaccount=act.glaccount
In discoverer desktop, sometime i would like to remove deptno or month to see the rollup figure. But it seems discoverer tried to sum the ytd to give me wrong figure.
I know that to ask oracle rewrite the query in order to roll up the figure, one may need to create dimension and specify the hierarchy for the related .
Anyway to do on this MV so that oracle can rewrite the query for me automatically?I suspect if your FY runs not from Jan - Dec, then someone has had to come to grips with this before and has created some kind of custom FUNCTION to determine the fiscal year from the date entered. Or maybe a table that populated with the same info.
Nevertheless, if there isn't one, then you'd just change the TRUNC(SYSDATE,'YYYY') logic to your fiscal year with a direct calculation.
ie:
calculation: what_fiscal_year
CASE WHEN to_char(sysdate,'MMM') IN ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP') THEN to_char(sysdate,'YY')
WHEN to_char(sysdate,'MMM') IN ('OCT','NOV','DEC') then to_char(sysdate,'YY')-1
ELSE '99' END
Something like that - I haven't tested it so treat as pseudo-code first (ie: the last to_char may need to have a to_char(to_number(to_char instead to substract the 1 but might work - Oracle's good with powerful date functions). It should give you an idea of what I'm referring to.
So once each record has an associated FY either by a calculation such as shown or by a calculation calling your corporate FY function, you just do the same thing as described early (ie: range between FY and FY-1).
Russ -
Speed up query with analytic function
Hi
how can I speed up the query below ?
All time is in analytic function (WINDOW SORT)
Thanks for your help
11.2.0.1
Rows Row Source Operation
28987 HASH UNIQUE (cr=12677 pr=155778 pw=109730 time=25010 us cost=5502 size=3972960 card=14880)
1668196 WINDOW SORT (cr=12677 pr=155778 pw=109730 time=890411840 us cost=5502 size=3972960 card=14880)
1668196 HASH JOIN RIGHT OUTER (cr=12677 pr=0 pw=0 time=1069165 us cost=3787 size=3972960 card=14880)
30706 TABLE ACCESS FULL FLO_FML_EVENT (cr=270 pr=0 pw=0 time=7420 us cost=56 size=814158 card=30154)
194733 HASH JOIN RIGHT OUTER (cr=12407 pr=0 pw=0 time=571145 us cost=3730 size=3571200 card=14880)
613 VIEW (cr=342 pr=0 pw=0 time=489 us cost=71 size=23840 card=745)
613 HASH UNIQUE (cr=342 pr=0 pw=0 time=244 us cost=71 size=20115 card=745)
745 WINDOW SORT (cr=342 pr=0 pw=0 time=1736 us cost=71 size=20115 card=745)
745 MAT_VIEW ACCESS FULL MVECRF_CUR_QUERY (cr=342 pr=0 pw=0 time=1736 us cost=69 size=20115 card=745)
194733 HASH JOIN (cr=12065 pr=0 pw=0 time=431813 us cost=3658 size=3095040 card=14880)
43 MAT_VIEW ACCESS FULL MVECRF_VISIT_REVS (cr=3 pr=0 pw=0 time=0 us cost=2 size=946 card=43)
194733 HASH JOIN OUTER (cr=12062 pr=0 pw=0 time=292098 us cost=3656 size=2767680 card=14880)
194733 HASH JOIN OUTER (cr=10553 pr=0 pw=0 time=234394 us cost=2962 size=2574240 card=14880)
194733 HASH JOIN (cr=9999 pr=0 pw=0 time=379996 us cost=2570 size=2380800 card=14880)
30076 MAT_VIEW ACCESS FULL MVECRF_ACTIVATED_FORMS (cr=1817 pr=0 pw=0 time=28411 us cost=361 size=2000285 card=29855)
194733 HASH JOIN (cr=8182 pr=0 pw=0 time=209061 us cost=1613 size=9026301 card=97057)
628 MAT_VIEW ACCESS FULL MVECRF_STUDYVERSION_FORMS (cr=19 pr=0 pw=0 time=250 us cost=6 size=18212 card=628)
194733 MAT_VIEW ACCESS FULL MVECRF_FORMITEMS (cr=8163 pr=0 pw=0 time=80733 us cost=1606 size=12462912 card=194733)
132342 MAT_VIEW ACCESS FULL MVECRF_ITEM_SDV (cr=554 pr=0 pw=0 time=23678 us cost=112 size=1720446 card=132342)
221034 MAT_VIEW ACCESS FULL MVECRF_ITEMDATA (cr=1509 pr=0 pw=0 time=46459 us cost=299 size=2873442 card=221034)
SELECT
DISTINCT
'CL238093011' AS ETUDE,
FI.STUDYID,
FI.STUDYVERSIONID,
FI.SITEID,
FI.SUBJECTID,
FI.VISITID,
VR.VISITREFNAME,
FI.SUBJECTVISITID,
FI.FORMID,
FI.FORMINDEX,
SVF.FORMREFNAME,
SVF.FORMMNEMONIC AS FMLNOM,
EVENT_ITEM.EVENT AS EVENUM,
EVENT_ITEM.EVENT_ROW AS LIGNUM,
NULL AS CODVISEVE,
MIN(DID.MINENTEREDDATE)
OVER (
PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
AS ATTDAT1ERSAI,
MIN(IFSDV.ITEMFIRSTSDV)
OVER (
PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
AS ATTDAT1ERSDV,
MAX(IFSDV.ITEMFIRSTSDV)
OVER (
PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
AS ATTDATDERSDV,
DECODE (AF.SDVCOMPLETESTATE,
0,
'N',
1,
'Y')
AS ATTINDSDVCOP,
AF.FMINSDVCOMPLETESTATE AS ATTDAT1ERSDVCOP,
DECODE (AF.SDVPARTIALSTATE,
0,
'N',
1,
'Y')
AS ATTINDSDVPTL,
EVENT_ITEM.EVENT_RELECT AS ATTINDRVUMEDCOP,
DECODE (QUERY.NBQSTFML, NULL, 'N', 'Y') AS ATTINDQST,
DECODE (AF.MISSINGITEMSSTATE,
0,
'N',
1,
'Y')
AS ATTINDITMABS,
DECODE (AF.FROZENSTATE,
0,
'N',
1,
'Y')
AS ATTINDETACON,
AF.FMINFROZENSTATE AS ATTDAT1ERCON,
AF.FMAXFROZENSTATE AS ATTDATDERCON,
DECODE (AF.DELETEDSTATE,
0,
'N',
1,
'Y')
AS ATTINDETASPR,
EVENT_ITEM.ROW_DELETED AS ATTINDLIGSPR
FROM CL238093011.MVECRF_FORMITEMS FI,
CL238093011.MVECRF_STUDYVERSION_FORMS SVF,
CL238093011.MVECRF_ACTIVATED_FORMS AF,
CL238093011.MVECRF_ITEM_SDV IFSDV,
CL238093011.MVECRF_VISIT_REVS VR,
CL238093011.MVECRF_ITEMDATA DID,
(SELECT DISTINCT
SUBJECTID,
VISITID,
FORMID,
FORMINDEX,
COUNT (
DISTINCT QUERYID
OVER (
PARTITION BY SUBJECTID, VISITID, FORMID, FORMINDEX
NBQSTFML
FROM CL238093011.MVECRF_CUR_QUERY
WHERE QUERYSTATE IN (0, 1, 2)) QUERY,
CL238093011.FLO_FML_EVENT EVENT_ITEM
WHERE (AF.VISITDELETED IS NULL OR AF.VISITDELETED = 0)
AND AF.FORMTYPE NOT IN (4, 5, 6, 7, 8, 103)
AND (AF.DELETEDDYNAMICFORMSTATE IS NULL
OR AF.DELETEDDYNAMICFORMSTATE = 0)
AND FI.SUBJECTVISITID = AF.SUBJECTVISITID
AND FI.FORMID = AF.FORMID
AND FI.FORMREV = AF.FORMREV
AND FI.FORMINDEX = AF.FORMINDEX
AND FI.VISITID = VR.VISITID
AND FI.VISITREV = VR.VISITREV
AND FI.CONTEXTID = IFSDV.CONTEXTID(+)
AND FI.CONTEXTID = DID.CONTEXTID(+)
AND FI.SUBJECTID = QUERY.SUBJECTID(+)
AND FI.VISITID = QUERY.VISITID(+)
AND FI.FORMID = QUERY.FORMID(+)
AND FI.FORMINDEX = QUERY.FORMINDEX(+)
AND FI.STUDYVERSIONID = SVF.STUDYVERSIONID
AND FI.FORMID = SVF.FORMID
AND FI.VISITID = SVF.VISITID
AND FI.SUBJECTID = EVENT_ITEM.SUBJECTID(+)
AND FI.VISITID = EVENT_ITEM.VISITID(+)
AND FI.FORMID = EVENT_ITEM.FORMID(+)
AND FI.FORMINDEX = EVENT_ITEM.FORMINDEX(+)user12045475 wrote:
Hi
how can I speed up the query below ?
All time is in analytic function (WINDOW SORT)
Thanks for your help
11.2.0.1
Rows Row Source Operation
28987 HASH UNIQUE (cr=12677 pr=155778 pw=109730 time=25010 us cost=5502 size=3972960 card=14880)
1668196 WINDOW SORT (cr=12677 pr=155778 pw=109730 time=890411840 us cost=5502 size=3972960 card=14880)
1668196 HASH JOIN RIGHT OUTER (cr=12677 pr=0 pw=0 time=1069165 us cost=3787 size=3972960 card=14880)
30706 TABLE ACCESS FULL FLO_FML_EVENT (cr=270 pr=0 pw=0 time=7420 us cost=56 size=814158 card=30154)
194733 HASH JOIN RIGHT OUTER (cr=12407 pr=0 pw=0 time=571145 us cost=3730 size=3571200 card=14880)
613 VIEW (cr=342 pr=0 pw=0 time=489 us cost=71 size=23840 card=745)
613 HASH UNIQUE (cr=342 pr=0 pw=0 time=244 us cost=71 size=20115 card=745)
745 WINDOW SORT (cr=342 pr=0 pw=0 time=1736 us cost=71 size=20115 card=745)
745 MAT_VIEW ACCESS FULL MVECRF_CUR_QUERY (cr=342 pr=0 pw=0 time=1736 us cost=69 size=20115 card=745)
194733 HASH JOIN (cr=12065 pr=0 pw=0 time=431813 us cost=3658 size=3095040 card=14880)
43 MAT_VIEW ACCESS FULL MVECRF_VISIT_REVS (cr=3 pr=0 pw=0 time=0 us cost=2 size=946 card=43)
194733 HASH JOIN OUTER (cr=12062 pr=0 pw=0 time=292098 us cost=3656 size=2767680 card=14880)
194733 HASH JOIN OUTER (cr=10553 pr=0 pw=0 time=234394 us cost=2962 size=2574240 card=14880)
194733 HASH JOIN (cr=9999 pr=0 pw=0 time=379996 us cost=2570 size=2380800 card=14880)
30076 MAT_VIEW ACCESS FULL MVECRF_ACTIVATED_FORMS (cr=1817 pr=0 pw=0 time=28411 us cost=361 size=2000285 card=29855)
194733 HASH JOIN (cr=8182 pr=0 pw=0 time=209061 us cost=1613 size=9026301 card=97057)
628 MAT_VIEW ACCESS FULL MVECRF_STUDYVERSION_FORMS (cr=19 pr=0 pw=0 time=250 us cost=6 size=18212 card=628)
194733 MAT_VIEW ACCESS FULL MVECRF_FORMITEMS (cr=8163 pr=0 pw=0 time=80733 us cost=1606 size=12462912 card=194733)
132342 MAT_VIEW ACCESS FULL MVECRF_ITEM_SDV (cr=554 pr=0 pw=0 time=23678 us cost=112 size=1720446 card=132342)
221034 MAT_VIEW ACCESS FULL MVECRF_ITEMDATA (cr=1509 pr=0 pw=0 time=46459 us cost=299 size=2873442 card=221034)
SELECT
DISTINCT
'CL238093011' AS ETUDE,
FI.STUDYID,
FI.STUDYVERSIONID,
FI.SITEID,
FI.SUBJECTID,
FI.VISITID,
VR.VISITREFNAME,
FI.SUBJECTVISITID,
FI.FORMID,
FI.FORMINDEX,
SVF.FORMREFNAME,
SVF.FORMMNEMONIC AS FMLNOM,
EVENT_ITEM.EVENT AS EVENUM,
EVENT_ITEM.EVENT_ROW AS LIGNUM,
NULL AS CODVISEVE,
MIN(DID.MINENTEREDDATE)
OVER (
PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
AS ATTDAT1ERSAI,
MIN(IFSDV.ITEMFIRSTSDV)
OVER (
PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
AS ATTDAT1ERSDV,
MAX(IFSDV.ITEMFIRSTSDV)
OVER (
PARTITION BY FI.SUBJECTID, FI.VISITID, FI.FORMID, FI.FORMINDEX
AS ATTDATDERSDV,
DECODE (AF.SDVCOMPLETESTATE,
0,
'N',
1,
'Y')
AS ATTINDSDVCOP,
AF.FMINSDVCOMPLETESTATE AS ATTDAT1ERSDVCOP,
DECODE (AF.SDVPARTIALSTATE,
0,
'N',
1,
'Y')
AS ATTINDSDVPTL,
EVENT_ITEM.EVENT_RELECT AS ATTINDRVUMEDCOP,
DECODE (QUERY.NBQSTFML, NULL, 'N', 'Y') AS ATTINDQST,
DECODE (AF.MISSINGITEMSSTATE,
0,
'N',
1,
'Y')
AS ATTINDITMABS,
DECODE (AF.FROZENSTATE,
0,
'N',
1,
'Y')
AS ATTINDETACON,
AF.FMINFROZENSTATE AS ATTDAT1ERCON,
AF.FMAXFROZENSTATE AS ATTDATDERCON,
DECODE (AF.DELETEDSTATE,
0,
'N',
1,
'Y')
AS ATTINDETASPR,
EVENT_ITEM.ROW_DELETED AS ATTINDLIGSPR
FROM CL238093011.MVECRF_FORMITEMS FI,
CL238093011.MVECRF_STUDYVERSION_FORMS SVF,
CL238093011.MVECRF_ACTIVATED_FORMS AF,
CL238093011.MVECRF_ITEM_SDV IFSDV,
CL238093011.MVECRF_VISIT_REVS VR,
CL238093011.MVECRF_ITEMDATA DID,
(SELECT DISTINCT
SUBJECTID,
VISITID,
FORMID,
FORMINDEX,
COUNT (
DISTINCT QUERYID
OVER (
PARTITION BY SUBJECTID, VISITID, FORMID, FORMINDEX
NBQSTFML
FROM CL238093011.MVECRF_CUR_QUERY
WHERE QUERYSTATE IN (0, 1, 2)) QUERY,
CL238093011.FLO_FML_EVENT EVENT_ITEM
WHERE (AF.VISITDELETED IS NULL OR AF.VISITDELETED = 0)
AND AF.FORMTYPE NOT IN (4, 5, 6, 7, 8, 103)
AND (AF.DELETEDDYNAMICFORMSTATE IS NULL
OR AF.DELETEDDYNAMICFORMSTATE = 0)
AND FI.SUBJECTVISITID = AF.SUBJECTVISITID
AND FI.FORMID = AF.FORMID
AND FI.FORMREV = AF.FORMREV
AND FI.FORMINDEX = AF.FORMINDEX
AND FI.VISITID = VR.VISITID
AND FI.VISITREV = VR.VISITREV
AND FI.CONTEXTID = IFSDV.CONTEXTID(+)
AND FI.CONTEXTID = DID.CONTEXTID(+)
AND FI.SUBJECTID = QUERY.SUBJECTID(+)
AND FI.VISITID = QUERY.VISITID(+)
AND FI.FORMID = QUERY.FORMID(+)
AND FI.FORMINDEX = QUERY.FORMINDEX(+)
AND FI.STUDYVERSIONID = SVF.STUDYVERSIONID
AND FI.FORMID = SVF.FORMID
AND FI.VISITID = SVF.VISITID
AND FI.SUBJECTID = EVENT_ITEM.SUBJECTID(+)
AND FI.VISITID = EVENT_ITEM.VISITID(+)
AND FI.FORMID = EVENT_ITEM.FORMID(+)
AND FI.FORMINDEX = EVENT_ITEM.FORMINDEX(+)
Do you have the license for parallel query (may/may not help)? PQO can help with sorts ... -
Hi..I'm having trouble wiht my query.
I'm getting way too many rows when displayed.
I should have either 12 or 24 row...I think 12, but not sure.
What I am getting is 228 rows displayed.
This is all my code, including the select statment that dsiplays rows.
--Begin Create View Casses_Schedule(2)
Drop view classes_schedule;
Create View Classes_Schedule
AS SELECT
Class_ID,
School_year,
Semester,
Course.Course_ID,
Class_Location.Class_Room,
Class_Location.Class_Building,
Title,
Starting_time,
Day,
Duration
FROM
Class, Course,
Class_Location,
Schedule_Type_Details
WHERE
semester ='SPRING'
AND
School_Year= To_Char(To_Date('1/mar/1997'))
AND
Class.Course_ID = Course.Course_ID
AND
Class.Schedule_ID = Schedule_Type_details.Schedule_ID
AND
Class.Class_Building = Class_Location.Class_Building
ORDER BY
Course.Title, Class.Class_ID;
--Query to display view data
SELECT
SubStr(Class_ID,1,7) "Class",
SubStr(School_year,1,10) "Year",
SubStr(Semester,1,10) "Semester",
SubStr(Class_Room,1,4) "Loc",
SubStr(Class_Building,1,15) "Bldng",
SubStr(Title,1,20) "title",
SubStr(Starting_time,1,6) "STime",
SubStr(Day,1,2)"Day",
SubStr(Duration,1,3) "Period"
FROM
Classes_Schedule;
Thankyou.Suggestions:
You can use "CREATE OR REPLACE VIEW" instead of "DROP VIEW" and "CREATE VIEW", although either will work.
Preface column names with table names to avoid ambiguity.
Select from the fewest tables possible. In other words, if some columns are in multiple tables, and you can get all the columns you want from one of those tables, then don't use the others; It just overly complicates things. It looks like you can get all the columns you want from the class, course, and schedule_type_details tables, so eliminate the class_location and schedule_type tables. For example, instead of joining class.schedule_id to schedule_type.schedule_id and joining schedule_type.schedule_id to schedule_type_details.schedule_id, just join class.schedule_id to schedule_type_details.schedule_id.
Make sure you have all the join conditions that you need. For example, is the course_id unique by itself? Or, does it require a combination of course_id and department_id to be unique? You may need to add a join condition for department_id. If this is what you are missing, then this
would account for having more rows than expected.
What data type is school_year? Is it VARCHAR2 or NUMBER or DATE? You have used TO_DATE to convert the VARCHAR2 string '1/mar/1997' to a DATE, then used TO_CHAR to convert it back to VARCHAR2, which seems pointless. If school_year is a DATE, then you want to convert '1/mar/1997' to a DATE for comparison. The best way to do that is to use TO_DATE and supply a date format,
to avoid any problems with implicit conversions and conflicting date formats.
Please see suggested corrected code below:
CREATE OR REPLACE VIEW classes_schedule
AS
SELECT class.class_id,
class.school_year,
class.semester,
class.course_id,
class.class_room,
class.class_building,
course.title,
schedule_type_details.starting_time,
schedule_type_details.day,
schedule_type_details.duration
FROM class,
course,
schedule_type_details
WHERE class.course_id = course.course_id
AND class.department_id = course.department_id
AND class.schedule_id = schedule_type_details.schedule_id
AND class.semester = 'SPRING'
AND class.school_year = TO_DATE ('1/mar/1997', 'dd/mon/yyyy')
ORDER BY course.title,
class.class_id
Maybe you are looking for
-
Parse xml in inputstreamobject and decode base64
Hello I have got a http-package with content-type text/xml, from a HttpURLConnection object. From the HttpURLConnection object i get an InputStreamObject. Now i'm looking for the easiest to parse the xml, that is in the Inputstream object. The xml ju
-
Password for new modem not opening config page.
New ADSL Modem/Router from ISP.A Zyxel P-660HN-T1A_1Pv6 Only wanted the modem function as I use Time Capsule and an Airport Express to extend the signal. On bringing up the modem web page and login box for device configuration, my password is not acc
-
After placing a photo on an ibook page, I try to edit it. I highlight the picture & click on options. When I click on "edit photo" it goes to that menu, but the photo does not appear. Just black. Any ideas on why that may be? I've already made a book
-
JDK 1.4.2 for Intel Xeon 64 bit
Gurus, I am installing ECC 6.0 on Windows. I am unable to download the JDK 1.4.2* for Intel xeon processors on 64 bit running Windows Server x64 standard edition. Been to the site http://java.sun.com/j2se/1.4.2/SAPsite/download.html, to download JDK
-
How to find that 2 references are pointing to same obejct??
how to find that 2 references are pointing to same obejct?? i feel that hashCode and equals will not work as far as i understood from javadoc