Problem in the group by [message #282645] |
Thu, 22 November 2007 20:47 |
samit_gandhi
Messages: 226 Registered: July 2005 Location: Hong Kong
|
Senior Member |
|
|
Hi All
I have some data like this :
Weight Colour
0.46 F
0.46 D
0.46 E
0.46 F
0.46 G
0.47 F
0.49 G
0.50 F
0.56 E
0.58 F
0.59 D
I want the data in grouping like weight between 0.46-0.49,0.50-0.57. in the order of the colour
How to do it pls let me know
Thx in advance.
Samit gandhi
|
|
|
Re: Problem in the group by [message #282647 is a reply to message #282645] |
Thu, 22 November 2007 20:57 |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
How did you decide to break the range at 0.49/0.50?
Is it based on a change of the 1st digit after the decimal point?
Show us some sample output as well.
Ross Leishman
|
|
|
|
|
|
Re: Problem in the group by [message #282667 is a reply to message #282645] |
Thu, 22 November 2007 23:25 |
|
rajavu1
Messages: 1574 Registered: May 2005 Location: Bangalore , India
|
Senior Member |
|
|
Are u trying something like ..
CREATE TABLE OF_NUM
(
OF_NUMBER NUMBER(5,2)
);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.46);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.5);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.56);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.59);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.46);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.46);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.47);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.49);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.46);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.46);
Insert into OF_NUM
(OF_NUMBER)
Values
(0.58);
COMMIT;
select distinct --OF_NUMBER , trunc(OF_NUMBER,1) ,
dense_rank() over (Order by trunc(OF_NUMBER,1) ) rnk ,
mIN(OF_NUMBER) over (partition by trunc(OF_NUMBER,1) ) MN,
max(OF_NUMBER) over (partition by trunc(OF_NUMBER,1) ) MX
from OF_num
Rajuvan.
|
|
|
|
Re: Problem in the group by [message #282698 is a reply to message #282648] |
Fri, 23 November 2007 01:17 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
SQL> select * from t order by weight, colour;
WEIGHT COLOUR
---------- ------
.46 D
.46 E
.46 F
.46 F
.46 G
.47 F
.49 G
.5 F
.56 E
.58 F
.59 D
11 rows selected.
SQL> select trunc(10*weight) grp, weight, colour
2 from t
3 order by grp, colour, weight
4 /
GRP WEIGHT COLOUR
---------- ---------- ------
4 .46 D
4 .46 E
4 .46 F
4 .46 F
4 .47 F
4 .46 G
4 .49 G
5 .59 D
5 .56 E
5 .5 F
5 .58 F
11 rows selected.
Regards
Michel
|
|
|