By comparing the date with the BIGGEST rows

Hi all
Why don't the last statement asking all values?
Suppose that:
 SQL> select * from test;

TEMP_DATE
---------
14-APR-11
15-APR-11
16-APR-11

SQL> select months_between(to_date((select temp_date from test where rownum=1)),to_date((select temp_date from test where rownum=2)))test from test;

      TEST
----------




 
I try to get the biggest date of temp_date column of the table of test, but instead, I myself dump of null values. What has gone wrong?
Is there a way more easy to compare these values using GREATEST (I can do that easily with the MAX function however)?

Best regards
TA.

Published by: Valerie good-natured April 14, 2011 20:48

Hi, Val,

Valerie Debonair wrote:
... I try to get the largest temp_date column of the table of test date...

The simplest approach, which is

SELECT  MAX (temp_date)   AS greatest_date
FROM    test;

but instead, I got dump of null values. What has gone wrong?

As someone has already said, ROWNUM = 2 will never be TRUE. ROWNUM is 1 until a line was selected; then only does ROWNUM get incremented to 2.

Is there a way more easy to compare these values using GREATEST (I can do that easily with the MAX function however)?

To use the LARGER, you will need to rotate all values not NULL on a single line. It's a very bad idea. In fact, people sometimes unpivot data just so that they can use MAX instead of GREAT.

Why do you want to do more BIG?
If you use it, be careful for NULL values, because BIGGER returns NULL if one of its arguments is NULL.

Tags: Database

Similar Questions

  • How to compare a Date with the current year data and member of period on FIX

    Hi experts,

    I have a Sun project that each Member is a project (P01, P02,...)
    and account IMGs who stores the information of each project (name, Start date, finished...)
    Finished Date member is of data type Date

    So how can write an IF condition below in order to be able to compare the end Date of the project with the members of the current year and period on FIX
    DIFFICULTY (@Descendants (Projects), Descendants (year-round), Descendants ("year Total")...)
    IF (@CURRMBR (Period)-> @CURRMBR (Year) < Project > - FinishedDate)
    Do something...
    On the other
    Do something


    Please help me on this. Sorry for my bad grammar. Please ask if there is something not clear

    Thank you very much
    Van Huy.

    Published by: Van Huy on 29 January 2013 01:14

    Published by: Van Huy on 29 January 2013 02:24

    Published by: Van Huy on 29 January 2013 02:25

    Published by: Van Huy on 29 January 2013 18:04

    Here's what I did. Post for which may later cover

    VAR FM; / * End of month of the project.
    VAR EXERCISE; / * Year of the project terminated * /.
    VAR CM; / * Capture the current month on FIX declarations * /.
    VAR CY; / * Capture current year on FIX declarations * /.

    DIFFICULTY (@RELATIVE ('year', 0), @RELATIVE ('period', 0), @IDescendants ("core projects")...)

    FY = @ROUND ('TGHT'-> ' NA contract "-> 'FY06'-> ' NA period" / 10000, 0);
    FM = @MOD (@ROUND ('TGHT'-> ' NA contract "-> 'FY06'-> ' NA period" / 100, 0), 100);
    / * For FY13 back 13... */
    CY = @JgetDoubleFromString (@CONCATENATE ('20', @SUBSTRING (@NAME (@CURRMBRRANGE (year, Lev, 0, 0, 0)), 2)));
    / * Value CM set based on perceived period on the DIFFICULTY of statement * /.
    IF (@ISMBR ("Jan"))
    CM = 1;
    ELSE IF (@ISMBR ("February"))
    CM = 2;
    .....
    ELSE IF (@ISMBR ("Dec"))
    CM = 12;
    ENDIF

    IF (CY< fy="" or="" (="" cy="=" fy="" and="" cm=""><>
    Do something...
    ON THE OTHER
    Do something...
    ENDIF
    ENDFIX

    Published by: Van Huy on 19 February 2013 23:10

    Published by: Van Huy on February 20, 2013 19:46

  • Compare a date with the date system

    Hello

    I use the script (that I found in this forum) in below in order to obtain a date of datefield1, add a year and give the date of datefield2.

    It works very well.

    Kai var = util.scand ("yyyy-mm-dd", this.rawValue);
    var sFullYear = oDate.getFullYear ();
    var sMonth = oDate.getMonth ();
    sDate var = oDate.getDate ();
    Datefield2.FormattedValue = util.printd ("JJ", new Date ((sFullYear+1), sMonth, sDate));
    Datefield2.RawValue = Datefield2.formattedvalue;

    But now I would compare the new date (David [added a year]) with the date current system (cDate).

    Does anyone have an idea how to compare dates? The result should change color as below.

    If (David < cDate) {}
    Datefield2.fontcolor = "255,0,0";
    }

    Thank you very much.

    Kind regards

    ra_be

    Try to use the Date of Javascript object:

    var myDate = new Date();
    myDate.setFullYear (2010,0,14);
    var today = new Date();

    If (myDate > today)
    {
    Alert ("the date is before January 14, 2010");
    }
    on the other
    {
    Alert ("today, it is after January 14, 2010");
    }

    If this does not work, try the analysis on the month, day and year, and then do a comparison on all of them (without forgetting to convert strings of months an integer. For example if you store the release date: February 2, 2009, February goes to 2).

    Then your comparison would look like:

    if(myYear == sysYear) {}

    if(myMonth == sysMonth) {}

    if(myDay == sysDay) {}

    days are equal

    }

    Else if (myDay<>

    myDay is before sysDay
    }

    else {}

    myDay is after sysDay

    }

    }

    }

    essentially to follow this same logic for comparisons of month and year and it should work as well.  It would be certainly cleaner and much easier using this Date however (http://www.w3schools.com/jsref/jsref_obj_date.asp)

  • Compare start date with the end date

    Hello

    I'm a newbie in the apex. And my plsql programming skills are also not much.

    I have a request to the apex. I have a page where I insert the username and organization and begindate and the enddate.
    A user can belong to more than one organization.
    A user can also be belong to the same organization, several times, but then the new begindate must be greater than the old endate that already exist for this user and the organization.

    Can someone please help me on my way with the code?

    Thank you

    Instead of using a button, use a PL/SQL Expression:

    : ASK ('CREATE', 'APPLY_CHANGES')

    Be careful, the CREATION and the APPLY_CHANGES are the names of button the text displayed on the button. These two things can be different.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    -------------------------------------------------------------------

  • Comparing the 2 attributes of lines

    Readers,

    I have 2 instances of VO in my AM. The two instances are used for the display/update of data on the same page. So basically I have 1 row of both the OV every time. Is it possible to compare the 2 rows to find data that is rare among themselves or basically the data updates without you know by comparing each one attribute?

    thnks
    11.1.1.5 jdev

    in line with etc,.

    If you wrote a base class for your line impl view and then made your view line impl extend this, then just write the code once. In fact, you only need a basic structure IF, not much. Something like this pseudocode:

    public Map compareTo(Row rowToCompare)
    {
    
    Map results = some type of new Map;
    
    for (loop through i=0 to this.getAttributeCount())
    {
       name = this.getAttributeName(i)
       value = this.getAttributeValue(i)
    
       if (rowToCompare.getAttribute(name) exists)
       compare rowToCompare.getAttribute to value and if it's different, then results.put(name, value) or something like that
    
       else results.put(name, "doesn't exist") or something like that
    
    }
    
    return results;
    }
    

    Then, you simply call:

    Map of diffs = row1.compareTo (row2).

    John

  • No need to advise - compare the date in *.sql with sysdate.

    Hi guys,.

    Need some help here.

    Someone has a script that will compare the date specified with the current sysdate. If previously, he will order that SQL * PLUS to leave immediately.
    The audit will be essentially in a script *.Sql. Whenever we run the script, @c:\script.sql, it will be first of all to compare the dates and decide whether to proceed with the rest of the codes (dml) below the date checker in the same script.sql

    Thank you

    I would like to combine the solutions of bencol and alberto:

    whenever sqlerror exit
    
    DECLARE
       v_date   DATE := TO_DATE('', 'YYYYMMDD');
    BEGIN
       IF v_date >= TRUNC(SYSDATE) -- or perhaps:  v_date>= sysdate
       THEN
         null;
       ELSE
         raise_application_error(-20000,'Date is before SYSDATE!');
       END IF;
    END;
    /
    
    whenever sqlerror continue
    
    -- rest of your script
    ...
    

    (not tested)

    Published by: hm on 08.05.2012 02:51

  • Compare the current time and date with last modified?

    Compare the current time and date with last modified?

    What is the ideal way due to report at the last modified file with the date and time class? last modifed class in the file value is of type long.

    798642 wrote:
    No no no no, currentTimeMillis() only gets you the time... I need to compare the Date and time.

    You should read the docs more closely. It gives you the current time in time, which includes the date.

  • How to compare the length of the data to a staging table with the definition of the base table

    Hello
    I have two tables: staging of the table and the base table.
    I get flatfiles data in the staging of the table, depending on the structure of the requirement of staging of the table and the base table (length of each column in the staging table is 25% more data dump without errors) are different for ex: If we have the city long varchar 40 column in table staging there 25 in the base table. Once data are discharged into the intermediate table that I want to compare the actual length of the data for each column in the staging table with the database table definition (data_length for each column of all_tab_columns) and if no column is different length that I need to update the corresponding line in the intermediate table which also has an indicator called err_length.

    so for that I use the cursor c1 is select length (a.id), length (b.SID) of staging_table;
    c2 (name varchar2) cursor is select data_length all_tab_columns where table_name = 'BASE_TABLE' and column_name = name;
    But we get atonce data in the first query while the second slider, I need to get for each column and then compare with the first?
    Can someone tell me how to get the desired results?

    Thank you
    Manoi.

    Hey, Marco.

    Of course, you can set src.err_length in the USING clause (where you can reference all_tab_columns) and use this value in the SET clause.
    It is:

    MERGE INTO  staging_table   dst
    USING  (
           WITH     got_lengths     AS
                     (
              SELECT  MAX (CASE WHEN column_name = 'ENAME' THEN data_length END)     AS ename_len
              ,     MAX (CASE WHEN column_name = 'JOB'   THEN data_length END)     AS job_len
              FROM     all_tab_columns
              WHERE     owner          = 'SCOTT'
              AND     table_name     = 'EMP'
              )
         SELECT     s.ename
         ,     s.job
         ,     CASE WHEN LENGTH (s.ename) > l.ename_len THEN 'ENAME ' END     ||
              CASE WHEN LENGTH (s.job)   > l.job_len   THEN 'JOB '   END     AS err_length
         FROM     staging_table     s
         JOIN     got_lengths     l     ON     LENGTH (s.ename)     > l.ename_len
                             OR     LENGTH (s.job)          > l.job_len
         )     src
    ON     (src.ename     = dst.ename)
    WHEN MATCHED THEN UPDATE
         SET     dst.err_length     = src.err_length
    ;
    

    As you can see, you have to hardcode the names of the columns common to several places. I swam () to simplify that, but I found an interesting (at least for me) alternative grouping function involving the STRAGG user_defined.
    As you can see, only the subquery USING is changed.

    MERGE INTO  staging_table   dst
    USING  (
           SELECT       s.ename
           ,       s.job
           ,       STRAGG (l.column_name)     AS err_length
           FROM       staging_table          s
           JOIN       all_tab_columns     l
          ON       l.data_length  < LENGTH ( CASE  l.column_name
                                              WHEN  'ENAME'
                                    THEN      ename
                                    WHEN  'JOB'
                                    THEN      job
                                       END
                               )
           WHERE     l.owner      = 'SCOTT'
           AND      l.table_name     = 'EMP'
           AND      l.data_type     = 'VARCHAR2'
           GROUP BY      s.ename
           ,           s.job
           )     src
    ON     (src.ename     = dst.ename)
    WHEN MATCHED THEN UPDATE
         SET     dst.err_length     = src.err_length
    ;
    

    Instead of the user-defined STRAGG (that you can copy from AskTom), you can also use the undocumented, or from Oracle 11.2, WM_CONCAT LISTAGG built-in function.

  • By comparing the Dates in a group of data (different lines)

    I have a requirement where I have to compare dates in a dataset for each employee.  The data looks like this:

    WITH test_data AS

    (SELECT the '1' AS pk, '5900' AS emp_id, '5' AS rec_id, to_date('01-JAN-2014') AS rec_date FROM dual

    UNION ALL

    SELECT '2', '5900', '5', to_date('01-FEB-2014') FROM dual

    UNION ALL

    SELECT '3', '5900', '5', to_date('01-MAR-2014') FROM dual

    UNION ALL

    SELECT '4', '5900', '5', to_date('01-JAN-2014') FROM dual

    UNION ALL

    SELECT '5', '5900', '6', to_date('06-JAN-2014') FROM dual

    UNION ALL

    SELECT '6', '5900', '6', NULL FROM dual

    UNION ALL

    SELECT '7', '5900', '6', to_date('01-JUL-2014') FROM dual

    UNION ALL

    SELECT '8', '5900', '7', to_date('29-JAN-2014') FROM dual

    UNION ALL

    SELECT '9', '5900', '7', to_date('29-SEP-2014') FROM dual

    UNION ALL

    SELECT '10', '5900', '7', to_date('01-OCT-2014') FROM dual

    UNION ALL

    SELECT '11', '8595', '5', to_date('01-SEP-2014') FROM dual

    UNION ALL

    SELECT '12', '8595', '6', to_date('05-SEP-2014') FROM dual

    UNION ALL

    SELECT '13', '8595', '7', to_date('30-SEP-2014') FROM dual

    UNION ALL

    SELECT '14', '8595', '7', NULL FROM dual

    )

    REC_ID column is composed of 3 different types of records, which must satisfy this requirement:

    REC_ID 5 acts as point of departure, and REC_ID 6 must have a REC_DATE within 7 days of REC_ID 5 REC_ID 7 must have a REC_DATE within 30 days of REC_ID 6.

    • If the requirements are any record in REC_ID 5 acts like zero day or the starting point;
    • Any record in REC_ID 6 must be within 7 days of the date of REC_ID 5;
    • Any record in REC_ID 7 must be within 30 days from 6 REC_ID.

    My results:

    Expected results - satisfactory records

    EMP_ID

    DATE_1

    DATE_2

    DATE_3

    5900

    1 January 14

    6 January 14

    29 January 14

    8595

    1 sep-14

    5 sep-14

    30 sep-14

    I don't know how to compare dates in a dataset that are on different lines.  I thought using self-joins, query using the window as rank (), factoring functions, but I'm stuck pretty quickly.

    I appreciate all help.  Thank you!

    Aqua

    Hello

    AquaNX4 wrote:

    WOW odie_63: it would be a blessing if I was... but unfortunately, I'm on 10 gr 2.  That would have been great!

    Frank Kulash:

    I'm stuck (mentally) to the fact that there is an amount without discernment of records in the base table for each type of REC_ID.

    Some employees have 5 folders for REC_ID, 10 REC_ID 6 and 7 for REC_ID 7, which leaves me confused in how many self-joins I should do, or if it is at all possible.  I did a lot of arithmetic of dates with the data on the same line and certain ranks () functions for data residing on different lines, but this 1 seems to confuse me...

    I ran 1 self-join as below to see what it looks like and it confused me even more because I know the timestamp of the arithmetic in where clause still will not produce data as I want...  I am now trying another way...

    SELECT td2.rec_id,

    TD2.emp_id,

    TD2.rec_date

    Of

    test_data2 td2

    LEFT JOIN test_data td1 ON td1.emp_id = td2.emp_id


    It's a good start.

    You want an inner join, however, not an outer join, not you?  Outer join means "include td2 lines if they have data in the corresponding TD1".  If I understand the question, you are only interested in cases where it is matching data.

    Here's a way to do it:

    WITH joined_data AS

    (

    SELECT d5.emp_id

    d5.rec_date LIKE date_1

    d6.rec_date AS date_2

    d7.rec_date AS date_3

    ROW_NUMBER () OVER (PARTITION BY d5.emp_id

    ORDER BY d5.rec_date

    d6.rec_date

    d7.rec_date

    ) AS r_num

    OF test_data d5

    JOIN test_data d6 ON d6.emp_id = d5.emp_id

    AND d6.rec_date > = d5.rec_date

    AND d6.rec_date<= d5.rec_date="" +="">

    JOIN test_data d7 ON d7.emp_id = d6.emp_id

    AND d7.rec_date > = d6.rec_date

    AND d7.rec_date<= d6.rec_date="" +="">

    WHERE d5.rec_id = '5'

    AND d6.rec_id = "6"

    AND d7.rec_id = "7"

    )

    SELECT emp_id, date_1, date_2, date_3

    OF joined_data

    WHERE r_num = 1

    ;

    The subquery joined_data find all combinations of rows that meet the criteria.  We want to only 1 line by emp_id, so I used ROW_NUMBER assign unique r_nums (starting at 1) to all lines with the same emp_id and then, in the main query, rejected all but the 1st row.

    Knapen had a good idea, but it won't work for all cases.  There may be situations where the only combination of rows that meet the criteria does not use the MIN or MAX of dates of one (or several).

  • The GPS data with other analyzed data record

    Hello!

    I am a new user of DASYLab and not very good with coding, so please bear with me! I try to record (timestamp, latitude, longitude) already analysed GPS data with other data (accelerometer, etc.) in the same. DDF file. Right, GPS analysed is now sent through a series of three demultiplexers for each signal and only 1 of 16 channels, reducing the size of the output data. This data is then saved in a. The CAD file. Other data on average, recorded in one. DDF file, then saved another. The CAD file. We used to compare the data from the GPS and other devices by comparing timestamps.

    I would like to save all data to a file, either. DDF of. CSA (.) DDF would be preferable).

    When I try to add more channels in the. DDF save the module after the demultiplexer black box and GPS data to it, I get an error saying "the data to an entry in this module are the wrong type." I also receive this error when trying to send the data GPS to the. CSA Save module. I learned that this means that the size of the files is not the same of this thread. My question is, how can I make sure that the data have the same characteristics of time so I can save to the same file?

    If you need more information I would be happy to provide it, I apologize if I have something important to go.

    Thanks for reading,

    etdiv

    That's what I needed. Your time is the driver. In the RS232 input module, click the Options button.

    Select the measurement of output value, and then click the button on the time Base and select sync/time Base driver.

    That should allow you to write to the DDF file.

  • With a sampling of the data with DAQMX, error-200279 occurs when making 2d array dbl

    Hello

    I did a system of simple analog voltage with DAQMX data acquisition.

    It is made for reading of capacitance, where output capacitance value out of a circuit in the periodic voltage signal.

    What I want is to get data from four capacitors simultaneously through four channels, using samples n n (dbl 2d).

    The structure of my VI is almost similar with examples of continuous sampling of voltage in LabView, with the exception of a few other calculations in the loop.

    And for the synchronization of the trigger, I've corrected the edge of release with the external signal from the capacitance reading circuit.

    Version no. 1 has a channel for data input voltage. Version n ° 2 has four channels for the input data.

    While ver.1 can get accurate reading of four capacitors circuit data each (a single channel at a time),.

    ver.2 acquires four channels of data, with a single thin data channel, all the others were wrong.

    I saw a 200279 error occur in the DAQMX read part 2d dbl, so I tried increasing the buffers by changing the sampling frequency or the number of samples, but it wasn't everything.

    I rose for most of the forums with the 200279 error, but the solution would not work on mine.

    Anyone can find the problem? I will attach my screws it may include a bit of Korean language, but most of them are in English, shouldn't be too hard to recognize. Sorry for the inconvenience.

    Oh I forgot, my DAQ is NI USB-6259, and it works in Win XP sp3 and LabView 8.6.

    Thank you.

    Hello Azurenight,

    The 6259 is a DAQ card of the M Series Multiplexed, which means that it is not possible to sample each signal at the same instant, rather the channels are all sent through the ADC even and must be sampled in order. More information on this can be found here:

    LabVIEW Help: Multiplexing compared with simultaneous sampling

    http://zone.NI.com/reference/en-XX/help/370466W-01/mxcncpts/multisimulsamp/

    It may still be possible to get the data you need with the card you have - could you give more information about the maximum eligible period between samples on different channels?

    If you require * real * simultaneous sampling, you will probably need different hardware.

    Kind regards

  • compare the mixed data clusters which include some floats

    Did someone come up with what they consider to be a slick way to compare groups of mixed (including floats) data for functional equality (close enough)? Are all I have manged to come with specific-the-cluster screws using a while loop with a case statement internal focus on the index to scroll the cluster element by element to make comparisons, using an appropriate method to compare the floats that can accept a tolerance.  I thought that maybe someone can already built a more generic solution based on clusters of variant data conversion and then direction each piece of data to a correct comparison for its data type.

    The attached Zip file has versions v7.1.1, v8.0 and v2014 my VI for this comparison. I need to rework the managed case RefNum objects to the fact that they will be digital or ASCII (e.g.: VISA). I also added an error output to make it easier to tell when the process runs off the rails. At this point, I'll say I'm done with this, because what I created, this is what I need to do and the elves of the forum NOR are harassing me to mark something on this topic as a response. Enjoy!

  • When I subtract two numbers DBL and try to compare the result with another DBL, it fails

    I found a curious problem with subtraction and compare numbers DBL in LabVIEW (8.6). Here's how it works:

    1. subtract two numbers DBL such that the result is not incorporated. (Say, 3.2 - 3.1)

    2. compare the result with a constant/control that is on the result of the subtraction (in the example, 0.1)

    3 see the output of the comparison.

    If the result of the subtraction is an integer, the Boolean result is (as expected). If the result is not complete, the comparison fails.

    (Now, if I simply compare two floating point numbers, it works, so the issue is not with the node comparison itself, but with the data that is entered to the node). Can someone understand why this happens? It's unexpected, it's a pretty serious bug.

    It is provided with all programming languages. Numbers do not have an exact binary floating-point representation. This has been discussed endlessly. Never use the equal function with floats. You can use the function in the range and force.

  • Compare the string to date?

    Hello everyone, I have a date recorded in this format string ' 25/05/2011' and I want to compare this string with the current date. I am able to do so if I divided the Date to a String [] string, but it's using a coding hard to compare dates, which does not work if I use: String CurDate = dateFormat.formatLocal (System.currentTimeMillis ()); Because the format is not always as DD/MM/YYYY, depending on the settings of the user's phone. I'm sure that there is a better way to compare two dates, could someone ' a please advise me on this matter. Please note that I have saved in this format DD/MM/YYYY Date String. Thanks in advance.

    create a calendar, to day/month/year and check if it's the day same long http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/util/DateTimeUtilities.html#is... )

  • Foreign key constraint, not recognized during the synchronization of data with the model dictionary

    Hello

    Data Modeler is a foreign key constraints do not recognize when synchronizing data with the model dictionary, although the foreign key is there (in the database that a data dictionary is read). I can't find any criterion when a foreign key is not recognized by the Data Modeler. Are there limits to the length of the attribute, or the number of columns in a foreign key, or other limitations which may lead to this behavior not to recognize a fk by Data Modeler? I have columns more than 32 characters. I compared with the fk is recognized by DM, but I can't find anything that indicates why it is not recognized.

    I wonder if someone also has constraints of foreign keys that are not recognized in the comparison of data bases and model?

    Thank you

    Robert

    Hi Robert,.

    Thanks for the comments, I logged a bug.

    Philippe

Maybe you are looking for