Need Help in tuning of the query
Hi all,
Can any body help me how we can rewrite this query in
optimized way.
SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
FROM A,B
WHERE A.C1 IN (
SELECT COLUMN_1 FROM(
(SELECT A.C1 AS COLUMN_1,
COUNT(C1) AS COUNT,
RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
FROM A, B, C
WHERE A.C1 = B.C3
AND B.C2 = C.C1
AND <other conditions>
GROUP BY A.C1)
WHERE RANK <= 10)
AND A.C1 = B.C3
AND <other conditions>
ORDER BY A.C1
I am using <other conditions> are same in outer query and inner query also.
Thanks in Advance,
Hi,
Yes exactly I am looking TOP-10 results the query is like this
SELECT A.C1 AS COLUMN_1, B.C2 AS COLUMN_2
FROM A,B
WHERE B.C2 IN (
SELECT COLUMN_1 FROM(
(SELECT B.C2 AS COLUMN_1,
COUNT(A.C1) AS COUNT,
RANK() OVER (ORDER BY COUNT(C1) DESC) AS RANK
FROM A, B, C
WHERE A.C1 = B.C3
AND B.C2 = C.C1
AND <other conditions>
GROUP BY B.C2)
WHERE RANK <= 10)
AND A.C1 = B.C3
AND <other conditions>
ORDER BY B.C2
Thanks
Similar Messages
-
Need help to re-format the query
Hi All,
Could any one please help me to rewrite this query or explain me how to do it as it is taking 20 mins to execute....
SELECT
AC.ACC_NO||DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.PAYMENT_SET
FROM
MIF LMI2 WHERE LMI2.MID =
(SELECT CHILDMID FROM MFAMILY WHERE PARENTMID= MI.MID AND RELATION='ROF')),MI.PAYMENT_SET)||
DECODE(MI.MSG_CLASS,'ROF', (SELECT LMI2.SERVICE FROM MIF LMI2 WHERE LMI2.MID = (SELECT CHILDMID FROM
MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),MI.SERVICE) HASH_KEY,
MI.MID ,
DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.PAYMENT_SET FROM MIF LMI2
WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
RELATION='ROF')),MI.PAYMENT_SET) PAYMENT_SET,
MI.AMOUNT,
NVL(DECODE(MI.MSG_CLASS,'ROF',MI.CRAMOUNT, MI.DBAMOUNT) ,0) AMT,
AC.ACC_NO,
DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.BATCH_COMPANY_CD FROM MIF LMI2 WHERE
LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
RELATION='ROF')),MI.BATCH_COMPANY_CD) BATCHCOMP,
AC.ACC_ALIAS, NVL(AC.IBAN,
NVL(AC.ACC_ALIAS,AC.ACC_NO)) IBAN_ACCNO,
AC.CURRENCY , AC.ACCOUNTNAME ,
CASE
WHEN (SIGN(MI.PROCESS_DT - TO_DATE(:B2 ,'YYYYMMDD'))) = '1'
THEN 'F'
ELSE 'C' END FUTURE_IND,
(CASE
WHEN (MI.MSG_STATUS = 'CANCELED' OR MI.STATBFHELD = 'CANCELED')
THEN 'C'
WHEN MI.BATCH_PAYMENT_TP = 'RMTRT'
THEN 'R'
WHEN (MI.REJECT_RETURN='REJT' OR MI.MSG_CLASS = 'ROF' OR MI.MSG_STATUS = 'REJECTED')
THEN 'A'
WHEN (MI.REJECT_RETURN='RETN' OR (MI.BATCH_PAYMENT_TP='RTACH' AND MSG_CLASS='ROF'))
THEN 'B'
WHEN MI.MSG_STATUS='FORWARD_PROCESSING'
THEN 'F'
WHEN (MI.MSG_STATUS NOT IN ('COMPLETE','CANCELED','REJECTED') OR (MI.MSG_STATUS='AGED' AND
MI.STATBFHELD NOT IN ('COMPLETE','CANCELED','REJECTED')) )
THEN 'U'
WHEN MI.PROCESS_DT = TO_DATE(:B2 ,'YYYYMMDD')
THEN 'P' END)
PAY_STATUS,
MT.DB_FEE_ACCOUNT_CCY,
(SELECT MESSAGEFREETEXT.CONTENTS
FROM
MESSAGEFREETEXT
WHERE
FIELDNAME ='MANDATEREFERENCE'
AND MESSAGEFREETEXT.MID= MI.MID) MANDREF,
(SELECT MESSAGEFREETEXT.CONTENTS
FROM MESSAGEFREETEXT
WHERE FIELDNAME ='DIRECT_DEBIT_REFERENCE' AND MESSAGEFREETEXT.MID=MI.MID) DDREF,
MT.CUSTOMER_BATCH_REFERENCE LOCINFO,
(SELECT MESSAGEFREETEXT.CONTENTS
FROM MESSAGEFREETEXT WHERE FIELDNAME = 'SECOND_PARTY_ID' AND MESSAGEFREETEXT.MID=MI.MID) SECPRTYINF,
(SELECT MESSAGEFREETEXT.CONTENTS
FROM MESSAGEFREETEXT WHERE FIELDNAME = 'HUB_PAY_PROD_TYP' AND MESSAGEFREETEXT.MID=MI.MID) PAYPRODTYP,
DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.CHANNEL_REFERENCE FROM MIF LMI2
WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
RELATION='ROF')),MI.CHANNEL_REFERENCE) CHNREF,
(SELECT MESSAGEFREETEXT.CONTENTS
FROM MESSAGEFREETEXT
WHERE FIELDNAME = 'CHN_BATCH_REF' AND MESSAGEFREETEXT.MID=MI.MID) CHNBATREF,
TO_CHAR(DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.VALUE_DATE FROM MIF LMI2
WHERE LMI2.MID = (SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND
RELATION='ROF')),MI.VALUE_DATE),'DD/MM/YYYY') VALUEDT,
DECODE(MI.MSG_CLASS,'ROF',(SELECT LMI2.ORIG_REFERENCE FROM MIF LMI2 WHERE LMI2.MID = (SELECT
CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),
MI.ORIG_REFERENCE) ORIGREF,
CASE
WHEN (MI.OFFICE <> MI.ORIG_OFFICE)
THEN MT.DR_SIDE_RATE_AM
ELSE
CASE
WHEN MI.DBCURRENCY = MI.CRCURRENCY
THEN
CASE
WHEN MI.CRCURRENCY = :B4
THEN MT.DR_RATE ELSE MT.CR_RATE
END
ELSE
CASE
WHEN MI.CRCURRENCY = :B4
THEN MT.DR_RATE ELSE MT.CR_RATE
END
END
END EXCHRT,
MT.BBK_ADDR1,
MT.BBK_ADDR2,
MT.BBK_ADDR3 ,
MT.BBK ,
MT.BNF_ADDR1,
MT.BNF_ADDR2,
MT.BNF_ADDR3,
MT.BNF_ADDR4 ,
MT.BNF ,
DECODE(MT.BNF_IDCODE,'AC',MT.BNF_ID,' ') ORGBNFID,
DECODE(NVL(MI.ORIG_INSTRUCT_AMOUNT,0),0, MI.ORIG_AMOUNT) ORGINSTAMT,
NVL(TRIM(MI.ORIG_INSTRUCT_CURRENCY), MI.ORIG_CURRENCY) ORGINSTCUR,
CASE
WHEN MOP LIKE 'DRFT%'
THEN 'DD'
WHEN MOP LIKE 'CHEQ%'
THEN 'CO'
WHEN MOP LIKE 'SWIFT'
THEN 'TT'
WHEN MOP LIKE 'DDP%'
THEN 'T'
WHEN MOP LIKE 'BOOK'
THEN 'T' ELSE 'LP'
END PYMTTP,
MT.OBI ,
TO_CHAR(MI.PROCESS_DT,'YYYYMMDD') PROCESSDT,
MI.REFERENCE,
MT.BBK_BIC,
MT.BBK_IDCODE,
DECODE(MT.BBK_IDCODE,'AC',' ',SUBSTR(MT.BBK_ID,1,12)) BBKID,
MI.LOCAL_REF,
MI.CURRENCY INDCURR,
MI.MSG_STATUS,
MI.PK_BATCH_SUBSET,
TO_CHAR(SBBATCH.PROCESS_DT,'YYYYMMDD') SBPROCESSDT,
DECODE(MI.MSG_CLASS,'ROF',MI.CRCURRENCY, MI.DBCURRENCY) DBCURR,
MI.ORIG_REFERENCE ORIGREFRET
FROM
MIF MI,
MTF1000 MT,
ACCOUNTS AC,
( SELECT
MF.PK_BATCH_SUBSET,
MF.PROCESS_DT,
MTF.ORG_ID,
MTF.MP_CR_ACC,
MTF.CR_ACC_NO
FROM
MIF MF,
MTF1000
MTF
WHERE
((MSG_STATUS IN ('COMPLETE','CANCELED','REJECTED')) OR
(MSG_STATUS = 'AGED' AND STATBFHELD IN ('COMPLETE','CANCELED','REJECTED')))
AND
BATCH_MSG_TP = 'S' AND MF.MID = MTF.MID )
SBBATCH
WHERE
MI.MSG_TYPE = :B3
AND MI.PROCESS_DT = TO_DATE(:B2 ,'YYYYMMDD')
AND MI.BATCH_MSG_TP = 'I'
AND DECODE(MI.MSG_CLASS,'ROF',
(SELECT LMI2.SERVICE FROM MIF LMI2 WHERE LMI2.MID =
(SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')),MI.SERVICE)
IN ('NET','HCN','BIB','LST','MRI')
AND MI.PK_BATCH_EXCH IN (SELECT PK_BATCH_EXCH FROM BATCH_EXCH)
AND MI.MID = MT.MID
AND SBBATCH.PK_BATCH_SUBSET = MI.PK_BATCH_SUBSET
AND TRIM(DECODE(MI.MSG_CLASS,'ROF',MT.CR_ACC_NO, NVL(MT.ORG_ID,NVL(MT.MP_DB_ACC,MT.ACC_NO))) )=AC.ACC_NO
AND AC.OFFICE = :B1
ORDER BY HASH_KEY,PAY_STATUSHi,
please try this.
The first decode or at least part of it repeats at least 7 times.
DECODE(MI.MSG_CLASS,'ROF',
(SELECT LMI2.PAYMENT_SET
FROM MIF LMI2 WHERE LMI2.MID =
(SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')
),MI.PAYMENT_SET
||
DECODE(MI.MSG_CLASS,'ROF',
(SELECT LMI2.SERVICE
FROM MIF LMI2 WHERE LMI2.MID =
(SELECT CHILDMID FROM MFAMILY WHERE PARENTMID=MI.MID AND RELATION='ROF')
),MI.SERVICE) HASH_KEY,
is similar to this
select mif.* from mif, mfamily where mif.mid=mfamily.childmid
and relation = 'ROF' and msg_class='ROF'
insert it as an inline view and add a conditition
from ...
(select mif.* from mif, mfamily where mif.mid=mfamily.childmid
and relation = 'ROF' and msg_class='ROF') rof
Where ...
and mi.mid=Rof.mid (+)...
and your code above would look like
nvl(rof.payment_set,mi.payment_set) || nvl(rof.service,mi.service) HASH_KEY,
nvl(rof.payment_set,mi.payment_set) PAYMENT_SET
replace all the same decode above with corresponding nvl(...)Hope this helps. -
Need help in rewriting a sql query
Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
Any help in this regard will be highly appreciated.If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
You might look into thrid party tools like Quest- SQL Navigator and TOAD.
But I don't advise this based on the following:
Re: Oracle Third Party Tools and Oracle Database
Oracle have enough tools of its own to satisfy the various needs.
Adith -
I actually need help but cannot find the answer.
Please.......Lately when open a new tab it does not open with a blank page. I don't want to set my homepage as blank as when I first open Firefox, it automatically loads my hotmail page. But then if I open other pages I don't get a blank page. Help, please?
Thank you.
''[Personal information removed by moderator. Please read [[Forum and chat rules and guidelines]], thanks.]''hello, please refer to [[New Tab Page – show, hide and customize top sites]] in order to switch the feature off.
-
I buy for mac app but not for the iPad, so how do I reinstall a program that has already purchased? I need help because I bought the imovie'11 but when he opened it only brought 8 movie trailer templates instead of the 15 it says on the program. How do I solve this problem? Once paid for a program incomplete. I also liked that the AppStore itself had a button to reinstall programs already bought, because it is very hard to understand how to do this in the store, only option is to install and hide purchase, and how do I reinstall, attention'm talking about reinstalling a computer mac, not an ipad or iphone.
Thank you.Prodesigntools.com , go ahead and download the software from there and use your serial number to serialize it.
-
I get the following message when trying to open an .avi downloaded from my video cam, need help, can not find the codec, thank you. This is for Quicktime Player.
"The document “IMAG0026.AVI” could not be opened. A required codec isn't available."Try Perian.
http://perian.org/ -
Need help in PO Approval Group Query
Hi,
I need a Query which will list of users that has the Approval Group “BUYER” and “BUYER_DEMO” assigned to them.
It will be needful if anyone provides me the Query
Thanks and RegardsHi
Try this.
SELECT PAPF.employee_number
,PAPF.full_name
FROM po_control_groups_all PCGA
,po_position_controls_all PPCA
,per_all_assignments_f PAAF
,per_all_people_f PAPF
WHERE PCGA.control_group_name IN ('BUYER','BUYER_DEMO')
AND PCGA.control_group_id = PPCA.control_group_id
AND PPCA.position_id = PAAF.position_id
AND PAAF.person_id = PAPF.person_id
Thanks and Regards,
JD -
I need help in finding all the new fontsin iPad 2 using iOS 5
I need help in finding all the new fonts in ipad 2 using ios 5
You cannot change the email font. You can make it bold, italics and underline the type, but Helvetica is your only choice in the mail app.
In the notes app you have 3 choice Noteworthy, Helvetica and Marker Felt. The font can be changed in Settings>Notes>Font.
You can only use fonts that are built into the app that you are using at the time. You cannot pick and choose fonts from a list of all of the fonts that may be on the iPad but only from the list of fonts that the app allows. -
Yosemite made my MacBook Pro so slow !! Need help ? what is the solution?
Yosemite made my MacBook Pro so slow !! Need help ? what is the solution?
I've ran a benchmark on my Mac (iMac early 2009). Performance of Yosemite in general was about the same as Mavericks. But that can be different on other Mac's of course. Safari is mostly a bit slower. It's recommended you clean your old internet-caches and then restart Safari. (you can use a little app called CCleaner to do that). That might make a difference. Speed-issues are usually solved in the first and second update of OS X.
-
I need help! I updated the new 6.1.3 last night. Since that time my phone will not charge. The phone is plugged in and shows as charging but the battery still drains. What can I do? I need help!
Restore iPhone with iTunes on your computer.
-
I need help quick please sold the iPod and before handing it over wanted to clear out info so pushed erase now there is only a plug icon for iTunes but it won't now recognize my computer what can I do??
Try
iOS: Device not recognized in iTunes for Windows
or
iPhone, iPad, iPod touch: Device not recognized in iTunes for Mac OS X -
I had to put my computer by together without migration or time machine I NEED help with order of the files?
Hi, where are these other files exactly?
-
Need help with passcode using the "Remote" app
Hello and thanks in advance. I can't find a place on iTunes to enter the passcode from the Remote app.
PLEASE READ!!!
I have a HP Pavilion - Windows XP
I need help as well with the passcode. I went to Networking and Sharing center and clicked customize and changed the name to NetGear because that is what it says next to my WiFi on my iPhone but with my iPhone under Settings it says WiFi NETGEAR > but when I click on it, it says choose a Network. Is NETGEAR a network? How do I find or change to a Network? is this the problem? -
I Need help!!! The card I used when I first set up my account I lost it so now I can't download any music cause it's wanting a number off that card and I don't have it anymoe... Someone tell me what to do please???
Add another good card and delete the old one, Yu can also purchase and redeem an iTunes gift card and hthen delee the bad credit card. Yu need a valid payment method for update as well even purchasing free apps if the account was set up with a credit card.
-
I need help! I have the iphone 5 and I want to buy the whastsaap, but it turns out I get to put the answers up and answer the questions but I do not remember. Someone could help me? Help! Thank you!
Security questions:
https://discussions.apple.com/thread/4533485?tstart=0
Maybe you are looking for
-
Problem in creating purchase order document
Hi, I created a new business document : Purchase request that once it is validated we can copy it to Puchase order. when i save the purchase order doc and then launch the creation of the purchase order the operation succed. But when i try to copy an
-
I bought an ipad2 bought scrabble app worked for 1day and now app won't work????
-
I know, I think so, this is a Perian issue, but there's always good people here with wonderful ideas to beat strange problems. Since Perian 1.1 it's on my Mac I can't see FLV files, Quictime jumps onece, then it's dead, crashed. Any clue? At Perian f
-
CSCul04610 - ASA showing SSH internal error in device console
I think I have this bug on a non generation X firewall, a 5520 running 8.4(3)9. I've been trrying to find a workaround without wasting a TAC case. Could you test this model and version? And then widen the parameters of the bug?
-
Boot Camp access to mac partition
Hi. I have Windows 7 Pro on Boot Camp, which is also on a server 2003 domain. When the windows network users log in, they can access the Mac Partition. How do I prevent this from happening? I know it is read only, but I prefer to have them access onl