order by with an additional condition?

Hello

Oracle 11g r2.

I have a few items (let's say the dominoes of a domino game that are placed on one table in front of the other).
Sometimes, between the 2 items, I have a beam (piece of wood) which is an element too.

I have tables that store the entry and exit of each element and the distance accumulated between them.
A point is identified by a name of area (where it is placed), a class, a number (not really, just an identifier) and type of point (entry (E) or output (S)).
CREATE TABLE SPATIAL_POINTS (
     SPAT_ID INTEGER,
     SPAT_AREA_NAME VARCHAR2(10),
     SPAT_CLASS VARCHAR2(15),
     SPAT_NUMBER VARCHAR2(15),
     SPAT_PT VARCHAR2(1),
     ...
     CONSTRAINT PK_SPAT_ID PRIMARY KEY(SPAT_ID),
     CONSTRAINT FK_SPAT_AREA FOREIGN KEY(SPAT_AREA_NAME) REFERENCES AREAS(AREA_NAME),
     CONSTRAINT CHK_SPAT_PT CHECK(SPAT_PT) IN ('E','S')
);

CREATE TABLE ALL_COORDINATES (
     ALL_ID INTEGER,
     ALL_SPAT_ID INTEGER,
     ALL_CUMUL NUMBER(15,9),
     ...,
     CONSTRAINT PK_ALL_ID PRIMARY KEY(ALL_ID),
     CONSTRAINT FK_ALL_SPAT_ID FOREIGN KEY(ALL_SPAT_ID) REFERENCES SPATIAL_POINTS(SPAT_ID),
);
Here is an example of data:
select
     spat_area_name as "AREA",
     spat_class as "CLASS",
     spat_number as "NUMBER",
     spat_pt as "POINT",
     all_cumul as "CUMUL DIST"
from
     spatial_points inner join all_coordinates on spat_id = all_spat_id
where
     spat_area_name = 'P61'
order by
     all_cumul,
     spat_class,
     spat_number,
     spat_pt


AREA     CLASS     NUMBER     POINT     CUMUL DIST

P61     POUTRE     01     E     -0.07700
P61     CLSNA     0105     E     0.00000
P61     CLSNA     0105     S     0.00400
P61     CLSNB     0110     E     0.05600
P61     CLSNB     0110     S     0.12400
P61     CLBPE     0125     E     0.37240
P61     CLBPE     0125     S     0.37240
P61     CLSNC     0130     E     0.44500
P61     CLSNC     0130     S     0.45500
P61     CLSNC     0140     E     0.79500
P61     CLSNC     0140     S     0.80500
P61     CLSNC     0160     E     0.99500
P61     CLSNC     0160     S     1.00500
P61     CLMTV     0165     E     1.06100
P61     CLMTV     0165     S     1.14100
P61     CLBPE     0166     E     1.18440
P61     CLBPE     0166     S     1.18440
P61     CLSNC     0170     E     1.19500
P61     CLSNC     0170     S     1.20500
P61     POUTRE     01     S     1.32300
P61     POUTRE     02     E     1.36000
P61     CLSND     0210     E     1.37750
P61     CLSND     0210     S     1.42250
P61     CLPBU     0215     E     1.50700
P61     POUTRE     02     S     1.54200
...     ...     ...     ...     ...
I want to display the points sorted by distance (as in the example), but I want to show at each point of exit right after the entry point, I don't want all the other points to apear beetween an entry and an exit point of the same element.
I want to order by cumulative distance of entry points (E) and then add the exit point (S) after each entry point regardless of the cumulative distance of the outlet. I hope I'm understandable!

Here is an example of what I want, according to the example above:
AREA     CLASS     NUMBER     POINT     CUMUL DIST

P61     POUTRE     01     E     -0.07700
P61     POUTRE     01     S     1.32300
P61     CLSNA     0105     E     0.00000
P61     CLSNA     0105     S     0.00400
P61     CLSNB     0110     E     0.05600
P61     CLSNB     0110     S     0.12400
P61     CLBPE     0125     E     0.37240
P61     CLBPE     0125     S     0.37240
P61     CLSNC     0130     E     0.44500
P61     CLSNC     0130     S     0.45500
P61     CLSNC     0140     E     0.79500
P61     CLSNC     0140     S     0.80500
P61     CLSNC     0160     E     0.99500
P61     CLSNC     0160     S     1.00500
P61     CLMTV     0165     E     1.06100
P61     CLMTV     0165     S     1.14100
P61     CLBPE     0166     E     1.18440
P61     CLBPE     0166     S     1.18440
P61     CLSNC     0170     E     1.19500
P61     CLSNC     0170     S     1.20500
P61     POUTRE     02     E     1.36000
P61     POUTRE     02     S     1.54200
P61     CLSND     0210     E     1.37750
P61     CLSND     0210     S     1.42250
P61     CLPBU     0215     E     1.50700
...     ...     ...     ...     ...
In this way 'E' and ' go for the points of the "BEAM", and we don't care about cumulative distance of ' point.

I tried some things with PARTITION BY, but without success.

Any idea on how I can achieve this? I need a query, no PL/SQL.

Thank you!

Yann.

As...

select *
from(
select
    spat_area_name as "AREA",
    spat_class as "CLASS",
    spat_number as "NUMBER",
    spat_pt as "POINT",
    all_cumul as "CUMUL_DIST",
    min(CUMUL DIST) over(partition by spat_area_name) mn
from
    spatial_points inner join all_coordinates on spat_id = all_spat_id
where
     spat_area_name = 'P61'
order by
     all_cumul,
     spat_class,
     spat_number,
     spat_pt)
order by mn,AREA,CUMUL_DIST

tested with the EMP table. The query below will be stopped first by empno, then it will show all employees of the particular department...

SQL> select empno,deptno
  2      from scott.emp
  3      order by empno;

     EMPNO     DEPTNO
---------- ----------
      7369         20
      7499         30
      7521         30
      7566         20
      7654         30
      7698         30
      7782         10
      7788         20
      7839         10
      7844         30
      7876         20
      7900         30
      7902         20
      7934         10

14 rows selected.

SQL> select *
  2  from(
  3      select empno,deptno,min(empno) over(partition by deptno) mn
  4      from scott.emp
  5      order by empno
  6      )
  7  order by mn,deptno,empno;

     EMPNO     DEPTNO         MN
---------- ---------- ----------
      7369         20       7369
      7566         20       7369
      7788         20       7369
      7876         20       7369
      7902         20       7369
      7499         30       7499
      7521         30       7499
      7654         30       7499
      7698         30       7499
      7844         30       7499
      7900         30       7499
      7782         10       7782
      7839         10       7782
      7934         10       7782

14 rows selected.

Published by: JAC on April 3, 2012 19:40

Tags: Database

Similar Questions

  • No problem with the addition of a Kingston SSDNow V300 240 GB SDD to a D7-1245dx?

    A knowledge of any problems with the addition of a Kingston SSDNow V300 240 GB SDD to a D7-1245dx? Its size is 7mm width 69,85 mm x depth 100mm height but not sure of the size of the computer laptop berries/caddy supports

    Decide whether to use the laptop for a little longer so to upgrade the system to a Kingston 240 GB SDD drive and move the current drive to the secondary location (already got 2nd coming of caddy). It lets me do a bit more space on the laptop in addition to increasing performance.  Figure between an SSD and get up to 8 GB ram it should last a little longer.

    You will have a shopping cart for the SSD, but it looks like you have an and get a second wagon. Dv7-1000 series does not use a cable or connector. the hard disk plug right into SATA ports on the motherboard. 7mm drive has the connectors SATA and the mounting holes exactly in the same place as a 9.5 mm drive. All is just shorter so the reader rides low in the caddy. As a swimming pool with 20% water let out. 7mm SSD works perfectly. Windows 7 or 8/8.1 are preferred; Vista is not configured to treat SSDS as well or easily.

    If it's 'the Answer' please click on 'Accept as Solution' to help others find it.

  • can someone help me with the addition of an account for child microsoft under a perintal account

    need of assistants with you that links child account to perintal for the child account is connected to Xbox live Microsoft account. He is asked to accept the terms of use on the Xbox site. She also asked inter in perinatal password and ID. The perinatal e-mail password was disassociated from the perinatal account. went to account.live.com account add kid account with parental account but how always to choose the option to add an account it takes me to a new page and I don, t know how to navigate the page. Can someone from Microsoft help me please with the addition of my son's account to my account.

    Hello

    Did you manage on behalf of your son using a parent account? You have already set up a parental control using the Windows parental control? If it isn't yet, please visit the link below on how to set up parental controls on your son's account by using Windows parental control:

    Bind the child account for a Parent account

    You can also download the installer of Windows parental control in the link below:

    http://Windows.Microsoft.com/en-us/Windows-Live/Essentials-home

    If you have any other questions, please let us know.

    Thank you!

  • Using laptop with an additional monitor above. To set the default appearance as Monitor 2 above 1 monitor

    I can set up my laptop with an additional monitor as extended desktop.  By going to the followed control panel display I can manually fix the default setting for the two monitors side by side, to have one on the other.

    However, every morning when I do my laptop in to work and reconnect to the extra monitor I have to redo it.  Is there a way to set the default display settings so that it affects automatically two monitors as one above the other?

    Using Windows XP Pro.  Help appreciated.

    Hi Andrew_Wright,

    Windows XP does not record the settings once you unplug the extra monitor.

    You can use some third party such as the software provided with the video driver software.

    Use your favorite search engine to find all these software for you help.

    Important: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

  • When I try to watch/listen to media on Google Chrome, a yellow bar with ' an additional plugin is required to view some items on this page

    Original title: plugin prob

    When I try to watch/listen to video and other media on Google Chrome, a yellow bar with ' an additional plugin is required to view some items on this page "always comes to the top. I found it quite frustrating, and when I do not click on 'Install plugin' Google Chrome is unresponsive. I then refresh the page, click on the yellow bar once again. How can I change the additional Plugin to websites like YouTube etc. ?

    Start here: http://support.google.com/chrome/?hl=en

  • order by with analytic function

    Hi gurus

    Need your help again.

    I have the following data.

    Examples of data

    Select * from

    (

    As with a reference

    (

    Select ' 100 ', ' 25' grp lb, to_date('2012-03-31') ter_dt, 'ABC' package_name FROM DUAL union all

    Select ' 100 ', ' 19', to_date ('2012-03-31'), 'AA' OF the whole union DOUBLE

    Select ' 200 ', ' 25', to_date('2012-03-31'), 'CC' FROM DUAL union all

    Select ' 300 ', ' 28', to_date('2012-03-31'), 'XX' from DUAL union all

    Select ' 300 ', ' 28', to_date('4444-12-31'), 'XY' from DUAL

    )

    Select the grp, lb, ter_dt, Package_name

    ROW_NUMBER() over (partition by order of grp by case when lb = '19' then 1)

    When lb = '25' then 2

    ro_nbr end)

    Reference)

    -where ro_nbr = 1

    ;

    -----------

    The query above returns the following result:

    Existing query result

    GRP LB TER_DT package_name RO_NBR

    1001903/12/31AA1
    1002503/12/31ABC2
    2002503/12/31CC1
    3002803/12/31XX1
    3002844 12-31XY2

    If you can see the data above then I use the order clause with function row_number analytic and prioritize data according to LB using the order by clause.

    Now the problem is I need simple stored against each group so I write the following query:

    Query

    Select * from

    (

    As with a reference

    (

    Select ' 100 ', ' 25' grp lb, to_date('2012-03-31') ter_dt, 'ABC' package_name FROM DUAL union all

    Select ' 100 ', ' 19', to_date ('2012-03-31'), 'AA' OF the whole union DOUBLE

    Select ' 200 ', ' 25', to_date('2012-03-31'), 'CC' FROM DUAL union all

    Select ' 300 ', ' 28', to_date('2012-03-31'), 'XX' from DUAL union all

    Select ' 300 ', ' 28', to_date('4444-12-31'), 'XY' from DUAL

    )

    Select the grp, lb, ter_dt, Package_name

    ROW_NUMBER() over (partition by order of grp by case when lb = '19' then 1)

    When lb = '25' then 2

    ro_nbr end)

    Reference)

    where ro_nbr = 1

    ;

    The query result

    GRP LB TER_DT RO_NBR

    1001903/12/31AA1
    2002503/12/31CC1
    3002803/12/31XX1

    My required result is that 300 GRP contains 2 folders and I need the record with the latest means of ter_dt and right now, I only get the latest.

    My output required

    GRP LB TER_DT RO_NBR

    1001903/12/31AA1
    2002503/12/31CC1
    3002844 12-31XY1

    Please guide. Thank you

    Hello

    The query you posted is the ro_nbr assignment based on nothing other than lb.  When there are 2 or more lines that have an equal claim to get assigned ro_nbr = 1, then one of them is chosen arbitrarily.  If, when a tie like that occurs, you want the number 1 to be assigned based on some sort, and add another expression of Analytics ORDER BY clause, like this:

    WITH got_ro_nbr AS

    (

    SELECT the grp, lb, ter_dt, nom_package

    ROW_NUMBER () OVER (PARTITION BY grp

    ORDER OF CASES

    WHEN lb = '19' THEN 1

    WHEN lb = '25' THEN 2

    END

    , ter_dt DESC-* NEW *.

    ) AS ro_nbr

    REFERENCE

    )

    SELECT the grp, lb, ter_dt, nom_package

    OF got_ro_nbr

    WHERE ro_nbr = 1

    ;

  • I have an idea on the program application Adobe InDesign to increase the power of sale of Adobe InDesign, by adding an additional menu, with an additional menu that I hear more important for the future of printing.  How can I report directly to the

    I have an idea on the program application Adobe InDesign to increase the power of sale of Adobe InDesign, by adding an additional menu, with an additional menu that I hear more important for the future of printing.

    How can I report directly to the developer indesingn adobe...!

    You can create a feature here request:

    Feature requests/bug reports

  • Hi, I had problems with the addition of soundtrack to Adobe premiere elements 13. When I add it or drag it immediately comes crashing windows, where says "Adobe Premiere Elements has stopped working". I can add videos with no problems, but cannot add any

    Hi, I had problems with the addition of soundtrack to Adobe premiere elements 13. When I add or drag it happens immediately windows crash, where says "Adobe Premiere Elements has stopped working". I can add videos with no problems, but cannot add .mp3 files.

    I had Windows 8.1, 2.4 GHz, 6 GB of RAM. How to solve this problem?

    Fixed a problem when converting the mp3 file. WAV...

    some poor Adobe Premiere Elements if there is for example simple bug in the software.  Waste of money for this software.

  • Search strings / with some applied condition

    Hello comrades,.

    I am writing an extendscript which is supposed to loop through all of the PGF and find all the strings / with a certain condition applied (say, comment).

    The problem is that in the script guide, I couldn't find a function that retrieves the status of character property. I tried to use the function "charAt() (i)" js, but it doesn't seem to work in ARE. No idea how to implement such a function?

    Here's the 1st draft of the script.

    var doc is app. ActiveDoc;

    If doc. {ObjectValid()}

    checkCondFMt (doc);

    }

    else {}

    Alert ("no open section");

    }

    function checkCondFMt (doc) {}

    FMP var is doc. MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

    var CondObj is doc. GetNamedObject ("Comment");

    While (FMP. {ObjectValid()})

    var textItems is bmp. GetText(Constants.FTI_String |) Constants.FTI_LineEnd);

    var b = new TextRange();

    TR. Beg.obj = tr.end.obj = textItems;

    TR. Beg.offset = 0;

    for (var i = 0; i < tr.len; i ++) {}

    var c = tr.charAt (i);

    var PgfProps is doc. GetTextVal c [i], Constants.FO_CondFmt;

    Alert (PgfProps.Name);

    }

    PGF = bmp. NextPgfInFlow;

    }

    }

    Thanks in advance for your comments!

    OK, I see the problem now. JavaScript doesn't have a "block scope" for its variables. She carried the function, so your 'i' variable is used in more than a loop. You must use a different variable for the inner loop:

    for (var j = 0; j < oCond.length; j += 1) {
        if (oCond[j].Name == CondObj.Name) {
            applyCharFmt(textRange, doc);
        }
    }
    

    In the code example above, I use 'j' for a counter for the inner loop.

    In general, you can avoid problems of this kind to declare all your variables at the top of the function:

    function functionName (param1, param2) {
    
        var i, j, textlist; // etc.
    
        // function code...
    }
    

    That makes it easier to 'follow' variables and make sure that you do not use one more than once.

    -Rick

  • Need help with an additive attached to my class

    Hello

    I'm a bit new to Captivate. I have a problem and do not know which way to go or even if it is feasible.

    I created a course for medical personnel. A number of different types of employees taking the same course - RNs, therapists, social workers and so on.

    Asked me to add an addendum that will have only a discipline (OT). It's a few slides of information and 3 additional questions.

    What I'm trying to do, is when the user enters their medical discipline I use these data to direct them to the additive as appropriate.

    My problem is that I can't know if I should use questions branch up-to-date (I can't seem to get to work properly no matter how I do it), make a Multi-SCORM package with the additive as a second module that only some people will take or use the aggregator (which I have practically excluded because I think that I can't have it report to my LMS.)

    I use WIN 7, Captivate 7 and my LMS is the cornerstone. For example, we use only SCORM 1.2.

    I tried to quiz branch informed several ways but I get NaN results.

    I'm currently trying so he can work in Multi-SCORM with the user to take the first test, passing it, then if the user needs to the additive, jumping to the second SCO. But I can't do the link between the SCO to work because it is a local link when I put in place (open another project opens C:\User... project2.swf)

    I hope that's not too complicated. I'm a little drowned here.

    Thanks much for any help you can give!

    Pete

    It is after midnight here in Belgium. OK, in this case you should really check management up-to-date as well. The solution that I told you is that the content slides, but if the branch of knowledge is checked, normally 3 question slides last would not take into account for users who do not have the additive. The score slide must be at the end, after all question slides. And the jump to the slide of score must work to add users and show the right amount of questions and the exact score. Must say that I was not at length check in CP7, he worked at the COP6 and 6.1

    I recommend now is to add a text container, for the rest of the project, in which you can follow a few variables system quiz like cpQuizInfoPointsscored, cpInQuizScope (you must stay within the scope of the first question at the last in the addendum).

  • [Flex 3] Problem with the additional compiler arguments (cannot open)

    Hello world

    I have a problem with an additional compiler argument:

    Error Msg: can't open 'WEB-INF/flex/service-config.xml'

    This is the error I have to manage.

    I read that it is has to do with the argument of the compiler:

    -Compiler arguments additional properties - Flex compiler:

    -local = en_US, fr_FR, nl_NL-source-path = local / {local} -services "WEB-INF/flex/service-config.xml"

    But what's not here?

    Best regards.

    PS: I tried with a lot of path to the file.

    Hi PLbe,

    Using weborb in your project or any type of remote access in your project.

    Try to give the complete path for argument of services instead of the relative path.

    Thus to specify---> - services "c:\inetpub\wwwroot\weborb30\web-inf\flex\services-config.xml".

    instead of -services "WEB-INF/flex/service-config.xml"

    If you pasted the WEB - INF folder in your Flex application project file in src so no need to specify the full path. But if you have not included the WEB - INF folder (including configuration files) in the folder of your project, then you must include the full path.

    "c:\inetpub\wwwroot\weborb30\web-inf\flex\services-config.xml" is the default path where this file...

    Thank you

    Jean Claude Chari.S

  • I need help with RoboHelp 10 conditional compilation tag option

    I need assistance with the option of conditional compilation tag. I want to apply CBT to the contents of a field. I looked at the help topics and believes that I applied the function correctly. However, it does not work as you wish. In the 2nd sentence below, I want the text highlighted in blue to appear only to the printed output and printed in purple text to appear only to the .htm / output online. Help, please.

    There are common tasks for managing files and folders in the browser

    in the grid of BBS files viewer. For more information on these common tasks see help

    and support in the successful business. click on the links below.

    Hello

    With the help of marking is a two part process.

    First part

    You create and apply tags for the information you want to order.

    Second part

    You create a create an Expression that is used when you generate your output. The Expression of build usually reads something like: NO Tag1 (or whatever the name of your tag)

    Then when generate you and use the Expression to build, the information containing the tag is not included in the build.

    See you soon... Rick

  • Homepage opens with two additional tabs with quicklinks undesirable.

    Opening of my homepage now also open 2 two additional tabs with tile links to Facebook, Twitter and other undesirable websites. Maybe it's Yahoo, which I don't use. I might add the screenshot of these tabs, but need help to do it. It's a painting, *.png file. Homepage has no "pipes" | in the address.

    You can check the setting of the homepage:

    • Tools > Options > general > startup: Homepage

    Firefox supports several home pages separated by ' |' symbol (pipe).

    You can check the suspicious extensions or recently installed unknowns.

    Your list of details of the system shows that you have a user.js file in the profile folder to initialize prefs each time you start Firefox.

    The user.js file is present than if you or another software has created this file and normally it wouldn't be here.
    You can check its contents with a text editor (right click: open with) If you do not create this file yourself.

    The user.js file is read whenever Firefox is started and initializes the preferences to the specified value in this file, so the preferences set via user.js can be changed temporarily for the current session.

    You can remove possible user.js and numbered prefs-# .js files and rename (or delete) the file prefs.js to reset all the prefs by default, including the prefs set via user.js and pref which is no longer supported in the current version of Firefox.

  • problem with the addition of delivery address

    I can't add shipping address to the Japan order a photo book. He said "the information in the following areas is missing or incomplete: State value 'Chiba' was not found in the list of valid values.» I get a value any is not valid. Help, please

    Using Photos to iPhoto or Mac application?

    It is no longer possible at all to order products printed Apple using iPhoto.  Apple has stopped the service of printed products for iPhoto at the end of March.

    To get a printed iPhoto book, print it as a PDF and send the PDF file to a printing service, for example Presto Photos.

    See the link below on how to save the PDF file for printing with PrestoPhoto post by PrestoMeghan:

    Re: Re: how to export a book done in opening a similar book in pictures?

    In this discussion are also reported by kgem and Astro7x on the first experiences with this service.

    You can only order from Apple books, if you create them in Photos for Mac. And then the delivery address must be in the same country as the billing address for your AppleID.

  • communicate with the addition of additional groups

    Looking to add additional group in my contacts as a new group of my associates in a group with a different name, I all ready have several contacts in different folders, but when I ask to import the new group, contact ask to choose between before or the new group do not add the new group did something mist?

    can I add a new group without deleting the existing contact?

    canna you have the idea, thanks for your help.

    Not sure I understand.

    You can add contacts to several groups. Just drag from one group to another and it will be both.

    If you get a card of Group of someone else and try to import it, it will not import it as a group, it is important contacts only.

    A Group vCard is not a 'group' for what is Contacts is. It's just a list of contacts.

    After you import, it will be in a smart group called last import. You can create a new group and drag the contacts since the last import to the new group.

Maybe you are looking for

  • ITunes not burning to disc

    Since I upgraded to El Capitan, I had problems burning to CD. On my mac, why itunes says that there is not enough space on a cd that contain 700 MB and the talks are only 315 MB. They appear in iTunes as MPEG, but have been downloaded as MP3 audio fi

  • Satellite - white screen, dvd search, no post or bios

    Following my previous post about the bios checksum and of possible battery issue errors, I tried to turn on the laptop today. Sighted on the satellite A210 - 1 4 lights with battery or a mounted a/c adapter, power lights on too. However, the on-scree

  • activate windows vista

    How can I get a product key for a computer that had a new hard drive. I have the disc for windows vista, but no product key. Even though I bought my new computer and it came with the drive.

  • Using Smartphones blackBerry 8300

    It's what my screen has a small balck with number 1 to the left of this one.  I have no messages in any folder or saved e-mails or recorded telephone messages too weak to describe what it is, how can I get rid of it

  • Critical process WMC has failed while trying to use Extender

    Hello I use Xbox 360 as an extender like extender WMC.  This worked very well for the last two months, but now I get this error: Enforcement failed A critical Windows Media Center process has failed. Restart the computer and try again. If the problem