To return the rows when there is a certain difference between dates

Hello.

I have a table called

#president #.
pres_name
BIRTH_DATE

and

#winner #.
name
year_elected

I wish I had all the presidents returned, who where under the age of 50 years when they elected.
year_elected is only a 4-digit number; 1924 etc. While birth_date is 2001-01-01 etc.

I have no idea how to make this work, ive tried substr and one things and a lot of other weird (prob wrong).
select distinct p.pres_name, substr(p.birth_date, 0, 4), w.year_elected
from president p, winner w
where p.pres_name = w.name
I did this witch query will show me all the presidents and their dates for the election and the date of birth. Now I just want something that returns only the guys where there is a difference in value 49 (?) between birth_date and year_elected


Johan

Edited by: user10248089 02-Oct-2008 00:42

Based on information from Dave on presidents being elected the first Tuesday of November...

SQL> with president as (select 'Bob' as pres_name, to_date('1/7/1934','DD/MM/YYYY') as birth_date from dual union all
  2                     select 'Fred', to_date('13/5/1950','DD/MM/YYYY') from dual union all
  3                     select 'Jim', to_date('21/12/1960','DD/MM/YYYY') from dual)
  4      ,winner    as (select 'Bob' as name, '1979' as year_elected from dual union all
  5                     select 'Fred', '2005' from dual union all
  6                     select 'Jim', '2000' from dual)
  7  --
  8  select p.pres_name, p.birth_date, w.year_elected
  9        ,trunc(months_between(next_day(to_date('01/11/'||w.year_elected,'DD/MM/YYYY'),'TUE'),birth_date)/12) as age
 10  from president p join winner w on (p.pres_name = w.name)
 11  /

PRES BIRTH_DAT YEAR        AGE
---- --------- ---- ----------
Bob  01-JUL-34 1979         45
Fred 13-MAY-50 2005         55
Jim  21-DEC-60 2000         39

SQL>

And the WHERE clause can be applied based on the same calculation as described in the age column

Tags: Database

Similar Questions

  • Why apple is only stream at 256kbs? ! ? ! Anyone know if the upgrade is in the works? There is a significant difference between the quality of the sound between 256 and 320 on spotify.  If they do not upgrade it is switch it on Spotify.

    256kbs? ! ? ! It will be upgraded to 320?

    Here nobody Apple plans for the future. Submit your comments here:

    http://www.Apple.com/feedback

  • How to hide a column in the report when there are only zeros.

    Hi Experts.,.

    Is it possible to hide a column in the report when there are only zeros.

    Thanks in advance
    Vincent

    Vincent Krishna wrote:
    Hi Experts.,.

    Is it possible to hide a column in the report when there are only zeros.

    Thanks in advance
    Vincent

    No out-of-the-box, but there are several workaround solutions if you want to continue an any of them:

    (1) use a view selector. A single report will be a pivot table with the column, the other will have the same report less column. Users can switch reports.

    (2) use a column selector. The two choices would be this column or an empty space. If white is chosen (because the user has no values), the column "will disappear" according to the report.

    (3) guided use NAV. This method involves the intervention of the user. Build a small report using the single column and put a filter "is not equal to" 0. Because there is only a single column, so all lines are 0, the report returns no rows.

    Use this report in the properties of guided navigation from one section of the dashboard. Assign to this "If the report returns lines" and put the report that contains the column in this section. Now add another article on your table edge and in the properties of guided navigation of this section, set on "If the report will return no rows" and it points to the small report as well. In this section, put a second version of your report without the column in it.

    When the column contains all zeros, the second section with column will not display in it; the first section is not displayed. When at least a line contains a value not zero, the first section is displayed with the column, and the second part will not be.

  • SELECT returns no results when there is a default namespace definition inXML

    Hello

    I have a problem that my select returns no results when there is a default namespace definition in my XML file.

    I'm using oracle 11g release 1

    XML file that is stored as a binary XML:

    < SIMS xmlns = "http://sims.ics.muni.cz" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://sims.ics.muni.cz jh_sims_matricni_vystupy_or.xsd" >
    < Vystup Datum = '2006-07-18' type = '2' Nazev = 'Last etapy' PocetStudentu = '1' PocetStudii = '2' >
    < Student RodneCislo = "8001011001" >
    Petr < name > < / name >
    < / student >
    < / Vystup >
    < / SIMS >

    This select return no results:
    SELECT s jh_sims_bin_no_schema student.jmeno, XMLTable ('/ the SIMS/Vystup/student ' PASSAGE s.OBJECT_VALUE jmeno PATH VARCHAR2 COLUMNS (10) 'Name') student

    When I remove the definition of default namespace (xmlns = "http://sims.ics.muni.cz") everything works well and even SELECT returns "Petr". When the file is stored in the storage object relational everything works great too!

    < SIMS xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://sims.ics.muni.cz jh_sims_matricni_vystupy_or.xsd" >
    < Vystup Datum = '2006-07-18' type = '2' Nazev = 'Last etapy' PocetStudentu = '1' PocetStudii = '2' >
    < Student RodneCislo = "8001011001" >
    Petr < name > < / name >
    < / student >
    < / Vystup >
    < / SIMS >

    Thanks for any help!

    Jan Hruby

    Lazy response:
    See the post "How to declare mapping prefix to namespace with XMLTable()?" in the {: identifier of the thread = 410714} stickied to the top of this forum.
    aka
    XMLTable (XMLNamespaces (...), "/ the SIMS/Vystup/student")

    Published by: A_Non on June 16, 2010 13:07
    Beat in a few seconds

  • "There is a time difference between the client and the server"

    Unit 4.0.3

    Everything worked very well, and all of a sudden, I'm not able to connect to the server unit using any domain account. When I enter the domain/name username/password, I get this error message:

    ************************************************

    The system is unable to log on due to the following error:

    There is a time difference between the client and the server.

    Try again or contact your system administrator.

    **************************************************

    I can use the same domain account (unityinstall) and the journal in other machines. I can connect the machine to the unit using a local account. There is no time difference between the DC server and unity.

    Need help,

    Thank you

    Partha

    Log on to your LOCAL computer using an account that has privileges

    At the command prompt, type the following:

    NET TIME ancien_mot_passe/set

    Found this on the MS site:

    Cannot open a session if the Date and time are not synchronized

    http://support.Microsoft.com/default.aspx?scid=kb;en-us;232386&product=Win2000

  • How Suprass a presentation of the State when there is no data

    Hello community,

    I have a Sql query that gives me the list of the pretreatments that does not have the corresponding post processing

    Sometimes this query returns no rows

    At this time is there a way I can suprass the the whole layout of the printing of the report

    I use oracle reports 6i

    Please help me!

    Create a column of synthesis (say "CS_TotalRecords") at the level of the report and set the following properties:

    Function: County
    Source: column that cannot be null (if the report displays data)
    Reset to: report

    Create a format trigger frame to the outside (all the object in this and the image you want to hide) and write the following code:

    BEGIN
    IF NVL(:CS_TotalRecords,0) = 0 THEN
    RETURN (FALSE);
    END IF;

    RETURN (TRUE);

    END;

    I hope this helps.

  • What return dbms_sql.last_error_position when ther is no error

    Good grief, good afternoon, good evening
    I need your i read all documentation Abu dbms_sql.last_error_position there receive no information on this subject this function to return when he exist' Error n, can any body help me
    that you for your time,
    MI excume English

    Michael:

    It's kind of strange. I ran your code exactly as you have it posted and got the same result, for the first time. After running it a few times, he started to give 0 as the last position of the error in a reliable way, even after my closing session and start a new. I had to go to another database to replicate the result. Once a database returned the correct result, it seemed to make for any session of anywhere and apparently for all users. I don't have a database that I can bounce at the moment, but I wonder if it survives a reboot.

    O/P
    If there is an error in the sql statement that you are monitoring, it will throw an error like it normally would.

    SQL> DECLARE
      2     c   INTEGER := DBMS_SQL.open_cursor ();
      3  BEGIN
      4     DBMS_SQL.parse (c, 'select * form dual', DBMS_SQL.native);
      5     DBMS_OUTPUT.put_line ('Last Error: ' || DBMS_SQL.LAST_ERROR_POSITION ());
      6     DBMS_SQL.close_cursor (c);
      7  END;
      8  /
    DECLARE
    *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    ORA-06512: at "SYS.DBMS_SYS_SQL", line 909
    ORA-06512: at "SYS.DBMS_SQL", line 39
    ORA-06512: at line 4
    

    In order to capture the position of the error using DBMS_SQL. LAST_ERROR_POSITION, you must do so within an exception like this block:

    SQL> DECLARE
      2     c   INTEGER := DBMS_SQL.open_cursor ();
      3  BEGIN
      4     DBMS_SQL.parse (c, 'select * form dual', DBMS_SQL.native);
      5
      6     DBMS_SQL.close_cursor (c);
      7  EXCEPTION
      8     WHEN OTHERS THEN
      9        DBMS_OUTPUT.put_line ('Last Error: ' || DBMS_SQL.LAST_ERROR_POSITION ());
     10        DBMS_SQL.close_cursor (c);
     11        RAISE;
     12  END;
     13  /
    Last Error: 9
    DECLARE
    *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    ORA-06512: at line 11
    

    So, to answer your question explicit "I need know what back when ther appears no error", if it does not throw an exception he analysis successfully.

    By the way, if you are taking into the sql statements to analyze of outside the database (for example a statement entered on a form or a dynamic sql statement, you want to be really sure that the statement is 'clean' ", because according to the documentation, the procedure of ANALYSIS ' analyzes the instruction given in the given cursor.) All the instructions are analyzed immediately. In addition, the DDL statements are executed immediately when analysis. ». you could leave yourself open to a nasty sql injection.

    John

  • My helmet is bright red, and the speakers does not work, when I try to adjust the volume when there is no headset/speakers in, there is a sign of the cross as the symbol of the volume where the places are supposed to be, macbook pro retina display

    My helmet is for some time, as the eye of the terminator, glowing and speakers have not worked since. I need to plug headphones or external speakers. Whenever I try to adjust the volume when it shows just a cross symbol under the sign of the volume, where small squares usually are (see below)

    Is there a way to fix this? Some other similar forums tell me to try to manually move a switch in the audio jack, but I can't seem to find such a change and the thing that seems most like a light switch, does not move.

    Can someone please help?

    Thank you

    Your audio output is stuck in optical mode, this is the red light.

    The solution is to try to insert and remove the plug a dozen times or more in the hopes of convincing making fall out of optical mode and in electric mode.

  • Why open the pictures when there is nothing to download

    Why Photos opens when the iPhone is connected to the computer and there are no photos to download? I use not iCloud for my photo library.

    With iPhoto, if there is nothing to download, it was not open.

    He is an annoying extra step to close pictures when it is not necessary to be open to all. I find no preference in iTunes or Photos to prevent that from happening.

    (I have this set in the editing category since nothing else fit)

    Photos (or iPhoto) has obviously no idea if there are new photos to be imported until the program opens and focuses on what is on the phone and your Mac.

    While the phone is connected and photo is opened in the upper left corner, uncheck the box for pen pictures when the unit is plugged - this will make the manual import ony when you want to

    LN

  • To return the rows less value and the next line of the value 'hungry '.

    I'm about 10 gr 2

    My best here trying to just do a single SQL rather than writing PL/SQL. I know it's possible, that I'm not good at SQL past oracle 8i. I have searched the forums and found many examples for the beaches and dates to help connect by level, but nothing specifically related to the scales of value.

    Basically I have a table with the number of employees and approval limits:
      with  a as (select 12345 emp_no,1000 val from dual 
                     UNION select 12346,5000 from dual UNION select 12347,9999 from dual)
      select * from a 
    Returns
    EMP_NO  VAL
    ------- ---------------
    12345   1000
    12346   5000
    12347   9999
    I want a SQL statement that returns all lines less that the & parameter, but also the line of 'the child' who, as "greater" as the largest value of the value to be less than the value parameter.

    It is probably easier to show examples.

    If & parameter was broadcast then 2342
    EMP_NO  VAL
    ------- ---------------
    12345   1000
    12346   5000
    If & parameter was broadcast then 7898
    EMP_NO  VAL
    ------- ---------------
    12345   1000
    12346   5000
    12347   9999
    If & parameter was broadcast then 10
    EMP_NO  VAL
    ------- ---------------
    12345   1000
    If & parameter was broadcast and 788777
    No rows returned 
    Basically, I'm trying to return the chain of trust that a Bill will have to cross before it can be approved until the & amount of parameter.

    Tried to connect, even lead function. Request for assistance from the gurus to do things. Hope that this could also help others.

    Published by: user13007502 on February 8, 2012 04:56

    Published by: user13007502 on February 8, 2012 04:58

    Hello

    Here's a way (very similar to what Peter posted previously):

    SELECT     *
    FROM     a
    WHERE     val     <= (
                   SELECT  MIN (val)
                   FROM     a
                   WHERE     val > 3000     -- or whatever
                 )
    ;
    

    If the parameter is greater than any what val in the table, then the scalar subquery terturn will be NULL, and the WHERE clause will never real.

  • To return the rows

    Dear members
    I need a function to return the lines

    This is my sample data
    ID     DESC               UNI          CODE
    1     BO_USER               40352          A
    2     BO_USER1          40353          D
    3     BUSINESS_PARTNER1     40353          F
    4     BUSINESS_PARTNER2     40354          R
    5     BUSINESS_PARTNER3     40354          N
    If I pass the id and United as an input value, that I need to get all of the line as well

    Create or replace function ((ID en varchar2, UNI en varchar2))
    return
    l_val;


    Itry to serve table tpe
    and the type as object and call that function, but when I try to call this value, I am not able to
    use of the name of the function instead of this I need to use
    slect * form the name of the table function

    If somene post a few syntax how to I will follow

    regads

    Hello

    You can create the function with the return type as table % rowtype. And even you can call this function in a block anonymous plsql and display the desired value.
    But in sqlplus, you won't be able to use it as a sql statement since it is the unsupported data type.

    This was based on my understanding of the declared scénarion. Let us know if its different

    SBH

  • How to create a date for the restoration of the system when there is no previous restore date.

    When you try to create an earlier date for the restoration of my pc (windows 8.1) for the first time (no previous restore point) the only option I get is to create point of restoration of the date and time of today. I need to restore to an earlier date. Does anyone have a solution?

    You can click on the box "Show more restore points" to view the older, but they may not be as reliable (they may fail to apply or they may not actually work).

    If you do not see the box to check, or the oldest, so it is not of the ancients still show.  If this is the case, you will need to use the 'Refresh PC'.

  • What are the variables system will report to the LMS for the completion of the course, when there is a test (developed with conditional actions manually).

    I developed a course where the learner must pass the test to complete the course in LMS.

    I developed a quiz (quiz developed using conditional actions) manual.

    Now I want my course should show in LMS completion status, only after the learner either in quiz.

    How do my report course to the LMS of completion criteria?

    I use 6 Captivate and LMS is CSOD.

    I tried to include in quiz option is not working for me... anyone have any ideas to fix this?

    Thanks in advance

    Have you checked that Panel Advanced Interaction, please? All of the marked objects that are indicated to be added to the total of the Quiz are part of all system Quizzing variables. Insert a slide to score in your project and check the result when previewing in the browser or after publication.

  • How can I remove the audio when there is no cutting to click on?

    I did several films, however, the latter has a problem. He didn't there is audio that plays at the end of my movie, but no visible cutting (video or audio) for me, right click and delete.  It's as if the element is missing, but audio plays for five or six seconds, not related to any video.  I can't highlight the audio delete (there is no image showing same) and I cannot reduce the volume level here either.  I think that there is a bug in the last update of the components of Prime Minister.  Any ideas?  Or I have to start all over in the creation of my film?

    todde

    Thanks for the reply with screenshot.

    On your screen, you are in the quick workspace. Please go to the Expert workspace where you can get a better view of what's going on

    and therefore have more control.

    It expanded to display the titles and their content will be a definite advantage.

    We will follow to your results.

    RTA

  • View the hours and minutes to obtain a difference in date

    I can calculate a time difference by subtracting two date values. This translates into a numeric value. My question is how to return the calculated value in a date/time again?

    Hello

    but does Oracle provide a built-in method of doing this?
    

    Yes he did :)

    A simpler than my last request version (well of course assuming you have the TIMESTAMP data type and no date datatype)

    SELECT EXTRACT(DAY FROM &END_DATE - &START_DATE) * 24 +
           EXTRACT(HOUR FROM &END_DATE - &START_DATE) || ':' ||
           EXTRACT(MINUTE FROM &END_DATE - &START_DATE)
      FROM DUAL
    

Maybe you are looking for

  • How to cancel a free trial of 3 month individual membership of Apple's music.

    Hello, I am subscribed to a free 3-month trial APPLE MUSIC MEMBERSHIP individual. It will expire on 15/08/16, and then I will be charged $9.99 for the period. I don't want to take this subscription. Therefore, I am trying to cancel it. I can't seem t

  • Cannot find multimedia drivers for Qosmio PQF20E

    I formatted a Qosmio PQF20E and put Windows XP on it. I want to install the drivers for the laptop and I have 2 left with yellow symbols under other devices... Multimedia video controller and multimedia Audio Controller. I'm unable to locate these on

  • Satellite A50-522: DRIVER_IRQL_NOT_LESS_OR_EQUAL when shutdown XP

    Hello When I stop my laptop TOSHIBA SA50-522, I got a blue screen with the textSmall Nyctale DRIVER_IRQL_NOT_LESS_OR_EQUAL may be the problem?I hope you can help me. Thank youRubby

  • Reinstalling Vista on my Inspiron 1720

    For the past 2 days now ive tried to reinstall Vista.  When im at "complete installation" the green progress bar does not move.  After about 30-40 minutes, the screen will turn black, but I'm still able to move the mouse. If anyone has a solution, or

  • Web authentication

    / * Style definitions * / table. MsoNormalTable {mso-style-name : « Table Normal » ; mso-tstyle-rowband-taille : 0 ; mso-tstyle-colband-taille : 0 ; mso-style-noshow:yes ; mso-style-priorité : 99 ; mso-style-qformat:yes ; mso-style-parent : » « ;" ms