We will be migrating from Ask to Discourse on the first week of August, read the details here

division calculation in base [closed]

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 reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp close date 2020-08-07 03:22:46.825296

Sort by » oldest newest most voted

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).

more

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?

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

I got it! Thanks again!!

( 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)

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

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

( 2017-01-29 03:03:24 +0200 )edit

Stats

Seen: 188 times

Last updated: Jan 28 '17