0
GOAL
I have two tables (tb_get_gap, tb_getCountSRVS), where in the first table count to get the desired values and in the second I have integer values, I just want to take the values of the two and subtract
QUERY
select
(cast(srvs as int) - (SELECT COUNT(*) hostname FROM tb_get_gap
LEFT JOIN tb_get_customers
ON tb_get_gap.customer = tb_get_customers.cust_cmdb WHERE tb_get_customers.customer in (select customer from tb_get_customers) and tb_get_gap.exception = 'NO'
GROUP BY tb_get_gap.customer ORDER BY tb_get_gap.customer ASC))
from tb_getCountSRVS order by cust_code asc
OUTPUT
>[Error] Script lines: 1-6 --------------------------
ERROR: more than one row returned by a subquery used as an expression
Line: 1
Wouldn’t you have to correlate your subquery with some table value tb_getCountSRVS? Your subquery is counting for each existing Customer value in tb_get_gap and returning such list.
– anonimo
I believe so, because if I put LIMIT 1 inside the subquery it returns the values, but decreases the same values of all.
– Luis Henrique
Then check which field of table tb_getCountSRVS refers the value srvs for you to correlate with your subquery (kicking, since I don’t know your tables, I would say Customer).
– anonimo
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.
– Luis Henrique
OUTPUT: >[Error] Script Lines: 1-5 -------------------------- ERROR: syntax error at or near "-" Line: 1
– Luis Henrique