Am writing the query below using laravel to find the average unit price of a part number in the table called StockDetails:
$part = $request->part;
$qty = $request->qty;
$ceter = request()->user()->costcenter;
$stkNumb = DB::select("
SELECT a.*
FROM StockDetails AS a
JOIN
(
SELECT x.*, SUM(y.quantity) AS qtt
FROM StockDetails AS x
JOIN StockDetails AS y ON y.partNumb = x.partNumb
AND y.id <= x.id
AND y.costCenter = x.costCenter
WHERE x.partNumb = :part AND x.costCenter = :center
GROUP BY x.id
HAVING :qty > SUM(y.quantity) - x.quantity AND :qty1 <= SUM(y.quantity)
) AS b
ON b.partNumb = a.partNumb
AND b.id >= a.id AND a.costCenter = :center2",
['qty' => "$qty", 'qty1' => "$qty", 'part' => "$part", 'center2' => "$ceter", 'center' => "$ceter"]);
It is throwing an error SQLSTATE[42000]: Syntax error or access violation: 1055 'fleetvue.x.stockNumber' isn't in GROUP BY (SQL:
i have tried to change the 'strict' => false,
but am sill getting the error.
Any solution to this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire