Please help me constructing this query
please help me .
table a
===========
transactionid personname year dept
r001 person1 y1 d1
r002 person1 y2 d2
r005 person3 y1 d2
r004 person2 y2 d1
table b
===========
transactionid personname year
r005 person3 y2
r006 person4 y1
r001 person1 y1
outout should be like
======================
transactionid personname year dept
r001 person1 y1 d1 record present (combination of transactionid/personname/year)in table a from table b
r005 person3 y2 d2 (no data present in table a (transactionid/personname/year) from table b
so it will retrive previous dept records for this person for this year so here d2)
r006 person4 y1 unknown no data present for this person in table a so department will be unknown
table creation script
=====================
CREATE TABLE A
TRANSACTIONID VARCHAR2(30 BYTE),
PERSONNAME VARCHAR2(30 BYTE),
YEAR VARCHAR2(30 BYTE),
DEPT VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r001', 'person1', 'y1', 'd1');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r002', 'person1', 'y2', 'd2');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r004', 'person2', 'y2', 'd1');
Insert into A
(TRANSACTIONID, PERSONNAME, YEAR, DEPT)
Values
('r005', 'person3', 'y1', 'd2');
COMMIT;
CREATE TABLE B
TRANSACTIONID VARCHAR2(30 BYTE),
PERSONNAME VARCHAR2(30 BYTE),
YEAR VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r001', 'person1', 'y1');
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r006', 'person4', 'y1');
Insert into B
(TRANSACTIONID, PERSONNAME, YEAR)
Values
('r005', 'person3', 'y2');
COMMIT;
Anirudha Dhopate wrote:
Following query should work - Data magic:
SQL> SELECT *
2 FROM a
3 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d1
r002 person1 2011 d2
r004 person2 2011 d1
r005 person3 2010 d2
r001 person1 2010 d2
SQL> SELECT *
2 FROM b
3 /
TRANSACTIONID PERSONNAME YEAR
r001 person1 2010
r006 person4 2010
r005 person3 2011
SQL> SELECT b.transactionid
2 ,b.personname
3 ,b.year
4 ,a.dept
5 FROM a
6 RIGHT OUTER JOIN b
7 ON ((a.transactionid = b.transactionid) AND
8 (a.personname = b.personname) AND
9 (a.year = b.year OR a.year = b.year - 1))
10 ORDER BY b.transactionid
11 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d1
r001 person1 2010 d2
r005 person3 2011 d2
r006 person4 2010
SQL> select b.transactionid,
2 b.personname,
3 b.year,
4 max(a.dept) keep(dense_rank last order by a.year) dept
5 from b
6 left join
7 a
8 on (
9 b.transactionid = a.transactionid
10 and
11 b.personname = a.personname
12 and
13 b.year >= a.year
14 )
15 group by b.transactionid,
16 b.personname,
17 b.year
18 /
TRANSACTIONID PERSONNAME YEAR DEPT
r001 person1 2010 d2
r005 person3 2011 d2
r006 person4 2010
SQL> SY.
Similar Messages
-
Please help to modifiy this query for better performance
Please help to rewrite this query for better performance. This is taking long time to execute.
Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains 200000 rows.
I have created index on ACCOUNT_ID
Query is shown below
update rbabu.t_t_bil_bil_cycle_change a
set account_number =
( select distinct b.account_number
from rbabu.t_acctnumberTab b
where a.account_id = b.account_id
Table structure is shown below
SQL> DESC t_acctnumberTab;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24)
SQL> DESC t_t_bil_bil_cycle_change;
Name Type Nullable Default Comments
ACCOUNT_ID NUMBER(10)
ACCOUNT_NUMBER VARCHAR2(24) YIshan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
merge rbabu.t_t_bil_bil_cycle_change a
using
( select distinct account_number, account_id
from rbabu.t_acctnumberTab
) t
on ( a.account_id = b.account_id
and decode(a.account_number, b.account_number, 0, 1) = 1
when matched then
update set a.account_number = b.account_number -
Could you please help me make this query less complicated
could you please help me make this query less complicated
select t1.R_OBJECT_ID
from dm_relation_sp a, ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID
union all
select t3.R_OBJECT_ID
from ddt_resolution_sp t3
where t3.R_OBJECT_ID in (select t2.child_id
from dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
union all
select t4.R_OBJECT_ID
from ddt_resolution_sp t4
where t4.R_OBJECT_ID in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
union all
select t5.R_OBJECT_ID
from ddt_resolution_sp t5
where t5.R_OBJECT_ID in
(select t4.child_id
from dm_relation_sp t4
where t4.parent_id in(
select t3.child_id from dm_relation_sp t3
where t3.parent_id in (
select t2.child_id
from asud_fsk.dm_relation_sp t2
where t2.parent_id in (select a.child_id
from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
where a.parent_id = '0900000283560456' -----------ID
and a.child_id = t1.R_OBJECT_ID))
and t3.relation_name = 'RESOLUTION_RELATION')
and t4.relation_name = 'RESOLUTION_RELATION')
Edited by: user13025450 on 29.04.2010 16:23Hi,
Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
Describe what you're doing. Think about it: how do we know that
SELECT NULL
FROM dual;doesn't do what you want?
Post CREATE TABLE and INSERT statements for a little sample data.
Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
Describe, as well as you can, how the present query is doing it.
Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
When posting formatted text (code or results) type these 6 characters
\(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing? -
I would like to create a view on this table with four columns
1. PN#_EXP_DATE
2. PN#
3. PN#_EFF_DATE
4. PN#
P_S_C A_C P EXP_DT
21698 13921 1 5/29/2009 3:15:41 PM
21698 13921 1 5/29/2009 3:54:57 PM
21698 1716656 4 5/29/2009 3:15:41 PM
21698 3217 3 5/29/2009 3:15:40 PM
21698 3217 3 5/29/2009 3:54:57 PM
21698 60559 2 5/29/2009 3:15:41 PM
21698 60559 2 5/29/2009 3:54:57 PM
I have a trigger on A, which inserts the DML records into B. (Table A and B structure is the almost the same,
where table B will have one extra column exp_dt)
NOw Table B can have records with same P_S_C and A_C columns and exp_dt will capture the history.
for example: from the above sample data, let us take first two records..
P_S_C A_C P EXP_DT
21698 13921 1 5/29/2009 3:15:41 PM --- Record 1
21698 13921 1 5/29/2009 3:54:57 PM --- Record 2
from this..
Note: 1. Table A and Table C can be joined using A.P_S_C and C.R_C to get the start_date.
2. PN# comes from table D. It contains numbers for the resp. weeks.
3. PN#_EFF_DATE is the previous immediate previous date for that record in history table (Table B).
I wanted the data like..
---- this is for the second record in the above..
PN#_EXP_DATE PN# PN#_EFF_DATE PN#
5/29/2009 3:54:57 PM 214 5/29/2009 3:15:41 PM 214
---- this is for the first record in the above..
PN#_EXP_DATE PN# PN#_EFF_DATE PN#
5/29/2009 3:54:41 PM 214 ( for this we should query the table C to get the
start_date, for this combinatation of P_S_C and A_C in table B
where B.P_S_C = C.A_C
and that value should be the EFF_DT for this record)
Please help me with this....
Thanks in advance..Hi All,
select d.P# as "PN#_EXP_DATE", exp_date
from daily_prd d, cbs1_assoc_hist b
where to_char(d.day_date,'MM/DD/YYYY') = to_char(b.exp_date,'MM/DD/YYYY')
and d.period_type = 'TIMEREPORT';
This above query gives the output as follows:
pn#_exp_date exp_date
214 5/29/2009 3:15:40 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:15:41 PM
214 5/29/2009 3:54:57 PM
214 5/29/2009 3:54:57 PM
214 5/29/2009 3:54:57 PM
This below is the data from history table (Table B).
P_S_C A_C PLACE EXP_DATE
21698 3217 3 5/29/2009 3:15:40 PM
21698 13921 1 5/29/2009 3:15:41 PM
21698 1716656 4 5/29/2009 3:15:41 PM
21698 60559 2 5/29/2009 3:15:41 PM
21698 13921 1 5/29/2009 3:54:57 PM
21698 3217 3 5/29/2009 3:54:57 PM
21698 60559 2 5/29/2009 3:54:57 PM
I got the pn#_exp_date from the Table 'D', for the given exp_date from Table B.
My question is again....
CASE - 1
from the given records above, I need to look for exp_date for the given same P_S_C and A_C.
in this case we can take the example...
P_S_C A_C PLACE EXP_DATE
21698 3217 3 5/29/2009 3:15:40 PM
21698 3217 3 5/29/2009 3:54:57 PM
In this case, the
pn#_exp_date exp_date pn#_eff_date eff_date
214 5/29/2009 3:15:57 PM < PN# corresponding to the 5/29/2009 3:15:40 PM
eff_date .>
<Basically the eff_date is
nothing but the exp_date only.
we should take the immediate before one.
In this case, our eff_date is '5/29/2009 3:15:40 PM'.
but how to get this.
CASE - 2
from the above sample data, consider this
P_S_C A_C PLACE EXP_DATE
21698 1716656 4 5/29/2009 3:15:41 PM
In this case, there is only one record for the P_S_C and A_C combination.
The expected result :
pn#_exp_date exp_date pn#_eff_date eff_date
214 5/29/2009 3:15:41 PM < PN# corresponding to the 5/29/2009 3:15:40 PM
eff_date .>
<Basically the eff_date is
nothing but the exp_date only.
we should take the immediate before one.
In this case to get the eff_date, we should query the Table 'C', to get the eff_date, which is START_DT column in this table.
for this join B.P_S_C and C.R_C.
Hope I am clear now..
Thanks in advance..... -
Hi Everyone...Please help me with this query...!
Please Help me with this doubt as I am unable to understand the logic...behind this code. It's a begineer level code but I need to understand the logic so that I am able to grasp knowledge. Thank you all for being supportive. Please help me.
//Assume class Demo is inherited from class SuperDemo...in other words class Demo extends SuperDemo
//Volume is a method declared in SuperDemo which returns an integer value
//weight is an integer vairable declared in the subclass which is Demo
class Example
public static void main(String qw[])
Demo ob1=new Demo(3,5,7,9);
//Calling Constructor of Demo which takes in 4 int parameters
SuperDemo ob2=new SuperDemo();
int vol;
vol=ob1.volume();
System.out.println("Volume of ob1 is " + vol);
System.out.println("Weight of ob1 is " + ob1.weight);
System.out.println();
ob2=ob1;
}Can someone please make me understand --- how is this possible and why !
If the above statement is valid then why not this one "System.out.println(ob2.weight);"
Thanks Thanks Thanks!u see the line wherein I am referencing the objectof
a subclass to the superclass...right? then why we
can't do System.out.println(ob2.weight)?You need to distinguish two things:
- the type of the object, which determines with the
object can do
- the type of the reference to the object, which
determines what you see that you can do
Both don't necessarily have to match. When you use a
SuperDemo reference (obj2) to access a Demo instance
(obj1), for all you know, the instance behind obj2 is
of type SuperDemo. That it's in reality of type Demo
is unknown to you. And usually, you don't care -
that's what polymorphism is about.
So you have a reference obj2 of type SuperDemo.
SuperDemo objects don't have weight, so you don't see
it - even though it is there.So from ur explanation wat I understand is - Even though u reference a subclass object to a superclass, u will only be able to access the members which are declared in the superclass thru the same...right
? -
Please help me with this query -- i am trying with Dense rank
version 10g
i received a quote for an account. if the same quote is received under different account then i should mark the previous account received as deleted.
please help me .
/* Formatted on 2010/06/28 14:13 (Formatter Plus v4.8.8) */
WITH temp AS
(SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
TO_DATE ('12/23/2009 3:37:54',
'mm/dd/yyyy hh:mi:ss PM'
) captured_date
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'RFS',
TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Rejected',
TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Ordered',
TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'RFS',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Rejected',
TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Validated',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
FROM DUAL)
SELECT quote_id, ACCOUNT, status, captured_date,
DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
ACCOUNT) rn
-- ,CASE DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id,
-- ACCOUNT)
-- WHEN 1
-- THEN 'Y'
-- ELSE 'N'
-- END deleted_flag
FROM temp
ORDER BY quote_id, captured_date;output required
WITH temp AS
(SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
TO_DATE ('12/23/2009 3:37:54',
'mm/dd/yyyy hh:mi:ss PM'
) captured_date, 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'RFS',
TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Rejected',
TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Ordered',
TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'RFS',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Rejected',
TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-11TWQL', 'D1', 'Validated',
TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'RFS',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Rejected',
TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'COPS', 'Validated',
TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM'), 'Y' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'RFS',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8X', 'D1', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Validated',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL
UNION ALL
SELECT '1-249A8Z', 'COPS', 'Ordered',
TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM'), 'N' deleted_flag
FROM DUAL)
SELECT quote_id, ACCOUNT, status, captured_date, deleted_flag
FROM temp
ORDER BY quote_id, captured_date;try to wrap your query to become an in-line view. use a case statement or decode to your derived column RN from the analytic query of DENSE RANK. either way they both will work.
SQL> WITH temp AS
2 (SELECT '1-11TWQL' quote_id, 'COPS' ACCOUNT, 'Ordered' status,
3 TO_DATE ('12/23/2009 3:37:54',
4 'mm/dd/yyyy hh:mi:ss PM'
5 ) captured_date
6 FROM DUAL
7 UNION ALL
8 SELECT '1-11TWQL', 'COPS', 'RFS',
9 TO_DATE ('12/23/2009 3:37:50', 'mm/dd/yyyy hh:mi:ss PM')
10 FROM DUAL
11 UNION ALL
12 SELECT '1-11TWQL', 'COPS', 'Rejected',
13 TO_DATE ('12/23/2009 3:37:52', 'mm/dd/yyyy hh:mi:ss PM')
14 FROM DUAL
15 UNION ALL
16 SELECT '1-11TWQL', 'COPS', 'Validated',
17 TO_DATE ('12/23/2009 3:37:51', 'mm/dd/yyyy hh:mi:ss PM')
18 FROM DUAL
19 UNION ALL
20 SELECT '1-11TWQL', 'D1', 'Ordered',
21 TO_DATE ('12/23/2009 3:04:24', 'mm/dd/yyyy hh:mi:ss PM')
22 FROM DUAL
23 UNION ALL
24 SELECT '1-11TWQL', 'D1', 'RFS',
25 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
26 FROM DUAL
27 UNION ALL
28 SELECT '1-11TWQL', 'D1', 'Rejected',
29 TO_DATE ('12/23/2009 3:04:22', 'mm/dd/yyyy hh:mi:ss PM')
30 FROM DUAL
31 UNION ALL
32 SELECT '1-11TWQL', 'D1', 'Validated',
33 TO_DATE ('12/23/2009 3:04:23', 'mm/dd/yyyy hh:mi:ss PM')
34 FROM DUAL
35 UNION ALL
36 SELECT '1-249A8X', 'COPS', 'RFS',
37 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
38 FROM DUAL
39 UNION ALL
40 SELECT '1-249A8X', 'COPS', 'RFS',
41 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
42 FROM DUAL
43 UNION ALL
44 SELECT '1-249A8X', 'COPS', 'RFS',
45 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
46 FROM DUAL
47 UNION ALL
48 SELECT '1-249A8X', 'COPS', 'Rejected',
49 TO_DATE ('3/5/2010 12:04:24', 'mm/dd/yyyy hh:mi:ss PM')
50 FROM DUAL
51 UNION ALL
52 SELECT '1-249A8X', 'COPS', 'Rejected',
53 TO_DATE ('3/16/2010 7:55:50', 'mm/dd/yyyy hh:mi:ss PM')
54 FROM DUAL
55 UNION ALL
56 SELECT '1-249A8X', 'COPS', 'Rejected',
57 TO_DATE ('3/16/2010 7:55:51', 'mm/dd/yyyy hh:mi:ss PM')
58 FROM DUAL
59 UNION ALL
60 SELECT '1-249A8X', 'COPS', 'Validated',
61 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
62 FROM DUAL
63 UNION ALL
64 SELECT '1-249A8X', 'COPS', 'Validated',
65 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
66 FROM DUAL
67 UNION ALL
68 SELECT '1-249A8X', 'COPS', 'Validated',
69 TO_DATE ('12/23/2009 3:37:54', 'mm/dd/yyyy hh:mi:ss PM')
70 FROM DUAL
71 UNION ALL
72 SELECT '1-249A8X', 'D1', 'Ordered',
73 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
74 FROM DUAL
75 UNION ALL
76 SELECT '1-249A8X', 'D1', 'Ordered',
77 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
78 FROM DUAL
79 UNION ALL
80 SELECT '1-249A8X', 'D1', 'RFS',
81 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
82 FROM DUAL
83 UNION ALL
84 SELECT '1-249A8X', 'D1', 'RFS',
85 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
86 FROM DUAL
87 UNION ALL
88 SELECT '1-249A8X', 'D1', 'Validated',
89 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
90 FROM DUAL
91 UNION ALL
92 SELECT '1-249A8X', 'D1', 'Validated',
93 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
94 FROM DUAL
95 UNION ALL
96 SELECT '1-249A8Z', 'COPS', 'Validated',
97 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
98 FROM DUAL
99 UNION ALL
100 SELECT '1-249A8Z', 'COPS', 'Ordered',
101 TO_DATE ('3/26/2010 12:32:27', 'mm/dd/yyyy hh:mi:ss PM')
102 FROM DUAL)
103 select vt.quote_id,
104 vt.account,
105 vt.status,
106 vt.captured_date,
107 case when vt.rn = 1 then 'N'
108 else 'Y'
109 end deleted_flag
110 from (SELECT quote_id, ACCOUNT, status, captured_date,
111 DENSE_RANK () OVER (PARTITION BY quote_id ORDER BY quote_id, ACCOUNT) rn
112 FROM temp
113 ORDER BY quote_id, captured_date) vt;
QUOTE_ID ACCOUNT STATUS CAPTURED_DATE DELETED_FLAG
1-11TWQL D1 Rejected 23-Dec-2009 3 Y
1-11TWQL D1 RFS 23-Dec-2009 3 Y
1-11TWQL D1 Validated 23-Dec-2009 3 Y
1-11TWQL D1 Ordered 23-Dec-2009 3 Y
1-11TWQL COPS RFS 23-Dec-2009 3 N
1-11TWQL COPS Validated 23-Dec-2009 3 N
1-11TWQL COPS Rejected 23-Dec-2009 3 N
1-11TWQL COPS Ordered 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS Validated 23-Dec-2009 3 N
1-249A8X COPS RFS 05-Mar-2010 1 N
1-249A8X COPS Rejected 05-Mar-2010 1 N
1-249A8X COPS RFS 16-Mar-2010 7 N
1-249A8X COPS Rejected 16-Mar-2010 7 N
1-249A8X COPS Rejected 16-Mar-2010 7 N
1-249A8X COPS RFS 16-Mar-2010 7 N
1-249A8X D1 Ordered 26-Mar-2010 1 Y
1-249A8X D1 Ordered 26-Mar-2010 1 Y
1-249A8X D1 RFS 26-Mar-2010 1 Y
1-249A8X D1 RFS 26-Mar-2010 1 Y
1-249A8X D1 Validated 26-Mar-2010 1 Y
1-249A8X D1 Validated 26-Mar-2010 1 Y
1-249A8Z COPS Validated 26-Mar-2010 1 N
1-249A8Z COPS Ordered 26-Mar-2010 1 N
25 rows selected
SQL> -
Hi experts,
I have data like this in a table with 5000 records.
ID cid Name
1 10 Ram
1 20 Raj
2 10 Kiran
2 20 Kishor
2 30 Krishna
2 40 Karuna
2 50 Kamesh
2 50 Kumar
2 50 Kamal
2 60 Keerti
3 10 Syam
3 20 Suresh
3 30 Suman
3 40 Santosh
3 40 Sarat
3 50 Sirisha
3 60 Sumanth
4 10 Tarun
4 20 Tanish
4 30 Taman
4 40 Tomas
4 40 Teenu
5 10 Prakash
5 20 Pavan
5 30 Prasad
etc
I want the output like
ID CID NAME
1 10,20 Ram,Raj
2 10,20,30,40,50,50,50,60 Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Keerti
3 10,20,30,40,40,50,60 Syam,Suresh,Suman,Santosh, Sarat,Sirisha,Sumanth
4 10,20,30,40,40 Tarun,Tanish,Taman,Tomas,Teenu
5 10,20,30 Prakash,Pavan,Prasad
Please help me to get the output like this
Thanks in advancewith t as (
select 1 id,10 cid,'Ram' name from dual union all
select 1,20,'Raj' from dual union all
select 2,10,'Kiran' from dual union all
select 2,20,'Kishor' from dual union all
select 2,30,'Krishna' from dual union all
select 2,40,'Karuna' from dual union all
select 2,50,'Kamesh' from dual union all
select 2,50,'Kumar' from dual union all
select 2,50,'Kamal' from dual union all
select 2,60,'Keerti' from dual union all
select 3,10,'Syam' from dual union all
select 3,20,'Suresh' from dual union all
select 3,30,'Suman' from dual union all
select 3,40,'Santosh' from dual union all
select 3,40,'Sarat' from dual union all
select 3,50,'Sirisha' from dual union all
select 3,60,'Sumanth' from dual union all
select 4,10,'Tarun' from dual union all
select 4,20,'Tanish' from dual union all
select 4,30,'Taman' from dual union all
select 4,40,'Tomas' from dual union all
select 4,40,'Teenu' from dual union all
select 5,10,'Prakash' from dual union all
select 5,20,'Pavan' from dual union all
select 5,30,'Prasad' from dual
-- end of on-the-fly data sample
select id,
rtrim(xmlagg(xmlelement(e,cid,',').extract('//text()') order by cid),',') cid,
rtrim(xmlagg(xmlelement(e,name,',').extract('//text()') order by cid),',') name
from t
group by id
order by id
ID CID NAME
1 10,20 Ram,Raj
2 10,20,30,40,50,50,50,60 Kiran,Kishor,Krishna,Karuna,Kamesh,Kamal,Kumar,Keerti
3 10,20,30,40,40,50,60 Syam,Suresh,Suman,Santosh,Sarat,Sirisha,Sumanth
4 10,20,30,40,40 Tarun,Tanish,Taman,Tomas,Teenu
5 10,20,30 Prakash,Pavan,Prasad
SQL> SY. -
Please help me tune this query
Hi,
Could you please suggest how the below query can be tuned? At present the query takes an hour to execute for a single transaction.
===================================================================
/* Formatted on 2009/07/27 17:44 (Formatter Plus v4.8.8) */
SELECT 'x' x,
SUBSTR (cn.trx_number, 1, INSTR (cn.trx_number, 'CN') - 1) invoice_num,
DECODE (INSTR (cn.trx_number, 'CNT'),
0, '¿¿¿¿¿¿¿¿ (CREDIT NOTE)',
'¿¿¿¿¿¿¿¿ (CREDIT NOTE) / ¿¿¿¿¿¿¿¿¿¿¿'
) report_name,
INSTR (cn.trx_number, 'CNT') v_or_nv,
xxth_get_info.get_org_name (:org_id) head_office_name, lc.location_id,
lc.location_code, lc.attribute1 tax_regis_number,
lc.attribute2 tax_payer_id, lc.attribute14 branch_number,
lc.attribute15 name_of_place_of_business,
lc.address_line_1 || ' ' || lc.address_line_2 address_line1,
lc.address_line_3 || ' ' || lc.region_1 address_line2,
lc.region_2
|| ' '
|| lc.town_or_city
|| ' '
|| lc.postal_code
|| ' '
|| lc.country address_line3,
cn.type_cn, cn.rac_bill_to_customer_name, cn.address1,
cn.raa_bill_to_address3, cn.bill_to_site_use_id, cn.trx_date,
cn.trx_number, cn.rac_bill_to_customer_num, cn.description,
ABS (cn.extended_amount) extended_amount, ABS (cn.tax_amt) tax_amt,
rc.trx_rec_number, rc.apply_date, rc.cash_receipt_id
FROM ra_cust_trx_types cc,
hr_locations_v lc,
(SELECT b.cash_receipt_id, a.trx_number, b.trx_rec_number,
b.apply_date
FROM ar_payment_schedules a, ar_app_adj_v b,ar_cash_receipts c
WHERE b.payment_schedule_id = a.payment_schedule_id
AND c.cash_receipt_id=b.cash_receipt_id
AND c.status='APP'
AND b.CLASS = 'Payment'
group by b.cash_receipt_id, a.trx_number, b.trx_rec_number,b.apply_date) rc,
(SELECT 'B' type_cn, a.customer_trx_id, a.cust_trx_type_id,
a.rac_bill_to_customer_name,
a.raa_bill_to_address1
|| ' '
|| a.raa_bill_to_address2 address1,
a.raa_bill_to_address3, a.bill_to_site_use_id, a.trx_date,
a.trx_number,
( SUBSTR (a.trx_number, 1,
INSTR (a.trx_number, 'CN', -1) - 1)
|| SUBSTR (a.trx_number, INSTR (a.trx_number, 'CN', -1) + 2)
) trx_number_cmp,
a.rac_bill_to_customer_num,
ctl.description, -- b.description
sum(nvl(ctl.gross_extended_amount, ctl.extended_amount)) extended_amount, -- V2.0
-- SUM (c.extended_amount) tax_amt -- V2.0
select SUM (ctl_tax.extended_amount)
from ra_customer_trx_lines ctl_tax,
ra_customer_trx_lines ctl_line
WHERE ctl_tax.link_to_cust_trx_line_id = ctl_line.customer_trx_line_id
AND ctl_tax.line_type = 'TAX'
AND ctl_tax.customer_trx_id = a.customer_trx_id
) tax_amt
FROM ra_customer_trx_partial_v a,
ra_customer_trx_lines ctl,
ra_customer_trx ct,
ra_cust_trx_types ctt,
hz_cust_acct_sites radd,
hz_party_sites party_site,
hz_locations loc,
hz_cust_site_uses site
-- ra_customer_trx_lines_v b
-- ar_tax_summ_v c
WHERE a.ctt_class = 'CM'
AND ctl.line_type = 'LINE'
&P_CUSTOMER_NUM_CLAUSE
&P_CUST_TRX_NUM_CLAUSE
-- AND b.customer_trx_id = a.customer_trx_id
AND ctl.customer_trx_id = a.customer_trx_id
AND ctl.customer_trx_id = ct.customer_trx_id
AND ct.cust_trx_type_id = ctt.cust_trx_type_id
AND ctt.TYPE NOT IN ('DEP', 'GUAR', 'BR')
AND ct.bill_to_site_use_id = site.site_use_id
AND site.cust_acct_site_id = radd.cust_acct_site_id
AND radd.party_site_id = party_site.party_site_id
AND loc.location_id = party_site.location_id
-- AND c.customer_trx_id(+) = a.customer_trx_id
GROUP BY a.cust_trx_type_id,
a.rac_bill_to_customer_name,
a.raa_bill_to_address1,
a.raa_bill_to_address2,
a.raa_bill_to_address3,
a.bill_to_site_use_id,
a.trx_date,
a.trx_number,
a.rac_bill_to_customer_num,
a.customer_trx_id,
ctl.description,
(SUBSTR (a.trx_number, 1, INSTR (a.trx_number, 'CN') - 1)
)) cn
WHERE cc.cust_trx_type_id = cn.cust_trx_type_id
AND cc.global_attribute19 = lc.location_code(+)
AND rc.trx_number = cn.trx_number_cmp
=============================================================Post relevant all details as explained in this instruction:
HOW TO: Post a SQL statement tuning request - template posting -
Please help me tuning this query...
Hi all,
Can any body suggest some changes (synthatic) so that it can improve its performance... taking too much time...
This is a query used in oracle report...
SELECT distinct cc.seg1,cc.seg2,cc.seg3,cc.seg4,cc.seg5,cc.seg6,cc.seg7,cc.seg8,cc.code_combination_id code_comb_id,
r.flex_validation_rule_name cv_rule,gl.currency_code currency1,
(NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0)) trans_amount,
gjh.doc_sequence_value doc_num,
gjs.user_je_source_name je_source, gjc.user_je_category_name je_category,
fu.user_name last_updated_by,(NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0))
+ (NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0)) balance,
gjh.last_update_date last_updated_date,gjl.effective_date
FROM gl_code_combinations cc,
fnd_flex_vdation_rules_vl r,
fnd_flex_validation_rule_lines l,
gl_je_headers gjh,
gl_je_lines gjl,
gl_balances gb,
fnd_user fu,
gl_je_categories gjc,
gl_je_sources gjs,
gl_ledgers gl
WHERE cc.enabled_flag = 'Y'
AND NVL (cc.end_date_active, SYSDATE + 1) > SYSDATE
AND cc.chart_of_accounts_id = :p_chart_of_accounts_id
AND r.id_flex_num = cc.chart_of_accounts_id
AND r.id_flex_code = 'GL#'
AND r.application_id = 101
AND gjs.je_source_name=gjh.je_source
AND gjc.je_category_name=gjh.je_category
AND l.application_id = r.application_id
AND gb.code_combination_id=cc.code_combination_id
AND gjh.period_name=gb.period_name
AND r.enabled_flag = 'Y'
AND NVL (r.end_date_active, SYSDATE + 1) > SYSDATE
AND l.id_flex_code = r.id_flex_code
AND l.id_flex_num = r.id_flex_num
AND l.flex_validation_rule_name = r.flex_validation_rule_name
AND l.include_exclude_indicator = 'E'
AND gjl.code_combination_id = gb.code_combination_id
AND gjh.je_header_id = gjl.je_header_id
AND gjh.status = 'P'
AND gl.ledger_id=gjh.ledger_id
and gl.ledger_id=:p_ledger_id
AND gjh.last_updated_by = fu.user_id
and (gjh.last_update_date,gjl.last_update_date)=(
SELECT MAX (a.last_update_date) ,MAX(b.last_update_date)
FROM gl_je_headers a, gl_je_lines b
WHERE b.code_combination_id = cc.code_combination_id
AND a.je_header_id = b.je_header_id
AND a.status = 'P'
AND ROWNUM = 1)
and (NVL (gjl.accounted_dr, 0) - NVL (gjl.accounted_cr, 0))=(select (NVL (accounted_dr, 0) - NVL (accounted_cr, 0)) from gl_je_lines
where je_header_id=gjh.je_header_id and code_combination_id=cc.code_combination_id and period_name=gjh.period_name and
last_update_date=gjh.last_update_date and rownum=1)
and (NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0))
+ (NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0))=(select max((NVL (begin_balance_dr, 0)
- NVL (begin_balance_cr, 0))
+ (NVL (period_net_dr_beq, 0)
- NVL (period_net_cr_beq, 0))) from gl_balances where code_combination_id=cc.code_combination_id
and period_name=gb.period_name)
and gjl.description=(select description from gl_je_lines where code_combination_id=cc.code_combination_id and
je_header_id=gjh.je_header_id and period_name=gb.period_name and rownum=1)
AND cc.seg1 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 1, 3),
cc.seg1
AND NVL (SUBSTR (l.concatenated_segments_high, 1, 3),
cc.seg1
AND cc.seg2 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 5, 4),
cc.seg2
AND NVL (SUBSTR (l.concatenated_segments_high, 5, 4),
cc.seg2
AND cc.seg3 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 10, 4),
cc.segt3
AND NVL (SUBSTR (l.concatenated_segments_high, 10, 4),
cc.seg3
AND cc.seg4 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 15, 3),
cc.seg4
AND NVL (SUBSTR (l.concatenated_segments_high, 15, 3),
cc.seg4
AND cc.seg5 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 19, 6),
cc.seg5
AND NVL (SUBSTR (l.concatenated_segments_high, 19, 6),
cc.seg5
AND cc.seg6 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 26, 4),
cc.segment6
AND NVL (SUBSTR (l.concatenated_segments_high, 26, 4),
cc.seg6
AND cc.seg7 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 31, 6),
cc.seg7
AND NVL (SUBSTR (l.concatenated_segments_high, 31, 6),
cc.seg7
AND cc.seg8 BETWEEN NVL (SUBSTR (l.concatenated_segments_low, 38, 6),
cc.seg8
AND NVL (SUBSTR (l.concatenated_segments_high, 38, 6),
cc.seg8)Thanks for help
aspDear all,
the folliwing is explain plan for above query...
<ExplainPlan>
- <PlanElement object_ID="0" id="0" operation="SELECT STATEMENT" optimizer="ALL_ROWS" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
- <PlanElements>
- <PlanElement object_ID="0" id="1" operation="HASH" option="UNIQUE" cost="1,417" cardinality="1" bytes="477" cpu_cost="263,995,086" io_cost="1,385" time="18">
- <PlanElements>
- <PlanElement object_ID="0" id="2" operation="FILTER" filter_predicates="("GJH"."LAST_UPDATE_DATE","GJL"."LAST_UPDATE_DATE")= (SELECT MAX("A"."LAST_UPDATE_DATE"),MAX("B"."LAST_UPDATE_DATE") FROM "GL"."GL_JE_LINES" "B","GL"."GL_JE_HEADERS" "A" WHERE ROWNUM=1 AND "A"."JE_HEADER_ID"="B"."JE_HEADER_ID" AND "A"."STATUS"='P' AND "B"."CODE_COMBINATION_ID"=:B1) AND NVL("GJL"."ACCOUNTED_DR",0)-NVL("GJL"."ACCOUNTED_CR",0)= (SELECT NVL("ACCOUNTED_DR",0)-NVL("ACCOUNTED_CR",0) FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B2 AND "CODE_COMBINATION_ID"=:B3 AND "JE_HEADER_ID"=:B4 AND "LAST_UPDATE_DATE"=:B5) AND NVL("GB"."BEGIN_BALANCE_DR",0)-NVL("GB"."BEGIN_BALANCE_CR",0)+(NVL("GB"."PERIOD_NET_DR_BEQ",0)-NVL("GB"."PERIOD_NET_CR_BEQ",0))= (SELECT MAX(NVL("BEGIN_BALANCE_DR",0)-NVL("BEGIN_BALANCE_CR",0)+(NVL("PERIOD_NET_DR_BEQ",0)-NVL("PERIOD_NET_CR_BEQ",0))) FROM "GL"."GL_BALANCES" "GL_BALANCES" WHERE "PERIOD_NAME"=:B6 AND "CODE_COMBINATION_ID"=:B7)">
- <PlanElements>
- <PlanElement object_ID="0" id="3" operation="NESTED LOOPS" cost="1,262" cardinality="1" bytes="477" cpu_cost="254,376,045" io_cost="1,231" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="4" operation="NESTED LOOPS" cost="1,261" cardinality="1" bytes="464" cpu_cost="254,366,853" io_cost="1,230" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="5" operation="NESTED LOOPS" cost="1,260" cardinality="1" bytes="433" cpu_cost="254,357,622" io_cost="1,229" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="6" operation="NESTED LOOPS" cost="1,259" cardinality="1" bytes="402" cpu_cost="254,348,331" io_cost="1,228" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="7" operation="NESTED LOOPS" cost="1,258" cardinality="1" bytes="350" cpu_cost="254,337,522" io_cost="1,227" time="16">
- <PlanElements>
- <PlanElement object_ID="0" id="8" operation="NESTED LOOPS" cost="1,239" cardinality="1" bytes="273" cpu_cost="254,166,811" io_cost="1,208" time="15">
- <PlanElements>
- <PlanElement object_ID="0" id="9" operation="HASH JOIN" cost="1,184" cardinality="1" bytes="248" cpu_cost="253,727,112" io_cost="1,153" access_predicates=""B"."ID_FLEX_NUM"="CC"."CHART_OF_ACCOUNTS_ID"" filter_predicates=""CC"."SEGMENT1">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT1"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",1,3),"CC"."SEGMENT1") AND "CC"."SEGMENT2">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT2"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",5,4),"CC"."SEGMENT2") AND "CC"."SEGMENT3">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT3"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",10,4),"CC"."SEGMENT3") AND "CC"."SEGMENT4">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT4"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",15,3),"CC"."SEGMENT4") AND "CC"."SEGMENT5">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT5"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",19,6),"CC"."SEGMENT5") AND "CC"."SEGMENT6">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT6"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",26,4),"CC"."SEGMENT6") AND "CC"."SEGMENT7">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT7"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",31,6),"CC"."SEGMENT7") AND "CC"."SEGMENT8">=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_LOW",38,6),"CC"."SEGMENT8") AND "CC"."SEGMENT8"<=NVL(SUBSTR("L"."CONCATENATED_SEGMENTS_HIGH",38,6),"CC"."SEGMENT8")" time="15">
- <PlanElements>
- <PlanElement object_ID="1" id="10" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULE_LINES" object_type="TABLE" object_instance="3" cost="3" cardinality="1" bytes="119" cpu_cost="49,909" io_cost="3" filter_predicates=""L"."INCLUDE_EXCLUDE_INDICATOR"='E'" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="11" operation="NESTED LOOPS" cost="6" cardinality="1" bytes="189" cpu_cost="75,588" io_cost="6" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="12" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="70" cpu_cost="25,679" io_cost="3" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="13" operation="NESTED LOOPS" cost="3" cardinality="1" bytes="39" cpu_cost="23,779" io_cost="3" time="1">
- <PlanElements>
- <PlanElement object_ID="2" id="14" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS" object_type="TABLE" object_instance="10" cost="1" cardinality="1" bytes="8" cpu_cost="8,541" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="3" id="15" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_LEDGERS_U2" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,050" io_cost="0" access_predicates=""GL"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID)" time="1" />
</PlanElements>
</PlanElement>
- <PlanElement object_ID="4" id="16" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES" object_type="TABLE" object_instance="19" cost="2" cardinality="1" bytes="31" cpu_cost="15,238" io_cost="2" filter_predicates=""B"."ENABLED_FLAG"='Y' AND NVL("B"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="1">
- <PlanElements>
<PlanElement object_ID="5" id="17" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VALIDATION_RULES_U1" object_type="INDEX (UNIQUE)" search_columns="3" cost="1" cardinality="1" cpu_cost="7,321" io_cost="1" access_predicates=""B"."APPLICATION_ID"=101 AND "B"."ID_FLEX_CODE"='GL#' AND "B"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID)" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
<PlanElement object_ID="6" id="18" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VDATION_RULES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="5" cost="0" cardinality="1" bytes="31" cpu_cost="1,900" io_cost="0" access_predicates=""T"."APPLICATION_ID"=101 AND "T"."ID_FLEX_CODE"='GL#' AND "T"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "B"."FLEX_VALIDATION_RULE_NAME"="T"."FLEX_VALIDATION_RULE_NAME" AND "T"."LANGUAGE"=USERENV('LANG')" time="1" />
</PlanElements>
</PlanElement>
<PlanElement object_ID="7" id="19" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_FLEX_VAL_RULE_LINES_N1" object_type="INDEX" search_columns="4" cost="1" cardinality="41" cpu_cost="16,371" io_cost="1" access_predicates=""L"."APPLICATION_ID"=101 AND "L"."ID_FLEX_CODE"='GL#' AND "L"."ID_FLEX_NUM"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND "L"."FLEX_VALIDATION_RULE_NAME"="B"."FLEX_VALIDATION_RULE_NAME"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
<PlanElement object_ID="8" id="20" operation="TABLE ACCESS" option="FULL" optimizer="ANALYZED" object_owner="GL" object_name="GL_CODE_COMBINATIONS" object_type="TABLE" object_instance="1" cost="1,177" cardinality="1,088" bytes="64,192" cpu_cost="249,419,570" io_cost="1,147" filter_predicates=""CC"."ENABLED_FLAG"='Y' AND "CC"."CHART_OF_ACCOUNTS_ID"=TO_NUMBER(:P_CHART_OF_ACCOUNTS_ID) AND NVL("CC"."END_DATE_ACTIVE",SYSDATE@!+1)>SYSDATE@!" time="15" />
</PlanElements>
</PlanElement>
- <PlanElement object_ID="9" id="21" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="6" cost="55" cardinality="52" bytes="1,300" cpu_cost="439,699" io_cost="55" time="1">
- <PlanElements>
<PlanElement object_ID="10" id="22" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="52" cpu_cost="25,693" io_cost="2" access_predicates=""GB"."CODE_COMBINATION_ID"="CC"."CODE_COMBINATION_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="11" id="23" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="5" cost="19" cardinality="40" bytes="3,080" cpu_cost="170,710" io_cost="19" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="24" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="2" cardinality="49" cpu_cost="24,693" io_cost="2" access_predicates=""GJL"."CODE_COMBINATION_ID"="GB"."CODE_COMBINATION_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="13" id="25" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="4" cost="1" cardinality="1" bytes="52" cpu_cost="10,809" io_cost="1" filter_predicates=""GJH"."STATUS"='P' AND "GJH"."LEDGER_ID"=TO_NUMBER(:P_LEDGER_ID) AND "GJH"."PERIOD_NAME"="GB"."PERIOD_NAME"" time="1">
- <PlanElements>
- <PlanElement object_ID="14" id="26" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,950" io_cost="0" access_predicates=""GJH"."JE_HEADER_ID"="GJL"."JE_HEADER_ID"" filter_predicates=""GJL"."DESCRIPTION"= (SELECT "DESCRIPTION" FROM "GL"."GL_JE_LINES" "GL_JE_LINES" WHERE ROWNUM=1 AND "PERIOD_NAME"=:B1 AND "CODE_COMBINATION_ID"=:B2 AND "JE_HEADER_ID"=:B3)" time="1">
- <PlanElements>
- <PlanElement object_ID="0" id="27" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="11" id="28" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="15" cost="5" cardinality="1" bytes="62" cpu_cost="39,168" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="29" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="15" id="30" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL" object_type="TABLE" object_instance="16" cost="1" cardinality="2" bytes="62" cpu_cost="9,291" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="16" id="31" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_SOURCES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_SOURCE_NAME"="GJH"."JE_SOURCE" AND "LANGUAGE"=USERENV('LANG')" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="17" id="32" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL" object_type="TABLE" object_instance="17" cost="1" cardinality="2" bytes="62" cpu_cost="9,231" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="18" id="33" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_CATEGORIES_TL_U1" object_type="INDEX (UNIQUE)" search_columns="2" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""JE_CATEGORY_NAME"="GJH"."JE_CATEGORY" AND "LANGUAGE"=USERENV('LANG')" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="19" id="34" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER" object_type="TABLE" object_instance="7" cost="1" cardinality="1" bytes="13" cpu_cost="9,191" io_cost="1" time="1">
- <PlanElements>
<PlanElement object_ID="20" id="35" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="APPLSYS" object_name="FND_USER_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""GJH"."LAST_UPDATED_BY"="FU"."USER_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="0" id="36" operation="SORT" option="AGGREGATE" cardinality="1" bytes="33">
- <PlanElements>
- <PlanElement object_ID="0" id="37" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="0" id="38" operation="NESTED LOOPS" cost="69" cardinality="49" bytes="1,617" cpu_cost="624,699" io_cost="69" time="1">
- <PlanElements>
- <PlanElement object_ID="11" id="39" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="12" cost="20" cardinality="49" bytes="882" cpu_cost="164,029" io_cost="20" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="40" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="1" cost="3" cardinality="49" cpu_cost="30,964" io_cost="3" access_predicates=""B"."CODE_COMBINATION_ID"=:B1" time="1" />
</PlanElements>
</PlanElement>
- <PlanElement object_ID="13" id="41" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS" object_type="TABLE" object_instance="11" cost="1" cardinality="1" bytes="15" cpu_cost="9,401" io_cost="1" filter_predicates=""A"."STATUS"='P'" time="1">
- <PlanElements>
<PlanElement object_ID="14" id="42" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_HEADERS_U1" object_type="INDEX (UNIQUE)" search_columns="1" cost="0" cardinality="1" cpu_cost="1,900" io_cost="0" access_predicates=""A"."JE_HEADER_ID"="B"."JE_HEADER_ID"" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="0" id="43" operation="COUNT" option="STOPKEY" filter_predicates="ROWNUM=1">
- <PlanElements>
- <PlanElement object_ID="11" id="44" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES" object_type="TABLE" object_instance="13" cost="5" cardinality="1" bytes="33" cpu_cost="39,068" io_cost="5" filter_predicates=""JE_HEADER_ID"=:B1 AND "LAST_UPDATE_DATE"=:B2" time="1">
- <PlanElements>
<PlanElement object_ID="12" id="45" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_JE_LINES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="4" cpu_cost="22,364" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
- <PlanElement object_ID="0" id="46" operation="SORT" option="AGGREGATE" cardinality="1" bytes="25">
- <PlanElements>
- <PlanElement object_ID="9" id="47" operation="TABLE ACCESS" option="BY INDEX ROWID" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES" object_type="TABLE" object_instance="14" cost="6" cardinality="1" bytes="25" cpu_cost="45,399" io_cost="6" time="1">
- <PlanElements>
<PlanElement object_ID="10" id="48" operation="INDEX" option="RANGE SCAN" optimizer="ANALYZED" object_owner="GL" object_name="GL_BALANCES_N1" object_type="INDEX" search_columns="2" cost="3" cardinality="2" cpu_cost="21,964" io_cost="3" access_predicates=""CODE_COMBINATION_ID"=:B1 AND "PERIOD_NAME"=:B2" time="1" />
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</PlanElements>
</PlanElement>
</ExplainPlan>Sorry this xml generated...
Regards
asp -
Please help me getting this query in MDX
Select CASE WHEN DSL.Latest_Label IS NULL THEN DS.[Label] ELSE DSL.Latest_Label END AS Label From Dim_Label AS DS LEFT OUTER JOIN
(Select Idx,GRP_Idx,Max(Latest_Label) Latest_Label,MAX(Date_ID) Date_ID from [Dim_Label_Change] DSL te_Day = DSL.Date_Effective Where (Date_Id <= 333 ) Group by idx,GRP_Idx)
DSL ON DS.Idx = DSL.Idx
Thanks in Advance for the helpMy Cube has Dimensions, Fact tables and Measures , and Dimension table consists of Main and History table(Type 2 Slowly Changing Dimension).
I would like to display the History(Latest_Label) Name based on the date selected on SSRS Report.
Hi SKPSR,
According to your description, you need to get the latest history name based on a date that selected by use in SSRS report, right?
In SSAS, we can use the LastNonEmpty function or Tail function to get the last member from a set. We cannot give you the detail MDX query based on the limited information, you can refer to the links below to see the details.
http://msdn.microsoft.com/en-us/library/ms146056.aspx
http://thinknook.com/ssas-lastnonempty-aggregation-function-2012-08-18/
If the issue persists, please provide us more information about your cube structure, so that we can make further analysis.
Regards,
Charlie Liao
TechNet Community Support -
Please help me optimize this query
Hi,
Can you’ll please recommend me if there is any way to optimize the SQL statement below.
I have 3 tables:
item_master: contains master list of items
item_rentout: items currently out on rent
item_missing: items having special status like missing, withdrawn and so on.
I want to find items that are currently available.
Which is items in table item_master –(minus) items in table item_rentout –(minus) items in table in item_missing.
This is how my sql statement is:
select item_master.item_id from item_master where item_master.item_id not in
((select item_id from item_rentout) union (select item_id from item_missing where status in (‘missing’,withdrawn’)))Regards,
RajaIn addition to what Pointless posted (which is very valuable information!) you could always try and write a logical equivalent SQL statement. It may generate a more favorable plan.
I have written the following that I think may work but they are untested:
SELECT ITEM_MASTER.ITEM_ID FROM ITEM_MASTER
MINUS
SELECT ITEM_ID FROM ITEM_RENTOUT
MINUS
SELECT ITEM_ID FROM ITEM_MISSING WHERE STATUS IN ('missing','withdrawn')
SELECT item_master.item_id
FROM ITEM_MASTER IM
WHERE NOT EXISTS
SELECT NULL
FROM ITEM_RENTOUT IR
WHERE IR.ITEM_ID = IM.ITEM_ID
AND NOT EXISTS
SELECT NULL
FROM ITEM_MISSING IIM
WHERE IIM.ITEM_ID = IM.ITEM_ID
) -
Please, help me with this query
When running the SQL query below, It retrieves some lines that have the same ID_VAGA (ex. 386) but different ID_DETALHE_STATUS. in this case I want to retrieve only the line with the higher ID_DETALHE_STATUS that would be 1047. How can I do this in this SQL query ??
This is the query:
Select VAGAS.ID_VAGA, TITULOS_VAGAS.TIT_VAGA, VAGAS.QTDE_VAGAS, DETALHE_STATUS.ID_DETALHE_STATUS, DETALHE_STATUS.DETALHE_STATUS
From VAGAS Inner Join TITULOS_VAGAS On TITULOS_VAGAS.ID_TIT_VAGA = VAGAS.TIT_VAGA Inner Join DETALHE_STATUS On VAGAS.ID_VAGA = DETALHE_STATUS.ID_VAGA
Order By VAGAS.ID_VAGA
And these are the results it's returning to me: But I want it to return only the higher ID_DETALHE_STATUS, that is 1047:
ID_VAGA QTDE_VAGAS TIPO_VAGA VALOR_SALARIO TAXA_SELECAO TAXA_CANCEL UNIDADE ATIVO ID_DETALHE_STATUS DETALHE_STATUS
386 1 Estagiario 500,00 70 0 1 1 1047 A5
386 1 Estagiario 500,00 70 0 1 1 937 A2
Thanks for reading.
Roger.Hi,
You can try this too:
SELECT * FROM (
Select VAGAS.ID_VAGA, TITULOS_VAGAS.TIT_VAGA, VAGAS.QTDE_VAGAS, DETALHE_STATUS.ID_DETALHE_STATUS, DETALHE_STATUS.DETALHE_STATUS
From VAGAS
Inner Join
TITULOS_VAGAS On TITULOS_VAGAS.ID_TIT_VAGA = VAGAS.TIT_VAGA Inner Join DETALHE_STATUS On VAGAS.ID_VAGA = DETALHE_STATUS.ID_VAGA
Order By VAGAS.ID_VAGA)
WHERE DETALHE_STATUS.ID_DETALHE_STATUS>1047;Regards,
Lakshmi. -
Please help me at this query (sum function)
hi every one
if I have column and the datatype is varchar2 and in this column has data like
number,number mix varchar2,and character
i want use sum function to summarize then number only but i want to ignore any number with char
this example
12
23
1q2
wer
34rt
the result=35
thanks in advanceNot sure what you need here.
However here is a sample of what's possible:
SQL> WITH test_data AS
2 (
3 SELECT '12' AS DAT FROM DUAL UNION ALL
4 SELECT '23' AS DAT FROM DUAL UNION ALL
5 SELECT '1q2' AS DAT FROM DUAL UNION ALL
6 SELECT '34rt' AS DAT FROM DUAL
7 )
8 SELECT SUM(DAT)
9 FROM test_data
10 WHERE NOT REGEXP_LIKE(DAT,'[^[:digit:]]')
11 /
SUM(DAT)
35 -
Please help me with this SQL query
I am practicing SQL queries and have come across one involving fetching data from 3 different tables.
The three tables are as below
<pre>
Country
location_id country
loc1 Spain
loc2 England
loc3 Spain
loc4 USA
loc5 Italy
loc6 USA
loc7 USA
</pre>
<pre>
User
user_id location_id
u1 loc1
u2 loc1
u3 loc2
u4 loc2
u5 loc1
u6 loc3
</pre>
<pre>
Post
post_id user_id
p1 u1
p2 u1
p3 u2
p4 u3
p5 u1
p6 u2
</pre>
I am trying to write an SQL query - for each country of users, display the average number of posts
I understand the logic behind this that we first need to group together all the locations and then the users belonging to one country and then find the average of their posts.
But, i'm having a difficulty in putting this in SQL form. Could someone please help me with this query.
Thanks.select
country.country,
count(*) Totalpostspercountry,
count(distinct post.user_id) Totaldistincuserspercountry,
count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
from
country, muser, post
where country.location_id = muser.location_id
and muser.user_id = post.user_id
group by country.country
The output is like this for your sample data - hope this is what you were looking for :)
COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
England,1,1,1,
Spain,5,2,2.5, -
i am using
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production
Please help to simplify this query. I also want to make this as a procedure.
select
RH.resort as RH_RESORT,
RH.rate_code as RH_RATE_CODE,
RD.rate_detail_id as RD_RATE_DETAIL_ID,
RD.rate1 as RD_RATE1,
RD.rate2 as RD_RATE2,
RD.rate3 as RD_RATE3,
RD.rate4 as RD_RATE4,
RD.rate5 as RD_RATE5,
RRC.room_category as RM_CAT,
initcap(RRMCAT.long_description) as RM_DESC,
RH.DAY1,
RH.DAY2,
RH.DAY3,
RH.DAY4,
RH.DAY5,
RH.DAY6,
RH.DAY7,
RH.WEEKEND1,
RH.WEEKEND2,
RH.WEEKEND3,
RH.WEEKEND4,
RH.WEEKEND5,
RH.WEEKEND6,
RH.WEEKEND7
from pms_rate_header RH,
pms_rate_detail RD,
pms_rate_room_cat RRC,
resort_room_category RRMCAT
where RH.inactive_date is NULL
and RH.RESORT='FABGOI'
and RH.RATE_CODE ='CRRRACK'
and ('15-Jan-2007' >= RH.BEGIN_DATE
and '16-Jan-2007' <= RH.END_DATE)
and RD.rate_header_id=RH.rate_header_id
and RD.inactive_date is NULL
and ('15-Jan-2007' >= RD.BEGIN_DATE
and '16-Jan-2007' <= RD.END_DATE)
and RRC.rate_detail_id=RD.rate_detail_id
and RRC.resort=RH.resort
and RRMCAT.resort=RH.resort
and RRMCAT.room_category=RRC.room_category
and RRC.inactive_date is NULL
and RRMCAT.inactive_date IS NULL
regards
lee1212where RH.inactive_date is NULL
and RH.RESORT='FABGOI'
and RH.RATE_CODE ='CRRRACK'
and ('15-Jan-2007' >= RH.BEGIN_DATE
and '16-Jan-2007' <= RH.END_DATE)
and RD.rate_header_id=RH.rate_header_id
and RD.inactive_date is NULL
and ('15-Jan-2007' >= RD.BEGIN_DATE
and '16-Jan-2007' <= RD.END_DATE)
and RRC.rate_detail_id=RD.rate_detail_id
and RRC.resort=RH.resort
and RRMCAT.resort=RH.resort
and RRMCAT.room_category=RRC.room_category
and RRC.inactive_date is NULL
and RRMCAT.inactive_date IS NULL
in the above part i am finding repeated joins and lot of 'and's
i want to know any line can be eliminated or the the query can be rewritten in a simple way without affecting it's accuracy?
regards
Lee1212
Maybe you are looking for
-
I am a system administrator and need a way to set a global preference to not open the Whats New and first run pages. I found the browser.startup.homepage_override.mstone preference in the user profile but want to be able to set this globally.
-
External drive stuck in limbo - no errors, data intact, still won't mount?
Background story: -I had an external enclosure with two drives (one Hitachi, one WD, both SATA) running seperately inside as storage. Things were good. One day something went wrong, because I turned it on and weird clicking could be heard and the dri
-
Storing Sapscript data in Tab delimited format
Hi All, Can anyone please advise me how can I store my Sapcript data in Application server in a Tab delimited format? Is there any FM for that or should I use Open dataset? Please send sample code, if anyone have. Moreover, please let me know where t
-
Preview Encrypt PDF - Really Secure?
When you use the Preview app in OS X to encrypt a PDF is it really secure? I haven't been able to find anything about the level of encryption used by Preview in OS X. What type of encryption does Preview use (40-bit, 128-bit)? A quick search of the w
-
Pixelated Footage AFTER rendering
I shot my footage on the Panasonic HVX and when I imported it to my project, everything was fine. BUT, whenever I make an adjustment to the footage that requires rendering, the footage comes out (after the render) VERY pixelated. I set my sequence se