错误代码:1054。'字段列表中的未知列'

时间:2015-11-08 07:08:21

标签: mysql sql

请帮助我尝试执行以下存储过程。我收到一条错误消息,指出错误代码:1054。未知列' bpc2016.entity'在'字段列表'。当我在industryCY视图中取出对industryPY的引用时,错误消失了。请帮助数据库中存在表和列。

CREATE DEFINER=`root`@`localhost` PROCEDURE `getAbudgetnow`()
BEGIN
CREATE OR REPLACE VIEW industryPY
AS
SELECT
alet.area AS 'area',
alet.industry_description AS 'industry_desc',
alet.industry AS 'industry',
alet.percentage AS 'perc',
ref_data.product AS 'product',
ref_data.pz AS 'pz',
ref_data.rate AS 'amount'
FROM
alet
RIGHT JOIN
ref_data ON (alet.industry = ref_data.industry and alet.area = ref_data.area)
WHERE alet.industry IS NOT NULL;

CREATE OR REPLACE VIEW industryCY
AS
SELECT
bpc2016.entity AS 'entity',
bpc2016.plant AS 'plant',
bpc2016.product_desc AS 'product_desc',
bpc2016.product AS 'product',
bpc2016.customer AS 'customer',
bpc2016.route AS 'route',
bpc2016.pz_desc AS 'pz_desc',
bpc2016.pz AS 'pz',
bpc2016.amount AS 'amount',
industryPY.area AS 'area',
industryPY.industry_desc AS 'industry_desc',
industryPY.industry AS 'industry',
industryPY.perc AS 'percentage',
industryPY.amount AS 'PYamount',
TRUNCATE(bpc2016.amount*industryPY.perc,2) AS 'budget_2016_vol'
FROM
bpc2016
FULL JOIN
industryPY ON (bpc2016.pz = industryPY.pz and bpc2016.product = industryPY.product);

END

enter image description here

' bpc2016',(\ n
entity varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
plant varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
product_desc varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
product varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
interplant varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
customer varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
route varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
pz_desc varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
pz varchar(255)CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \' \',\ n
amount float NOT NOT DEFAULT \' 0 \' \ n)ENGINE = InnoDB DEFAULT CHARSET = latin1'

2 个答案:

答案 0 :(得分:0)

您可以重新定义分隔符,以告诉解析器在您的过程中语句结束的位置;

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `getAbudgetnow`()
BEGIN

  CREATE OR REPLACE VIEW industryPY 
  AS
  SELECT
  alet.area AS 'area',
  alet.industry_description AS 'industry_desc',
  alet.industry AS 'industry',
  alet.percentage AS 'perc',
  ref_data.product AS 'product',
  ref_data.pz AS 'pz',
  ref_data.rate AS 'amount'
  FROM
  alet
  RIGHT JOIN
  ref_data ON (alet.industry = ref_data.industry and alet.area = ref_data.area)
  WHERE alet.industry IS NOT NULL;

  CREATE OR REPLACE VIEW industryCY
  AS
  ...
  ;


END $$
DELIMITER ;

答案 1 :(得分:0)

感谢所有帮助这似乎是问题 - 当我用FULL JOIN或{{1}代替完整联接时,Mihai是对的“mysql没有right至少没有直接”程序执行。