This type of possible to query (select with based correspondence stop lines)

I'm trying to write a SQL query and suspect it is impossible. Or at least, I cannot not mentally grasp, despite various stabs with subqueries. I simplified it by changing the metaphor here a bit.

Let's say I have a truck in a city (say, Chicago). There are several roads leading out of town, with routes, we will label according to the compass points (N, NE, SW, etc.) Each truck can carry only one shipment. It starts along his route, and as soon as it comes to a city in need of his expedition, he stops.

Yes, one cooked, but it is similar to my problem.

Here is a table:

TABLE: truck_routes
scenario (integer - possible scenarios)
Route (NE, SW, etc - 8 cardinal points)
destination (towns along this road)
sequence_number (order in which should go to the cities)

So if I have a truck in Chicago, I can tell

SELECT the road, sequence_number, destination
OF truck_routes
Scenario WHERE = 10 (or other)
ORDER BY road_out, sequence_number;

And I would get a report like this:

SE 1 Gary
SE 2 Valparaiso
SE 3 Plymouth
SE 4 Warsaw
NO 1 Michigan City
2 Kalamazoo
ONLY 3 Grand Rapids
DO 4 Cadillac
ONLY 5 Traverse City

So far so good. I have another table with a list of cities that must be the subject of the expedition:

TABLE: cities
scenario (integer - possible scenarios)
Route (NE, SW, etc - 8 cardinal points)
destination (same keys as in truck_routes)

for example:

10 Valparaiso SE
Warsaw SE 10
10 DON'T Cadillac
10 DON'T cross City

Now... the delicate part... How do rewrite the query above so that after a truck hit a city in need of a shipment (in this case), it stops? In other words, I want a report (for all channels) of which cities the truck stops to- and such that mentioned, it stops at the first one she performed. I don't want to see lines beyond that. If the report is as follows:

SE 1 Gary
SE 2 Valparaiso
NO 1 Michigan City
2 Kalamazoo
ONLY 3 Grand Rapids
DO 4 Cadillac

Gary arises because it does not require a delivery. Valparaiso (road SE, sequence_number 2) arises because he takes delivery. The rest of the Southeast route does not appear. Same thing for the road DON'T.

There are scenarios where I actually want to stop at the city just before the place of delivery, etc. and of course in the real world, that it's more complicated, but I think that if I could get this working model I could flesh out in a real-world application.

Certainly I can code something in PL/SQL for this do, or do it in the logic of the application - but I wonder if there is a way to do it in a single SQL statement? I suspect there is something that could be built with subqueries and sorting, but... I can't reach him quite ;-)
WITH report AS(
    SELECT 'SE' route, '1' seq_num, 'Gary' dest  FROM DUAL UNION ALL
    SELECT 'SE' route, '2' seq_num, 'Valparaiso' dest FROM DUAL UNION ALL
    SELECT 'SE' route, '3' seq_num, 'Plymouth' dest FROM DUAL UNION ALL
    SELECT 'SE' route, '4' seq_num, 'Warsaw' dest FROM DUAL UNION ALL
    SELECT 'NE' route, '1' seq_num, 'Michigan City' dest FROM DUAL UNION ALL
    SELECT 'NE' route, '2' seq_num, 'Kalamazoo' dest FROM DUAL UNION ALL
    SELECT 'NE' route, '3' seq_num, 'Grand Rapids' dest FROM DUAL UNION ALL
    SELECT 'NE' route, '4' seq_num, 'Cadillac' dest FROM DUAL UNION ALL
    SELECT 'NE' route, '5' seq_num, 'Traverse City' dest FROM DUAL
),
cities AS (
    SELECT '10' scenario, 'SE' route, 'Valparaiso' city FROM DUAL UNION ALL
    SELECT '10' scenario, 'SE' route, 'Warsaw' city FROM DUAL UNION ALL
    SELECT '10' scenario, 'NE' route, 'Cadillac' city FROM DUAL UNION ALL
    SELECT '10' scenario, 'NE' route, 'Traverse City' city FROM DUAL
),
need_a_shipment AS (
      SELECT r.*
          , CASE WHEN EXISTS( SELECT 'Y' FROM cities c WHERE c.route = r.route AND c.city = r.dest )
                 THEN 'Y'
                 ELSE 'N'
            END need_a_shipment
    FROM report r
)

SELECT  route
      , seq_num
      , dest
      , need_a_shipment

FROM need_a_shipment n
WHERE seq_num <= (  SELECT MIN(seq_num) FROM need_a_shipment
                    WHERE route = n.route AND need_a_shipment = 'Y' )
ORDER BY route DESC, seq_num
;

ROUTE SEQ_NUM DEST          NEED_A_SHIPMENT
----- ------- ------------- ---------------
SE    1       Gary          N
SE    2       Valparaiso    Y
NE    1       Michigan City N
NE    2       Kalamazoo     N
NE    3       Grand Rapids  N
NE    4       Cadillac      Y

Tags: Database

Similar Questions

  • query selection with numbers

    I have something on my site, which select bands with the letter that is clicked

    < name cfquery = 'results' datasource = '#APPLICATION. DataSource #">"
    SELECT *.
    Of artist_art
    WHERE the bandname_art as '#url.firstletter#% '.
    < / cfquery >
    http://www.musicexplained.co.uk/index.cfm
    the thing is, im trying to consolidate all the bands that start with a number together and am unsure of the symbol which refers to "all numbers" in coldfusion...
    Searched everywhere, but this place seems to be the only place with responses from lately, so...

    Thank you

    you spend a specific number in the URL? If you are, this is the same code that you (WHERE bandname_art LIKE ' % #url.firstLetter # ').

    If you use the sign # and want to get the strips that begin with any number from 0 to 9, check if access supports regex. in SQL Server, the following would work:

    WHERE bandname_art LIKE ' [0-9] %'

    can't vouch for access tho.

    EDIT: If Access doesn't support it, the worse your query will look:

    WHERE bandname_art LIKE ' 0% ' GOLD bandname_art AS 1% ' OR bandname_art LIKE 2% '...

    -or-

    WHERE left (bandname_art, 1) with ('0', '1', '2', '3', '4', '5' ', 6',' 7 ', ' 8',' 9 ', ' 0')

    (the latter is where I think that Dan was trying to direct you towards)

  • What happened to the ability to hide the "mobile dash" (CTRL/CMD (H) in Photoshop?  I can't see the edges of my selection with the mobile dotted lines in the way!

    I used Photoshop since version 2.5 when it came to 16 disks.  In all versions I've bought over the years (many) up to CS3, I've always been able to use CTRL + H (Windows) or CMD + H (Mac) to hide the "mobile dash" edge of the selection.  This is extremely useful when doing all sorts of adjustments where the outline of the selection must be considered while "fiddling with the buttons" (so to speak).  Without being able to hide the limits of selection ("mobile dash"), I often have to get a better idea, cancel the selection, get disgusted that the edge is not what I want, then have to cancel, select new, try again... over and over again.   It is a SIMPLE feature, but the lack of it, driving me crazy.  HELP, I tried, but it doesn't have the height of the promise.  If there is a way to hide the dotted moving line, where is the menu item, and what the shortcut?

    You can assign Ctrl/Cmd-H to hide the edges of the selection (Edit > keyboard shortcuts) only, if you want to hide everything, but you will be notified if any other function has the shortcut.

  • Find paragraphs with fewer than 2 lines

    The following is a script request...


    Anyone who wishes to create a script for me who find all paragraphs in a history selected with less than 2 lines and change the style of the paragraph.  It would be for use in a magazine for styling all body headers in a story.  It would be necessary to limit the changes only the text inside the selected story.  I would also need to be able to customize the name of the header of the body paragraph style.

    That's what you want and more...

    http://in-tools.com/plugin.php?p=6

    Substances

  • This is how a SELECT query fails with ORA-1555 occur?

    11 GR 2/RHEL 6.2

    I would like to know exactly how a SQL fails with error ORA-1555.

    Please take a look at the following simple example.

    INVENTORY_DETAIL is a table that stores information about items in a store.

    For this DB UNDO_RETENTION is set to 3 600 (1 hour) and TUNED_UNDO_RETENTION Meanwhile 5400 (1.5 hours)

    At 15:00, there's 12 Logitek involved in inventory.

    ITEM_ID NOM_ELEMENT STOCK_LEFT

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

    8432 LOGITEK 12 SPEAKER

    At 15:00 Session1, starts a SELECT large with several tables joins query. Something like

    Select id.item_id, id.item_name, su.supplier_price, su.supplier_code

    Su.batch_code...

    of INVENTORY_DETAIL id join in-house suppliers knew on (id.supplier_id = su.supplier_id)

    ...

    ..

    03:02, Session1 reads the block that stores the line with item_id = 8432 and learns that he has 12 Logitek left speakers.

    15:10, Session2 delivers the next UPDATE and he agrees immediately.

    Update inventory_detail set stock_left = 7 where item_id = 8432;

    commit;

    The UNDO data for Session2 transaction are stored in the measure of cancellation remaining, and the UNDO data gets debusquees at 04:40 when the TUNED_UNDO_RETENTION of 1.5 hours is crossed at 16:40.

    Because of the bad of e/s, query SELECT of Session1 manages to retrieve all the records only from 17:00.

    But session1 notice this line with item_id = 8432 changed. Now, there's only 7 Logitek speakers which is inconsistent with what he learned at 15:02 (who was then at 12). Because of this incompatibility SO not able to recover data UNDO on this gap, ORA-1555 is thrown. My assumptions are good?

    3:10PM                             4:10PM                          4:40PM                       5:00PM

    |===================================|-------------------------------|-----------------------------|

    UNDO_RETENTION = 1 HR retention Undo Tuned = 1.5 h finishes of request for enforcement

    Martin, you asked, "are the correct on the circumstances that led to ORA-1555 my explanations?  The answer is no.  Oracle does not notice at the end of the query that changed a line he read.  Instead, each read line is at the same point in time.  When Oracle sees that a row has changed Oracle reads the UNDO segments to find the version of the data corresponding to the query start time.  If these data cannot be found the ORA-01555 error is raised.

    - -

    HTH - Mark D Powell.

  • Is it possible to add "Open with" to context menu right click while we select several files?

    I found somw ways to add 'Open with' to the right, click pop up constantly, but I want to know if it is possible to add this option to select a group of files of the same type.

    Please guide me if I make a mistake.

    Thank you

    1. right click on the interested file called 'test1.abc '.

    2. click on 'Open with' option

    3. Select the application needed to open the file

    4. Please activate option "always use the selected program to open this type of file"

    5. click on ok

    Subsequently all "* .abc" files (test2.abc, test3.abc etc.) are opened by preferred application (selected) you in what precedes.

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

    If this response has resolved your problem, please select this answer as a response

  • Windows will not honor "always use the selected program to open this type of file."

    When I try to open a file *.img using 'open with... '. "I get a window of"Leader Type Helper"asking what software I want to use.  I have check "open this file using a software program (sic) that (sic) is already installed."  This very unnecessarily opens another dialog box titled 'open with' * Sub * the files already browser window fill the screen while I'm not yet aware that the box is here.  Having managed to find, I choose "7-Zip File Manager" and click on the box always saying "use the selected program to open this type of file", and then click OK.  This opens the file using the selected program, as you wish.

    However next time I try to open a *.img file, I again get the window "Help file of Type" and must go through the whole process again.  (By double-clicking on the file shows "Windows Disc Image Burner".)  Why don't Windows 'always use the selected program' like I asked?  Windows is aware that I have chosen before, because it is considered to be the only 'recommended program' in the 'Open with' dialog box  Thanks for any help!

    Care to try another tool?  This small utility can help: http://izt.name/apps/types/

    You will find the file type in the list of icons (.img files, then), and then to change what he uses to open the file by clicking on the option 'open' and edit the properties.

  • inadvertently, click "always use the selected program to open this type of file" how undefault and redo icon to the icon of white empty file?

    I accidentally click "always use the selected program to open this type of file" on the srt file. How to make it undefault and again the icon to icon file empty white?

    You can do this via a registry change, but it is more appropriate for a typical user to simply use the system restore:

    System restore

    Ever wished that you can go back in time following a bad fall? With Windows, you can.

    Installation sometimes a driver or a program can make Windows run slowly or erratically. System Restore can return programs and system files from your PC to a time where everything worked, potentially prevent hours of troubleshooting of headaches. This will not affect your documents, images or other data.

    In Windows 7, you can create system restore points more and see exactly what files will be deleted or added when your PC is restored. For more information, see create a restore point.

    For more protection, use the restore system backup and restore, which is designed to help save email, photos, documents and other personal files.

    To use the system restore

    Before you start the system restore, save open files and close all programs. System Restore will restart your PC.

    1. Open system restore by clicking the start . In the search box, type restore the system and then, in the list of results, click on system restore.  If you are prompted for an administrator password or a confirmation, type the password or provide confirmation.
    2. Follow the steps in the wizard to select a restore point and restore your computer.

      For more information, see System Restore: frequently asked questions.

    In Windows 7 system restore can prevent headaches hours after an accident.

  • Is it possible to automate this type of snippet indented?

    Is it possible to automate this type of snippet indented with a vertical row of dots in the left margin? I have a manuscript of 600 000 words with this type of snippet running across it. Author has set up as a separate style in the manuscript, but she throws herself with normal text. Someone has an idea how this could be implemented under the paragraph style or other thing INDD roadmap? Using INDD CC thanks!

    StClare Extract.jpg

    If you want: a paragraph with this fully automatic effect style, you will need to ParagraphBorder, from DTPUtils, because InDesign doesn't know how to do it!

    Useful DTP | Products | Paragraph border

  • How can I perform this type of beach using DPL join query?

    How can I perform this type of beach using DPL join query?

    SELECT * from t where 1 < = t.a < = 2 and 3 < = t.b. < = 5

    In this pdf file: http://www.oracle.com/technology/products/berkeley-db/pdf/performing%20queries%20in%20oracle%20berkeley%20db%20java%20edition.pdf,

    It shows how to perform "Two motion equal on a single primary database" like SELECT * TAB WHERE A = col1 AND col2 = B using the join entity class, but it does not give a solution on the range join query.

    Right, you can only use an index for this query. If you do not need another index for another query, you might fall (remove @SecondaryKey).

    -mark

  • Can we add this type on the Windows Server that comes with the Microsoft Action Pack subscription?

    Can we add this type on the Windows Server that comes with the Microsoft Action Pack subscription?

    Hello

    The question you have posted is related to professional level support. Please visit the link below to find a community that will offer in support of your request:

    http://social.technet.Microsoft.com/forums/en/category/WindowsServer

  • Problem with installing the game "no apps are installed to open this type of link try find at the store.

    Original title: problem with installing the game

    install a game but saying o\s

    No apps are installed to open this type of link try find in the store and when I opened store it for the app its available nt tried compatibility troubleshooting but no use it please help

    Hi harsh,

    For a better understanding of the issue, I would need more information on your side.

    1. What is the name of the game you install?

    2. where did you install the game from?

    3. What is the full error message?

    4. the question facing you while opening the store Windows or you are looking for an app? Have what compatibility troubleshooting steps you tried?

    To resolve the problem with applications, I suggest you try the procedure described in the article and see if it helps.

    Solve problems with a soft

    Please provide the necessary information to help you further, I'll be happy to help you.

  • PROBLEMA: PHOTOMERGE NOT RUN! AND GET THIS ERROR MESSAGE: ERROR 22 WINDOWS NOT HAS DI A COSTRUTTORE LINEA 388 VAR W = NEW WINDOW (RES) PLEASE, IF POSSIBLE, HELP ME. THIS PROBLEM IS ONLY WITH WINDOWS 10!

    Adobe Photoshop version: 13.0.1 (13.0.1.3 20131024.r.34, 2013/10 / 24:21:00:00) x 64

    Operating system: Windows NT version: 6.2 Architettura di sistema: Famiglia CPU AMD:15, Modello:10, Stepping: 0 con MMX, SSE Intero, SSE FP, SSE2, SSE3

    Fisico processore Conteggio: 6 Velocità processore: 3214 MHz

    PROBLEMA: PHOTOMERGE NOT RUN! AND GET THIS ERROR MESSAGE: ERROR 22 WINDOWS NOT HAS DI A COSTRUTTORE LINEA 388 VAR W = WINDOW (RES) NEW

    PLEASE, IF POSSIBLE, HELP ME. THIS PROBLEM IS ONLY WITH WINDOWS 10!

    Hi biagiob,

    Seems that the operating system is obsolete.

    Photoshop CS6 has not been tested on Windows NT in accordance with this article: Photoshop system requirements

    Suggest you to see this link to the similar problem: Photoshop: Err: "window 22 has no constructor" (Win 7/64 bit)

    Kind regards

    Claes

  • I downloaded and installed creative cloud with no problems. From the window of creative cloud cannot display the APPS page (while other 'Home', 'Community' can be seen). This is why I can't select the application to be updated. Thanks for your help

    I have download and install creative cloud with no problems. In the window of creative cloud cannot display the APPS page (while other 'Home', 'Community' can be seen. This is why I can't select the application to be updated. Thanks for your help

    Please refer to the threads below where the issue has been addressed:

    Re: desktop is not displayed Panel apps? PC

    Missing Creative Cloud Desktop applications tab

  • How can I search all subjects in my guide? and if this is not possible, how do I get books have not not subjects with the same name?

    How can I search all subjects in my guide? and if this is not possible, how do I get books have not not subjects with the same name?

    "People need be able to find these without having to look inside each book TOC.

    Sorry, but I'm not a big fan or user of this sensitive arrangement "New kid on the block. Therefore, it may be that I am simply misunderstanding because I do not regularly use it. Of what you say, it seems to me that if you (or more precisely your users) are not able to click on the right side, where he says 'Getting Started' or 'List of Email Campaign' and see these topics open and view the content with search terms highlighted?

    Regarding the "bookmarks", those that are normally visible by the user and will be not viewable unless the name of the bookmark appears also as text within the topic. Although, if the two are different, you could probably get there by adding the name of the bookmark as a keyword search in the properties of the section.

    In any case, I feel that at this point, I can just be frustrating you and you may need someone else to try to help that probably better understand the issue.

    Sorry, I was not able to help.

    See you soon... Rick

Maybe you are looking for

  • Portege M200 - How can I change the BIOS battery?

    Hallo, I have a Portege M200 and I want to change the battery of the BIOS but I don't know where it is! Can someone help me?Thank you!

  • Error reading database! help needed please.

    My project is to monitor the ovens. The oven temperature is obtained with the help of advantech ADAM module. Each material between the oven and an alert is given out after the hour you want inside the oven. When I run this program. an error exactly 1

  • Blocked sender: alert

    I use Windows Live Mail to years (2012) and all of a sudden one of my blocked senders get through.  This isn't a scam, not someone who changes addresses, etc..  Only a business standard that I don't need to hear.  Their domain is blocked, sent junk m

  • Code DAQ Express reports difficult DT

    All, I have a strange problem where some code DAQ Express reports systematically bad DT. This occurs with peripheral equipment and a simulated device. I've attached screenshots detailing everything that I found relevant to the problem as well as the

  • How to disable notification 'Get Windows 10' of the taskbar?

    * Original title: 10 Windows and taskbar Anyone know how to get rid definitely an upgrade of windows 10 come in my task bar, I already had on my other computer I deleted the list "windows update", he disappears from the bar and then when I reboot but