简体   繁体   中英

ERROR: syntax error at or near “-” - SUBQUERY

Goal

I have two tables with values that should be subtracted, but error is returning me to subquery because subtraction should occur as follows ( TABLE1 . COLUMN1 - TABLE2 . COLUMN1 ), and so on.

Query

SELECT COUNT(*) hostname - CAST(tb_getCountSRVS.srvs AS int)
FROM tb_get_gap
LEFT JOIN tb_getCountSRVS
  ON tb_get_gap.customer = tb_getCountSRVS.cust_code
WHERE tb_getCountSRVS.customer in (
  SELECT customer
  FROM tb_getCountSRVS
) AND tb_get_gap.exception = 'NO'
GROUP BY tb_get_gap.customer
ORDER BY tb_get_gap.customer ASC

Output

> [Error] Script lines: 1-5 --------------------------
 ERROR: syntax error at or near "-"
 Line: 1 

The syntax error is due to the fact that, in your main SELECT , you are giving an alias ( hostname ) to COUNT(*) , then you're trying to do a subtraction.
You should correct the first row of your query as follows:

SELECT (COUNT(*) - CAST(tb_getCountSRVS.srvs AS int)) AS hostname

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