01 Jun 19 · Mike-Barn ·       Add to Favorites  

BigQuery: Subselect not allowed in SELECT clause

I used the following query in Google BigQuery:

SELECT count_in_bin/(SELECT SUM(count_in_bin) FROM [table])
FROM [table]

Then I get

error:Query Failed Error: Subselect not allowed in SELECT clause

Solution:

BigQuery Standard SQL

#standardSQL
SELECT 
  count_in_bin, 
  count_in_bin / total AS ratio
FROM `project.dataset.table`, 
(SELECT SUM(count_in_bin) total FROM `project.dataset.table`)

Mike-Barn

posted on 01 Jun 19

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds

Copied