Left joins on multi-million rows
i have a simple query doing left joining on several tables, upward of 7 tables. each table has several hundred million rows.
tblA is 1:M tblB and tblB is 1:M tblC and so on.
how to tune a query liked that?
sample query is
select distinct
a.col,b.col,c.col
from tblA a left join tblB b
on a.id=b.id
and a.col is not null
left join tblC
on b.id=c.id
and c.col > criteria
thanks.
hi
a simple query is liked
SELECT my_DEP.description,
my_DEP.addr_id,
hundredRowsTbl.address,
5MillTbl.checkin_TIME,
5MillTbl.checkout_TIME,
hundredRowsTbl.ID2,
5MillTbl.ID,
5MillTbl.col2,
my_DEP.col3,
5MillTbl.col13,
hundreds.desc,
50mmTbl.col6,
50mmTbl.col5,
5MillTbl.col33
FROM
my.5MillTbl 5MillTbl
LEFT OUTER JOIN
my.50mmTbl 50mmTbl
ON 5MillTbl.ID = 50mmTbl.ID
LEFT OUTER JOIN my.hundreds hundreds
ON 5MillTbl.banding =
hundreds.banding
INNER JOIN my.my_DEP my_DEP
ON 5MillTbl.organization_ID = my_DEP.organization_ID
INNER JOIN my.my_40millTbl
ON 5MillTbl.seqID = my_40millTbl.seqID
LEFT OUTER JOIN my.hundredRowsTbl hundredRowsTbl
ON my_DEP.addr_id = hundredRowsTbl.ID2
LEFT OUTER JOIN my.30millTbl 30millTbl
ON my_DEP.organization_ID = 30millTbl.dept_id
WHERE 1=1
AND 5MillTbl.ID IS NOT NULL
AND ( 5MillTbl.checkout_TIME >= TO_DATE ('01-01-2009 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
AND 5MillTbl.checkout_TIME <TO_DATE ('12-31-2010 00:00:00', 'DD-MM-YYYY HH24:MI:SS')
AND ( 5MillTbl.col2 IS NULL
OR NOT (5MillTbl.col2 = 5
OR 5MillTbl.col2 = 6)
AND 5MillTbl.ID IS NOT NULL
AND 30millTbl.TYPE= '30'
AND my_DEP.addr_id = 61
Similar Messages
-
Left join and where clause with not equal ( ) returns too many rows
Say I have something like this
Table A
=========
Id
OrderNum
Date
StoreName
AddressKey
Table B
========
Id
StreetNumber
City
State
select a.* from [Table A] a
left join [Table B] b on a.AddressKey = b.Id
where a.StoreName <> 'Burger place'
The trouble is that the above query still returns rows that have StoreName = 'Burger place'
One way Ive handled this is to use a table expression, select everything into that, then select from the CTE and apply the filter there. How could you handle it in the same query however?Hi Joe,
Thanks for your notes.
INT SURROGATE PRIMARY KEY provides a small footprint JOIN ON column. Hence performance gain and simple JOIN programming. In the Addresses table, address_id is 4 bytes as opposed to 15 bytes san. Similarly for the Orders table.
INT SURROGATE PRIMARY KEY is a meaningless number which can be duplicated at will in other tables as FOREIGN KEY. Having a meaningful PRIMARY KEY violates the RDBMS basics about avoiding data duplication. If I make CelebrityName (Frank Sinatra)
a PRIMARY KEY, I have to duplicate "Frank Sinatra" as an FK wherever it needed as opposed to duplicating SURROGATE PRIMARY KEY CelebrityID (79) a meaningless number.
This is how we design in SQL Server world.
QUOTE from Wiki: "
Advantages[edit]
Immutability[edit]
Surrogate keys do not change while the row exists. This has the following advantages:
Applications cannot lose their reference to a row in the database (since the identifier never changes).
The primary or natural key data can always be modified, even with databases that do not support cascading updates across related
foreign keys.
Requirement changes[edit]
Attributes that uniquely identify an entity might change, which might invalidate the suitability of natural keys. Consider the following example:
An employee's network user name is chosen as a natural key. Upon merging with another company, new employees must be inserted. Some of the new network user names create conflicts because their user names were generated independently (when the companies
were separate).
In these cases, generally a new attribute must be added to the natural key (for example, an
original_company column). With a surrogate key, only the table that defines the surrogate key must be changed. With natural keys, all tables (and possibly other, related software) that use the natural key will have to change.
Some problem domains do not clearly identify a suitable natural key. Surrogate key avoids choosing a natural key that might be incorrect.
Performance[edit]
Surrogate keys tend to be a compact data type, such as a four-byte integer. This allows the database to query the single key column faster than it could multiple columns. Furthermore a non-redundant distribution of keys causes the resulting
b-tree index to be completely balanced. Surrogate keys are also less expensive to join (fewer columns to compare) than
compound keys.
Compatibility[edit]
While using several database application development systems, drivers, and
object-relational mapping systems, such as
Ruby on Rails or
Hibernate, it is much easier to use an integer or GUID surrogate keys for every table instead of natural keys in order to support database-system-agnostic operations and object-to-row mapping.
Uniformity[edit]
When every table has a uniform surrogate key, some tasks can be easily automated by writing the code in a table-independent way.
Validation[edit]
It is possible to design key-values that follow a well-known pattern or structure which can be automatically verified. For instance, the keys that are intended to be used in some column of some table might be designed to "look differently from"
those that are intended to be used in another column or table, thereby simplifying the detection of application errors in which the keys have been misplaced. However, this characteristic of the surrogate keys should never be used to drive any of the logic
of the applications themselves, as this would violate the principles of
Database normalization"
LINK: http://en.wikipedia.org/wiki/Surrogate_key
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
Getting One to Many Left Join to be in One Result Row...
11G APEX 4.2
At this time I don't have access to make a view or anything like that. Just select access to the data.
BEGIN
for i in (
SELECT CAA.NODE_NAME THENODE,CNF.FEATURE_TYPE CNFFT from CMS.CMS_APP_ASSIGN "CAA"
LEFT JOIN CMS.CMS_NODE_FEATURE "CNF" on CAA.NODE_NAME=CNF.NODE_NAME
WHERE CAA.NODE_APP = :WHICHAPP and CAA.REMOVE_DT is NULL)
LOOP
dbms_output.put_line(i.THENODE||'--'||i.CNFFT||'<BR>');
END LOOP;
END;
When this returns there is a row for each of the left joins.
server1--CPUCount<BR>
server1--ContactInfo<BR>
server1--ContactInfo<BR>
server1--ContactInfo<BR>
server2--CPUCount<BR>
What I would like to do it just have one row:
NODENAME
CPUCount
Contactinfo
Contact Info
Contact Info
ETC
server1
value1
value2
value4
c
ThanksHi,
Taking 1 column from N rows, and transforming that into N columns on 1 row is called Pivoting.
The forum FAQ has a page on this subject. See https://forums.oracle.com/message/9362005#9362005
While you're in the Forum FAQ, also see https://forums.oracle.com/message/9362002 -
I am tuning a SELECT query with 36 Left Joins in addition to normal Inner Joins and a View.
I have used the RESULT_CACHE hint with some success.
I have tried the LEADING hint and USE_MERGE with no success.
Is there an Undocumented HINT and that may assist me?
Thanks
BRADHi, Brad,
Welcome to the forum!
970109 wrote:
I am tuning a SELECT query with 36 Left Joins in addition to normal Inner Joins and a View.Why does the query need so many outer joins? Could there be a bad table design behind this problem? Post a simplified version ot the problem (with maybe 3 tables that need to be outer-joined). Post CREATE TABLE and INSERT statements for a little sample data (relevant columns only), the results you want from that sample data, and an explanation of how you get those results from that data.
See the forum FAQ {message:id=9360002}
For all tuning problems, see {message:id=9360003} -
Hi Everyone,
Can someone pls shed some light on the situation below
I am understanding alot of what Michael and Rod wrote.... with my prev. post of LEFT JOIN and testing for
not null and doing a double Boolean OR etc.
- but- AM NOT understanding why the IS NOT NULL works, without the double boolean OR
Pls help... have to explain what left join means to user tomm. I'm going to demo the query below and
not the one with the double boolean OR bec. maybe too much info to present at one sitting. tx, sandra
=====================
the query below is left joining the STUDENT table to
HOLD table.
The HOLD table - contains rows for students who have holds on their record.
a student can have more than one hold (health, HIPAA, basic life saving course)
BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
1 to many relationship.
Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
me having to code IS NOT NULL twice....
Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
the IS NOT NULL condition.
I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
and how they should create a query. I need to come up with rules.
If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
thx sooo much, Sandra
SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
ORDER BY O100384.NAME ASCHi,
OK, I will try to explain this. When you outer join table B to table A then the rows in table A which do not match any rows in table B will returned with NULL in the columns from the table B.
Oracle uses the syntax ( +) for outer joins. Now if you add another condition using the ( +) syntax (as shown below) the condition will be processed before the table is joined. Therefore if table A does not match any rows in table B which have col2=1 then the row from table A will be returned with NULLs for the table B columns.
SELECT A.col1, B.col1
FROM A, B
WHERE A.col1 = B.col1( +)
AND B.col2( +)=1
Now, if the condition B.col2=1 was used instead then the condition would be processed after the join and therefore the rows from table A that were joined to table B but did not meet the condition would not be returned by the query.
This applies to a WHERE clause and to the HAVING clause, but with one exception. If you use the ( +) within a group function in a HAVING clause then the ( +) will have no affect because the condition must be processed after group by and group by can only be processed after the join. Therefore MAX(B.col2( +)) = 1 is processed after the join even through it uses the ( +) syntax.
You cannot use an OR or an IN with the ( +) syntax because the meaning of the OR in this situation is ambiguous, is the OR done before or after the join. A query with an OR or IN in an outer will fail with an Oracle ORA-01719 error. Discoverer recognises this situation and removes the ( +) so that the error does not occur. However, without the ( +) the conditions are processed after the join.
Using the ( +) with IS NULL, e.g. col2( +) IS NOT NULL works in the same way. You just have to remember that the col2( +) could be NULL as a result of the outer join and therefore if the condition is processed after the query then the IS NOT NULL will remove the outer joined rows.
Hope that is clear.
Rod West -
Testing for IS NOT NULL with left join tables
Dear Experts,
The query is showing the NULL rows in the query below....
Any ideas, advice please? tx, sandra
This is the sql inspector:
SELECT O100321.FULL_NAME_LFMI, O100321.ID, O100404.ID, O100321.ID_SOURCE
, O100404.NAME, O100321.PERSON_UID, O100404.PERSON_UID, O100404.VISA_TYPE
FROM ODSMGR.PERSON O100321
, ODSMGR.VISA O100404
WHERE ( ( O100321.PERSON_UID = O100404.PERSON_UID(+) ) ) AND ( O100404.VISA_TYPE(+) IS NOT NULL )Hi Everyone,
I am understanding alot of what Michael and Rod wrote.... I am just puzzled over the following:
the query below is left joining the STUDENT table to
HOLD table.
The HOLD table - contains rows for students who have holds on their record.
a student can have more than one hold (health, HIPAA, basic life saving course)
BUT, for this query: I'm only interested that a hold exists, so I'm choosing MAX on hold desc.
Selecting a MAX, helps me, bec. it reduces my join to a 1 to 1 relationship, instead of
1 to many relationship.
Before I posted this thread at all, the LEFT JOIN below testing for IS NOT NULL worked w/o
me having to code IS NOT NULL twice....
Is that because, what's happening "behind the scenes" is that a temporary table containing all max rows is being
created, for which Discoverer has no predefined join instructions, so it's letting me do a LEFT JOIN and have
the IS NOT NULL condition.
I would so appreciate clarification. I have a meeting on Tues, for which I have to explain LEFT JOINS to the user
and how they should create a query. I need to come up with rules.
If I feel "clear", I asked my boss to buy Camtasia videocast software to create a training clip for user to follow.
Also, if any Banner user would like me to email the DIS query to run on their machine, I would be glad to do so.
thx sooo much, Sandra
SELECT O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID, MAX(O100255.HOLD_DESC)
FROM ODSMGR.HOLD O100255, ODSMGR.STUDENT O100384
WHERE ( ( O100384.PERSON_UID = O100255.PERSON_UID(+) ) ) AND ( O100384.ACADEMIC_PERIOD = '200820' )
GROUP BY O100384.ACADEMIC_PERIOD, O100255.ID, O100384.ID, O100255.NAME, O100384.NAME, O100255.PERSON_UID, O100384.PERSON_UID
HAVING ( ( MAX(O100255.HOLD_DESC(+)) ) IS NOT NULL )
ORDER BY O100384.NAME ASC -
Insert/select one million rows at a time from source to target table
Hi,
Oracle 10.2.0.4.0
I am trying to insert around 10 million rows into table target from source as follows:
INSERT /*+ APPEND NOLOGGING */ INTO target
SELECT *
FROM source f
WHERE
NOT EXISTS(SELECT 1 from target m WHERE f.col1 = m.col2 and f.col2 = m.col2);There is a unique index on target table on col1,col2
I was having issues with undo and now I am getting the follwing error with temp space
ORA-01652: unable to extend temp segment by 64 in tablespace TEMPI believce it would be easier if I did bulk insert one million rows at a time and commit.
I appriciate any advice on this please.
Thanks,
Ashok902986 wrote:
NOT EXISTS(SELECT 1 from target m WHERE f.col1 = m.col2 and f.col2 = m.col2);
I don't know if it has any bearing on the case, but is that WHERE clause on purpose or a typo? Should it be:
NOT EXISTS(SELECT 1 from target m WHERE f.col1 = m.COL1 and f.col2 = m.col2);Anyway - how much of your data already exists in target compared to source?
Do you have 10 million in source and very few in target, so most of source will be inserted into target?
Or do you have 9 million already in target, so most of source will be filtered away and only few records inserted?
And what is the explain plan for your statement?
INSERT /*+ APPEND NOLOGGING */ INTO target
SELECT *
FROM source f
WHERE
NOT EXISTS(SELECT 1 from target m WHERE f.col1 = m.col2 and f.col2 = m.col2);As your error has to do with TEMP, your statement might possibly try to do a lot of work in temp to materialize the resultset or parts of it to maybe use in a hash join before inserting.
So perhaps you can work towards an explain plan that allows the database to do the inserts "along the way" rather than calculate the whole thing in temp first.
That probably will go much slower (for example using nested loops for each row to check the exists), but that's a tradeoff - if you can't have sufficient TEMP then you may have to optimize for less usage of that resource at the expense of another resource ;-)
Alternatively ask your DBA to allocate more room in TEMP tablespace. Or have the DBA check if there are other sessions using a lot of TEMP in which case maybe you just have to make sure your session is the only one using lots of TEMP at the time you execute. -
3 tables with left joins - bug?
Hello,
i am making query where i encounter problem with left join in oracle. I am using oracle 10g and i prepare simple test case.
he is testing tables and datas - really simple i think:
drop table t1;
drop table t2;
drop table t3;
create table t1 (a number not null);
create table t2 (a number, b number);
create table t3 (b number);
insert into t3 values (1);
insert into t3 values (2);
insert into t3 values (3);
insert into t1 (a) values (1);
insert into t2 (a,b) values (1,1);
insert into t1 (a) values (2);
insert into t2 (a,b) values (2, null);
insert into t1 (a) values (3);
insert into t1 (a) values (4);
insert into t2 (a,b) values (4,1);
insert into t1 (a) values (5);
insert into t2 (a,b) values (5,3);
and now query with left joins:
select
t1.a
, t2.a, t2.b
, t3.b
from
t1, t2, t3
where
t1.a = t2.a (+)
and t2.b = t3.b (+)
and t3.b is null
order by t1.a
i get two rows as result:
A A_1 B B_1
2 2 null null
3 null null null
i expect these rows but when i change my query - i dont want get back t3.b column:
select
t1.a
, t2.a, t2.b
/* , t3.b*/
from
t1, t2, t3
where
t1.a = t2.a (+)
and t2.b = t3.b (+)
and t3.b is null
order by t1.a
i get only one row
A A_1 B
2 2 null
My question is simple how can i only by changing columns getting back change number of returned rows? I must say i dont expect these result i expect two rows again.
Thanks for help.BluShadow wrote:
I think I know what you are getting at.
By testing for null on t3.b when you aren't selecting the column, you are enforcing oracle to perform the join through t2 onto t1, but Oracle can't join because t2 has no matching row (although it's outer joined to t1) and therefore, for the one row it can't actually determine if t3.b is null or not, so that row can't match the conditions in a "true" sense and be displayed. If you select the column then oracle can test its nullness ok. (Perhaps this is a bug, I don't know, it's just how I know it works)If you get different results only by changing the projection part of the query this is a bug and nothing else. I can't reproduce using Oracle 10g XE, I get in both cases shown the expected two rows.
What versions are you using to test this?
SQL>
SQL> select * from v$version
2 where rownum <= 1;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
SQL>
SQL> drop table t1 purge;
Table dropped.
SQL> drop table t2 purge;
Table dropped.
SQL> drop table t3 purge;
Table dropped.
SQL>
SQL> create table t1 (a number not null);
Table created.
SQL> create table t2 (a number, b number);
Table created.
SQL> create table t3 (b number);
Table created.
SQL>
SQL> insert into t3 values (1);
1 row created.
SQL> insert into t3 values (2);
1 row created.
SQL> insert into t3 values (3);
1 row created.
SQL>
SQL> insert into t1 (a) values (1);
1 row created.
SQL> insert into t2 (a,b) values (1,1);
1 row created.
SQL>
SQL> insert into t1 (a) values (2);
1 row created.
SQL> insert into t2 (a,b) values (2, null);
1 row created.
SQL>
SQL> insert into t1 (a) values (3);
1 row created.
SQL>
SQL> insert into t1 (a) values (4);
1 row created.
SQL> insert into t2 (a,b) values (4,1);
1 row created.
SQL>
SQL> insert into t1 (a) values (5);
1 row created.
SQL> insert into t2 (a,b) values (5,3);
1 row created.
SQL>
SQL> commit;
Commit complete.
SQL>
SQL> select t1.a
2 , t2.a, t2.b
3 , t3.b
4 from
5 t1 left outer join t2 on (t1.a = t2.a)
6 left outer join t3 on (t2.b = t3.b)
7 where t3.b is null
8 order by t1.a;
A A B B
2 2
3
SQL>
SQL> select t1.a
2 , t2.a, t2.b
3 -- , t3.b
4 from
5 t1 left outer join t2 on (t1.a = t2.a)
6 left outer join t3 on (t2.b = t3.b)
7 where t3.b is null
8 order by t1.a;
A A B
2 2
3
SQL>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/ -
Query taking more than 1/2 hour for 80 million rows in fact table
Hi All,
I am stuck in this query as it it taking more than 35 mins to execute for 80 million rows. My SLA is less than 30 mins for 160 million rows i.e. double the number.
Below is the query and the Execution Plan.
SELECT txn_id AS txn_id,
acntng_entry_src AS txn_src,
f.hrarchy_dmn_id AS hrarchy_dmn_id,
f.prduct_dmn_id AS prduct_dmn_id,
f.pstng_crncy_id AS pstng_crncy_id,
f.acntng_entry_typ AS acntng_entry_typ,
MIN (d.date_value) AS min_val_dt,
GREATEST (MAX (d.date_value),
LEAST ('07-Feb-2009', d.fin_year_end_dt))
AS max_val_dt
FROM Position_Fact f, Date_Dimension d
WHERE f.val_dt_dmn_id = d.date_dmn_id
GROUP BY txn_id,
acntng_entry_src,
f.hrarchy_dmn_id,
f.prduct_dmn_id,
f.pstng_crncy_id,
f.acntng_entry_typ,
d.fin_year_end_dt
Execution Plan is as:
11 HASH JOIN Cost: 914,089 Bytes: 3,698,035,872 Cardinality: 77,042,414
9 TABLE ACCESS FULL TABLE Date_Dimension Cost: 29 Bytes: 94,960 Cardinality: 4,748
10 TABLE ACCESS FULL TABLE Position_Fact Cost: 913,693 Bytes: 2,157,187,592 Cardinality: 77,042,414
Kindly suggest, how to make it faster.
Regards,
SidThe above is just a part of the query that is taking the maximum time.
Kindly find the entire query and the plan as follows:
WITH MIN_MX_DT
AS
( SELECT
TXN_ID AS TXN_ID,
ACNTNG_ENTRY_SRC AS TXN_SRC,
F.HRARCHY_DMN_ID AS HRARCHY_DMN_ID,
F.PRDUCT_DMN_ID AS PRDUCT_DMN_ID,
F.PSTNG_CRNCY_ID AS PSTNG_CRNCY_ID,
F.ACNTNG_ENTRY_TYP AS ACNTNG_ENTRY_TYP,
MIN (D.DATE_VALUE) AS MIN_VAL_DT,
GREATEST (MAX (D.DATE_VALUE), LEAST (:B1, D.FIN_YEAR_END_DT))
AS MAX_VAL_DT
FROM
proj_PSTNG_FCT F, proj_DATE_DMN D
WHERE
F.VAL_DT_DMN_ID = D.DATE_DMN_ID
GROUP BY
TXN_ID,
ACNTNG_ENTRY_SRC,
F.HRARCHY_DMN_ID,
F.PRDUCT_DMN_ID,
F.PSTNG_CRNCY_ID,
F.ACNTNG_ENTRY_TYP,
D.FIN_YEAR_END_DT),
SLCT_RCRDS
AS (
SELECT
M.TXN_ID,
M.TXN_SRC,
M.HRARCHY_DMN_ID,
M.PRDUCT_DMN_ID,
M.PSTNG_CRNCY_ID,
M.ACNTNG_ENTRY_TYP,
D.DATE_VALUE AS VAL_DT,
D.DATE_DMN_ID,
D.FIN_WEEK_NUM AS FIN_WEEK_NUM,
D.FIN_YEAR_STRT AS FIN_YEAR_STRT,
D.FIN_YEAR_END AS FIN_YEAR_END
FROM
MIN_MX_DT M, proj_DATE_DMN D
WHERE
D.HOLIDAY_IND = 0
AND D.DATE_VALUE >= MIN_VAL_DT
AND D.DATE_VALUE <= MAX_VAL_DT),
DLY_HDRS
AS (
SELECT
S.TXN_ID AS TXN_ID,
S.TXN_SRC AS TXN_SRC,
S.DATE_DMN_ID AS VAL_DT_DMN_ID,
S.HRARCHY_DMN_ID AS HRARCHY_DMN_ID,
S.PRDUCT_DMN_ID AS PRDUCT_DMN_ID,
S.PSTNG_CRNCY_ID AS PSTNG_CRNCY_ID,
SUM
DECODE
PNL_TYP_NM,
:B5, DECODE (NVL (F.PSTNG_TYP, :B2),
:B2, NVL (F.PSTNG_AMNT, 0) * (-1),
NVL (F.PSTNG_AMNT, 0)),
0))
AS MTM_AMT,
NVL (
LAG (
SUM (
DECODE (
PNL_TYP_NM,
:B5, DECODE (NVL (F.PSTNG_TYP, :B2),
:B2, NVL (F.PSTNG_AMNT, 0) * (-1),
NVL (F.PSTNG_AMNT, 0)),
0)))
OVER (
PARTITION BY S.TXN_ID,
S.TXN_SRC,
S.HRARCHY_DMN_ID,
S.PRDUCT_DMN_ID,
S.PSTNG_CRNCY_ID
ORDER BY S.VAL_DT),
0)
AS YSTDY_MTM,
SUM (
DECODE (
PNL_TYP_NM,
:B4, DECODE (NVL (F.PSTNG_TYP, :B2),
:B2, NVL (F.PSTNG_AMNT, 0) * (-1),
NVL (F.PSTNG_AMNT, 0)),
0))
AS CASH_AMT,
SUM (
DECODE (
PNL_TYP_NM,
:B3, DECODE (NVL (F.PSTNG_TYP, :B2),
:B2, NVL (F.PSTNG_AMNT, 0) * (-1),
NVL (F.PSTNG_AMNT, 0)),
0))
AS PAY_REC_AMT,
S.VAL_DT,
S.FIN_WEEK_NUM,
S.FIN_YEAR_STRT,
S.FIN_YEAR_END,
NVL (TRUNC (F.REVSN_DT), S.VAL_DT) AS REVSN_DT,
S.ACNTNG_ENTRY_TYP AS ACNTNG_ENTRY_TYP
FROM
SLCT_RCRDS S,
proj_PSTNG_FCT F,
proj_ACNT_DMN AD,
proj_PNL_TYP_DMN PTD
WHERE
S.TXN_ID = F.TXN_ID(+)
AND S.TXN_SRC = F.ACNTNG_ENTRY_SRC(+)
AND S.HRARCHY_DMN_ID = F.HRARCHY_DMN_ID(+)
AND S.PRDUCT_DMN_ID = F.PRDUCT_DMN_ID(+)
AND S.PSTNG_CRNCY_ID = F.PSTNG_CRNCY_ID(+)
AND S.DATE_DMN_ID = F.VAL_DT_DMN_ID(+)
AND S.ACNTNG_ENTRY_TYP = F.ACNTNG_ENTRY_TYP(+)
AND SUBSTR (AD.ACNT_NUM, 0, 1) IN (1, 2, 3)
AND NVL (F.ACNT_DMN_ID, 1) = AD.ACNT_DMN_ID
AND NVL (F.PNL_TYP_DMN_ID, 1) = PTD.PNL_TYP_DMN_ID
GROUP BY
S.TXN_ID,
S.TXN_SRC,
S.DATE_DMN_ID,
S.HRARCHY_DMN_ID,
S.PRDUCT_DMN_ID,
S.PSTNG_CRNCY_ID,
S.VAL_DT,
S.FIN_WEEK_NUM,
S.FIN_YEAR_STRT,
S.FIN_YEAR_END,
TRUNC (F.REVSN_DT),
S.ACNTNG_ENTRY_TYP,
F.TXN_ID)
SELECT
D.TXN_ID,
D.VAL_DT_DMN_ID,
D.REVSN_DT,
D.TXN_SRC,
D.HRARCHY_DMN_ID,
D.PRDUCT_DMN_ID,
D.PSTNG_CRNCY_ID,
D.YSTDY_MTM,
D.MTM_AMT,
D.CASH_AMT,
D.PAY_REC_AMT,
MTM_AMT + CASH_AMT + PAY_REC_AMT AS DLY_PNL,
SUM (
MTM_AMT + CASH_AMT + PAY_REC_AMT)
OVER (
PARTITION BY D.TXN_ID,
D.TXN_SRC,
D.HRARCHY_DMN_ID,
D.PRDUCT_DMN_ID,
D.PSTNG_CRNCY_ID,
D.FIN_WEEK_NUM || D.FIN_YEAR_STRT || D.FIN_YEAR_END
ORDER BY D.VAL_DT)
AS WTD_PNL,
SUM (
MTM_AMT + CASH_AMT + PAY_REC_AMT)
OVER (
PARTITION BY D.TXN_ID,
D.TXN_SRC,
D.HRARCHY_DMN_ID,
D.PRDUCT_DMN_ID,
D.PSTNG_CRNCY_ID,
D.FIN_YEAR_STRT || D.FIN_YEAR_END
ORDER BY D.VAL_DT)
AS YTD_PNL,
D.ACNTNG_ENTRY_TYP AS ACNTNG_PSTNG_TYP,
'EOD ETL' AS CRTD_BY,
SYSTIMESTAMP AS CRTN_DT,
NULL AS MDFD_BY,
NULL AS MDFCTN_DT
FROM
DLY_HDRS D
Plan
SELECT STATEMENT ALL_ROWSCost: 11,950,256 Bytes: 3,369,680,886 Cardinality: 7,854,734
25 WINDOW SORT Cost: 11,950,256 Bytes: 3,369,680,886 Cardinality: 7,854,734
24 WINDOW SORT Cost: 11,950,256 Bytes: 3,369,680,886 Cardinality: 7,854,734
23 VIEW Cost: 10,519,225 Bytes: 3,369,680,886 Cardinality: 7,854,734
22 WINDOW BUFFER Cost: 10,519,225 Bytes: 997,551,218 Cardinality: 7,854,734
21 SORT GROUP BY Cost: 10,519,225 Bytes: 997,551,218 Cardinality: 7,854,734
20 HASH JOIN Cost: 10,296,285 Bytes: 997,551,218 Cardinality: 7,854,734
1 TABLE ACCESS FULL TABLE proj_PNL_TYP_DMN Cost: 3 Bytes: 45 Cardinality: 5
19 HASH JOIN Cost: 10,296,173 Bytes: 2,695,349,628 Cardinality: 22,841,946
5 VIEW VIEW index$_join$_007 Cost: 3 Bytes: 84 Cardinality: 7
4 HASH JOIN
2 INDEX FAST FULL SCAN INDEX (UNIQUE) proj_ACNT_DMN_PK Cost: 1 Bytes: 84 Cardinality: 7
3 INDEX FAST FULL SCAN INDEX (UNIQUE) proj_ACNT_DMN_UNQ Cost: 1 Bytes: 84 Cardinality: 7
18 HASH JOIN RIGHT OUTER Cost: 10,293,077 Bytes: 68,925,225,244 Cardinality: 650,237,974
6 TABLE ACCESS FULL TABLE proj_PSTNG_FCT Cost: 913,986 Bytes: 4,545,502,426 Cardinality: 77,042,414
17 VIEW Cost: 7,300,017 Bytes: 30,561,184,778 Cardinality: 650,237,974
16 MERGE JOIN Cost: 7,300,017 Bytes: 230,184,242,796 Cardinality: 650,237,974
8 SORT JOIN Cost: 30 Bytes: 87,776 Cardinality: 3,376
7 TABLE ACCESS FULL TABLE proj_DATE_DMN Cost: 29 Bytes: 87,776 Cardinality: 3,376
15 FILTER
14 SORT JOIN Cost: 7,238,488 Bytes: 25,269,911,792 Cardinality: 77,042,414
13 VIEW Cost: 1,835,219 Bytes: 25,269,911,792 Cardinality: 77,042,414
12 SORT GROUP BY Cost: 1,835,219 Bytes: 3,698,035,872 Cardinality: 77,042,414
11 HASH JOIN Cost: 914,089 Bytes: 3,698,035,872 Cardinality: 77,042,414
9 TABLE ACCESS FULL TABLE proj_DATE_DMN Cost: 29 Bytes: 94,960 Cardinality: 4,748
10 TABLE ACCESS FULL TABLE proj_PSTNG_FCT Cost: 913,693 Bytes: 2,157,187,592 Cardinality: 77,042,414 -
Inconsistent results with ANSI LEFT JOIN on 9iR2
Is this a known issue? Is it solved in 10g?
With the following data setup, I get inconsistent results. It seems to be linked to the combination of using LEFT JOIN with the NULL comparison within the JOIN.
create table titles (title_id int, title varchar(50));
insert into titles values (1, 'Red Book');
insert into titles values (2, 'Yellow Book');
insert into titles values (3, 'Blue Book');
insert into titles values (4, 'Orange Book');
create table sales (stor_id int, title_id int, qty int, email varchar(60));
insert into sales values (1, 1, 1, '[email protected]'));
insert into sales values (1, 2, 1, '[email protected]');
insert into sales values (3, 3, 4, null);
insert into sales values (3, 4, 5, '[email protected]');
SQL> SELECT titles.title_id, title, qty
2 FROM titles LEFT OUTER JOIN sales
3 ON titles.title_id = sales.title_id
4 AND stor_id = 3
5 AND sales.email is not null
6 ;
TITLE_ID TITLE QTY
4 Orange Book 5
3 Blue Book
1 Red Book
2 Yellow Book
SQL>
SQL> SELECT titles.title_id, title, qty
2 FROM titles LEFT OUTER JOIN sales
3 ON titles.title_id = sales.title_id
4 AND 3 = stor_id
5 AND sales.email is not null;
TITLE_ID TITLE QTY
2 Yellow Book 1
4 Orange Book 5
3 Blue Book
1 Red Book
It seems to matter what order I specify the operands stor_id = 3, or 3 = stor_id.
In the older (+) environment, I would understand this, but here? I'm pretty sure most other databases don't care about the order.
thanks for your insight
KevinDon't have a 9i around right now to test ... but in 10 ...
SQL> create table titles (title_id int, title varchar(50));
Â
Table created.
Â
SQL> insert into titles values (1, 'Red Book');
Â
1 row created.
Â
SQL> insert into titles values (2, 'Yellow Book');
Â
1 row created.
Â
SQL> insert into titles values (3, 'Blue Book');
Â
1 row created.
Â
SQL> insert into titles values (4, 'Orange Book');
Â
1 row created.
Â
SQL> create table sales (stor_id int, title_id int, qty int, email varchar(60));
Â
Table created.
Â
SQL> insert into sales values (1, 1, 1, '[email protected]');
Â
1 row created.
Â
SQL> insert into sales values (1, 2, 1, '[email protected]');
Â
1 row created.
Â
SQL> insert into sales values (3, 3, 4, null);
Â
1 row created.
Â
SQL> insert into sales values (3, 4, 5, '[email protected]');
Â
1 row created.
Â
SQL> SELECT titles.title_id, title, qty
2 FROM titles LEFT OUTER JOIN sales
3 ON titles.title_id = sales.title_id
4 AND stor_id = 3
5 AND sales.email is not null
6 ;
Â
TITLE_ID TITLE QTY
4 Orange Book 5
3 Blue Book
1 Red Book
2 Yellow Book
Â
SQL>
SQL> SELECT titles.title_id, title, qty
2 FROM titles LEFT OUTER JOIN sales
3 ON titles.title_id = sales.title_id
4 AND 3 = stor_id
5 AND sales.email is not null;
Â
TITLE_ID TITLE QTY
4 Orange Book 5
3 Blue Book
1 Red Book
2 Yellow Book
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options -
Don'T repeat item with a LEFT JOIN QUERY
Hello,
I would like to know how display the following results:
*Name*: John Fox
*Sales:* 1- LAPTOP
2- HARDDRIVE
3- COMPUTERHere is my 2 tables: CUSTOMER and SALES
CUSTOMER
ID NAME GENDER
1 John Mayer F
2 Melissa John F
3 Julie Black F
4 Mickael Fox M
5 John Fox M
SALES
ID ID_CUSTOMER TYPE
1 1 Boat
2 1 TV
3 4 CD PLAYER
4 5 LAPTOP
5 5 HARDDRIVE
6 5 COMPUTER
My QUERY
SELECT customer.Name as NAME, customer.Gender, sales.TYPE
from customer
LEFT JOIN sales
ON customer.ID = sales.ID_CUSTOMER
WHERE customer.Name = 'John Fox'The problem: If I use the default template, I have:
NAME GENDER TYPE
John Fox M LAPTOP
John Fox M HARDDRIVE
John Fox M COMPUTER I don'T want the Name John Fox to be repeated at each row.
I tried to add: #Name# in the REGION DEFINITION - REGION HEADER but I have this result:
#NAME#
NAME GENDER TYPE
John Fox M LAPTOP
John Fox M HARDDRIVE
John Fox M COMPUTER
So, what can I do to have this result? Change the query???
Name: John Fox
Sales: 1- LAPTOP
2- HARDDRIVE
3- COMPUTER thanks,
RoselineHi Roseline,
You can adapt the solution suggested in this post Re: More than 1 records in one cell
Thanks,
Manish -
Oracle 8i, left join with conditional
Coming from the MySQL world, I'm trying to do a left join with a
condition:
select c.givenname,c.surname,c.userid,r.letternr
from cand c,responses r
where (c.userid=r.username(+))
and
c.activeprofile=1
No problem whatsoever.
If there is no corresponding "response" in R for a given
candidate, I get a NULL return for R.letternr.
However, there is a flag in R, called "VISIBLE" that I wish to
use to mean "Don't count this entry in R". R.VISIBLE=0 means
that the response is not active/present/visible/valid.
Am I making any sense? :-)If you don't want to display a row with a null value for
r.letternr when r.visible = 0, then:
SELECT c.givenname,
c.surname,
c.userid,
r.letternr
FROM cand c,
responses r
WHERE c.userid = r.username (+)
AND c.activeprofile = 1
AND r.visible != 0
Or, if you do want to display a row with a null value for
r.letternr when r.visible = 0, then:
SELECT c.givenname,
c.surname,
c.userid,
r.letternr
FROM cand c,
responses r
WHERE c.userid = r.username (+)
AND c.activeprofile = 1
AND r.visible (+) != 0 -
How to do a left join to create a timesheet status report in Power View
I am trying to create a very simple report in power view for Project Online. It's a timesheet status report that should show a list of resources, and the current status of their timesheet (in progress, not started, etc).
In Excel, I created an odata connection with Resources and Timesheets, and set up the connection between them. So, I can now easily display a list of timesheets, and filter them by end date. Good. But this only displays rows where there is an existing timesheet.
So resources who have not started a timesheet are not displayed. So, I need a "left join" in power view to display all resources, whether or not they have a timesheet for the period. (and, for the ones that do, I need to display fields from the timesheet,
such as the status description.)
Any suggestions?
Mike G.Hi Mike,
I'm not sure of what I'm suggesting since I got no instance to test it, but I'm wondering if the OLAP Cube "MSP_Project_Timesheet" wouldn't contain all resources of the enterprise pool with assignments (and not only resources that already submitted
a timesheet) since it is a combination of the assignment timephased, resource timephased and EPM timesheet cubes.
Hope this helps.
Guillaume Rouyre - MBA, MCP, MCTS -
How to make a customize form with optional parameter and left join
Hi,
I am trying to make a report with a left join. I also want ot have optional parameters in it.
I am using the Create Reports From SQL Query method:
SQL is :
select ename, sal
from scott.emp left join scott.dept
on scott.emp.deptno = scott.dept.deptno
where sal >= :lower_sal
and sal <= :higher_sal;
However, if I do it this way, I those 2 parameters are not optional.... How can I make them optional?
If I use the Create Reports From Query Wizard method, I can make the parameters optional, but then I cannot do the left join...
Thanks,
Wilsonhi,
to catch null values on both sides I use:
where nvl(sal,0) >= nvl(:lower_sal,nvl(sal,0))
and nvl(sal,0) <= nvl(:higher_sal,9999999999)
otherwise there will be no rows in the report where the value of sal is null, even if there are no selection criteria entered.
regards Michael -
I have gone through LEFT JOIN . Here is LEFT JOIN . Check the link
http://i218.photobucket.com/albums/cc298/curseofgoldendragon/test-3.png
I have a doubt here. I see we are picking all the records from Table A ...so, I dont think we need to join here.
We could just use a "select" query to fetch all the records from Table A...is not it ?
Hence, I dont find usefulness of "LEFT JOIN".
Can anybody explain if I'm missing something ?i like OUTER JOIN when Multi-Column Join and Join to a Constant (see table in http://www.orafaq.com/node/855)
example
select * from T1, T2 where T1.C1 = T2.C1(+) and T1.C2(+) = ‘Y’;but below code is more beautiful :)
select *
from T1 left outer join T2 on (T1.C1 = T2.C1 and T1.C2 = ‘Y’)also U may use something
select *
from T1 left outer join T2 on (T1.C1 = T2.C1 and substr(T1.C2,10,20) = ‘Y’)but in plus notation it's more complex
Edited by: AlexAnd on Jun 24, 2011 1:08 AM
Maybe you are looking for
-
not able to set security group without mail enabled as site collection admin using powershell in sharepoint online site - office 365? Any idea?
-
Exit for ME51n - ABAP OO coding
Hi, I am writing a BADI for ME51n - ME_REQ_POSTED. In that i want to restrict the account assignment category either A or K. but i am not able to write a coding as i am not good enough in OO. field name is KNTTP. how to do it? Thanks.
-
Mailbox recipient does not have a mailbox database
For one of our customers we are currently working on a prove of concept to implement on premise exchange servers. The problem mentioned below takes place on test servers. Server names and mail domain names are changed to generic values. On our on pre
-
Hi: On OA Framework Developers Guide Chapter 3 there is a sectioin of " Creating Attribute Sets" I followed the example and try to execute the command on the tiltle "Generating Attribute Sets Automatically (Only on Linux)" which I tried the following
-
Opening A Premiere Pro CS6 Project in Premiere Pro CS 5.5
I downloaded Premiere Pro CS 6. I already have Premiere Pro CS 5.5 on my computer. I had read you can open up a CS 6 Project in CS 5.5 by doing the following: 1) Saving your project file on your Hard Drive 2) Copy it just for back up 3) Right Click (