0
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

Why is this query wrong?

I'm getting syntax error right now, and VB doesn't highlight specific the part that's wrong when the error is thrown.

4

2 回答 2

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;
于 2013-10-22T13:12:43.640 回答
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
于 2013-10-22T13:25:15.067 回答