Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: dividing to group with the same weight

Re: dividing to group with the same weight

From: <liorlew_at_gmail.com>
Date: 9 Feb 2006 01:36:49 -0800
Message-ID: <1139477809.896487.98670@g14g2000cwa.googlegroups.com>


I did the following:
select name, salary, dept , mod(row_number() over(order by salary ),3) group_no from info_table
order by salary desc;

the answer I got is not exactly what I need, because I do not need the salaries (weight) to be put each time in the following group. I need them in the group with the lowest weight.

I need that if I have the following
20,20,13,5,5,4,4,4,3,2,1,1,1,1,1,1,1
the answer for 3 group will be
20, 20,13

            5
            5

4, 4, 4
3, 2,

      1, 1
1 1, 1
1



29 , 28, 29 <-- total
The query I wrote would return the following instead: 20 ,20 ,13
5    ,5    ,4
4    ,4    ,3
2    ,1    ,1
1    ,1    ,1

1

33, 31, 22 <-- wrong total

of course the is always the possibility of opening a cursor and writing a C++ or pl/sql program, but I will be more satisfy if I could get oracle 10g to do it.

I am sorry if you got the impression that I want you do do my work for me. trust me I am working on it too and will supply an answer if I found one. Received on Thu Feb 09 2006 - 03:36:49 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US