By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,321 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,321 IT Pros & Developers. It's quick & easy.

Need help with RATIO and ROUND

P: n/a
I have a table that I need to extract values, determine their ratio,
and then round to the nearest 50.

SELECT NAME, MFG, ROUND((WEIGHT/VOLUME),50) AS WV_RATIO, COUNT(*) OVER
(ORDER BY NAME, MFG, WV_RATIO) AS NUMBER_OF_MATCHES FROM MEMBERS;
1) To calculate the ratio, can I just use the "/" symbol in my select
statement?

2) I want to ROUND this ratio to the nearest 50. Ie. 0, 50, 100,
150, 200... How can this be accomplished?

Thanks!!

Marc
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

Try this:

SELECT NAME, MFG
, TRUNC(WEIGHT/VOLUME,-2)
+ DECODE(SIGN(TRUNC(MOD(WEIGHT/VOLUME,100))-50) ,1,100,50) AS WV_RATIO
, COUNT(*) OVER (ORDER BY NAME, MFG, WV_RATIO) AS NUMBER_OF_MATCHES
FROM MEMBERS;

--
Posted via http://dbforums.com
Jul 19 '05 #2

P: n/a
> ROUND((WEIGHT/VOLUME),50) AS WV_RATIO

maybe:
(ROUND( (weight / volume) / 50 ) * 50) AS wv_ratio

Hilarion
Jul 19 '05 #3

P: n/a

Hilarion's formula wont work correctly:

SQL>select rownum, rownum*31.416, (ROUND( (rownum*31.416) / 50 ) * 50)
SQL>AS wv_ratio
2* from user_objects
SQL>/

ROWNUM ROWNUM*31.416 WV_RATIO
---------- ------------- ----------
1 31.416 50
2 62.832 50
3 94.248 100
4 125.664 150
5 157.08 150
6 188.496 200
7 219.912 200
8 251.328 250
9 282.744 300
10 314.16 300
11 345.576 350
12 376.992 400
13 408.408 400
14 439.824 450
15 471.24 450
16 502.656 500
17 534.072 550
18 565.488 550
19 596.904 600
20 628.32 650

20 rows selected.

SQL>SELECT rownum, rownum*31.416
2 , TRUNC(rownum*31.416,-2)
3 + ECODE(SIGN(TRUNC( MOD(rownum*31.416,100))-50) ,1,100,50)
AS WV_RATIO
4 FROM user_objects
5 /

ROWNUM ROWNUM*31.416 WV_RATIO
---------- ------------- ----------
1 31.416 50
2 62.832 100
3 94.248 100
4 125.664 150
5 157.08 200
6 188.496 200
7 219.912 250
8 251.328 300
9 282.744 300
10 314.16 350
11 345.576 350
12 376.992 400
13 408.408 450
14 439.824 450
15 471.24 500
16 502.656 550
17 534.072 550
18 565.488 600
19 596.904 600
20 628.32 650

20 rows selected.

SQL>

--
Posted via http://dbforums.com
Jul 19 '05 #4

P: n/a
ROUND((WEIGHT/VOLUME),50) AS WV_RATIO

maybe:
(ROUND( (weight / volume) / 50 ) * 50) AS wv_ratio

Hilarion
Jun 27 '08 #5

P: n/a

Hilarion's formula wont work correctly:

SQL>select rownum, rownum*31.416, (ROUND( (rownum*31.416) / 50 ) * 50)
SQL>AS wv_ratio
2* from user_objects
SQL>/

ROWNUM ROWNUM*31.416 WV_RATIO
---------- ------------- ----------
1 31.416 50
2 62.832 50
3 94.248 100
4 125.664 150
5 157.08 150
6 188.496 200
7 219.912 200
8 251.328 250
9 282.744 300
10 314.16 300
11 345.576 350
12 376.992 400
13 408.408 400
14 439.824 450
15 471.24 450
16 502.656 500
17 534.072 550
18 565.488 550
19 596.904 600
20 628.32 650

20 rows selected.

SQL>SELECT rownum, rownum*31.416
2 , TRUNC(rownum*31.416,-2)
3 + ECODE(SIGN(TRUNC( MOD(rownum*31.416,100))-50) ,1,100,50)
AS WV_RATIO
4 FROM user_objects
5 /

ROWNUM ROWNUM*31.416 WV_RATIO
---------- ------------- ----------
1 31.416 50
2 62.832 100
3 94.248 100
4 125.664 150
5 157.08 200
6 188.496 200
7 219.912 250
8 251.328 300
9 282.744 300
10 314.16 350
11 345.576 350
12 376.992 400
13 408.408 450
14 439.824 450
15 471.24 500
16 502.656 550
17 534.072 550
18 565.488 600
19 596.904 600
20 628.32 650

20 rows selected.

SQL>

--
Posted via http://dbforums.com
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.