0

I need to perform simple calculations in BigQuery and save the result in a new column. Below is my code:

SELECT id, 
CPM, 
(1 / 1000000000 * CPM) AS Revenue
FROM `big_query_table`

For some numbers, it does the calculations right, but for other numbers, it is not even a number that is being returned. Here is the output:

enter image description here

The last number 930000 should have returned 0.00093

Chique_Code
  • 1,422
  • 3
  • 23
  • 49

1 Answers1

2

use below instead (BigQuery Standard SQL)

SELECT id, 
CPM, 
CAST(1 / 1000000000 * CPM as numeric) AS Revenue
FROM `big_query_table`  

this will output below

enter image description here

Mikhail Berlyant
  • 165,386
  • 8
  • 154
  • 230