Ask Your Question
0

division calculation in base

asked 2017-01-28 22:09:21 +0200

DougKMiles gravatar image

I have a query in Base that produces two columns of numbers. I'd like to create a third column that produces the results of dividing one column by the other column.

Seems like it should be easy, but I've not been able to come up with the solution.

Any thoughts or help would be most greatly appreciated.

Thanks, dm

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-01-28 22:49:25 +0200

Ratslinger gravatar image

updated 2017-01-28 23:00:29 +0200

SELECT ID, N1, N2, (N1/N2) AS RESULT FROM "Table1"

where N1 & N2 are the number columns. Also you may want to consider checking for zeroes as that may cause errors:

SELECT ID, N1, N2, (N1/N2) AS RESULT FROM TESTTABLE where (N1 <> 0) AND (N2 <> 0)

Also:

 SELECT ID, NUMBERFIRST, NUMBERSECOND, (NUMBERFIRST/NUMBERSECOND) AS RESULT FROM (SELECT ID, N1 As NUMBERFIRST, N2 AS NUMBERSECOND FROM TESTTABLE where (N1 <> 0) AND (N2 <> 0))

should work to generate from your existing query (Select from Select).

edit flag offensive delete link more

Comments

Thank you once again for your rapid response Mr. R!

Newbie questions -- what would be ID and what would be TESTTABLE? Are these the name of the Query?

DougKMiles gravatar imageDougKMiles ( 2017-01-28 23:49:48 +0200 )edit

I got it! Thanks again!!

DougKMiles gravatar imageDougKMiles ( 2017-01-29 00:11:51 +0200 )edit

Don't need to test N1. Only need to test N2 to avoid division by zero. This should work I think: SELECT ID, N1, N2, (N1/N2) AS RESULT FROM [testtable] WHERE (N2 <> 0)

EasyTrieve gravatar imageEasyTrieve ( 2017-01-29 02:40:44 +0200 )edit

@EasyTrieve you are absolutely correct. However it is a wasted calculation and generation of a record.

Ratslinger gravatar imageRatslinger ( 2017-01-29 03:03:24 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-01-28 22:09:21 +0200

Seen: 124 times

Last updated: Jan 28 '17