where子句存储过程中的mysql错误

时间:2019-01-04 04:29:18

标签: mysql stored-procedures mysql-workbench where concat

我收到此错误:错误代码:1054。“ where子句” 0.128秒中的未知列“ last_name_letter”

,我不确定为什么。几个小时前,代码就可以工作了,现在却不行了!未做任何更改。

请注意,我确实在最初的几个临时表之后删除了一些;但是,它们与手头的问题无关,我这样做是为了使代码更短,更易读。

#### OPEN STORED PROCEDURE
DELIMITER // 

DROP PROCEDURE IF EXISTS child_sp_trigger_conversion_1_2; 

CREATE PROCEDURE child_sp_trigger_conversion_1_2(IN last_name_letter VARCHAR(5))
   BEGIN

#### DROP TABLE IF EXISTS

DROP TABLE IF EXISTS cte_leenk_ladder_history; 
DROP TABLE IF EXISTS cte_ladder_history_self_join_lh1;
DROP TABLE IF EXISTS cte_ladder_history_self_join_lh2;
DROP TABLE IF EXISTS cte_ladder_history_join_lh1_lh2_current_trigger_record;


#### CREATE PARAMETERS FOR LADDERS

    CREATE TEMPORARY TABLE cte_leenk_ladder_history
        SELECT 
        lh.member_id
        ,sc.salesforce_id
        ,sc.lastname 
        ,ladder_change
        ,date_trigger_event
        ,@ladder_value
        ,lh.ladder_config_id as ladder_config_id
        ,trigger_name
        ,coalesce(lh.ladder_advocacy,lh.ladder_elected,lh.ladder_policy,lh.ladder_organizing,lh.ladder_organizing,lh.ladder_engagement) as ladder_value 
        ,CASE WHEN lh.ladder_advocacy is not null THEN 'ladder_advocacy'
               WHEN lh.ladder_elected is not null THEN 'ladder_elected'
               WHEN lh.ladder_policy is not null THEN 'ladder_policy'
               WHEN lh.ladder_organizing is not null THEN 'ladder_organizing'
               WHEN lh.ladder_collective is not null THEN 'ladder_collective'
               WHEN lh.ladder_engagement is not null THEN 'ladder_engagement'
            END
            AS ladder_name
        FROM leeds_new.leenk_ladder_history as lh 
            inner join leeds_new.leenk_ladder_config as lc on lh.ladder_config_id = lc.ladder_config_id
            inner join leeds_new.salesforce_contacts as sc on lh.member_id = sc.salesforce_id 
            where lh.ladder_change = 1 and lc.active = 1 and lc.trigger = 1
                and sc.lastname like concat ('%', last_name_letter); 

#### CLOSE STORED PROCEDURE 
   END // 
DELIMITER ; 

0 个答案:

没有答案