Select MIN OR greater than something

Hi
I need to select a MIN value from column, but if that column contains something bigger than X, then I want to select that something.
Example :
Column
3
9
7
I want to select 3, because ther is nothing that's greater than 10. BUT if column looks like this:
Column
3
9
12
7
15
I want to select 12, because it's the smallest number that is greater than 10.
How can I do such a thing? If I can, that is...

Rahul India wrote:
This solution is not for working when values in the table are 3,9,123,15,7Better provide proof when you give statements like this.. Or explain, what do you mean by "not working".. :)
with t as (select 3 num from dual
               union all
               select 9 num from dual
               union all
               select 123 num from dual
               union all
               select 15 num from dual
               union all
               select 7 num from dual
select nvl(
           min(case when num > 10 then num end),
           min(num)
           ) mn
from t ;
MN
15

Similar Messages

  • Select only dates greater than static value

    I am retreiving dates from an sql table, currently I am pulling all the dates. How do I only pull dates greater than say 5/1/2008?
    Below is the current code.
    String strSQL = "Select convert(nvarchar, wk_dt, 101) as outDt From t_fiscal_weeks Where wk_dt <= '" +
    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new java.util.Date()) + "' Order by wk_dt desc";
    Thanks for the help

    Always, always, always use a PreparedStatement: [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html]

  • Query to select values greater than, where AS clause is used

    Oracle 10g
    Requesting your help in writing the query correctly.
    I have the following 2 tables. The AddProjectPhase and AddProject tables. It is many to many relationship. Each project can have a predefined set of 4 different phases under it. Each phase has a start date and an end date. I am writing a report to get the phases which have a duration greater than, for example, 3 months.
    The query below is working fine to just display the list of all the phases along with the duration of each phase. I am not able to modify it to select the phases which have a duration, for example, 3 or more months.
    CREATE TABLE  "ADDPROJECT"
       (     "VERSIONNO" NUMBER(*,0),
         "PROJID" VARCHAR2(20),
         "PROJNAME" VARCHAR2(60),
         "PROJSTARTDATE" DATE,
         "PROJSTATUS" VARCHAR2(20),
         "PROJENDDATE" DATE,
         "PROJENDTYPE" VARCHAR2(20),
         "PROJENDREASON" VARCHAR2(1000),
         "UCPROJECTMANAGER" VARCHAR2(20),
         "FROMDATE" DATE,
         "TODATE" DATE,
         "SRCHFIELD" VARCHAR2(20),
         "OPERATOR" VARCHAR2(20),
         "PARENTPROJID" VARCHAR2(20),
         "PROJHIDDENDATE" VARCHAR2(20),
          CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
    CREATE TABLE  "ADDPROJECTPHASE"
       (     "VERSIONNO" NUMBER(*,0),
         "PROJPHASEID" NUMBER(9,0),
         "PHASESTARTDATE" DATE,
         "PHASEENDDATE" DATE,
         "RRDATE" DATE,
         "PHASENAME" VARCHAR2(30),
         "PROJPHASESTATUS" VARCHAR2(20),
         "PROJID" VARCHAR2(20),
         "OPERATOR" VARCHAR2(20),
         "FROMDATE" DATE,
         "TODATE" DATE,
         "SRCHFIELD" VARCHAR2(20),
         "REVIEWCOMMENTS" VARCHAR2(1000),
         "PROJHIDDENDATE" VARCHAR2(20),
         "ISUEVALUATION" NUMBER(1,0),
         "SOLUTIONINGTEAMINVOLVEMENT" NUMBER(1,0),
         "ISUNAME" VARCHAR2(20),
          CONSTRAINT "PK_A63" PRIMARY KEY ("PROJPHASEID") ENABLE
       )Below is the query to display the list of all the phases along with the duration of each phase which is working fine.
    SELECT pp.phaseName "phasename",
    pp.phaseStartDate "phaseStartDate",
    pp.phaseEndDate "phaseEndDate",
    pp.projPhaseStatus "projPhaseStatus",
    ap.projID "projID",
    ap.projName "projName",
    ap.projHiddenDate "projHiddenDate",
    ap.projStartDate "projStartDate",
    CASE
        WHEN pp.phaseEndDate IS NOT NULL
        THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
        WHEN pp.phaseEndDate IS NULL
        THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
        ELSE null
    END "phaseMonths"
    FROM AddProjectPhase pp, AddProject ap
    WHERE ap.projID = pp.projID
    AND ap.projHiddenDate = pp.projHiddenDate
    ORDER BY ap.projIDHowever the modified query shown below to select all the phases greater than, for example, 3 months, is resulting in
    ORA-00904: "PHASEMONTHS": invalid identifier SELECT pp.phaseName, pp.phaseStartDate, pp.phaseEndDate
    FROM AddProjectPhase pp, AddProject ap
    WHERE ap.projID = pp.projID
    AND ap.projHiddenDate = pp.projHiddenDate
    AND PhaseMonths IN
    (SELECT
    (CASE
    WHEN pp.phaseEndDate IS NOT NULL
    THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
    WHEN pp.phaseEndDate IS NULL
    THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
    ELSE null
    END) AS PhaseMonths
    FROM AddProjectPhase pp, AddProject ap
    WHERE ap.projID = pp.projID
    AND ap.projHiddenDate = pp.projHiddenDate)
    ORDER BY ap.projID

    Looking for this?
    select *
       from (
            SELECT pp.phaseName "phasename"
              , pp.phaseStartDate "phaseStartDate"
              , pp.phaseEndDate "phaseEndDate"
              , pp.projPhaseStatus "projPhaseStatus"
              , ap.projID "projID"
              , ap.projName "projName"
              , ap.projHiddenDate "projHiddenDate"
              , ap.projStartDate "projStartDate"
              , CASE WHEN pp.phaseEndDate IS NOT NULL THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
                     WHEN pp.phaseEndDate IS NULL     THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
                     ELSE null
                END "phaseMonths"
              FROM AddProjectPhase pp, AddProject ap
             WHERE ap.projID = pp.projID
               AND ap.projHiddenDate = pp.projHiddenDate
             ORDER
                BY ap.projID
      where "phaseMonths" >= 3

  • How do I disallow negative numbers in a selected group of cells (i.e. only allow values greater than or equal to zero)?

    I have a table of calculated values in Numbers, and I want to disallow negative numbers in the entire table. Any numbers that would be negative I would like changed to/displayed as zeroes, that way future calculations that may be based on this cell use the value of 0 for the calculation rather than the negative value. I have seen ways of doing this to single cells at a time, but I am interested in applying it to a large selection of cells.
    There is the Conditional Format option when you bring up the inspector, but I cannot get a custom rule to work for me. I select "Greater than or equal to" and I enter 0 in the box, but nothing changes. Can anyone help with this?
    Thanks

    A step toward simplifying the application of MAX to the issue, Jerry.
    This part, though:
    Now apply your long, animal-modeling, expressions to this new, interposing, table rather than the original.
    may still leave several references to be change from the original data table to the new one.
    One way to get around that is to use the Duplicate ("DATA-1) as the new table for raw data, and the Original (DATA) as the interposing table, using the formula =MAX(DATA-1::A2) as above, starting in DATA::A2.
    This way, the long expressions could continue to reference the original table (with its content now modified).
    ALTERNATE process:
    Find/Replace could also be used to speed the process of reassigning the modeling expressions to the duplicate table, as suggested by Jerry. But some cautions apply here.
    Find/Replace can be limited to Formulas only, but not to Some formulas only.
    Find/Replace can be limited to the Current Sheet only, but this can't be combined with Formulas only.
    More on this later, when I've had a chance to check some possibilities.
    Regards,
    Barry

  • How can a function returning character length greater than 4000 be selected in SQL

    Hi,
    I want to know if there is a way to write a select query on a function call which returns a varchar of more than 4000 characters.
    CREATE OR REPLACE FUNCTION FUNC1
    RETURN VARCHAR2
    IS
    str VARCHAR2(32767);
    BEGIN
         str := <some string greater than 4000 char>;
          RETURN str;
    END;
    SELECT FUNC1 from dual; ---- This gives an PL/SQL numeric or value error. Character string buffer too small.
    Is there any way to resolve this?
    Thanks

    32767 is not default. The default is still 4000 for VARCHAR2. You need to set the initialization parameter MAX_STRING_SIZE= EXTENDED for 32767.
    Text from Oracle documentation
    Extended Data Types
    Beginning with Oracle Database 12c, you can specify a maximum size of 32767 bytes for the VARCHAR2, NVARCHAR2, and RAW data types. You can control whether your database supports this new maximum size by setting the initialization parameter MAX_STRING_SIZE as follows:
    If MAX_STRING_SIZE = STANDARD, then the size limits for releases prior to Oracle Database 12c apply: 4000 bytes for the VARCHAR2 and NVARCHAR2 data types, and 2000 bytes for the RAW data type. This is the default.
    If MAX_STRING_SIZE = EXTENDED, then the size limit is 32767 bytes for the VARCHAR2, NVARCHAR2, and RAW data types.

  • Selection screen -greater than

    I want to write a code in the program  for the condition where i say the selection screen value is greater than mara-prdha.(Also for the levels of this field) Prdha is product hierachy and has different levels .So Is it possible to restrict it based on the entries greater than or less than the different levels..  .How do i do it?.Pls help

    Table: T179, restrict with field name "STUFE"  get the Product.
    And do your selection from MARA..

  • Ok so i'm trying to do a conditional format on numbers if (cell a2) = greater than or text then make the same cell or another cell do something. Does anybody knows how to do that on numbers. thanks.

    hi I'm from Italy.
    ok so i'm trying to do a conditional format on numbers if "a cell" = greater than or text then make the same cell
    or another cell do something like insert a number or change color.
    Does anybody knows how to do that on numbers?. thanks.

    Among the things you'll learn from the User Guide:
    Conditional formatting can be used to change the style of the text in a cell and/or the fill colour of the cell.
    A formula may be used to set the value in a cell. In both cases, the format rule or the formula affects only the cell to which the rule is attached or which contains the formula. Neither values or formats may be 'pushed' onto another cell.
    Regards,
    Barry

  • Report data showing a date 1 day greater than selection formula end date

    Hi All,
       I have a report that contains the following selection:
    date(dateadd("h",-{Calendar.EstUTCOffset}, {tbl.TimeStamp})) >= date(minimum({?Date})) and date(dateadd("h",-{Calendar.EstUTCOffset}, {tbl.TimeStamp})) <= date(maximum({?Date})) and dayofweek(dateadd("h",-{Calendar.EstUTCOffset}, {tbl.TimeStamp})) in {?DayOfWeek} and
        time(dateadd("h",-{Calendar.EstUTCOffset}, {tbl.TimeStamp})) >= time({?Start Time}) and
        time(dateadd("h",-{Calendar.EstUTCOffset}, {tbl.TimeStamp})) < time({?End Time})
    When I view the report, if my date(maximum({?Date}))  is 5/1/2011, the report shows data for 5/2/2011. I can't seem to figure out why my report is generating data for a date that is 1 day greater than my end date.
    Any suggestions would be appreciated.
    Thank you in advance,

    No need to send SQL as dates are not in WHERE clause.
    It someting to do with the way crystal handles datetimes
    If you want to see dates up to an including 6/2/2011 if its a date time crystal will create a where caluse
    Datetimefield <= 6/3/2011 00:00:00
    Looks like when this is converted to date its stayin as 6/3/2011
    Sorry can't think of any solutions, also I live in UK so just about to leave, hopefully some one else may be able to offer a solution.
    Ian

  • Final Cut X 10.0.4 - cannot share a movie greater than 15 mins to youtube

    So I just updated to 10.0.4 this morning. Open an existing project that is roughly 19 minutes long, which by the way I previously published to my YouTube account with no problem at all. Now Final Cut will not allow me to publish the video. I get an error in the bottom left corner of the screen that reads: "Publishing movies greater than 15 minutes may fail". The "next" button is grayed out. But when I open a project that is only 7 minutes long, it does allow me to share. Has anyone ran into this problem?

    FCPX "shares" to YouTube at best resolution... I think... (very high quality at least.)
    You may have an account that will allow > 15 minutes of video, but I'll bet there is a file size limit on that as well; somewhere around 2GB. YouTube will reject any file that is larger than allowed, regardless of how long the video takes to play.
    You didn't specify the format of your project, but for 1080, FCPX will output H.264 @ ~ 15-18Mbps. A 12 minute 1080 project is dangerously close to the 2GB limit. Switching to 720 will cut the output file size to almost 1/2 of 1080.
    Currently, there is no way to specify the bitrate in FCPX. You can check FCPX's estimated output file size on the Summary pane of the Share dialog.
    Since you're not getting the "Next" button, then your login is incomplete or incorrect. You must specify your YouTube username/account name, your password, a Description (required) and tags (also required.)

  • Edge Animate CC 2014 issue with SVG - Images greater than 1024 x 1024

    Hi, since i updated my Edge Animate CC for Edge Animate CC 2014 i have issues when i import .svg files. Edge told me "Images greater than 1024 may cause unexpected behavior on mobile device" when i import .svg files smaller than 1024 x 1024 ?
    When i publish my animation i have a weird things happening and my image scaling default is 10% instead of 100% when i import. Someone had this issue ? Something we can do ? My images a less then 1024 x 1024 and work perfectly in Edge Animate CC 2.0

    Ok. I've solved. I needed to load some things:
    EC.Parallax.setup (sym);
    The full code (that works for me) is:
    -- compositionReady:
    EC.Parallax.setup(sym);
    // Load Edge Commons
    yepnope({
    load: [
    "http://cdn.edgecommons.org/an/1.1.0/js/min/EdgeCommons.js",
    // Load style sheet for the overlay
    "http://cdn.edgecommons.org/an/1.1.0/css/style.css"
    -- click
    // Open image in spotlight overlay
    // Set up configuration
    var config = {
    width: "1024",
    height: "768",
    type: "image",
    source: "images/dog.jpg"
    EC.Spotlight.open( config );
    I hope to serve others.
    Regards

  • [10g] Way to find least value greater than a value?

    I have a simple (I think) question ...
    Part 1:
    Is there a way to determine the least value, among a set of values, that is greater than 0?
    A couple of examples:
    Set of values:
    {0,1,2,3}
    Return value:
    1
    Set of values:
    {0,5,10,20,100}
    Return value:
    5
    Set of values:
    {1,4,9,11}
    Return value:
    1Part 2:
    Same thing, but greater than some given value, not necessary 0.
    Set of values:
    {0,1,2,3}
    Parameter value:
    2
    Return value:
    3
    Set of values:
    {0,5,10,20,100}
    Parameter value:
    2
    Return value:
    5
    Set of values:
    {1,4,9,11}
    Parameter value:
    2
    Return value:
    4In particular, I'm looking for an efficient way of doing this. I believe I can do it with a set of CASE statements, but it gets really complex the more values you are comparing.
    My first thought was to use the LEAST function, but that doesn't allow me a way to use a parameter.
    Any suggestions?

    -- this section has been edited
    And that's basically where I was heading. I was hoping there was a less complex way to do it... somehow replacing any zeros with an impossibly large number, without using case statements (something equivalent to the NVL function, but to replace any value with another), so that they'd never be less than anything, and then I could just use the LEAST function. The only way I can think of to do that though, would be to convert the numbers to strings, use REPLACE, and then convert them back to numbers, which doesn't seem less complex than the CASE statements, and most likely is worse performance-wise.
    For example:
    SELECT     ord_nbr
    ,     seq_nbr
    ,     time_spent /
         CASE     WHEN     comp_qty     <= plan_qty
              AND     comp_qty     <> 0
              THEN     comp_qty
              WHEN     comp_qty     > plan_qty
              THEN     LEAST     ( TO_NUMBER(REPLACE(TO_CHAR(ord_qty-scrap_qty),'0','999999999'))
                        , TO_NUMBER(REPLACE(TO_CHAR(plan_qty),'0','999999999'))
                        , TO_NUMBER(REPLACE(TO_CHAR(comp_qty),'0','999999999'))
              ELSE 1
         END     AS unit_time
    FROM     ord_detail
    ;-- end of section edited (I posted before I had fully gone through the solution provided)
    I checked the data, and though, theoretically all values could be zero, there are no instances where that happens. I think that, in the case all values were 0, I'd just want to use 1 instead.
    Side note on the "big" problem behind this question....
    My ultimate problem, (and if I end up needing help with that, I'll start a new post for it) is that the quantity data in our system has a fair amount of junk in it...values that can't be true. With this solution, I would assume that in any case where the quantity complete at a given step of a process is less than or equal to the quantity planned to be complete at that step, the value is good, which is not necessarily a correct assumption. Then, only in cases where something can't be true, like when quantity complete > the quantity planned, are when I would intervene with this solution to make a "best guess" at the correct value. There a few things related to this that I have to determine before I can figure out my next step.
    We have another database (so we can keep things straight, I'll call the database I've been querying up til now DB1, and this other one, DB2) that has much more reliable quantity data and step data (sometimes it has steps that aren't in DB1) but its structure is complex, I'm rather unfamiliar with it, and it does not have time spent data. Additionally, some products have all their information in DB1, and none in DB2.
    So my options are to:
    1) ...try to learn the structure of the other database, find the data I need, and query both databases together, using this thread's solution to resolve any questionable data that does not exist in both systems, and skipping any steps that occur in DB2, but not DB1 (since they won't have any time data, which is ultimately what I'm after)
    2) ...try to come up with a method to pre-"scrub" my data in DB1, based on some logical assumptions and looking at all steps in an order, so that I can then just query the scrubbed data...
    3) ...use the solution from this thread, and assume that the bad data isn't enough to significantly impact my calculations...
    What I wouldn't give for a single system with all good data!
    Edited by: user11033437 on Nov 19, 2010 4:21 PM

  • Numbers function IF greater than using date & time

    I am trying to produce a number sheet that will allow me calculate a working rota for staff.
    The problem i am having is when i try and use a IF function to remove 1hr (for lunch) if the person works 8 hours or more.
    If that person works between 6 and 8 they require a 30 mins lunch.
    I have already setup the sheet to calculate the total shift time by subtracting the starting time from the finishing time. i.e. 18:00 - 08:00 = 10hrs
    Now i need it to subtract 1hr for lunch.
    It should read something like IF 10 >8 then -1 from 10.
    I just don't know how to not cause an error.
    ideally i would like it to be able to handle 2 IF's in the one cell. if its 6-8hrs - 30mins or if its greater than 7 -1 hr.
    I currently have all the cells set at time and date.
    Any help would be greatly appreciated.
    Richard

    this works a little but it seems to subtract 0.5 and then 1 removing to much time.
    I have attached a link which i hope will explain this better.
    https://onedrive.live.com/redir?resid=82B56CEF9A61CDE9!8770&authkey=!ALJn-lja2b2 q1iw&ithint=file%2cnumbers
    Thank you for your help

  • Date Greater Than Operator

    I am comparing two date fields from two tables. Both are in DATE format. The dates look like this: 22-Apr-2006 07:00:10 AM and 01-Jun-2007 12:00:00 AM. I am adding this statement to a WHERE clause:
    and vendors.vend_obsolete_date > document_xref.acceptance_date;
    In this particualr case, I should get no result because the 1st date came before the 2nd date. But when I run my program, it seems to be ignoring my > statement. Is using a greater than sign the proper syntax to compare if the 1st date field is bigger (came after) another?
    Thanks!

    Greater than works on DATE columns, no problem. A simple test confirms it.
    SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jul 9 17:50:52 2007
    select 'oops, something is wrong' as result
    from   dual
    where
      to_date( '22-Apr-2006 07:00:10 AM', 'dd-Mon-yyyy hh12:mi:ss AM' )
      > to_date( '01-Jun-2007 12:00:00 AM', 'dd-Mon-yyyy hh12:mi:ss AM' )
    no rows selectedThere must be something else about your query or data that's causing the anomaly.
    Joe Fuda
    SQL Snippets

  • ROWNUM with Greater than symbol..!

    Hi
    Can any one explain why ">" greater than operator not working with ROWNUM.
    FOR EXAMPLE:
    SELECT * FROM EMP where rownum > 2;
    But the less than operator is working.
    SELECT * FROM EMP where rownum < 2;
    Please clarify this.
    Thanks in advance.
    Regards
    Sathya

    Hello,
    " … since something like a rownumber actually doesn't exist …"I’m pretty sure the OP is referring to the pseudo-column ROWNUM, which generated automatically by the db systems, for every query. This value, starting with 1, is being attached to every record which satisfy the where clause condition. Hence, for the first record to be assigned a rownum, the where clause must consider rownum=1 as a valid condition.
    " Rownum needs to be "generated" in a subquery first "I don't see any problem with the following code (with no subquery):
    select * from emp
    where rownum <=3;This query will display the first 3 fetched (not sorted) records from the emp table.
    Regards,
    Arie.

  • Aprroval for Invoice have due date greater than 100 days

    Hi all!
    I would like to create query to approve for Invoice have due date greater than 100 days.
    SELECT 'true' from OINV  where max(datediff(day, OINV.docduedate, getdate()))>100 and OINV.docstatus ='O' and  cardcode = $[$4.0.0] group by cardcode
    It's not working. Can you help me!
    Thanks!

    Hi Tien,
    Hopefully not trying to teach you how to suck eggs here, but it looks like the query is doing too much. There shouldn't be a need to perform a "GROUP BY" in a query to dictate if an approval is to be triggered or not, only the criterai to make it happen.
    For examle, the following code will send a transaction for approval if the customers code equals a specific reference.....
    SELECT 'TRUE' FROM ORDR T0 WHERE ${ORDR.CardCode} = 'ABC001'
    If you're wanting a query to just return a boolean answer based on the date criteria, you might want to try adapting your query to something like.......
    SELECT 'true' from OINV where max(datediff(day, ${OINV.docduedate}, getdate()))>100 and ${OINV.docstatus} ='O' and  cardcode = ${$4.0.0}
    (As an additional tip, in order to test a query that you're wanting to use as either a formatted search or approval type selection, when in the transaction, if you locate the relevant saved query under "Tools > Queries > User Queries" etc, where you have references to specific fields e.g. ${ORDR.CardCode}, this will pick up the values from the current record and give you a what if scenario. I tend to have just a "Temp" query I use for WIP type queries of this nature.)
    Note - You need to replace the bracket's "{}" with square ones, I've used the others as the forum posts as a http reference.
    Hope this helps!
    Julian

Maybe you are looking for

  • HP scanjet G3110 in windows 7 64 bit, XP mode (Twain Driver)

    Hallo I have just installed my "HP scanjet G3110" windows 7 64 bit, I have installed CorelDraw in XP mode and it work OK. When I try to scan an image I get a popup saying: "Could not find a Twain driver that matches the function of the application" C

  • How do I save formatting from Word docs to pages?

    Hi Often when I open a word document in Pages I get a document warning pop up box.  Often I find that basic things from the Word doc have been changed.  For example, things that were in Bold text in the Word doc are no longer in Bold in the Pages fil

  • File to Multiple RFCs

    Hi, The source file is having addressing data and functional location data I need to call two BAPIs one is for addressing data and another one is for functional location data to create those in R/3. Input file comes with multiple records. How can we

  • How to force datagrid headerRenderer to redraw itself?

    Hi guys,     I had datagrid headers that blinks however, I want to turn the blinking off by assigning a new value of a property inside the headerRenderer. The newly assigned value is indeed stored in the property. But my problem is how to force this

  • LOBs in Weblogic server

    hi, i am trying to read and update the CLOB and BLOB datatypes in my entity bean. within an ordinary java class the same code works well. but when i deploy the bean with same code to read/write LOBS in weblogic 5.1, following exceptions are thrown, w