Help Needed in Query Creation
Hi,
I have two tables,
A) User Groups
PKID Group User
pk797 G1 U1
pk2 G1 U2
pk42 G1 U3
pk422 G2 U1
pk423 G2 U6
pk424 G2 U7
pk43 G2 U4
pk435 G3 U5
pk435 G3 U6
pk435 G3 U7
B) EventGroup Table
PKID Event Group User
pk1 E1 G1
pk2 E1 G1 U1
pk3 E2 G2
pk4 E2 G2 U1
pk5 E2 G2 U6
pk6 E4 G1
pk7 E5 G3
I need a view which combines this two tables and give me columns based on Event
Expected Output
EVENT GROUP USER
E1 G1 U2
E1 G1 U3
E2 G2 U7
E2 G2 U4
E4 G1 U1
E4 G1 U2
E4 G1 U3
E5 G3 U5
E5 G3 U6
E5 G3 U7
Explaination: If the 'USER'column in 'EventGroup' Table is NULL then, We need all the users from that group But If a record is available with user column as in 'pk2' in EventGroup Table
then we have to exclude the user from the list.
user8635057 wrote:
Explaination: If the 'USER'column in 'EventGroup' Table is NULL then, We need all the users from that group But If a record is available with user column as in 'pk2' in EventGroup Table
then we have to exclude the user from the list.
with user_groups as (
select 'pk797' pkid,'G1' grp,'U1' usr from dual union all
select 'pk2','G1','U2' from dual union all
select 'pk42','G1','U3' from dual union all
select 'pk422','G2','U1' from dual union all
select 'pk423','G2','U6' from dual union all
select 'pk424','G2','U7' from dual union all
select 'pk43','G2','U4' from dual union all
select 'pk435','G3','U5' from dual union all
select 'pk435','G3','U6' from dual union all
select 'pk435','G3','U7' from dual
event_group as (
select 'pk1' pkid,'E1' event,'G1' grp,null usr from dual union all
select 'pk2','E1','G1','U1' from dual union all
select 'pk3','E2','G2',null from dual union all
select 'pk4','E2','G2','U1' from dual union all
select 'pk5','E2','G2','U6' from dual union all
select 'pk6','E4','G1',null from dual union all
select 'pk7','E5','G3',null from dual
select a.event,
a.grp,
b.usr
from event_group a,
user_groups b
where a.usr is null
and b.grp = a.grp
minus
select event,
grp,
usr
from event_group
where usr is not null
order by event,
grp,
usr
EV GR US
E1 G1 U2
E1 G1 U3
E2 G2 U4
E2 G2 U7
E4 G1 U1
E4 G1 U2
E4 G1 U3
E5 G3 U5
E5 G3 U6
E5 G3 U7
10 rows selected.
SQL> SY.
Similar Messages
-
I have one table Prd_mst, I need a query or function where whenever i pass the child_id into query or function i get the Parent_id of that
example Data is below :-
P_ID,P_NAME,C_ID
null,Computer,1
1,KeyBoard,2
1,Mouse,3
1,Mother Board,4
3,Scroll Mouse,5
3,Optical Scroll Mouse,6
3,Fibre Scroll Mouse,7
2,Multimedia Key Board,8
2,Cordless Key Board,10
2,Normal Key Board,9
4,586 Mother Board,13
4,386 Mother Board,11
4,486 Mother Board,12
4,P1 Mother Board,14
4,P2 Mother Board,15
4,P3 Mother Board,16
4,P4 Mother Board,17
14,533 Mhtz P1 CPU,19
14,433 Mhtz P1 CPU,18
19,533 Mhtz P1 CPU With 100Mhtz BUS,20
19,533 Mhtz P1 CPU With 133Mhtz BUS,21
18,433 Mhtz P1 CPU With 100Mhtz BUS,22
So when ever i put the child id as 22 i should get the 14
So when ever i put the child id as 21 i should get the 14
So when ever i put the child id as 9 i should get the 1
So when ever i put the child id as 15 i should get the 1
So when ever i put the child id as 5 i should get the 1
So when ever i put the child id as 3 i should get the null
So when ever i put the child id as 14 i should get the 1.
Please help me......
There is one complex requirement in matrix format.
Need P_ID , P_NAME , Count( child records)
P_(nth), P_NAME(nth), Count(child record) nth times.
Child is again the parent of some child.
Report is needed for audit purpose.
Message was edited by: Sandeep Sharma
Sandeep SharmaSQL> CREATE TABLE SANDEEP(P_ID NUMBER,P_NAME VARCHAR2(100),C_ID NUMBER);
Table created.
SQL> INSERT INTO SANDEEP VALUES(null,'Computer',1);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(1,'KeyBoard',2);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(1,'Mouse',3);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(1,'Mother Board',4);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(3,'Scroll Mouse',5);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(3,'Optical Scroll Mouse',6);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(3,'Fibre Scroll Mouse',7);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(2,'Multimedia Key Board',8);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(2,'Cordless Key Board',10);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(2,'Normal Key Board',9);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(4,'586 Mother Board',13);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(4,'386 Mother Board',11);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(4,'486 Mother Board',12);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(4,'P1 Mother Board',14);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(4,'P2 Mother Board',15);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(4,'P3 Mother Board',16);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(4,'P4 Mother Board',17);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(14,'533 Mhtz P1 CPU',19);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(14,'433 Mhtz P1 CPU',18);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(19,'533 Mhtz P1 CPU With 100Mhtz BUS',20);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(19,'533 Mhtz P1 CPU With 133Mhtz BUS',21);
1 row created.
SQL> INSERT INTO SANDEEP VALUES(18,'433 Mhtz P1 CPU With 100Mhtz BUS',22);
1 row created.
SQL> COMMIT;
Commit complete.
SQL> set null null
SQL> SELECT P_ID
2 FROM SANDEEP
3 WHERE LEVEL = 2
4 START WITH C_ID = &1
5 CONNECT BY C_ID = PRIOR P_ID;
Enter value for 1: 22
old 4: START WITH C_ID = &1
new 4: START WITH C_ID = 22
P_ID
14
SQL> /
Enter value for 1: 21
old 4: START WITH C_ID = &1
new 4: START WITH C_ID = 21
P_ID
14
SQL> /
Enter value for 1: 9
old 4: START WITH C_ID = &1
new 4: START WITH C_ID = 9
P_ID
1
SQL> /
Enter value for 1: 15
old 4: START WITH C_ID = &1
new 4: START WITH C_ID = 15
P_ID
1
SQL> /
Enter value for 1: 5
old 4: START WITH C_ID = &1
new 4: START WITH C_ID = 5
P_ID
1
SQL> /
Enter value for 1: 3
old 4: START WITH C_ID = &1
new 4: START WITH C_ID = 3
P_ID
null
SQL> /
Enter value for 1: 14
old 4: START WITH C_ID = &1
new 4: START WITH C_ID = 14
P_ID
1
SQL> SY. -
Hi,
I've select query to retrive the data in the following order
Sequnce ID Model Barcode
1 Dell 123
2 Dell 124
3 Dell 125
4 HP 126
5 hp 127
6 hp 128
7 apple 129
8 apple 130
I want the following to be selected round robin for Dell and Hp laptop alone as mentioned below.
Sequnce ID Model Barcode
1 Dell 123
4 HP 126
2 Dell 124
5 hp 127
3 Dell 125
6 hp 128
7 apple 129
8 apple 130
Can you help me to acheive this?
Thanks!Hi,
user601042 wrote:
Hi,
I've select query to retrive the data in the following order
Sequnce ID Model Barcode
1 Dell 123
2 Dell 124
3 Dell 125
4 HP 126
5 hp 127
6 hp 128
7 apple 129
8 apple 130If that's what you want, then it looks like
ORDER BY barcodeis all you need.
If you want the results sorted as below, Then you can use the analytic ROW_NUMBER function:
ORDER BY CASE
WHEN UPPER (model) IN ('DELL', 'HP')
THEN ROW_NUMBER () OVER ( PARTITION BY UPPER (model)
ORDER BY barcode
END
, barcode
I want the following to be selected round robin for Dell and Hp laptop alone as mentioned below.
Sequnce ID Model Barcode
1 Dell 123
4 HP 126
2 Dell 124
5 hp 127
3 Dell 125
6 hp 128
7 apple 129
8 apple 130Either way, I assume that sequnce id is not actually in your table.
Edited by: Frank Kulash on Mar 14, 2013 12:38 PM
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Hello Query experts,
I have the following data in my DSO.
Char1 date Kf1 KF2
a 01.01.2011 10 20
a 03.01.2011 50 70
a 05.01.2011 5 10
b 02.01.2011 20 25
b 05.01.2011 10 15
b 06.01.2011 5 15
Now, I need to design a query to produce the following result:
Char1 date Kf1 KF2 KF3(KF2-KF1) KF4
a 01.01.2011 10 20 10 10
a 03.01.2011 50 70 20 30 [KF3+Prev(KF4)]
a 05.01.2011 5 10 5 35
b 02.01.2011 20 25 5 5
b 05.01.2011 10 15 5 10
b 06.01.2011 5 15 10 20
Can anybody help me achieve this through a BI Query?
Thanks and regards,
JashuaHI,
I think kf3 can easily be created at query level itself without writing complex logic..As far as i understand your requirement kf3 is a differnce of kf2 and kf1.
so jst make local formula and in that put kf2-kf1.it will give you the desired output for kf3.
Kf4 i need to think,i will update you soon -
SQL HELP NEEDED IN QUERY FOR COUNT
I Have this Query
SUM (CASE WHEN b.VET_OTHR_ELIG_CDE IN ('02', '03', '04') THEN 1 END) AS VET_YES,
SUM (CASE WHEN b.VET_OTHR_ELIG_CDE = '01' THEN 1 END) VET_NO, COUNT (E.ACTV_CDE) AS CNT_ACTV_CDE
Now i need to Add two more columns from the same Query Showing the count of VET_YES and VET_NO i.e count of TOTAL Veterans And TOTAL Non Veterans
those two columns i will be using as summary columns in my report.The bolded columns are those which i need to show the total column .anyone please help in this issue ..
ACTV_DESC ACTV_CDE VET_YES VET_NO CNT_ACTV_CDE
INACT DUE 13993 2 1 3
NOW I NEED TO MAKE IT LIKE THIS
ACTV_DESC ACTV_CDE VET_YES VET_NO CNT_VET CNT_NONVET CNT_ACTV_CDE (This is the total count)
INACT DUE 13993 2 1 2 1 3
Thanks in Advance,
Dev Kishore.T
Message was edited by:
Dev Kishore
Message was edited by:
Dev KishoreCheck this link.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1612
Regards
Raj -
I have troubles with my XML query. It returns to many results and double results.
My code
select xmlelement("test", XMLAgg(xmlelement("Customer", XmlAttributes(a.CUSTOMER_ID "cid"))),
XMLAgg(xmlelement("Account", xmlagg(xmlelement("Account", b.ACCOUNT_ID) ))),
XMLAgg(xmlelement("ServicePoint", xmlagg(xmlelement("sp", c.SPID) ))) ).extract('*').getstringval() xml
From DM_SERVICE_POINT c, DM_CUSTOMER a, DM_ACCOUNT b where a.CUSTOMER_ID = b.CUSTOMER_ID And a.CUSTOMER_ID=c.CUSTOMER_ID AND a.CUSTOMER_ID='15058'
group by a.CUSTOMER_ID
i have 1 customer id in the table dm_customer, 2 account_id 's that are linked to customer_id with a FK. DM_Servicepoint contains 6 rows that are linked to dm_customer with a FK.
My result is 1 result for customer, thats correct but account shows 12 results, where i expect 2 results
and Service point shows also 12 records where i expect 6 records.
There is no direct link between account and service point but both are linked to customer. Each customer can have 1 or 2 account And each customer can have 1 or many servicepoints.
Can you help me?
Message was edited by:
MarindaNow to see whether we can get this to work with XML....Turns out it's a lot easier than I thought it would be:
SQL> select dbms_xmlgen.getxml('select c.name
2 , cursor(select a.acctno, a.name
3 from my_accounts a
4 where a.cust_id = c.id ) as accounts
5 , cursor(select s.sp_ref
6 from my_service_points s
7 where s.cust_id = c.id ) as srv_points
8 from my_customers c
9 ') from dual
10 /
DBMS_XMLGEN.GETXML('SELECTC.NAME,CURSOR(SELECTA.ACCTNO,A.NAMEFROMMY_ACCOUNTSAWHE
<?xml version="1.0"?>
<ROWSET>
<ROW>
<NAME>APC</NAME>
<ACCOUNTS>
<ACCOUNTS_ROW>
<ACCTNO>900000</ACCTNO>
<NAME>No1 a/c</NAME>
</ACCOUNTS_ROW>
<ACCOUNTS_ROW>
<ACCTNO>900002</ACCTNO>
<NAME>Business</NAME>
</ACCOUNTS_ROW>
</ACCOUNTS>
<SRV_POINTS>
<SRV_POINTS_ROW>
<SP_REF>SP1</SP_REF>
</SRV_POINTS_ROW>
<SRV_POINTS_ROW>
<SP_REF>SP2</SP_REF>
</SRV_POINTS_ROW>
<SRV_POINTS_ROW>
<SP_REF>SP3</SP_REF>
</SRV_POINTS_ROW>
<SRV_POINTS_ROW>
<SP_REF>SP4</SP_REF>
</SRV_POINTS_ROW>
<SRV_POINTS_ROW>
<SP_REF>SP5</SP_REF>
</SRV_POINTS_ROW>
<SRV_POINTS_ROW>
<SP_REF>SP6</SP_REF>
</SRV_POINTS_ROW>
</SRV_POINTS>
</ROW>
<ROW>
<NAME>MARINDA</NAME>
<ACCOUNTS>
<ACCOUNTS_ROW>
<ACCTNO>900004</ACCTNO>
<NAME>Checking</NAME>
</ACCOUNTS_ROW>
</ACCOUNTS>
<SRV_POINTS>
<SRV_POINTS_ROW>
<SP_REF>SP7</SP_REF>
</SRV_POINTS_ROW>
<SRV_POINTS_ROW>
<SP_REF>SP8</SP_REF>
</SRV_POINTS_ROW>
</SRV_POINTS>
</ROW>
</ROWSET>
SQL> Obviously you'll need to do some smartening up of the tag names.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
Hi Friends,
I need to create a Tree with functionality of creating the Nodes dynamically.In the window we need to have 2 buttons Add Node and Remove Node.Can we achieve this requirement.
Please provide me your valuable inputs.
Reagrds,
ravikanthHi Ravi,
For this, you can go thru the following components
DEMODYNAMIC AND WDR_TEST_UI_ELEMENTS in your system.
Hopes this will helps you.
Regard
Manoj Kumar
Edited by: Manoj Kumar on Mar 2, 2009 4:51 PM -
Help needed in query optimization.....
Hi
I have this below query which automatically gets generated in siebel.
Problem is when i execute this query in toad for "Nichole" it took 2 mins to return 30 records but when i execute this same query for "Adam" it returns more records than Nichole and return results in 1-2 secs. i Know executing query in toad is not a proper way but this below query will get executed in same way thru siebel application. Histogram is already created on column "Name" but of no help. Composite Index(CX_AA_EVNT_RADIO_BATCH_TIME) is there on column bot_id & timestp.
Table s_org_ext has only 5 records of "Nichole" and 10 records of "Adam".
Will including Column "Name" in Above composite index can help?
Please anybody can suggest me anything in this? whatelse i can do to tune this query?
Thanks for your help in advance
Chandan Singh
Also, don't know how better i can format this code :-(
SELECT t7.conflict_id, t7.last_upd, t7.created, t7.last_upd_by,
t7.created_by, t7.modification_num, t7.row_id, t7.last_upd,
t7.aa_acount_id, t7.aa_last_step, t7.accessory, t7.account_exists,
t7.account_number, t7.actn_cd, t7.action_counter, t7.activated_by,
t7.address, t7.address_2, t7.address_validation_status,
t4.account_name, t7.aggregated_account_id, t7.aggregated_flag,
t7.asset_id, t7.auto_delivery_type, t7.auto_make, t7.auto_model,
t7.auto_year, t7.automated_approval, t7.activation_frequency,
FROM siebel.s_prod_int t1,
siebel.s_org_ext t2,
siebel.s_asset t3,
siebel.av_account t4,
siebel.s_org_ext t5,
siebel.s_prod_int_x t6,
siebel.av_event t7
WHERE t1.row_id = t6.par_row_id(+)
AND t7.promotion_code = t1.part_num(+)
AND t7.asset_id = t3.row_id(+)
AND t3.owner_accnt_id = t5.par_row_id(+)
AND t7.id = t2.par_row_id --- S_ORG_EXT_U3
AND t7.id1 = t4.row_id(+)
AND (t2.NAME = 'Nichole')
ORDER BY t7.bot_id, t7.timestp
Below is the execution plan for above query.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=399904 Card=5609601 Bytes=4930839279)
1 0 NESTED LOOPS (OUTER) (Cost=399904 Card=5609601 Bytes=4930839279)
2 1 NESTED LOOPS (OUTER) (Cost=343808 Card=5609601 Bytes=4824256860)
3 2 NESTED LOOPS (OUTER) (Cost=231616 Card=5609601 Bytes=4740112845)
4 3 NESTED LOOPS (OUTER) (Cost=175520 Card=5609601 Bytes=4482071199)
5 4 NESTED LOOPS (OUTER) (Cost=119424 Card=5609601 Bytes=4325002371)
6 5 NESTED LOOPS (Cost=63328 Card=5609601 Bytes=4240858356)
7 6 TABLE ACCESS (BY INDEX ROWID) OF 'av_event' (Cost=6729 Card=5659910 Bytes=4126074390)
8 7 INDEX (FULL SCAN) OF 'av_event_timpstp' (NON-UNIQUE) (Cost=24559 Card=5659910)
9 6 TABLE ACCESS (BY INDEX ROWID) OF 'S_ORG_EXT' (Cost=1 Card=1 Bytes=27)
10 9 INDEX (UNIQUE SCAN) OF 'S_ORG_EXT_U3' (UNIQUE)
11 5 TABLE ACCESS (BY INDEX ROWID) OF 'S_PROD_INT' (Cost=1 Card=1 Bytes=15)
12 11 INDEX (RANGE SCAN) OF 'S_PROD_INT_M3' (NON-UNIQUE)
13 4 TABLE ACCESS (BY INDEX ROWID) OF 'av_account' (Cost=1 Card=1 Bytes=28)
14 13 INDEX (UNIQUE SCAN) OF 'av_account_P1' (UNIQUE)
15 3 TABLE ACCESS (BY INDEX ROWID) OF 'S_ASSET' (Cost=1 Card=1 Bytes=46)
16 15 INDEX (UNIQUE SCAN) OF 'S_ASSET_P1' (UNIQUE)
17 2 TABLE ACCESS (BY INDEX ROWID) OF 'S_PROD_INT_X' (Cost=1 Card=1 Bytes=15)
18 17 INDEX (RANGE SCAN) OF 'S_PROD_INT_X_U1' (UNIQUE) (Cost=1 Card=1)
19 1 TABLE ACCESS (BY INDEX ROWID) OF 'S_ORG_EXT' (Cost=1 Card=1 Bytes=19)
20 19 INDEX (UNIQUE SCAN) OF 'S_ORG_EXT_U3' (UNIQUE)
Below is the No. of records in each table.
NUM_ROWS LAST_ANALYZED TABLE_NAME BLOCKS
5,594,027.00 09/08/2006 03:03:02 av_account 92,565.00
6,659,910.00 09/22/2006 16:14:06 av_event 608,292.00
15,384,080.00 09/22/2006 15:28:04 S_ASSET 1,244,124.00
10,249,905.00 04/23/2006 23:51:44 S_ORG_EXT 2,313,814.00
1,081.00 09/22/2006 15:26:12 S_PROD_INT 129.00
602.00 09/08/2006 04:39:42 S_PROD_INT_X 10.00can you plz try this
SELECT /*+ LEADING(t2) */ t7.conflict_id, t7.last_upd, t7.created, t7.last_upd_by,
t7.created_by, t7.modification_num, t7.row_id, t7.last_upd,
t7.aa_acount_id, t7.aa_last_step, t7.accessory, t7.account_exists,
t7.account_number, t7.actn_cd, t7.action_counter, t7.activated_by,
t7.address, t7.address_2, t7.address_validation_status,
t4.account_name, t7.aggregated_account_id, t7.aggregated_flag,
t7.asset_id, t7.auto_delivery_type, t7.auto_make, t7.auto_model,
t7.auto_year, t7.automated_approval, t7.activation_frequency,
FROM siebel.s_prod_int t1,
siebel.s_org_ext t2,
siebel.s_asset t3,
siebel.av_account t4,
siebel.s_org_ext t5,
siebel.s_prod_int_x t6,
siebel.av_event t7
WHERE t1.row_id = t6.par_row_id(+)
AND t7.promotion_code = t1.part_num(+)
AND t7.asset_id = t3.row_id(+)
AND t3.owner_accnt_id = t5.par_row_id(+)
AND t7.id = t2.par_row_id --- S_ORG_EXT_U3
AND t7.id1 = t4.row_id(+)
AND (t2.NAME = 'Nichole')
ORDER BY t7.bot_id, t7.timestp -
Help needed with constraint creation!!
Hi all,
I need to create a constraint on an existing table with respect ot the below requirement.
Let say there is a table with name kamal_temp as follows:
SQL> desc kamal_temp
Name Null? Type
ID NUMBER
STATE NUMBER
VALU VARCHAR2(10)
Now let’s assume there are values in the table as follows:
SQL> select * from kamal_temp;
ID STATE VALU
10 1 one
10 2 one
10 2 two
11 1 one
Now I need to create a constraint on this table to make sure that there should not be another row inserted with ID as ‘10’ and STATE as ‘1’. But there can be multiple rows for ID ‘10’ with STATE ‘2’.
Which means “insert into kamal_temp values (10, 1, ‘three’)” should throw an constraint violation error.
Do help me out with this.
With Best Regards,
R. Kamal Raj GupthaA trigger will not be multi-user aware (what if two different people insert a state value of 1 for a certain id simultaneously?).
A unique function-based index will enforce your business rule:
create unique index kamal_temp_idx
on kamal_temp(decode(state, 1, id, null), decode(state, 1, state, null)); -
Hi All,
I am using the following queries in formula columns of a 6i report. The query count for these queries as seen from the trc file is very high, which is causing performance issues in the report.
Can anyone please help me to tune these queries.
SELECT ROUND (SUM (pld.denom_burdened_cost))
FROM pa_project_asset_lines_v pl,
gl_code_combinations glcc,
pa_asset_line_details_v pld
WHERE pl.project_asset_line_detail_id = pld.project_asset_line_detail_id
AND glcc.code_combination_id = pl.cip_ccid
AND transfer_status_code = 'T'
AND pld.project_id = :b1
AND glcc.segment2 = '131340'
Query Count - 1579401
SELECT SUM (DECODE (ei.system_linkage_function,
'ST', DECODE (pa_security.view_labor_costs (:b1),
'Y', ei.project_burdened_cost,
NULL
'OT', DECODE (pa_security.view_labor_costs (:b1),
'Y', ei.project_burdened_cost,
NULL
ei.project_burdened_cost
) aa
FROM pa_expenditure_items_all ei, pa_tasks t
WHERE ei.project_id = :b1
AND pa_expenditures_utils.get_latest_gl_date (ei.expenditure_item_id)
BETWEEN :b4
AND :b5
AND ei.org_id = fnd_profile.VALUE ('ORG_ID')
AND ei.project_id = t.project_id
AND NVL (t.billable_flag, 'N') = 'N'
Query Count - 1969414
SELECT SUM (DECODE (ei.system_linkage_function,
'ST', DECODE (pa_security.view_labor_costs (:b1),
'Y', ei.project_burdened_cost,
NULL
'OT', DECODE (pa_security.view_labor_costs (:b1),
'Y', ei.project_burdened_cost,
NULL
ei.project_burdened_cost
) aa
FROM pa_cost_distribution_lines_all pcd,
gl_code_combinations glcc,
pa_expenditure_items_all ei,
pa_tasks t
WHERE ei.project_id = :b1
AND pa_expenditures_utils.get_latest_gl_date (ei.expenditure_item_id)
BETWEEN :b4
AND :b5
AND ei.org_id = fnd_profile.VALUE ('ORG_ID')
AND pcd.dr_code_combination_id = glcc.code_combination_id
AND glcc.segment2 != '131340'
AND ei.project_id = pcd.project_id
AND ei.expenditure_item_id = pcd.expenditure_item_id
AND t.project_id = ei.project_id
AND t.billable_flag = 'Y'
Query Count - 1973901
Regards,
ShrutiThis statement
SELECT SUM (DECODE (ei.system_linkage_function,
'ST', DECODE (pa_security.view_labor_costs (:b1),
'Y', ei.project_burdened_cost,
NULL
'OT', DECODE (pa_security.view_labor_costs (:b1),
'Y', ei.project_burdened_cost,
NULL
ei.project_burdened_cost
) aa
FROM pa_expenditure_items_all ei, pa_tasks t
WHERE ei.project_id = :b1
AND pa_expenditures_utils.get_latest_gl_date (ei.expenditure_item_id)
BETWEEN :b4
AND :b5
AND ei.org_id = fnd_profile.VALUE ('ORG_ID')
AND ei.project_id = t.project_id
AND NVL (t.billable_flag, 'N') = 'N'uses at least 3 different functions inside the SQL.
<ul><li>pa_security.view_labor_costs (:b1)</li>
<li>fnd_profile.VALUE ('ORG_ID')</li>
<li>pa_expenditures_utils.get_latest_gl_date (ei.expenditure_item_id)</li>
</ul>
Each function call might result in a context switch from SQL to pl/SQL and back. This is expensive and slow. For each line 4 functions are called. Which means 8 context switches per base line. In your case aproximately 16 million switches.
You can try to avoid this context switch.
The first and second function an be encapsulated in a with query wich should result in a single call. The logic in the second function should be rewritten iinto pure SQL.
This can make a huge difference.
example untested
with singlerowdata as (select pa_security.view_labor_costs (:b1) v_labor_costs, fnd_profile.VALUE ('ORG_ID') profile_org_id from dual)
SELECT SUM (DECODE (ei.system_linkage_function,
'ST', DECODE (s.v_labor_costs,
'Y', ei.project_burdened_cost,
NULL
'OT', DECODE (s.v_labor_costs,
'Y', ei.project_burdened_cost,
NULL
ei.project_burdened_cost
) aa
FROM pa_expenditure_items_all ei, pa_tasks t, singlerowdata s
WHERE ei.project_id = :b1
/* "the latest date can also be found with an analytic function, but there is not enough information to show how to do it here"
This would potentially improve the performance even more. */
AND (select max(datecolumn) from pa_expenditure_items x where x.id = ei.expenditure_item_id) BETWEEN :b4 AND :b5
AND ei.org_id = s.profile_org_id
AND ei.project_id = t.project_id
AND NVL (t.billable_flag, 'N') = 'N' -
Help needed in query for Materialized View
Hi,
I want to create a materialized view which has some precalcultaed values.
I have four dimension tables out of which one is a Time Dimension table with levels as Year->Quarter->Month.
The precalculations are the moving averages and cummulative values of Sales Amt on the dimension values over a period of 4 Months.
The dimension tables are Clients, Products, Channel, Time.
Fact Table is Sales_Fact which will have the sales amount for different members of the dimension.
Since my fact table is very huge, i want to create a materialized view where i could store the required calculated measures, here Moving Average of Sales Amt for each Client, Product, Channel dimensions over a period of 4 Months.
Can anybody help with writing the query for this..Any help in this regard will be appreciated..
Please give me suggestions for this..Check this link.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1612
Regards
Raj -
Hi All,
I have a table structure along with sample data like this
ID PatID Lastname Firstname DOS
1 2 aaa xxx 11/12/20013
2 1 bbb xxx 11/12/20013
3 3 ccc xxx 10/12/20013
4 1 bbb xxx 11/11/20013
5 2 aaa xxx 11/10/20013
6 1 bbb xxx 11/10/20013
7 2 aaa xxx 11/09/20013
8 3 ccc xxx 11/09/20013
My requirement is that if there are more than one record with the PatID for First record the last name should be displayed from 2nd record on words in last name null value should be displayed like this.
ID PatID Lastname Firstname DOS
1 1 aaa xxx 11/12/20013
2 1 xxx 11/12/20013
3 1 xxx 10/12/20013
4 2 bbb xxx 11/11/20013
5 2 xxx 11/10/20013
6 2 xxx 11/10/20013
7 3 ccc xxx 11/09/20013
8 3 xxx 11/09/20013
Please guide me on this.
Waiting for valuable replies.
Thanks and Regards
Sridhar.RThis is quite complex query, but my idea above applies.
;with cte AS (SELECT DISTINCT Rxs.FacID, Rxs.RxNo, Rxs.RxBatch, Patients.PatLName, Patients.PatFName, Rxs.InitReview, Rxs.LabelPrintedOn, Rxs.Packed, Rxs.PlacedInTote, Patients.Street1, Patients.Zip, RxBatches.BatchDescr, ROW_NUMBER() OVER (partition by Patients.PatId ORDER BY Patients.PatFnName) AS Rn
FROM FwReports.dbo.Patients Patients
INNER JOIN FwReports.dbo.Rxs Rxs ON Rxs.PatID = Patients.PatID
INNER JOIN FwReports.dbo.RxBatches RxBatches
ON RxBatches.RxBatch = Rxs.RxBatch AND RxBatches.FacID = Rxs.FacID AND RxBatches.PharmID = Rxs.PharmID
WHERE ((Rxs.RxBatch Like 's%' And Rxs.RxBatch<>'eileen' And Rxs.RxBatch Like 'STAT%') AND (Rxs.ProfileOnly=0) AND (Rxs.TransType<>'B' And Rxs.TransType<>'B') AND (Rxs.DrugLabelName Not Like 'delivery%') OR (Rxs.RxBatch<>'eileen' And Rxs.RxBatch Like 'STAT%') AND (Rxs.TransType<>'B' And Rxs.TransType<>'B') AND (Rxs.DrugLabelName Not Like 'delivery%') AND (Rxs.FacID In ('crh') And Rxs.FacID='CRH') OR (Rxs.FacID='CRH') OR (Rxs.FacID In ('CRH','LSRX')) OR (Rxs.FacID In ('CRH','LSRX'))))
SELECT FacId, RxNo, RxBatch, case when Rn = 1 then PatLName end as PatLName, PatFName, ...
FROM cte
I didn't list every column and I am not sure what column do you need to use in ORDER BY clause, but you should get the idea.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Help needed with query.....
I have a table TableA with two columns
ColA, DateCol
The data is as follows:
Table A
ColA DateCol
A 03-JUL-07
B 15-DEC-07
C 25-MAR-08
D 11-AUG-07
E 31-AUG-07
F 29-FEB-08 I want to generate data something as follows and insert into another table TableB which has columns ValueColA, DateColA:
If the value in ColA has date as 03-JUL-07, then for that value i want to generate all the dates after JUL-07 till JUN-08 something like this
Table B
ValueColA DateColA
A 01-JUL-07
A 01-AUG-07
A 01-SEP-07
A 01-OCT-07
A 01-NOV-07
A 01-DEC-07
A 01-JAN-08
A 01-FEB-08
A 01-MAR-08
A 01-APR-08
A 01-MAY-08
A 01-JUN-08If B has date 15-DEC-07 then values after DEC-07 to JUN-08
Table B
ValueColA DateColA
B 01-DEC-07
B 01-JAN-08
B 01-FEB-08
B 01-MAR-08
B 01-APR-08
B 01-MAY-08
B 01-JUN-08If C has date 25-MAR-08 then values after MAR-08 to JUN-08
Table B
ValueColA DateColA
C 01-MAR-08
C 01-APR-08
C 01-MAY-08
C 01-JUN-08Is it possible to achieve this way using query..IF anybody can help me with this...Please...SQL> with t as
2 (
3 select 'A' id, to_date('03-JUL-07','dd-mon-yy') dt from dual union all
4 select 'B', to_date('15-DEC-07','dd-mon-yy') from dual union all
5 select 'C', to_date('25-MAR-08','dd-mon-yy') from dual
6 ),
7 months as (
8 select add_months(date '2007-07-01', level - 1) as month
9 from dual
10 connect by level <= 12
11 )
12 select t.id, M.month
13 from t, months M
14 where trunc(t.dt, 'month') <= M.month
15 order by id, M.month
16 ;
I MONTH
A 01.07.2007
A 01.08.2007
A 01.09.2007
A 01.10.2007
A 01.11.2007
A 01.12.2007
A 01.01.2008
A 01.02.2008
A 01.03.2008
A 01.04.2008
A 01.05.2008
A 01.06.2008
B 01.12.2007
B 01.01.2008
B 01.02.2008
B 01.03.2008
B 01.04.2008
B 01.05.2008
B 01.06.2008
C 01.03.2008
C 01.04.2008
C 01.05.2008
C 01.06.2008
23 rows selected.Regards,
Dima -
Hi All,
I am using Oracle 11g version.
Could you please help me on this
i have table like this
personid planid rate
1 poo1 500
2 poo1 500
3 poo2 200
4 p003 100
But i want to get output like this
personid planid rate
1 p001 500
2
3 poo2 200
4 p003 100LRAJESH wrote:
Hi All,
I am using Oracle 11g version.
Could you please help me on this
i have table like this
personid planid rate
1 poo1 500
2 poo1 500
3 poo2 200
4 p003 100
But i want to get output like this
personid planid rate
1 p001 500
2
3 poo2 200
4 p003 100Depending on the context of the query,, it could be as simple as issueing a sqlplus BREAK command.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch6.htm#sthref1252 -
Hello every one,
Please help me with the query
i have two tables providerxwalk and load_status.
data are as under
providerxwalk
P_EXTERNAL_PROV_ID PROVIDER_TYPE
981870000016 PRACTITIONER
981670000028 PRACTITIONER
981400000045 PRACTITIONER
981240000008 PRACTITIONER
9650 ANCILLARY
95 ANCILLARY
9467 ANCILLARY
9408 ANCILLARY
9286 ANCILLARY
9144 ANCILLARY
91 ANCILLARY
8967 ANCILLARYload_status
CLAIMNUMBER CCODE STATUS PHCS_PROVIDER_ID
061018500214 PHCS11323 NOT LOADED 981870000016
061018500215 PHCS11323 NOT LOADED 981870000016
070514500260 PHCS11323 NOT LOADED 981870000016
060816500698 PHCS10841 NOT LOADED 981670000028
070303501383 PHCS11326 NOT LOADED 981400000045
070303501382 PHCS11326 NOT LOADED 981400000045
070205500171 PHCS11323 NOT LOADED 981240000008
060118501033 PHCS11028 NOT LOADED 9650
060803501605 PHCS11326 NOT LOADED 9650
060712501255 PHCS11326 NOT LOADED 9650
060310500904 PHCS11326 NOT LOADED 9650
070615501407 PHCS11326 NOT LOADED 9650
060819500754 PHCS11326 NOT LOADED 9650
060801501405 PHCS11326 NOT LOADED 9650
070516501078 PHCS11180 NOT LOADED 95
060531501686 PHCS11326 LOADED 9467
060620501240 PHCS11326 NOT LOADED 9408
060414501703 PHCS11326 LOADED 9286
060317500871 PHCS11326 LOADED 9144
060319500405 PHCS11326 LOADED 9144
060531501861 PHCS11326 LOADED 9144
060326500602 PHCS11326 LOADED 9144
060525501245 PHCS11326 NOT LOADED 91
060211500411 PHCS11372 NOT LOADED 8967
060120500488 PHCS11372 NOT LOADED 8967expected outout
provider_type Loaded Not_loaded Total
PRACTITIONER 0 7 7
ANCILLARY 6 12 18
Total 6 19 25 i have been trying hard but not able to get the expected out put
i got this so far
SELECT p.provider_type,
COUNT(DECODE(s.STATUS,'LOADED',1))Loaded,
COUNT(DECODE(s.STATUS,'NOT LOADED',1))NOT_Loaded,
COUNT(*)Total,
FROM CLAIMLOAD_STATUS s, PROVIDERXWALK p
WHERE s.PHCS_PROVIDER_ID=p.P_EXTERNAL_PROV_ID
GROUP BY p.provider_typeany help please.
thank you
added format
Message was edited by:
user553284I cannot believe my eyes you are saying it is not meeting your requirement.
create table providerxwalk(p_external_prov_id number, provider_type varchar2(20));
insert into providerxwalk values (981870000016, 'PRACTITIONER');
insert into providerxwalk values (981670000028, 'PRACTITIONER');
insert into providerxwalk values (981400000045, 'PRACTITIONER');
insert into providerxwalk values (981240000008, 'PRACTITIONER');
insert into providerxwalk values (9650 , 'ANCILLARY');
insert into providerxwalk values (95 , 'ANCILLARY');
insert into providerxwalk values (9467 , 'ANCILLARY');
insert into providerxwalk values (9408 , 'ANCILLARY');
insert into providerxwalk values (9286 , 'ANCILLARY');
insert into providerxwalk values (9144 , 'ANCILLARY');
insert into providerxwalk values (91 , 'ANCILLARY');
insert into providerxwalk values (8967, 'ANCILLARY');
create table load_Status (claimnumber varchar2(20), ccode varchar2(20), status varchar2(20), phcs_provider_id number);
insert into load_Status values ('061018500214','PHCS11323','NOT LOADED',981870000016);
insert into load_Status values ('061018500215','PHCS11323','NOT LOADED',981870000016);
insert into load_Status values ('060514500260','PHCS11323','NOT LOADED',981870000016);
insert into load_status values ('070816500698','PHCS10841','NOT LOADED',981670000028);
insert into load_status values ('070303501383','PHCS11326','NOT LOADED',981400000045);
insert into load_status values ('070303501382','PHCS11326','NOT LOADED',981400000045);
insert into load_status values ('070205500171','PHCS11323','NOT LOADED',981240000008);
insert into load_status values ('060118501033','PHCS11028','NOT LOADED',9650);
insert into load_status values ('060803501605','PHCS11326','NOT LOADED',9650);
insert into load_status values ('060712501255','PHCS11326','NOT LOADED',9650);
insert into load_status values ('060310500904','PHCS11326','NOT LOADED',9650);
insert into load_status values ('070615501407','PHCS11326','NOT LOADED',9650);
insert into load_status values ('060819500754','PHCS11326','NOT LOADED',9650);
insert into load_status values ('060801501405','PHCS11326','NOT LOADED',9650);
insert into load_status values ('070516501078','PHCS11180','NOT LOADED',95);
insert into load_status values ('0531501686', 'PHCS11326','LOADED',9467);
insert into load_status values ('060620501240','PHCS11326','NOT LOADED',9408);
insert into load_status values ('060414501703','PHCS11326','LOADED',9286);
insert into load_status values ('060317500871','PHCS11326','LOADED',9144);
insert into load_status values ('060319500405','PHCS11326','LOADED',9144);
insert into load_status values ('060531501861','PHCS11326','LOADED',9144);
insert into load_status values ('060326500602','PHCS11326','LOADED',9144);
insert into load_status values ('060525501245','PHCS11326','NOT LOADED',91);
insert into load_status values ('060211500411','PHCS11372','NOT LOADED',8967);
insert into load_status values ('060120500488','PHCS11372','NOT LOADED',8967);
The query which you have posted :
SQL> SELECT p.provider_type, COUNT(DECODE(s.STATUS,'LOADED',1))Loaded, COUNT(DECODE(s.STATUS,'NOT LOADED',1))NOT_Loaded, COUNT(*)Total
2 FROM LOAD_STATUS s, PROVIDERXWALK p WHERE s.PHCS_PROVIDER_ID=p.P_EXTERNAL_PROV_ID GROUP BY p.provider_type;
PROVIDER_TYPE LOADED NOT_LOADED TOTAL
ANCILLARY 6 12 18
PRACTITIONER 0 7 7
And this is what i have suggested in my earlier example.
SELECT decode(grouping_id(p.provider_type),1,'TOTAL',p.provider_type) provider_type,
COUNT(DECODE(s.STATUS,'LOADED',1))Loaded,
COUNT(DECODE(s.STATUS,'NOT LOADED',1))NOT_Loaded,
COUNT(*)Total
FROM LOAD_STATUS s, PROVIDERXWALK p
WHERE s.PHCS_PROVIDER_ID=p.P_EXTERNAL_PROV_ID
GROUP BY rollup(p.provider_type);
provider_type LOADED NOT_LOADED TOTAL
ANCILLARY 6 12 18
PRACTITIONER 0 7 7
TOTAL 6 19 25
Regards
Raj
Added couple of blank lines before the signature
Message was edited by: Raj
s.rajaram
Message was edited by:
s.rajaram
Message was edited by:
s.rajaram
Maybe you are looking for
-
Is it possible in Workflow to auto-forward messagefrom SAPinbox to Outlook
Hi Experts, In my workflow, previously I included a send mail step that sends notification message to holders of a position id in their SAP business workplace inbox. Then an activity step was there to determine the Outlook email addresses of those us
-
TS5181 How do I stop apple radio? Closing browser doesn't seem to help.
I made the mistake of clicking on an apple radio icon. How do I shut the darn thing off? I'm on Safari on OSX 10.
-
Hi! I would like to make a website for a friend, but later move the website on his computer, so he will not be depending on me all the time when he want to change something. Is it possible to do this? I cannot find any 'save as' options in my iWeb, i
-
Torn Movie Logo after "Run Active X"
Example : Utube movies still run in their box but the Quicktime torn movie logo comes up after clicking Active X box. Im using Windows XP Pro and downloaded Quicktime a month ago along with the new update of Internet Explorer when the problems occure
-
Proper schooling for App Development?
Hi, I am curious to know if there are schools that major in app development? Or at least proper training to become an iOS developer? Through proper schooling like Universities or community colleges? I am in Las Vegas, NV and was wondering if they off