mysql程序中的用户定义变量增量

mysql程序中的用户定义变量增量,mysql,Mysql,我试图在mysql过程中使用一个用户定义的变量。该变量将根据值进行递增和递减。两个select语句被加入其中,并且该变量将在这两个语句中使用。此外,在分配变量时将放置一个函数而不是静态值。谁能帮我一下我犯的错误吗?由于此错误,我无法创建它。 多谢各位 错误: #1064-您的SQL语法有错误;查看与MySQL服务器版本对应的手册,了解第59行“END”附近要使用的正确语法 你错过了一次机会;在极限线上,在终点之前 LIMIT start_row, end_row; 在结束前放置半柱 DE

我试图在mysql过程中使用一个用户定义的变量。该变量将根据值进行递增和递减。两个select语句被加入其中,并且该变量将在这两个语句中使用。此外,在分配变量时将放置一个函数而不是静态值。谁能帮我一下我犯的错误吗?由于此错误,我无法创建它。 多谢各位

错误: #1064-您的SQL语法有错误;查看与MySQL服务器版本对应的手册,了解第59行“END”附近要使用的正确语法


你错过了一次机会;在极限线上,在终点之前

LIMIT start_row, end_row;

在结束前放置半柱

   DELIMITER $$
CREATE DEFINER=`local`@`localhost` PROCEDURE `sp_select_customer_account_lesuire`(IN `date_from` VARCHAR(10), IN `date_to` VARCHAR(10), IN `account_id` INT(11) UNSIGNED, IN `company_name` INT(11) UNSIGNED, IN `start_row` INT(11) UNSIGNED, IN `end_row` INT(11) UNSIGNED)
    NO SQL
BEGIN
SET @runningBalance := -199999; /*need a function for dynamic value*/
SELECT
c.`customer_account_id` AS 'id',
c.`received` AS 'date',
c.`description` AS 'desc',
'' AS 'sales_type',
NULL AS 'sales_us',
NULL AS 'sales_rate',
NULL AS 'sales_yen',
CONCAT('$ ',FORMAT(c.`usd_amount`,0)) AS 'us',
c.`rate` AS 'rate',
CONCAT('¥ ',FORMAT(c.`yen_amount`,0)) AS 'yen',
(@runningBalance := @runningBalance-c.`yen_amount`) AS 'balance'

FROM `customer_account` c

LEFT JOIN `customer_detail` cd ON
cd.`customer_detail_id` = c.`customer_detail_id`

WHERE
(
    (account_id='' OR c.customer_account_id=account_id)
    AND
    (cd.customer_detail_id=company_name)
    AND
    (c.received BETWEEN (CASE WHEN (date_from="" OR date_from="0000-00-00") THEN '1990-01-01' ELSE date_from END) AND (CASE WHEN (date_to="" OR date_to="0000-00-00") THEN CURRENT_DATE ELSE date_from END))
)
GROUP BY c.customer_account_id
UNION
SELECT
cs.`invoice_id`,
cs.`sales_date`,
CONCAT('INV#',cs.`invoice_no`),
(CASE WHEN cs.`sales_type`='1' THEN 'FOB' WHEN cs.`sales_type`='2' THEN 'C&F' WHEN cs.`sales_type`='3' THEN 'CIF' WHEN cs.`sales_type`='4' THEN 'Dealer' WHEN cs.`sales_type`='5' THEN 'Auction'END),
CASE WHEN cs.`currency`='usd' THEN CONCAT('$ ',FORMAT((cs.`grand_total`/cs.`exchange_rate`),0)) ELSE NULL END,
CASE WHEN cs.`exchange_rate` > 1 THEN cs.`exchange_rate` ELSE NULL END,
CONCAT('¥ ',FORMAT(cs.`grand_total`,0)),
NULL,
NULL,
NULL,
(@runningBalance := @runningBalance+cs.`grand_total`)

FROM `car_sales` cs

LEFT JOIN `customer_detail` cd ON
cd.`customer_detail_id` = cs.`buyer_name`

WHERE 
(
    (cd.customer_detail_id=company_name)
    AND
    (cs.sales_date BETWEEN (CASE WHEN (date_from="" OR date_from="0000-00-00") THEN '1990-01-01' ELSE date_from END) AND (CASE WHEN (date_to="" OR date_to="0000-00-00") THEN CURRENT_DATE ELSE date_from END))
)
ORDER BY 2 ASC
LIMIT start_row, end_row;
END$$
DELIMITER ;

缺少
限制开始行、结束行之后
   DELIMITER $$
CREATE DEFINER=`local`@`localhost` PROCEDURE `sp_select_customer_account_lesuire`(IN `date_from` VARCHAR(10), IN `date_to` VARCHAR(10), IN `account_id` INT(11) UNSIGNED, IN `company_name` INT(11) UNSIGNED, IN `start_row` INT(11) UNSIGNED, IN `end_row` INT(11) UNSIGNED)
    NO SQL
BEGIN
SET @runningBalance := -199999; /*need a function for dynamic value*/
SELECT
c.`customer_account_id` AS 'id',
c.`received` AS 'date',
c.`description` AS 'desc',
'' AS 'sales_type',
NULL AS 'sales_us',
NULL AS 'sales_rate',
NULL AS 'sales_yen',
CONCAT('$ ',FORMAT(c.`usd_amount`,0)) AS 'us',
c.`rate` AS 'rate',
CONCAT('¥ ',FORMAT(c.`yen_amount`,0)) AS 'yen',
(@runningBalance := @runningBalance-c.`yen_amount`) AS 'balance'

FROM `customer_account` c

LEFT JOIN `customer_detail` cd ON
cd.`customer_detail_id` = c.`customer_detail_id`

WHERE
(
    (account_id='' OR c.customer_account_id=account_id)
    AND
    (cd.customer_detail_id=company_name)
    AND
    (c.received BETWEEN (CASE WHEN (date_from="" OR date_from="0000-00-00") THEN '1990-01-01' ELSE date_from END) AND (CASE WHEN (date_to="" OR date_to="0000-00-00") THEN CURRENT_DATE ELSE date_from END))
)
GROUP BY c.customer_account_id
UNION
SELECT
cs.`invoice_id`,
cs.`sales_date`,
CONCAT('INV#',cs.`invoice_no`),
(CASE WHEN cs.`sales_type`='1' THEN 'FOB' WHEN cs.`sales_type`='2' THEN 'C&F' WHEN cs.`sales_type`='3' THEN 'CIF' WHEN cs.`sales_type`='4' THEN 'Dealer' WHEN cs.`sales_type`='5' THEN 'Auction'END),
CASE WHEN cs.`currency`='usd' THEN CONCAT('$ ',FORMAT((cs.`grand_total`/cs.`exchange_rate`),0)) ELSE NULL END,
CASE WHEN cs.`exchange_rate` > 1 THEN cs.`exchange_rate` ELSE NULL END,
CONCAT('¥ ',FORMAT(cs.`grand_total`,0)),
NULL,
NULL,
NULL,
(@runningBalance := @runningBalance+cs.`grand_total`)

FROM `car_sales` cs

LEFT JOIN `customer_detail` cd ON
cd.`customer_detail_id` = cs.`buyer_name`

WHERE 
(
    (cd.customer_detail_id=company_name)
    AND
    (cs.sales_date BETWEEN (CASE WHEN (date_from="" OR date_from="0000-00-00") THEN '1990-01-01' ELSE date_from END) AND (CASE WHEN (date_to="" OR date_to="0000-00-00") THEN CURRENT_DATE ELSE date_from END))
)
ORDER BY 2 ASC
LIMIT start_row, end_row;
END$$
DELIMITER ;