用于未来预期销售查询的函数将不运行-mysql

hivapdat  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(145)

我有这个查询,它是一个函数,用于获取任何给定的未来月份的预期销售额。

DELIMITER //

CREATE FUNCTION get_expected_sales(month INT)
RETURNS DOUBLE(4, 2)

BEGIN
  DECLARE month INT;
  DECLARE total_sales_2015 INT;
  DECLARE total_sales_2016 INT;
  DECLARE total_sales_2017 INT;
  DECLARE expected_sales DOUBLE(5, 2);

  SELECT SUM(amount) INTO total_sales_2015
  FROM fss_Payment payTableRef
  WHERE MONTH(paydate)=month AND YEAR(paydate)=2015;

  SELECT SUM(amount) INTO total_sales_2016
  FROM fss_Payment payTableRef
  WHERE MONTH(paydate)=month AND YEAR(paydate)=2016;

  SELECT SUM(amount) INTO total_sales_2017
  FROM fss_Payment payTableRef
  WHERE MONTH(paydate)=month AND YEAR(paydate)=2017;

  SET expected_sales = ROUND((total_sales_2015+total_sales_2016+total_sales_2017)/3,2);

  RETURN expected_sales;

  END //

  DELIMITER;

我得到的主要错误是:“函数已经存在”和“第15行where子句中的错误”

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题