Join Selectivity
Hello,
Below is an extract of a 10053 trace file for a test case, I am trying to understand a join selectivity value of 0.200781 when joining TABLE_2 to TABLE_3 my understanding of the join selectivity formula is:
Join Selectivity = greater(num_distinct(t1.c1),num_distinct(t2.c2) - Assuming no nulls.
However in the example below this does not appear to be case in this situation, I am just trying to understand the behaviour therfore any suggestions would be appreciated.
Database is 11gR2
QUERY BLOCK TEXT
select x1.x ,count(*)
from table_3 x3
join table_2 x2 on x2.x = x3.x
join table_1 x1 on x1.x = x2.x
where x1.x=1
group by x1.x
QUERY BLOCK SIGNATURE
signature (optimizer): qb_name=SEL$9E43CB6E nbfros=3 flg=0
fro(0): flg=0 objn=688324 hint_alias="X2"@"SEL$1"
fro(1): flg=0 objn=688325 hint_alias="X3"@"SEL$1"
fro(2): flg=0 objn=688323 hint_alias="X1"@"SEL$2"
SYSTEM STATISTICS INFORMATION
Using WORKLOAD Stats
CPUSPEED: 500 millions instructions/sec
SREADTIM: 10.000000 milliseconds
MREADTIM: 20.000000 millisecons
MBRC: 16 blocks
MAXTHR: -1 bytes/sec
SLAVETHR: -1 bytes/sec
BASE STATISTICAL INFORMATION
Table Stats::
Table: TABLE_1 Alias: X1
#Rows: 4 #Blks: 60 AvgRowLen: 2.00 ChainCnt: 0.00
Column (#1): X(
AvgLen: 2 NDV: 4 Nulls: 0 Density: 0.250000
Table Stats::
Table: TABLE_2 Alias: X2
#Rows: 20 #Blks: 60 AvgRowLen: 2.00 ChainCnt: 0.00
Column (#1): X(
AvgLen: 2 NDV: 8 Nulls: 0 Density: 0.025000
Histogram: Freq #Bkts: 8 UncompBkts: 20 EndPtVals: 8
Table Stats::
Table: TABLE_3 Alias: X3
#Rows: 80 #Blks: 60 AvgRowLen: 2.00 ChainCnt: 0.00
Column (#1): X(
AvgLen: 2 NDV: 9 Nulls: 0 Density: 0.012500
Histogram: HtBal #Bkts: 80 UncompBkts: 80 EndPtVals: 9
Access path analysis for TABLE_3
SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for TABLE_3[X3]
Table: TABLE_3 Alias: X3
Card: Original: 80.000000 Rounded: 80 Computed: 80.00 Non Adjusted: 80.00
Access Path: TableScan
Cost: 9.09 Resp: 9.09 Degree: 0
Cost_io: 9.00 Cost_cpu: 439286
Resp_io: 9.00 Resp_cpu: 439286
Best:: AccessPath: TableScan
Cost: 9.09 Degree: 1 Resp: 9.09 Card: 80.00 Bytes: 0
Access path analysis for TABLE_2
SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for TABLE_2[X2]
Table: TABLE_2 Alias: X2
Card: Original: 20.000000 Rounded: 20 Computed: 20.00 Non Adjusted: 20.00
Access Path: TableScan
Cost: 9.09 Resp: 9.09 Degree: 0
Cost_io: 9.00 Cost_cpu: 430286
Resp_io: 9.00 Resp_cpu: 430286
Best:: AccessPath: TableScan
Cost: 9.09 Degree: 1 Resp: 9.09 Card: 20.00 Bytes: 0
Access path analysis for TABLE_1
SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for TABLE_1[X1]
Table: TABLE_1 Alias: X1
Card: Original: 4.000000 Rounded: 1 Computed: 1.00 Non Adjusted: 1.00
Access Path: TableScan
Cost: 9.09 Resp: 9.09 Degree: 0
Cost_io: 9.00 Cost_cpu: 428486
Resp_io: 9.00 Resp_cpu: 428486
Best:: AccessPath: TableScan
Cost: 9.09 Degree: 1 Resp: 9.09 Card: 1.00 Bytes: 0
Grouping column cardinality [ X] 1
OPTIMIZER STATISTICS AND COMPUTATIONS
GENERAL PLANS
Considering cardinality-based initial join order.
Permutations for Starting Table :0
Join order[1]: TABLE_1[X1]#0 TABLE_2[X2]#1 TABLE_3[X3]#2
Now joining: TABLE_2[X2]#1
NL Join
Outer table: Card: 1.00 Cost: 9.09 Resp: 9.09 Degree: 1 Bytes: 2
Access path analysis for TABLE_2
Inner table: TABLE_2 Alias: X2
Access Path: TableScan
NL Join: Cost: 18.17 Resp: 18.17 Degree: 1
Cost_io: 18.00 Cost_cpu: 858773
Resp_io: 18.00 Resp_cpu: 858773
Best NL cost: 18.17
resc: 18.17 resc_io: 18.00 resc_cpu: 858773
resp: 18.17 resp_io: 18.00 resc_cpu: 858773
Join Card: 2.500000 = = outer (1.000000) * inner (20.000000) * sel (0.125000)
Join Card - Rounded: 3 Computed: 2.50
Grouping column cardinality [ X] 1
Outer table: TABLE_1 Alias: X1
resc: 9.09 card 1.00 bytes: 2 deg: 1 resp: 9.09
Inner table: TABLE_2 Alias: X2
resc: 9.09 card: 20.00 bytes: 2 deg: 1 resp: 9.09
using dmeth: 2 #groups: 1
SORT ressource Sort statistics
Sort width: 598 Area size: 536576 Max Area size: 104857600
Degree: 1
Blocks to Sort: 1 Row size: 13 Total Rows: 1
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 5000000
Total Temp space used: 0
SORT ressource Sort statistics
Sort width: 598 Area size: 536576 Max Area size: 104857600
Degree: 1
Blocks to Sort: 1 Row size: 13 Total Rows: 20
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 5003894
Total Temp space used: 0
SM join: Resc: 20.17 Resp: 20.17 [multiMatchCost=0.00]
SM Join
SM cost: 20.17
resc: 20.17 resc_io: 18.00 resc_cpu: 10862667
resp: 20.17 resp_io: 18.00 resp_cpu: 10862667
Outer table: TABLE_1 Alias: X1
resc: 9.09 card 1.00 bytes: 2 deg: 1 resp: 9.09
Inner table: TABLE_2 Alias: X2
resc: 9.09 card: 20.00 bytes: 2 deg: 1 resp: 9.09
using dmeth: 2 #groups: 1
Cost per ptn: 0.50 #ptns: 1
hash_area: 131 (max=25600) buildfrag: 1 probefrag: 1 ppasses: 1
Hash join: Resc: 18.67 Resp: 18.67 [multiMatchCost=0.00]
HA Join
HA cost: 18.67
resc: 18.67 resc_io: 18.00 resc_cpu: 3360923
resp: 18.67 resp_io: 18.00 resp_cpu: 3360923
Best:: JoinMethod: Hash
Cost: 18.67 Degree: 1 Resp: 18.67 Card: 2.50 Bytes: 4
Now joining: TABLE_3[X3]#2
NL Join
Outer table: Card: 2.50 Cost: 18.67 Resp: 18.67 Degree: 1 Bytes: 4
Access path analysis for TABLE_3
Inner table: TABLE_3 Alias: X3
Access Path: TableScan
NL Join: Cost: 42.94 Resp: 42.94 Degree: 1
Cost_io: 42.00 Cost_cpu: 4678782
Resp_io: 42.00 Resp_cpu: 4678782
Best NL cost: 42.94
resc: 42.94 resc_io: 42.00 resc_cpu: 4678782
resp: 42.94 resp_io: 42.00 resc_cpu: 4678782
Join Card: 40.156250 = = outer (2.500000) * inner (80.000000) * sel (0.200781)
Join Card - Rounded: 40 Computed: 40.16
Grouping column cardinality [ X] 1
Outer table: TABLE_2 Alias: X2
resc: 18.67 card 2.50 bytes: 4 deg: 1 resp: 18.67
Inner table: TABLE_3 Alias: X3
resc: 9.09 card: 80.00 bytes: 2 deg: 1 resp: 9.09
using dmeth: 2 #groups: 1
SORT ressource Sort statistics
Sort width: 598 Area size: 536576 Max Area size: 104857600
Degree: 1
Blocks to Sort: 1 Row size: 15 Total Rows: 3
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 5000214
Total Temp space used: 0
SORT ressource Sort statistics
Sort width: 598 Area size: 536576 Max Area size: 104857600
Degree: 1
Blocks to Sort: 1 Row size: 13 Total Rows: 80
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 5022787
Total Temp space used: 0
SM join: Resc: 29.76 Resp: 29.76 [multiMatchCost=0.00]
SM Join
SM cost: 29.76
resc: 29.76 resc_io: 27.00 resc_cpu: 13823210
resp: 29.76 resp_io: 27.00 resp_cpu: 13823210
Outer table: TABLE_2 Alias: X2
resc: 18.67 card 2.50 bytes: 4 deg: 1 resp: 18.67
Inner table: TABLE_3 Alias: X3
resc: 9.09 card: 80.00 bytes: 2 deg: 1 resp: 9.09
using dmeth: 2 #groups: 1
Cost per ptn: 0.50 #ptns: 1
hash_area: 131 (max=25600) buildfrag: 1 probefrag: 1 ppasses: 1
Hash join: Resc: 28.26 Resp: 28.26 [multiMatchCost=0.00]
HA Join
HA cost: 28.26
resc: 28.26 resc_io: 27.00 resc_cpu: 6308659
resp: 28.26 resp_io: 27.00 resp_cpu: 6308659
GROUP BY sort
GROUP BY adjustment factor: 1.000000
GROUP BY cardinality: 1.000000, TABLE cardinality: 40.000000
SORT ressource Sort statistics
Sort width: 598 Area size: 536576 Max Area size: 104857600
Degree: 1
Blocks to Sort: 1 Row size: 17 Total Rows: 40
Initial runs: 1 Merge passes: 0 IO Cost / pass: 0
Total IO sort cost: 0 Total CPU sort cost: 5009591
Total Temp space used: 0
Best:: JoinMethod: Hash
Cost: 29.26 Degree: 1 Resp: 29.26 Card: 40.16 Bytes: 6
Best so far: Table#: 0 cost: 9.0857 card: 1.0000 bytes: 2
Table#: 1 cost: 18.6722 card: 2.5000 bytes: 12
Table#: 2 cost: 29.2637 card: 40.1562 bytes: 240
***********************
When transitive closure is applied, wouldn't this be evident from a) the predicates section of the execution plan (not supplied) and b) an adjustment in the computed cardinality in the SINGLE TABLE ACCESS PATH section, as seen for TABLE_1:
Access path analysis for TABLE_1
SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for TABLE_1[X1]
Table: TABLE_1 Alias: X1
Card: Original: 4.000000 Rounded: 1 Computed: 1.00 Non Adjusted: 1.00Edited by: Dom Brooks on Jul 19, 2011 3:56 PM
Similar Messages
-
Dynamic table name in an inner join - select statement
Hi,
Please can you let me know if is possible to use a Dynamic table name in an inner join?
Something like the statement below? (It works in a simple select statement but not in an inner join)
SELECT *
INTO CORRESPONDING FIELDS OF <t_itab>
FROM <Dynamic table name> INNER JOIN pa0050 ON
( <Dynamic table name>pernr = pa0050pernr )
WHERE <Dynamic table name>~pernr = it_pernr-l_pernr
AND pa0050~bdegr = f_bdegr.
Any help would be apprecited very much.
Thanks & Regards.Hi,
Check this link.
[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb39c4358411d1829f0000e829fbfe/frameset.htm]
[Re: accessing dynamic internal table's fields??;
hope it'll help u.
Regards,
Sneha.
Edited by: sneha kumari on Jun 18, 2009 1:57 PM -
How to do outer join select query for an APEX report
Hello everyone,
I am Ann.
I have one select statement that calculate the statistics for one month(October 2012 in this example)
select ph.phase_number
, sum ( (case
WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE('Oct 2012','MON YYYY'))
THEN last_day(TO_DATE('Oct 2012','MON YYYY'))
ELSE ph.date_finished
END )
- ph.date_started + 1) / count(def.def_id) as avg_days
from phase_membership ph
inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
inner join defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY'))
and ph.active = 1
and UPPER(ce.court_name) LIKE '%'
group by rollup(phase_number)
Result is as below
Phase_Number AVG_DAYS
Phase One 8.6666666666666667
Phase Two 14.6
Phase Three 12
11.4615365
I have other select list mainly list the months between two date value.
select to_char(which_month, 'MON YYYY') as display_month
from (
select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
from all_objects
where
rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
order by which_month )
Query result is as below
DISPLAY_MONTH
AUG 2012
SEP 2012
OCT 2012
Is there any way that I can join these two select statement above to generate a result like:
Month Phase Number Avg days
Aug 2012 Phase One 8.666
Sep 2012 Phase One 7.66
Oct 2012 Phase One 5.66
Aug 2012 Phase Two 8.666
Sep 2012 Phase Two 7.66
Oct 2012 Phase Two 5.66
Aug 2012 Phase Three 8.666
Sep 2012 Phase Three 7.66
Oct 2012 Phase Three 5.66
Or
Month Phase Number Avg days
Aug 2012 Phase One 8.666
Aug 2012 Phase Two 7.66
Aug 2012 Phase Three 5.66
Sep 2012 Phase One 8.666
Sep 2012 Phase Two 7.66
Sep 2012 Phase Three 5.66
Oct 2012 Phase One 8.666
Oct 2012 Phase Two 7.66
Oct 2012 Phase Three 5.66
And it can be order by either Phase Number or Month.
My other colleague suggest I should use an left outer join but after trying so many ways, I am still stuck.
One of the select I tried is
select a.display_month,b.* from (
select to_char(which_month, 'MON YYYY') as display_month
from (
select add_months(to_date('Aug 2012','MON YYYY'), rownum-1) which_month
from all_objects
where
rownum <= months_between(to_date('Oct 2012','MON YYYY'), add_months(to_date('Aug 2012','MON YYYY'), -1))
order by which_month )) a left outer join
( select to_char(ph.date_finished,'MON YYYY') as join_month, ph.phase_number
, sum ( (case
WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(a.display_month,'MON YYYY'))
THEN last_day(TO_DATE(a.display_month,'MON YYYY'))
ELSE ph.date_finished
END )
- ph.date_started + 1) / count(def.def_id) as avg_days
from phase_membership ph
inner join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
inner join defendant def on ce.defendant_id = def.def_id
where def.active = 1
and ph.date_started <= last_day(TO_DATE(a.display_month,'MON YYYY'))
and ph.active = 1
and UPPER(ce.court_name) LIKE '%'
group by to_char(ph.date_finished,'MON YYYY') , rollup(phase_number)) b
on a.display_month = b.join_month
but then I get an error
SQL Error: ORA-00904: "A"."DISPLAY_MONTH": invalid identifier
I need to display a report on APEX with option for people to download at least CSV format.
I already have 1 inteactive report in the page, so don’t think can add another interactive report without using the iframe trick.
If any of you have any ideas, please help.
Thanks a lot.
AnnFirst of all, a huge thanks for following this Frank.
I have just started working here, I think the Oracle version is 11g, but not sure.
To run Oracle APEX version 4, I think they must have at least 10g R2.
This report is a bit challenging for me.I has never worked with PARTITION before.
About the select query you suggested, I run , and it seems working fine, but if I try this,
it return error ORA-01843: not a valid month
DEFINE startmonth = "Aug 2012";
DEFINE endmonth = "Oct 2012";
WITH all_months AS
select add_months(to_date('&startmonth','MON YYYY'), rownum-1) AS which_month
, add_months(to_date('&startmonth','MON YYYY'), rownum ) AS next_month
from all_objects
where
rownum <= months_between(to_date('&endmonth','MON YYYY'), add_months(to_date('&startmonth','MON YYYY'), -1))
select TO_CHAR (am.which_month, 'Mon YYYY') AS month
, ph.phase_number
, sum ( (case
WHEN ph.date_finished IS NULL OR ph.date_finished > last_day(TO_DATE(am.which_month,'MON YYYY'))
THEN last_day(TO_DATE(am.which_month,'MON YYYY'))
ELSE ph.date_finished
END )
- ph.date_started + 1) / count(def.def_id) as avg_days
FROM all_months am
LEFT OUTER JOIN phase_membership ph PARTITION BY (ph.phase_number)
ON am.which_month <= ph.date_started
AND am.next_month > ph.date_started
AND ph.date_started <= last_day(TO_DATE(am.which_month,'MON YYYY')) -- May not be needed
AND ph.active = 1
LEFT OUTER join court_engagement ce on ph.mpm_eng_id = ce.engagement_id
and ce.court_name IS NOT NULL -- or something involving LIKE
LEFT OUTER join defendant def on ce.defendant_id = def.def_id
AND def.active = 1
group by rollup(phase_number, am.which_month)
ORDER BY am.which_month
, ph.phase_number
;Here is the shorted versions of the three tables:
A_DEFENDANT, A_ENGAGEMENT, A_PHASE_MEMBERSHIP
CREATE TABLE "A_DEFENDANT"
"DEF_ID" NUMBER NOT NULL ENABLE,
"FIRST_NAME" VARCHAR2(50 BYTE),
"SURNAME" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"DOB" DATE NOT NULL ENABLE,
"ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
CONSTRAINT "A_DEFENDANT_PK" PRIMARY KEY ("DEF_ID"))
Sample Data
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (101,'Joe','Bloggs',to_date('12/12/99','DD/MM/RR'),1);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (102,'John','Smith',to_date('20/05/00','DD/MM/RR'),1);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (103,'Jane','Black',to_date('15/02/98','DD/MM/RR'),1);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (104,'Minnie','Mouse',to_date('13/12/88','DD/MM/RR'),0);
Insert into A_DEFENDANT (DEF_ID,FIRST_NAME,SURNAME,DOB,ACTIVE) values (105,'Daisy','Duck',to_date('05/08/00','DD/MM/RR'),1);
CREATE TABLE "A_ENGAGEMENT"
"ENGAGEMENT_ID" NUMBER NOT NULL ENABLE,
"COURT_NAME" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"DATE_REFERRED" DATE,
"DETERMINATION_HEARING_DATE" DATE,
"DATE_JOINED_COURT" DATE,
"DATE_TREATMENT_STARTED" DATE,
"DATE_TERMINATED" DATE,
"TERMINATION_TYPE" VARCHAR2(50 BYTE),
"ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
"DEFENDANT_ID" NUMBER,
CONSTRAINT "A_ENGAGEMENT_PK" PRIMARY KEY ("ENGAGEMENT_ID"))
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (1,'AA',to_date('12/08/12','DD/MM/RR'),null,to_date('12/08/12','DD/MM/RR'),null,null,null,1,101);
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (2,'BB',to_date('01/09/12','DD/MM/RR'),null,to_date('02/09/12','DD/MM/RR'),null,null,null,1,102);
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (3,'AA',to_date('02/09/12','DD/MM/RR'),null,to_date('15/09/12','DD/MM/RR'),null,null,null,1,103);
Insert into A_ENGAGEMENT (ENGAGEMENT_ID,COURT_NAME,DATE_REFERRED,DETERMINATION_HEARING_DATE,DATE_JOINED_COURT,DATE_TREATMENT_STARTED,DATE_TERMINATED,TERMINATION_TYPE,ACTIVE,DEFENDANT_ID) values (4,'BB',to_date('01/10/12','DD/MM/RR'),null,to_date('02/10/12','DD/MM/RR'),null,null,null,1,105);
CREATE TABLE "A_PHASE_MEMBERSHIP"
"MPM_ID" NUMBER NOT NULL ENABLE,
"MPM_ENG_ID" NUMBER NOT NULL ENABLE,
"PHASE_NUMBER" VARCHAR2(50 BYTE),
"DATE_STARTED" DATE NOT NULL ENABLE,
"DATE_FINISHED" DATE,
"NOTES" VARCHAR2(2000 BYTE),
"ACTIVE" NUMBER(2,0) DEFAULT 1 NOT NULL ENABLE,
CONSTRAINT "A_PHASE_MEMBERSHIP_PK" PRIMARY KEY ("MPM_ID"))
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (1,1,'PHASE ONE',to_date('15/09/12','DD/MM/RR'),to_date('20/09/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (2,1,'PHASE TWO',to_date('21/09/12','DD/MM/RR'),to_date('29/09/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (3,2,'PHASE ONE',to_date('12/09/12','DD/MM/RR'),null,null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (4,3,'PHASE ONE',to_date('20/09/12','DD/MM/RR'),to_date('01/10/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (5,3,'PHASE TWO',to_date('02/10/12','DD/MM/RR'),to_date('15/10/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (6,4,'PHASE ONE',to_date('03/10/12','DD/MM/RR'),to_date('10/10/12','DD/MM/RR'),null,1);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (7,3,'PHASE THREE',to_date('17/10/12','DD/MM/RR'),null,null,0);
Insert into A_PHASE_MEMBERSHIP (MPM_ID,MPM_ENG_ID,PHASE_NUMBER,DATE_STARTED,DATE_FINISHED,NOTES,ACTIVE) values (8,1,'PHASE THREE',to_date('30/09/12','DD/MM/RR'),to_date('16/10/12','DD/MM/RR'),null,1);
The requirements are:
The user must be able to request the extract for one or more calendar months, e.g.
May 2013
May 2013 – Sep 2013.
The file must contain a separate row for each calendar month in the requested range. Each row must contain the statistics computed for that calendar month.
The file must also include a row of totals.
The user must be able to request the extract for either Waitakere or Auckland or Consolidated (both courts’ statistics accumulated).
Then the part that I am stuck is
For each monitoring phase:
Phase name (e.g. “Phase One”)
Avg_time_in_phase_all_particip
for each phase name,
Add up days in each “phase name” Monitoring Phase, calculated as:
If Monitoring Phase.Date Finished is NULL or > month end date,
+(*Month end date* Minus Monitoring Phase.Date Started Plus 1)+
Otherwise (phase is complete)
+(Monitoring Phase.Date Finished Minus Monitoring Phase.Date Started Plus 1.)+
Divide by the numbers of all participants who have engaged in “phase name”.
This is the words of the Business Analyst,
I try to do as required but still struggle to identify end_month for the above formula to display for the range of months.
Of course, I can write two nested cursor. The first one run the list of month, then for each month, run the parameterised report.
But I prefer if possible just use SQL statements, or at least a PL/SQL but return a query.
With this way, I can create an APEX report, and use their CSV Extract function.
Yes, you are right, court_name is one of the selection parameters.
And the statistics is not exactly for one month. It is kind of trying to identify all phases that are running through the specified month (even phase.date_started is before the month start).
This is the reason why I put the condition AND ph.date_started <= last_day(TO_DATE('Oct 2012','MON YYYY')) (otherwise I get negative avg_days)
User can choose either one court "AA" or "BB" or combined which is all figures.
Sorry for bombarding you a lot of information.
Thanks a lot, again.
Edited by: Ann586341 on Oct 29, 2012 9:57 PM
Edited by: Ann586341 on Oct 29, 2012 9:59 PM -
Inner join-select -primary key in table issue
Hi ,
Iam using FEBKO(header) and FEBEP(item) in inner join select .But the datas fetching by this selct in not correct.The analysis is the is no common primary fields in the both table.
Question 1-> Can i use inner join without common primary key in the both tables, weather it possible to make a select without common primary key in both table. Please kindly let me know.
Question 2-> What is the other possible way to give the selct for both table(better performance)
Regards,
VeeraHi,
When you use INNER JOIN in this case, link your tables based on KUKEY and ESNUM fields, bcoz there can be many items under a single header. So this will work for you, even from the performance point of view.
Hope this is helpful to you. If you need further information, revert back.
Reward all the helpful answers.
Regards
Nagaraj T -
Joining/Selection problem...
I have created this view:
- First it selects the Lowest and Highest date which should be taken in DATES
- Then it selects every first of the month between the Lowest and Highest date and stores that in MONTHS
- Then it selects the ID, FirstOfTheMonth, (intakes UP TO FirstOfTheMonth), (Outgoing UP TO FirstOfTheMonth) from TWO tables without matching any id field...
Now If I run the view in SQL Developer, it works nicely. If I use the view in Crystal Reports i get an error message saying a subquery returns more than 1 row...
I have a feeling that my CALCULATIONS table is wrongly setup. The problem is that I need to select the PNM_AUTO_KEY from Parts_master and use this Key in the two subqueries... The way i did that is probably wrong.... My guessing is I should use a OUTER JOIN in stead of the way I did it now...?_
CREATE OR REPLACE FORCE VIEW "VIEW_STOCK_COUNT" ("PNM_AUTO_KEY", "COUNT_DATE", "QTY_RECEIVED", "QTY_USED", "QTY_BALANCE") AS
with
DATES as
(select (select min(REC_DATE) from STOCK) as FROM_DT, (select max(CHANGE_DATE) from STOCK_ADJUST) as TO_DT from DUAL),
MONTHS as
(select add_months(trunc(FROM_DT,'MM'),ROWNUM-1) as DT from DATES connect by ROWNUM <= months_between(TO_DT, FROM_DT)+1),
CALCULATIONS as
(select
PNM.PNM_AUTO_KEY PNM_KEY,
MONTHS.DT DT,
NVL((select sum(stm.qty_rec) from stock stm WHERE STM.REC_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY GROUP BY pnm_auto_key),0) INCOMING,
NVL((select sum(saj.qty_adj) from stock_adjust saj
inner join stock stm on saj.stm_auto_key = stm.stm_auto_key
inner join parts_master pnm on stm.pnm_auto_key = pnm.pnm_auto_key where SAJ.CHANGE_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY group by pnm_auto_key),0) OUTGOING
from MONTHS, PARTS_MASTER PNM)
SELECT
CALCULATIONS.PNM_KEY PNM_AUTO_KEY, CALCULATIONS.DT COUNT_DATE,CALCULATIONS.INCOMING QTY_RECEIVED, CALCULATIONS.OUTGOING QTY_USED, (CALCULATIONS.INCOMING + CALCULATIONS.OUTGOING) QTY_BALANCE
FROM
CALCULATIONS;Hi,
user574699 wrote:
I have created this view:
- First it selects the Lowest and Highest date which should be taken in DATES
- Then it selects every first of the month between the Lowest and Highest date and stores that in MONTHS
- Then it selects the ID, FirstOfTheMonth, (intakes UP TO FirstOfTheMonth), (Outgoing UP TO FirstOfTheMonth) from TWO tables without matching any id field...
Now If I run the view in SQL Developer, it works nicely. If I use the view in Crystal Reports i get an error message saying a subquery returns more than 1 row...
Sorry, I don't know anything about Crystal Reports. I would expect the view to be handled entirely by the database. What is the query that you're running when you get the error?
Will Crystal Reports run a very simple query on this view?
I have a feeling that my CALCULATIONS table is wrongly setup. The problem is that I need to select the PNM_AUTO_KEY from Parts_master and use this Key in the two subqueries... The way i did that is probably wrong.... My guessing is I should use a OUTER JOIN in stead of the way I did it now...?_That's easy to test. Replace the scalar sub-queries with literals, and see if Crystal Reports will run it.
If not, that's not the problem.
If you do decide to re-write the calculations sub-query, and you need help, post some sample data and what calculations should contain given that data.
Could the WITH-clause be causing the problem? (Again, it's hard to see why the front-end tool would care how the view was defined.)
It looks like you could use in-line views instead of WITH, if necessary.
CREATE OR REPLACE FORCE VIEW "VIEW_STOCK_COUNT" ("PNM_AUTO_KEY", "COUNT_DATE", "QTY_RECEIVED", "QTY_USED", "QTY_BALANCE") AS
with
DATES as
(select (select min(REC_DATE) from STOCK) as FROM_DT, (select max(CHANGE_DATE) from STOCK_ADJUST) as TO_DT from DUAL),
MONTHS as
(select add_months(trunc(FROM_DT,'MM'),ROWNUM-1) as DT from DATES connect by ROWNUM <= months_between(TO_DT, FROM_DT)+1),
CALCULATIONS as
(select
PNM.PNM_AUTO_KEY PNM_KEY,
MONTHS.DT DT,
NVL((select sum(stm.qty_rec) from stock stm WHERE STM.REC_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY GROUP BY pnm_auto_key),0) INCOMING,
NVL((select sum(saj.qty_adj) from stock_adjust saj
inner join stock stm on saj.stm_auto_key = stm.stm_auto_key
inner join parts_master pnm on stm.pnm_auto_key = pnm.pnm_auto_key where SAJ.CHANGE_DATE < MONTHS.DT AND STM.PNM_AUTO_KEY = PNM.PNM_AUTO_KEY group by pnm_auto_key),0) OUTGOING
from MONTHS, PARTS_MASTER PNM)
SELECT
CALCULATIONS.PNM_KEY PNM_AUTO_KEY, CALCULATIONS.DT COUNT_DATE,CALCULATIONS.INCOMING QTY_RECEIVED, CALCULATIONS.OUTGOING QTY_USED, (CALCULATIONS.INCOMING + CALCULATIONS.OUTGOING) QTY_BALANCE
FROM
CALCULATIONS;Don't post unformatted code -
Hi, Please help on the Select Join query. I want to compare code_stat_system1/code_stat_system2 and code_date_system1 /code_date_system2 column from table #system1 and #system2 but there is 2 rule to get correct row from table #system1 and #system2.
Rule 1: We need to get max(code_date_system1) record from #system1 for every code_system1 for compare.
Rule 1: We need to get max(code_date_system2) record from #system2 BUT BEFORE THE RECORD OF 'DKNOW' OF code_stat_system2 for every code_system2 for compare.
drop table #system1,#system2
create table #system1
(Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
Insert into #system1 values ('10','Dead','2013-01-01')
Insert into #system1 values ('10','Dead','2013-12-30')
Insert into #system1 values ('10','UnOpen','2014-10-01')
Insert into #system1 values ('10','Open','2014-11-01') --This record should max(code_stat_system1) for compare
Insert into #system1 values ('20','Dead','2013-12-01')
Insert into #system1 values ('20','Dead','2013-12-30')
Insert into #system1 values ('20','Open','2014-08-01')
Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
create table #system2
(Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
Insert into #system2 values ('10','Dead','2013-01-01')
Insert into #system2 values ('10','Dead','2013-12-30')
Insert into #system2 values ('10','Open','2014-10-01')
Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('10','DKNOW','2015-01-01')
Insert into #system2 values ('10','DKNOW','2015-02-01')
Insert into #system2 values ('20','Dead','2013-12-01')
Insert into #system2 values ('20','Dead','2013-12-30')
Insert into #system2 values ('20','Open','2014-08-01')
Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('20','DKNOW','2015-01-01')
Insert into #system2 values ('20','DKNOW','2015-02-01')
--Desired Output
Code_system1 code_stat_system1 code_date_system1 Code_system1 code_stat_system2 code_date_system1 Rrmk_code_stat Rrmk_code_date
10 Open 2014-11-01 10 UnOpen
2014-12-01 Codes not matching Dates not matching
20 UnOpen 2014-09-01 20 UnOpen
2014-09-01 Codes matching Dates matching
Thanks.drop table #system1,#system2
create table #system1
(Code_system1 varchar(10),code_stat_system1 varchar(10),code_date_system1 datetime)
Insert into #system1 values ('10','Dead','2013-01-01')
Insert into #system1 values ('10','Dead','2013-12-30')
Insert into #system1 values ('10','UnOpen','2014-10-01')
Insert into #system1 values ('10','Open','2014-11-01') --This record should max(code_stat_system1) for compare
Insert into #system1 values ('20','Dead','2013-12-01')
Insert into #system1 values ('20','Dead','2013-12-30')
Insert into #system1 values ('20','Open','2014-08-01')
Insert into #system1 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system1) for compare
create table #system2
(Code_system2 varchar(10),code_stat_system2 varchar(10),code_date_system2 datetime)
Insert into #system2 values ('10','Dead','2013-01-01')
Insert into #system2 values ('10','Dead','2013-12-30')
Insert into #system2 values ('10','Open','2014-10-01')
Insert into #system2 values ('10','UnOpen','2014-12-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('10','DKNOW','2015-01-01')
Insert into #system2 values ('10','DKNOW','2015-02-01')
Insert into #system2 values ('20','Dead','2013-12-01')
Insert into #system2 values ('20','Dead','2013-12-30')
Insert into #system2 values ('20','Open','2014-08-01')
Insert into #system2 values ('20','UnOpen','2014-09-01') --This record should max(code_stat_system2) which is before 'DKNOW' for compare
Insert into #system2 values ('20','DKNOW','2015-01-01')
Insert into #system2 values ('20','DKNOW','2015-02-01')
;with mycte1 as (select * ,row_number() Over (partition by Code_system1 Order by code_date_system1 Desc ) rn from #system1)
,mycte2 as (select *,row_number() Over (partition by Code_system2 Order by code_date_system2 Desc ) rn2 from #system2
where code_stat_system2<>'DKNOW')
Select m1.Code_system1, m1.code_stat_system1, m1.code_date_system1, Code_system2, code_stat_system2,code_date_system2 ,
case When code_date_system1=code_date_system2 then 'Dates matching' else 'Dates not matching' End as checkDate,
case When code_stat_system1=code_stat_system2 then 'Codes matching' else 'Codes not matching' End as checkStat
from mycte1 m1 inner join mycte2 m2 on m1.Code_system1= m2.Code_system2 and m1.rn=m2.rn2
Where m1.rn=1 -
Hash semi join and join selectivity
Hi,
I'm looking for an explanation of the rule-of-thumb that hash joins are more efficient for high selectivity joins.
If I have a query with two tables, semi-joined together using an EXISTS clause, why would a hash join be better for a high selectivity join as opposed to a low selectivity join?
To clarify, my definition of selectivity is:
selectivity = # of rows returned / # of rows processed
Or in more database specific terms:
selectivity = num_rows/cardinality
Selectivity is a value between 0 and 1, so by high selectivity, I mean a selectivity value closer to 1.
Thanks for any input.
- KRkenny r. wrote:
Hi,
I'm looking for an explanation of the rule-of-thumb that hash joins are more efficient for high selectivity joins.
If I have a query with two tables, semi-joined together using an EXISTS clause, why would a hash join be better for a high selectivity join as opposed to a low selectivity join?
To clarify, my definition of selectivity is:
selectivity = # of rows returned / # of rows processed
Or in more database specific terms:
selectivity = num_rows/cardinality
Selectivity is a value between 0 and 1, so by high selectivity, I mean a selectivity value closer to 1.KR,
the question is "more efficient" than ... what?
A hash join is usually the most efficient operation if you have to join a large set or two large sets. Often the hash join operation performs full table scans as part of the join operation, but not necessarily.
The cost of the hash join depends on the volume to join, the available memory and the resulting operation (optimal / one-pass / multi-pass). If the hash table can be kept in memory then it's simply the cost to read the first data set used as hash table, the cost of reading the probe table and the CPU cost of processing the hash join. If the hash table doesn't fit into memory, it depends on how often the build (hash) table and probe data needs to be read (one-pass / multi-pass) to perform the join with the hash table.
If you have a "low selectivity" join, and I assume you mean that the join actually filters out many rows by "low selectivity", then other join operations might be more effective, like a NESTED LOOP that uses the smaller table to iterate via an index access over the second table, selectively picking the rows corresponding to the first table. Depending on the number of iterations and the number of rows of the second table to process per iteration this can be very efficient, but tends to be very inefficient if the iterations and/or number of rows in second table is significantly larger than estimated.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
hello all,
Below is a inner join query
SELECT aebeln aebelp apackno bzekkn b~ps_psp_pnr
FROM ( ( ekpo AS a INNER JOIN ekkn AS b
ON aebeln = bebeln
AND aebelp = bebelp )
INNER JOIN prps AS c
ON bps_psp_pnr = cpspnr )
INTO TABLE t_wbspo
WHERE a~ebeln IN s_ebeln
AND c~psphi IN s_psphi
AND stufe = c_task.
I want to modify this select and put one more join on ekkn-aufnr
and aufk-afunr .
Now for this i write the below code
SELECT aebeln aebelp apackno bzekkn bps_psp_pnr baufnr
FROM ( ( ( ekpo AS a INNER JOIN ekkn AS b
ON aebeln = bebeln
AND aebelp = bebelp )
INNER JOIN prps AS c
ON bps_psp_pnr = cpspnr )
INNER JOIN aufk AS d
ON baufnr = daufnr )
INTO TABLE t_wbspo
WHERE a~ebeln IN s_ebeln
AND c~psphi IN s_psphi
AND d~aufnr IN s_aufnr
AND stufe = c_task.
By the above way does it puts a join on ekkn-aufnr and aufk-aufnr ?
Is the above way the right way to do it ?
Please confirm
regardsHello Bhanu,
Do you face any performance issue? Query looks good now, further you can refer to following threads to know more on JOIN-
Re: Inner join
http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ec77446011d189700000e8322d00/frameset.htm
Thank You,
Nishikant Kumbhar. -
Hi all,
I have a query, but it doesn't work when i give select-options range table in WHERE clause.
SELECT-OPTIONS :
l_bukrs FOR WA_INPUT-bukrs NO INTERVALS ,
SELECT
VBAK~BUKRS_VF AS BUKRS "COMPANY CODE
PA0001~ENAME "SALES EMPLOYEE NAME
KNA1~NAME1 "CLIENT
VBKD~BSTKD "PO NO
VBAK~VBELN "SO NO
VBAK~AUDAT "SO DATE
VBAP~POSNR "LINE
VBAP~KWMENG "QTY
VBAP~VRKME "UNIT
VBAP~NETPR "RATE
VBAP~NETWR "ORDER VALUE
VBAP~WAERK "DOCUEMNT CURRENCY
VBAP~MATNR "MATERIAL NO
VBAP~ARKTX "MATERIAL NAME
VBKD~KURSK "EXCHANGE RATE
INTO CORRESPONDING FIELDS OF TABLE IT_OPSALES
FROM VBAP
LEFT OUTER JOIN VBPA ON VBPAVBELN = VBAPVBELN AND VBPA~PARVW = 'AF'
INNER JOIN PA0001 ON PA0001PERNR = VBPAPERNR
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN KNA1 ON KNA1KUNNR = VBAKKUNNR
INNER JOIN VBKD ON VBKDVBELN = VBAKVBELN AND VBKDPOSNR = VBAPPOSNR
WHERE BUKRS IN L_BUKRS
it wont support when i give L_bukrs in inner join clause..!!
any idea to change the query??
thaks and regards
JoseHi,
Declare the select option as s_bukrs .
SELECT-OPTIONS :
S_bukrs FOR WA_INPUT-bukrs NO INTERVALS ,
SELECT
VBAK~BUKRS_VF AS BUKRS "COMPANY CODE
PA0001~ENAME "SALES EMPLOYEE NAME
KNA1~NAME1 "CLIENT
VBKD~BSTKD "PO NO
VBAK~VBELN "SO NO
VBAK~AUDAT "SO DATE
VBAP~POSNR "LINE
VBAP~KWMENG "QTY
VBAP~VRKME "UNIT
VBAP~NETPR "RATE
VBAP~NETWR "ORDER VALUE
VBAP~WAERK "DOCUEMNT CURRENCY
VBAP~MATNR "MATERIAL NO
VBAP~ARKTX "MATERIAL NAME
VBKD~KURSK "EXCHANGE RATE
INTO CORRESPONDING FIELDS OF TABLE IT_OPSALES
FROM VBAP
LEFT OUTER JOIN VBPA ON VBPAVBELN = VBAPVBELN AND VBPA~PARVW = 'AF'
INNER JOIN PA0001 ON PA0001PERNR = VBPAPERNR
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN KNA1 ON KNA1KUNNR = VBAKKUNNR
INNER JOIN VBKD ON VBKDVBELN = VBAKVBELN AND VBKDPOSNR = VBAPPOSNR
WHERE BUKRS IN S_BUKRS
Hope this helps you.
Thanks & Regards,
Y.R.Prem Kumar -
I had my data declaration as below.
DATA :BEGIN OF t_plaf OCCURS 0,
normt LIKE mara-normt,
matnr LIKE plaf-matnr,
pwwrk LIKE plaf-pwwrk,
paart LIKE plaf-paart,
verid LIKE plaf-verid,
auffx LIKE plaf-auffx,
psttr LIKE plaf-psttr,
gsmng LIKE plaf-gsmng,
END OF t_plaf.
corresponding inner join statement
SELECT maranormt plafmatnr
plafpwwrk plafpaart plaf~verid
plafauffx plafpsttr plaf~gsmng
INTO TABLE t_plaf
FROM plaf
INNER JOIN mara
ON plafmatnr EQ maramatnr
WHERE plaf~paart = 'LA'.
Now I have changed the declaration as below
DATA : BEGIN OF t_plaf OCCURS 0,
normt LIKE mara-normt.
INCLUDE STRUCTURE plaf.
DATA : END OF t_plaf.
now i have changed the data declaration as mentioned above and need a inner join statement for the data declaration i have specified.
Any suggestions,
MAdhuHi Madhu,
USE INTO CORRESPONDING option instead of INTO TABLE.
SELECT maranormt plafmatnr
plafpwwrk plafpaart plaf~verid
plafauffx plafpsttr plaf~gsmng
<b>INTO CORRESPONDING FIELDS OF TABLE t_plaf</b>
FROM plaf
INNER JOIN mara
ON plafmatnr EQ maramatnr
WHERE plaf~paart = 'LA'.
Thanks,
Vinay -
Outer Join (select) statement
hI
Im BW-Consultant. I have two tables with some fileds.
ZTABLE1 ---> MATNR, PRCTR, BUKRS, LIGNG, MATGR.And this table has 5-materials
ZTABLE2 --> MATNR, PRCTR, BUKRS, FKMNG, VERID. And this table has 10-materials.
These two tables(ZTABLE1, ZTABLE2) has 3-materials are common.
But i want all 15-materials in an another table ZTABLE3. So how can i write an <b>outer join statement.</b> .
Please give the OuterJoinCode(select statement) to get all 15-materials
regards
kumarExample
SELECT KNA1~KUNNR KNA1~ADRNR ADR6~SMTP_ADDR
INTO (A, B, C)
FROM KNA1 LEFT OUTER JOIN ADR6
ON KNA1~ADRNR = ADR6~ADDRNUMBER
WHERE KUNNR BETWEEN '0000000000' AND '0000500000'.
DATA: BEGIN OF wa,
carrid TYPE scarr-carrid,
carrname TYPE scarr-carrname,
connid TYPE spfli-connid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH NON-UNIQUE KEY carrid.
SELECT s~carrid s~carrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON s~carrid = p~carrid AND
p~cityfrom = 'FRANKFURT'.
LOOP AT itab INTO wa.
WRITE: / wa-carrid, wa-carrname, wa-connid.
ENDLOOP.
A -
Joins, Select or Union of unrelated tables
I have about 7 tables that have data that I need to get in a
report but the columns in those tables are unrelated which makes
it a little difficult to do a leading-trailing table select ie
a.xxx,b.yyy
where a.xxx=b.yyy
I am trying to get various columns from the tables together to
generate a report. Is there a better way to do that. Unions puts
all under one column but I need to have then in seperate columns
eg name,address,DOB,phone#. name is in a different table same
with the other fields and there is nothing in any of the tables
that are related put when I pull the various columns together it
will make a meaningful output.
Also
XXX_1099_AAAAAA
XXX_1199_AAAAAA
YYY_1299_BBBBBB
YYY_0100_BBBBBB
SSS_0200_CCCCCC
SSS_0300_AAAAAA
TTT_0400_BBBBBB
I have a column in the above format, and the column info is data
that I need to load another table. I need to get the last 6
xters as products and load them into a product column of another
table. I need to use them in a table. I did substr(column,10,6)
as
PRODUCTS but that didn't work and also I have more than 500,000
rows and will
be impossible to list then all one by one. I have multiple
entries for
different products and different months and for XXX and YYY. I
need a way to be
able to get those last 6 characters into a table.
I will need to end up with a table like
PRODUCTS
AAAAA
AAAAA
BBBBB
CCCCC so I can them match them again to the various columns from
where they were created to get that data to do sums for output.In response to your first question, if the columns are completely unrelated, how do you know which row of data in the different tables goes with the rows in the others? If there is nothing to indicate which name goes with which address, then you can't join them.
In response to your second question, why did substr(column,10,6) not work? It looks like it should, unless there are a variable number of characters in front of the six you need, in which case you could do either ...
substr(column,length(column)-5,6) to get the last six, or ...
substr(column,instr(column,'_',2)+1,6) to get the six characters after the second underscore. -
Error joining selected wireless network
the airport extreme was working fine for a couple of years until few days ago. i have not been using it since then because i can't, for some reasons.
i tried hard resetting it (the little button at the back of the airport extreme) and re-install the software (from the CD)
keep getting this message that "an error occurred joining the selected network"
please help as i'm getting frustrated..
and oh, i have updated all the required updates.
/Users/oliviajap/Desktop/Picture 1.jpg
/Users/oliviajap/Desktop/Picture 2.jpg
now, it won't even show a picture of my airport extreme..
please please help.. thanksThank you very much for your help.
Thanks to your advice I was able to get contact with and seemingly successful initiate the AirPort Extreme again. It seems the connection of the ethernet cable made the difference. But the Airport does not yet function properly. When I unplug the ethernet cable I cannot connect to the internet. When I select my network in the menu bar, the Airport sign "radiates" for some seconds, but no connection is made.
Any suggestion how to solve this is much welcome. -
Joining select statements-performance problem
Here two cases are there.Is it posiible to combine the two cases and make it one? I am using OR in the select statement, performance is very bad, i want to improve it.Is there any chance of avoiding that...
1.
select vbeln from vbfa into itab-vbeln where vbelv = final_data-xblnr1
or vbelv = final_data-xblnr2.
select single vbeln from vbrk into tabvbrk-vbeln
where vbeln = itab-vbeln and fkart = 'RTS'.
if sy-subrc eq 0.
move tabvbrk-vbeln to final_data-vbeln1.
modify final_data.
endif.
endselect.
2.
select vbeln from vbfa into itab-vbeln where vbelv = final_data-xblnr1
or vbelv = final_data-xblnr2.
select single vbeln from vbrk into tabvbrk-vbeln
where vbeln = itab-vbeln and fkart = 'ZTR'.
if sy-subrc eq 0.
move tabvbrk-vbeln to final_data-vbeln2.
modify final_data.
endif.
endselect.
Thanks,
fractalThe first main thing is dont use select... endselect.
select vbeln from vbfa into itab-vbeln where vbelv = final_data-xblnr1
or vbelv = final_data-xblnr2.
U can use
select vbeln from vbfa into
corresponding fields of table itab
for all entries in final_data
where vbelv = final_data-xblnr1
or vbelv = final_data-xblnr2.
Instead of this
select single vbeln from vbrk into tabvbrk-vbeln
where vbeln = itab-vbeln and fkart = 'RTS'.
if sy-subrc eq 0.
move tabvbrk-vbeln to final_data-vbeln1.
modify final_data.
endif.
endselect.
Use
select vbeln from vbrk
appending table final_data
where vbeln = itab-vbeln
and fkart = 'RTS'.
if sy-subrc eq 0.
endif.
Try like this.
Hope this helps.
Kindly reward points for the answer which helped u and helped to solve the problem. -
Using functions in select statement(joining 5 tables) taking long time in Oracle
Hi,
I have created a query in oracle which joins 5 tables and uses two functions(function names are 'ca_concat' and 'ca_concat_noseq').
Query takes approximately 40 secs to execute around 12000 records. If I remove the functions from query it excutes within a second..
Note : I have used the oracle SQL Developer for testing the query.
It would be appriciated if anybody helps me to improve the perfomance of the query.
Below are the querie with and without functions:
1. Query with functions:
select
imsAuditEvent12.id as ID,
imsAuditEvent12.audit_time as AUDIT_TIME,
imsAuditEvent12.admin_dn as ADMIN_DN,
imsAuditEvent12.admin_name as ADMIN_NAME,
imsAuditEvent12.event_name as EVENT_NAME,
imsAuditEvent12.event_description as EVENT_DESCRIPTION,
imsAuditEvent12.event_state as EVENT_STATE,
imsAuditEvent12.envname as ENVNAME,
imsAuditTaskSession12.task_name as TASK_NAME,
imsAuditTaskSession12.id as TASK_ID,
imsAuditTaskSession12.task_description as TASK_DESCRIPTION,
imsAuditTaskSession12.task_priority as TASK_PRIORITY,
S1.OBJECT_ID,
S1.OBJECT_NAME as OBJECT_NAME,
S1.OBJECT_TYPE as OBJECT_TYPE,
S2.ATTRIBUTE_NAME as ATTRIBUTE_NAME,
S2.ATTRIBUTE_OLDVALUES as ATTRIBUTE_OLDVALUES,
S2.ATTRIBUTE_NEWVALUES as ATTRIBUTE_NEWVALUES,
S3.OBJECT_DN as OBJECT_DN,
S3.OBJECT_TYPE as IMSOBJECT_TYPE,
S3.CONTAINER_NAME as CONTAINER_NAME,
S3.CONTAINER_DN as CONTAINER_DN,
S3.CONTAINER_TYPE as CONTAINER_TYPE
from
imsAuditEvent12 LEFT JOIN imsAuditTaskSession12 ON imsAuditTaskSession12.id=imsAuditEvent12.tasksession_id LEFT JOIN
(select parent_event_id,
ca_concat('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.object_name','imsAuditEventObject12') as OBJECT_NAME,
ca_concat('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.object_type','imsAuditEventObject12') as OBJECT_TYPE,
ca_concat_noseq('imsAuditEventObject12.parent_event_id',parent_event_id,'imsAuditEventObject12.ID','imsAuditEventObject12') as OBJECT_ID
from
imsAuditEventObject12 group by parent_event_id) S1
ON imsAuditEvent12.id = S1.parent_event_id LEFT JOIN
(select
parent_object_id,
ca_concat('parent_object_id',parent_object_id,'attribute_name','imsauditobjectattributes12') as ATTRIBUTE_NAME,
ca_concat('parent_object_id',parent_object_id,'attribute_oldvalue','imsauditobjectattributes12') as ATTRIBUTE_OLDVALUES ,
ca_concat('parent_object_id',parent_object_id,'attribute_newvalue','imsauditobjectattributes12') as ATTRIBUTE_NEWVALUES
from
imsauditobjectattributes12 group by parent_object_id) S2
ON S1.OBJECT_ID = S2.parent_object_id LEFT JOIN
(select
parent_event_id,
ca_concat('parent_event_id',parent_event_id,'OBJECT_DN','imsauditobjectrelationship12') as OBJECT_DN,
ca_concat('parent_event_id',parent_event_id,'OBJECT_TYPE','imsauditobjectrelationship12') as OBJECT_TYPE ,
ca_concat('parent_event_id',parent_event_id,'CONTAINER_NAME','imsauditobjectrelationship12') as CONTAINER_NAME,
ca_concat('parent_event_id',parent_event_id,'CONTAINER_DN','imsauditobjectrelationship12') as CONTAINER_DN,
ca_concat('parent_event_id',parent_event_id,'CONTAINER_TYPE','imsauditobjectrelationship12') as CONTAINER_TYPE
from
imsauditobjectrelationship12 group by parent_event_id) S3
ON imsAuditEvent12.id =S3.parent_event_id where imsauditevent12.id > 0 and imsauditevent12.id <12000 order by imsauditevent12.id ASC;
2. Query without using functions:
select * from imsauditeventobject12 left join imsauditevent12 on imsauditeventobject12.id=imsauditevent12.id left join imsauditobjectattributes12 on imsauditeventobject12.id=imsauditobjectattributes12.parent_object_id left join imsaudittasksession12 on imsauditevent12.tasksession_id=imsaudittasksession12.id left join imsAuditObjectRelationship12 on imsAuditEvent12.id =imsAuditObjectRelationship12.parent_event_id where imsauditevent12.id >0 and imsauditevent12.id < 12000 order by imsauditevent12.id asc;
Thanks,
BadriHi,
Please find the below more information about the query.
DB version: Oracle 11g Enterprise Edition Release 11.2.0.1.0
Below are source of the functions:
create or replace function ca_concat( ca_key_name in varchar2,
ca_key_val in varchar2,
ca_other_col_name in varchar2,
ca_tname in varchar2 )
return varchar2
as
type rc is ref cursor;
l_str varchar2(32000);
l_sep varchar2(1);
l_val varchar2(32000);
l_count number(6);
l_cur rc;
begin
l_count :=1;
l_str := '';
open l_cur for 'select '|| ca_other_col_name ||'
from '|| ca_tname || '
where ' || ca_key_name || ' = '
using ca_key_val;
loop
fetch l_cur into l_val;
l_val := SUBSTR(l_val,0,102);
exit when (l_cur%notfound or l_count > 38);
l_str := l_str || l_sep || l_count || '.' || l_val;
l_sep := ',';
l_count := l_count + 1;
end loop;
close l_cur;
return l_str;
end;
create or replace function ca_concat_noseq( ca_key_name in varchar2,
ca_key_val in varchar2,
ca_other_col_name in varchar2,
ca_tname in varchar2 )
return varchar2
as
type rc is ref cursor;
l_str nvarchar2(32000);
l_sep varchar2(1);
l_val varchar2(32000);
l_count number(6);
l_cur rc;
begin
l_count :=1;
open l_cur for 'select '||ca_other_col_name||'
from '|| ca_tname || '
where ' || ca_key_name || ' = '
using ca_key_val;
loop
fetch l_cur into l_val;
exit when (l_cur%notfound or length(l_val)>3000 or l_count>1);
l_str := l_str || l_sep || l_val ;
l_sep := ',';
l_count := l_count + 1;
end loop;
close l_cur;
return l_str;
end;
Below are the tables structures:
DESC imsauditevent12;
Name Null Type
ID NOT NULL NUMBER
TASKSESSION_ID NOT NULL NUMBER
TASKSESSION_OID VARCHAR2(100)
PARENT_EVENT_OID VARCHAR2(100)
AUDIT_TIME NOT NULL TIMESTAMP(6)
EVENT_OID NOT NULL VARCHAR2(100)
ADMIN_DN NOT NULL VARCHAR2(512)
ADMIN_NAME VARCHAR2(255)
EVENT_NAME NOT NULL VARCHAR2(255)
EVENT_DESCRIPTION VARCHAR2(4000)
EVENT_STATE VARCHAR2(100)
ENVNAME NOT NULL VARCHAR2(100)
ENV_OID NOT NULL VARCHAR2(100)
DESC imsauditeventobject12;
Name Null Type
ID NOT NULL NUMBER
PARENT_EVENT_ID NOT NULL NUMBER
AUDIT_TIME NOT NULL TIMESTAMP(6)
OBJECT_TYPE NOT NULL VARCHAR2(100)
OBJECT_NAME VARCHAR2(255)
DESC imsauditobjectattributes12;
Name Null Type
ID NOT NULL NUMBER
PARENT_OBJECT_ID NOT NULL NUMBER
AUDIT_TIME NOT NULL TIMESTAMP(6)
DISPLAY_NAME VARCHAR2(255)
ATTRIBUTE_NAME NOT NULL VARCHAR2(255)
ATTRIBUTE_OLDVALUE VARCHAR2(4000)
ATTRIBUTE_NEWVALUE VARCHAR2(4000)
DESC imsaudittasksession12;
Name Null Type
ID NOT NULL NUMBER
PARENT_TS_OID VARCHAR2(100)
PARENT_EVENT_OID VARCHAR2(100)
AUDIT_TIME NOT NULL TIMESTAMP(6)
TASKSESSION_OID NOT NULL VARCHAR2(100)
ADMIN_DN NOT NULL VARCHAR2(512)
ADMIN_NAME VARCHAR2(255)
TASK_NAME VARCHAR2(255)
TASK_TAG NOT NULL VARCHAR2(255)
TASK_DESCRIPTION VARCHAR2(4000)
TASK_PRIORITY NUMBER
STATE NOT NULL VARCHAR2(100)
ENVNAME NOT NULL VARCHAR2(100)
ENV_OID NOT NULL VARCHAR2(100)
DESC imsAuditObjectRelationship12;
Name Null Type
ID NOT NULL NUMBER
PARENT_EVENT_ID NOT NULL NUMBER
AUDIT_TIME NOT NULL TIMESTAMP(6)
OBJECT_TYPE NOT NULL VARCHAR2(100)
OBJECT_DN NOT NULL VARCHAR2(512)
CONTAINER_TYPE NOT NULL VARCHAR2(100)
OBJECT_NAME NOT NULL VARCHAR2(255)
CONTAINER_NAME NOT NULL VARCHAR2(255)
CONTAINER_DN NOT NULL VARCHAR2(512)
OPERATION NOT NULL VARCHAR2(50)
Thanks,
Badri
Maybe you are looking for
-
ITunes 7, software 1.2 videos gone from iPod
I recently updated to iTunes 7 so that i would be able to purchase and download a show from the music store. After my iPod was finished updating with the new software all of my shows were gone from my iPod except for the one i just bought. They are s
-
How to determine IE type(32 bit or 64 bit) in a task sequence while updating Java
How to determine IE type(32 bit or 64 bit) in a task sequence Hi, Currently i have to update new version of Java after removing all the previous existing version of Java by using TS in SCCM 2007. we have both 32 bit and 64 bit browser in the environm
-
Hi, Currently translation date for foreign currency is taken as posting date. We need to change the same to Document Date. We have tried the substitution rule with user exit, but unfortunately could not get thru. Can anyone suggest the solution for
-
Photobooth didn't come with my Mac, is there any way I can download it?
I just noticed that my Macbook didn't have Photo booth built in... I tried to download it but there's no option and it says my photo booth is outdates (2.3 version or something), and it doesn't have an option to update it. Is there any way I can re d
-
Airport Express and Linksys WRT54g
I can't get my AE to find my Linksys WRT54g router. How can I make this work together Thanks Pete