Help in below query
Hi ,
SELECT wip_entity_name , pr_coc
FROM AEC.COC
WHERE WIP_ENTITY_NAME in (
'NP127408',
'NP127409',
'NP127407',
'NP127406')
Now the result I want is even if the wip_entity_name is not in the table the qry should return the wip_entity_name and pr_coc as a null along with normal result.
Thanks
PRC
Hello India :-)
Actually Toronto is the city where I live, my name is john.
If y ou have thousands of rows in an Excel spreadsheet, you are going to have to load them into the database (or at least make them accessible to the database) before you can use them for a query.
The simplest way, particularly if this is a one time shot. would be to use a formula in Excel to generate the insert statements, then copy the generated insert statements to the database server as a text file and then run it is sqlplus. Make sure that you do ALTER SESSION SET CURSOR_SHARING = FORCE before running those insert statements.
Then run my outer join query, replacing the WITH clause with your loaded table.
So, assuming you inserted the jobs into a table called excel_jobs, then the statement would be something like:
SELECT ej.wip_entity_name, coc.coc
FROM excel_jobs ej
LEFT JOIN coc ON el.wip_entity_name = coc.wip_jobs;HTH
John from Toronto
Similar Messages
-
Need Help on below Query.
Hi All,
Need Help on below Query.
Consider,
"test9" Table Data in COLUMN "Name" AS
Name
=====
'a'
'b'
'c'
'd'
'e'
I am writing a query as :
SELECT * FROM test9 WHERE Name IN ('a','b','c','d','e','f','g')
I want result set as , It should show data as -
'f'
'g'
i.e. data which does not exists in the table and which is give in in clause
Is it possible in a single query.You can put the data that is to be checked for into a table instead or an inline view, for example:
with t as
(select 'a' as c1 from dual
union all
select 'b' from dual
union all
select 'c' from dual
union all
select 'd' from dual
union all
select 'e' from dual)
select c1 from (select 'a' as c1 from dual
union all
select 'b' from dual
union all
select 'c' from dual
union all
select 'd' from dual
union all
select 'e' from dual
union all
select 'f' from dual
union all
select 'g' from dual)
minus
select c1 from t
C
f
g
2 rows selected. -
Can you help on below Query ?
Hi Experts,
Can anyone help me with Query? the query need to retrieve below info based on set of books ID.
Needed columns:
1 SOB
2 Legal Entities
3 Fixed Asset Org Name
4 Applications/Responsibilities
5 Operating Units
6 Inventory Org
7 COA
8 Assigned Responsibilities
ThanksAlthough this is not a complete query, it will give you a start
select haou.name "Name",'Legal Entity' "Type", gsb.name "Set Of Books"
from hr_all_organization_units haou,
hr_organization_information hoi,
gl_sets_of_books gsb
where haou.organization_id = hoi.organization_id
and hoi.org_information_context = 'Legal Entity Accounting'
and hoi.org_information1 = gsb.set_of_books_id
and gsb.set_of_books_id = :sob
UNION
select haou.name "Name",'Operating Unit' "Type", gsb.name "Set Of Books"
from hr_all_organization_units haou,
hr_organization_information hoi,
gl_sets_of_books gsb
where haou.organization_id = hoi.organization_id
and hoi.org_information_context = 'Operating Unit Information'
and hoi.org_information3 = gsb.set_of_books_id
and gsb.set_of_books_id = :sob
UNION
select haou.name "Name",'Inventory Org' "Type", gsb.name "Set Of Books"
from hr_all_organization_units haou,
hr_organization_information hoi,
gl_sets_of_books gsb
where haou.organization_id = hoi.organization_id
and hoi.org_information_context = 'Accounting Information'
and hoi.org_information1 = gsb.set_of_books_id
and gsb.set_of_books_id = :sob
UNION
select fifs.id_flex_structure_name "Name",'Chart Of Account' "Type", gsb.name "Set Of Books"
from fnd_id_flex_structures_vl fifs,
fnd_id_flexs fif,
gl_sets_of_books gsb
where fif.application_id = fifs.application_id
and fif.id_flex_name = 'Accounting Flexfield'
and fifs.id_flex_num = gsb.chart_of_accounts_id
and gsb.set_of_books_id = :sobOther tables which would help you are fnd_application_tl and fnd_responsibility_tl
HTH -
Can anyone help me with Query ?
Hi Experts,
Can anyone help me with Query? the query need to retrieve below info based on set of books ID.
Needed columns:
1 SOB
2 Legal Entities
3 Fixed Asset Org Name
4 Applications/Responsibilities
5 Operating Units
6 Inventory Org
7 COA
8 Assigned Responsibilities
ThanksDuplicate post -- Can you help on below Query ?
Please post only once! -
I am getting "Invalid Identifier" while running the below query
Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
select a.*, b.pog_description pog_description, b.start_date,
row_number() over(partition by b.pog_description order by b.start_date) c_rank
from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
where a.sku = c.pog_sku
and b.pog_id = c.pog_id
and b.pog_dept = c.pog_dept
and b.pog_number = c.pog_number
and b.pog_level = c.pog_level
and a.sku = 10263477
and c_rank = 1;>
Iam getting the error "Invalid Identifier, c_rank" while running the below query. Please help.
select a.*, b.pog_description pog_description, b.start_date,
row_number() over(partition by b.pog_description order by b.start_date) c_rank
from temp_codi_dept_35 a, pog_master_msi b, pog_skus_msi c
where a.sku = c.pog_sku
and b.pog_id = c.pog_id
and b.pog_dept = c.pog_dept
and b.pog_number = c.pog_number
and b.pog_level = c.pog_level
and a.sku = 10263477
and c_rank = 1;
>
You can't use 'c_rank' in the where clause because it doesn't exist; you are computing it in the SELECT clause.
Remove the last condition and wrap your query in another one to select by 'c_rank'. -
Help needed in query optimization.....
Hi
I have this below query which automatically gets generated in siebel.
Problem is when i execute this query in toad for "Nichole" it took 2 mins to return 30 records but when i execute this same query for "Adam" it returns more records than Nichole and return results in 1-2 secs. i Know executing query in toad is not a proper way but this below query will get executed in same way thru siebel application. Histogram is already created on column "Name" but of no help. Composite Index(CX_AA_EVNT_RADIO_BATCH_TIME) is there on column bot_id & timestp.
Table s_org_ext has only 5 records of "Nichole" and 10 records of "Adam".
Will including Column "Name" in Above composite index can help?
Please anybody can suggest me anything in this? whatelse i can do to tune this query?
Thanks for your help in advance
Chandan Singh
Also, don't know how better i can format this code :-(
SELECT t7.conflict_id, t7.last_upd, t7.created, t7.last_upd_by,
t7.created_by, t7.modification_num, t7.row_id, t7.last_upd,
t7.aa_acount_id, t7.aa_last_step, t7.accessory, t7.account_exists,
t7.account_number, t7.actn_cd, t7.action_counter, t7.activated_by,
t7.address, t7.address_2, t7.address_validation_status,
t4.account_name, t7.aggregated_account_id, t7.aggregated_flag,
t7.asset_id, t7.auto_delivery_type, t7.auto_make, t7.auto_model,
t7.auto_year, t7.automated_approval, t7.activation_frequency,
FROM siebel.s_prod_int t1,
siebel.s_org_ext t2,
siebel.s_asset t3,
siebel.av_account t4,
siebel.s_org_ext t5,
siebel.s_prod_int_x t6,
siebel.av_event t7
WHERE t1.row_id = t6.par_row_id(+)
AND t7.promotion_code = t1.part_num(+)
AND t7.asset_id = t3.row_id(+)
AND t3.owner_accnt_id = t5.par_row_id(+)
AND t7.id = t2.par_row_id --- S_ORG_EXT_U3
AND t7.id1 = t4.row_id(+)
AND (t2.NAME = 'Nichole')
ORDER BY t7.bot_id, t7.timestp
Below is the execution plan for above query.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=399904 Card=5609601 Bytes=4930839279)
1 0 NESTED LOOPS (OUTER) (Cost=399904 Card=5609601 Bytes=4930839279)
2 1 NESTED LOOPS (OUTER) (Cost=343808 Card=5609601 Bytes=4824256860)
3 2 NESTED LOOPS (OUTER) (Cost=231616 Card=5609601 Bytes=4740112845)
4 3 NESTED LOOPS (OUTER) (Cost=175520 Card=5609601 Bytes=4482071199)
5 4 NESTED LOOPS (OUTER) (Cost=119424 Card=5609601 Bytes=4325002371)
6 5 NESTED LOOPS (Cost=63328 Card=5609601 Bytes=4240858356)
7 6 TABLE ACCESS (BY INDEX ROWID) OF 'av_event' (Cost=6729 Card=5659910 Bytes=4126074390)
8 7 INDEX (FULL SCAN) OF 'av_event_timpstp' (NON-UNIQUE) (Cost=24559 Card=5659910)
9 6 TABLE ACCESS (BY INDEX ROWID) OF 'S_ORG_EXT' (Cost=1 Card=1 Bytes=27)
10 9 INDEX (UNIQUE SCAN) OF 'S_ORG_EXT_U3' (UNIQUE)
11 5 TABLE ACCESS (BY INDEX ROWID) OF 'S_PROD_INT' (Cost=1 Card=1 Bytes=15)
12 11 INDEX (RANGE SCAN) OF 'S_PROD_INT_M3' (NON-UNIQUE)
13 4 TABLE ACCESS (BY INDEX ROWID) OF 'av_account' (Cost=1 Card=1 Bytes=28)
14 13 INDEX (UNIQUE SCAN) OF 'av_account_P1' (UNIQUE)
15 3 TABLE ACCESS (BY INDEX ROWID) OF 'S_ASSET' (Cost=1 Card=1 Bytes=46)
16 15 INDEX (UNIQUE SCAN) OF 'S_ASSET_P1' (UNIQUE)
17 2 TABLE ACCESS (BY INDEX ROWID) OF 'S_PROD_INT_X' (Cost=1 Card=1 Bytes=15)
18 17 INDEX (RANGE SCAN) OF 'S_PROD_INT_X_U1' (UNIQUE) (Cost=1 Card=1)
19 1 TABLE ACCESS (BY INDEX ROWID) OF 'S_ORG_EXT' (Cost=1 Card=1 Bytes=19)
20 19 INDEX (UNIQUE SCAN) OF 'S_ORG_EXT_U3' (UNIQUE)
Below is the No. of records in each table.
NUM_ROWS LAST_ANALYZED TABLE_NAME BLOCKS
5,594,027.00 09/08/2006 03:03:02 av_account 92,565.00
6,659,910.00 09/22/2006 16:14:06 av_event 608,292.00
15,384,080.00 09/22/2006 15:28:04 S_ASSET 1,244,124.00
10,249,905.00 04/23/2006 23:51:44 S_ORG_EXT 2,313,814.00
1,081.00 09/22/2006 15:26:12 S_PROD_INT 129.00
602.00 09/08/2006 04:39:42 S_PROD_INT_X 10.00can you plz try this
SELECT /*+ LEADING(t2) */ t7.conflict_id, t7.last_upd, t7.created, t7.last_upd_by,
t7.created_by, t7.modification_num, t7.row_id, t7.last_upd,
t7.aa_acount_id, t7.aa_last_step, t7.accessory, t7.account_exists,
t7.account_number, t7.actn_cd, t7.action_counter, t7.activated_by,
t7.address, t7.address_2, t7.address_validation_status,
t4.account_name, t7.aggregated_account_id, t7.aggregated_flag,
t7.asset_id, t7.auto_delivery_type, t7.auto_make, t7.auto_model,
t7.auto_year, t7.automated_approval, t7.activation_frequency,
FROM siebel.s_prod_int t1,
siebel.s_org_ext t2,
siebel.s_asset t3,
siebel.av_account t4,
siebel.s_org_ext t5,
siebel.s_prod_int_x t6,
siebel.av_event t7
WHERE t1.row_id = t6.par_row_id(+)
AND t7.promotion_code = t1.part_num(+)
AND t7.asset_id = t3.row_id(+)
AND t3.owner_accnt_id = t5.par_row_id(+)
AND t7.id = t2.par_row_id --- S_ORG_EXT_U3
AND t7.id1 = t4.row_id(+)
AND (t2.NAME = 'Nichole')
ORDER BY t7.bot_id, t7.timestp -
Please help with the query creating Materialized View
Hi,
We are using the below query to create a Materialized View but it has been running since 3 hours. It is an Oracle 9i database running in HP-UX.The quey is as follows,
(SELECT
/*+ use_nl(A) parallel (A,4)*/
A.ICD_CODE AS ICD_CODE,
A.ICD_DESC AS ICD_DESC,
A.PROC_GROUP as PROC_GROUP,
B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
C.PROC_TYPE AS PROC_TYPE ,
C.I_O_IND AS I_O_IND,
C.DISC_MON AS QUARTER ,
B.PAT_KEY AS PAT_KEY ,
D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
C.PROV_ID AS PROV_ID ,
A.SPECIALTY AS SPECIALTY
FROM
EES_ICD_9_CODE A ,
EES_CLINICAL_COMPL_DATA B,
EES_CLINICAL_DATA C,
EES_CLINCL_COMPL_ICD D
WHERE A.ICD_CODE= B.ICD_CODE
AND B.ICD_CODE= C.ICD_CODE
AND B.COMPL_ICD_CODE=D.ICD_9_CD
AND B.PAT_KEY=C.PAT_KEY
AND B.COMPL_ICD_CODEB.ICD_CODE
AND C.PROC_TYPE 'L'
AND B.COMPL_GRP_TXT'Reoperations'
AND D.COMPL_TYPE_TXT'Intra-operative Misadventure'
AND C.DISC_MON>='2003101'
AND A.SPECIALTY='Colo-Rectal')
union
(SELECT
/*+ use_nl(A) parallel (A,4)*/
A.ICD_CODE AS ICD_CODE,
A.ICD_DESC AS ICD_DESC,
A.PROC_GROUP as PROC_GROUP,
B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
C.PROC_TYPE AS PROC_TYPE ,
C.I_O_IND AS I_O_IND,
C.DISC_MON AS QUARTER ,
B.PAT_KEY AS PAT_KEY ,
D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
C.PROV_ID AS PROV_ID ,
A.SPECIALTY AS SPECIALTY
FROM
EES_ICD_9_CODE A ,
EES_CLINICAL_COMPL_DATA B,
EES_CLINICAL_DATA C,
EES_CLINCL_COMPL_ICD D
WHERE A.ICD_CODE= B.ICD_CODE
AND B.ICD_CODE= C.ICD_CODE
AND B.COMPL_ICD_CODE=D.ICD_9_CD
AND B.PAT_KEY=C.PAT_KEY
AND B.COMPL_ICD_CODEB.ICD_CODE
AND C.PROC_TYPE 'L'
--AND B.COMPL_GRP_TXT'Reoperations'
AND D.COMPL_TYPE_TXT='Intra-operative Misadventure'
AND B.PROC_DAY=C.PROC_DAY
AND C.DISC_MON>='2003101'
AND A.SPECIALTY='Colo-Rectal')
union
(SELECT
/*+ use_nl(A) parallel (A,4)*/
A.ICD_CODE AS ICD_CODE,
A.ICD_DESC AS ICD_DESC,
A.PROC_GROUP as PROC_GROUP,
B.COMPL_ICD_CODE AS COMPL_ICD_CODE,
B.COMPL_GRP_TXT AS COMPL_GRP_TXT,
C.PROC_TYPE AS PROC_TYPE ,
C.I_O_IND AS I_O_IND,
C.DISC_MON AS QUARTER ,
B.PAT_KEY AS PAT_KEY ,
D.COMPL_TYPE_TXT AS COMPL_TYPE_TXT ,
C.PROV_ID AS PROV_ID ,
A.SPECIALTY AS SPECIALTY
FROM
EES_ICD_9_CODE A ,
EES_CLINICAL_COMPL_DATA B,
EES_CLINICAL_DATA C,
EES_CLINCL_COMPL_ICD D
WHERE A.ICD_CODE= B.ICD_CODE
AND B.ICD_CODE= C.ICD_CODE
AND B.COMPL_ICD_CODE=D.ICD_9_CD
AND B.PAT_KEY=C.PAT_KEY
AND B.COMPL_ICD_CODEB.ICD_CODE
AND C.PROC_TYPE 'L'
AND B.COMPL_GRP_TXT='Reoperations'
--AND D.COMPL_TYPE_TXT='Intra-operative Misadventure'
AND B.PROC_DAY>C.PROC_DAY
AND C.DISC_MON>='2003101'
AND A.SPECIALTY='Colo-Rectal')
The explain plan is as follows,
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | 46935 | 6716K| | 10648 | | | |
| 1 | SORT UNIQUE | | 46935 | 6716K| 14M| 10648 | 45,14 | P->S | QC (RAND) |
| 2 | UNION-ALL | | | | | | 45,13 | P->P | HASH |
|* 3 | HASH JOIN | | 42801 | 6102K| | 4640 | 45,13 | PCWP | |
|* 4 | TABLE ACCESS FULL | EES_CLINCL_COMPL_ICD | 875 | 18375 | | 2 | 45,02
|* 5 | HASH JOIN | | 41552 | 5072K| 14M| 4638 | 45,13 | PCWP | |
|* 6 | TABLE ACCESS FULL | EES_CLINICAL_DATA | 1430K| 40M| | 2855 | 45,03
|* 7 | HASH JOIN | | 628K| 56M| | 494 | 45,10 | P->P | HASH |
|* 8 | TABLE ACCESS FULL | EES_ICD_9_CODE | 37 | 2183 | | 1 | 45,08
|* 9 | TABLE ACCESS BY INDEX ROWID | EES_CLINICAL_COMPL_DATA | 2090K| 71M| | 49
| 10 | BITMAP CONVERSION TO ROWIDS | | | | | | |
|* 11 | BITMAP INDEX FULL SCAN | INX_COMPL_GRP | | | | | |
|* 12 | TABLE ACCESS BY INDEX ROWID | EES_CLINICAL_DATA | 1 | 33 | | 1
| 13 | NESTED LOOPS | | 1327 | 196K| | 947 | 45,13 | PCWP | |
|* 14 | HASH JOIN | | 60205 | 6996K| | 495 | 45,13 | PCWP | |
| 15 | TABLE ACCESS BY INDEX ROWID | EES_CLINCL_COMPL_ICD | 36 | 756 | |
|* 16 | INDEX RANGE SCAN | COMPL_TYPE_TXT_3 | 1 | | | 1 |
|* 17 | HASH JOIN | | 1420K| 132M| | 494 | 45,13 | PCWP | |
|* 18 | TABLE ACCESS FULL | EES_ICD_9_CODE | 37 | 2183 | | 1 | 45,11
|* 19 | TABLE ACCESS BY INDEX ROWID | EES_CLINICAL_COMPL_DATA | 4722K| 175M| | 49
| 20 | BITMAP CONVERSION TO ROWIDS| | | | | | | |
| 21 | BITMAP INDEX FULL SCAN | INX_COMPL_GRP | | | | | |
|* 22 | INDEX RANGE SCAN | EES_CLINICAL_DATA_IND1 | 1 | | | 2 | 45,13
|* 23 | HASH JOIN | | 2807 | 416K| | 4695 | 45,13 | PCWP | |
| 24 | TABLE ACCESS FULL | EES_CLINCL_COMPL_ICD | 911 | 19131 | | 2 | 45,06
|* 25 | HASH JOIN | | 2617 | 334K| 15M| 4693 | 45,13 | PCWP | |
|* 26 | TABLE ACCESS FULL | EES_CLINICAL_DATA | 1430K| 45M| | 2855 | 45,07
|* 27 | HASH JOIN | | 791K| 74M| | 305 | 45,12 | P->P | HASH |
|* 28 | TABLE ACCESS FULL | EES_ICD_9_CODE | 37 | 2183 | | 1 | 45,09
|* 29 | TABLE ACCESS BY INDEX ROWID | EES_CLINICAL_COMPL_DATA | 2632K| 97M| | 30
| 30 | BITMAP CONVERSION TO ROWIDS | | | | | | |
|* 31 | BITMAP INDEX SINGLE VALUE | INX_COMPL_GRP | | | | | |
Predicate Information (identified by operation id):
3 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
4 - filter("D"."COMPL_TYPE_TXT"'Intra-operative Misadventure')
5 - access("B"."ICD_CODE"="C"."ICD_CODE" AND "B"."PAT_KEY"="C"."PAT_KEY")
6 - filter("C"."PROC_TYPE"'L' AND "C"."DISC_MON">=2003101)
7 - access("A"."ICD_CODE"="B"."ICD_CODE")
8 - filter("A"."SPECIALTY"='Colo-Rectal')
9 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
11 - filter("B"."COMPL_GRP_TXT"'Reoperations')
12 - filter("B"."ICD_CODE"="C"."ICD_CODE" AND "C"."PROC_TYPE"'L' AND "B"."PROC_DAY"="C"."PROC_DA
14 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
16 - access("D"."COMPL_TYPE_TXT"='Intra-operative Misadventure')
17 - access("A"."ICD_CODE"="B"."ICD_CODE")
18 - filter("A"."SPECIALTY"='Colo-Rectal')
19 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
22 - access("B"."PAT_KEY"="C"."PAT_KEY")
23 - access("B"."COMPL_ICD_CODE"="D"."ICD_9_CD")
25 - access("B"."ICD_CODE"="C"."ICD_CODE" AND "B"."PAT_KEY"="C"."PAT_KEY")
filter("B"."PROC_DAY">"C"."PROC_DAY")
26 - filter("C"."PROC_TYPE"'L' AND "C"."DISC_MON">=2003101)
27 - access("A"."ICD_CODE"="B"."ICD_CODE")
28 - filter("A"."SPECIALTY"='Colo-Rectal')
29 - filter("B"."COMPL_ICD_CODE""B"."ICD_CODE")
31 - access("B"."COMPL_GRP_TXT"='Reoperations')
Note: cpu costing is offPlease help.Try removing the hints.
Is 47,000 a reasonable estimate of how many rows you expect in the results?
See these posts for other information that you should supply.
HOW TO: Post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
When your query takes too long
When your query takes too long ... -
How to use outer join condition in my below query.
Hi All,
How to use outer join condition in my below query.
In the table APPS_JP.GEDIS_OFFER_HEADER goh I have more records
in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
including other conditions.
I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
[code]SELECT GOH.ORIG_SYSTEM,
gsp.USER_NAME,
goh.ORDER_NO,
goh.OMEGA_ORDER_NUMBER,
goh.ORDER_TYPE,
gc.CUSTOMER_ID,
gc.OMEGA_CUSTOMER_NUMBER,
CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
AS COMPANY_NAME,
goh.ORDER_STATUS,
goh.TOTAL_SELLING_PRICE,
goh.TOTAL_MARGIN,
ga1.ADDRESS1
|| ','
|| ga1.ADDRESS2
|| ','
|| ga1.ADDRESS3
|| ','
|| ga1.POSTAL_CODE
|| ','
|| ga1.CITY
AS SHIPPING_ADDRESS,
ga2.ADDRESS1
|| ','
|| ga2.ADDRESS2
|| ','
|| ga2.ADDRESS3
|| ','
|| ga2.POSTAL_CODE
|| ','
|| ga2.CITY
AS BILLING_ADDRESS,
ga.ADDRESS_ID,
gol.DESCRIPTION,
APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
AS OFFER_DATE,
gc.LEVEL_8,
goh.NO_OF_BUILDS,
gob.SFDC_ID,
goh.PURCHASE_ORDER_NO AS PO,
gc1.CUSTOMER_NAME AS END_USAGE,
gol.LOB,
goh.TOTAL_MARGIN_PCT,
goh.TOTAL_DISCOUNT,
goh.TOTAL_DISCOUNT_PCT
FROM APPS_JP.GEDIS_OFFER_HEADER goh,
APPS_JP.GEDIS_ORDER_BUILDS gob,
APPS_JP.GEDIS_ORDER_LINES gol,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
APPS_JP.GEDIS_CUSTOMER gc,
APPS_JP.GEDIS_CUSTOMER gc1,
APPS_JP.GEDIS_CONTACT gct,
APPS_JP.GEDIS_ADDRESS ga,
APPS_JP.GEDIS_ADDRESS_NORM ga1,
APPS_JP.GEDIS_ADDRESS_NORM ga2,
(SELECT DISTINCT SALESPERSON_ID, USER_NAME
FROM APPS_JP.GEDIS_SALESPERSON
WHERE SALESPERSON_ID IN
(SELECT TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
FROM TABLE (APPS_GLOBAL.SplitString ('337309'))))
gsp
WHERE goh.ORDER_NO <> 0
AND goh.OFFER_NO <> 0
AND goh.OFFER_NO=gol.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
AND goh.OFFER_NO=gob.OFFER_NO
AND gob.BUILD_NO = 1
AND goh.OFFER_NO = gorc.OFFER_NO
AND gct.CONTACT_ID = gorc.CONTACT_ID
AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
AND ga.PRIMARY = 'Y'
AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
AND goh.OFFER_NO = ship.OFFER_NO
AND ship.RELATION_TYPE = 'SHIP'
AND ga1.ADDRESS_ID = ship.ADDRESS_ID
AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
AND goh.OFFER_NO = bill.OFFER_NO
AND bill.RELATION_TYPE = 'BILL'
AND ga2.ADDRESS_ID = bill.ADDRESS_ID
AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
SYSDATE - 30
AND APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
AND gorc.RELATION_TYPE = 'BASE'
AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
AND gc.SALES_CHANNEL = 'SMB'
AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
ORDER BY goh.OFFER_NO;[/code]
Please help me how to use this outer join condition.
Thanks in advance.Hi,
If you want all the rows from goh, then you don't want any conditions like goh.OFFER_NO <> 0.
Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
FROM APPS_JP.GEDIS_OFFER_HEADER goh
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_BUILDS gob ON gob.OFFER_NO = goh.OFFER_NO
AND gob.BUILD_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_LINES gol ON gol.OFFER_NO = goh.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
gorc ...
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, do you really need all those tables to show what the problem is? Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
Explain, using specific examples, how you get those results from that data.Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ https://forums.oracle.com/message/9362002#9362002 -
Hi,
I need a help in writing an SQL query . I am actually confused how to write a query. Below is the scenario.
CREATE TABLE demand_tmp
( item_id NUMBER,
org_id NUMBER,
order_line_id NUMBER,
quantity NUMBER,
order_type NUMBER
CREATE TABLE order_tmp
( item_id NUMBER,
org_id NUMBER,
order_line_id NUMBER,
open_flag VARCHAR2(10)
INSERT INTO demand_tmp
SELECT 12438,82,821,100,30 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,849,350,30 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,NULL,150,29 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,0,50,-1 FROM dual;
INSERT INTO order_tmp
SELECT 12438,82,821,'Y' FROM dual;
INSERT INTO order_tmp
SELECT 12438,82,849,'N' FROM dual;
Demand_tmp:
Item_id org_id order_line_id quantity order_type
12438 82 821 100 30
12438 82 849 350 30
12438 82 NULL 150 29
12438 82 0 50 -1
Order_tmp :
Item_id org_id order_line_id open_flag
12438 82 821 Y
12438 82 849 N I need to fetch the records from demand_tmp table whose order_line_id is present in order_tmp and having open_flag as 'Y' or if order_type in demand_tmp table is 29.
The below query will give the records whose order line id is present in order_tmp. But, If i need records which are having order_type=29 the below query wont return any records as order_line_id is NULL. If I place outer join I will get other records also (In this example order_type -1 records) . Please help me how can we write a query for this. Expected o/p is below.
Query :
Select item_id,org_id,order_line_id,quantity,order_type,open_flag
from demand_tmp dt , order_tmp ot
where dt.order_line_id = ot.order_line_id
AND dt.item_id=ot.item_id
AND dt.org_id = ot.org_id
AND ot.open_flag = 'Y';
Expected Output :
item_id org_id order_line_id quantity order_type open_flag
12438 82 821 100 30 Y
12438 82 NULL 150 29 NULL Thanks in advance,
Rakesh
Edited by: Venkat Rakesh on Oct 7, 2012 6:32 PM
Edited by: Venkat Rakesh on Oct 7, 2012 8:39 PMHi Rakesh,
the query is not working as you would like ( but IS working as expected ) since your trying to compare null to another value.
Comparing null always results in FALSE, also if you compare null to null. This is because null means undefined.
select 1 from dual where null=null results in no data found.
I would suggest using a non natural key to join the tables.
For example include a column ID in the master table which is filled with a sequence and include that field as a foreign key in the detail table.
This way you can easily join master and detail on ID = ID, and you don't have to worry about null values in this column since it's always filled with data.
Regards,
Bas
btw, using the INNER JOIN and OUTER JOIN syntax in your SQL makes it better readable, since you're separating join conditions from the where clause, just a tip ;) -
Hello all,
Total newbie to this pl/sql stuff. So, deseperately need help in my query.
BOOKING_ID BOOKING_STATUS BOOKING_DATE BOOKING_TIME BOOKING_DATE_TIME
1234567 CANCELLED 20090301 37252 5/1/2010 10:20
1234567 CANCELLED 20090301 44229 5/1/2010 12:17
1234567 BOOKED 20090301 39462 5/1/2010 10:57
1234567 CANCELLED 20090301 43549 5/1/2010 12:05
9671111 BOOKED 20090301 68124 5/1/2010 12:57
9671111 CANCELLED 20090301 45001 5/1/2010 12:05
How do I write my query such that I would get the following results:
BOOKING_ID BOOKING_STATUS BOOKING_DATE BOOKING_TIME BOOKING_DATE_TIME
9671111 BOOKED 20090301 68124 2/4/2010 12:17
Basically, I am looking at the latest BOOKING_TIME and making sure the BOOKING_STATUS=BOOKED, if not, don't even bother bring back the result. Hence, you see that BOOKING_ID=1234567 is not required since at the latest BOOKING_TIME=44229, the BOOKING_STATUS=CANCELLED.
Any help is greatly appreciated.
Thank you in advance for your help.
Stanley HoHi, Stanley,
Welcome to the forum!
Whenever you have a question, please post your sample data in a form that people can actually use. CREATE TABLE and INSERT statements are perfect.
For example:
CREATE TABLE booking
( booking_id NUMBER (8)
, booking_status VARCHAR2 (10)
, booking_date_time DATE
INSERT INTO booking (booking_id, booking_status, booking_date_time)
VALUES (1234567, 'CANCELLED', TO_DATE ('5/1/2010 10:20', 'MM/DD/YYYY HH24:MI'));
INSERT INTO booking (booking_id, booking_status, booking_date_time)
VALUES (1234567, 'CANCELLED', TO_DATE ('5/1/2010 12:17', 'MM/DD/YYYY HH24:MI'));
INSERT INTO booking (booking_id, booking_status, booking_date_time)
VALUES (1234567, 'BOOKED', TO_DATE ('5/1/2010 10:57', 'MM/DD/YYYY HH24:MI'));
INSERT INTO booking (booking_id, booking_status, booking_date_time)
VALUES (1234567, 'CANCELLED', TO_DATE ('5/1/2010 12:05', 'MM/DD/YYYY HH24:MI'));
INSERT INTO booking (booking_id, booking_status, booking_date_time)
VALUES (9671111, 'BOOKED', TO_DATE ('5/1/2010 12:57', 'MM/DD/YYYY HH24:MI'));
INSERT INTO booking (booking_id, booking_status, booking_date_time)
VALUES (9671111, 'CANCELLED', TO_DATE ('5/1/2010 12:05', 'MM/DD/YYYY HH24:MI'));What you want is called a Top-N Query .
Here's one way to do it:
WITH got_rnum AS
SELECT booking.*
, ROW_NUMBER () OVER ( PARTITION BY booking_id
ORDER BY booking_date_time DESC
) AS rnum
FROM booking
SELECT booking_id
, booking_status
, TO_CHAR (booking_date_time, 'YYYYMMDD') AS booking_date
, TO_CHAR (booking_date_time, 'SSSSS') AS booking_time
, TO_CHAR (booking_date_time, 'MM/DD/YYYY HH24:MI') AS booking_date_time
FROM got_rnum
WHERE rnum = 1
AND booking_status = 'BOOKED'
;Notice that you don't need PL/SQL to do this; plain old SQL is good enough.
Of course, if you're using PL/SQL for other reasons, you can use a query like this within PL/SQL.
Dates (including time of day) should always be stored in DATE columns.
If you have a DATE column, like booking_date_time, then there's no need for redundant date and time columns.
You can always display just the year-month-day, or just the time, in any format, as I did above.
The output from the query above, with the data above, is:
BOOKING_ID BOOKING_ST BOOKING_ BOOKI BOOKING_DATE_TIM
9671111 BOOKED 20100501 46620 05/01/2010 12:57I realize the booking_date and booking_time columns aren't quite what you posted. If they are not derivable from booking_date_time, then you probably do need separate columns for them, and those columns can easily be added to the query above.
Edited by: Frank Kulash on Feb 5, 2010 4:41 PM
KEEP (DENSE_RANK ...) , like Max used below, is a great tool to have in your kit. The problem with it is that you have to repeat a lot of stuff for every column, so the more columns you have in your output, the more tedious it gets. ROW_NUMBER sclaes much better, and is adaptable to more situations. I suggest you master ROW_NUMBER first, and look into KEEP (DENSE_RANK ...) later. -
Hi ,
Below query is taking more time (4mins) for 41 rows returning and there is no full table scan .Can some one help to rewrite the query.
SELECT
esma.candidate AS candidate_additional_sample,
ccr.raw_mark,
ccr.split_session_year AS year,
ccr.split_session_month AS month,
ccr.paper_code,
ccr.assessment_school AS school_code,
get_cand_session_number(ccr.split_session_year,ccr.split_session_month,ccr.candidate) AS candidate_session_number,
ccr.candidate AS candidate_code,
c.firstname AS candidate_firstname,
c.lastname AS candidate_lastname,
ema.moderator_code,
ema.examiner_code,
csr.self_taught
FROM
ibis.candidate_component_reg ccr
INNER JOIN ibis.candidate_examiner_allocation cea
ON ccr.split_session_year= cea.year
AND ccr.split_session_month=cea.month
AND ccr.assessment_school=cea.assessment_school
AND ccr.paper_code= cea.paper_code
AND ccr.candidate = cea.candidate
INNER JOIN ibis.examination_paper ep
ON ccr.split_session_year= ep.year
AND ccr.split_session_month=ep.month
AND ccr.paper_code=ep.paper_code
INNER JOIN ibis.examiner_moderator_allocation ema
ON ema.year =cea.year
AND ema.month =cea.month
AND ema.no_lang_code=ep.no_lang_code
AND ema.examiner_code=cea.examiner_code
AND ema.year =ccr.split_session_year
AND ema.month =ccr.split_session_month
INNER JOIN ibis.candidate_subject_registration csr
ON ccr.split_session_year=csr.year
AND ccr.split_session_month=csr.month
AND ccr.main_school=csr.main_school
AND ccr.candidate=csr.candidate
AND ccr.subject=csr.subject
AND ccr.subject_option=csr.subject_option
AND ccr.lvl=csr.lvl
AND ccr.language=csr.language
INNER JOIN ibis.candidate c
ON ccr.candidate=c.candidate
LEFT OUTER JOIN ibis.exam_sample_mark_additional esma
ON ccr.split_session_year = esma.year
AND ccr.split_session_month = esma.month
AND ep.no_lang_code = esma.nolang_code
AND ccr.candidate = esma.candidate
WHERE
ccr.split_session_year=:v_year
AND ccr.split_session_month=:v_month
AND ccr.subject=:v_subject
AND ccr.subject_option=nvl(:v_subject_option,ccr.subject_option)
AND ccr.language=nvl(:v_language, ccr.language)
AND ccr.component=:v_component
AND ccr.lvl=:v_lvl
AND ccr.raw_mark IS NOT NULL
AND cea.examiner_code = :v_examiner_code
AND ((ccr.sampled='Y'
AND csr.self_taught='N'
AND EXISTS (SELECT 1 FROM ibis.subject_component sc
WHERE sc.assessment_method_id = 11
AND sc.assessment_type='INTERNAL'
AND ccr.split_session_year=sc.year
AND ccr.split_session_month=sc.month
AND ccr.paper_code=sc.paper_code
AND ccr.subject=sc.subject
AND ccr.subject_option=sc.subject_option
AND ccr.lvl=sc.lvl
AND ccr.language=sc.language
AND ccr.component=sc.component)
AND NOT EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
WHERE ccr.split_session_year = cpt.year
AND ccr.split_session_month = cpt.month
AND ccr.subject = cpt.subject
AND ccr.subject_option = cpt.subject_option
AND ccr.component = cpt.component
AND cpt.combined = 'Y')
AND NOT EXISTS (SELECT 1 FROM ibis.school_sample_mark ssm
WHERE ssm.year= ccr.split_session_year
AND ssm.month = ccr.split_session_month
AND ssm.paper_code = ccr.paper_code
AND ssm.candidate =ccr.candidate
AND ssm.examiner_sample = 'Y'))
OR (ccr.sampled='N'
AND csr.self_taught='Y'
AND EXISTS (SELECT 1 FROM ibis.subject_component sc
WHERE sc.assessment_method_id = 11
AND ccr.split_session_year=sc.year
AND ccr.split_session_month=sc.month
AND ccr.paper_code=sc.paper_code
AND ccr.subject=sc.subject
AND ccr.subject_option=sc.subject_option
AND ccr.lvl=sc.lvl
AND ccr.language=sc.language
AND ccr.component=sc.component)
AND NOT EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
WHERE ccr.split_session_year = cpt.year
AND ccr.split_session_month = cpt.month
AND ccr.subject = cpt.subject
AND ccr.subject_option = cpt.subject_option
AND ccr.component = cpt.component
AND cpt.combined = 'Y'))
OR (ccr.sampled='N'
AND EXISTS (SELECT 1 FROM ibis.subject_component sc
WHERE sc.assessment_method_id = 11
AND ccr.split_session_year=sc.year
AND ccr.split_session_month=sc.month
AND ccr.paper_code=sc.paper_code
AND ccr.subject=sc.subject
AND ccr.subject_option=sc.subject_option
AND ccr.lvl=sc.lvl
AND ccr.language=sc.language
AND ccr.component=sc.component)
AND EXISTS (SELECT 1 FROM ibis.cw_portfolio_template cpt
WHERE ccr.split_session_year = cpt.year
AND ccr.split_session_month = cpt.month
AND ccr.subject = cpt.subject
AND ccr.subject_option = cpt.subject_option
AND ccr.component = cpt.component
AND cpt.combined = 'Y')));
explain plan
line 1: SQLPLUS Command Skipped: set linesize 130
line 2: SQLPLUS Command Skipped: set pagesize 0
PLAN_TABLE_OUTPUT
Plan hash value: 2594643366
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2 | 1036 | 34 (3)| 00:00:01 |
|* 1 | FILTER | | | | | |
|* 2 | HASH JOIN OUTER | | 2 | 1036 | 34 (3)| 00:00:01 |
| 3 | VIEW | | 2 | 974 | 32 (0)| 00:00:01 |
| 4 | CONCATENATION | | | | | |
|* 5 | FILTER | | | | | |
|* 6 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_SUBJECT_REGISTRATION | 1 | 58 | 3 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 1 | 485 | 16 (0)| 00:00:01 |
| 8 | NESTED LOOPS | | 1 | 427 | 13 (0)| 00:00:01 |
| 9 | NESTED LOOPS | | 1 | 357 | 11 (0)| 00:00:01 |
| 10 | NESTED LOOPS | | 1 | 129 | 8 (0)| 00:00:01 |
| 11 | NESTED LOOPS | | 1 | 80 | 5 (0)| 00:00:01 |
|* 12 | INDEX RANGE SCAN | PK_EXAMINER_MODERATOR_ALLOC | 1 | 39 | 3 (0)| 00:00:01 |
|* 13 | INDEX RANGE SCAN | RFL_EP1 | 1 | 41 | 2 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID| CANDIDATE_EXAMINER_ALLOCATION | 1 | 49 | 3 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | CANDIDATE_ALLOCATION_EXAMINER | 1 | | 2 (0)| 00:00:01 |
|* 16 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG | 1 | 228 | 3 (0)| 00:00:01 |
|* 17 | INDEX RANGE SCAN | SPLIT_SESSION_CANDIDATE | 1 | | 2 (0)| 00:00:01 |
| 18 | TABLE ACCESS BY INDEX ROWID | CANDIDATE | 1 | 70 | 2 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | CANDIDATE_PK | 1 | | 1 (0)| 00:00:01 |
|* 20 | INDEX RANGE SCAN | Y_M_CAND_SUBJ_LVL_OPTION | 1 | | 2 (0)| 00:00:01 |
|* 21 | FILTER | | | | | |
|* 22 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_SUBJECT_REGISTRATION | 1 | 58 | 3 (0)| 00:00:01 |
| 23 | NESTED LOOPS | | 1 | 485 | 16 (0)| 00:00:01 |
| 24 | NESTED LOOPS | | 1 | 427 | 13 (0)| 00:00:01 |
| 25 | NESTED LOOPS | | 1 | 357 | 11 (0)| 00:00:01 |
| 26 | NESTED LOOPS | | 1 | 129 | 8 (0)| 00:00:01 |
| 27 | NESTED LOOPS | | 1 | 80 | 5 (0)| 00:00:01 |
|* 28 | INDEX RANGE SCAN | PK_EXAMINER_MODERATOR_ALLOC | 1 | 39 | 3 (0)| 00:00:01 |
|* 29 | INDEX RANGE SCAN | RFL_EP1 | 1 | 41 | 2 (0)| 00:00:01 |
| 30 | TABLE ACCESS BY INDEX ROWID| CANDIDATE_EXAMINER_ALLOCATION | 1 | 49 | 3 (0)| 00:00:01 |
|* 31 | INDEX RANGE SCAN | CANDIDATE_ALLOCATION_EXAMINER | 1 | | 2 (0)| 00:00:01 |
|* 32 | TABLE ACCESS BY INDEX ROWID | CANDIDATE_COMPONENT_REG | 1 | 228 | 3 (0)| 00:00:01 |
|* 33 | INDEX RANGE SCAN | SPLIT_SESSION_CANDIDATE | 1 | | 2 (0)| 00:00:01 |
| 34 | TABLE ACCESS BY INDEX ROWID | CANDIDATE | 1 | 70 | 2 (0)| 00:00:01 |
|* 35 | INDEX UNIQUE SCAN | CANDIDATE_PK | 1 | | 1 (0)| 00:00:01 |
|* 36 | INDEX RANGE SCAN | Y_M_CAND_SUBJ_LVL_OPTION | 1 | | 2 (0)| 00:00:01 |
|* 37 | INDEX RANGE SCAN | EXAM_SAMP_MARK_ADD_IOT_PK | 36 | 1116 | 1 (0)| 00:00:01 |
|* 38 | TABLE ACCESS BY INDEX ROWID | CW_PORTFOLIO_TEMPLATE | 1 | 46 | 4 (0)| 00:00:01 |
|* 39 | INDEX RANGE SCAN | YEAR_MON_PORTFOLIO_TEMPLATE | 1 | | 3 (0)| 00:00:01 |
|* 40 | TABLE ACCESS BY INDEX ROWID | SCHOOL_SAMPLE_MARK | 1 | 34 | 4 (0)| 00:00:01 |
|* 41 | INDEX RANGE SCAN | CAND_PAPER_YEAR_MONTH | 1 | | 3 (0)| 00:00:01 |
|* 42 | TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT | 1 | 96 | 4 (0)| 00:00:01 |
|* 43 | INDEX RANGE SCAN | SUBJECT_COMPONENT_PK | 1 | | 3 (0)| 00:00:01 |
|* 44 | TABLE ACCESS BY INDEX ROWID | CW_PORTFOLIO_TEMPLATE | 1 | 46 | 4 (0)| 00:00:01 |
|* 45 | INDEX RANGE SCAN | YEAR_MON_PORTFOLIO_TEMPLATE | 1 | | 3 (0)| 00:00:01 |
|* 46 | TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT | 1 | 87 | 4 (0)| 00:00:01 |
|* 47 | INDEX RANGE SCAN | SUBJECT_COMPONENT_PK | 1 | | 3 (0)| 00:00:01 |
|* 48 | TABLE ACCESS BY INDEX ROWID | SUBJECT_COMPONENT | 1 | 87 | 4 (0)| 00:00:01 |
|* 49 | INDEX RANGE SCAN | SUBJECT_COMPONENT_PK | 1 | | 3 (0)| 00:00:01 |
|* 50 | TABLE ACCESS BY INDEX ROWID | CW_PORTFOLIO_TEMPLATE | 1 | 46 | 4 (0)| 00:00:01 |
|* 51 | INDEX RANGE SCAN | YEAR_MON_PORTFOLIO_TEMPLATE | 1 | | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter("from$_subquery$_011"."SAMPLED"='Y' AND "from$_subquery$_011"."SELF_TAUGHT"='N' AND NOT EXISTS
(SELECT /*+ */ 0 FROM "IBIS"."CW_PORTFOLIO_TEMPLATE" "CPT" WHERE "CPT"."COMPONENT"=:B1 AND
"CPT"."SUBJECT_OPTION"=:B2 AND "CPT"."SUBJECT"=:B3 AND "CPT"."MONTH"=:B4 AND "CPT"."YEAR"=:B5 AND
"CPT"."COMBINED"='Y') AND NOT EXISTS (SELECT /*+ */ 0 FROM "IBIS"."SCHOOL_SAMPLE_MARK" "SSM" WHERE
"SSM"."MONTH"=:B6 AND "SSM"."YEAR"=:B7 AND "SSM"."PAPER_CODE"=:B8 AND "SSM"."CANDIDATE"=:B9 AND
"SSM"."EXAMINER_SAMPLE"='Y') AND EXISTS (SELECT /*+ */ 0 FROM "IBIS"."SUBJECT_COMPONENT" "SC" WHERE
"SC"."COMPONENT"=:B10 AND "SC"."SUBJECT_OPTION"=:B11 AND "SC"."LANGUAGE"=:B12 AND "SC"."LVL"=:B13 AND
"SC"."SUBJECT"=:B14 AND "SC"."MONTH"=:B15 AND "SC"."YEAR"=:B16 AND "SC"."PAPER_CODE"=:B17 AND
"SC"."ASSESSMENT_METHOD_ID"=11 AND "SC"."ASSESSMENT_TYPE"='INTERNAL') OR "from$_subquery$_011"."SAMPLED"='N'
AND "from$_subquery$_011"."SELF_TAUGHT"='Y' AND NOT EXISTS (SELECT /*+ */ 0 FROM
"IBIS"."CW_PORTFOLIO_TEMPLATE" "CPT" WHERE "CPT"."COMPONENT"=:B18 AND "CPT"."SUBJECT_OPTION"=:B19 AND
"CPT"."SUBJECT"=:B20 AND "CPT"."MONTH"=:B21 AND "CPT"."YEAR"=:B22 AND "CPT"."COMBINED"='Y') AND EXISTS (SELECT
/*+ */ 0 FROM "IBIS"."SUBJECT_COMPONENT" "SC" WHERE "SC"."COMPONENT"=:B23 AND "SC"."SUBJECT_OPTION"=:B24 ANDEdited byCan you please post the following scripts:
1. Tables structure (with all indexes & constraints)
2. Tables data
3. SQL trace file
possibly everything that one can need to regenerate the scenario on his own DB...
OR
spend some time with Oracle Docs on Performance Tuning and then resolve it yourself.
Regards,
Ankit Rathi
http://theoraclelog.blogspot.in -
Hi,
I am using SQL Server 2008 Enterprise edition 64 bit on Windows serer 2008 enterprise edition 64 bit.
The below query works fine. I am trying to rewrite the code without using the sub query. In the end i should get the same results for both the query which we are going to rewrite and the below mentioned query.
Can any help me please.
SELECT
t1.DOCUMENT_NO,
RTRIM(CAST(t1."ENVIRONMENT_CD" AS VARCHAR(5))) + '*' + RTRIM(CAST(t1."ORDER_NO" AS VARCHAR(25)))
+
CASE WHEN (SELECT COUNT(DISTINCT S1.TEST_REPORTING_MATERIAL_SID)
FROM dbo.TBLTEST S1 ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
WHERE S1.TEST_REPORTING_MATERIAL_SID > 0
AND S1.COMPANY_CD = T1.COMPANY_CD AND S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
AND S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
AND S1.ORDER_NO = T1.ORDER_NO) > 1 THEN
RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS VARCHAR(10)))
ELSE
END as sum_key,
t1.SALES_ANALYSIS_CD
FROM
dbo.TBLTEST_ALL T1
WHERE
t1.TIME_SID >= 20001001 ;
I tried to use a left outer Join , it did not work out. I tried to take the subquery and assign it to a variable and use in the above mentioned query. But i am not getting the same results.
I don't want to use the above query so i am planning to rewrite the code.
Thank You,I doubt that the query you posted works fine, because:
FROM dbo.TBLTEST S1 ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
This is a syntax error. I will have to assume that your inteded query reads:
SELECT t1.DOCUMENT_NO,
rtrim(cast(t1."ENVIRONMENT_CD" AS varchar(5))) + '*' +
rtrim(cast(t1."ORDER_NO" AS varchar(25))) +
CASE WHEN (SELECT COUNT(DISTINCT S1.TEST_REPORTING_MATERIAL_SID)
FROM dbo.TBLTEST S1
WHERE S1.DOCUMENT_NO = T1.DOCUMENT_NO
AND S1.TEST_REPORTING_MATERIAL_SID > 0
AND S1.COMPANY_CD = T1.COMPANY_CD
AND S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
AND S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
AND S1.ORDER_NO = T1.ORDER_NO) > 1 THEN
RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS VARCHAR(10)))
ELSE '*-'
END as sum_key, t1.SALES_ANALYSIS_CD
FROM dbo.TBLTEST_ALL T1
WHERE t1.TIME_SID >= 20001001
Here is a query with a left join. Whether it is actually better than the one you have I am not sure.
SELECT t1.DOCUMENT_NO,
rtrim(cast(t1."ENVIRONMENT_CD" AS varchar(5))) + '*' +
rtrim(cast(t1."ORDER_NO" AS varchar(25))) +
CASE WHEN S1."EXISTS" IS NOT NULL
THEN RTRIM(CAST(t1."TEST_REPORTING_MATERIAL_SID" AS varchar(10)))
ELSE '*-'
END as sum_key, t1.SALES_ANALYSIS_CD
FROM dbo.TBLTEST_ALL T1
LEFT JOIN (SELECT 1 AS "EXISTS"
FROM dbo.TBLTEST
WHERE TEST_REPORTING_MATERIAL_SID > 0
GROUP BY DOCUMENT_NO, COMPANY_CD, INVOICE_SEQ_NO,
DOCUMENT_ITEM_NO, ORDER_NO
HAVING COUNT(DISTINCT TEST_REPORTING_MATERIAL_SID) > 1) AS S1
ON S1.DOCUMENT_NO = T1.DOCUMENT_NO
AND S1.COMPANY_CD = T1.COMPANY_CD
AND S1.INVOICE_SEQ_NO = T1.INVOICE_SEQ_NO
AND S1.DOCUMENT_ITEM_NO = T1.DOCUMENT_ITEM_NO
AND S1.ORDER_NO = T1.ORDER_NO
WHERE t1.TIME_SID >= 20001001
Erland Sommarskog, SQL Server MVP, [email protected] -
Hi,
I have a client requirement to show a report on the device availability. The report should show the output as
Node Availability%
Formula for Availability = (Total No. of Failed/Total No. rows) * 100
My Oracle Table has the following data
NODE SUMMARY
172.16.10.55 Default Interface Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Interface Ping restore for 172.16.10.55
172.16.10.55 Default Chassis Ping restore for 172.16.10.55
172.16.10.55 Default Chassis Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Chassis Ping restore for 172.16.10.55
172.16.10.55 Default Chassis Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Chassis Ping fail for 172.16.10.55: ICMP timeout
172.16.10.55 Default Interface Ping restore for 172.16.10.55
172.16.10.55 Default Interface Ping fail for 172.16.10.55: ICMP timeout
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Interface Ping fail for 172.16.10.56: ICMP timeout
172.16.10.56 Default Chassis Ping fail for 172.16.10.56: ICMP timeout
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Chassis Ping fail for 172.16.10.56: ICMP timeout
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Chassis Ping restore for 172.16.10.56
172.16.10.56 Default Interface Ping fail for 172.16.10.56: ICMP timeout
In the above table the Summary column has the details like 'Ping fail' , 'Ping restore' for each Node. So, for each Node I have to compute the Total Ping Fail / (Total Ping Fail + Ping Restore) * 100 to compute the availability %.
My output should be like the below
Node Availability%
172.16.10.55 55.55
172.16.10.56 54
Can someone please help me with query.
I appreciate your help in advance.
Thanks.
Regards,
RaviShankar.My Oracle Table has the following dataThat's great, but if you want maximum response to your question, then post CREATE TABLE + INSERT INTO statements.
I currently do not have the time to turn your data into them.
And always post the database version you're using.
http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
Also use the {noformat}{noformat} tag in order to post examples that benefit from staying formatted and thus readable when posted on the forum.
Simply put the tag before and after your examples.
For example, when you type:
{noformat}select *
from dual;{noformat}
it will appear as:select *
from dual; -
Hi,
I have 2 tables A and B with below data and description, i want to update Table B when C1, C2 are equal and C3 is not equal by comparing with Table A. If A contains 2 records with same such condition then update any 1 record's different description in Table B.
I can achieve this by using below query but i don't want to query Table A twice. Also if this is update is possible using Cursor is also fine for me..
Please help me on this...Thanks in Advance
Query
Update B
set B.c3 = (select c3 from A
where A.c1 = B.c1
and A.c2 = B.c2
and A.c3 <> B.c3
and ROWNUM = 1)
where exists (select 1 from A
where A.c1 = B.c1
and A.c2 = B.c2
and A.c3 <> B.c3);
Table A Table B
C1 C2 C3 C1 C2 C3
1 B desc1 1 B desc3
1 B desc2 2 x desc2
2 x desc1 3 y desc3
3 y desc3
Expected Output
Table B
C1 C2 C3
1 B desc1 or desc2 (any 1 different description should get updated)
2 x desc1
3 y desc3I am a bit confused. this also works without numbers in the C3 column.
drop table tablea;
drop table tableb;
create table tablea as
(select 1 C1,'B' C2, 'descA' C3 from dual union
select 1, 'B', 'descB' from dual union
select 2, 'x', 'descC' from dual union
select 3, 'y', 'descC' from dual
create table tableb as
(select 1 C1,'B' C2, 'descC' C3 from dual union
select 2, 'x', 'descB' from dual union
select 3, 'y', 'descC' from dual
merge into tableb t1
using (
select tablea.C1, tablea.C2, max(tablea.C3) C3
from tablea, tableb
where tablea.c1 = tableb.c1
and tablea.c2 = tableb.c2
and tablea.c3 != tableb.c3
group by tablea.C1, tablea.C2) t2
on (t1.C1 = t2.C1 and t1.C2 = t2.C2 )
when matched then
update
set T1.C3 = t2.C3;
select * from tableb;
C1 C2 C3
1 B descB
2 x descC
3 y descC -
How to group by below query?
Hi All,
I have below query,
SELECT username,firstname,lastname,country
FROM emp e1
WHERE EXISTS (
SELECT 1
FROM emp
WHERE e1.lastname = firstname
AND e1.firstname) = lastname )
OR EXISTS (
SELECT 1
FROM emp
WHERE lastname = e1.lastname
AND firstname) = e1.firstname )
and the result of the query is
USERNAME, FIRSTNAME, LASTNAME, COUNTRY
1, b6, a6, CH
2, a6, b6, CH
3, a1, b1, CH
4, b1, a1, CH
5, a2, b2, CH
6, a2, b2, CH
7, b1, a1, CH
8, b1, a1, CH
9, b2, a2, CH
10, b2, a2, CH
now i have to group all the firstname and lastname which are haviing values
1) a1,b1 and b1,a1
2) a2,b2 and b2,a2
3) a6,b6 and b6,a6
Can you please help me in this?
Thanks in advance.
Edited by: user9258447 on Jul 27, 2010 6:16 AMWelcome to the forum!
select least (first_name, last_name)
, greatest (first_name, last_name)
, ctry
from test
group by least (first_name, last_name)
, greatest (first_name, last_name)
, ctryas in
SQL> with test as
2 (
3 select 1 username, 'b6' first_name, 'a6' last_name, 'CH' ctry from dual union all
4 select 2 username, 'a6' first_name, 'b6' last_name, 'CH' ctry from dual union all
5 select 3 username, 'a1' first_name, 'b1' last_name, 'CH' ctry from dual union all
6 select 4 username, 'b1' first_name, 'a1' last_name, 'CH' ctry from dual union all
7 select 5 username, 'a2' first_name, 'b2' last_name, 'CH' ctry from dual union all
8 select 6 username, 'a2' first_name, 'b2' last_name, 'CH' ctry from dual union all
9 select 7 username, 'b1' first_name, 'a1' last_name, 'CH' ctry from dual union all
10 select 8 username, 'b1' first_name, 'a1' last_name, 'CH' ctry from dual union all
11 select 9 username, 'b2' first_name, 'a2' last_name, 'CH' ctry from dual union all
12 select 1 username0, 'b2' first_name, 'a2' last_name, 'CH' ctry from dual
13 )
14 select least (first_name, last_name)
15 , greatest (first_name, last_name)
16 , ctry
17 from test
18 group by least (first_name, last_name)
19 , greatest (first_name, last_name)
20 , ctry
21 /
LE GR CT
a1 b1 CH
a2 b2 CH
a6 b6 CH
Maybe you are looking for
-
Editing properties of some of my mu
Can anyone help me understand how to edit the properties of some of my music please? For instance, some tracks are from compilation albums and I'd like to rename them and add them to the folder of the artist. Some are also oddly named for other reaso
-
Smart Collection not letting me click Save
Hello, I have no smart collections or regular collections created. I am trying to create a smart collection containing all the photographs with the keyword Goofy in them. 1. I click "Create new smart collection" 2. Look in: 'my photos' folder 3. Crit
-
Incorrect Job description in PA & OM
Hi Guru's Wish you all a happy New year.. I have an issue , i can see the incorrect job descriptionfor an terminated employee in 0001 new record and old record Ex : Old record Quality Analyst II new record(after termination) says Quality Analyst I.
-
I have an iMac running system 10.7.5 and have AI CS 5 and CS 6 installed. I am thinking to upgrade to system 10.8, but I wonder if I won't be able to run AI CS 5 anymore? I like CS 5 a lot better than CS 6.
-
Hi trying to create a new apple id but im still waiting to send me verification so i can use my new apple id but they never send me i try to make a new mail same thing:( i need your help ineed new apple id asap PLEASE WHAT WRONG