Best way to resolve this table?

Lets say you're dealing with these two tables:

CREATE TABLE VEHICLES
(
NUMBER OF VEHICLE_ID
VEHICLE_NAME VARCHAR2 (100 BYTE),
NUMBER OF MILES
);


CREATE TABLE VEHICLE_PARTS
(
NUMBER OF PART_ID,
VEHICLE_ID NUMBER OF NON-NULL,
PART_TYPE NUMBER OF NON-NULL,
PART_DESCRIPTION VARCHAR2 (1000 BYTE) NOT NULL,
START_SERVICE_DATE DATE NOT NULL,
DATE OF END_SERVICE_DATE,
PART_TYPE_NAME VARCHAR2 (100 BYTE)
);

And some data for example as follows:

Insert into VEHICLES (VEHICLE_ID, VEHICLE_NAME, MILES) Values (1, "Honda Civic", 75500);
Insert into VEHICLES (VEHICLE_ID, VEHICLE_NAME, MILES) Values (2, 'Ford Taurus', 156000);

Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, END_SERVICE_DATE, PART_TYPE_NAME)
Values
(1, 1, 1, "1.4 VTEC",)
TO_DATE('07/07/2009_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), TO_DATE (3 MAY 2010 00:00:00 "," MM/DD/YYYY HH24:MI:SS'), "ENGINE");
Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, PART_TYPE_NAME)
Values
(2, 1, 1, "1.6 VTEC",)
TO_DATE('05/03/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'ENGINE');
Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, END_SERVICE_DATE, PART_TYPE_NAME)
Values
(3, 1, 2, 'Happy new year all seasons',)
TO_DATE('07/07/2009_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), TO_DATE (10 AUGUST 2010 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'TYRES');
Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, PART_TYPE_NAME)
Values
(4, 1, 2, 'Bridgestone Blizzaks',)
TO_DATE('08/10/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), "TIRES");
Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, PART_TYPE_NAME)
Values
(5, 2, 1, "3.5 L Duratec",)
TO_DATE('06/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'ENGINE');
Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, END_SERVICE_DATE, PART_TYPE_NAME)
Values
(6, 2, 2, 'Happy new year all seasons',)
TO_DATE('06/01/2008_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), TO_DATE (15 MARCH 2009 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'TYRES');
Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, END_SERVICE_DATE, PART_TYPE_NAME)
Values
(7, 2, 2, 'Michelin All-Seaon',)
TO_DATE('03/15/2009_00:00:00',_'MM/DD/YYYY_HH24:MI:SS'), TO_DATE (12 JANUARY 2011 00:00:00 ',' DD/MM/YYYY HH24:MI:SS'), 'TYRES');
Insert into VEHICLE_PARTS
(PART_ID, VEHICLE_ID, PART_TYPE, PART_DESCRIPTION, START_SERVICE_DATE, PART_TYPE_NAME)
Values
(8, 2, 2, "Nokian")
TO_DATE('01/12/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), "TIRES");


And you need produce a view that shows the flattened attached data where each vehicle has one row with columns representing their most recent part (which has a service as Start Date of null terminator).

Like this:

Car: Engine: tires:
Honda Civic 1.6 VTEC Bridgestone Blizzaks
Ford Taurus 3.5 L Duratec Nokian


There he has a fast and efficient to do that?

My current approach, which is the brute force method is to have a separate outer join for each column, I need to shoot with the condition of max (START_SERVICE_DATE) to get the current part for each type (engine, tires, etc...).

but its so slow and painful code.

I thought pivot but I don't think that Pivot help here since there is no aggregation going, right?

Anything with the partition could over aid? IM unfamiliar with this syntax

Hello

Trant says:
Lets say you're dealing with these two tables:

CREATE TABLE VEHICLES
(
NUMBER OF VEHICLE_ID
VEHICLE_NAME VARCHAR2 (100 BYTE),
NUMBER OF MILES
); ...

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

I thought pivot but I don't think that Pivot help here since there is no aggregation going, right?

Pivot is always aggregation; you take any number of rows in the table and only one line display. It is the aggregation.

Anything with the partition could over aid? IM unfamiliar with this syntax

Yes: ROW_NUMBER analytic function can help to identify the most recent line for each vehicle_id and part_type_name in vehicle_parts.

Here's a way to do it:

WITH     got_r_num     AS
(
     SELECT     vehicle_id
     ,     part_description
     ,     part_type_name
     ,     ROW_NUMBER () OVER ( PARTITION BY  vehicle_id
                         ,             part_type_name
                         ORDER BY        start_service_date
                       )     AS r_num
     FROM     vehicle_parts
     WHERE     end_service_date     IS NULL
)
SELECT       v.vehicle_name
,       MIN (CASE WHEN r.part_type_name = 'ENGINE' THEN r.part_description END)     AS engine
,       MIN (CASE WHEN r.part_type_name = 'TIRES'  THEN r.part_description END)     AS tires
FROM            vehicles     v
LEFT OUTER JOIN     got_r_num     r  ON     v.vehicle_id     = r.vehicle_id
WHERE       r.r_num     = 1
GROUP BY  v.vehicle_name
ORDER BY  v.vehicle_name
;

You must add another column in the main query for each part. It's just one line of code, not nearly as bad but to join another subquery.

Whenever you have a problem, don't forget to tell what version of Oracle you are using.
The above query will work in Oracle 9 (and), but if you have Oracle 11, you'll want to use SELECT... PIVOT.

Tags: Database

Similar Questions

  • What is the best way to refresh the table after autosubmit (10.1.3.4)

    What is the best way to refresh the table after autosubmit?

    I have a page that contains a table where if one of the fields is changed it autosubmitted where the view object changes some attributes, based on the field having been changed. I need these modified attributes that appear in the table. But without doing anything, the only way to see these values is to cause the iterator updated table.

    I've been refreshing the table is having a method in a grain of beacking called "getSystemSettingIter.getCurrentRow ();". This seems to be a bit of a hack for me and I was wondering if there is a better way to get the table to update.

    Thanks in advance!

    Have you tried setting between the two partial page refresh?
    http://www.Oracle.com/pls/as111120/lookup?ID=ADFUI385

    http://download.Oracle.com/docs/CD/E15523_01/Web.1111/b31974/web_form.htm#CACEIEEI

  • What is the best way to read this binary file?

    I wrote a program that acquires data from a card DAQmx and he writes on a binary file (attached file and photo). The data I'm acquisition comes 2.5ms, 8-channel / s for at least 5 seconds. What is the best way to read this binary file, knowing that:

    -I'll need it also on the graphic (after acquisition)

    -J' I need also to see these values and use them later in Matlab.

    I tried the 'chain of array to worksheet', but LabView goes out of memory (even if I don't use all 8 channels, but only 1).

    LabView 8.6

    I think that access to data is just as fast, what happens to a TDMS file which is an index generated in the TDMS file that says 'the byte positions xxxx data written yyyy' which is the only overload for TDMS files as far as I know.

    We never had issues with data storage. Data acquisition, analysis and storage with > 500 kech. / s, the questions you get are normally most of the time a result of bad programming styles.

    Tone

  • I'm moving my files to workspaces to cloud.adobe.  What is the best way to achieve this?

    I'm moving my files to workspaces to cloud.adobe.  What is the best way to achieve this?

    Hi Traci,

    So big that you get ready for the transition to cloud.acrobat.com! Please see that the specified item was not found. For more detailed information on downloading your files.

    When you open a session workspaces, however, you will see a big red box at the bottom left. Click this box, and your files will be packed to the top for you. You will receive an email with the instructions when the packaged files are ready for you.

    Best,

    Sara

  • AS3 best way to clear a table

    What is the best way to clear a table? (performance and resources)

    Array.Length = 0;

    array = [];

    array.splice(0);


    Array.Length = 0;

  • I have an After Effects project and I want to re-do edge animate. What is the best way work for this?

    I have an After Effects project and I want to re-do edge animate. What is the best way work for this?

    Hello

    Sorry, but you will probably need to rebuild everything in Animate. Although their timelines are similar in some ways, there is no interoperability between After Effects and animate dashboard.

    Kind regards

    Joe

  • Best way to film this scene, stitch together plates or green screen?

    I have a call where I walk past a player with him framed on the right of the screen, ' actor A. ' then on the shoulder 'Actor A' (on the left side of the screen) another character is in sight, "actor B." at the end of shooting the camera move to stop and I want at the speed of the actor 'A' of the ramp so that it revolves around very quickly While the 'B' actor maintains a normal speed (which is him walking toward the camera as well). Is the best way to do this shoot with two plates separate and assemble them (if if, what is the best way to assemble the shots)? Or is - this green screen actor 'A' or 'B' and add them in? Remember, the camera moves to the rear while the actor 'A' heading, when moving player 'B' is also in the shot. Ramp speed of the actor 'A' occurs once it stops (it will whisk around extremely fast), how the camera will also be stopped.

    You have a few options. Usually, I start a VFX shot by the thought of the movement of the camera. If I move the camera what are the problems that will result?

    According to your description, you have a dolly with two actors. Tracks camera, the first actor as the second player enters the scene, then the unit stops and the second actor continues to his notes at normal speed while the first actor is accelerating. Two shooting plates will give control the moment where the first actor, but, in view of the camera move, requires you to simulate accurately the moment where two follow-up plans so the point of view between actors is consistent. It doesn't matter if the photos are on a green background. For the view between the two actors to match the camera moves must be identical to the camera angle and the speed of follow up.

    If, however, you shoot all the action in a single pass while you can use rotoscoping to separate into two pieces shooting where the camera stops moving and then adjust the time where the first actor. This works easily if you make sure that you don't move the camera at all once the track ends.

    If the players do not overlap so the second option is a piece of cake because your roto can be a very simple rough mask. If the players overlap in the framework then your roto work will have to be very precise when the players overlap, and you may need to perform a few background replacement to fill in the holes.

    If you decide to do with two plates, then you will probably need to track movement. stabilisation and re-synchronization of two shots to make them at the height. If the camera is moving when you accelerate the first actor, you will have to keep track of movement.

    A final option is to pull the first actor on a green screen and the second player as a bottom plate and then follow and stabilize the two shots to try to combine them. Here again, if the speed and angle of the two plans that you combine are not identical or at least nearby enough that you can easily fix them you'll be in a lot of tweaking to than the shots work.

    If it were my project, I shoot the two actors in a single plug and then divided take it there where should be the first actor have the speed change and make a few roto work. That seems to be the most straightforward approach.

  • What is the best way to get a Table name in Oracle Applications: 12.1.1 (web)

    Hello friends...


    I need your help my friends...


    We are currently working on Oracle Applications: 12.1.1

    I would like to know the best way to get the name of the Table to form based on a Web...


    Concerning

    Yas.

    Hello

    Please see this thread and documents referenced in it.

    RECORD HISTORY (or) COLUMNS in R12?
    RECORD HISTORY (or) COLUMNS in R12?

    Kind regards
    Hussein

  • I'll do a clean install on a blank hard drive upgrade but want to keep my Firefox settings - what is the best way to do this?

    I'll do an upgrade from Windows XP to Windows 7. I will be installing Windows 7 on a new empty hard drive. I want to keep my bookmarks Firefox and Ad Ons. What is the best way to do it. Thank you for your help.

    Hello

    The best thing for you to do is to make a backup of your Firefox profile. It is a folder that stores bookmarks and Add-ons that you can then add to the reinstalled Firefox on your new operating system.

    Learn you more about the Firefox profile folder, how to backup and restore, here.

    I hope this helps, but if not, please come back here and we can look at in another option for you.

  • Best way to make this step motor control system

    The goal of my project is to have real-time data collected by a controller of Sir 158u Dataq a stepper motor.  I grappler planned on executing it with the basic stamp, but I realize that's not possible.  I have a stepper motor and a L293DNE driver.  I'll be permanently registration of data with the dataq, the form of volts and want these values to determine how the engine works.  For example, if the voltage is 0-3 volts, I want it running clockwise, 3-5 volts not turns not, and 5-8 Volt turn clockwise.

    I tried to understand this last week, searching through discussions with basic stamp, matlab and labview now.

    Is there an easy way to do this? or easier way that I'm trying to understand?

    Any help would be greatly appreciated!

    Thanks in advance.

    -Nick

    Nick,

    What I was describing, this is how you configure the motor controller to accept PWM of LabVIEW and mode locked anti-phase so you can control the direction of the motor. Much on the part of LabVIEW depends on the acquisition of data you use. For example the acquisition of your data doesn't have a counter which can generate a PWM? I did some checking everything on time and the acquisition of your data is not made by National Instruments and I couldn't locate the native LabVIEW drivers. I did however go to the MFG Dataq 158u site and found that they do not have drivers LabVIEW BUT their software (SW) should run in the background. Dataq 158u website also has a help forum, I suggest you start to understand the capacity of the 158u Dataq. Also it seems that you are not familiar with LabVIEW, until you can take on a project like this, you have to start with the LabVIEW Basics, learn how to manage the tables so you can store your results of EDA and records the use of loops and timing and movement.  NOR has a basic training FREE as the intrudction 6hr to LabVIEW, I would like to start their. Oh, and in your OP (original post) you doubted the Basic Stamp could do that, I do this type of control using the Atmel microcontrollers all the time, I'm sure that the stamp eaisily could do. Download right on one of their forums for more information. Oh and to answer your question a UPS is an IC that reverses the input signal, which you would end upward with the direction of you pines motor controller is PWM on a spindle and 180Deg off phase PWM, on the other hand.

    Alan

  • I replace a website done previously before Page with a new site that I built in Dreamweaver, but wants to keep the URL address, what is the best way to achieve this?

    I replace a site is at the top with a new website that I'm building in Dreamweaver, but want to keep the same URL which is the best way to go about this?

    If you want to keep the same hosting provider, you have nothing to do. Just delete the old files of the site and download your new.

  • Best way to update a table with separate values

    Hi, I would really appreciate some advise:

    I need to regularly perform a task where I update 1 table with all the new data that has been entered in another table. I cannot perform a complete insert because this will create data duplicated each time it works, so the only way I can think of is the use of cursors in the script below:


    CREATE OR REPLACE PROCEDURE update_new_mem IS
    tmpVar NUMBER;

    CURSOR c_mem IS
    SELECT nom_membre, member_id
    OF gym.members;
    CREC c_mem % ROWTYPE;


    BEGIN
    OPEN c_mem.
    LOOP
    SEEK c_mem INTO crec;
    EXIT WHEN c_mem % NOTFOUND;
    BEGIN
    UPDATE gym.lifts
    Name = crec.member_name
    WHERE member_id = crec.member_id;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN NULL;
    END;
    IF SQL % NOTFOUND THEN
    BEGIN
    INSERT INTO gym.lifts
    (name, member_id)
    VALUES (crec.member_name, crec.member_id);
    END;
    END IF;
    END LOOP;
    CLOSE C_mem;

    END update_new_mem;



    This method works, but y at - it a (faster) easier way to update another table with new data only?

    Thank you very much

    >
    This method works, but y at - it a (faster) easier way to update another table with new data only?
    >
    Almost anything would be better than this treatment of slow-by-slow loop.

    You don't need a procedure, you should just use MERGE for this. See the examples in the section of the MERGER of the doc of the SQL language
    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_9016.htm

    MERGE INTO bonuses D
       USING (SELECT employee_id, salary, department_id FROM employees
       WHERE department_id = 80) S
       ON (D.employee_id = S.employee_id)
       WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
         DELETE WHERE (S.salary > 8000)
       WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
         VALUES (S.employee_id, S.salary*.01)
         WHERE (S.salary <= 8000);
    
  • best way to write this query

    Hello

    I have a problem and I realized a simplified version of it:

     
    
    create table deals (id_prsn number, id_deal number, fragment number); 
    create table deal_values (id_prsn number, id_deal number, value_ number, date_ date); 
    
    insert into deals values(1,1,50); 
    insert into deals values(2,2,40); 
    insert into deals values(1,3,50); 
    insert into deals values(2,4,80); 
    insert into deals values(1,5,20); 
    insert into deals values(2,6,80); 
    
    insert into deal_values values(1,1,10 ,sysdate - 3); 
    insert into deal_values values(2,2,208, sysdate - 3); 
    insert into deal_values values(2,4,984, sysdate - 3); 
    insert into deal_values values(1,null,134,sysdate - 3); 
    insert into deal_values values(1,1,13, sysdate - 2); 
    insert into deal_values values(2,2,118, sysdate - 2); 
    insert into deal_values values(2,4,776, sysdate - 1); 
    insert into deal_values values(1,null,205,sysdate - 1); 
    insert into deal_values values(2,null,-5,sysdate - 1); 
    The id of the requirement to join these two tables based on:

    1.) ID_PRSN and ID_DEAL
    2.) max DATE_ grouped per person and deal
    (3.) in the case that ID_DEAL is defined in the AGREEMENTS, but not defined in the DEAL_VALUES table, I have to join this records to DEAL_VALUES based on the person where id_Deal is null.

    Number 3 gives me headache. I realized the following query:
     
    
    select *from ( 
    select a.id_prsn, 
           a.id_deal, 
           a.fragment, 
           b.value_, 
           b.date_, 
           max(b.date_) over (partition by b.id_prsn, b.id_deal) max_date 
      from deals a 
    inner join deal_values b 
        on a.id_deal = b.id_deal or b.id_deal is null 
       and not exists  (select 1 from deal_values 
                                  where id_prsn = a.id_prsn 
                                    and id_deal = a.id_deal) 
       and a.id_prsn = b.id_prsn 
    ) 
    where date_ = max_Date; 
    It returns the correct result of he,


    ID_PRSN ID_DEAL FRAGMENT VALUE_ DATE_ MAX_DATE
    1 1 50 13 16.10.2012 09:59:48 16.10.2012 09:59:48
    1 3 50 205 17.10.2012 09:59:48 17.10.2012 09:59:48 OK
    1 5 20 205 17.10.2012 09:59:48 17.10.2012 09:59:48 OK
    2 2 40 118 16.10.2012 09:59:48 16.10.2012 09:59:48
    2 4 80 776 17.10.2012 09:59:48 17.10.2012 09:59:48
    2 6 80-5 17.10.2012 09:59:48 17.10.2012 09:59:48 OK



    but the join clause:
     
    
    
        on a.id_deal = b.id_deal or b.id_deal is null 
       and not exists  (select 1 from deal_values 
                                  where id_prsn = a.id_prsn 
                                    and id_deal = a.id_deal) 
       and a.id_prsn = b.id_prsn 
    in fact the query much slower.

    I was wondering is there a different way to write this join and manage the logic.

    Thanks in advance

    Here's a different approach:

    select * from (
      select a.id_prsn, a.id_deal, a.fragment, B.value_, b.date_,
      ROW_NUMBER() over(
        partition by a.ID_PRSN, a.ID_DEAL
        order by B.ID_DEAL nulls last, B.DATE_ desc
      ) RN
      from DEALS a
      join DEAL_VALUES B
      on a.ID_PRSN = B.ID_PRSN and a.ID_DEAL = NVL(B.ID_DEAL, a.ID_DEAL)
    )
    where rn = 1
    order by 1, 2;
    

    "nulls last" is the default sort order; I just put that for clarity.

    Published by: stew Ashton on October 18, 2012 12:58

  • What is the best way to detect this text is part of the ContainerControllers without scrolling?

    Hello.

    Question

    What is the best way to detect that the text typed by the user (or added programmatically) exceeds the available space container and find where the truncated part begins? There are others (as described below) highlights the easy way to detect or to prohibit controllers to receive more characters that can be displayed in the area of publication given?

    My attempt partially (Simplified)

    For example, lets say I have a textflow editable with joints two instances of ContainerController.


    var flow:TextFlow = createSomeFlowFromGivenString(sampleText),
        firstController = new ContainerController(firstSprite, 100, 30),
        lastController = new ContainerController(secondSprite, 600, 30);
    
    
    flow.interactionManager = new EditManager(new UndoManager());
    flow.flowComposer.addController(firstController);
    flow.flowComposer.addController(lastController);
    
    flow.flowComposer.updateAllControllers();
    

    Vertical scroll policy enabled I can compare the height of the composition in the last controller with the height of the content:

    var bounds:Rectangle = lastController.getContentBounds(),
        overflow:Boolean =  lastController.compositionHeight < bounds.height;
    
    trace('Content does not fit into given area?', overflow)
    
    

    But when I change of vertical scroll policy off (lastController.verticalScrollPolicy = ScrollPolicy.OFF)-Unfortunately this does not work anymore... (In my case scroll must be disabled, since the text boxes can have only one line with narrow width)

    Use cases

    I want to create the form to fill out. Field can have one or more lines. A field could start in the middle of the page, continue in the following line, where it spreads throughout the page and put an end to the third line - long quarter of the width of the page. Text typed by the user may not exceed given the region since it could cover some static text that is located just after in below field.

    Something like ascii image below:

    --------------------------------------------
    |                <PAGE>                    |
    |                                          |
    |                                          |
    |                                          |
    |               [Field starts here........ |  
    | ........................................ |
    | ........................................ |
    | Ends here..]                             |
    |                                          |
    |                                          |
    | [Another field] xxxx  xxxx xxxxxxxx x xx |
    | xxxxxxxxxxxxxxxxxxx                      |
    |                                          |
    |                              [One more.. |
    | .....]                                   |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    --------------------------------------------
    

    Info:

     [......]  <-- form fields starts with '[' character, and ends with ']'
     xxx       <-- sample, static text
     | and _   <-- page borders
    

    If you want to detect the overflow in the final container, there is another thread discussed before.

    http://forums.Adobe.com/thread/795264

    You can detect it with lastContainerController.absoluteStart + lastContainerController.textLength «»<>

  • Best way to achieve this shadow effect?

    Im trying to recreate the shadow effect of the main content area on this site;

    http://www.CSSzengarden.com/?cssfile=196/196.CSS

    Is a filter drop shadow, the best way to do it and that I have to have 2 shadows or is it possible to make one appear on both sides?

    Thank you

    I think you want to just play with the settings of the shadow from the corner. The default angle puts the shadow to the lower right. You can move that kind of shadow is just below. Then play with the distance and the amount of fabric softener. This is a .png of Fireworks with some changed settings:

Maybe you are looking for