01 June 2019 · Mike-Barn ·       Add to Favorites   Report

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 June 2019

Read great educational content like this and a lot more !

Members get free exclusive access to content, new courses, and discounts. Signup for a free account to write a post / comment / upvote posts. Creating an account takes less than 5 seconds and you can start earning badges & points too

Copied