Cross joins on queries
HI,
how we can apply cross joins on select query.plz help me .I am using tables ekko,ekpo and lfa1 .Plz help.
Hi Amardeep,
as code given by one of guru's in the above joins statement is good when only if use the KEY-FIELDS in where condition if not it causes performance issue , so that you can use the FOR ALL ENTRIES IN statement which it gives good perfomance.
Table declarations
TABLES: ekko, "Purchasing Document Header
ekpo, "Purchasing Document Item
lfa1. "Vendor Master (General Section)
Declaration of types:
data: BEGIN OF tbl_ekko,
ebeln TYPE ebeln,
lifnr TYPE lifnr,
END OF tbl_ekko.
data: BEGIN OF tbl_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF tbl_ekpo.
data: BEGIN OF tbl_lfa1,
lifnr TYPE lifnr
ebelp TYPE ebelp,
END OF tbl_lfa1.
*Selection screen:
PARAMETERS: p_lifnr TYPE lifnr,
p_ebeln type ebeln.
Selection (JOIN):
START-OF-SELECTION.
SELECT lifnr
FROM lfa1
INTO table tbl_lfa1
WHERE lifnr EQ p_lifnr.
if sy-subrc = 0.
sort tbl_lfa1 by lifnr.
endif.
if not tbl_lifnr is initial.
SELECT ebeln lifnr
FROM ekko
INTO table tbl_ekko
FOR ALL INTRIES IN tbl_lfa1
WHERE ebeln EQ p_ebeln
AND lifnr EQ tbl_lfa1-lifnr.
if sy-subrc = 0.
sort tbl_ ekko by ebeln.
endif.
endif.
if not tbl_ekko is initial.
SELECT ebeln ebelp
FROM ekpo
INTO table tbl_ekpo
FOR ALL INTRIES IN tbl_ekko
WHERE ebeln EQ tbl_ekko-eblen.
if sy-subrc = 0.
sort tbl_ ekpo by ebeln.
endif.
endif.
END-OF-SELECTION.
Main program logic:
LOOP AT tbl_ekpo.
read table ekko with key ebeln = tbl_ekpo-ebeln BINARY SEARCH.
if sy-subrc = 0
WRITE: / tbl_ekko-ebeln,
tbl_ekko-ebelp,
tbl_ekpo-lifnr.
endif.
ENDLOOP.
<b>NOTE : use only KEY-FIELDS in WHERE condition for better perfomance</b>
In that above code you can change a/c to ur inputs availabe.
<b>Reward with points if helpful.</b>
Regards,
Vijay
Similar Messages
-
Is it possible to create a cross join between queries in Power Query?
I plan to use a table holding budgetlines that i want to cross join with a timetable to create monthly budgetlines.
Thanks, Menno van LeewenHi Menno,
Yes, it's possible to perform different kinds of join operations in Power Query, including a cross join. Please check out this page for more information on the different options,
http://office.microsoft.com/en-us/excel-help/table-join-HA104112136.aspx
The library specification also contains a description about the different Join Kinds (around page 164):
http://office.microsoft.com/en-us/excel-help/learn-about-power-query-formulas-HA104003958.aspx?CTT=5
According to your description, I think you will want to do a full outer join. It should look similar to this:
Table.Join(Customers, "CustomerID",Table.PrefixColumns(Orders, "Order"), "Order.CustomerID", JoinKind.FullOuter)
Thanks,
M. -
CONNECT BY with CROSS JOIN and WHERE not executing as described in doc
Hello all,
please see these two statements. They are the same, but the 1st uses t1 INNER JOIN t2 while the snd uses a CROSS JOIN with WHERE.
The 2nd statement shows one row more than the first, but the CROSS JOIN with WHERE is the same as the INNER JOIN.
The result would be OK if Oracle did:
JOIN -> CONNECT BY PRIOR -> WHERE
But according to the docs it does:
JOIN (and WHEREs for JOINS) -> CONNECT BY PRIOR -> Rest of WHERE
See http://docs.oracle.com/cd/E11882_01/server.112/e26088/queries003.htm#SQLRF52332 for details. There it says:
Oracle processes hierarchical queries as follows:
A join, if present, is evaluated first, whether the join is specified in the FROM clause or with WHERE clause predicates.
The CONNECT BY condition is evaluated.
Any remaining WHERE clause predicates are evaluated.
+.....+
Is this a bug? I'd say yes, because it differs from the docs and it also is not what people are used to ("a,b WHERE" is the same as "a INNER JOIN b").
Thanks,
Blama
--Statement 1:
WITH t1
AS
(SELECT 1 a, 2 b FROM DUAL UNION ALL
SELECT 2 a, 3 b FROM DUAL UNION ALL
SELECT 3 a, 4 b FROM DUAL UNION ALL
SELECT 4 a, 5 b FROM DUAL UNION ALL
SELECT 5 a, 6 b FROM DUAL),
t2 AS
(SELECT 1 c FROM DUAL UNION ALL
SELECT 2 c FROM DUAL UNION ALL
SELECT 3 c FROM DUAL UNION ALL
SELECT 5 c FROM DUAL)
SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
FROM t1 INNER JOIN t2
ON t1.a = t2.c
CONNECT BY t1.a = PRIOR t1.b
START WITH t1.a = 1
ORDER BY
1,2,3;
--Result:
--1 1 2 1 /1
--2 2 3 2 /1/2
--3 3 4 3 /1/2/3
--Statement 2:
WITH t1
AS
(SELECT 1 a, 2 b FROM DUAL UNION ALL
SELECT 2 a, 3 b FROM DUAL UNION ALL
SELECT 3 a, 4 b FROM DUAL UNION ALL
SELECT 4 a, 5 b FROM DUAL UNION ALL
SELECT 5 a, 6 b FROM DUAL),
t2 AS
(SELECT 1 c FROM DUAL UNION ALL
SELECT 2 c FROM DUAL UNION ALL
SELECT 3 c FROM DUAL UNION ALL
SELECT 5 c FROM DUAL)
SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
FROM t1 CROSS JOIN t2
WHERE t1.a = t2.c
CONNECT BY t1.a = PRIOR t1.b
START WITH t1.a = 1
ORDER BY
1,2,3;
--Result:
--1 1 2 1 /1
--2 2 3 2 /1/2
--3 3 4 3 /1/2/3
--5 5 6 5 /1/2/3/4/5My details:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Solaris: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Productionblama wrote:
Hello Paul,
that means that "a,b" isn't the same as "a CROSS JOIN b".
I don't think that that is really the case.
Do you have docs on this one?No explicit docs just (my) logic - having said that, I suppose it is implied that if you are doing ANSI style joins, it's not the where clauses that
are specifying the join.
If you do t1,t2 where t1.a=t2.a then Oracle figures out the kind of join from the (relevant) where clauses and treats the other where clauses after the CONNECT BY.
If you do t1 cross join t2 where t1.a=t2.a then you are saying the join is completely specified by the CROSS JOIN - i.e it's Cartesian. Oracle doesn't look at the where clauses for this. Therefore
all where clauses are treated as 'other' and are evaluated after the CONNECT BY.
So, in my mind it's 10g that has the bug. -
Performance considerations between a cross join and inner join
Hi there,
What's the performance difference and impact on running a cross-join based query against an inner join based query?
Regards and thanksBefore going to the performance issue - ensure you get the required data and not just some data shown.
Performance should be checked only between equivalent queries which produce same output but with different processing.
Are you sure you get same output in cross join as well as inner join?
If so pass on your different queries and then discuss with one is better. -
Hi all,
Two tables who have no relation with each other. For example an employees table and a systemparameter table with a startworktime.
We need a query with data from both tables:
Get all employees and the startworktime (which is the same for everybody)
Which is cheaper: an inline query or a cartesian product or crossjoin?
Inine :
select name, function
, (select startworktime from systemparameter)
from employees;
Cartesian product:
select name, function, startwoime
rktfrom employees
cross join systemparameter;
Your thoughts on this.Hi,
To see which runs faster on your system, with your sub-query, there's no sibstitute for testing on your system, with your sub-query.
I predict you won't notice any difference. Scalar sub-queries (as in your first example) are cached (at least in recent versions of Oracle), so you can include a scalar sub-query in a result set of a million rows, and the sub-query can be executed once, not a million times. -
Hello Guys,
I have a bit of trouble understanding the MERGE I have written here.
All the code executes without errors. As far as I see,
the below MERGE SELECT is a Cartesian product/cross join and I remember that is not
good. The ON (join condition) seems to be only for the merge into table (T_CLAIMS_BB) and
the table that comes from the select (d).
merge into T_CLAIMS_BB t
using
SELECT sch_vt.SCH#,vert.CNO,vers.SubCNo,regv.ReturnNo,regv.SndReturnNo,sch_vt.MainProd,sch_vt.Prod
FROM mainschema.TCONTRACT vert, mainschema.TVERSCONTRACT vers, commonschema.VC_REGVEREINB regv, myschema.T_CLAIMS_VT sch_vt
) d
ON (
t.sch# = d.sch# AND
SUBSTR(UPPER(t.BOOKINGTEXT),1,2) = d.SndReturnNo AND d.SubCNo IS NULL
) -- Join
when matched then
update
set t.CNO = 'a',
t.ReturnNo = 'a',
t.MainProd = 'b',
t.Prod = 'c';
I wonder now, what is the advantage of using MERGE in my case - if there is one.
Finally I want to demonstrate how the whole thing would look without a MERGE:
SELECT vers.* FROM TVERSCONTRACT vers
LEFT OUTER JOIN myschema.T_CLAIMS_BB sch ON sch.SubCNo = vers.SubCNo
LEFT OUTER JOIN commonschema.VC_REGVEREINB regv ON sch.SCH# = regv.SCH# AND SUBSTR(UPPER(sch.BUCHTEXT),1,2) = regv.SndReturnNo AND sch.SubCNo IS NULL
LEFT OUTER JOIN myschema.T_CLAIMS_VT sch_vt ON sch.SCH# = sch_vt.SCH#Hi,
metalray wrote:
Hello Guys,
I have a bit of trouble understanding the MERGE I have written here.
All the code executes without errors. As far as I see,
the below MERGE SELECT is a Cartesian product/cross join and I remember that is not
good.Cross joins are good for some purposes. In practice, they're useful in only 1 or 2 queries out of every 1000.
Using the old join notation, it was very easy to get a cross join by mistake. Given how rarely cross joins are needed, the vast majority of cross joins (using old notation) were not good, but that was the fault of the programmers and the notation, not an indication that cross join itself was bad.
The ON (join condition) seems to be only for the merge into table (T_CLAIMS_BB) and
the table that comes from the select (d).Exactly!
You can have separate ON conditions inside the USING sub-query, if you need them.
>
merge into T_CLAIMS_BB t
using
SELECT sch_vt.SCH#,vert.CNO,vers.SubCNo,regv.ReturnNo,regv.SndReturnNo,sch_vt.MainProd,sch_vt.Prod
FROM mainschema.TCONTRACT vert, mainschema.TVERSCONTRACT vers, commonschema.VC_REGVEREINB regv, myschema.T_CLAIMS_VT sch_vt
) d
ON (
t.sch# = d.sch# AND
SUBSTR(UPPER(t.BOOKINGTEXT),1,2) = d.SndReturnNo AND d.SubCNo IS NULL
) -- Join
when matched then
update
set t.CNO = 'a',
t.ReturnNo = 'a',
t.MainProd = 'b',
t.Prod = 'c';
I wonder now, what is the advantage of using MERGE in my case - if there is one.I don't see any advantage, but I suspect the statement, as written, is not doing what it's supposed to. If someone made the mistake of using MERGE when UPDATE would be better, that might be the least of the mistakes in this statement.
Finally I want to demonstrate how the whole thing would look without a MERGE:It looks like the MERGE statement above is equivalent to:
UPDATE t_claims_bb
SET cno = 'a'
, returnno = 'a'
, mainprod = 'b'
, prod = 'c'
WHERE UPPER (SUBSTR (bookingtext, 1, 2)) IN
SELECT returnno
FROM commonschema.vc_regvereinb
AND EXISTS
SELECT 1
FROM mainschema.tverscontract
WHERE subcno IS NULL
AND EXISTS
SELECT 1
FROM mainschema.tcontract
AND EXISTS
SELECT 1
FROM myschema.t_claims_vt
;Again, I suspect that the MERGE state,ment above is not doing what it was meant to do, or may coinncidentally be getting the right results on a small sample set. Many of the tables named in the USING clause of the MERGE statement do'nt seem to have much of a role in this problem.
SELECT vers.* FROM TVERSCONTRACT vers
LEFT OUTER JOIN myschema.T_CLAIMS_BB sch ON sch.SubCNo = vers.SubCNo
LEFT OUTER JOIN commonschema.VC_REGVEREINB regv ON sch.SCH# = regv.SCH# AND SUBSTR(UPPER(sch.BUCHTEXT),1,2) = regv.SndReturnNo AND sch.SubCNo IS NULL
LEFT OUTER JOIN myschema.T_CLAIMS_VT sch_vt ON sch.SCH# = sch_vt.SCH#What is this query? Perhaps you meant to have something like this in the USING clause of the MERGE.
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.
The sample data should show what the tables are like before the MERGE (or UPDATE), and the results will be the contents of the changed table after the MERGE.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using. -
Getting Error : Illegal cross join within the same dimension
Hi All,
At database there are 4 tables - XLE_Entity_profiles (A) , XLE_ETB_profiles (B) ,XLE_Registration (C),XLE_Reg_Function(D) .
Attribute info is as below -
A.Le_name
B.LRU_name
C. Registraton name
D. Function_code
I have to model a single dimension which contains the attributes from these tables and dimension should also support queries which contains attributes from this dimension only without selecting any fact.
For Exp - query is as below -
Le_name,Le-Registraton name,Le_Function_code,LRU_name,LRU_Registraton name,LRU_Function_code
To support such query , i created aliases of table XLE_Registration,XLE_Reg_Function.
Aliases names are - XLE_Registration_LE (E),XLE_Registration_LRU (F),XLE_Reg_Function_LE (G).,XLE_Reg_Function_LRU (H)
Attributes from aliases are as below -
XLE_Registration_LE- Le-Registraton name
XLE_Registration_LRU -LRU_Registraton name
XLE_Reg_Function_LE - Le_Function_code
XLE_Reg_Function_LRU - LRU_Function_code
i have renamed the attributes For LE and LRU.
The Physical layer diagram is as below
A < B
E F
G H
[A:B (1:M) , A:E(1:M), E:G(1:M),B:F(1:M),F:H(1:M)]
At logical layer , i have created a dimension DIM-LE with below logical table sources -
A ,B,E,F,G,H
Using the properties of LTS B , i mapped B to A.
Using the properties of LTS E , i mapped E to A.
Using the properties of LTS F , i mapped F to B.
Using the properties of LTS G , i mapped G to E.
Using the properties of LTS H , i mapped H to F.
Now when i run the query , i am getting the error -
Query - Le_name,Le-Registraton name,Le_Function_code,LRU_name,LRU_Registraton name,LRU_Function_code
+++Administrator:2a0000:2a0004:----2008/11/07 19:39:03
Query Status: Query Failed: [nQSError: 14065|http://forums.oracle.com/forums/] Illegal cross join within the same dimension caused by incorrect subject area setup: [
XLE_REGISTRATIONS T1218 On XLE_REGISTRATIONS_LRU.REGISTRATION_ID = XLE_REG_FUNCTIONS_LRU.REGISTRATION_ID,
XLE_REG_FUNCTIONS T5737,
XLE_ETB_PROFILES T900 On XLE_ETB_PROFILES.ESTABLISHMENT_ID = XLE_REGISTRATIONS_LRU.SOURCE_ID,
XLE_ENTITY_PROFILES T836 On XLE_ENTITY_PROFILES.LEGAL_ENTITY_ID = XLE_ETB_PROFILES.LEGAL_ENTITY_ID] with [
XLE_REGISTRATIONS T1155 On XLE_REGISTRATIONS_LE.REGISTRATION_ID = XLE_REG_FUNCTIONS_LE.REGISTRATION_ID,
XLE_REG_FUNCTIONS T5703,
XLE_ENTITY_PROFILES T836 On XLE_ENTITY_PROFILES.LEGAL_ENTITY_ID = XLE_REGISTRATIONS_LE.SOURCE_ID]
But when i run below query,which resembles the BI Answer query, against the database ,
select distinct A.NAME as c1,
B.REGISTERED_NAME as c2,
E.Function_code as c5,
C.NAME as c3,
D.REGISTERED_NAME as c4,
F.Function_code as c6
from
XLE_ENTITY_PROFILES A,
XLE_REGISTRATIONS B,
XLE_REG_FUNCTIONS E,
XLE_ETB_PROFILES C,
XLE_REGISTRATIONS D,
XLE_REG_FUNCTIONS F
where (A.LEGAL_ENTITY_ID = C.LEGAL_ENTITY_ID and
A.LEGAL_ENTITY_ID = B.SOURCE_ID and
C.ESTABLISHMENT_ID = D.SOURCE_ID and
B.SOURCE_TABLE = 'XLE_ENTITY_PROFILES' and
D.SOURCE_TABLE = 'XLE_ETB_PROFILES' and
E.Registration_id = B.Registration_id and
F.Registration_id = D.Registration_id)
order by c1, c2,c5, c3, c4,c6
i don't get any error.
Please let me know , why am i getting this error and how can i resolve this issue?Hi All,
Is there any update on this ?
Thanks,Ashish -
Hello,
I've written the following query, which works fine:
select * from
select
to_char(SCB_OPENTIME, 'YYYY-MM') as curr_date,
SCB_TASK
from EM_DATA_MSR_SC
pivot
count(SCB_TASK) for curr_date in
'2011-01',
'2011-02',
'2011-03',
'2011-04',
'2011-05',
'2011-06',
'2011-07',
'2011-08',
'2011-09',
'2011-10',
'2011-11',
'2011-12'
);Now I need to apply a cross join on it:
select * from
select
to_char(SCB_OPENTIME, 'YYYY-MM') as curr_date,
SCB_TASK
from EM_DATA_MSR_SC
where
EMSCG_STATUS = status.name
pivot
count(SCB_TASK) for curr_date in
'2011-01',
'2011-02',
'2011-03',
'2011-04',
'2011-05',
'2011-06',
'2011-07',
'2011-08',
'2011-09',
'2011-10',
'2011-11',
'2011-12'
cross join
select 0, 'Closed' as name from DUAL union
select 1, 'Denied' from DUAL union
select 2, 'Open' from DUAL
) status;When I try to execute this query, I get this error message:
"STATUS"."NAME": invalid identifierHowever, SQL is supposed to have table references scoped to one level deep.
Am I doing something wrong?Unfortunately, your snippet doesn't work either.
Here is a simple test case:
CREATE TABLE TEST
NUM NUMBER NOT NULL,
DAT DATE NOT NULL
insert into TEST (NUM, DAT) values (32, SYSDATE - 43);
insert into TEST (NUM, DAT) values (9, SYSDATE - 143);
insert into TEST (NUM, DAT) values (90, SYSDATE - 13);
insert into TEST (NUM, DAT) values (24, SYSDATE - 3);
insert into TEST (NUM, DAT) values (244, SYSDATE - 39);
insert into TEST (NUM, DAT) values (44, SYSDATE - 9);
insert into TEST (NUM, DAT) values (44, SYSDATE - 9);
insert into TEST (NUM, DAT) values (44, SYSDATE - 9);
insert into TEST (NUM, DAT) values (60, SYSDATE - 9);
insert into TEST (NUM, DAT) values (51, SYSDATE - 9);
insert into TEST (NUM, DAT) values (44, SYSDATE - 9);
insert into TEST (NUM, DAT) values (0, SYSDATE - 3);
insert into TEST (NUM, DAT) values (16, SYSDATE - 11);
insert into TEST (NUM, DAT) values (24, SYSDATE - 9);
insert into TEST (NUM, DAT) values (59, SYSDATE - 27);
insert into TEST (NUM, DAT) values (29, SYSDATE - 16);
insert into TEST (NUM, DAT) values (20, SYSDATE - 47);
insert into TEST (NUM, DAT) values (103, SYSDATE - 1);
insert into TEST (NUM, DAT) values (41, SYSDATE - 92);
insert into TEST (NUM, DAT) values (42, SYSDATE - 40);Here's the corresponding working query:
select * from
select
to_char(DAT, 'YYYY-MM') as curr_date,
NUM
from TEST
pivot
count(NUM) for curr_date in
'2011-01',
'2011-02',
'2011-03',
'2011-04',
'2011-05',
'2011-06',
'2011-07',
'2011-08',
'2011-09',
'2011-10',
'2011-11',
'2011-12'
;Now, say I want to display the number of NUMs grouped by range values and by DAT. I'd like to have this kind of output (each # is a different number):
-------- 2011-01 2011-02 2011-03 2011-04 2011-05 2011-06 2011-07 2011-08 2011-09 2011-10 2011-11 2011-12
0 - 20 # # # # # # # # # # # #
21 - 50 # # # # # # # # # # # #
51 - 300 # # # # # # # # # # # #To do so, I'd like to write something like this:
select * from
select
to_char(DAT, 'YYYY-MM') as curr_date,
NUM
from TEST
where NUM >= ranges.mini and NUM <= ranges.maxi
pivot
count(NUM) for curr_date in
'2011-01',
'2011-02',
'2011-03',
'2011-04',
'2011-05',
'2011-06',
'2011-07',
'2011-08',
'2011-09',
'2011-10',
'2011-11',
'2011-12'
cross join
select 0, 0 as mini, 20 as maxi from DUAL union
select 1, 21, 50 from DUAL union
select 2, 51, 300 from DUAL
) ranges
;Alas, this isn't a valid query:
"RANGES"."MAXI": invalid identifierUsing a WITH clause doesn't help (same error message):
with ranges as
select 0, 0 as mini, 20 as maxi from DUAL union
select 1, 21, 50 from DUAL union
select 2, 51, 300 from DUAL
select * from
select
to_char(DAT, 'YYYY-MM') as curr_date,
NUM
from TEST
where NUM >= ranges.mini and NUM <= ranges.maxi
pivot
count(NUM) for curr_date in
'2011-01',
'2011-02',
'2011-03',
'2011-04',
'2011-05',
'2011-06',
'2011-07',
'2011-08',
'2011-09',
'2011-10',
'2011-11',
'2011-12'
cross join ranges
;EDIT:
Always say which version of Oracle you're using.Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
"CORE 11.1.0.7.0 Production"
TNS for Solaris: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
EDIT 2:
SCB_TASK replaced by NUM in queries
Edited by: 895536 on 7 nov. 2011 09:01 -
When I'm seeing an article about cross join I got a doubt. In that physical diagram they connected the the column-1 from table A and column 2 from table B.Table-A is xls and table-2 is Oracle.
Now IN BMM layer they connected the col-1 and col-2 as foreign key join. I think In BMM layer we prefer to do complex join. Any idea to get an idea
Thanks & Regards,
PallisHi Pallis,
Check my blog regarding joins; http://obibb.wordpress.com/2010/08/06/joins-in-oracle-bi-ee/
From Answers a Logical query is fired. The BI Server fires two Physical queries to the seperate databases. The results of the two seperate queries are stiched toghether by the BI Server and presented in Answers.
Cheers,
Daan Bakboord
http://obibb.wordpress.com -
I have 2 separate data providers/queries
Let's say in the first one it returns something like this:
OrderId Product Amount
1 Apple 500
1 Orange 400
1 Banana 600
2 Apple 300
2 Orange 200
And in the second one it returns something like this:
OrderId SalesPerson
1 Bob
1 Mary
2 Steve
I'd like to have the webi report output something like this (basically a cross join)
OrderId Product Amount SalesPerson
1 Apple 500 Bob
1 Orange 400 Bob
1 Banana 600 Bob
1 Apple 500 Mary
1 Orange 400 Mary
1 Banana 600 Mary
2 Apple 300 Steve
2 Orange 200 Steve
I think I've tried every combination of merge dimensions/detail objects, etc. but always end up with either #INCOMPATIBLE or #MULTIVALUE in SalesPerson when there are multiple salespersons associated with an order (such as order 1 in the example above). When there is only one SalesPerson associated with the order then it works as expected, such as below:
OrderId Product Amount SalesPerson
1 Apple 500 #MUTLIVALUE
1 Orange 400 #MULTIVALUE
1 Banana 600 #MULTIVALUE
2 Apple 300 Steve
2 Orange 200 Steve
I can't really change the universe, so is this possible to do within webi?Thanks Bala, but I should have mentioned in my original post I tried that as well. It gives me something like this:
OrderId Product Amount SalesPerson
1 Apple 500 Bob
1 Orange 400 Bob
1 Banana 600 Mary
2 Apple 300 Steve
2 Orange 200 Steve
It avoids the #MULTIVALUE, but it doesn't do a proper cross-join. It shows only the number of rows associated with the Product, but doesn't cross-join across SalesPerson. Worse, it seems to "randomly" join against SalesPerson for one of the rows - i.e, I'm not sure why it displayed Mary for one of the rows instead of Bob. -
I can't figure out how to combine a full outer join with another type of join ... is this possible?
Here's some create table and insert statements for some basic sample data:
CREATE TABLE my_tab1
( record_id NUMBER NOT NULL
, workstation VARCHAR2(4)
, my_value NUMBER
CONSTRAINT my_tab1_pk PRIMARY KEY (record_id)
INSERT INTO my_tab1
VALUES(1,'ABCD',10);
INSERT INTO my_tab1
VALUES(2,'ABCD',15);
INSERT INTO my_tab1
VALUES(3,'ABCD',5);
INSERT INTO my_tab1
VALUES(4,'A123',5);
INSERT INTO my_tab1
VALUES(5,'A123',10);
INSERT INTO my_tab1
VALUES(6,'A123',20);
INSERT INTO my_tab1
VALUES(7,'????',5);
CREATE TABLE my_tab2
( workstation VARCHAR2(4)
, wkstn_name VARCHAR2(20)
CONSTRAINT my_tab2_pk PRIMARY KEY (workstation)
INSERT INTO my_tab2
VALUES('ABCD','WKSTN 1');
INSERT INTO my_tab2
VALUES('A123','WKSTN 2');
INSERT INTO my_tab2
VALUES('B456','WKSTN 3');
CREATE TABLE my_tab3
( my_nbr1 NUMBER
, my_nbr2 NUMBER
INSERT INTO my_tab3
VALUES(1,2);
INSERT INTO my_tab3
VALUES(2,3);
INSERT INTO my_tab3
VALUES(3,4);And, the results I want to get:
workstation sum(my_value) wkstn_name my_nbr1 my_nbr2
ABCD 30 WKSTN 1 1 2
ABCD 30 WKSTN 1 2 3
ABCD 30 WKSTN 1 3 4
A123 35 WKSTN 2 1 2
A123 35 WKSTN 2 2 3
A123 35 WKSTN 2 3 4
B456 0 WKSTN 3 1 2
B456 0 WKSTN 3 2 3
B456 0 WKSTN 3 3 4
???? 5 NULL 1 2
???? 5 NULL 2 3
???? 5 NULL 3 4I've tried a number of different things, googled my problem, and no luck yet...
SELECT t1.workstation
, SUM(t1.my_value)
, t2.wkstn_name
, t3.my_nbr1
, t3.my_nbr2
FROM my_tab1 t1
, my_tab2 t2
, my_tab3 t3
...So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. I'm wondering if I can't find any examples of this online because it's not possible....
Note: I'm stuck dealing with Oracle 8i
Thanks!!Hi,
The query I posted yesterday is a little more complicated than it needs to be.
Since my_tab2.workstation is unique, there's no reason to do a separate sub-query like mt1; we can join my_tab1 to my_tab2 and get the SUM all in one sub-query.
SELECT foj.workstation
, foj.sum_my_value
, foj.wkstn_name
, mt3.my_nbr1
, mt3.my_nbr2
FROM ( -- Begin in-line view foj for full outer join
SELECT mt1.workstation
, SUM (mt1.my_value) AS sum_my_value
, mt2.wkstn_name
FROM my_tab1 mt1
, my_tab2 mt2
WHERE mt1.workstation = mt2.workstation (+)
GROUP BY mt1.workstation
, mt2.wkstn_name
UNION ALL
SELECT workstation
, 0 AS sum_my_value
, wkstn_name
FROM my_tab2
WHERE workstation NOT IN ( -- Begin NOT IN sub-query
SELECT workstation
FROM my_tab1
WHERE workstation IS NOT NULL
) -- End NOT IN sub-query
) foj -- End in-line view foj for full outer join
, my_tab3 mt3
ORDER BY foj.wkstn_name
, foj.workstation
, mt3.my_nbr1
, mt3.my_nbr2
;Thanks for posting the CREATE TABLE and INSERT statements, as well as the very clear desired results!
user11033437 wrote:
... So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. That it, exactly!
The tricky part is how and when to get SUM (my_value). You might approach this by figuring out exactly what my_tab3 has to be cross-joined to; that is, exactly what should the result set of the full outer join between my_tab1 and my_tab2 look like. To do that, take your desired results, remove the columns that do not come from the full outer join, and remove the duplicate rows. You'll get:
workstation sum(my_value) wkstn_name
ABCD 30 WKSTN 1
A123 35 WKSTN 2
B456 0 WKSTN 3
???? 5 NULL So the core of the problem is how to get these results from my_tab1 and my_tab2, which is done in sub-query foj above.
I tried to use self-documenting names in my code. I hope you can understand it.
I could spend hours explaining different parts of this query in more detail, but I'm sure I'd waste some of that time explaining things you already understand. If you want an explanation of somthing(s) specific, let me know. -
Illegal cross join within the same dimension caused by incorrect subject ar
hi!
Imagine the following BMM:
There is one Logical Dimension Table "Service Account" with the following LTS:
- LTS "D_SERVICE"
- LTS "D_SERVICE_CLASS"
- LTS "D_SERVICE_STATUS"
This Logical Tabe "Service Account" joins (One-to-many) with several Fact Tables (other Logical Tables).
In the Physical Layer the joins for the "Service Account" LTS are:
- One-to-many between D_SERVICE_CLASS and D_SERVICE
- One-to-many between D_SERVICE_STATUS and D_SERVICE
The problem is that when I build a report in Answers using only the following columns of the Logical Table "Service Account":
- Service Class Desc (which exists in the Logical Table "Service Account" and in the Physical Table D_SERVICE_CLASS)
- Service Status Desc (which exists in the Logical Table "Service Account" and in the Physical Tabl D_SERVICE_STATUS)
- MSISDN (which existis in the Logical Table "Service Account" and in the Phsyical Table D_SERVICE)
the following error appears:
Estado: HY000. Código: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14065] Illegal cross join within the same dimension caused by incorrect subject area setup: [ (select * from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) as T1836, D_SERVICE_CLASS T1916] with [ D_SERVICE_STATUS T1948] (HY000)
SQL emitido: SELECT "SERVICE ACCOUNT"."TLC MSISDN9" saw_0, "SERVICE ACCOUNT"."IWS Service Class Desc" saw_1, "SERVICE ACCOUNT"."TLC Service Status Desc" saw_2 FROM "VFPT - Upgrade Siebel" WHERE "SERVICE ACCOUNT"."TLC MSISDN9" = '917330340' ORDER BY saw_0, saw_1, saw_2
Help, please!
Thanks.Physically, only D_SERVICE is joined to the facts. Then D_SERVICE_CLASS is joined to D_SERVICE (one-to-many) and D_SERVICE_STATUS is joined also to D_SERVICE (one-to-many).
In the BMM, there is only one Logical Dimension Table for those 3 physical tables. This Logical Dimension Table is called "Service Account" and has 3 LTS: D_SERVICE, D_SERVICE_CLASS, D_SERVICE_STATUS. The Logical Dimension Table has several logical columns that are associated to those 3 LTS: SERVICE_KEY, SERVICE_CLASS_KEY, SERVICE_STATUS_KEY, SERVICE_MSISDN, SERVICE_CLASS_DESC, SERVICE_STATUS_DESC.
The Logical Dimension Table "Service Account" is then joined to a fact table (one-to-many).
I didn't understand the suggestion about the 3 LTS... Aren't we doing that already? Can you explain it better, please?
thanks. -
OBIEE: non empty cross join function problem with some reports
Hi all,
I am getting some problem ,when we are excuting some requests in OBIEE its taking long time , Actually our OBIEE is connected with Essbase when we are generating some reports its taking long time so i captured the Query in OBIEE and Iam excuting that query in Essbase MDX editor
its having the the function " NON EMPTy CROSS JOIN"
which reports having non empty crossjoin function its taking long time so how can i disable this function in OBIEEfor that reports
I dont want to use that function for my reports so how can i do this in OBIEE
your help would be appriciated.
Thanks
Edited by: user8815661 on 26 mai 2010 08:44Any Help
-
How to avoid duplicates in CROSS JOIN Query
Hi,
I am using CROSS JOIN to get all the subset of a table col values as shown below:
PRODUCT (Col Header)
Bag
Plate
Biscuit
While doing cross join we will get as
Bag Bag
Bag Plate
Bag Biscuit
Plate Bag
Plate Plate
Plate Biscuit ..... like this
By placing where condition prod1 <> prod2 to avoid Bag Bag and Plate Plate values. So the output will be like below
Bag Plate
Bag Biscuit
Plate Bag
Plate Biscuit
Now "Bag Plate" and "Plage Bag" are same combination how to avoid these records. My expected result is
Bag Biscuit
Plate Biscuit
How to derive this ?
SridharHi,
This is the the solution that I found as fit to the OP question, but
Visakh16 already posted the same idea (assuming the names are unique) from the start and I don't think that anyone notice it!
Sridhar.DPM did
you check Visakh16's response
(the second response received)?!?
I will mark his response as an answer. If this is not what you need pls clarify and you can unmark it :-)
[Personal Site] [Blog] [Facebook] -
How to resolve illegal cross join error
Can someone please tell me how can we avoid illegal cross join error in modeling? If someone has any reference document , please share it.
I have 5 tables - Dim (A, B , C,E) and Fact( D). C is lookup table which is used to resolve the lookup code column in table E.
The relationships between these are
A--< B--< E >--C
& A--<D
My requirement is i have to expose Attributes of A,B ,C & E within Dimension.
These attributes (from B,C,E) will be treated as property of A.
Someone may query these attributes without selecting any column from fact table.
Thanks & Regards,
AshishHi Ashish,
it's not the first time you come up with this kind of question and I'm wondering if you understand the principle of granularity when I read your questions.
On physical level, a fact table must always join with the lowest level of detail of your dimension table. Let me explain, by giving an example which looks like your situation.
Assume I have three tables:
Table "E" contains products, which has attributes like: product_id and product_name
Table "B" contains order line items, which has attributes like: order_line_item_id, order_id and product_id.
Table "A" contains orders, which has attributes like: order_id and customer_name.
Table "D" contains facts ("metrical data") about my order: which has attributes like: order_id, order_revenue.
This will be the diagram on physical level: E--<B--<A--<D
Here are my joins: E.product_id on B.produc_id, B.order_id on A.order_id, A.order_id--<D.order_id
Now, my question to you is: will I be able to get the revenue of a certain product?
The answer is: No, because I don't know what part of my order is spent on a certain product. The problem is thus that the data in the fact table isn't stored on that level of detail, or in other words the fact and dimension table don't share the same level of granularity.
How it should be:
If you want to get the revenue per product, you will need to have a second fact table "G", which has data which is stored on order line item level. This table contains the following attributes: order_line_item_id, product_id and order_line_item_revenue.
This will become your diagram on physical level:
B--<G>--E
Joins: B.order_line_item_id on G.order_line_item_id and E.product_id on G.product_id
Table E has become a dimension of fact table G.
The first physical diagram should look like this:
A--<D
If you want you can model both physical diagrams into one logical diagram, assuming that A and D (order dimension and fact table) are aggregates of B and G (order line items dimension and fact table). In that case you should read this blog item: http://obiee101.blogspot.com/2008/11/obiee-making-it-aggregate-aware.html
Regards,
Stijn
Maybe you are looking for
-
Why there is a SIP settings if VoIP is not present...
Hello, Kindly ask you to explain subject of this post. There is SIP settings on my C5-03 but I can find how to make an internet call ! Moreover nothing about SIP in official attached phone manual. There is an advise to install "SIP_VoIP_3_1_Settings_
-
does anyone know how i could get web archive files into FCE?? they are documents that are public domain from a website and i want to use some of them in my prod but FCE says ''unknow file type" i tried text editor "save as" but only get web archive.
-
I-pod shuts down when browsing album covers
After updating the i-pod touch to the new Op System 5 the player will shut down when I browse the album covers (holding the i-pod horizontal). It will work for about 5 covers but then shuts down. I did a reset but did not help Anybody who is familiar
-
Updating my firmware for my ZEN mi
can somebody please tell me how to update my firmware on my ZEN micro because i cant put anything on it and i dont have the cd but some said i can use WMP
-
Adobe Application Mgr crashes constantly ...
hi ... I've got a 2009 Macbook Pro laptop with an intel dual core 64-bit + 4 gig RAM. in Lion OS, the Adobe application manager crashed every time i started it. I've now upgraded to the latest OS, "Mountain Lion", with all updates; I trashed AAM & r