0

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

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
  • 1
    That is not a valid SQL query. It is not allowed to add values from different SELECT clauses. Please, provide more information about the source data and what you are trying to achieve so that we can help – David Morales Dec 12 '22 at 22:20

1 Answers1

0

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

WITH Calculo AS (
   foo - bar
)

it should be

WITH Calculo AS (
   SELECT foo - bar as some_name
)

i.e.

WITH CALCULO AS (
  SELECT 
    (SELECT SUM(UTILITY) FROM _coste_rv) - 
    (SUM(UTILITY) + (SELECT SUM(UTILITY) FROM _tmp_coste))
        AS some_name
) 
SELECT ...
Michael Entin
  • 7,189
  • 3
  • 21
  • 26