select v.nroventa, sum(v.importe)
from ventas v, pagosventas p
where v.nroventa=p.nroventa
and v.codigocliente=41
and v.nroventa not in (select p.nroventa
from pagosventas p, ventas v
where p.nroventa=v.nroventa)
group by v.nroventa
为什么这个查询错了?
我现在遇到语法错误,并且VB没有突出显示错误引发时错误的部分。
答案 0 :(得分:0)
以下查询应该有效。尝试从sql server或任何sql ide运行它。
SELECT A.nroventa,A.sum_importe
FROM
(
select v.nroventa, sum(v.importe) AS sum_importe
from ventas v, pagosventas p
where v.nroventa=p.nroventa
and v.codigocliente=41
group by v.nroventa
) A,
(
SELECT v.nroventa
FROM ventas v
WHERE v.nroventa
not in
(select p.nroventa from pagosventas p, ventas v where p.nroventa=v.nroventa)
) B
WHERE A.nroventa = B.nroventa;
答案 1 :(得分:0)
我认为你还需要在select的第一个字段上使用agg函数,例如MAX(v.nroventa)
select MAX(v.nroventa), sum(v.importe)
from ventas v, pagosventas p
where v.nroventa=p.nroventa
and v.codigocliente=41
and v.nroventa not in (select p.nroventa
from pagosventas p, ventas v
where p.nroventa=v.nroventa)
group by v.nroventa