[英]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. 我有应减去值的两个表,但错误返回我子查询,因为应该发生减法如下(
TABLE1
。 COLUMN1
- TABLE2
。 COLUMN1
),依此类推。
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. 语法错误是由于以下事实导致的:在主
SELECT
,您给COUNT(*)
赋予了别名( hostname
COUNT(*)
,然后您尝试进行减法。
You should correct the first row of your query as follows: 您应该按如下所示更正查询的第一行:
SELECT (COUNT(*) - CAST(tb_getCountSRVS.srvs AS int)) AS hostname
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.