473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need help with RATIO and ROUND

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
5 5341

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
> ROUND((WEIGHT/VOLUME),50) AS WV_RATIO

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

Hilarion
Jul 19 '05 #3

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
ROUND((WEIGHT/VOLUME),50) AS WV_RATIO

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

Hilarion
Jun 27 '08 #5

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Shi | last post by:
Hello, I'm running into a strange issue with GD. Please review the script attached bellow. I'm using it to generate thumbnail icon on a fly. I don't know why it gives different results on...
4
by: Kevin | last post by:
Is there anyway to find out an image's DPI using GD? Can I change an image which is 300 DPI down to 200 DPI? I am fully aware of that DPI doesn't matter on screen, but these are to be used for...
7
by: eric | last post by:
Hi there, BP hit ratio = 1 - (BP physical reads / BP logical reads). If all the BP physical reads are asynchronous, it should mean that the pages are brought up to the bufferpool before the...
4
by: xixi | last post by:
the formula for package cache hit ratio is 1 - (package cache inserts/package cache lookups), what the result would be a effective ratio? currently we have cache inserts=25, cache lookups=35, so...
5
by: MFC | last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key of C#, and C# Weekend Crash Course) and three weeks, I believe I have tried everything to make a certain form function...
1
by: ngreplies | last post by:
I am using a label as a tooltip box because I need to be able to change the background of the box depending on the information it is representing. That aside, I need to be able to auto-size the...
24
by: user923005 | last post by:
The purpose is for a shellsort. I am experimenting with the increment for shellsort using a modified version of Pete's driver and this bit of code (shell_ratio is a floating point number for the...
3
by: xavo2007 | last post by:
Hi there. I am required to produce the greek flag however it requires me to use ratios. Below is the excercise question which I was given. I've got the starting code:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.