简体   繁体   中英

SyntaxError when adding and subtracting with BigQuery

When executing this basic query I have this error:

 WITH CALCULO AS (
   (SELECT SUM(UTILITY) FROM _coste_rv) - (SUM(UTILITY) + (SELECT SUM(UTILITY) FROM _tmp_coste))) 

Message of Error:

Syntax error: Expected ")" but got "-"

What I want it to show is the amount of those 2 values

The top-level statement should be SELECT. Ie you cannot write

WITH Calculo AS (
   foo - bar
)

it should be

WITH Calculo AS (
   SELECT foo - bar as some_name
)

ie

WITH CALCULO AS (
  SELECT 
    (SELECT SUM(UTILITY) FROM _coste_rv) - 
    (SUM(UTILITY) + (SELECT SUM(UTILITY) FROM _tmp_coste))
        AS some_name
) 
SELECT ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM