Another way to write the query:
Dear Experts, I am a beginner in sql. With my knowledge, I wrote this querybut he took great moment in my database 11g
Please tell any alternative to write this query in another way to increase performance
Please find the explanation below
SELECT DISTINCT *
FROM UPGRADATION r1,
LOG t2,
OMNIACCOUNT m1,
(SELECT rid
, LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY ACCOUNTNO) AS ACCOUNTNO
FROM OMNIACCOUNT
GROUP BY rid) mk3,
(SELECT mobileno
, LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY ACCOUNTNO) AS ACCOUNTNO
FROM OMNIACCOUNT
GROUP BY mobileno) mk1,
(SELECT mobileno
, LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY accounttype) AS ACCOUNTTYPE
FROM OMNIACCOUNT
GROUP BY mobileno) mk2
WHERE t2.txnauthid = r1.txnauthid
AND r1.rid = mk3.rid
AND t2.txntype = '54'
AND mk1.mobileno = r1.regmobileno
AND t2.reqtype = '11'
AND t2.dc_id IN (SELECT deliverychannel_id
FROM Channel)
AND t2.custbankcode = '32472'
AND t2.txndatetime BETWEEN TO_DATE ('28/12/2011 12:00:00 AM',
'DD/MM/YYYY hh:mi:ss AM'
)
AND TO_DATE ('28/12/2012 11:59:59 PM',
'DD/MM/YYYY hh:mi:ss PM'
)
AND r1.rid = m1.rid(+)
AND t2.txnstatus IN ('C', 'F', 'T')
AND t2.paymentinitiator = 'C'
AND mk1.mobileno = mk2.mobileno
Explain Plan For the above statement :
-----------------------------------
SELECT STATEMENT FIRST_ROWSCost: 16 Bytes: 4,270 Cardinality: 1
25 HASH UNIQUE Cost: 16 Bytes: 4,270 Cardinality: 1
24 NESTED LOOPS Cost: 15 Bytes: 4,270 Cardinality: 1
19 NESTED LOOPS Cost: 14 Bytes: 4,270 Cardinality: 1
13 HASH JOIN Cost: 13 Bytes: 2,268 Cardinality: 1
9 NESTED LOOPS OUTER Cost: 4 Bytes: 252 Cardinality: 1
7 NESTED LOOPS Cost: 3 Bytes: 239 Cardinality: 1
4 NESTED LOOPS Cost: 2 Bytes: 119 Cardinality: 1
2 TABLE ACCESS BY INDEX ROWID TABLE LOG Cost: 1 Bytes: 116 Cardinality: 1
1 INDEX RANGE SCAN INDEX IX_LOG Cost: 1 Cardinality: 8
3 INDEX UNIQUE SCAN INDEX (UNIQUE) PK_Channel Cost: 1 Bytes: 3 Cardinality: 1
6 TABLE ACCESS BY INDEX ROWID TABLE UPGRADATION Cost: 1 Bytes: 120 Cardinality: 1
5 INDEX RANGE SCAN INDEX IDX_REG_AUTH Cost: 1 Cardinality: 1
8 INDEX RANGE SCAN INDEX IDX_MLTN_BNK_ACCT Cost: 1 Bytes: 13 Cardinality: 1
12 VIEW Cost: 8 Bytes: 1,110,816 Cardinality: 551
11 SORT GROUP BY Cost: 8 Bytes: 16,530 Cardinality: 551
10 TABLE ACCESS FULL TABLE OMNIACCOUNT Cost: 7 Bytes: 21,210 Cardinality: 707
18 VIEW PUSHED PREDICATE Cost: 1 Bytes: 2,002 Cardinality: 1
17 FILTER
16 SORT GROUP BY Bytes: 33 Cardinality: 1
15 TABLE ACCESS BY INDEX ROWID TABLE OMNIACCOUNT Cost: 1 Bytes: 33 Cardinality: 1
14 INDEX RANGE SCAN INDEX IDX_MUL_LNKG Cost: 1 Cardinality: 1
23 VIEW PUSHED PREDICATE Cost: 1 Cardinality: 1
22 FILTER
21 SORT GROUP BY Bytes: 29 Cardinality: 1
20 INDEX RANGE SCAN INDEX IDX_MLTN_BNK_ACCT Cost: 1 Bytes: 29 Cardinality: 1
It would be best to leave the desired projection.
Probably you don't really want all columns form this query.
However, these are your join criteria:
t2.txnauthid = r1.txnauthid
AND r1.rid = mk3.rid
AND r1.regmobileno = mk1.mobileno
AND mk1.mobileno = mk2.mobileno
AND r1.rid = m1.rid(+)
Maybe you can get rid of AND mk1.mobileno = mk2.mobileno
with
(SELECT mobileno
, LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY ACCOUNTNO) AS ACCOUNTNO
, LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY accounttype) AS ACCOUNTTYPE
FROM OMNIACCOUNT
GROUP BY mobileno)
After the combination seems to be suspicious:
AND r1.rid = mk3.rid
AND r1.rid = m1.rid(+)
The first limit the result on all lines with the same id in
OMNIACCOUNT and UPGRADATION
so, o see no gain from the outer join.
Do you really need the listagg on all OMNIACCOUNT lines.
If this isn't the case, it would be probably better to do the listagg in the final projection.
Maybe one way could be to start with OMNIACCOUNT and join outer UPGRADATION to it.
You can do the listagg at the end.
Maybe something like
select
*
from
OMNIACCOUNT m1
left outer join
(Select
projection goes here
from
log t2 join UPGRADATION r1
on
r1.txnauthid = t2.txnauthid
AND t2.reqtype = '11'
AND t2.dc_id IN (SELECT deliverychannel_id
FROM Channel)
AND t2.custbankcode = '32472'
AND t2.txndatetime BETWEEN TO_DATE ('28/12/2011 12:00:00 AM',
'DD/MM/YYYY hh:mi:ss AM'
)
AND TO_DATE ('28/12/2012 11:59:59 PM',
'DD/MM/YYYY hh:mi:ss PM'
)
AND t2.txntype = '54'
AND t2.txnstatus IN ('C', 'F', 'T')
AND t2.paymentinitiator = 'C'
) r1
on
m1.rid=r1.rid
AND
r1.regmobileno = m1.mobileno
Published by: chris227 on 10.01.2013 01:45
fix
Tags: Database
Similar Questions
-
Best way to write the Pl/Sql
Hi all
Can someone say best written below stored proc:
procedure missing_authorized_services is
v_truncate_sql varchar2 (200);
v_sql varchar2 (2000);
BEGIN
v_truncate_sql: = "truncate table missing_authorized_services;
immediately run v_truncate_sql;
commit;
v_sql: = "INSERT into missing_authorized_services select distinct trim (service_group_Cd) as service_group_Cd, trim (service_cd) as stage_1_mg_service_request service_cd
where (service_group_cd, service_cd) not in)
Select distinct service_group_cd, stage_3_servcd_servgrp_dim service_cd)';
immediately run v_sql;
commit;
END missing_authorized_services;
/ * I do select the table and then try to insert into another table the result set * /.
Please help,
Thank you
JHello
The best way to write the PL/SQL (or any code) is by small steps.
Start with a very simple procedure that does something (anything), just enough to make sure it works.
Add a lot of statements of output so you can see what made the procedure. Don't forget to delete them after that trial is over.For example:
CREATE OR REPLACE procedure missing_authorized_services IS v_truncate_sql VARCHAR2 (200); BEGIN v_truncate_sql := 'truncate table missing_authorized_services'; dbms_output.put_line ( v_truncate_sql || ' = v_truncate_sql inside missing_authorized_services' ); END missing_authorized_services;
If you get any errors (for example, ORA-00955, because you try to give the same name to a procedure that you already use for a table), then fix the error and try again.
When he worls perfectly, then add another baby step. For example, you can add the lineEXECUTE IMMEDIATE v_truncate_sql;
and test again.
Do not use SQL dynamic (EXECUTE IMMEDIATE) unless you have to.
Is there a reason to use dynamic SQL for INSERT statements? -
Is the another way to get the download from the support section
Is there another way to get the download from the support section?
Because the download speed is very slow. For example, in the new version of the value-added packaging and its 116 MB big need. A normal download time would be approximately 5-10 minutes. But when I download from Toshiba I need 2 to 6 hours. Not good for a company that manufactures laptops and high-performance computers.
And the worst thing is that the connection is reset after a few hours... so I'll never get the update.
Does anyone know help?
Gruss
ThomasUnfortunately, he has no other way to get the Toshiba drivers from the European pilot of Toshiba page.
You are right at this moment that the file transfer is too long.
I get about 10-19KO/s. That s is really very slow.
Maybe the server is overloaded who knows I hope this will be resolved in the next time.Best regards
-
Original title: screen toggle main F
Some of my F keys on my laptop no longer work. Therefore, I can't turn my screen to another monitor (IE. TV.) Fixing of the F keys would be great, but at least it is another way to switch the video output?
Hello
Have you made changes on the computer before this problem?
Step 1: Check if you are able to use on-screen keyboard function keys and send back the same.
Step 2: The following article can help you in the selection of the display.
How to configure and use multiple monitors in Windows XP
http://support.Microsoft.com/kb/307873 -
Taché product key
HelloI try to install vista on my laptop but a letter of the key is not visible, all the other parts are very well including the serial code, is there another way to get the key of the other information? The laptop currently has non-OS I've tried to reinstall.
Thank you
Scott
Product keys are bit-agnostic - they don't care if it's 32-bit or 64-bit.
However, cannot legally use the recovery disk from one computer to a different constructor machine - as other licenses are not properly paid..
There is nothing nonetheless to try all possible variations on the absence of character (there are only 25, after all the
) Other than that, your best option is to contact the manufacturer and order a set of recovery disc for the machine. I do no download available for Vista with SP2 - but you can download Vista with SP1 and create the disc.
http://www.heidoc.NET/Joomla/technology-science/Microsoft/57-Windows-Vista-direct-download-links
-
Hi, I'm checking the existence of the file in pl/sql with utl_file.
DECLARE
Yn BOOLEAN;
FLEN NUMBER;
BSIZE NUMBER;
BEGIN
UTL_FILE.fgetattr ('RMCMIFIDDWH_OUTPUT', - directory
'filname.txt', - filename
Yn, - Boolean Yes or no.
FLEN, - length of file
BSIZE);-block size
IF yn THEN
dbms_output.put_line ("'File Exists");
ON THE OTHER
dbms_output.put_line ('file does not exist');
END IF;
dbms_output.put_line (' length of file: ' |) To_char (Flen));
dbms_output.put_line (' block size: ' |) To_char (BSIZE));
END fgetattr;
Please help me if there is another way to do the same thing.
There is no problem, but I was looking for a simple method to check only file existence and for this reason only I have my question here with the solution.
-
I have Photoshop elements for Christmas 14. When I go to install it, he invited me for a serial number which I can't find anywhere on the disc, disc sleeve or box product. Is there another way to find the serial number for this product, so I can continue the installation? And no, I have not installed or registered this product before.
Redemption Code http://helpx.adobe.com/x-productkb/global/redemption-code-help.html
- and https://forums.adobe.com/thread/1572504
Find your http://helpx.adobe.com/x-productkb/global/find-serial-number.html serial No.
-
How to write the query option in expdp
Hi Please someone help me how to write the query option in expdp... .in expdp using the query option...
where AM columnname between 5 May 12 02:57:00.000' and ' 02:59:59.999 6 May 12: ';
Please do what is necessary...Pavan Kumar says:
QUERY = (columnname scott.test: "where between 5 May 12 02:57:00.000 h ' and ' 6 May 12 AM 02:59:59.999'")Who will fail in databases, because you assume nls_date_format. How it is difficult to put to_date() surround channels? Rather than play with quotation marks, using one parfile thusly.
query=table_owner.table_1:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')" query=table_owner.table_2:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')" query=table_owner.table_3:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
You do not have to have all the clauses in a single line, as they are side by side parfile, which would be enough. For this reason parfile is better than the command line in order to avoid all the back-citing dance.
-
write the query sql for the following situation?
We have a table like format following...
A AND B
...................
10 30
50 40
60 80
90 100
so to write the query and get the result like formats following...
RESULT
............
30
50
80
100
Try this... He's one of the interview question. I can't write the query...
If a knowledge write the query...Hello
Try thisselect (case when a>b then a else b end) "Result" from
; -
Another way to recover the data - query
I tried the latest data for these type_idS: '306 ', '303', '304',' 305'
Here's the query according to datatime. Other alternatives to get the same
Select T.TYPE_ID, t.t_desc, T.CREATED_DATE in gen_comment t
where
(t.type_id, created_date) in
(select dfd.type_id, max (dfd.created_date) in gen_comment Diabaté
When type_id in ('306', '303', '304',' 305')
Dfd.type_id group);
gen_comment
TYPE_ID created_date t_desc
rere 303 13/05/2009-09:07:50
Diabate 303 2009-05-13 10:14:24
Wew 303 05/13/2009 10:20:51
304 dsds 2009-05-13 10:20:51
304 sds 13/05/2009 10:20:51
sfef 305 13/05/2009 10:20:51
305 European works councils 2009-05-13 10:20:51
305 ewged 13/05/2009 10:20:51
305 hghgg 13/05/2009 10:20:51
Ferfer 306 13/05/2009 10:20:51
306 dfdfbv 13/05/2009 10:20:51
Thank you.Hello
An alternative:
SQL> select * from gen_comment; TYPE_ID T_DESC CREATED_DATE ---------- ------ ---------------------- 303 rere 05/13/2009 09:07:50 AM 303 dfdf 05/13/2009 10:14:24 AM 303 wew 05/13/2009 10:20:51 AM 304 dsds 05/13/2009 10:20:51 AM 304 sds 05/13/2009 10:20:51 AM 305 sfef 05/13/2009 10:20:51 AM 305 ewcs 05/13/2009 10:20:51 AM 305 ewged 05/13/2009 10:20:51 AM 305 hghgg 05/13/2009 10:20:51 AM 306 ferfer 05/13/2009 10:20:51 AM 306 dfdfbv 05/13/2009 10:20:51 AM 11 rows selected. Elapsed: 00:00:00.01 SQL> select type_id 2 , t_desc 3 , created_date 4 from ( select type_id 5 , t_desc 6 , created_date 7 , max(created_date) over (partition by type_id) max_date 8 from gen_comment 9 where type_id in (306,303,304,305) -- HOPE WE'RE NOT STORING NUMBERS AS STRINGS HERE? 10 ) 11 where max_date = created_date; TYPE_ID T_DESC CREATED_DATE ---------- ------ ---------------------- 303 wew 05/13/2009 10:20:51 AM 304 dsds 05/13/2009 10:20:51 AM 304 sds 05/13/2009 10:20:51 AM 305 sfef 05/13/2009 10:20:51 AM 305 hghgg 05/13/2009 10:20:51 AM 305 ewcs 05/13/2009 10:20:51 AM 305 ewged 05/13/2009 10:20:51 AM 306 ferfer 05/13/2009 10:20:51 AM 306 dfdfbv 05/13/2009 10:20:51 AM 9 rows selected. Elapsed: 00:00:00.09 SQL> -- your query SQL> select t.type_id,t.t_desc,t.created_date 2 from gen_comment t 3 where (t.type_id,created_date) in ( select dfd.type_id,max(dfd.created_date) 4 from gen_comment dfd 5 where type_id in ('306','303','304','305') 6 group by dfd.type_id); TYPE_ID T_DESC CREATED_DATE ---------- ------ ---------------------- 303 wew 05/13/2009 10:20:51 AM 305 hghgg 05/13/2009 10:20:51 AM 305 ewged 05/13/2009 10:20:51 AM 305 ewcs 05/13/2009 10:20:51 AM 305 sfef 05/13/2009 10:20:51 AM 306 dfdfbv 05/13/2009 10:20:51 AM 306 ferfer 05/13/2009 10:20:51 AM 304 sds 05/13/2009 10:20:51 AM 304 dsds 05/13/2009 10:20:51 AM 9 rows selected. Elapsed: 00:00:00.11
-
Hello
I have a problem and I realized a simplified version of it:
The id of the requirement to join these two tables based on:create table deals (id_prsn number, id_deal number, fragment number); create table deal_values (id_prsn number, id_deal number, value_ number, date_ date); insert into deals values(1,1,50); insert into deals values(2,2,40); insert into deals values(1,3,50); insert into deals values(2,4,80); insert into deals values(1,5,20); insert into deals values(2,6,80); insert into deal_values values(1,1,10 ,sysdate - 3); insert into deal_values values(2,2,208, sysdate - 3); insert into deal_values values(2,4,984, sysdate - 3); insert into deal_values values(1,null,134,sysdate - 3); insert into deal_values values(1,1,13, sysdate - 2); insert into deal_values values(2,2,118, sysdate - 2); insert into deal_values values(2,4,776, sysdate - 1); insert into deal_values values(1,null,205,sysdate - 1); insert into deal_values values(2,null,-5,sysdate - 1);
1.) ID_PRSN and ID_DEAL
2.) max DATE_ grouped per person and deal
(3.) in the case that ID_DEAL is defined in the AGREEMENTS, but not defined in the DEAL_VALUES table, I have to join this records to DEAL_VALUES based on the person where id_Deal is null.
Number 3 gives me headache. I realized the following query:
It returns the correct result of he,select *from ( select a.id_prsn, a.id_deal, a.fragment, b.value_, b.date_, max(b.date_) over (partition by b.id_prsn, b.id_deal) max_date from deals a inner join deal_values b on a.id_deal = b.id_deal or b.id_deal is null and not exists (select 1 from deal_values where id_prsn = a.id_prsn and id_deal = a.id_deal) and a.id_prsn = b.id_prsn ) where date_ = max_Date;
ID_PRSN ID_DEAL FRAGMENT VALUE_ DATE_ MAX_DATE
1 1 50 13 16.10.2012 09:59:48 16.10.2012 09:59:48
1 3 50 205 17.10.2012 09:59:48 17.10.2012 09:59:48 OK
1 5 20 205 17.10.2012 09:59:48 17.10.2012 09:59:48 OK
2 2 40 118 16.10.2012 09:59:48 16.10.2012 09:59:48
2 4 80 776 17.10.2012 09:59:48 17.10.2012 09:59:48
2 6 80-5 17.10.2012 09:59:48 17.10.2012 09:59:48 OK
but the join clause:
in fact the query much slower.on a.id_deal = b.id_deal or b.id_deal is null and not exists (select 1 from deal_values where id_prsn = a.id_prsn and id_deal = a.id_deal) and a.id_prsn = b.id_prsn
I was wondering is there a different way to write this join and manage the logic.
Thanks in advanceHere's a different approach:
select * from ( select a.id_prsn, a.id_deal, a.fragment, B.value_, b.date_, ROW_NUMBER() over( partition by a.ID_PRSN, a.ID_DEAL order by B.ID_DEAL nulls last, B.DATE_ desc ) RN from DEALS a join DEAL_VALUES B on a.ID_PRSN = B.ID_PRSN and a.ID_DEAL = NVL(B.ID_DEAL, a.ID_DEAL) ) where rn = 1 order by 1, 2;
"nulls last" is the default sort order; I just put that for clarity.
Published by: stew Ashton on October 18, 2012 12:58
-
Is there a another way to resize the browser to share window by dragging the corner?
My Firefox window is slightly larger than the size of my desktop, so I put the hand on the corner down to resize the window horizontally. Y at - it a shortcut keyboard or another way to do this?
- You can resize the window by dragging the cursor of the mouse on any part of the edge of the window, not just the lower corner.
- Press Alt + space to display the window menu, press S to select the size option, use the arrow keys to resize the window and then Enter to confirm.
- Click expand in the upper right of the window.
- Click on the title bar and drag the window to the left, up, or the right edge of the desktop. For more information, see Aero snap.
- Move the cursor to the upper edge or bottom of the window, until the cursor turns into a two-headed arrow, and then double-click the left button of the mouse.
-
Hello
How to write the sql query
I have three type of table as
1 table emp
EMP_ID FIRST_NAME DEPT_ID
---------- -------------------- ----------
1 kumar 10
2 sam 20
3 30 damu
2 table dept
EMP_ID SALE_ID DEPT_ID
---------- ---------- ----------
1 101 10
2 102 20
3 103 30
3. table sale
EMP_ID SALE_ID SALE_AMT
---------- ---------- ----------
1 101 7
2 102 8
3 103 9
I want the result as
EMP_ID DEPT_ID SALE_AMT
------- --------- - --------
1 10 7
Thank you
Are you looking for this?
SELECT T1. EMP_ID,
T1. DEPT_ID,
W3M SALE_AMT
FROM EMP T1,
SALE T3
WHERE T1. EMP_ID = T3. EMP_ID;
OUTPUT:
EMP_ID DEPT_ID SALE_AMT
------- ---------- ----------
1 10 7
2 20 8
3 30 9
If this is not the case, after the actual output, you need. Because that gives you the amount of sales deptwise
-
Need help to write the query to extract the value of the previous row - Lag not help
HelloI created follwing table.
Create table test
(number of fi,
number of fo_fv
number of jup_fv
action varchar2 (10)
);
insert into TEST(1,1,1,'LOAD');
Insert into TEST (2, NULL, 2, "ROLL");
insert into TEST(3,,3,'ROLL');
insert into TEST(4,,4,ROLL);
insert into TEST (5,2,5,LOAD);
I want the result of the query as below:
FI FO_FV JUP_FV ACTION
-------------------------------------------------------------------
1 1 1 LOAD
2 1 2 ROLL
3 1 3 ROLL
4 1 4 ROLL
5 2 5 LOAD
Help, please.
Thank you!
SQL > select fi
2, max (fo_fv) on fo_fv (fi control)
3, jup_fv
4, action
5 of the test;FI FO_FV JUP_FV ACTION
---------- ---------- ---------- ----------
1 1 1 LOAD
ROLL OF 2 1 2
3 1 3 ROLL
4 1 4 ROLL
5 2 5 LOADOR
SQL > select *.
2 test
model 3
Dimension 4 by (fi)
5 measures (fo_fv, jup_fv, action)
6 rules
7 (
8 fo_fv [any] = case when fo_fv [cv ()] is null
9. can fo_fv [cv () - 1]
10 fo_fv [cv () else]
11 end
(12);FI FO_FV JUP_FV ACTION
---------- ---------- ---------- ----------
1 1 1 LOAD
ROLL OF 2 1 2
3 1 3 ROLL
4 1 4 ROLL
5 2 5 LOAD -
Another way to get the trial version? Downloads/speed of satellite are terrible!
Unfortunately, we're on Hughes.net and so that we can not download something that takes more than a few minutes because of their speed and bandwidth restrictions.
Is there a way to get the software to test through paper, CD or DVD? If there is not, then this whole process to this point has been a waste of time. Thank you...
You can contact customer service at the 8008336687 and ask for a CD / DVD for the software you bought to be shipped to you.
Maybe you are looking for
-
my bit defender can't seem to get rid of malware called OSX/InstallMiez need help
I have a Mac with OSX EL Capitan my bit defender 2014 I can't seem to get rid of malware called OSX/InstallMiez. Need help thanks in advance
-
Satellite L650 - 19 p - upgrade graphics card question
First to say hello to everyone ;) OK my question is:I have a Sat L650 - 19 p and I upgraded my ram to 8 GB.It is now possible to upgrade my graphics chip. I have the ati mobility radeon HD 5145 graphics cardI hope that some out there may help much th
-
I rec would be a msg telling me my FB acct was to be terminated. I went to all the FB help pages and couldn't find any place or anyone to answer my question of "why?" There is no confirmation for the cancellation email or anything else. I ran my McAf
-
Lync 2010 - is lack of submit button?
Hello I am using Lync 2010. It is one of the best application for communication. However, I use the mouse more keyboard to copy paste the content. that works very well, my question is sent the message I have to press the ENTER key on the keyboard. so
-
Define 'My task list' as a home page for a specific user
HelloAs long as administrator, I can not put the default homepage to "My list" for a specific user (at the moment of the user's default home page is a blank page and must be 3 steps to get to "My to-do list").I know how to change the home page in the