Reputation: 771
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
Upvotes: 0
Views: 445
Reputation: 5201
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
Upvotes: 1