Force the order in which WHERE clauses are applied?

I need to make sure that one where clause filtering is applied before the other. How do I do that?
Several of my where clauses are below.
I need to make sure than the where clause in bold is applied before several where clauses on the bottom. Otherwise, I get error: division by 0.
where ...
and a.surveydate = (select max(surveydate) from survey
where id = a.id
and surveydate < b.surveydate
and b.surveydate between TO_DATE('&lowdate','DD-MON-YYYY')
and TO_DATE('&highdate','DD-MON-YYYY')
and (
( abs( (b.totvacant/totunits - a.totvacant/totunits) /
(b.surveydate - a.surveydate) * 365 ) >= 0.00 )
or ( abs( (b.avgcost/ a.avgcost -1 ) /
(b.surveydate - a.surveydate) * 365 ) >= 0 )
or ( abs( (b.free_rent - a.free_rent ) /
(b.surveydate - a.surveydate) * 365 ) >= 0 )
Thank you. I know very little about query optimization, but I have a sense that I need to use some kind of SQL hint.

Why not rewrite the where clause a bit to intercept »ORA-01476: divisor is equal to zero«?:
SELECT *
  FROM tab
WHERE a.surveydate =
          (SELECT MAX (surveydate)
             FROM survey
            WHERE ID = a.ID
              AND surveydate < b.surveydate
              AND b.surveydate BETWEEN TO_DATE ('&lowdate', 'DD-MON-YYYY')
                                   AND TO_DATE ('&highdate', 'DD-MON-YYYY')
              AND (   (ABS ((b.totvacant / totunits - a.totvacant / totunits
                            / NULLIF (b.surveydate - a.surveydate, 0) * 365
                           ) >= 0.00
                   OR (ABS ((b.avgcost / a.avgcost - 1)
                            / NULLIF (b.surveydate - a.surveydate, 0) * 365
                           ) >= 0
                   OR (ABS ((b.free_rent - a.free_rent)
                            / NULLIF (b.surveydate - a.surveydate, 0) * 365
                           ) >= 0
                  ))

Similar Messages

  • ADF: controlling the order in which VO records are inserted

    All,
    in an ADF BC project, we have some complex MD insert pages that add records to master and detail tables at the same time. The application sits on top of CDM RuleFrame, which exposes the datamodel as DB views with instead-of triggers and adds (Designer) a few nifty things like auto-populated PK fields. Sad enough, we can't use these auto-generated PKs as the 'refresh after insert' settings in an EO work with a RETURNING clause, which is not supported for instead-of triggers. This means we'll have to find the PK sequences ourselves from the EOs and populate these fields ourselves, before committing to the database. So far so good, but things go wrong when we want to insert master and detail at the same time. The PK and FK of the child record are already filled in at insert time (which is nice) but for some reason the child records get inserted before the parents, resulting in an error on the FK as the parent record does not yet exist (which is not nice).
    So, here's the question: is there a way to control the order in which new VO records are inserted ? On what is the default order based (maybe a little renaming could help us out to get the alphabet our way) ?
    We know defining the FKs as 'initially deferred' will make sure they are only checked at commit time, but our DBA prefers to not use that solution unless strictly necessary. (is there anything bad about deferred keys why we should believe him? ;o) )
    And additionally, is there a way around all this manual PK-fetching ? We've tried using the refresh(int refreshMode) method of EntityImpl, but it didn't seem to work.
    Many thanks in advance for your tips, suggestions and solutiosn !
    Best regards,
    Benjamin De Boe

    Benjamin,
    To handle the problem with the child/parent records being inserted in the wrong order - have a read of the Oracle ADF Developer's Guide for Forms/4GL developers, section 26.7. I use that technique with great success.
    John

  • JSTL Change the order in which children tags are processed

    Hi there,
    Is there any way one can manipulate the order in which tags are executed/processed within for example an iteration tag? I.e. let's say I have the following:
    <m:my_iterate_tag data="data">
      <dotag1>XX</dotag1>
      <dotag2>YY</dotag2>
    </m:my_iterate_tag/>The user can set as a preference in my application that they want <dotag2> to
    be displayed/executed first before <dotag1>, e.g. like in a column in a table. How can I change
    the order of these tags when I execute the <m:my_iterate_tag>? Do I do it in
    <m:my_iterate_tag> or is there another or better way? Please help.
    Thanks,
    Marius Botha

    Okay, lets start with getting the order in which to display columns... So you say:
    get the order of these columns from the db (e.g. client
    says 1=title, 2=number, don't display "type" column)Based on the DB, then, create a java.util.List that would have the column names in the order they want... (not real code...)
    ArrayList columnOrder = ["title", "number"]
    When you get to iter_tag:table.doStartBody, then create a java.util.HashMap (lets say) called tableColumnData.
    Then in the iter_tag:column tag, you would the value provided in the tag mapped to the property name as the key in the tableColumnData map:
    tableColumnData.put("number", <this iteration's number value>);
    tableColumnData.put("title", <the value returned from the g:href tag>);
    tableColumnData.put("type", <anything>);
    Then, in the iter_tag:table.doEndBody, you do a loop, getting the name of the column to display from the columnOrder list, and using that name to pull the value out of the tableColumnData map:
        for (int i = 0; i < columnOrder.size(); i++) {
            out.println("<td>" + tableColumnData.get(columnOrder.get(i)) + "</td>");
        }You would put the columnOrder in a scope where you won't have to relaod it all the time, like maybe the user's session. You would put the tableColumnDataMap to make sure it is unique to the table... either in the pageContext, or store it in the iter_tag and make a method where the nested tags can retrieve it.

  • Lion has changed the order in which Finder items are sorted in Icon View; Acc vs. Desc.  How can you change this order?

    The order in which items are sorted has changed in Lion and I can't figure out how, or if, it can be changed.  Previously in Snow Leopard if you sorted by 'Date' in Icon View, your icons would be arranged from oldest to newest.  The same was true for 'Kind' and all the order sort options.  In Kind my *.zip files were positioned last.
    Now in Lion, the order is reversed.  Newest and Zips on top... the accending vs. decnding order has been changed.  How can I change the sort order in Icon View?

    I managed to fix the reverse order issue by deleting the com.apple.finder.plist and com.apple.finder.plist.lockfile in the user library folder. I did have to use terminal to delete the files and then re-launch finder from the force quit window. Here are the step-by-step instructions:
    Hold down the option key while selecting the Go menu. Select Library.
    Navigate to the Preferences.
    Find the com.apple.finder.plist.lockfile and delete it.
    Open Terminal (Application/Utilites)
    In Terminal type in sudo rm (include a space after the rm and do not hit enter)
    Drag com.apple.finder.plist file to the terminal window. It will fill in the path to the file)
    Press return.
    Type in your password and hit return. (The cursor will not move when you type in your password)
    From the Apple menu, select force quit.
    Highlight finder and select re-launch.
    Be careful when using Terminal. There is no undo button and you can accidentally delete important files.
    I hope this helps.
    Henry

  • What determines the order in which phone numbers are displayed in address book/contacts on Mac and iPad/iPhone?

    I may have "Work, Home, Skype, Work Fax" (for example) order in Adress Book on my Mac, but there is no gurantee, apparently, that this order will be preserved across entries on my iPad and iPhone.  In some entries I might get "Home, Work, Skype, Work Fax" while others might have "Work, Skype, Home, Work Fax".  Even with just Work and Home, the ordering is not consistent.  Can I force a specific order?

    Having the same problem.  Have iPad and iPhone, both running ios5, both sync to the cloud, and data entered on one soon shows up like magic on the other.  But Lion MacBook Pro refuses to join in the dance.  Contacts and calendar entries on the mbp don't show up in either the ipad or iphone.  I have the same account login info setup on all three devices, and as much as I can tell, preferences set up correctly.  Oddly enough, when I am in the mbp cloud preference pane, and click on the ? for help, it tells me it can't give me help because it is not connected to the internet.  Well, it clearly IS connected to the internet.  Don't know if that is related to the non-syncing or not, but it is a little strange.  A little bit of operating manual for cloud would be helpful.

  • How can I change the order in which purchased movies are downloaded?

    If for instance, I rent three movies on iTunes Store and decide I want the download of my last pick, to be the first one finished downloading... is there a way to do this?

    Pause the ones that you do not want to be first.

  • Any way to control the order in which data is exported?

    I found it surprisingly easy to set up a form to submit its contents via a formmail script -- perhaps too easy...
    Using Acrobat 9 (and the demo version of Acrobat X), I've modified a form that students fill out so that when they hit the submit button it pushes the form contents to a script which relays it to an e-mail address specified on the form -- no problems there.
    But the order in which those fields are listed in the e-mail bears no relation to the order the fields appear in the form -- or alphabetical order of the field names or data values or the tab order. It's the same order every time. And as far as I can tell the mailing script isn't doing anything to change the order of the data.
    This is mostly an issue of making the e-mail friendly for the supervisor who has to look at the e-mails as they come in. (I've done a number of searches on Google and here in the forums before posting and haven't found any references to similar problems, so maybe I do have a funky script.)
    I'm wondering if a) there's something native to the form that could change the order of the data and b) there's some straightforward way of controlling that. (I imagine I could write some JavaScript to control the output I had to, but it seems like a needless step.)
    Thanks for any insight anyone can provide.

    function(){return A.apply(null,[this].concat($A(arguments)))}
    A solution would be to modify the server script to output in the order you want, as opposed to just looping over the collection of fields present in the incoming data as formmail type scripts typically do.
    That is what I wound up doing -- making a copy of the mailing script and reformatting the message body string to contain just the data responses my colleage wanted in the order he wanted. It beats the old method of requiring users to fill out the PDF, save the document and then e-mail in the PDF as an attachment.

  • Is  order in which the conditions given in the 'WHERE' clause are imortant

    Hi All,
    Is the order in which the conditions are given in the 'WHERE' clause are important for
    performance with regard to oracle query plan.
    Regards

    Short answer: no.
    Longer answer: Well. probably not. If you are using very old versions of the database or the rule-based optimizer, you can probably find some corner cases where it mattered. If you are using a vaguely recent version of the database with the cost based optimizer, it shouldn't matter-- the optimizer is free to evaluate the conditions in whatever order it would like and it chooses to do so in the order that it expects to be most efficient. That said, as the number of objects and conditions increases, the number of possible permutations the CBO tries to consider increase dramatically to the point that an exhaustive analysis of all possible conditions isn't feasible. In that case, the optimizer will have to make a reasonable effort to explore the set of possible plans rather than doing an exhaustive search-- the order of conditions is likely to matter slightly in the optimizer's choice of which branches to explore and which to prune if there are many conditions with similar (or identical) costs. Now, that being said, it is very unlikely that you could do anything useful with this knowledge that would be able to force the optimizer to do something that you'd want. It's possible to do, of course, it's just not a particularly useful way of influencing the optimizer.
    Justin

  • I have multiple email accounts on my iPad. How do I control the order in which the accounts are displayed?

    I have multiple email accounts on my iPad. How do I control the order in which the accounts are displayed?

    In landscape mode, the mailbox list is automatically displayed (in portrait mode, you will need to tap the button to,show it).
    To edit the list, tap edit as shown below.

  • How can I change the order in which photos are presented on an Apple TV?

    I am showing photos on my Apple TV via my Apple MacBook, iTunes and Home Sharing.
    That all works nicely for me, except that I wish to change the order in which a few photos
    are being presented.  How can I change the presentation order on the Apple TV?

    Welcome to the Apple community.
    You'll need to change the order in iPhoto. Open the album you wish to re-order, manually sort them to the order you want, then use the time and date and batch change options as applicable from the photos menu to retag your photos.

  • Can I change the order in which my different e-mail accounts are displayed in TB?

    I use TB to access e-mails from 5 different accounts. They are displayed in the order in which I added them but I would like to change that order. Is it possible, please?

    Many thanks @Airmail for taking the time to provide the solution.

  • Change the order in which the processes come up on restart

    Is there a way to change the order in which the processes come up again when restarting the OC4J?

    Hi --
    Do you mean the order of the applications deployed to an OC4J instance, or the processes started by OPMN when OracleAS is started.
    For the former, we put the application entries into a ordered map based on the order they are seen as in the server.xml file. While we don't offer a feature that the applications will definitively be started in that order, we do work our way through the ordered list. So for more parts you'll see the application starting the same order as they are seen in server.xml.
    For the latter, I'm not sure. I also tend to think that its again based on the order within OPMN. What you can try and use is the opmnctl startall sequential=true command, which will sequentially start each process, where it waits for the previous process to start before starting the next one. That will at least show you the order the processes are starting in and help you test the opmn ordering hypothesis.
    cheers
    -steve-

  • What is the order in which implementaions of a BADI be executed??

    Hi Frnds,
                  If i have more than one implementation for a BADI, what is the order in which they will be executed.
    Regards,
    Navin.

    Hi,
        abt <b>enhancement ponts</b> in simple language
    They are POINTS in standard sap program
    (eg. Before Saving data, Before Displaying Data)
    where some other BADI/Include/Form
    is called.
    In this called badi/include/form,
    the customer can write his own code
    eg. for validation purpose etc.
    2. By doing so,
    the standard sap program need not be changed.
    Only the badi/fm/include/form
    needs to be changed.
    Enhancement-Point is a part of the new enhancement framework. He is some lite reading.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/94/9cdc40132a8531e10000000a1550b0/frameset.htm
    Please check this blogs and wiki as well.
    /people/thomas.weiss/blog/2006/05/03/source-code-enhancements--part-5-of-the-series-on-the-new-enhancement-framework
    /people/thomas.weiss/blog/2006/03/15/the-new-enhancement-framework-part-2--what-else-you-need-to-know-before-building-an-enhancement
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/thenewEnhancementFrameworkandthenewkernel-basedBAdI&
    REgards

  • How to control the order in which records get indexed

    Hi,
    I like to control the order in which the ATG (10.1.2) product records get indexed in Endeca (3.1.1). I like the products/categories to be indexed in the order in which they are sequenced in BCC (in otherwords baseed on the sequence num they have). How to do this? Please help

    If you want TopLink to set the values in a particular order you can order the mappings on a descriptor by setting their ‘weight’ (DatabaseMapping.setWeight(int). All DirectToField type mappings are defaulted to a weight of 1 and all relationship mappings are defaulted to a weight of MAX_INTEGER. Mappings with a lower weight value will be processed first by TopLink.
    --Gordon

  • [svn] 4241: A collection of minor fixes for FXG transcoding to SWF: matrix attribute name correction; allowing for 0x prefix for hexadecimal colors; allowing for an id attribute on FXG nodes; fixing blur filter quality encoding; fixing the order in which

    Revision: 4241
    Author: [email protected]
    Date: 2008-12-05 11:00:45 -0800 (Fri, 05 Dec 2008)
    Log Message:
    A collection of minor fixes for FXG transcoding to SWF: matrix attribute name correction; allowing for 0x prefix for hexadecimal colors; allowing for an id attribute on FXG nodes; fixing blur filter quality encoding; fixing the order in which bevel filter colors are encoding - the SWF specification appears to have the wrong order specified; updating SwfxPrinter to display a linestyle's fillstyle (if present).
    Temporarily removing generated id attribute emitted in FXG to SWF optimization as this attribute is not present in the AS impl.
    Also updating compiler error base types to allow a rootcause to be specified for additional detail to a compiler message exception.
    QE: No
    Doc: No
    Checkintests: Pass
    Reviewer: Discussed compiler base error change with Paul.
    Modified Paths:
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/CompilerException.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/as3/EmbedEvaluator.java
    flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/util/CompilerMessage.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/FXGConstants.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/AbstractFXGNode.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/dom/TextGraphicNode.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/fxg/swf/AbstractFXGGraphics.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/TagDecoder.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/TagEncoder.java
    flex/sdk/trunk/modules/swfutils/src/java/flash/swf/tools/SwfxPrinter.java

Maybe you are looking for