我很难用存储过程中的select语句生成s.no.任何人都可以请告诉我如何增加每行的变量值
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_select_invoice_pdf`(IN `cus_ivc_id` INT(11))
NO SQL
BEGIN
DECLARE a INT(11);
set a=0;
SELECT
a:=a+1 as 'S.No',
ci.`order_id` as 'Order ID',
cp.`date` as 'Date',
cp.`product_name` as 'Design name',
(`customer_invoice`.`amount`-`customer_invoice`.`discount`) as 'Amount'
from `customer_invoice` ci
LEFT JOIN `customer_product` cp on cp.`customer_product_id` =
ci.`customer_product_id`
END$$
DELIMITER ;
错误:MySQL说:#1064 - 你的SQL语法有错误;校验 与您的MariaDB服务器版本对应的手册 正确的语法使用':= a + 1作为' S.No',ci。
order_id
as' Order ID',cp'在第5行
然而,下面对我来说工作正常,但无法弄清楚如何在存储过程中执行此操作。我们将非常感谢您的帮助。
set @a:=0;
SELECT
@a:=@a+1 as 'S.No',
ci.`order_id` as 'Order ID',
cp.`date` as 'Date',
cp.`product_name` as 'Design name',
(`customer_invoice`.`amount`-`customer_invoice`.`discount`) as 'Amount'
from `customer_invoice` ci
LEFT JOIN `customer_product` cp on cp.`customer_product_id` =
ci.`customer_product_id`;