I am trying to achieve a sum of all orders of a cuctomer. I have created an SQL function to calculate the amount of a given order:
DELIMITER $$
CREATE FUNCTION invoices.orderAmount(quantity INT, price INT) RETURNS INT
BEGIN
DECLARE orderTotal INT;
SET orderTotal = quantity * price;
RETURN orderTotal;
END$$
DELIMITER ;
while trying to save this function, i get this error:
now I want to get all the sums of all customer's orders with a command like:
$totalOrderQuery =" SELECT price, quantity, sum(invoices.orderAmount(price,quantity)) AS CustomersTotalBill FROM invoices
WHERE purchaseId=$purchaseId AND status='ordered' AND OrderCancel='NO'";