determine the closest date of you at our days

Hello all;

I have a table with the following dates in the table. See code below

create table t1
(
       close_date date


)
insert into t1
  (close_date)
values
  (to_date('22-10-2010', 'DD-MM-YYYY'));


insert into t1
  (close_date)
values
  (to_date('11-11-2010', 'DD-MM-YYYY'));
  
  insert into t1
  (close_date)
values
  (to_date('29-11-2010', 'DD-MM-YYYY'));
  
  insert into t1
  (close_date)
values
  (to_date('10-10-2010', 'DD-MM-YYYY'));
Now, I would like to determine the earliest date you to today. In this example, the answer should be

29/11/2010

How can I determine it? Any help is appreciated. Thank you.

Hello

Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

Here is a variation on the Kendenny solution:

WITH     got_r_num  AS
(
     SELECT     close_date
     ,     ROW_NUMBER () OVER ( ORDER BY  ABS (SYSDATE - close_date)
                                  ) AS r_num
     FROM    t1
)
SELECT     close_date
FROM     got_r_num
WHERE     r_num     = 1
;

This can be more effective, and it is certainly more flexible where the requirements change.

Tags: Database

Similar Questions

  • problem with access to the image data after you have installed latest windows

    Hi, my name s mayur, I got the problem when I open my photos data, actuly I have a computer laptop sony vaio there and I m a photographer so usually I saved my data in my vista drive was slove, so I upgraded mwan Formate c drive and install windows 7 in there then when I cheack my image data in f drive I cant able to see the thuumbs when I open it in the windows image viewer He told me i dnt have the permission to access

    I did this solutions

    I changed my user to administrator - has not worked
    I changed the security settings and gives full control to user - does not work
    I've changed owner ship - does not work, I reinstalled vista - not worked
    I used hodden administrator - has not worked
    I have attached the HDD in the pc of windows genuen - has not worked
    I opened my hard drive under linux and not worked

    I am a hardware engineer also so can someone tell me what will be the reson when I cheak the propertese folder there are a few user (s16561613) with red qustion mark in the authenticated user, my laptop has a genuien windows and now I have installed the windows is not genuine and I dnt have the original windows. so is this problem related to the license... or is the problem of pricing to someone please help me... the security and

    Hello

    There will not be any support for a pirated copy of Windows. I suggest you install a genuine Windows 7 on the computer and test the issue. If you face the same problem let us know so that we can help you further.

    Reference:

    Windows Genuine

    http://Windows.Microsoft.com/en-us/Windows/genuine

  • Retrieves the CLOB data when you use the keyword DISTINCT to the other columns

    I have a question about how to recover the CLOB data.

    The requirement is something that there are about 20 + columns I need to recover around 5 tables joined in the select statement.
    Since the result set after that join will also duplicate values, I need to use the distinct keyword to filter the result set.
    But there is in the columns of 20 + 2 columns to CLOB data I need to recover.

    Whenever I have use SEPARATE, I'm ORA-00932: inconsistent data types: expected - received the CLOB error.

    I know that this DISTINCT keyword cannot be used for CLOB data types.

    So can anyone here help me with any work around / another way to get the CLOB value in the QUERY SELECT.

    So please help me out in the present.

    Hello
    This forum is for problems using SQL * Developer. If the problem only occurs if you are using SQL * Developer then please give us the SQL code that you are running.
    If it happens in SQLPLUS then, it would be preferable to raise it in the SQL Forum-

    Forum: SQL and PL/SQL

    SQL and PL/SQL

    This forum is for problems using SQL * Developer.

    Kind regards
    Mike

  • Is there a way to access the HTML data as you can do with XML data?

    I am new to AS3 and I'm trying to figure out how to access HTML as you can with the XML data?

    HTML isn't XML, nor is the DOM supported as JavaScript does, so you'll have to go with the typical string operations. If it's on a website, you can use JavaScript to make the analysis of DOM for you in HTML via AJAX loading and working back and forth between JS<->As.

    Otherwise the Interior HAVE only, Regular Expressions are most useful for this. The HTML code in a viable XML structure analysis may be possible when it is not applying the same syntax rules it and is of a dynamic nature. For example, it is perfectly valid to put the content in a page that is not nested inside a tag, for example

    some paragraph

    Some text let only locked in the body. You need detect possible syntactic questions and manage all of them. Channel ops are much easier.

    Any specific markup? you have trouble to detect/work?

  • Check if the entry date lands on a certain "day".

    Hello-

    I am looking for a simple way to check if a date entered in a PDF form lands on a certain "day" of the week (i.e. Sunday).

    If then... nothing happens. However, if this isn't the desired programmed day (i.e. Sunday) then the user will receive a warning similar to: "error, the effective date must be a Sunday.

    The form will be a field called "Start Date" format: dd/mm/yyyy.

    Please notify.

    Thank you in advance.

    Tony

    You can use this code as a custom field validation script:

    event.rc = true;
    if (event.value) {
        var d = util.scand("mm/dd/yyyy", event.value);
        if (d.getDay()!=0) {
            app.alert("Error, the date entered must be a Sunday");
            event.rc = false;
        }
    }
    
  • Questions about to determine the size of the array of data storage with flexibility

    I try to use the CVI function below to load data from .csv file to the table that I was intending to use later:

    filereturnvalue = FileSelectPopup ("c:\\Users\\Desktop\\FileDirectory", "*.csv", "", 'Select the data file', VAL_LOAD_BUTTON, 0, 0, 1, 0, LoadFilePath);

    FileToArray (DATAArray, VAL_CHAR, LoadFilePath, MaxDataSize, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_COLUMNS, VAL_ASCII);

    For the data table "predetermined", it is quite straightforward, because the size of the table is already set.  However, I wonder if there is anyway I could use CVI directly import data and determine the size of the array on the fly?  Which means that the user need not know the length of the data, and it could be determined then to import the file.

    Hello

    for ASCII files, you can do so in any first read the file and counting the newline characters, something like:

    int file_handle;
    int index;
    int size = 0;
    char line_buffer [80];

    If (OpenFile (...) > 0)
    {
    While (ReadLine (...) > 0)
    {
    size ++;
    }
    }
    CloseFile(f) (file_handle);

    This way you can determine the number of rows you have, but you must have an idea of how long a line may be, one number per line or 32000 because you must specify the size of your line_buffer.

    In the next step you analyserions monotube for occurrence of your column separator (say a ;) to determine the number of columns (separators found + 1).

  • DTS moves to the same data store

    Greetings,

    We are short v5.5u1 esxi and vcenter device with DTS clusters installation using thresholds to space only at this time. We do not limit our VM to place records on the same data and store, and in view of the virtual machine can have his records scattered across data warehouses in a cluster of the DS.

    We have many events that seem to do nothing is represented below.  Everyone agrees that something actually happens or vcenter turns his wheels?

    Thank you

    Ron

    Just answered my own question... it has to do with my scattered placement of vmdk. Since the vmx file lives on a given data store, the event shows that the activity... However if you check the DTS tab for the cluster data store you will find the disks associated with the virtual machine on other data warehouses were actually moved.

  • Determine the maximum use of the processor for a virtual computer in the custom user interface

    I want to determine the maximum use of the processor for a virtual computer in the custom user interface.  How can I do this?

    If I use a supermetric, there is no kind of attribute under CPU called "maximum use.

    Certainly, you get points for a long question! Although to be fair, it's probably my fault to feed you so much information to digest at once.

    1. I would say you can do two ways visually. Use the operations > detail view for 'normal ranges' use the upper limit of the normal range as your typical max. You want an absolute peak, add the metric of a graph or observe that highlight high and low watermarks.

    2. There are a lot of ways to display data, but if you want to display a single metric over a period of time, we could use the following widgets [on top of my head]:

    Top - N analysis

    Weather map

    Analysis of distribution of data

    Among these, I think of your desire for a "peak". Who you want real value, which eliminates the weather map. Then, I think that the concept of a 'Summit' and what is the best thing, I think that the 95th percentile... then I came with the widget of data distribution. The decision is ultimately yours given your particular use case.

    3. you can have it apply to several virtual machines - it's just a widget capable of being an independent provider or receiving widget (metrics, DO NOT choose to select resources). Each resource/metric will add to the widget and you can remove them if you like after it is added. You can certainly all the time you visit... It is date and time standard options you have in all the other widgets chart. With the widget data distribution, you want as much time as possible to get an accurate histogram of the cycles of workload.

    4. This is similar to the question above. You can certainly add parameters of individual resource or a DM that summarizes or AVG groups of resources. And as above, the delay is configurable, along with the other graph widgets.

    5. it's part of Q4 - you can sumN or avgN up to any number of resources with a SM, then discovers that SM in the widget of data distribution. When I said container, I mean an application, group resource pool... all that acts as a container parent within the vCOps.

    6. that's correct, SMs calc using data collected last points... aka single period of time. When you are referring to the longest period, I gave you a few examples of the attributes that are composed of several periods of time which are calculated and created by the adapter for VMware vCenter behvaior. In this case, you have the GVA 15 min CPU 1.5; These specific simple mobile GVA can be specific OR a copy using SMs. Next, you will have the chance is to find a way to distribute what you need through a widget [at that time].

    7. the distribution of data is not for export, it is for Visual functions. If you want the data in CSV, just use a typical chart of metrics and export to a csv and calc your own pics, avg, 95th, whatever.

    8. This is a bit of a mix of all your questions, put in place.

    You are right, if you added those 3 VMs, then calc was the 95th of the AVG. Like Q7, you would not export the data of the distribution of data because the raw data points are not - you do not pass the metric to a metric graphics standard and export via csv.

    Take advantage of...

  • Choose the nearest Date of a group of Dates

    Hey people!
    I need to find the closest Date that corresponds to a given Date. The earliest Date of the Group may be lower or higher than the Date that I will try to find.

    I have two columns: VISIT_DATE and ACTUAL_DATE. The VISIT_DATE columns a number of records with different dates, while ACTUAL_DATE column would have only one record per student.

    Here is an example of dates:
    Visit Date      Actual Date
    ==========================
    01-APR-09     19-MAR-10
    16-NOV-09     19-MAR-10
    17-MAR-10     19-MAR-10
    21-MAR-10     19-MAR-10
    04-APR-11     19-MAR-10
    15-JUN-11     19-MAR-10
    19-SEP-11     19-MAR-10
    24-FEB-12     19-MAR-10
    The nearest date you for March 19, 10 are in fact 17 March 10 and March 21, 10. In this case, I would need to pick up the two records. Any help would be greatly appreciated. :-)

    Thank you!
    SQL> select visit, actual
      2  from
      3  (
      4     select visit, actual
      5           ,dense_rank() over (order by abs(visit - actual)) dr
      6     from   t
      7  )
      8  where dr = 1
      9  ;
    
    VISIT                ACTUAL
    -------------------- --------------------
    17-MAR-2010 00:00:00 19-MAR-2010 00:00:00
    21-MAR-2010 00:00:00 19-MAR-2010 00:00:00
    
  • ODI can load data into the planning and REPLACE the existing data?

    Hello
    ODI (9.3.1.1) can load data into the planning and REPLACE the existing data?
    Currently of our ODI by "ADD" load to existing data data - so that is I accidentally run the load twice, it would be double planning numbers. I don't know how to do it to REPLACE so that running more than twice has no effect.

    With the help of the essbase adapter you would use a rule of load, in the State of charge, you can set whether to replace or add to existing values. It is not difficult to pass.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • cannot restore from the previous date says computer is unprotected I just get rid of the virus of audit system

    rid of virus check system but cannot restore the computer to the previous date

    You never said how you got rid of the "System Check" malware. As far as we know, he is still there. Follow these instructions (if you have not already done so):

    Also, as Jose pointed out, there are programs that are designed to interfere with the system restore (Norton is one of the most common). But there are really two questions. First of all, we will treat your malware problem. We can always revisit SR at a later date.
    Finally, even once as Jose pointed out, you NEVER run the system restore after the removal of the malware! Which could only bring him back! That you have to turn it off and then put it again, which will REMOVE all previous restore points. You really all gone!
  • Record JPG with the wrong date

    When I save a PSD file, he recorded with the date and the current time today, but when I "save under" a JPG file, it's save my computer first started when I got it with the date and time. What happens to all THE jpg files. Ones I saved yesterday and today have the same date and time. (I started having to set the date and time in my file name!)

    I'm on Windows 10.

    Thanks in advance for any help!

    The screen 'Open' uses Windows Explorer, so it's definitely a Windows problem.

    Try this:

    On the title bar, just above the list of files/folders (Date, Type, size) right click on the empty part of the bar and look at the context menu.

    You should see a list of the types of possible columns, the checkmarks on the possible options. There are more than 15 available date types. Try to create another column with another date than the simple 'Date' type, you now by checking the box. See if other dates are displayed.

  • Use the case of the Cluster data without DRS storage store?

    Can someone tell me please the use case of the Cluster data without DRS storage store?

    Virtually no,.

    The only one that is useful is the aggregation of resources of data warehouses in a cluster data store. But it is aggregation of resources in its crudest form. When you create a virtual machine and the use of a cluster as the destination data store, you must always select the data store that will store the virtual machine.

    Storage DRS off =

    No calculation of initial investment

    No space load balancing

    No I/O load balancing

    No rule affinity VMDK

    No maintenance mode

    For this purpose a group of data without active DRS storage store is a kind of a data store folder.

  • Find the next available date which is not necessarily the maximum Date

    Morning people!

    I'm trying to find the next date of appointment (including any day after today) for a patient who may not be the maximum date for this person. I am doing this in Oracle Forms. My query works in SQL * more, but does not work in forms.
    FUNCTION get_next_sched_date(P_PATIENT_ID in varchar2) RETURN DATE IS
      v_next_scheduled_date   patient_visit.target_date%TYPE;
    
    BEGIN
      select next_target_date into v_next_scheduled_date
      from   ( select v.*, max(target_date) over (partition by patient_id) max_target_date,
                           lead(target_date) over (partition by patient_id order by target_date) next_target_date
               from   patient_visit v)
      where  patient_id = P_PATIENT_ID
      and    next_target_date >= SYSDATE
      and    max_target_date > next_target_date;
    
      return( v_next_scheduled_date );
    
    EXCEPTION
       when NO_DATA_FOUND then
         return(NULL);
    When I compile in Oracle Forms, it gives me an Error.Encountered symbol "(" quand attend une deles de valeurs suivantes:, de.) "

    I also noticed that Oracle Forms is not taste keywords such as LAG and LEAD. I'm working on Oracle Forms 9i.

    No idea what I'm doing wrong here? Thanks for listening to my harping on Monday. :-)
    Forms [32 Bit] Version 9.0.4.0.19 (Production)
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    Published by: Roxyrollers on August 27, 2012 08:43

    Published by: Roxyrollers on August 27, 2012 08:46

    Hello

    The forms PL/SQL engine is never at the same level as the database one. It seams that you are using an older version of forms.

    François

  • Get the closest previous date you

    First, example table and data:
    drop table CUSTOMER_INFO_TEST;

    CREATE TABLE CUSTOMER_INFO_TEST
    (
    ACCOUNT_NUM VARCHAR2 (40 BYTE),
    PHONE VARCHAR2 (100 BYTE),
    E-MAIL VARCHAR2 (300 BYTE),
    DATE OF START_DT,
    DATE OF CHANGE_DT,
    END_DT DATE
    );



    INSERT INTO CUSTOMER_INFO_TEST VALUES ('BOB', 555-1234', ", TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-05', 'YYYY-MM-DD'), TO_DATE ('2011-01-10', 'YYYY-MM-DD'));
    INSERT INTO CUSTOMER_INFO_TEST VALUES ('BOB', 555-1234', ", TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-11', 'YYYY-MM-DD'), NULL);
    INSERT INTO CUSTOMER_INFO_TEST VALUES ('BOB', 555-1234', ", TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-15', 'YYYY-MM-DD'), NULL);
    INSERT INTO CUSTOMER_INFO_TEST VALUES ('JACK', 555-4321', ", TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-05', 'YYYY-MM-DD'), NULL);
    INSERT INTO CUSTOMER_INFO_TEST VALUES ('JACK', 555-4321', ", TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-09', 'YYYY-MM-DD'), NULL);

    commit;

    I want to query this table with a date range, change_dt, always to give me the lines in the range AND the previous row.
    select * from CUSTOMER_INFO_TEST where change_dt >= TO_DATE('2011-01-05', 'YYYY-MM-DD') and change_dt <= TO_DATE('2011-01-10', 'YYYY-MM-DD')
    
    BOB     555-1234          2011-01-01     2011-01-05     2011-01-10
    JACK     555-4321          2011-01-01     2011-01-05     
    JACK     555-4321          2011-01-01     2011-01-09     
    The foregoing will give me the correct result, a BOB and two jacks, since also while JACK and BOB changes the 5 January.

    But I want the same result, when you select it with 6 Jan as start date,


    This is how I can make it explicit for BOB
    select * from CUSTOMER_INFO_TEST where 
    change_dt >= (select max(change_dt ) from CUSTOMER_INFO_TEST where change_dt <= to_date('2011-01-06','YYYY-MM-DD') and ACCOUNT_NUM = 'BOB')
    and change_dt <= to_date('2011-01-06','YYYY-MM-DD')
    and ACCOUNT_NUM = 'BOB'
    
    BOB     555-1234          2011-01-01     2011-01-05     2011-01-10
    Is this possible without a sub request, and in a statement across the table without specifying the actual table data, as I did with "BOB" in the above statement?

    Edited by: Rydman January 14, 2013 14:39

    Hello

    I think I understand now: you have 2 parameters, range_start_dt and range_end_dt, and you want to find the rows where the change_dt is between these parameters, PLUS you want the last row for each account_number coming before the interval given, if the same customer has lines in the range.

    Here's a way to do it:

    VARIABLE  range_start_dt     VARCHAR2 (10)
    VARIABLE  range_end_dt          VARCHAR2 (10)
    EXEC      :range_start_dt := '2011-01-06';
    EXEC      :range_end_dt   := '2011-01-10';
    
    WITH     got_r_num     AS
    (
         SELECT     account_num, phone, email, start_dt, change_dt, end_dt
         ,     RANK ()       OVER ( PARTITION BY  account_num
                                   ,                    SIGN (start_dt - TO_DATE ( :range_start_dt
                                                                 , 'YYYY-MM-DD'
                                                     )
                                       )
                             ORDER BY        start_dt   DESC
                           )         AS r_num
         FROM     customer_info_test
         WHERE     change_dt     < TO_DATE ( :range_end_dt
                                 , 'YYYY-MM-DD'
                               ) + 1   -- See note below
    )
    SELECT       account_num, phone, email, start_dt, change_dt, end_dt
    FROM       got_r_num
    WHERE       change_dt     >= TO_DATE ( :range_start_dt
                                , 'YYYY-MM-DD'
                           )
    OR       r_num          = 1
    ;
    

    Range_end_dt indicates just the calendar day of the end of the range; in other words: range_end_dt = ' 2011-01-10' means anything at any time, January 10, 2011, until 23:59:59, must be included. Instead of saying you want everything up to and including 23:59:59 on January 10, I find it easier just to say you want everything up to but not including the day after January 10.

    If all change_dts for a given account_num after range_end_dt, then no output for this account_num will be generated.

Maybe you are looking for