Help to tun this sql please thanks
SELECT ORG.NAME ORGNAME,ORG.ORGANIZATIONUNITID
,ACC.NAME ACCNAME,ACC.ACCOUNTID
,INVOICEDEF.BILLDAY
,CSM.FIRSTNAME||' '||CSM.LASTNAME CSMNAME,SALES.FIRSTNAME||' '||SALES.LASTNAME SALESNAME
,SUM(MRC.BOOKINGVALUE) MRCVALUE ,SUM(PORTS.BOOKINGVALUE) PORTSVALUE,'' EXPDAYS
FROM BLIS_ORGANIZATIONUNIT ORG
,BLIS_ACCOUNT ACC
,BLIS_CUSTOMER CUS
,BLIS_SERVICESNAPSHOT SNAPSHOT
,BLIS_ORDERBOOKING MRC
,BLIS_ORDERBOOKING PORTS
,BLIS_INVOICEDEFINITION INVOICEDEF
,BLIS_PORTFOLIOSNAPSHOTREF PORREF
,BLIS_AGENT CSM
,BLIS_AGENTASSIGNMENT CSMASSIGN
,BLIS_AGENT SALES
,BLIS_AGENTASSIGNMENT SALESASSIGN
WHERE
ORG.ULTIMATEPARENTID =130169
OR ORG.ORGANIZATIONUNITID IN
(SELECT ORGANIZATIONUNITID FROM BLIS_ORGANIZATIONUNIT start with ORGANIZATIONUNITID=130169 connect by PARENTID=Prior ORGANIZATIONUNITID)
AND CUS.ORGANIZATIONUNITID = ORG.ORGANIZATIONUNITID
AND ACC.CUSTOMERID = CUS.CUSTOMERID
AND ACC.SERVICEPORTFOLIOID = PORREF.SERVICEPORTFOLIOID(+)
AND PORREF.SERVICESNAPSHOTID = SNAPSHOT.SERVICESNAPSHOTID(+)
AND INVOICEDEF.ACCOUNTID(+) = ACC.ACCOUNTID
AND INVOICEDEF.ISDEFAULT(+) = 1
AND MRC.ORDERSERVICEID(+) = SNAPSHOT.ORDERSERVICEID
AND MRC.BOOKINGTYPEID(+) = 115
AND PORTS.ORDERSERVICEID(+) = SNAPSHOT.ORDERSERVICEID
AND PORTS.BOOKINGTYPEID(+) = 117
AND CSMASSIGN.ENTITYID(+)=3
AND CSMASSIGN.ASSIGNMENTTYPEID(+)=2
AND CSMASSIGN.STATUS(+) = 'Active'
AND CSMASSIGN.AGENTID = CSM.AGENTID(+)
AND CSMASSIGN.KEYID(+) = ACC.ACCOUNTID
AND SALESASSIGN.ENTITYID=3
AND SALESASSIGN.ASSIGNMENTTYPEID=1
AND SALESASSIGN.STATUS = 'Active'
AND SALESASSIGN.AGENTID = SALES.AGENTID
AND SALESASSIGN.KEYID = ACC.ACCOUNTID
GROUP BY INVOICEDEF.BILLDAY
,ACC.NAME, ACC.ACCOUNTID
,ORG.NAME,ORG.ORGANIZATIONUNITID
,CSM.FIRSTNAME,CSM.LASTNAME,SALES.FIRSTNAME,SALES.LASTNAME
ORDER BY ORG.NAME, ACC.ACCOUNTID
1 row selected.
Elapsed: 00:01:49.16
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 18618 | 4090K| 54266 |
| 1 | SORT GROUP BY | | 18618 | 4090K| 54266 |
| 2 | FILTER | | | | |
| 3 | HASH JOIN | | 372K| 79M| 36070 |
| 4 | VIEW | index$_join$_011 | 4219 | 84380 | 8 |
| 5 | HASH JOIN | | | | |
| 6 | HASH JOIN | | | | |
| 7 | INDEX FAST FULL SCAN | XPKBLIS_AGENT | 4219 | 84380 | 2 |
| 8 | INDEX FAST FULL SCAN | INXBLIS_AGENT_1 | 4219 | 84380 | 2 |
| 9 | INDEX FAST FULL SCAN | INXBLIS_AGENT_2 | 4219 | 84380 | 2 |
| 10 | HASH JOIN RIGHT OUTER | | 372K| 72M| 36057 |
| 11 | VIEW | index$_join$_009 | 4219 | 84380 | 8 |
| 12 | HASH JOIN | | | | |
| 13 | HASH JOIN | | | | |
| 14 | INDEX FAST FULL SCAN | XPKBLIS_AGENT | 4219 | 84380 | 2 |
| 15 | INDEX FAST FULL SCAN | INXBLIS_AGENT_1 | 4219 | 84380 | 2 |
| 16 | INDEX FAST FULL SCAN | INXBLIS_AGENT_2 | 4219 | 84380 | 2 |
| 17 | HASH JOIN | | 372K| 65M| 36045 |
| 18 | INDEX FULL SCAN | INXBLIS_AGENTASSIGNMENT_4 | 345K| 8446K| 6444 |
| 19 | HASH JOIN RIGHT OUTER | | 210K| 32M| 27268 |
| 20 | TABLE ACCESS BY INDEX ROWID | BLIS_ORDERBOOKING | 339K| 3974K| 15334 |
| 21 | INDEX RANGE SCAN | INXBLIS_ORDERBOOKING_3 | 339K| | 105 |
| 22 | HASH JOIN RIGHT OUTER | | 169K| 23M| 10252 |
| 23 | TABLE ACCESS BY INDEX ROWID | BLIS_ORDERBOOKING | 22612 | 264K| 1023 |
| 24 | INDEX RANGE SCAN | INXBLIS_ORDERBOOKING_3 | 22612 | | 7 |
| 25 | HASH JOIN RIGHT OUTER | | 169K| 22M| 9227 |
| 26 | TABLE ACCESS FULL | BLIS_SERVICESNAPSHOT | 228K| 2234K| 1196 |
| 27 | HASH JOIN RIGHT OUTER | | 169K| 20M| 6675 |
| 28 | TABLE ACCESS FULL | BLIS_PORTFOLIOSNAPSHOTREF | 278K| 2718K| 269 |
| 29 | HASH JOIN RIGHT OUTER | | 165K| 18M| 5103 |
| 30 | TABLE ACCESS FULL | BLIS_INVOICEDEFINITION | 156K| 1681K| 664 |
| 31 | HASH JOIN RIGHT OUTER | | 165K| 16M| 3343 |
| 32 | INDEX SKIP SCAN | INXBLIS_AGENTASSIGNMENT_4 | 16010 | 390K| 534 |
| 33 | HASH JOIN | | 165K| 12M| 2807 |
| 34 | MERGE JOIN | | 143K| 5873K| 1334 |
| 35 | TABLE ACCESS BY INDEX ROWID| BLIS_ORGANIZATIONUNIT | 143K| 4475K| 481 |
| 36 | INDEX FULL SCAN | XPKBLIS_ORGANIZATIONUNIT | 143K| | 30 |
| 37 | SORT JOIN | | 143K| 1398K| 852 |
| 38 | TABLE ACCESS FULL | BLIS_CUSTOMER | 143K| 1398K| 267 |
| 39 | TABLE ACCESS FULL | BLIS_ACCOUNT | 156K| 5801K| 730 |
| 40 | FILTER | | | | |
| 41 | CONNECT BY WITH FILTERING | | | | |
| 42 | TABLE ACCESS BY INDEX ROWID | BLIS_ORGANIZATIONUNIT | 1 | 17 | 1 |
| 43 | INDEX UNIQUE SCAN | XPKBLIS_ORGANIZATIONUNIT | 1 | | 1 |
| 44 | NESTED LOOPS | | | | |
| 45 | CONNECT BY PUMP | | | | |
| 46 | TABLE ACCESS BY INDEX ROWID | BLIS_ORGANIZATIONUNIT | 314 | 2198 | 1 |
| 47 | INDEX RANGE SCAN | INXBLIS_ORGANIZATIONUNIT_1 | 1 | | 1 |
-------------------------------------------------------------------------------------------------------
Similar Messages
-
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, -
Hi, The Airport Express does not work with iOS 7.0.4, I appreciate your help to resolve this event. Thank you,
Please locate the model number of the AirPort Express and post back that information.
The model number is located on the side of the AirPort Express. It begins with an "A" followed by four numbers.
We are not sure what you mean by "does not work". Does this mean that the AirPort Express worked at one time and has just recently stopped working?
Have you installed a newer operating system on your iOS device recently?
Or, is this a new AirPort Express that you are trying to configure for the first time?
If yes, what service will the AirPort Express perform on your network?
Please remember that we cannot see your network, so we only know as much about your problem as you can tell us. -
Hi,
I'm using below query in procedure.It's taking more more time can some one help to tune this query or advice to rewrite the query.
Databse :10.1
SELECT 'Reading Comprehension' TEST_NAME,T.TEST_END_DATE TEST_SESSION_DATE,
C.POOL_VERSION_ID, I.CREATED_ON POOL_CREATED_DT,
C.ITEM_ID, C.ITEM_RESPONSE_ID, S.STUDENT_ID_PK, C.RESPONSE_KEY, C.IS_CORRECT RESPONSE_IS_CORRECT,
T.SCORE SCALE_SCORE, C.RESPONSE_DURATION, P.ITEM_KEY,
T.TEST_SESSION_DETAIL_ID, SYSDATE CREATED_ON
-- BULK COLLECT INTO TV_PSYCHO_DET
FROM
CAT_ITEM_PARAMETER P, CAT_ITEM_USER_RESPONSE C, TEST_SESSION_DETAIL T,
TEST_SESSION S, ITEM_POOL_VERSION I, TEST_DETAIL D
,INSTITUTION E
WHERE TRUNC(T.TEST_END_DATE) BETWEEN TO_DATE('01-11-09','dd-mm-yy') AND TO_DATE('30-11-09','dd-mm-yy')
AND D.TEST_NAME = 'Reading Comprehension'
AND T.TEST_SESSION_STATUS_ID = 3
AND I.POOL_AVAILABILITY='Y'
AND P.PRETEST=0 AND C.RESTART_FLAG=0
AND T.TEST_DETAIL_ID = D.TEST_DETAIL_ID
AND S.TEST_SESSION_ID = T.TEST_SESSION_ID
AND C.TEST_SESSION_DETAIL_ID = T.TEST_SESSION_DETAIL_ID
AND S.INSTITUTION_ID=E.INSTITUTION_ID
AND SUBSTR(E.INSTITUTION_ID_DISPLAY,8,3) <> '000'
AND I.ITEM_ID = C.ITEM_ID
AND P.ITEM_ID = I.ITEM_ID;expln plan
Plan hash value: 3712814491
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart|
Pstop |
| 0 | SELECT STATEMENT | | 50857 | 7151K| 93382 (1)| 00:18:41 | |
|
|* 1 | FILTER | | | | | | |
|
|* 2 | HASH JOIN | | 50857 | 7151K| 93382 (1)| 00:18:41 | |
|
| 3 | PARTITION HASH ALL | | 2312 | 23120 | 25 (0)| 00:00:01 | 1 |
5 |
|* 4 | TABLE ACCESS FULL | CAT_ITEM_PARAMETER | 2312 | 23120 | 25 (0)| 00:00:01 | 1 |
5 |
|* 5 | HASH JOIN | | 94938 | 12M| 93356 (1)| 00:18:41 | |
|
|* 6 | TABLE ACCESS FULL | ITEM_POOL_VERSION | 9036 | 132K| 30 (0)| 00:00:01 | |
|
|* 7 | TABLE ACCESS BY GLOBAL INDEX ROWID | CAT_ITEM_USER_RESPONSE | 9 | 279 | 18 (0)| 00:00:01 | ROWID |
ROWID |
| 8 | NESTED LOOPS | | 45349 | 5270K| 93325 (1)| 00:18:40 | |
|
|* 9 | HASH JOIN | | 4923 | 423K| 11377 (1)| 00:02:17 | |
|
|* 10 | INDEX FAST FULL SCAN | INSTI_ID_NAME_COUN_DISP_IDX | 8165 | 111K| 18 (0)| 00:00:01 | |
|
|* 11 | HASH JOIN | | 4923 | 355K| 11359 (1)| 00:02:17 | |
|
|* 12 | TABLE ACCESS BY GLOBAL INDEX ROWID| TEST_SESSION_DETAIL | 4107 | 148K| 6804 (1)| 00:01:22 | ROWID |
ROWID |
| 13 | NESTED LOOPS | | 4923 | 278K| 6806 (1)| 00:01:22 | |
|
|* 14 | INDEX RANGE SCAN | TEST_DETAIL_AK_1 | 1 | 21 | 2 (0)| 00:00:01 | |
|
|* 15 | INDEX RANGE SCAN | TEST_SESSION_DETAIL_FK2_I | 39737 | | 102 (0)| 00:00:02 | |
|
| 16 | PARTITION HASH ALL | | 1672K| 25M| 4546 (1)| 00:00:55 | 1 |
5 |
| 17 | TABLE ACCESS FULL | TEST_SESSION | 1672K| 25M| 4546 (1)| 00:00:55 | 1 |
5 |
|* 18 | INDEX RANGE SCAN | CAT_ITEM_USER_RESP_IDX1 | 18 | | 3 (0)| 00:00:01 | |
|
Predicate Information (identified by operation id):
1 - filter(TO_DATE('01-11-09','dd-mm-yy')<=TO_DATE('30-11-09','dd-mm-yy'))
2 - access("P"."ITEM_ID"="I"."ITEM_ID")
4 - filter("P"."PRETEST"=0)
5 - access("I"."ITEM_ID"="C"."ITEM_ID")
6 - filter("I"."POOL_AVAILABILITY"='Y')
7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0)
9 - access("S"."INSTITUTION_ID"="E"."INSTITUTION_ID")
10 - filter(SUBSTR("E"."INSTITUTION_ID_DISPLAY",8,3)<>'000')
11 - access("S"."TEST_SESSION_ID"="T"."TEST_SESSION_ID")
12 - filter(TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))>=TO_DATE('01-11-09','dd-mm-yy') AND "T"."TEST_SESSION_STATUS_ID"=3
AND TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))<=TO_DATE('30-11-09','dd-mm-yy'))
14 - access("D"."TEST_NAME"='Reading Comprehension')
15 - access("T"."TEST_DETAIL_ID"="D"."TEST_DETAIL_ID")
18 - access("C"."TEST_SESSION_DETAIL_ID"="T"."TEST_SESSION_DETAIL_ID")
43 rows selected.Edited by: user575115 on Dec 18, 2009 12:31 AMWhen you see something like ...
7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0) It means that Oracle had to do a conversion for you since you aren't using the proper data type in your query.
That would mean IF there is an index on that column, it won't be useable... -
hello i am trying to update my phone . i am connecting it to itunes but it is giving error 3194 . can you help me resolve this problem please.
Hi ali hakim,
Welcome to the Support Communities!
The article below may be able to help you with this issue.
Click on the link to see more details and screenshots.
iOS: Restore error 3194 or 'This device isn't eligible for the requested build'
http://support.apple.com/kb/TS4451
This occurs when iTunes is unable to communicate with the update-and-restore server (gs.apple.com). This is most likely because it is being blocked, redirected, or interrupted by security software, hosts-file entries, or other third-party software.
Cheers,
- Judy -
Hello, I have been exporting my photos with a watermark. Without changing any settings, half way through my day things changed, and now about 1 out of 7 photos have the watermark after export. Change you help me change this back please? Has anyone had this issue before?
I'm sorry to learn that you have endured the audio issues outlined in your post for almost 2 years SusanLM1! This is certainly not normal! Let's get to the bottom of this issue, first please confirm your phone model; your mention that you have the iPhone 5 but your post is on the iPhone 5S forum. Also, share the iOS version currently installed on your phone. What is your ZIP code? Does this happen mainly while you make/receive calls from a particular location (home, office, etc)?
AntonioC_VZW Follow us on Twitter at www.twitter.com/VZWSupport -
I get "We could not complete your iTunes Store request. An unknown error occurred (4002) Can any person help me with this on, please?
Turning off iTunes Match and Genius and then turning them back on appears to have worked for some people e.g.
https://discussions.apple.com/message/22059685#22059685
https://discussions.apple.com/message/18427550#18427550 -
I need help instantly on this program please
import java.util.*;
public class D3
private static int[] z = new int[100000];
private static int first=z[0];
private static int last=z[n-1];
private static int n=100000;
public static void main(String args[])
Scanner input=new Scanner(System.in);
for(int i=0;i<z.length;i++)
z=2*i;
int seqSearch(z;50000;n); //method call 4 key where key=mid
int binSearch(z;first;last;50000);
int seqSearch(z;35467;n); //method call 4 key where key in the left half
int binSearch(z;first;last;35467);
int seqSearch(z;89703;n); //method call 4 key where key in the right half
int binSearch(z;first;last;89703);
public int seqSearch(int z[];int key;int n)
long start = System.currentTimeMillis();
int count=0;
int ans=-1;
for(int i=0;i<n;i++)
if z[i]=key
count++
{ans=i
break;}
return ans;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
public int binSearch(int z[];int first;int last;int key)
long start = System.currentTimeMillis();
int count=0;
if(last<first){
count++;
index=-1;
else
count++;
int mid=(first+last)/2
if(ket=z[mid]{
index=mid;
else
if(key<z[mid]){
index = binSearch(z[];first;mid-1;key);
else
index=binSearch(z[];mid+1;last;key);
return index;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
// if anyone could tell me whats wrong with my code i'd be greatful...the program is supposed to perform binary and sequential search on a sorted array of 100000 numbers.once on an item in the middle of the array once on the right side of it and once on the left side...i also need to count the number of basic operations for the same number in both sequential and binary to see whats better.and i need to check the time...plz i need help now,,,"Guide to a first-time poster"
you need to add exclamation marks to signify how urgent it is
e.g.
i need help instantly on this program please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
capital letters is better
I NEED HELP INSTANTLY ON THIS PROGRAM PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
starting the italics on line 1, better again
import java.util.*;
public class D3
private static int[] z = new int[100000];
private static int first=z[0];
private static int last=z[n-1];
private static int n=100000;
public static void main(String args[])
Scanner input=new Scanner(System.in);
for(int i=0;i<z.length;i++)
z=2*i;
int seqSearch(z;50000;n); //method call 4 key where key=mid
int binSearch(z;first;last;50000);
int seqSearch(z;35467;n); //method call 4 key where key in the left half
int binSearch(z;first;last;35467);
int seqSearch(z;89703;n); //method call 4 key where key in the right half
int binSearch(z;first;last;89703);
public int seqSearch(int z[];int key;int n)
long start = System.currentTimeMillis();
int count=0;
int ans=-1;
for(int i=0;i<n;i++)
if z=key
count++
{ans=i
break;}
return ans;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
public int binSearch(int z[];int first;int last;int key)
long start = System.currentTimeMillis();
int count=0;
if(last><first){
count++;
index=-1;
else
count++;
int mid=(first+last)/2
if(ket=z[mid]{
index=mid;
else
if(key><z[mid]){
index = binSearch(z[];first;mid-1;key);
else
index=binSearch(z[];mid+1;last;key);
return index;
long elapsed = System.currentTimeMillis() - start;
System.out.print("Execution Time:" + elapsed);
System.out.print("# of Basic Operations:" + count);
and what about the dukes, offer 10 (never to be awarded, of course)
do this, then sit back and watch the replies roll in. -
my ipod touch brightness just went to zero after charging it. i've tried adjusting it to 100% but it still does not changed. can anybody help me solve this problem? thankS!
Have yu tried the standard fixes:
- Resetting:
Press and hold the On/Off Sleep/Wake button and the Home
button at the same time for at least ten seconds, until the Apple logo appears.
- Restoring the iPOd via iTunes. First from backup and if problem persists, restore to factory defaults/new iPod
- Make an appointment at the Genius Bar of an Apple store since you likely have a hardware problem -
I have had this problem since changing over to I Cloud and I thank you in advance for helping me with this...Cappuccini (Wayne).
1. Go to http://appleid.apple.com and change your password: make sure it has at least eight characters (more would be better), at least one of which is a capital, at least one lower case, and at least one a numeral.
2. Sign out in System Preferences>iCloud then sign back in again and re-enable Mail. -
Please help me tune this program,
Hi.
I have a item master data table and a transaction table.
For a given criteria I have to find items from master data table which do no exits in transaction table.
I have listed my flow below, can you please advice if there is any other optimal way of doing it.
1. For the given criteria read items from master data table into internal table 1. Sort the internal table 1.
2. For the given criteria read items from transaction table into internal table 2. Sort and remove duplicates from the internal table 2.
3. Loop at internal table 1, and check if item exists in internal table 2. Append items not in internal table 2 into another internal table 3.
At the end internal table 3 will have the items I am interested in. I can sort and use binary search addition, but is there any other efficient way of doing this task.
Thank you,
CDDon't use standard tables !!!!!!! They are o.k. in old coding in new coding you should
use only sorted and hashed tables and performance works automatically !!!
Forget about sorting and deleting duplicates !
> remove duplicates from the internal table 2.
use a hashed table with a unique key and collect you entries in the hash table,
Use sorted tables if the key is non-unique, or if the need also parts of the key!
Use hashed tables if the key must be unique.
Even for the append it is possible to APPEND into a sorted table, the records must come in a sort
order, i.e. if they come from a sorted table then it is o.k.
What I write is not imagination but the only really commendable way of handling internal tables.
Siegfried -
How to tune this SQL (takes long time to come up with results)
Dear all,
I have sum SQL which takes long time ... can any one help me to tune this.... thank You
SELECT SUM (n_amount)
FROM (SELECT DECODE (v_payment_type,
'D', n_amount,
'C', -n_amount
) n_amount, v_vou_no
FROM vouch_det a, temp_global_temp b
WHERE a.v_vou_no = TO_CHAR (b.n_column2)
AND b.n_column1 = :b5
AND b.v_column1 IN (:b4, :b3)
AND v_desc IN (SELECT v_trans_source_code
FROM benefit_trans_source
WHERE v_income_tax_app = :b6)
AND v_lob_code = DECODE (:b1, :b2, v_lob_code, :b1)
UNION ALL
SELECT DECODE (v_payment_type,
'D', n_amount,
'C', -n_amount
* -1 AS n_amount,
v_vou_no
FROM vouch_details a, temp_global_temp b
WHERE a.v_vou_no = TO_CHAR (b.n_column2)
AND b.n_column1 = :b5
AND b.v_column1 IN (:b12, :b11, :b10, :b9, :b8, :b7)
AND v_desc IN (SELECT v_trans_source_code
FROM benefit_trans_source
WHERE income_tax_app = :b6)
AND v_lob_code = DECODE (:b1, :b2, v_lob_code, :b1));
Thank You.....Thanks a lot,
i did change the SQL it works fine but slows down my main query.... actually my main query is calling a function which does the sum......
here is the query.....?
select A.* from (SELECT a.n_agent_no, a.v_agent_code, a.n_channel_no, v_iden_no, a.n_cust_ref_no, a.v_agent_type, a.v_company_code,
a.v_company_branch, a.v_it_no, bfn_get_agent_name(a.n_agent_no) agentname,
PKG_AGE__TAX.GET_TAX_AMT(:P_FROM_DATE,:P_TO_DATE,:P_LOB_CODE,A.N_AGENT_NO) comm,
c.v_ird_region
FROM agent_master a, agent_lob b, agency_region c
WHERE a.n_agent_no = b.n_agent_no
AND a.v_agency_region = c.v_agency_region
AND :p_lob_code = DECODE(:p_lob_code,'ALL', 'ALL',b.v_line_of_business)
AND :p_channel_no = DECODE(:p_channel_no,1000, 1000,a.n_channel_no)
AND :p_agency_group = DECODE(:p_agency_group,'ALL', 'ALL',c.v_ird_region)
group by a.n_agent_no, a.v_agent_code, a.n_channel_no, v_iden_no, a.n_cust_ref_no, a.v_agent_type, a.v_company_code, a.v_company_branch, a.v_it_no, bfn_get_agent_name(a.n_agent_no) ,
BPG_AGENCY_GEN_ACL_TAX.BFN_GET_TAX_AMOUNT(:P_FROM_DATE,:P_TO_DATE,:P_LOB_CODE,A.N_AGENT_NO),
c.v_ird_region
ORDER BY c.v_ird_region, a.v_agent_code DESC)
A
WHERE (COMM < :P_VAL_IND OR COMM >=:P_VAL_IND1);
Any idea to make this faster....
Thank You... -
What this SQL did is to generate a report like how many rows for each tp_stts when ims_toms_msge_type='TOMS NEW' (or 'TOMS CNCLO'). also, its corresponding total number for each ims_toms_msge_type.
Here is the sample:
Rownum H1 TP_STTS COUNT IMS_TOMS_MSGE_TYPE H FILTERTYPE
1 Trades Block Key Data Error 594 TOMS NEW A MSL
2 Allocation Data Error 334 TOMS NEW A MSL
3 Manual Processing Required 29 TOMS NEW A MSL
4 Manual Removal No Processing Required 67 TOMS NEW A MSL
5 Waiting For Authorization 2 TOMS NEW A MSL
6 Auto NAK 19764 TOMS NEW B SLS
7 Validated 165023 TOMS NEW B SLS
8 GRAND TOTAL 185813 TOMS NEW H MSL
9 Cancel Auto NAK 37 TOMS CNCLO X MSL
10 Manual Processing Required 114 TOMS CNCLO X MSL
11 Manually Processed 278 TOMS CNCLO X MSL
12 CANCEL GRAND TOTAL 429 TOMS CNCLO Z MSLSQL statement as below:
SELECT ROWNUM, MSGS.* FROM (with FTMReport as (
select tp_stts, ims_toms_msge_type, count(*) count from ims_trde, ims_toms_msge
where ( IMS_TRDE.PRCSG_GRP_ID = 5 ) AND ( IMS_TRDE.IMS_TRDE_RCPT_DTTM >= TO_DATE('12/01/2009 00:00', 'MM/DD/YYYY HH24:MI') AND IMS_TRDE.IMS_TRDE_RCPT_DTTM <= (TO_DATE('12/28/2009 23:59', 'MM/DD/YYYY HH24:MI')) ) AND (IMS_TRDE.GRS_TRX_TYPE NOT IN ('INJECTION','WITHDRAWAL','PAYMENT') OR IMS_TRDE.GRS_TRX_TYPE IS NULL) AND (IMS_TRDE.SSC_INVST_TYPE != 'FC' OR IMS_TRDE.SSC_INVST_TYPE IS NULL) AND (IMS_TRDE.SERVICE_TYPE='FS' OR IMS_TRDE.SERVICE_TYPE='CO') AND 1=1
and IMS_TRDE.SERVICE_TYPE='FS' and 1=1 and ims_trde.ims_trde_oid = ims_toms_msge.ims_trde_oid
group by tp_stts, ims_toms_msge_type
select 'GRAND TOTAL' H1, null tp_stts, sum(Count) count , ims_toms_msge_type ,'H', 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS NEW') group by ims_toms_msge_type
union
select 'CANCEL GRAND TOTAL' H1, null tp_stts, sum(Count) count, ims_toms_msge_type ,'Z', 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS CNCLO') group by ims_toms_msge_type
union
select DECODE(rownum, 1, 'Trades') H1, tp_stts, count, ims_toms_msge_type , 'A' , 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS NEW') and tp_stts not in ('Validated','Auto NAK','Manual NAK')
union
select ' ' H1, tp_stts, count, ims_toms_msge_type , 'B' , 'SLS' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS NEW') and tp_stts in ('Validated','Auto NAK','Manual NAK')
union
select DECODE(rownum, 1, 'Cancel') H1, tp_stts, count, ims_toms_msge_type , 'X' , 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS CNCLO') order by 5,6
) MSGS;Explain plan as below:
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 193 | 12738 | 32 |
| 1 | COUNT | | | | |
| 2 | VIEW | | 193 | 12738 | 32 |
| 4 | TEMP TABLE TRANSFORMATION | | | | |
| 3 | RECURSIVE EXECUTION | SYS_LE_4_0 | | | |
| 0 | INSERT STATEMENT | | 61 | 4575 | 9264 |
| 1 | LOAD AS SELECT | | | | |
| 2 | SORT GROUP BY | | 61 | 4575 | 9264 |
| 3 | NESTED LOOPS | | 1604 | 117K| 9251 |
|* 4 | TABLE ACCESS BY INDEX ROWID| IMS_TRDE | 1603 | 80150 | 6045 |
|* 5 | INDEX RANGE SCAN | IMS_TRDE_INDX4 | 539K| | 3917 |
|* 6 | INDEX RANGE SCAN | IMS_TOMS_MSGE_INDX1 | 1 | 25 | 2 |
| 5 | SORT UNIQUE | | 193 | 8831 | 30 |
| 6 | UNION-ALL | | | | |
| 7 | SORT GROUP BY NOSORT | | 5 | 115 | 6 |
|* 8 | VIEW | | 61 | 1403 | 2 |
| 9 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
| 10 | SORT GROUP BY NOSORT | | 5 | 115 | 6 |
|* 11 | VIEW | | 61 | 1403 | 2 |
| 12 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
| 13 | COUNT | | | | |
|* 14 | VIEW | | 61 | 2867 | 2 |
| 15 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
|* 16 | VIEW | | 61 | 2867 | 2 |
| 17 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
| 18 | COUNT | | | | |
|* 19 | VIEW | | 61 | 2867 | 2 |
| 20 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
Predicate Information (identified by operation id):
4 - filter(("IMS_TRDE"."GRS_TRX_TYPE"<>'INJECTION' AND "IMS_TRDE"."GRS_TRX_TYPE"<>'WITHDRAWAL'
AND "IMS_TRDE"."GRS_TRX_TYPE"<>'PAYMENT' OR "IMS_TRDE"."GRS_TRX_TYPE" IS NULL) AND
("IMS_TRDE"."SSC_INVST_TYPE"<>'FC' OR "IMS_TRDE"."SSC_INVST_TYPE" IS NULL))
5 - access("IMS_TRDE"."IMS_TRDE_RCPT_DTTM">=TO_DATE(' 2009-12-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "IMS_TRDE"."PRCSG_GRP_ID"=5 AND "IMS_TRDE"."SERVICE_TYPE"='FS' AND
"IMS_TRDE"."IMS_TRDE_RCPT_DTTM"<=TO_DATE(' 2009-12-28 23:59:00', 'syyyy-mm-dd hh24:mi:ss'))
filter("IMS_TRDE"."PRCSG_GRP_ID"=5 AND "IMS_TRDE"."SERVICE_TYPE"='FS')
6 - access("IMS_TRDE"."IMS_TRDE_OID"="IMS_TOMS_MSGE"."IMS_TRDE_OID")
8 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW')
11 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS CNCLO')
14 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW' AND "FTMREPORT"."TP_STTS"<>'Validated'
AND "FTMREPORT"."TP_STTS"<>'Auto NAK' AND "FTMREPORT"."TP_STTS"<>'Manual NAK')
16 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW' AND ("FTMREPORT"."TP_STTS"='Auto NAK' OR
"FTMREPORT"."TP_STTS"='Manual NAK' OR "FTMREPORT"."TP_STTS"='Validated'))
19 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS CNCLO')
Note: cpu costing is offCould you guys tell me what is wrong with this sql and how to tune it?
Is there any way to replace the UNION? Is using UNION a good idea?
Can I use DECODE or CASE WHEN to simplify it? How?
Also, could you help explain why there is SYS_LE_4_0, SYS_TEMP_0FD9D660F_B198D56F temporary segment? Is it caused by with FTMReport as ?
Thanks
Edited by: PhoenixBai on Dec 31, 2009 9:58 AM
Edited by: PhoenixBai on Dec 31, 2009 12:08 PM
Edited by: PhoenixBai on Dec 31, 2009 12:17 PMI consider using GROUP BY ROLLUP together with DECODE, CASE WHEN, but haven`t come out with a working sql yet:-(Some sample data to work with would have been much helpful. But we dont get that most of the time :(
I came up with this.
select case when ims_toms_msge_type = 'TOMS NEW' then
case when grouping(tp_stts) = 1 then 'GRAND TOTAL'
when tp_stts not in ('Validated','Auto NAK','Manual NAK') then 'Trades'
end
when ims_toms_msge_type = 'TOMS CNCLO' then
case when grouping(tp_stts) = 1 then 'CANCEL GRAND TOTAL'
when tp_stts in ('Validated','Auto NAK','Manual NAK') then 'Cancel'
end
end h1,
tp_stts,
count(*) count,
ims_toms_msge_type,
case when ims_toms_msge_type = 'TOMS NEW' then
case when grouping(tp_stts) = 1 then 'H'
when tp_stts not in ('Validated','Auto NAK','Manual NAK') then 'A'
end
when ims_toms_msge_type = 'TOMS CNCLO' then
case when grouping(tp_stts) = 1 then 'Z'
when tp_stts in ('Validated','Auto NAK','Manual NAK') then 'B'
end
end flag,
'MSL' FilterType
from ims_trde,
ims_toms_msge
where IMS_TRDE.PRCSG_GRP_ID = 5
AND IMS_TRDE.IMS_TRDE_RCPT_DTTM >= TO_DATE('12/01/2009 00:00', 'MM/DD/YYYY HH24:MI')
AND IMS_TRDE.IMS_TRDE_RCPT_DTTM <= TO_DATE('12/28/2009 23:59', 'MM/DD/YYYY HH24:MI')
AND (IMS_TRDE.GRS_TRX_TYPE NOT IN ('INJECTION','WITHDRAWAL','PAYMENT')
OR IMS_TRDE.GRS_TRX_TYPE IS NULL)
AND (IMS_TRDE.SSC_INVST_TYPE != 'FC'
OR IMS_TRDE.SSC_INVST_TYPE IS NULL)
AND (IMS_TRDE.SERVICE_TYPE = 'FS'
OR IMS_TRDE.SERVICE_TYPE = 'CO')
AND 1=1
and IMS_TRDE.SERVICE_TYPE = 'FS'
and 1=1
and ims_trde.ims_trde_oid = ims_toms_msge.ims_trde_oid
group by rollup(ims_toms_msge_type, tp_stts)Not sure if this code works. Because i dint have the table or the data to test it. So if it has some error just fix it and give it a try. Do post the kind of output it gives. So that we can see if we can work with this solution. -
Help asked for a sql request - thanks
Hello,
I'm not a sql Guru... Who can help for this sql request ?
First I have this:
SELECT ADDINFO_ID, INFO, LANGUAGE_FK, ENGLISH_NAME
FROM V_ADDINFOS
WHERE LANGUAGE_FK = 'EN' (which is very simple...-)
But now complicated... I have to add this in the same request:
select sum(val) as nbrInfo
from(
select count(*) val from eccgis where addinfo1_fk = ADDINFO_ID
union all
select count(*) val from eccgis where addinfo2_fk = ADDINFO_ID
union all
select count(*) val from eccgis where addinfo3_fk = ADDINFO_ID
union all
select count(*) val from thirdgis where addinfo1_fk = ADDINFO_ID
union all
select count(*) val from thirdgis where addinfo2_fk = ADDINFO_ID
In other words, for each row of the first select, I need to know how much it is linked in the tables eccgis and thirdgis...
Hope is is clear... -)
Thank you very very much,
MichelHi, Michel,
Almost anywhere that SQL allows an expression (such as a column name, literal or function call) it also allows a scalar sub-query, a SELECT statement based on any table (or tables) that returns one column and (at most) one row. Like other sub-queries, scalar sub-queries can be corellated to the main query.
To get the grand total you want on each row of your output:
SELECT ADDINFO_ID, INFO, LANGUAGE_FK, ENGLISH_NAME
, (select count(*) from eccgis where addinfo1_fk = ADDINFO_ID)
+ (select count(*) from eccgis where addinfo2_fk = ADDINFO_ID)
+ (select count(*) from eccgis where addinfo3_fk = ADDINFO_ID)
+ (select count(*) from thirdgis where addinfo1_fk = ADDINFO_ID)
+ (select count(*) from thirdgis where addinfo2_fk = ADDINFO_ID)
AS nrbInfo
FROM V_ADDINFOS
WHERE LANGUAGE_FK = 'EN';VERY IMPORTANT: Each sub-query must be in parentheses. You'll get a run-time error if any scalar sub-query returns more than one row. (Returning no rows is okay: the value will be NULL).
By the way, this looks like a bad table design. If each row in eccgis or thirdgis can be associated with more than one foreign key, they should be kept in a separate table. That's the standard way to handle many-to-many relationships. -
Hey guy can you please help me with this issue PLEASE!
Hey Apple can you please help me with this issue, i have a iPhone 3gs and when i put my sim card into the iPhone it makes iphone 3gs shut down suddenly how do i fix that?
iPhone version: 6.0.1
service provider: Vodafone nzYou could restarting your phone that sometimes fixes issues
Hold down the Sleep/Wake button and the home button together until the apple logo appears (ignore the ON/OFF slider) then let both buttons go and wait for phone to restart (no data will be lost).
Maybe you are looking for
-
I have a 3GS and since I did the IOS6 update my phone won't send pictures via text message. Anyone know how to fix this?
-
Getting an error message when trying to log on to imessage
Getting an error message when trying to log on to imessage... how do I fix this
-
USB 2.0 - Stick - Error on Solaris 10 x86 03/05 GA
Hello Solaris - Friends, I have a Problem with my USB 2.0 - Stick (Fujitsu-Siemens Memorybird 256 MB). He has 1 primary Partition (FAT16). When the Laptop (Fujitsu-Siemens Lifebook E8010) is booting, comes this Error-Message : "/pci@0,0/pci10cf,11ab@
-
Windows will not restart properly when iPod is Connected!
Please help...I am running Windows XP and i have a 5th Gen iPod. My computer will not restart when I have my iPod connected to my computer, it starts then after a few seconds it just goes to a blank screen. Yet if I unplug my iPod my compter will res
-
CD\DVD Storage Disconnects
Hello, I'm using a product that is a Device control. I have two policies for my computers. One for the Admin group and one for the Users group. When I log in as an Admin my policy allows me to see the Device. I'll log out and Log in as a User and t