duda con un select

duda con un select

Postby goosfancito » Fri Oct 29, 2021 12:50 pm

hola
este select da la lista de TODOS los movimientos de compras de productos, pero necesito ADEMAS tener el TOTAL del stock de cada producto,
y no logro hacerlo, intente con SUM(...) pero no me lo hace.
Select
a.id AS c1,
a.idprod AS c2,
a.fecha AS c3,
a.importe AS c4,
a.stock AS c5,
a.stockminimo AS c6,
a.ganancia AS c7,
c.nombre AS c8,
d.id AS c9,
d.nombre AS c10,
e.id AS c11,
e.nombre AS c12,
f.stockcongelado AS c13,
f.punitario AS c14
FROM tbprecio a
LEFT JOIN tbprod AS b ON b.id = a.idprod
LEFT JOIN tbprodnom AS c ON b.idnombre = c.id
LEFT JOIN tbsucursal AS d ON b.idsucursal = d.id
LEFT JOIN tbdistribuidores AS e ON b.iddistribuidor = e.id
LEFT JOIN tbstockres AS f ON f.idprod = a.idprod
ORDER BY a.idprod, b.idsucursal, a.fecha


el campo a sumar es "C5"

gracias
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: duda con un select

Postby leandro » Fri Oct 29, 2021 1:35 pm

Así debería funcionar

Code: Select all  Expand view  RUN

Select
a.id AS c1,
a.idprod AS c2,
a.fecha AS c3,
a.importe AS c4,
SUM(a.stock) AS c5,
a.stockminimo AS c6,
a.ganancia AS c7,
c.nombre AS c8,
d.id AS c9,
d.nombre AS c10,
e.id AS c11,
e.nombre AS c12,
f.stockcongelado AS c13,
f.punitario AS c14
FROM tbprecio a
LEFT JOIN tbprod AS b ON b.id = a.idprod
LEFT JOIN tbprodnom AS c ON b.idnombre = c.id
LEFT JOIN tbsucursal AS d ON b.idsucursal = d.id
LEFT JOIN tbdistribuidores AS e ON b.iddistribuidor = e.id
LEFT JOIN tbstockres AS f ON f.idprod = a.idprod
ORDER BY a.idprod, b.idsucursal, a.fecha GROUP BY a.idprod
 
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1676
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft and 32 guests