这是我的查询:如何把所有行的总和每一行
SELECT clientes.nombre as [NombreCliente],
venta.usuario as [NombreVendedor],
SUM((listaventa.precio)) as [FinalTotal],
venta.id as [IdVenta],
venta.fecha as [Fecha],
idproducto as [clave],
producto.descripcion ,
listaventa.precio as [preciounitario],
listaventa.cantidad,
listaventa.total as [PrecioTtoal]
FROM venta
JOIN clientes on venta.idcliente = clientes.id
JOIN listaventa on listaventa.idventa=venta.id
JOIN producto on listaventa .idproducto =producto.id
WHERE venta.id ='36'
GROUP BY clientes.nombre, venta.usuario, venta.id, venta.fecha, listaventa.idproducto, producto.descripcion, listaventa.precio, listaventa.cantidad, listaventa.total
问题是,我不明白的是总和,因为查询是ID确认ID,它永远不会返回总和(listaventa.precio)它返回的结果与每个产品的cantidad * preciou相同,但它不会总和它。否则,如果我尝试它
SELECT clientes.nombre as [NombreCliente],
venta.usuario as [NombreVendedor],
SUM((listaventa.precio)) as [FinalTotal],
venta.id as [IdVenta],
venta.fecha as [Fecha],
idproducto as [clave],
producto.descripcion ,
listaventa.precio as [preciounitario],
listaventa.cantidad,
listaventa.total as [PrecioTtoal]
FROM venta
JOIN clientes on venta.idcliente = clientes.id
JOIN listaventa on listaventa.idventa=venta.id
JOIN producto on listaventa .idproducto =producto.id
WHERE venta.id ='36'
AND venta.id IN (SELECT *
FROM listaventa
WHERE idventa = 36)
我得到这个错误:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
你可能想澄清你是什么后,因为查询因为书面没有意义。 – JNK
这没有意义。没有理由任何人想知道SUM(lista.precio)。 El de de los preciounitarios没有意义。 – hoodaticus
可能的重复[只有一个表达式可以在选择列表中指定,当子查询没有与EXISTS引入。](http://stackoverflow.com/questions/1904314/only-one-expression-can-be-specified- (SELECT *'也许你的意思是'IN(SELECT id'?) –