Tie on the row

Hello

Below is the structure of the table:
_STUD_
STUD_ID
MATH
MATH_RANK
SCIENCE
SCIENCE_RANK
ENGLISH
FIN_RANK
Here's something I'm trying to accomplish:
The MATH_RANK and SCIENCE_RANK columns contains the dense rank on MATH and SCIENCE, respectively. And FIN_RANK would be calculated as (0.5 * MATH_RANK) + (0.5 * SCIENCE_RANK).

Now, if there is a link between a set of students, I need to use ENGLISH in the tie.


This is something that I came with:
(1) add an additional column (INCR) on the table STUD
(2) calculate FIN_RANK initially as (0.5 * MATH_RANK) + (0.5 * SCIENCE_RANK).
(3) move through the records that are linked with others and fill levels
(4) add INCR to FIN_RANK.

Example code:
BEGIN
   FOR cur1 IN (SELECT   *
                    FROM stud s1
                   WHERE EXISTS (
                            SELECT 1
                              FROM stud s2
                             WHERE s1.fin_rank = s2.fin_rank
                               AND s1.stud_id <> s2.stud_id)
                ORDER BY s1.fin_rank, s1.english DESC)
   LOOP
      IF vprevrank IS NULL
      THEN
         vprevrank := 0;
      END IF;

      SELECT (incr - 1)
        INTO vincr
        FROM (SELECT DENSE_RANK () OVER (ORDER BY DECODE (b.english,
                                                          NULL, 0,
                                                          b.english
                                                         ) DESC) incr,
                     b.stud_id userid
                FROM stud b
               WHERE cur1.fin_rank = b.fin_rank)
       WHERE userid = cur1.stud_id;

      UPDATE stud a
         SET incr = incr + vincr
       WHERE a.stud_id = cur1.stud_id;

      IF vincr > 0 AND vincr > vprevrank
      THEN
         UPDATE stud
            SET incr = incr + 1
          WHERE fin_rank > cur1.fin_rank;
      END IF;

      vprevrank := vincr;
   END LOOP;

   UPDATE stud
      SET fin_rank = fin_rank + incr;
END;
Could you think of an alternative (perhaps with the collection or something)?

Thank you
CJM

Hello

It seems strange to me to calculate the fin_rank of math_rank and science_rank instead of mathematics and science.

Having no data to play with I tried this:

SQL> with s as (
  2  select 1 stud_id, 15 math, 10 science, 12 english from dual
  3  union all select 2, 10, 15, 18 from dual
  4  union all select 3, 17, 18, 13 from dual
  5  union all select 4, 12, 11, 17 from dual
  6  union all select 5, 18, 17, 14 from dual
  7  union all select 6, 14, 10, 14 from dual
  8  union all select 7, 11, 13, 11 from dual
  9  union all select 8, 13, 13, 12 from dual
 10  union all select 9, 10, 14, 14 from dual
 11  union all select 10, 19, 12, 15 from dual
 12  )
 13  select
 14  stud_id,
 15  math,
 16  dense_rank() over (order by math desc) math_rank,
 17  science,
 18  dense_rank() over (order by science desc) science_rank,
 19  dense_rank() over (order by math+science desc, english desc nulls last) fin_rank
 20  from s ;

   STUD_ID       MATH  MATH_RANK    SCIENCE SCIENCE_RANK   FIN_RANK
---------- ---------- ---------- ---------- ------------ ----------
        10         19          1         12            6          3
         5         18          2         17            2          1
         3         17          3         18            1          2
         1         15          4         10            8          6
         6         14          5         10            8          7
         8         13          6         13            5          4
         4         12          7         11            7          9
         7         11          8         13            5          8
         9         10          9         14            4          7
         2         10          9         15            3          5

10 rows selected.

Student5 is finally classified #1 before student3 because he's better in English.

Published by: Nicosa 27 July 2010 16:09
--> has added nulls last to properly manage students with no English. (assumed, he is not a student with null for the science or math)

Tags: Database

Similar Questions

  • entered in the row area or webb research is all backwards, i.e. from right to left

    1. by clicking on tools causes all tabs in the row to come and go across the screen.
    2 entry online research or the web to be backward, address line that is from right to left.
    apparently caused by some malware or Trojan virus. Can't seem to remove it.
    He came on my other computer because I do not see back.
    John

    You may have hit the SHIFT key by accident while cutting text via Ctrl + X.
    You can reverse the direction of the bidi from right to left text left to right with 'Shift + Ctrl + X.

    Start Firefox in Safe Mode to check if one of the extensions (Firefox/tools > Modules > Extensions) or if hardware acceleration is the cause of the problem.

    • Put yourself in the DEFAULT theme: Firefox/tools > Modules > appearance
    • Do NOT click on the reset button on the startup window Mode safe
  • How to change the rows and columns of newtabs?

    I can't change the rows and columns to mozilla version 33

    From topic: config browser.newtabpage.columns shows 5 by default, but these 5 columns appear not only 3 as before. Don't know why, but I use generally not even the default new tab page in my profile daily.

    Still works this - https://addons.mozilla.org/en-US/firefox/addon/new-tab-tools/ - extension to change the page of newTab via a user accessible interface name in the Addons, rather than routing autour Manager inside Firefox. I use this add-on in a second profile that I use for my favorite sites

  • How to sort the rows according to the contents in cells

    Hello

    Is it possible to use a formula to sort the rows according to their cell contents? I will include a screenshot of my table. What I want to do is group together people based on where they live. I wish that all rows with an 'x' in a certain State of group. Who is? Thank you!

    Nevemind, I thought about it.

  • How to access the data in the row (text of children) in a pragmatic control tree?

    In LabVIEW 2010, I entered the data in row a tree with pragmatism control using the Add item and providing the child text table and the child tag for the line. When a row in the tree control is selected, I can get the line label in the Value property of the tree. But how do I access the data in the child text table when the line is selected? I can't seem to find a tree control property or method which will return data back.

    What I'm trying to do is: once a line in a tree is selected and a button is pressed, if the line tag is valid, I want to transfer all the data in row in another tree the same formatting. For this I need the data for the tree line and the line that was selected. I don't find a way to get access to these data of the line when it was composed in the tree.

    Can someone tell me how to access pragmatically the child text or row data in a tree control from a selected line in the tree? I have the label of the line, but how do I access data?

    Thank you for your help.

    Looking through numerous examples, I found how to do this using the properties ActiveItemRow and ActiveColNum, but I can't find these documented properties anywhere using LabVIEW. Even research through aid could not do anything about them.

    Where these important parameters are documented?

    Why they do not appear in the help?

    Are there other ways to access the data in the row (child text) form a selected line in a tree control?

  • ListField Get focused on the row Index

    Hello

    I implemented a custom ListField.

    I'm looking for a way that I can get the index of the target line.

    For example, if my ListField contains 10 line and line 2 number concentrates (marked in blue), I want to receive the row index.

    Thank you!

    I'm sorry, I'm mixed messages here.  In your last post, you said this:

    "... and then try to scroll down once more, the last item is projected to"separate ":

    Maybe I'm just stupid, but I have no idea what it means.  And it sounded like it's your problem.

    Nevertheless, my logic goes like this.  There should be no problem to find a ListField index.  So if you have problems, then the question is in your code.  You tried to explain it and I'm sorry, I don't get it.  So instead of you trying to explain it, I suggest that you give us a piece of code that we can test, which illustrates the problem.  Who will save trying to explain it and means that if we find a solution we can actually give you the code to fix it.  To me, that seems the best way to solve this problem for all parties involved.

    If you create a sample screen with a single ListField on it and allows you to demonstrate your problem?  Then validate the code here so that we can try ourselves?

  • How to change the row height in tableLayoutManager?

    HIII all,.

    I used TableLayoutManager in my application but don't know how to increase the row height.

    I use this reference for the TableLayoutManager link.

    How - to create a presentation of the rich UI at TableLayoutManager
    Article number: DB-00783

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

    and I want to make the size of the entire line 68 px...

    any body can help me how to change the RowHeight in tableFieldManager?

    @peter

    Thank you Peter for your answer.

    I solved the problem as you indicate in the Tablelayoutmanager.java change before 5 months.

    I asked you our post reply you as soon as possible...

    I don't care

    Thank you.

    regaurds,

    Albert_anks

  • Can I edit in JDE when the Simulator is open? How to stop the debugger there tie in the Simulator?

    I see the output in the Simulator and I want to have changes in the code. To do this, I have to close the Simulator and the fact of the change in JDE. Y at - it an option for edit in JDE when Simulator works and we see the output changed in the open Simulator?

    And also how to stop the debugger's tie when the Simulator is on the way? It takes too long to launch the simulator when the debugger is attached.

    Thanks for any help.

    Simulator for stand-alone use.

    Build the project in jde and transfer all the cod files in stand-alone Simulator folder.

    And after that start the standalone trainer.

  • How to get broke the index of the row in the listview?

    Hi all

    I use the function of the snap of the listview to stop the scrolling on the single point. Is there a way to get the row of the line broke without drawing on the line?

    Just found a solution. With the help of the listscrollstatehandler and make use of the firstVisibleItem to get the row of the visible line of the listview, and everything will work.

  • If the OEM license is tied to the BIOS, the BIOS can be updated without problems?

    I think to update my Vista 64 bit on windows 7 laptop.  I was reading the Ant on the differences between OEM and full, and in a post, it said that the OEM license is tied to the BIOS serial #.  Is it a serial number of the equipment of a firmware #.  What would happen if you fast a new BIOS revision?

    Thank you

    a preinstalled OEM SLP key should interact with the slic table in bios in order to activate itself. You can update the bios without negative consequences as long as you get the bios that is appropriate for your machine.

    An OEM system builder license does not use the slic table.

    Computers, which are built by large manufacturers provided with pre-installed Windows are supplied with 2 two product keys:

    (A) OEM SLP: this key comes pre-installed in Windows, when it comes to the factory. This key is designed to work with the special instructions isn't on the hardware of this manufacturer. Then, when Windows was installed using the OEM SLP (in factory) Windows 7 key leans on the motherboard and he sees special instructions and activates. (that's why you had no need to turn on your computer after you brought it home)

    (B) SLP COA: it's the product key that you see on the sticker on the side (or at the bottom, [or in the battery compartment]) of your computer. It is a valid product key, but must be used only in certain situations (for example, if the OEM SLP key stops automatic activation for a reason any). The key must be activated by phone. (Note: all manufacturers that use the SLP OEM system are bound by contract to include a certificate of Authenticity sticker (COA), which has a COA SLP key, on the computer)

  • Another user changed the row with a primary key oracle.jbo.Key]

    I see many discussions about this error, but still cannot understand the difficulty that I need in my scenario.

    I am an Oracle Developer and completely new to ADF, please bear with me.

    I use JDeveloper 11.1.1.9.0

    My scenario:

    Creates an object editable view (UVO) with sub selects in the query, which is from several db tables.

    Creating a table using the UVO

    When I try to update a field in the table, and then click the validate, I get the error message:

    Another user changed the row with a primary key oracle.jbo.Key]

    Can someone explain in what scenarios I see this error and how do I solve this problem?

    Try the viewObject execution after validation and reQueryOnCommit set to true

    For details see - binary: a reason more for "Houston-25014: another user has modified the line containing oracle.jbo.Key primary key '

    Ashish

  • Effect of Zebra in the rows of interactive report

    Hello, I have a question about the interactive report. Is it possible to put lines in the display of the report with zebra effect. I know that highlight line will bring closer the colors in the rows. But I need color alternating lines with no strings attached. Help, please!

    Thanks in advance.

    Emilie S

    Sinduja Sivasailam wrote:

    I am attaching the CSS file for the cat. I'm not sure where to add in the CSS file. Can you help me with this.

    And I'm not quite sure what you're talking about now. What joint? Where?

    Add these rules at the end of the custom style sheet/c/cummins/cummins_oracle_apex.css

    /*
      Zebra stripe effect on interactive report rows.
    */
    #apexir_DATA_PANEL>table .apexir_WORKSHEET_DATA tbody tr:nth-child(even) td {
      background: #ffffff;
    }
    #apexir_DATA_PANEL>table .apexir_WORKSHEET_DATA tbody tr:nth-child(odd)  td {
      background: #f8f8f8;
    }
    
  • problem of adjustment of height of the rows in the tables in CS6

    I read all the debates devoted to setting the height of the rows in the tables and I can't find the answer to my problem.

    I placed a table that was created in Word.  I've done several times, but now I can not adjust the heights of less than 5mm line without losing the text in the line.  I went up to line on "exactly".  As soon as I try to reduce the height of the text disappears, but there is plenty of space above and below the text.   Hoping someone can help.

    Check the cell INSET on the cell options.

  • ADF: Double in taskflow Page Navigation click on the row in the table on the page .jsff

    Hi all

    My 11.1.1.7 Jdev.

    I have a taskflow with two fragments (.jsff) pages. On the first page, I have a table when I double click on the row in the table that I want to go to the next page.

    I tried to call java script but I do not understand. How can I get it?

    handleNavigation is the only thing that you should not use in the adf. Read 'How to navigate in the stubborn workflow' in this http://www.oracle.com/technetwork/developer-tools/adf/learnmore/nov2010-otn-harvest-190744.pdf.

    Timo

  • cannot access the rows of a table not nested element

    What Miss me? I'm under Oracle 12 c (12.1.0.1.0)

    CREATE TYPE dim_O AS OBJECT )

    dimension_id number

    label_en varchar2()300( )

    );

    CREATE TYPE dim_T AS TABLE OF dim_O;

    DECLARE

    dims_t dim_T

    START

    SELECT CAST(MULTISET( )) 

    SELECT  DIMENSION_ID LABEL_EN

    DE    DIMENSIONTABLE -actual physical table in oracle

       DIMENSION_ID IN (3001 3002 3003()

    ) AS dim_T) "dim_rec"

    BY dims_t

    DE    DOUBLE;

    FOR I IN dims_t. FIRST... dims_t. LAST LOOP

    DBMS_OUTPUT. Put_line() dims_t() I). dimension_id);

    END LOOP;

    -exit from the loop above is

    -3001

    -3002

    -3003

    -The following statement fails: cannot access the rows of a table not nested element

    UPDATE TABLE ( SELECT dimension_id FROM TABLE (dims_t) ( )

    Dimension_id SET = WHERE = dimension_id 3004 3003

    -The following statement fails: cannot access the rows of a table not nested element

    UPDATE TABLE ( SELECT dimension_id FROM TABLE (CAST (dims_t in dim_T () ) ( )

    Dimension_id SET = WHERE = dimension_id 3004 3003


    END;

    I'm trying to understand this example very simple, but to no avail.

    Can someone tell me why I get this error?

    Thank you all in advance for your time.

    Marc

    What Miss me? I'm under Oracle 12 c (12.1.0.1.0)

    CREATE TYPE dim_O () AS OBJECT

    number of dimension_id

    label_en varchar2 (300)

    );

    CREATE TYPE dim_T AS TABLE OF dim_O;

    DECLARE

    dims_t dim_T;

    BEGIN

    SELECT CAST (TYPE MULTISET)

    SELECT DIMENSION_ID, LABEL_EN

    OF DIMENSIONTABLE -actual physical table in oracle

    WHERE DIMENSION_ID IN (3001,3002,3003)

    () AS dim_T) 'dim_rec '.

    IN dims_t

    FROM DUAL;

    I'm IN dims_t.FIRST... dims_t.Last LOOP

    DBMS_OUTPUT. Put_line(dims_t (i) .dimension_id);

    END LOOP;

    -exit from the loop above is

    -3001

    -3002

    -3003

    -The following statement fails: cannot access the rows of a table not nested element

    UPDATE TABLE (SELECT dimension_id FROM TABLE (dims_t))

    SET dimension_id = dimension_id = 3003 3004 WHERE;

    -The following statement fails: cannot access the rows of a table not nested element

    UPDATE TABLE (SELECT dimension_id FROM TABLE (CAST (dims_t as dim_T)))

    SET dimension_id = dimension_id = 3003 3004 WHERE;

    END;

    I'm trying to understand this example very simple, but to no avail.

    Can someone tell me why I get this error?

    You get it because dims_t is an array of OBJECTS - not a table of scalars. But your SELECT statement returns scalar.

    There IS NO such object, named "dimension_id"; It is an ATTRIBUTE of the object DIM_O. DIMENSION_ID is a SCALAR which, as says the exception, is a "No nested table element; If you cannot select/Update lines of it.

    What you do is equivalent to the following:

    DECLARE

    dims_t dim_T;

    number of dim_id;

    dim_o design;

    BEGIN

    Design: = dim_o (3, 'ghi');

    SELECT DIM_O (DIM_ID, LABEL) BULK COLLECT INTO table DIMS_T (d_o);

    end;

    /

    ORA-06550: line 7, column 59:

    PL/SQL: ORA-22905: cannot access the rows of a table not nested element

    ORA-06550: line 7, column 1:

    PL/SQL: SQL statement ignored

    This SELECTION is trying to design it as a table when it's a SCALAR - so the same exception you get.

Maybe you are looking for