order by pulling on the cost of the query by 4 times

I have the following query:

Select company_id, company_name, total_depts,

TO_CHAR (case when total_depts = 0 then 0 otherwise (accnt_count/total_depts * 100) end, '990,99'). ' %' as accnt_count_percent.

TO_CHAR (case when total_depts = 0 then 0 otherwise (lib_count/total_depts * 100) end, '990,99'). ' %' as lib_count_percent.

TO_CHAR (case when total_depts = 0 then 0 otherwise (house_count/total_depts * 100) end, '990,99'). ' %' as house_count_percent.

TO_CHAR (case when total_depts = 0 then 0 otherwise (fin_count/total_depts * 100) end, '990,99'). ' %' as fin_count_percent.

"to_char (case when total_depts = 0 then 0 otherwise (total_depts - (accnt_count + lib_count + house_count + fin_count)) / total_depts * 100 end, ' 990.99' ') | ' %' as total_success

, total_deptments, less, More, version_id_count as total_users

Of

(

Select dpt_inst.company_id as company_id,

dpt_inst.company_name as company_name,

Count (*) as total_depts,

sum (case when (upper (err.problem) = upper ('accnt_count')) then 1 else 0 end) as accnt_count,

sum (case when (upper (err.problem) = upper ('lib_count')) then 1 else 0 end) as lib_count,

sum (case when (upper (err.problem) = upper ('fin_count')) then 1 else 0 end) as fin_count,

sum (case when (upper (err.problem) = upper ('house_count')) then 1 else 0 end) as house_count

of education.dept_and_inst_view dpt_inst

Err education.dept_error left join

On dpt_inst.dept_code = err.code

where dpt_inst.part_id in ('A', 'L', ')

and dpt_inst.company_id not in ('L100901', 'L20009')

Dpt_inst.company_id group, dpt_inst.company_name

) inst_dept_q

inner join

(

Select company_id, count of total_deptments (*)

of education.departments ed_acc

Join internal cv.cv_customers cv_usr

On ed_acc.cust_id = cv_usr.id

join in-house cv.customer_enrollment cvce

On cv_usr.subs_id = cvce.subs_id

where ed_acc.status = 'important'

and company_id not in ('L100901', 'L20009')

Company_id group

) dept_customers_q on inst_dept_q.company_id = dept_customers_q.company_id

inner join

(

Select

COMPANY_ID,

sum (case when version_id = 1 then 1 else 0 end) as less.

sum (case when version_id = 2 then 1 else 0 end) as More.

Count (*) version_id_count

de)

Select distinct (cvce.subs_id), ed_acc.company_id, cvce.version_id

of education.departments ed_acc

Join internal cv.cv_customers cv_usr

On ed_acc.cust_id = cv_usr.id

join in-house cv.customer_enrollment cvce

On cv_usr.subs_id = cvce.subs_id

If not ed_acc.company_id ("L100901", "L20009")

and ed_acc.status = 'important'

) company_id group

) inst_cust_cnt_q on dept_customers_q.company_id = inst_cust_cnt_q.company_id

order by 3 desc

The Decree of this query is the price increase by 4 times.

I wan to see the Plan to explain SQL Developer but when I paste in this window it is all unreadable (undergoes the hanging indent). How to put the plan to explain it?

The problem with sorting, is that it is based on the COUNT (*) FUNCTION total_depts. Since it is an aggregate, value

You can't have an index based on this value. Therefore, the cost will be higher for sorting on this column. You can

move the first part of the clause to a with clause that could help. It's certainly worth a try.

You should also allow each part of the query make each less expensive part, so all of the query will be cheaper to run.

ORACLE-BASE - Clause: subquery factoring

Tags: Database

Similar Questions

  • Need help to understand the query result

    Hi gurus

    I was reading one of the question here in this forum and its link is below:

    Query required for scenario

    I had some confusion related to this code and don't understand the logic of the out put, see query below:

    Query

    with sub_services as

    (

    Select su_seq 12323, 'HLR1' so_id, 1 seq Union double all the

    Select su_seq 12323, "HLR2' so_id, seq 2 Union double all the

    Select su_seq 12323, "A09" so_id, seq 3 of all the double union

    Select su_seq 12333, "MO1" so_id, seq 4 Union double all the

    Select su_seq 12333, "MO2' so_id, seq 5 Union double all the

    Select su_seq 12333, "A09" so_id, 6 seq in union double all the

    Select su_seq 12333, 'M0CR' so_id, seq 7 Union double all the

    Select su_seq 12999, "LOL1' so_id, seq 8 Union double all the

    Select su_seq 12999, "LOL2' so_id, seq 9 double

    )

    Select *.

    of sub_services b

    where exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    )

    order by 2;

    The query result

    12323 A09 3

    12333 6 A09

    12323 HLR1 1

    12323 HLR2 2

    12333 M0CR 7

    12333 4 MO1

    12333 5 MO2

    According to my understanding, the above query should return records in red only because of her is below command

    It exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    but don't know why he's back 7 files, can someone help me understand the result...

    It is query is functionally identical to the PL/SQL block, but much more effective.

    declare

    number of l_res;

    Start

    for line (select *)

    sub_services) loop

    Start

    Select 1 from l_res

    of sub_services

    where su_seq = row.su_seq and

    so_id = "A09" and

    rownum = 1;

    exception when

    NO_DATA_FOUND then

    null;

    end;

    end loop;

    end;

    Essentially every row in the outer query are tested against him exists query.  Given the correlation between two requests is based only on su_seq each line with a su_seq value returned by him is returned in the output.

    Another way to think he uses instead a join condition.  This query is equivalent to the query to exist

    Select the main

    of main sub_services

    Join select (separate su_seq

    of sub_services

    where so_id = "A09") cond

    We main.su_seq = cond.su_seq;

    John

  • How to automatically add the line number in the query

    Hello

    Can anyone please glimpses me the path to achieve this?

    I want to write a query that will search the record based on the line number in the result set.
    Let's say I have 500 rows in the employee table, but I want to put a condition on request where will see record only between 100 to 200 line number in the result set.



    Thank you
    Madam.

    It is wrong to say that look for the lines between ROWNUM 100 to 200 unless you define a column of lines must be ordered.

    Oracle does not guarantee that the lines will be be returned in the same order if you run the query several times without defining the ORDER BY clause.

    So first decide on what columns you want to order the files and then use the rownum to assign the line number and then get the records you want.

    something like that

    SQL>SELECT *
      2    FROM ( SELECT e.*
      3                 ,ROW_NUMBER() OVER (ORDER BY sal)  row_num
      4             FROM emp  e
      5         )
      6   WHERE row_num BETWEEN 5 AND 10;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO    ROW_NUM
    ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- ----------
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30          5
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    10          6
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30          7
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30          8
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10          9
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30         10
    
    6 rows selected.
    
    SQL>
    

    Concerning
    Arun

  • Cfquery results sorted by column being added after the query to execute

    I have a function that returns a Recordset, adds a column using QueryAddColumn goes through the recordset and rearranges the elements using QuerySetCell.

    Once the function is executed, the output displays the elements in their natural order and lists the new order as a table column.

    How I can make the equivalent of ORDER BY myNewColumn because the query has already been run.

    My code is attached.

    Thank you
    Paul

    Never mind, sussed it!

    Add the following to query of query:

  • Find my friends pulled from the app store

    So yesterday, there was an update pushed to find my friends and Podcasts. So when I try to update it says "my friends is available on IOS." To get to find my friends, get on the App Store on your iOS device. "(it's on my iTunes on my mac).

    So to speak of Apple Support and they say find them my friends and Podcasts was pulled from the App store inexplicably?

    Anyone know what is happening?

    We are not likely to know more about it than an Apple. A proposal, perhaps apps are updated.

  • Is it possible to change the order of items in the context menu of 'link' (I want to 'open in a new window... ("Be the first)?

    I did an upgrade FF v3.6.xx to v17.0.x and found that the order of items in the context menu 'Link' is not the same.
    v3.6 menu looks as follows: 1. "Open link in a new window", 2. "Open link in a new tab,"
    order of the items in menu v17.0 is 1 reverse. "Open link in a new tab", 2. " Open the link in a new window. "
    Position of all the other elements are uninteresting to me.
    How to exchange it two points higher in the contextual menu "link"?

    The two ways are useful:

    "Drag-n-drop" in the Editor window works.

    For my Windows XP path looks like: "C:\Documents and Settings\%account%\Application Data\Mozilla\Firefox\Profiles\%random_name%\chrome\userChrome.css".

  • Firefox pulls in the fake site on a name field on my PC, but the right pair on my laptop. Delete history - cookies, temporary files, etc. has not erased the problem.

    I changed the forwarding to one of my areas address a week or two ago. When I go on this site on my laptop (on Firefox), it pulls to the right address. On my PC, the old site is one that shot of Firefox in again, when I go on Internet Explorer on my PC the correct site is one that appears. It is apparently a problem with the version of Firefox on my PC that seems to me that Firefox is an absolute pain in the neck by flooding users with constant requests to update later. Very annoying!

    Reload Web pages, and ignore the cache.

    • Hold SHIFT and click reload.
    • Press 'Ctrl + F5' or 'Ctrl + Shift + R' (Windows, Linux)
    • Press 'Cmd + Shift + R' (MAC)

    Clear the cache and cookies from sites that cause problems.

    "Clear the Cache":

    • Tools > Options > advanced > network > storage (Cache) offline: 'clear now '.

    'Delete Cookies' sites causing problems:

    • Tools > Options > privacy > Cookies: "show the Cookies".
  • A good day! Make an order for the iPhone to your site, the provision of the code ' reservation number is: B2 * Q0A "many skills information. It is impossible to confirm the order. What is the problem?

    A good day!

    Make an order for the iPhone to your site, the provision of the code ' reservation number is: B2 * Q0A "many skills information. It is impossible to confirm the order. What is the problem?

    It is a support so nobody user forum here can help you. Maybe if you release with Apple itself.

    http://www.Apple.com/contact/

    There are links here to the online store.

  • How to order new parts to the A60?

    I was wondering if anyone knew where you can order new parts to the A60. At the moment my A60 is in bits... My dog stood on the HQ at the back and broken the internal pin connector.

    I removed the part by removing the soldering of the component that was relatively easy to do... but now I have to find the new part which is not so easy. The part is relatively simple, so I imagine quite cheap so I thought fit it me and save the repair bill which I couldn't justify paying on such an old laptop. I searched this site to find an email support but can't seem to find one anywhere.
    All ideas are welcome.
    Thank you.
    Snoot.

    Hello

    You can contact the authorized Toshiba Service partner and from here you can order all the parts that are compatible and supported for your laptop.
    On this site you will find the ASP that is responsible for your country.

    http://EU.computers.Toshiba-Europe.com/cgi-bin/ToshibaCSG/generic_content.jsp?service=EU&ID=ASP_SUPPORT

    Good bye

  • Photo constantly order of photos in a slideshow changes no matter how many times the movements of the user the photo back to the good look at an order. Example: Bathroom Plans eventually grouped with pictures of kitchen! I have found no way to stop this o

    Apple Photo 1.3 serious problems - how can I SOLVE all these problems?

    (1) breaks down without rhyme or reason no matter where I am in the workflow.

    (2) pictures will not be Shut Down Every Time, even after several days of waiting.

    (3) aPhoto frequently badly chooses picture in the EDIT picture option, I get a picture different than the one I clicked on which is on a 100 pictures in a row.

    (4) picture constantly order of photos in a slideshow changes no matter how many times the movements of the end user the photo back to the good look at an order. Example: Bathroom Plans eventually grouped with pictures of kitchen! I have found no way to stop this weird behavior! Is there a way to stop this? If I drag the photo again some 7 additional photos in the slide show, after a minute or less, he appears again to where it was it not. !@#$%$#

    (5) If you make any CHANGES to a photo, it often changes the appearance of your complete slideshow of this picture with impatience. So you lose all this not work fix your configuration of the slide show. Even changing the order of photos once more that I had put back where they should be. !@#$$#@

    (6) photo identifies often shades of lamps and long door handles as the faces of the people.

    (7) photo made bad decisions when it comes to brightness, contrast and colors effortlessly around other than to use other software, where as with iPhoto there was a lot of workarounds. I could continue, but will save one who might be reading of this.

    I am up to date on all updates for my Mac. If anyone have REAL answers so please spilling the beans, but according to me, it's the only truth is that Apple has rolled out a product inferrer to replace an exceptional product, called iPhoto, which does not work on my new iMac computer 5K of 27 ".   If I knew what I would have chosen another computer that I use iPhoto to prepare more of fifty to sixty thousand photos in a given year and I use iPhoto to make hundreds of slideshows from it.  Are there plugins for Photo 1.3? I ask because I see where there could be Add-ons, but I can't find.

    Apple has taken a serious decision by turning his back to iPhoto and tens of millions of loyal users.

    Thanks in advance to anyone brave enough to tackle this job.

    James

    First, back up your library of Photos and hold down the command and option keys while launching Photos - repair your database - you have a corrupted database

    LN

  • Load pull to the output corresponding to network design

    Hello

    I tried to design the entrance and exit of the matching networks for a power amplifier using the traction load script and the elements of HBTUNER2. According to the contours of traction load, the optimal point impedance is 15.37 - j21.99 (I chose a compromise between EAP, DCRF and PGain). Now my question is when I use the wizard iMatch to convert this to a 50 ohm termination impedance, use 15.37 - j21.99 or the conjugate 15.37 + j21.99? Otherwise, what is the reason? I always thought that load a script pull gave the impedance looking into the port of the active peripheral side. How did the point impedance suggested by loading a script pull to interpret?

    Thank you much in advance.


  • Order Java button in the Web browser - PLEASE HELP!

    Hello

    I just started using LabView and I read almost every post, but I could not find what I'm looking for. Also, if I run the Vi (picture_2) I get in innerHTML indicator HTML structure for my example:





    Homepage | Onclick = "ExecuteAction('a.wsdl',1) START " href = "#" > START | "  
    Version: 2,000
    Build: 20110110

    Here's where I can't find a way to press the START button with function ActiveX. I know how to simulate the position of the mouse and click mouse but I need the ActiveX function only.

    I found this function Onclick in ActiveX, but I can't make it work (do I need to write in (?) and if I need of more data in order to properly control the function.)

    Can anyone help me please with my DIF?

    Thank you

    Picture_1 - example of web browser page

    Picture_2 - source code


  • Please give me solution for my computer always view your computer have persist order check and solve the problem every time when I open my computer.

    When I start my system the output display poster always your computer have Persist modula order check and solve the Problem.How to solve this problem

    Permanently?

    Hello


    What operating system is installed on the computer?
     
    Note: install the drivers on the manufacturer's Web site

    Hope this information helps.
  • Can I order a laptop on the address of the hotel?

    Can I order a laptop on the address of the hotel?
    And if I can pay cash to get the parcel?
    I don't have a GSM local phone network if you can take the international registration number when sending?

    Hello

    What is the model # computer?

    You try to buy the computer at the Sony Store United States?

    If so, contact team Sony store for detailed information:

    http://eSupport.Sony.com/us/Perl/support-info.pl?info_id=927#place_order_1-1

    You can also check the link above for the Sony navigation policy.

    However, you can also get the item directly from Sony in the United States through a friend or a family member who can order it and sent it to an address in the United States. Then, your friend or relative can send it to you.

    If my post answered your question, please mark it as an "accepted Solution".

  • HOW CAN I GET A HP LASERJET 4V IN ORDER TO PROPERLY USE THE OPERATING SYSTEM TO XP PRO AND USB USING A PARALLEL CABLE?

    HOW CAN I GET A HP LASERJET 4V IN ORDER TO PROPERLY USE THE OPERATING SYSTEM TO XP PRO AND USB USING A PARALLEL CABLE?

    The printer works at all with this cable?

    The cable has recognized and installed by Windows XP when you logged on to the computer?

    If the cable has been recognized, what steps have you taken to install the printer then (be as accurate and complete as possible)?

    You get an error message?  If so, please provide, without paraphrasing.

    This printer has already been installed on this computer?  If so, with what type of connection?

    And especially, what is the brand and model of the USB to parallel cable?  Many of them do not work.  See, for example, the comments here , which suggests that 25% of the units will simply not work.  This seems to be one of these products you should buy at a local store, rather than on the Internet, then you can continue taking it back until you get a working unit.

Maybe you are looking for