Delicate issue of SQL

SQL experts: I need to write a query to search for empid that has at least one fake folder

example: empid 1 is bad since its start_date (record 3) 05/01/2013 is before it expires 15/02/2013 (sheet 2). Similarly, empid 3 is bad since 12-12 - 2012(record 7) of start_dt is before its date of expiry 31/12/1999 (chart 6).

There may be a number of entries for each empid.

empid start_dt               end_dt
1     01-01-2013          01-10-2013
1     01-11-2013          02-15-2013
1     01-05-2013          12-31-9999

2     01-01-2013         12-31-9999

3     01-20-2012         1-15-2012
3     01-31-2012         12-31-9999
3     12-12-2012         01-01-2013
I would be grateful for any input?

Oracle Version 11.2.0.3

Thank you
Kevin

Published by: Kevin_K on March 5, 2013 15:53
select distinct
 empid
from (
select
 empid
,case
 when lag(end_dt,1, start_dt) over (partition by empid order by start_dt) > start_dt
 then 1
 end flag
from your_table
)
where
flag = 1

Edited by: chris227 the 05.03.2013 16:32

Edited by: chris227 the 05.03.2013 16:32

Tags: Database

Similar Questions

  • During database migration issues in SQL Serever

    Hello

    In single database migration in SQL Server, what are all the possible questions, that allows us to get.

    Please help me on this.

    RD

    SQL server questions should be asked on the Technet site

    http://social.technet.Microsoft.com/forums/en-us/home

  • Base date regarding the issue of SQL

    create table emp (empname varchar2 (35), join_date date);

    Insert into emp VALUES ('JOHN', TO_DATE (March 23, 2005 09:00 ',' DD-MON-YYYY HH24 '));

    insert into emp VALUES ('HANS', TO_DATE (February 14, 2012 14:00 ',' DD-MON-YYYY HH24 '));

    commit;

    SQL > alter session set nls_Date_format = 'DD-MON-YYYY HH24. "

    Modified session.

    SQL > select * from emp;

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    HANS FEBRUARY 14, 2012 14:00

    To find all employees who have joined the date of March 23, 2005, I need to do the following.

    Y at - it a shorter version for this request?

    SQL > select * from emp where JOIN_DATE > TO_DATE (March 23, 2005 00:00 ') AND JOIN_DATE < TO_DATE (March 24, 2005 00:00 ');

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    Hello

    N.Page wrote:

    create table emp (empname varchar2 (35), join_date date);

    Insert into emp VALUES ('JOHN', TO_DATE (March 23, 2005 09:00 ',' DD-MON-YYYY HH24 '));

    insert into emp VALUES ('HANS', TO_DATE (February 14, 2012 14:00 ',' DD-MON-YYYY HH24 '));

    commit;

    SQL > alter session set nls_Date_format = 'DD-MON-YYYY HH24. "

    Modified session.

    SQL > select * from emp;

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    HANS FEBRUARY 14, 2012 14:00

    To find all employees who have joined the date of March 23, 2005, I need to do the following.

    Y at - it a shorter version for this request?

    SQL > select * from emp where JOIN_DATE > TO_DATE (March 23, 2005 00:00 ') AND JOIN_DATE< to_date="" ('24-mar-2005="">

    EMPNAME JOIN_DATE

    ----------------------------------- -----------------

    JOHN ON MARCH 23, 2005 09:00

    You mean > = instead of >, to register the join_dates that are exactly 12:00:00 AM on March 23.  Keep< at="" the="" end;="" you="" don't="" want="" anything="" from="" march="" 24,="" and="" you="" don't="" want="" between="" for="" the="" same="">

    What you posted is the fastest way.  Use DATE instead of TO_DATE literals, it is a bit shorter and just as fast.

    SELECT *.

    WCP

    WHERE join_date > = DATE '' 2005-03-23

    AND join_date<  date="">

    ;

    May be the shortest path (which will be slower):

    SELECT *.

    WCP

    WHERE TRUNC (join_date) = DATE '' 2005-03-23

    ;

    It's slower because we need to call a function for each row in the table, and (potentially much larger) this means that you cannot use an index on join_date.

  • What is the right answer, is that this issue is sql?

    Hello.. Please I need a correct answer to this question...

    See the exhibition and examine the structure of the PRODUCTS table.

    Using the PRODUCTS table, you publish the following query to generate names, current list prices, and

    price list for all these products whose list price falls below $10 after that a discount of 25% reduced

    on this subject.

    SQL > SELECT prod_name, prod_list_price,.

    prod_list_price - (prod_list_price *. 25) "DISCOUNTED_PRICE".

    PRODUCTS

    WHERE discounted_price < 10;

    The query generates an error.

    What is the reason of the error?

    Has the parentheses should be added to frame the entire expression.

    B - double quotes should be removed from the column alias.

    Column alias C - replace it with the expression in the WHERE clause.

    Alias column D - The should be capitalized and closed with the double quotes in the WHERE clause.

    Took me 5 seconds to see that in Google: alias in where clause that exactly answers your question.

  • issue backup SQL vCenter

    Can I backup the database Sql 2005 of the vCenterserver with a netbackup client like truncates logs then.

    Hello

    Honestly, I just create a SQL job to do the backup of the database and then simply leave netbackup backup your sql backup.  I did a post on how to make a backup of the database of Veeam, but the same thing applies to vCenter - it's just what I'd do...

    http://blog.mwpreston.NET/2011/11/28/Dr-for-your-Dr-solution-get-a-SQL-backup-of-your-Veeam-backup-replication-database/

  • Issue of SQL Plan Management

    Hello

    I have a question concerning the presence of 'Accepted' indicator (values or NOT) that is displayed by the function dbms_xplan.display_sql_plan_baseline.

    It is my understanding of the documentation of Oracle SQL plan does not become part of a plan SQL database until it is accepted by the process of evolution or manual loading in the base line. How is it possible to have a plan to be part of a reference that is not accepted? If the dbms_xplan.display_sql_plan_baseline function is used to display more than plans that are in a reference database and that are only in the story?


    Thanks for your thoughts on this.

    Richard

    PS. I use Oracle 11.1.0.7

    Welcome to the forum!
    >
    How is it possible to have a plan to be part of a reference that is not accepted? If the dbms_xplan.display_sql_plan_baseline function is used to display more than plans that are in a reference database and that are only in the story?
    >
    View code that you use to call the function and the result you get.

    Depending on how you call the function, and what plans are available, you will get different results. For example
    >
    plan_name
    Name of plan. It identifies a specific plan. Value default NULL means that all the plans associated with identified SQL statement are explained and displayed
    >
    You specify this setting? If this isn't the case, then all THE plans could include plans that have not been accepted.

    Section 15.5 display SQL Plan baseline in the Performance Tuning Guide contains an example of this and displays two plans: an accepted and the other not.
    http://docs.Oracle.com/CD/E11882_01/server.112/e16638/optplanmgmt.htm

    It's really the history display that includes all plans.

  • I need issue of SQL/PLSQL for practice

    Hi all

    I need to question of SQL/PLSQL for practice; could everything on send me the URL.

    I need only the PDF file.

    Thank you
    Gregory

    Here is the link for the link of PL/SQL oracle

    http://www.Oracle.com/pls/db111/portal.portal_db?selected=5&frame=

    IN the section of SQL and PL/SQL language, there is the language Pl/SQL.. PDF reference .you can download... its preety good to start.

  • Delicate issue on the field of the camera screen.

    I really like the camera of 4.6 code sample. But I come with a question:

    After I put the camera in full-screen opening: _videoControl.setDisplayFullScreen (true);

    Is it possible to draw anything on the top of the camera preview that is full screen?

    No, you can't paint on top of this preview field.

  • Delicate issue blackBerry Smartphones read carefully - without restoring all I can just restore my notes from phone?

    My 9900 works perfectly and I don't want to give it the bad food or any other restoration, what I want is my memos so I saved in the previous restoration. Help?

    Download a program called MagicBerry woot woot answered my own question.

  • Issue of SQL Hieraerchical

    Oracle Enterprise Version 11.2.0,.3

    I need to write a hierarchical query to give me registration with the version of henriq # if the record is a child of a parent. If the folder has no children so I need the parent to save himself.

    {code}

    Employee:

    ID ParentId Version #
    11
    21
    322
    433
    544
    61
    755
    81

    For example:

    so I need to show the sheet 1 1 recordID did no parentid

    RecordID 8 has no parentid so I need to see the card 8

    RecordID 2 has 4 levels of children, I need to get the record with max version 5 i.e Recordid 7

    2            1

    3-2-2

    4-3-3

    5-4-4

    7-5-5

    Expected result

    ID Parentid Version

    1            1

    7-5-5

    8            1

    Hello

    Maybe you want something like this:

    SELECT id

    parentid

    version #.

    The EMPLOYEE

    WHERE CONNECT_BY_ISLEAF = 1

    START WITH parentid IS NULL

    CONNECTION BY parentid = PRIOR id

    ;

    The output I get from your sample data is:

    PARENTID EXTRA STRONG VERSION

    --- ---------- ----------

    1                    1

    1                    1

    7          5         5

    6                    1

    8                    1

    Did you mean to have 2 identical rows in the table with id = 1?  If so, but you only you one of them appear in the results, use SELECT DISTINCT.

    Why you don't want to ID = 6 in the output?

    When you talk about "max version" do you mean the highest value, or the deep hierarchy?  In other words, if you have changed the row with id = 4 to be

    INSERT INTO EMPLOYEE (id, parentid, version #)

    VALUES (4, 3, 300) - version # was originally 3

    /

    the version 'max' in the output would still be 5, or would it be 300?

  • Lightroom delicate issue, need HELP :)

    In short, I have a MAMIYA ZD I am only able to tie with the old and shit PhotoStudio software mamiya digital Mamiya.

    My idea is to open lightroom with the folder in which the AMD transfer the pictures to see them immediately in LR, but I can't find a way to synchronize this folder refresh continuously, I have to manually synchronize folder, import new images.

    Any idea of a solution?  Thank you

    Greg

    is this what you need?

    Automatic import of photos in Lightroom

  • Performance issues for sql developer

    1. DB connection leaving open a SQLNavigator has no impact on the resources of the DB and the performance?

    If you got all the lines, then should be no impact on the database.

    You can close the table editor/query results grids just to be sure if you do not know.

  • Issue of SQL, to learn

    Can someone explain to me what / / means?

    CASES WHERE 1 = 1 THEN ELSE 0 0 END as the column alias_de_colonne

    or

    CASES WHERE 1 = 1 THEN 0 1 END as the column alias_de_colonne ELSE

    ?

    There are 3 tables that join each other and I select a few columns of A, B and C,.
    but then there are over this case and it is not referencing a Table at all, and I'm trying to
    to understand what this does? :-) with that 1 = 1 company, thank you!

    Thank you!
    CASE WHEN 1=1 THEN 0 ELSE 1 END as column column_alias
    

    Well, if I ask you "true or false: 1 = 1'? What would you say?

    A condition like '1 = 1' is used when you want to always set to TRUE. Similarly WHEN 1 = 0 will always evaluate to FALSE.

    In the code above "0" will always be returned since 1 'will always be equal to 1'. The ELSE and the rest is just to complete the CASE statement if you do not have a syntax error.
    This query returns a line

    select * from emp where 1=1 and empno = 7369
    
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
    7369,SMITH,CLERK2,7902,12/17/1980,4567,,20
    

    and it does not work

    select * from emp where 1=0 and empno = 7369
    
  • E4x delicate issue of filter?

    Hello
    I Googled it for a day. I have not found answer. I have an xml with inlets tag man node. I want to tag entries based on a filter condition. Here is a sample of my xml data.


    I want to search all the nodes of the tag with the given string somewhere in the value. For example, I want to find all nodes with 'book' in them. All of the examples of e4x on the net talking about filtering based on the attribute of the current node or child. But not the value of the node it self. I am newbee actionscript. I wonder if there is a way to do it. I know that I can use for the loop and iterate on each node. I'm looking for the e4x expression that made it easily.

    var myroot:XML =... / / the XML root, I got to the end
    var tags: XMLList = myroot.tag. (??????????????????????); What is the condition of filter that does

    Thank you
    Videoguy

    I thought about a way to do this. Thanks for your example that has a call to text(). That's what I did.

    var tags: XMLList = myroot.tag. (text () .indexof ("book") > = 0);

    It made me what I am looking for.

  • I found flaws in all of the calendars and the scientific calculators of Apple products. How can I send you my report pages 20 as a matter of course. Who should I go. This is a real case, and I am willing to work with Apple on this issue.

    Dear Sir/Madam,

    Topic: Default in some Apple products (important issue).

    This is not an unsolicited idea or suggestion (Please read)

    First of all, allow me to introduce myself as a teacher of mathematics, with more than 20 years of experience in the teaching of mathematics in Jordan.

    I take the liberty to write to you on a very delicate issue regarding the above topic. I'll try to be direct and fertilizers to point.

    Eight months ago, I have established contacts with the customer at Apple and succeeded to in explaining my intention to work with Apple on the flaws I found in all the following Apple products:

    -Scientific calculators built into the Apple iPhones and other products like Mack book pro (13 keys/operators applying bad mathematical concepts).

    -Calendars integrated into Apple iPhones and iPads (after a certain date).

    -Most of the calculators downloaded on Apple iPads (application).

    With my main concern during the final user, I already have reports submitted to Apple on the six keys with solid evidence and evidence supported with excerpts from various reliable resources that are no doubt as to the failure of these keys. I also presented copies of the date on which the calendar goes off track.

    Now iPhones for new generation of Apple (6s and 6 s-Plus) have already been launched on the market, keeping the same flaws, I decided to start contacts with Apple once again, hoping to succeed in reaching the right people at Apple to continue my rage in finding that the right to address this issue. I hope that you will respond positively.

    My worries and concern are oriented towards the end user and, in particular, students who take the responses of these calculators for granted when they are wrong and they don't realize.

    I have prepared a 20 page report although detailed on these defects and how to correct function solid evedence of reliable math textbooks. I'm ready to send this report to the person/department concerned, on which they can check and verify my claim with any or all of the following:

    ·       Apple/mathematicians engineers.

    ·       The mathematics books that are published by well known/good reputation

    publishers.

    ·        Calculators Casio or TI as the most reliable calculators in the world.

    ·        Reliable sources of mathematics of the internet.

    ·        Presentations power point math on YouTube.

    .        Math teachers well known working in renowned universities

    ·        American Mathematical Society.

    I reiterate my willingness to cooperate on the question above so that the genetions coming Apple products will be free by all means!

    I look forward to your positive reply,

    Sincerely,

    Nael

    < personal information deleted by host >

    This is a user to user forum.  Your message must be addressed to the Apple company.  Maybe a letter to Cupertino, California, is in order.  Your letter will receive no valid response here about your concerns.

    Ciao.

Maybe you are looking for