Can make comparisons Records without functions or PLSQL

I'm used to write Oracle functions to save comparisons, but on this project, managers do not want to use the functions or PLSQL
Is there a way to do the following with a SQL rather than write a function: see all data below? Oracle 9i.

I have the following data set used to track packages that are moved from warehouse to warehouse on trucks
I want only to retrieve a record if the starting location is Dallas Ft Worth and end location is another city.
I don't want to retrieve a record if the package moves between other cities (for example, Boston and New York)

For this set of data package 1324 was added and removed to warehouses in Dallas 4times trucked 735 front finally moved to a warehouse in Boston by the same truck

I want the query to return the next record
105273 345 1324 725 11/3 / 2010 14:32 11/3/2010 15:46 dallas Ft Worth WH4

Showing the last location in Dallas until he was moved to Boston

I don't want to return records Boston or NY or the Dallas Ft Worth the previous Records.

The way the system updates the records is as follows:
If a package is added to a warehouse of the record gets an extra date.
When it is removed from the system updates the deletion date of this same record
Once it is added to a new warehouse there is a new record with an additional date and null for the deleted date unless he leaves this place
In the recordset if the date of removal is null then it is the current location of the package


CREATE TABLE emplacement_module
(track_id NUMBER (10))
, sender_id NUMBER (10)
, package_id NUMBER (10)
, truck_id NUMBER (10)
package_add_date DATE,
package_remove_date DATE,
, city VARCHAR2 (50)
, VARCHAR2 (50) warehouse
) ;

INSERT ALL
IN emplacement_module (track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (100012
345, 1324, 725, 04/08/2010 14:39:48, 04/08/2010 14:53:07, "Dallas Ft Worth", "WH1")

IN emplacement_module (track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (100016
345, 1324, 725, 04/08/2010 14:53:07, 09/30/2010 10:41:01, "Dallas Ft Worth", "WH2")

IN emplacement_module (track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (103055
345, 1324, 725, 30/09/2010 10:41:01, 03/11/2010 14:32:14, "Dallas Ft Worth", "WH3")

IN emplacement_module (track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (105273
345, 1324, 725, 11-03-2010 14:32:14, 03/11/2010 15:46:22, "Dallas Ft Worth", "WH4")

IN emplacement_module (track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (105284
345, 1324, 725, 11-03-2010 15:46:22, 22/11/2010 11:55:18, 'Boston', "WH34")

IN emplacement_module (track_id, sender_id, package_id, truck_id, package_add_date, package_remove_date, city, warehouse) VALUES (106674
345, 1324, 725, 11/22/2010 11:55:18, NULL, 'New York', 'WH56')


I tried to do a query with a subquery... the main request was all the records with Dallas Ft Worth and then the subquery was to check if the location wasn't Dallas Ft Worth, but so far I could not quite get the correct dataset.

Any help is greatly appreciated. I don't know if there is a way to do it with just an sql query, if not other suggestions are welcome!


Thanks in advance

I added a few lines to your table, back from New York shipping package in Dallas on another truck, then return to Dallas for New York in order to ensure, I understand the requirements.

SQL> SELECT * FROM package_location;

  TRACK_ID  SENDER_ID PACKAGE_ID   TRUCK_ID PACKAGE_ADD_DATE     PACKAGE_REMOVE_DATE  CITY             WAREH
---------- ---------- ---------- ---------- -------------------- -------------------- ---------------- -----
    100012        345       1324        725 04-aug-2010 14:39:48 04-aug-2010 14:53:07 Dallas Ft Worth  WH1
    100016        345       1324        725 04-aug-2010 14:53:07 30-sep-2010 10:41:01 Dallas Ft Worth  WH2
    103055        345       1324        725 30-sep-2010 10:41:01 03-nov-2010 14:32:14 Dallas Ft Worth  WH3
    105273        345       1324        725 03-nov-2010 14:32:14 03-nov-2010 15:46:22 Dallas Ft Worth  WH4
    105284        345       1324        725 03-nov-2010 15:46:22 22-nov-2010 11:55:18 Boston           WH34
    106674        345       1324        725 22-nov-2010 11:55:18                      New York         WH56
    106675        345       1324        804 25-nov-2010 09:55:18 30-nov-2010 15:46:22 Dallas Ft Worth  WH4
    106676        345       1324        804 25-nov-2010 09:55:18 01-dec-2010 15:46:22 New York         WH42

Given these data, you do not want return 105273 and correct 106675 track_id?

If so, then something like:

SQL> SELECT track_id, sender_id, package_id, truck_id, package_add_date,
  2         package_remove_date, city, warehouse
  3  FROM (SELECT track_id, sender_id, package_id, truck_id, package_add_date,
  4               package_remove_date, city, warehouse,
  5               LEAD (city) OVER(PARTITION BY package_id
  6                                ORDER BY package_remove_date) next_city
  7        FROM package_location)
  8  WHERE city = 'Dallas Ft Worth' and
  9        next_city != city;

  TRACK_ID  SENDER_ID PACKAGE_ID   TRUCK_ID PACKAGE_ADD_DATE     PACKAGE_REMOVE_DATE  CITY             WAREH
---------- ---------- ---------- ---------- -------------------- -------------------- ---------------- -----
    105273        345       1324        725 03-nov-2010 14:32:14 03-nov-2010 15:46:22 Dallas Ft Worth  WH4
    106675        345       1324        804 25-nov-2010 09:55:18 30-nov-2010 15:46:22 Dallas Ft Worth  WH4

John

Published by: John Spencer on August 14, 2011 14:22

Operator non-display sets

Tags: Database

Similar Questions

  • Can make a record hard damaged by mistake of connection of the power cord on the jumper pin?

    Hello

    I tried to upgrade my HD, but I connected by mistake the SATA power cable to the axis of the lower rider after mistakenly removing the jumper shunt

    May I know if this could have damaged by HD?

    I tried to connect in the way justifiable but the system might not always detect the drive.

    What are the possible causes and how to overcome it?

    Thank you

    Low

    A Sata hard drive shouldn't have riders, so make sure you have the jumper in the right position and the cable correctly connected IDE.

  • Can I get the contacts and email from an old record without using the Migration Wizard?

    Can I recover Contacts and messaging of an old record without using the Migration Wizard? Disc of the user in question has been very corrupted with several programs having a weird behavior. Migration wizard migrated corrupt files, so, even a clean install with only migrated users gave rise to an unusable installation.

    I have now all own installed now, but need old email files and contacts. How can I transfer this information a copy of the old/bad drive and only this info?

    Yes. With the old drive mounted and available, open Mail and choose import mailboxes... from the file menu of mail. In the dialog box import data from , choose Apple Mail.

    Navigate to the Mail folder to the user of the old library drive. According to the version of courier used, you might see folders named V2 and / or V3. Choose the applicable folder, and then click Choose.

  • I tried to remove pictures of iCloud to make more room and they had also deleted from my Macbook Pro. How can I remove iCloud without deleting my Mac?

    I tried to remove pictures of iCloud to make more room and they had also deleted from my Macbook Pro. How can I remove iCloud without deleting my Mac?

    How iCloud library works is that all the photos are on iCloud and on the device connected to this library to iCloud. If you remove anywhere from anywhere, they are deleted.

  • windows vista 64-bit vista need upgrade Express dvd, but can't without a yellow sticker? is - this saposed to be somewhere on my pc? or on the vista cd case? and how to make the upgrade without the sticker? __

    need vista in windows vista 64-bit upgrade Express dvd, but can't without a yellow sticker? is - this saposed to be somewhere on my pc? or on the vista cd case? and how to make the upgrade without the sticker?

    32-bit to 64-bit is NOT an upgrade path.

    It must be done with a clean installation using a Vista FULL 64-bit disk/license.

    Buy a version of disk/license FULL Vista 64 bits of your local computer, or online store: amazon, newegg, etc.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    If you already have a version of Vista Home 64 bit, here's how to buy Vista 64 bit Ultimate Anytime Upgrade:

    http://www.Microsoft.com/Windows/Windows-Vista/get/Anytime-Upgrade-overview.aspx

    See you soon. Mick Murphy - Microsoft partner

  • What should I do so that I can make a routine (monthly) BACK to the top without having to allow a program that is not properly validated?

    Since July of this year, when I try to back up my computer to HP Envy 17 laptop I get a pop-up window asking if I want to allow the following program to make changes to my computer.  The program is: Microsoft Windows Backup/Windows Hardware Driver verification / valid from 07/12/2009 to 03/07/2011.  Because the validation is obviously outdated, I consider the program run out of appropriate verification, but I can't back up my computer without the program.

    Hewlett-Packard said the problem probably occurs because the computer was missing an update of windows.  Updates happen automatically without my intervention.  I bought the new computer, directly from HP in the month of August, 2011 (after the date of validation of program pop up) with Windows 7 Ultimate installed and had no problem backup of my files to a CD until July of this year.  I believe that the problem may be the result of a rather than a missed update windows update.  What should I do so that I can make a routine (monthly) BACK to the top without having to allow a program that is not properly validated?

    Since July of this year, when I try to back up my computer to HP Envy 17 laptop I get a pop-up window asking if I want to allow the following program to make changes to my computer... [Posted Sept 27-12]

    At this point, the problem of slower Internet connection and loading is probably resolved.  I wanted to try the simpler remedy without doing unnecessary downloads.  Fortunately, there is a Windows update that created a restore point the day before the problem occurred.  I restored the system to this date, and the problem disappeared... [Posted 03 Oct-12]

    Sorry, but I can't say what the problem is (or was) or when he started - especially since the moderator community Smittychat [or another Mod?] decided to merge your two threads. Maybe it can help you?

    I can tell you that v11.3.300.268 Java Version 6 update 32 and Flash Player are very badly outdated & subject to thousands of security vulnerabilities .

    Get Java Version 7 Update 7 installed (or higher) & all previous versions (for example, v1.6.0_32) removed as soon as POSSIBLE!  Follow the instructions here-online http://aumha.net/viewtopic.php?f=26&t=46263

    When finished, remove your Java cache by http://www.java.com/en/download/help/plugin_cache.xml

    Download Flash Player v11.4.402.278 installed as soon as POSSIBLE, also!  See this page-online http://aumha.net/viewtopic.php?f=26&t=46252

    Good luck!

  • You can make a video of your desktop? I have to make a tutorial for my work, and I need to record how a program works

    You can make a video of your desktop? I have to make a tutorial for my work, and I need to record how a program works

    Thanks guys,.

    I have a PC, so I'll try Camstudio.

    Thank you!!!

  • How can I make the recorder online flash

    How can I make the recorder online flash

    Like this http://demo.kcly.com/MicRecord/

    See here: http://www.bytearray.org/?p=1858

  • I would like to know how I can make firefox stop the message that I have to restart my browser to complete the update without having to reboot?

    I would like to know how I can make firefox stop the message that I have to restart my browser to complete the update? I'll restart later, but does not wish to do so immediately. I can
    Click on the cross, but after a few minutes the message is back and I can't figure out how to stop
    It's popping every few minutes.

    You need to restart it.

  • Assigning a page element in the region of the "body of function return PLSQL SQL query.

    I've not been here in a long time. I like the new forum text editor!

    I have a search page in my application that contains a return region of query SQL PLSQL function body. I use PLSQL to build a query based on the user entries in various page numbers (search text, serial number, year, etc.). Using PLSQL is very useful to enforce the page quickly because there are 1/2 million lines with a lot of text fields some of which are CLOB.

    Users want to know how many rows were returned, but if I allow using a paging system that includes the total performance dies because ApEx has to sort through all the pages of output. Instead, I use ' line varies X to Y "without the part of" Z", and it's pretty fast. I can't use the #TOTAL_ROWS # because it does not work with this system of pagination.

    So, I built a code within the region of function body PLSQL to build a second query that counts only the lines based on the input parameters. I can do this query within the region using EXECUTE IMMEDIATE and the number to an output variable. The disconnect is that I can not then assign it to a page element. If I add a statement assigned to a page element, either by

    : P45_COUNT: = p_count;
    or
    APEX_UTIL. SET_SESSION_STATE ('P45_COUNT', p_count);

    then when I submit the changes I get

    ERR-1002 unable to find point item ID 'P45_COUNT' in the application '4000 '.

    as if the ApEx is not looking for the item in my application, but in the application development environment. I am able to write the results to a table and then recover data in the next region. That's how I got around the problem, but it seems too complicated and unnecessary.

    I wrote the following code just to illustrate the problem.

    Make sense? Any ideas?

    Thank you!

    Bill


    declare
    p_sql varchar2 (32767).
    p_sql_count varchar2 (32767).
    p_table_count number (2);
    p_count number (10);
    p_instr number (10);
    Start
    p_sql: = q'! Select g.id, g.widget, g.year_made, g.serial!';
    p_sql: = p_sql | q'! g table_g where g.status = 1!';

    If: P45_YEAR_MADE is not null then
    p_sql: = p_sql | q'! and $P45_YEAR_MADE = g.year_made!';
    end if;
    If: P45_SERIAL is not null then
    p_sql: = p_sql | q'! and upper (g.serial) like '% "| Upper ($P45_SERIAL) | » %' !';
    end if;
    If: P45_WIDGET_SEARCH is not null then
    p_sql: = p_sql | q'! and upper (g.widget) like '% "| Upper ($P45_WIDGET_SEARCH) | » %' !';
    end if;

    p_instr: = instr (p_sql, 'of g table_g where g.status = 1');
    p_sql_count: = ' select count (g.id) of "| substr (p_sql, p_instr);

    p_sql_count: = replace (replace (replace (p_sql_count, ' $P45_YEAR_MADE ',: P45_YEAR_MADE), "$P45_SERIAL", "' |: P45_SERIAL |)) ('), "$P45_WIDGET_SEARCH", "' | : P45_WIDGET_SEARCH | '''');

    run immediately p_sql_count in p_count;

    / * the following

    : P45_COUNT: = p_count;

    gives this error when I submit the region in the development environment

    ERR-1002 unable to find point item ID 'P45_COUNT' in the application '4000 '.

    */

    Select count (1) in the table_sql p_table_count where app_session =: APP_SESSION.
    If p_table_count = 0 then
    insert into table_sql (app_session, sql_text, session_date, count) values (: APP_SESSION, p_sql_count, sysdate, p_count);
    on the other
    Update table_sql set sql_text = p_sql_count, session_date = sysdate, count = p_count where app_session =: APP_SESSION.
    end if;

    / * the above written SQL and count of a table * /.

    Return replace(p_sql,'$',':');
    end;

    Hello

    Try the suggestion of Scott in Re: how to get the query region "PL/SQL function body returns the query string"?

    Andy

  • C310 printer all-in-one... reloaded software but can not find the SCAN function

    HP Photosmart prem c310 with OS X 10.8.4.     The scan function has stopped working.  I removed the software and begin by downloading the all-in-one driver software on the HP site.  To install it without problem, but the pilot for the sweep feature that used to have an icon at the bottom of my MAC, did not reappear.  I don't find it or it does not exist.  I can't use the SCAN function without going through the application of screenshot on my MAC and I love how that works... its not as clean and user friendly than the driver of HP scanning function.  How to make it work again?

    Hello

    Launch installation once more, don't forget to check the recommended software HP during the installation:

    http://h10025.www1.HP.com/ewfrf/wc/softwareDownloadIndex?softwareitem=MP-111986-1&cc=us&DLC=en&LC=en&

    OS = 4142 & product = 4231205 & sw_lang =

    Once you are done go to Applications > Hewlett-Packard and open the HP scanning application.

    Shlomi

  • Make it more modular functions

    Here's what I have...

    for (var i: int = 0; i < numberOfChildren; i ++)
    {
    nor = new newsItemButtonMC();

    NI.x = numLeftPad + ((niWidth*i) + niSpacing);
    NI.y = 3;
    ni.buttonMode = true;
    ni.mouseEnabled = true;
    ni.textNumber.text = (i + 1);

    ni.addEventListener (MouseEvent.CLICK, showItem1);
    ni.addEventListener (MouseEvent.MOUSE_OVER, showTitle1);
    ni.addEventListener (MouseEvent.MOUSE_OUT, hideTitle1);
    addChild (nor);
    }


    Without knowing all the ins and outs you can always get the general idea.  I create several buttons, change the title on them, and then add event listeners.

    I want to make this as extensible as possible so I need to be able to build 1 function that can handle "showItem.  At the present time, showItem1 that...

    function showItem1(e:MouseEvent):void {}
    itemNum = 1;
    showNext();
    }

    It is, essentially, the action for "button 1.  I need to be able to do the action for all the buttons so I want to be able to dynamically choose what value of the itemNum to according to what button clicked on it.

    How do I do that?

    TIA.

    You can try something like:

    function showItem1(e:MouseEvent):void {}
    itemNum = int (e.currentTarget.textNumber.text);
    showNext();
    }

  • NB250-107 - extra Q: drive, without function (?)

    I have a * NB250-107 * and so far I do not know why my machine has a * local disk 'Q' * as shown below, without function (not available)

    [windows Explorer Q - full screen player | http://img42.imageshack.us/img42/4738/localdiskq00.png]
    [windows Explorer Q - main screen player | http://img809.imageshack.us/img809/5669/localdiskq01.png]
    [windows Explorer Q - screen message player | http://img197.imageshack.us/img197/169/localdiskq02.png]
    [properties drive Q - main screen | http://img217.imageshack.us/img217/4206/localdiskq03.png]
    [Management - main records screen | http://img51.imageshack.us/img51/6358/localdiskq05.png]

    You have an idea?
    Thank you

    Post edited by: carlob

    Hello

    It seems that the local disk Q: does not appear in disk management and therefore it cannot be a partition on the HARD drive.
    I think that it of also not a Toshiba HDD recovery partition or partition where the HARD drive files are stored.

    Have you noticed this local disk Q: from day of purchase?
    Do you have any USB flash stick or USB devices connected to the laptop?

  • Toshiba 40RL933 - can't program recording of TV programs

    I just bought an external hard drive and I plug my 40RL933. The TV is able to see the HD but I can't program recording of TV programs. I updated the software, but no new version is available. The USB Autostart parameter has on.

    Y at - it no object other than I have to do?
    Thanks for your help.

    > Is - anyone know how to download the user manual. I can only find the technical specification but is not cold the way the path to download the manual.

    Have a look here:
    http://www.Toshiba-OM.NET/LCD/PDF/English/RL933-233240-English.PDF

    * Page 40-> USB HDD recording function

  • that either the app can make me drawing on a photo with a pen?

    that either the app can make me drawing on a photo with the stylus? I tried with Picsay Pro, but I couldn't find the pen function. Are there any suggestions?

    If you have installed Evernote you can also send your project to Evernote and possibly save with this app.

Maybe you are looking for

  • Siri handsfree "Hey Siri" February 22, 2016 does not

    I'll implement speech recognition of Siri the thing free hands while it is plugged into the charger, and it shuts off hitch the first time. Then, I took my iPhone and play music through it while driving. Much to my dismay when trying to get direction

  • OfficeJet Pro 8600: USB connected OfficeJet Pro 8600: scanning on a network: is it possible?

    Hello world. I have a 8600 OfficeJet Pro connected to a computer via the usb port. This computer is running Windows 7 Professional and is connected to an ethernet network. The printer is shared with other computers (currently running either Win & and

  • Vertical lines on the Photos using HP Photosmart Plus

    I just bought the HP Photosmart Plus last week.  The 1st photos I printed, using the paper supplied with the printer (HP Advanced), went well.  My wife bought "Printworks' 4 x 6 sheets of brand.  First of all, I had a paper jam.  I don't know if it's

  • May have gotten rid of the pirate, but funky computer

    I had a pirate for a bit. He's not kidding too. But finally noticed it linked by 'riding piggy back '? Then came out and set password boot... Maybe that will be the case, but the computer is very slow and BIG and kind of weird looking. Until now the

  • How to set a layer style and not have some shape layers overlap?

    I don't know how to explain this very well, but I've created a mp4 to demonstrate what I worked on. I want to make sure when I apply a shadow effect drop, that all layers are affected but aren't above the knees. It is the video.Shape layer 2 are the