Oracle Discoverer sub query in join
I wonder if anyone can help me?
I've got two tables (table a and b) that have a number of joins.
I need to add another join between table a and b where a date field (from table a) equals the maximum value for this date field (where the above joins hold).
How do I add this as a join in Oracle Discoverer Administrator?
Basically, how do you add a subquery in a join?
Thanks.
Jon
I wonder if anyone can help me?
I've got two tables (table a and b) that have a number of joins.
I need to add another join between table a and b where a date field (from table a) equals the maximum value for this date field (where the above joins hold).
How do I add this as a join in Oracle Discoverer Administrator?
Basically, how do you add a subquery in a join?
Thanks.
Jon
Similar Messages
-
Correlated sub-query/outer join problem
Hi,
I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
select b.book_from,
b.book_to,
b.flat_rate,
nvl(c.discount,0),
p.hourly,
p.half_day,
p.daily,
p.discountable,
p.surcharge,
l.evening_start,
nvl(b.full_day,'N')
from booking.bookings b,
booking.customer c,
booking.room_prices p,
booking.rooms r,
booking.location l
where b.id = 9272
and c.id = b.customer
and b.room = p.room
and b.room = r.id
and r.loc = l.id
and p.from_date =
select max(p2.from_date)
from booking.room_prices p2
where p2.room = p.room
and p2.from_date < b.book_from
Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
Thanks,
HazelThanks for both of your responses.
Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
Here are some table creation scripts and test data to insert:
CREATE TABLE BOOKINGS
ID NUMBER NOT NULL,
ROOM NUMBER NOT NULL,
CUSTOMER NUMBER NOT NULL,
BOOK_FROM DATE NOT NULL,
BOOK_TO DATE NOT NULL,
CONFIG VARCHAR2(24) NOT NULL,
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
DELEGATES NUMBER,
NARRATIVE VARCHAR2(256),
CONTACT_DETAILS VARCHAR2(400),
CONFIRMED VARCHAR2(1),
CANC_REASON NUMBER,
FULL_DAY VARCHAR2(1),
FLAT_RATE NUMBER,
STANDBY NUMBER,
TOTAL_STANDBY_TIME DATE,
PRE_STANDBY_TIME DATE,
PRE_STANDBY NUMBER,
GL_CODE VARCHAR2(20)
CREATE TABLE CUSTOMER
ID NUMBER NOT NULL,
CUSTOMER VARCHAR2(160) NOT NULL,
CONTACT_ADDRESS VARCHAR2(240),
CONTACT_TELEPHONE VARCHAR2(20),
CONTACT_EMAIL VARCHAR2(160),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
DISCOUNT NUMBER(5,2),
CUST_TYPE VARCHAR2(1),
CONTACT_FAX VARCHAR2(20),
DEBTOR_NO VARCHAR2(20),
BC_CONTACT VARCHAR2(64)
CREATE TABLE ROOMS
ID NUMBER NOT NULL,
LOC NUMBER NOT NULL,
NAME VARCHAR2(160) NOT NULL,
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
ACTIVE VARCHAR2(1),
ROOM_DESC VARCHAR2(2000)
CREATE TABLE LOCATION
ID NUMBER NOT NULL,
NAME VARCHAR2(240) NOT NULL,
ADDRESS VARCHAR2(240),
PCODE VARCHAR2(8),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
CONF_RDF VARCHAR2(10),
CLOSING VARCHAR2(5),
EVENING_START VARCHAR2(5)
CREATE TABLE ROOM_PRICES
ROOM NUMBER NOT NULL,
FROM_DATE DATE NOT NULL,
HOURLY NUMBER(6,2),
HALF_DAY NUMBER(6,2),
DAILY NUMBER(6,2),
DISCOUNTABLE VARCHAR2(1),
CREATED_DATE DATE NOT NULL,
CREATED_BY VARCHAR2(16) NOT NULL,
UPDATED_DATE DATE,
UPDATED_BY VARCHAR2(16),
SURCHARGE NUMBER(6,2)
Insert into bookings
(ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
Values
(9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
Insert into customer
(ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
Values
(4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
Insert into rooms
(ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
Values
(7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
Insert into location
(ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
Values
(308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
Thanks,
Hazel -
Hi All,
I need to create a report in Oracle Discoverer. I would like to know if it is possible to create a report with the following logic. If yes, then how do I go about creating a report.
I have a table TBLREPORT with the following structure from which I have to pick up records.
Table: TBLREPORT
dttime DATE
interval VARCHAR2(10) (The field will have values BASE, HOURLY)
rdvalue number (aggregate to be applied in business area is AVG)
Data in table:
Dttime interval rdvalue
20-AUG-2001 9:00 am HOURLY 10
20-AUG-2001 10:00 am HOURLY 20
21-AUG-2001 9:00 am HOURLY 20
21-AUG-2001 10:00 am HOURLY 30
22-AUG-2001 9:00 am HOURLY 10
22-AUG-2001 10:00 am HOURLY 20
23-AUG-2001 9:00 am BASE 10
23-AUG-2001 9:15 am BASE 20
23-AUG-2001 9:30 am BASE 30
23-AUG-2001 9:45 am BASE 40
23-AUG-2001 9:00 am HOURLY 25 (the base data for 23-AUG-2001 from 9:00 am to 9:45 am is rolled up to arrive at HOURLY data e.g. 10+20+30+40 = 100/4 = 25)
23-AUG-2001 10:00 am BASE 50
23-AUG-2001 10:15 am BASE 60
23-AUG-2001 10:30 am BASE 70
23-AUG-2001 10:45 am BASE 80
23-AUG-2001 10:00 am HOURLY 65 (the base data for 23-AUG-2001 from 10:00 am to 10:45 am is rolled up to arrive at HOURLY data e.g. 50+60+70+80 = 260/4 = 65)
24-AUG-2001 9:00 am BASE 10
24-AUG-2001 9:15 am BASE 20
24-AUG-2001 9:30 am BASE 30
24-AUG-2001 9:45 am BASE 40
24-AUG-2001 9:00 am HOURLY 25 (the base data for 24-AUG-2001 from 9:00 am to 9:45 am is rolled up to arrive at HOURLY data e.g. 10+20+30+40 = 100/4 = 25)
24-AUG-2001 10:00 am BASE 50
24-AUG-2001 10:15 am BASE 60
24-AUG-2001 10:30 am BASE 70
24-AUG-2001 10:45 am BASE 80
24-AUG-2001 10:00 am HOURLY 65 (the base data for 24-AUG-2001 from 10:00 am to 10:45 am is rolled up to arrive at HOURLY data e.g. 50+60+70+80 = 260/4 = 65)
From this table I have to pick-up data for week = 20-AUG-2001 to 24-AUG-2001.
(the week start date is entered by the user in the report)
I have to first check if BASE data exists for the week.
If no base data exists then check for HOURLY data.
The following data exists:
No BASE data will be available for 20-AUG-201, 21-AUG-2001 or 22-AUG-2001, since it would have been deleted. HOURLY data is available for these days.
BASE data would be available for 23-AUG-2001 and 24-AUG-2001. HOURLY is available for these days also.
20-AUG-2001 21-AUG-2001 22-AUG-2001 23-AUG-2001 24-AUG-2001
No BASE No BASE No BASE BASE BASE
HOURLY HOURLY HOURLY HOURLY HOURLY
The input to the report is:
Week start date = 20-aug-2001
Hour range = 9:00 am to 10:00 am
Now in order to produce a weekly report,
1) The HOURLY data for 20-AUG-201, 21-AUG-2001 and 22-AUG-2001 should be viewed for the hour ranges the user enters.
2) The BASE data for 23-AUG-2001 and 24-AUG-2001 should be rolled-up to arrive at HOURLY data only for the hour ranges entered by the user, using the logic specified for rollup as given in the data. The HOURLY data present for 23-AUG-2001 and 24-AUG-2001 should not be considered but the BASE data should be considered which should be rolled-up to arrive at HOURLY data.
3) Then the HOURLY data from 20-AUG-201, 21-AUG-2001, 22-AUG-2001, Base data of 23-AUG-2001 and 24-AUG-2001 rolled-up to HOURLY should be used to generate the weekly report, taking into consideration the hour ranges entered by the user.
Any help will be greatly appreciated.
Thanks in advance
MFHi,
When users are removed from the system their privileges in EUL4_ACCESS_PRIVS are not removed. However, when the privileges are exported and imported only the privileges of valid users are imported into the EUL. Therefore it could be that the missing privileges relate to users that are no longer on the system. You would have to check in the original EUL4_ACCESS_PRIVS to confirm that.
Rod West -
Oracle Discoverer Plus - sub query
Hi,
Quick question do you know if the sub query is available in Disco Plus yet?
If so which version and/or what configuration is required.
I know you can still do this in the desktop and then run it in plus but this means users can't do it.
Regards,
Paul.Thanks for this I know it can't be done in the current version. I was hoping that it was something being addressed.
Its a pain to be able to do it in the desktop client and not the web version.
Its a work around when links are not present to the folders.
Cheers,
Paul -
Dear Sir/Madam
I'm a student who is interested in Oracle Database and
I have some problems with JOIN and Sub-query.
I hope so many of you could help me.
if i use JOIN without sub-query, may it be faster or not?
SELECT field1, field2 FROM tableA INNER JOIN tableB
if i use JOIN with sub-query, may it be faster or not?
SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
Thanks in advance!Hi,
fac30d8e-74d3-42aa-b643-e30a3780e00f wrote:
Dear Sir/Madam
I'm a student who is interested in Oracle Database and
I have some problems with JOIN and Sub-query.
I hope so many of you could help me.
if i use JOIN without sub-query, may it be faster or not?
SELECT field1, field2 FROM tableA INNER JOIN tableB
if i use JOIN with sub-query, may it be faster or not?
SELECT field1,field2,field3 FROM tableA INNER JOIN (SELECT field1,field2 FROM tableB)
Thanks in advance!
As the others have said, the execution plan will give you a better idea about which is faster.
If you're trying to see how using (or not using) a sub-query affects performance, make the rest of the queries as similar as possible. For example, include field3 in both queries, or ignore field3 in both queries.
In this particular case, I guess the optimizer would do the same thing either way, but that's just a guess. I can't see your execution plans.
In general, simpler code is faster, and better in other ways, too. In this case
tableB
is simpler than
(SELECT field1, field2 FROM tableB)
Why do you want a sub-query in this example? -
Outter-Join with requirement for sub-query
I am working on a view that needs to return 1 record per payment date within the primary payment table.
Part of the information that is to be returned in this row comes from a date-controlled table containing superannuation information. This data may or may not be present, requiring an outer-join. The final problem is that there may be multiple rows in this superannuation table requiring me to retrieve the record with the most recent start date, prior to the payment date. This is where I'm breaking down currently as I cannot outer-join to a sub-query.
I had an idea that I could create an inline view of the superannuation table with 1 row for each of the last 365 days (The reports that will be built off the view are always run within 1-2 months of the payment date), with the date and either the required information or blanks if it did not exist. This would avoid me requiring an outer-join as I could just join on the payment date to the date in the inline query and return whatever data was there.
I'm pretty sure I should be able to do this with analytics rather than creating a date table, by restricting the rows to 365, then havign a column that is effectively the previous column - 1. Unfortunately I'm fairly new to analytics and find the Oracle documentation hard to decipher.
Can anyone help with this or perhaps suggest an alternate solution?please don't do that. that's the most pathetic way generate rows. all_objects is a very nasty view, and oracle reserves the right to merge the view into the rest of your query, making performance less than you had hoped for. how about this instead:
select ...
from (
select trunc(sysdate-rownum+1) super_date
from dual
connect by level < = 365 ) dates,
your_table_here
where dates.super_date = your_column (+)
... -
Sub-query problem on Oracle 10g
The following query works on Oracle 10.2.0.1.0 on windows,but doesn't work on Oracle 10.2.0.2.0 on Linux.
Error report: SQL Error: ORA-00904: "T"."AUDIT_USECS": invalid identifier 00904. 00000 - "%s: invalid identifier"
It works after i remove the sub-query. I found that if use fields of T in sub-query,then error occurs. Is it saying that sub-query can't access the fields in main query?
What's the problem?
Is there any grammar erros?If so,what's the right likes?
Thanks!
CREATE TABLE AUDITHISTORY(
CASENUM numeric(20, 0) NOT NULL,
AUDIT_DATE date NOT NULL,
USER_NAME varchar(255) NULL,
AUDIT_USECS numeric(6, 0) NOT NULL,
TYPE_ID INT NOT NULL )
Query:
SELECT T.CASENUM,
T.USER_NAME,
T.AUDIT_DATE AS STARTED,
(SELECT *
FROM (SELECT S.AUDIT_DATE
FROM AUDITHISTORY S
WHERE S.CASENUM=T.CASENUM AND TYPE_ID=2
AND S.USER_NAME=T.USER_NAME
AND (S.AUDIT_DATE > T.AUDIT_DATE OR (S.AUDIT_DATE = T.AUDIT_DATE AND S.AUDIT_USECS > T.AUDIT_USECS))
ORDER BY S.AUDIT_DATE ASC,S.AUDIT_USECS ASC
) WHERE rownum <= 1) AS ENDED
FROM AUDITHISTORY T WHERE TYPE_ID=1
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod PL/SQL Release 10.2.0.2.0 - Production
CORE 10.2.0.2.0 Production
TNS for Linux: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - ProductionTry this way:
SQL> select * from AUDITHISTORY;
CASENUM AUDIT_DAT USER_NAME AUDIT_USECS TYPE_ID
10 12-MAR-10 USER 100 1
10 14-MAR-10 USER 100 2
10 16-MAR-10 USER 100 2
SQL> SELECT T.CASENUM,
2 T.USER_NAME,
3 T.AUDIT_DATE AS STARTED,
4 (SELECT max(S.AUDIT_DATE) keep (dense_rank first order by S.AUDIT_DATE ASC,S.AUDIT_USECS ASC)
5 from AUDITHISTORY S WHERE S.CASENUM=T.CASENUM AND TYPE_ID=2
6 AND S.USER_NAME=T.USER_NAME
7 AND (S.AUDIT_DATE > T.AUDIT_DATE OR
8 (S.AUDIT_DATE = T.AUDIT_DATE AND S.AUDIT_USECS > T.AUDIT_USECS))
9 ) as ended
10 FROM AUDITHISTORY T WHERE TYPE_ID=1;
CASENUM USER_NAME STARTED ENDED
10 USER 12-MAR-10 14-MAR-10Max
http://oracleitalia.wordpress.com -
How to make outer join in Sub Query?
Hi!
I'm facing one problem. Can anyone tell me - how to make outer join in sub query?
I'm pasting one sample code -
select e.empno, e.ename,e.job,e.sal,d.deptno,d.dname
from d_emp e, d_dept d
where e.deptno(+) = (
case
when d_dept.deptno = 10
then
select deptno
from d_dept
where dname = 'SALES'
else
d_dept.deptno
end
SQL>
ERROR at line 15:
ORA-01799: a column may not be outer-joined to a subqueryHow to resolve this issue?
Regards.And any luck with this?
SQL> with emp as
2 (select 100 empno, 'Abcd' ename, 1000 sal, 10 deptno from dual
3 union all
4 select 101 empno, 'RRR' ename, 2000 sal, 20 deptno from dual
5 union all
6 select 102 empno, 'KKK' ename, 3000 sal, 30 deptno from dual
7 union all
8 select 103 empno, 'PPP' ename, 4000 sal, 10 deptno from dual
9 )
10 ,dept as
11 (select 10 deptno, 'FINANCE' dname from dual
12 union all
13 select 20 deptno, 'SALES' dname from dual
14 union all
15 select 30 deptno, 'IT' dname from dual
16 union all
17 select 40 deptno, 'HR' dname from dual
18 )
19 select e.empno, e.ename, e.sal, d.deptno, d.dname
20 from emp e,
21 (select decode(a.deptno, 10, b.deptno, a.deptno) deptno, decode(a.deptno, 10, b.dname, a.dname) dname
22 from dept a, (select deptno, dname
23 from dept
24 where dname = 'SALES'
25 ) b
26 ) d
27 where e.deptno(+) = d.deptno
28 /
EMPNO ENAM SAL DEPTNO DNAME
101 RRR 2000 20 SALES
101 RRR 2000 20 SALES
102 KKK 3000 30 IT
40 HR
SQL> Cheers
Sarma. -
Joining with sub query not working
Hi
I am new with these complex queries. I am trying to join a sub query to a query as below;
SELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo, (SELECT EventID, SUM(Total) FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) AS Total
FROM tblEvents AS Events1 LEFT OUTER JOIN
tblClients ON Events1.ClientID = tblClients.ID
WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate
HAVING (Events1.InvoiceBatch = 5212)
ORDER BY tblClients.Company
I am getting these two errors;
Msg 8120, Level 16, State 1, Line 2
Column 'tblEvents.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 116, Level 16, State 1, Line 2
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
What am I missing?
Thanks
RegardsSELECT Events1.InvoiceBatch AS BatchNo, Events1.InvoiceBatchDate AS BatchDate, tblClients.Company, tblClients.ID AS ClientID, COUNT(Events1.ID) AS Invoices,
COUNT(*) - COUNT(Events1.InvoicePrintDate) AS E, Events1.InvoiceBatchFromDate AS BatchFrom, Events1.InvoiceBatchToDate AS BatchTo,Total
FROM tblEvents AS Events1 LEFT OUTER JOIN
tblClients ON Events1.ClientID = tblClients.ID
LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
ON sb.EventID = Events1.ID
WHERE (Events1.FactoringExportDate IS NULL) OR (Events1.AccountsExportDate IS NULL) OR (Events1.InvoiceSentDate IS NULL)
GROUP BY Events1.InvoiceBatch, Events1.InvoiceBatchDate, tblClients.Company, tblClients.ID, Events1.InvoiceBatchFromDate, Events1.InvoiceBatchToDate,Total
HAVING (Events1.InvoiceBatch = 5212)
ORDER BY tblClients.Company
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page
Says;
Msg 4104, Level 16, State 1, Line 5
The multi-part identifier "Events1.ID" could not be bound.
on
LEFT OUTER JOIN (SELECT EventID, SUM(Total) AS Total FROM tblStaffBookings AS StaffBookings WHERE StaffBookings.EventID = Events1.ID GROUP BY EventID) sb
Regards -
Best way to outer join a table that is doing a sub query
RDBMS : 11.1.0.7.0
Hello,
What is the best way to outer join a table that is doing a sub query? This is a common scenario in EBS for the date tracked tables.
SELECT papf.full_name, fu.description
FROM fnd_user fu
,per_all_people_f papf
WHERE fu.user_id = 1772
AND fu.employee_id = papf.person_id(+)
AND papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
FROM per_all_people_f per1
WHERE per1.person_id = papf.person_id)Output:
No output produced because the outer join cannot be done on the sub queryIn this case I did a query in the FROM clause. Is this my best option?
SELECT papf.full_name, fu.description
FROM fnd_user fu
,(SELECT full_name, person_id
FROM per_all_people_f papf
WHERE papf.effective_start_date = (SELECT MAX( per1.effective_start_date )
FROM per_all_people_f per1
WHERE per1.person_id = papf.person_id)) papf
WHERE fu.user_id = 1772
AND fu.employee_id = papf.person_id(+)Output:
FULL_NAME DESCRIPTION
{null} John DoeThanks,
--JohnnieHi,
BrendanP wrote:
... See the adjacent thread for the other with Row_Number().Do you mean {message:id=10564772} ? Which threads are adjacent is always changing. Post a link.
I think RANK suits the requirements better than ROW_NUMBER:
WITH all_matches AS
SELECT papf.full_name
, fu.description
, RANK () OVER ( PARTITION BY papf.person_id
ORDER BY papf.effective_start_date DESC
) AS r_num
FROM fnd_user fu
LEFT OUTER JOIN per_all_people_f papf ON fu.employee_id = papf.person_id
WHERE fu.user_id = 1772
SELECT full_name
, description
FROM all_matches
WHERE r_num = 1
Johnnie: I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
See the forum FAQ {message:id=9360002} -
Issue with join condition while using in the corelated sub query
Bees,
I am not able to use the below query since i have used a join condition in the corelated sub qery inline view.But i have a requirement like this . Please help me on this
select * from dept d
where exists (select 1 from (
select deptno
from emp where deptno= d.deptno)
Thank you
BooooHi,
I've never seen a general solution for how to reference columns from main query a from sub-query c, where c is is sub-query of b, which is a sub-query of a.
Whenever I've wanted to, I've been able to get the desired results with a different approach.
In this case, you seem to want
SELECT *
FROM dept d
WHERE EXISTS (
SELECT 1
FROM emp
WHERE deptno = d.deptno
);I'm guessing at your data and desired output. -
Oracle Discoverer Plus - Don't run query automatically
I have, in the Options tab in Oracle Discoverer Plus, a check mark next to not run a query automatically. This is not working when I have several worksheets in my report. After I run one worksheet and click on the next (tab) worksheet it automatically runs that report with the old parameter values thereby providing ambiguous results.
Hi,
Try editing the parameter and selecting "Allow a different value in each sheet".
Rod West -
Can i join a list in sub-site using Join query?
Hi all,
I'm newbie and i have tried to join a list in parent site with a list in sub-site using Join query but i always get the error. How can i do this action? Thanks!You could try using SPSiteDataQuery or a DataTable.
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery%28v=office.14%29.aspx
http://sharepoint.stackexchange.com/questions/75713/is-it-possible-to-populate-result-by-joining-two-lists-throughout-the-site-colle
--Cheers -
Correlation in Oracle Discoverer
Hi,
I know how to calculate correlation in Oracle discoverer plus using calculations but is there a way for us to give the users the ability to drag drop the variable they want to see the correlation between in viewer. So for example if the user wanted to see the correlation between SAT scores and age they could just select the variables somehow and see the correlation between them.
ThanksThere is no straight forward way but one possible solution:
1.
Create a folder in the eul that contains two columns
1) a dummy column
2) a LOV column
I usually do this with a query SELECT 'dummy' as joiner, 'LOV ITEM' as lov_item from dual union....;
2.
create a LOV on the LOV Item column
3.
create a join between the new table and another table in the workbook
4.
create 2 parameters based on the lov item column (do not create a condition with the parameter)
5. create a calculation that calculation that well correlate two items based on the values of the parameters
6. remove the new table from the workbook. The new table will not affect how many rows are returned but the parameters still look at the LOV table. -
Oracle date parameter query not working?
http://stackoverflow.com/questions/14539489/oracle-date-parameter-query-not-working
Trying to run the below query, but always fails even though the parameter values matches. I'm thinking there is a precision issue for :xRowVersion_prev parameter. I want too keep as much precision as possible.
Delete
from CONCURRENCYTESTITEMS
where ITEMID = :xItemId
and ROWVERSION = :xRowVersion_prev
The Oracle Rowversion is a TimestampLTZ and so is the oracle parameter type.
The same code & query works in Sql Server, but not Oracle.
Public Function CreateConnection() As IDbConnection
Dim sl As New SettingsLoader
Dim cs As String = sl.ObtainConnectionString
Dim cn As OracleConnection = New OracleConnection(cs)
cn.Open()
Return cn
End Function
Public Function CreateCommand(connection As IDbConnection) As IDbCommand
Dim cmd As OracleCommand = DirectCast(connection.CreateCommand, OracleCommand)
cmd.BindByName = True
Return cmd
End Function
<TestMethod()>
<TestCategory("Oracle")> _
Public Sub Test_POC_Delete()
Dim connection As IDbConnection = CreateConnection()
Dim rowver As DateTime = DateTime.Now
Dim id As Decimal
Using cmd As IDbCommand = CreateCommand(connection)
cmd.CommandText = "insert into CONCURRENCYTESTITEMS values(SEQ_CONCURRENCYTESTITEMS.nextval,'bla bla bla',:xRowVersion) returning ITEMID into :myOutputParameter"
Dim p As OracleParameter = New OracleParameter
p.Direction = ParameterDirection.ReturnValue
p.DbType = DbType.Decimal
p.ParameterName = "myOutputParameter"
cmd.Parameters.Add(p)
Dim v As OracleParameter = New OracleParameter
v.Direction = ParameterDirection.Input
v.OracleDbType = OracleDbType.TimeStampLTZ
v.ParameterName = "xRowVersion"
v.Value = rowver
cmd.Parameters.Add(v)
cmd.ExecuteNonQuery()
id = CType(p.Value, Decimal)
End Using
Using cmd As IDbCommand = m_DBTypesFactory.CreateCommand(connection)
cmd.CommandText = " Delete from CONCURRENCYTESTITEMS where ITEMID = :xItemId and ROWVERSION = :xRowVersion_prev"
Dim p As OracleParameter = New OracleParameter
p.Direction = ParameterDirection.Input
p.DbType = DbType.Decimal
p.ParameterName = "xItemId"
p.Value = id
cmd.Parameters.Add(p)
Dim v As OracleParameter = New OracleParameter
v.Direction = ParameterDirection.Input
v.OracleDbType = OracleDbType.TimeStampLTZ
v.ParameterName = "xRowVersion_prev"
v.Value = rowver
v.Precision = 6 '????
cmd.Parameters.Add(v)
Dim cnt As Integer = cmd.ExecuteNonQuery()
If cnt = 0 Then Assert.Fail() 'should delete
End Using
connection.Close()
End Sub
Schema:
-- ****** Object: Table SYSTEM.CONCURRENCYTESTITEMS Script Date: 1/26/2013 11:56:50 AM ******
CREATE TABLE "CONCURRENCYTESTITEMS" (
"ITEMID" NUMBER(19,0) NOT NULL,
"NOTES" NCHAR(200) NOT NULL,
"ROWVERSION" TIMESTAMP(6) WITH LOCAL TIME ZONE NOT NULL)
STORAGE (
NEXT 1048576 )
Sequence:
-- ****** Object: Sequence SYSTEM.SEQ_CONCURRENCYTESTITEMS Script Date: 1/26/2013 12:12:48 PM ******
CREATE SEQUENCE "SEQ_CONCURRENCYTESTITEMS"
START WITH 1
CACHE 20
MAXVALUE 9999999999999999999999999999still not comming...
i have one table each entry is having only one fromdata and one todate only
i am running below in sql it is showing two rows. ok.
select t1.U_frmdate,t1.U_todate ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf
from [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
on t0.DocEntry = t1.DocEntry
inner join ohem t2
on t2.empID = t0.U_empid where t0.U_empid between '830' and '850' and t1.U_frmdate ='20160801' and t1.u_todate='20160830'
in commond promt
select t1.U_frmdate,t1.U_todate ,ISNULL(t2.firstName,'')+ ',' +ISNULL(t2.middleName ,'')+','+ISNULL(t2.lastName,'') AS NAME, T2.empID AS EMPID, T2.U_emp AS Empticket,t2.U_PFAcc,t0.U_pf
from [@PR_PRCSAL1] t0 inner join [@PR_OPRCSAL] t1
on t0.DocEntry = t1.DocEntry
inner join ohem t2
on t2.empID = t0.U_empid where t0.U_empid between {?FromEmid} and {?ToEmid} and t1.U_frmdate ={?FDate} and t1.u_todate={?TDate}
still not showing any results..
Maybe you are looking for
-
Mail in continuous "Synchronizing with Server" (all mail, not just Mail.app)
Since upgrading to 10.9 Mavericks, Mail (Apple) continually syncrhonizes with the servers. I have a plethora of folders stored via iCloud (IMAP). When it gets to the end, there's a short lull but, if I do anything else, the process starts again. (Vie
-
I just wanted to share my experience with Snow Leopard. I've heard there are problems with Snow Leopard and some HP Printers. I depend on my printer for school, so I played it safe and installed Snow Leopard on an external USB drive and played around
-
Can you use same earphones for iPhone and iPad air
Can you use the earphones from an iPhone on an iPad air
-
Physical and Books stocks report
Hi Experts, I want to show the report with stock key figures as Physical and Book stock quantity and values in Bex report. Plz let me know any BW standard cube or ODS available for this. Thanks in Advance, chandra
-
Parameters to Stop Printing in Open_form
Hello All, i have one requirement, in some cases i should not print the printout Goods Issue. but right now we are using the standard print program and just before calling the Open_form i have one exit with same parameters as Open_form. By changing t