Question query - binding time span for Point-in-time references

I'm pulling historical data in a table for the duration of the recordings, using a reference point-in-time. I succumbed.

I threw some examples of tables and data to illustrate what I'm looking for:
Create Table EmployeeInfo (
       id Number(10,0),               -- Employee ID Number
       Name VarChar2(32 Byte),        -- Employee Name
       CurrentShift VarChar2(2 Byte)  -- Current Employee Shift
       );

Create Table ShiftChanges (
       id Number(10,0),               -- Employee ID that this shift change record is for
       ChangeDate Date,               -- Date that this Change Took Place
       OldShift VarChar2(2 Byte),
       NewShift VarChar2(2 Byte)
       );

Create Table TimeCard(
       id Number(10,0),               -- Employee ID Number for this Timecard
       WorkDay Date,                  -- What Day is this Timecard for?
       Hours Float(63)                -- Number of Hours worked.
       ); 

COMMIT;
INSERT INTO EmployeeInfo VALUES (100,'John Doe','Days')
INSERT INTO EmployeeInfo VALUES (101,'Jane Doe','Days');
INSERT INTO TimeCard VALUES (100, to_date('01012010','ddmmyyyy'), 10.5);
INSERT INTO TimeCard VALUES (101, to_date('01012010','ddmmyyyy'), 10);
INSERT INTO TimeCard VALUES (100, to_date('02012010','ddmmyyyy'), 9);
INSERT INTO TimeCard VALUES (101, to_date('02012010','ddmmyyyy'), 10.5);
INSERT INTO TimeCard VALUES (100, to_date('03012010','ddmmyyyy'), 8);
INSERT INTO TimeCard VALUES (101, to_date('03012010','ddmmyyyy'), 7);
INSERT INTO ShiftChanges VALUES (100, to_date('02012010','ddmmyyyy'), 'Nights', 'Days');
COMMIT;
I could do a query such as:
SELECT TC.id, 
       EM.Name, 
       TC.Workday, 
       EM.CurrentShift AS Shift
FROM   TimeCard TC,
       EmployeeInfo EM
WHERE  (TC.ID=EM.ID(+));
But he won't give me the history , only the current turn. Since John Doe last travel on Jan 2 nights to days, the query above would not reflect it.

I tried to join the historical table using a less - than operator. This does not work for more than one line may be returned.
SELECT TC.id, 
       EM.Name, 
       TC.Workday, 
       SC.NewShift AS Shift
FROM   TimeCard TC,
       EmployeeInfo EM,
       ShiftChanges SC
WHERE  (TC.ID=EM.ID(+)) AND
       (TC.ID=SC.ID(+) AND TC.WORKDAY<=SC.WORKDAY(+));
The problem is that you have to parse multiple records in a table in order to obtain accurate historical data for the other.

The following SQL script {color: green} works {color} - if the values are defined in advance.
DEFINE EMPID=101;
DEFINE CHGDATE=to_date('01/01/2010','dd/mm/yyyy');
SELECT SQ.Shift
FROM   (SELECT  ShiftChanges.NewShift AS Shift,
                RANK() OVER (ORDER BY ShiftChanges.ChangeDate DESC) R
        FROM    ShiftChanges
        WHERE   ShiftChanges.id = &EMPID AND
                ShiftChanges.ChangeDate <= &CHGDATE
        ) SQ
WHERE R = 1
However, I was unsuccessful in adapting the tables in the example I provided. If I insert the query as a subquery inline* in the statement select, it won't work, because the criteria is nested two levels down, and I can't get the values of parent in the first level.

I didn't think in a way I can do this by using a subquery nested - I keep running into this problem - how you link the data with a reference point-in-time.

Any ideas / illuminating thoughts?

Thank you

-----
{size: 8} _SELECT * FROM V$ VERSION information: _
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
"CORE 9.2.0.8.0 Production."
AMT for 32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
{size}

user10879184 re-written the original message on March 29, 2010 13:21 to take into account suggestions made by poster.

On the drive home, I realized that we had to refer to the OldShift rather than NewShift to cover cases where the shift that an amendment has been made. In this case, the days before first shift change would get the current passage reported, although this was not correct. The fixed code is:

SELECT TC.id,
       EM.Name,
       TC.Workday,
       NVL(SC.OldShift,EM.CurrentShift) AS Shift
FROM   TimeCard TC,
       EmployeeInfo EM,
       (SELECT ID, Workday, ChangeDate, OldShift
        FROM
               (SELECT TC2.ID, TC2.Workday, SC2.ChangeDate, SC2.Oldshift,
                       MIN (SC2.ChangeDate) KEEP (DENSE_RANK FIRST ORDER BY SC2.ChangeDate)
                                            OVER (PARTITION BY SC2.ID, TC2.Workday) AS Min_ChangeDate
                FROM   ShiftChanges SC2,
                       TimeCard TC2
                WHERE  TC2.Workday < SC2.ChangeDate
                AND    TC2.ID = SC2.ID
                )
        WHERE   ChangeDate = Min_ChangeDate
        ) SC
WHERE  TC.ID=EM.ID(+) AND
       TC.ID=SC.ID(+) AND
       TC.Workday = SC.Workday(+)

It works it is not terribly effective. Perspective online joined the entire table for the time sheet to the table of ShiftChange together. I imagine that you would be restrictive forms of presence reported by a range of dates in the main query, and you do not want to apply the same filter inside the display online. Even if you filter on employee ID's

For example.

SELECT TC.id,
       EM.Name,
       TC.Workday,
       NVL(SC.OldShift,EM.CurrentShift) AS Shift
FROM   TimeCard TC,
       EmployeeInfo EM,
       (SELECT ID, Workday, ChangeDate, OldShift
        FROM
               (SELECT TC2.ID, TC2.Workday, SC2.ChangeDate, SC2.Oldshift,
                       MIN (SC2.ChangeDate) KEEP (DENSE_RANK FIRST ORDER BY SC2.ChangeDate)
                                            OVER (PARTITION BY SC2.ID, TC2.Workday) AS Min_ChangeDate
                FROM   ShiftChanges SC2,
                       TimeCard TC2
                WHERE  TC2.Workday < SC2.ChangeDate
                AND    TC2.ID = SC2.ID
                AND    TC2.Workday >= SYSDATE - 7
                )
        WHERE   ChangeDate = Min_ChangeDate
        ) SC
WHERE  TC.ID=EM.ID(+) AND
       TC.ID=SC.ID(+) AND
       TC.Workday = SC.Workday(+) AND
       TC.Workday >= SYSDATE - 7

Tags: Database

Similar Questions

  • Need help with query for points and polygons, 2 tables of

    Hi all

    I'm slowly stumbling along trying to figure things out space.

    I have two tables, GEO_POINTS:
    (
    DEP_ID NUMBER (12) NOT NULL,
    LINE NUMBER 4 NOT NULL,.
    MDSYS. POINT_LOC SDO_GEOMETRY
    )

    and POLYGON_AREAS:
    (
    POLY_NAME VARCHAR2 (120 CHAR),
    POLY_DESC VARCHAR2 (120 CHAR),
    MDSYS POLY_POINTS. SDO_GEOMETRY
    )

    Neither table is engraved in stone, if any, I can change some structure.

    I'm trying to understand how to write a query to retrieve all the points in a polygon, perhaps even with an optional buffer provided by the user.

    Conversely, I would probably also need to know what polygons a point would have drawn in, and it's the only request I could make any progress on.

    What I have so far, which is not working properly, is the following:

    Select * from deposits_search where dep_id in)
    SELECT dep_id
    OF geo_points, polygon_areas
    where (sdo_relate)
    poly_points,
    (SELECT point_loc
    OF geo_points
    WHERE dep_id = 10282444),
    ("mask = ANYINTERACT") = "TRUE");

    In the light of the foregoing, I want to select all the lines of a third table (DEPOSITS_SEARCH), for all polygons which is a point. The DEP_ID column is my primary key for most of the data tables in the database, and the number rose in my application query. However, the above returns all rows. It should only return one, because I only have a polygon of test defined so far.

    Any help is greatly appreciated. Thank you

    Bill Ferguson

    in which case you must include a line of buffer for the interaction between the points and polygons (with a stamp),

    better, you use the SDO_WITHIN_DISTANCE operator.

    http://download.Oracle.com/docs/HTML/B14255_01/sdo_operat.htm#i77653

    Not so sure what you mean with "I always have problems while providing a point location and extract the polygons that point would be plotted in" as so-called before unless you want that as a 'transitional instance of a geometry. (Specified using a variable binding or a builder SDO_GEOMETRY.) »

    http://download.Oracle.com/docs/HTML/B14255_01/sdo_operat.htm#i78531

    Read what geometry2 means in there. Read the examples and you will see that you have the geometry second in space operator as a builder. If this is what you need.

    Luke

  • How long should you wait after badly answering security questions too many times in a row

    How long should you wait after badly answering security questions too many times in a row

    How long should you wait for what? If you have temporarily disabled your account screen should say how long you have to wait until you can try again. If you mean for the reset link show on your account then does not appear if you have an e-mail address of verified relief on your account, if you have not you don't you must follow the section "If you can not reset your security questions" at the bottom of the page you have posted since

  • Hello, I have a question, if I already paid for Adobe Creative Cloud (including all Adobe Applications) and I installed it in a desktop computer in my office, I might as well install in my laptop at home? Or should I uninstall it in the transfer Office

    Hello, I have a question, if I already paid for Adobe Creative Cloud (including all Adobe Applications) and I installed it in a desktop computer in my office, I might as well install in my laptop at home? Or should I uninstall it in the desktop to transfer it to my laptop? Thank you

    Cloud license allows 2 activations http://www.adobe.com/legal/licenses-terms.html

    -Install on a 2nd computer http://forums.adobe.com/thread/1452292?tstart=0

    -Windows or Mac has no importance... 2 on the same operating system or 1 on each

    -Two activations on one account CAN NOT be used at the same time (to be noted in the link above of the license)

    -An individual account is for one person and may not be shared with anyone else

  • SQL Query - store the result for optimization?

    Good day experts,

    I'm looking for advice on a report. I did a lot of analytical functions to get the basic data that I have to do my report and its takes about 50 min for SQL finish. Now, with these data, I need to create 3 different reports and I can't use the SQL even since there are a lot of aggregation (example would be product group in one case and by customer in 2nd). For each of these different group garages I need another report.

    So how to create 3 reports of 1 SQL query without running the query 3 times?

    First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.

    Best regards

    Igor

    So how to create 3 reports of 1 SQL query without running the query 3 times?

    You already know the obvious answer - store data 'somewhere '.

    If any 'somewhere' depends on your needs and you have not provided ALL the.

    MV - if the query is always the same, you might use a MV and make a complete refresh when you want that new data. The data are permanent and can be queried by other sessions, but the query that accesses the data is frozen in the definition of MV.

    GTT (global temporary table) - If a NEW charge of data AND three reports will be ALWAYS executed by a single session and then data are no longer necessary so a TWG may work. The application that loads the TWG can be different for each race, but the data won't be available for a single session and ONLY for the duration of this session. So if something goes wrong and the session ends the data are missing.

    First thing that comes to mind is to store the result set in a fictitious table, and then query the table since I get the basic data are about 300 lines and then perform different garages group.

    Which is commonly called a "table of REPORT-READY." Those that are useful when data must be permanent and available for multiple sessions/users. Generally, there is a batch (for example the package procedure) that periodically refreshes / updates the data during a window of failure. Or the table can have a column (for example AS_OF) that allows it to contain multiple data sets and the update process let alone the existing data and creates a new set of data.

    If your database is about 300 lines you can consider a table report and even use it to contain multiple data sets. Then, the reports can be written to query the data by using a value AS_OF that wraps and returns the appropriate data. You don't need a window of failure since the oldest data are still available (but can be removed when you no longer need.

    If you need a set of data, you can use a partitioned table work (with only one partition) to collect the new set of data, then a SWAP PARTITION to 'swap' in the new data. Only, this "Exchange" takes a fraction of a second and avoids a window of failure. Once the swap done no matter what user query will get new data.

  • In a hierarchical query, is it possible for a line having more than one immediate ancestor?

    Hello

    Question:

    In a hierarchical query, is it possible for a line having more than one immediate ancestor?


    Answer:



    Isn't it?  Surely this is Yes?


    Thank you

    Jason

    Line may have ancestors as much as you want. It goes the same for successors.

    SY.

  • If I press the button 2 times to run the query 2 times

    Hello..

    If I press the button 2 times to run query 2 times
    I want to limit this problem, than a run time enough.
    no need to rerun query when I press the button because it will make the erroneous data.

    Please give me a solution
    Maha

    Hello Maha

    did you use KEY-EXEQRY trigger and turn off the query button?

    SET_ITEM_PROPERTY('BLOCK1.) REPRINT ', ENABLED, PROPERTY_FALSE);

    Sorry not clear for me, but plu everything sounds good :)

    Kind regards

    Amatu Allah

  • How to get the query execution time without running...?

    Hello

    I had one condition... as follows...
    I had 3 sql statements. I need to run only sql what runtime is very less.

    Can someone help me, how to get the time query and run this query without using explain plan... ?

    Thank you
    Rajesh

    I can't think in any way at all to get the query execution time without running the query.

    You might get an estimate ( approximation ) If you are using explain plan.

    But you have governed to explain plan for a reason, so I can't help you.
    Why you do not want to use don't explain plan?

  • Question of event times

    Hi, after I look at the thread:

    Repeat after x seconds?

    I have a question about the time show, can you do something is disabled for an amount of seconds too? For example: you have a variable that you want to go 'false. ' If you click on 'Right' or something, and after a second or two, the variable go "true." Once again. What I really want to achieve here, it's that during an animation a variable will disable if you cannot for a game example animation "attack" while the animation of 'walk' is turned on.

    These two snippets are in the different fields of application.

    remove the code from your movieclip and attach it to an image.  There is never a reason for attaching code to an object, and there are several reasons to avoid this.

    your_mc. Speed = 3;

    your_mc. Moveable = true;

    {your_mc.onEnterFrame = Function ()}

    {if (Key.isDown (Key.up))}
    This.Moveable = false;

    setTimeout(resetF,1000,this);

    }

    If (Key.isDown (Key.Left) & this.moveable) {}

    This ._x-= speed;

    }

    }

    function resetF(mc:MovieClip) {}

    MC. Moveable = true;

    }

  • Odd variance in query execution time

    I am able the time it takes to run a query. The query produces a 363 object result set from a cache of the 704 150 object. I run the query 20 times in a row and get the average and standard deviation.

    When I run the query directly on a cluster node, I get: = 3,605 average Min = Max = StdDev 3,845 = 0.059 3,750

    When I run the query from a customer to extend I get: average = 3.759 Min = Max = StdDev 13.928 7.218 = 4.721

    (all time in seconds)

    I have a hard time explaining why he has this great fluctuation in the results when executing on the client to extend it. Can anyone provide an overview?

    Considering that the request was indeed not indexed the original sounds of run time much more reasonable although I find the new results from slower that I use on measure for same sizes queries (based on the number and size of the result) in our application, but this can be explained by the complexity of the query, how much help the index to , the complexity of serialization, material used etc etc...

    From what I remember of runing the program test your figures look ok (very well with 1.0 success rates - which is beter than I used to see with our network equipment!)

    I've done only brief essays to extend and did not measures of performance (especially not on performance gaps) so I can't say yet whether or not this is "expected" (I suppose not, but maybe someone who use extend in this project can "go in" and give some info better)?

    I'm sorry to say that I have any more sugestions on the variance "expand." Except for the things that I have already mentioned that I have a hard time to see how to add an additional IP-based communication protcoll would add that much variance...

    Maybe you better post a request for formal assistance on this specific issue as it may require some research?

    / Magnus

  • I have a question about the time machine. I recently updated my Quicken 2015 and there was something wrong with the update. Can I go back in just the Quicken file and restore it until I downloaded the update do I have to restore the entire

    I have a question about the time machine. I recently updated my Quicken 2015 and there was something wrong with the update. Can I come back in all the Quicken file and restore from time Machine before I downloaded the update to do, I need to restore the entire computer?

    Yes, you can just restore this file or application. Use Time Machine to back up or restore your Mac - Apple Support

  • First, I'm joining the forum with a question CS4 and CS5 Suite for Mac. Can someone tell me why it is NOT a place to submit a question as it is here?

    First, I'm joining the forum with a question CS4 and CS5 Suite for Mac. Can someone tell me why it is NOT a place to submit a question as it is here?

    Creative Suites Mac forum seems to be closed, so moved that Creative Suites Windows the Forum of Creative Suites "base".

    Then... Post your question and someone may be able to help... is your question about the installation of the old software on a new Mac?

    IF El Capitan Mac read below

    CS6 and previous programs have not been tested and will not be updated to run on Mac El Capitan

    -which means you are trying to use CS6 and earlier at YOUR risk of having problems

    -You can get CS6 and previous programs to install and run, or you can not (some do, some don't)

    -IF not, Details of the message from the error messages and a person may be able to help (just not Adobe)

    This information is a MUST to install old programs on Mac El Capitan

    -You can't get the same error message, but here are some links that CAN help with old programs

    -Java https://helpx.adobe.com/dreamweaver/kb/dreamweaver-java-se-6-runtime.html can help

    Install CS5 on Mac 10.11 https://forums.adobe.com/thread/2003455 can help (also for others than CS5)

    -also a TEMPORARY security change https://forums.adobe.com/thread/2039319

    -http://mac-how-to.wonderhowto.com/how-to/open-third-party-apps-from-unidentified-developer s-mac-os-x-0158095 /

    -the guardian https://support.apple.com/en-au/HT202491

  • Master Page Items question: I use master pages for a 60 page document and just found out that some of my master page items are multiplying! There are some boundaries on the pages and some of them are constantly a quantity apparently endless on top of e

    Master Page Items question: I use master pages for a 60 page document and just found out that some of my master page items are multiplying! There are some boundaries on the pages, and some of them are constantly a quantity apparently without end on top of the other. For example, I replace to change the color of the border and notice a black there's below him so I deleted the extra and there is another and another and another... EEK. I can easily hide them, BUT I fear they will lead to complications in the case of pre-press printing. What is the cause? What can I do to prevent it? How can I get rid of the stack-up?

    It's always haapening, if you substitute any element on the page and later master you reapply the same or another master. I would NEVER say to replace any itme master page in the page. Instead create another master based on the first, make the substitutions and apply this master. Substitutions on the pages should be avoided in all cases, not only for the problem you described above, other issues of accessibility will also come into play.

  • I have a note of galaxy tablet. with photoshop touch in English, my question is can be set for the Spanish program

    I have a note of galaxy tablet. with photoshop touch in English, my question is can be set for the Spanish program

    I could have sworn that PS Touch takes example of Android 'language & entry' slot parameter settings. for example, if it is set to English, then tap PS will be in English.

  • Different LOVs of af: query and af:form for the same attribute of VO

    Hello

    We need show different LOVs af:query and af:form for the same attribute in VO.

    Is it possible to use LOV Switcher for this?

    Can how we use in the LOV Switcher attribute to check if she is seen Critearia line or VO?

    Please see this post - http://jobinesh.blogspot.com/2011/04/identifying-request-for-lov-from-search.html

Maybe you are looking for

  • N600 WNDR3700V5 with firmware 1.1.0.32 stops after 2 hours

    Improved 1.0.0.17 (initial) to 1.1.0.32, in order to improve performance.Only after about 2 hours of service, there is no connection with the uplink port more. Connectivity Wi - Fi, and fails. Any ideas? Known issue?

  • Screen X 300 - 13O Qosmio cuts

    I was scary to my office today when all of a sudden my screen is black. I couldn't see anything, but when I had a flashlight up against the screen I saw that there was life in the computer, I was always on the desktop, but the light was just very, ve

  • How to transfer streams in Windows Media Player

    Napster Can someone tell me how to transfer Napster streams to my WMP library

  • E260 and Rhapsody To Go

    I can't allow my e260 with Rhapsody.  In MTP mode it just appears - in computer work or Rhapsody window.  However, when it is in MSC mode, it appears in both, just that I can't allow him to Rhapsody. Yes, my computer is allowed. We had the account fo

  • I'll be able to play a new game with

    Intel Core i7-2600 processor quad-core with Turbo Boost [upward to 3.8 GHz, 8 MB cache], 10 GB of DDR3 SDRAM at 1333 MHz [3DIMMs], 2 TB 7200 RPM SATA 3 Gb/s hard, nvidia Gtx 550 ti... thankss