sql语句可以工作,但无法创建视图

n1bvdmb6  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(377)

在workbench中运行此sql时,它会生成所需的输出:https://www.dropbox.com/s/4ofodxtwslz228i/screenshot%202018-01-02%2003.34.25.png?dl=0
但是,当我尝试创建视图时,会出现以下错误:未知列“lead”( latest_20 . session_date )覆盖(分区) latest_20 . level 订货人 latest_20 . session_date 描述, level “字段列表”中的“asc”
我做错什么了?

SELECT

* ,

CONCAT(
    `lead_table`.`Session_Count`, ', ',
    DATE_FORMAT(`lead_table`.`Session_Date`, '%c/%e/%Y'), ', ',
    DATE_FORMAT(`lead_table`.`Session_Date`, '%l:%i %p'), ', ',
    if(Timestampdiff(DAY, `lead_table`.`lead`, `lead_table`.`Session_Date`) is null, 'na', Timestampdiff(DAY, `lead_table`.`lead`, `lead_table`.`Session_Date`)), ', ',
    if(Mod(Timestampdiff(hour, `lead_table`.`lead`, `lead_table`.`Session_Date`), 24) is null, 'na', Mod(Timestampdiff(hour, `lead_table`.`lead`, `lead_table`.`Session_Date`), 24)), ', ',
    if(Mod(Timestampdiff(MINUTE, `lead_table`.`lead`, `lead_table`.`Session_Date`), 60) is null, 'na', Mod(Timestampdiff(MINUTE, `lead_table`.`lead`, `lead_table`.`Session_Date`), 60))
) AS comb_label

FROM
(
  SELECT
     *,
     LEAD(`latest_20`.`session_date`) OVER (PARTITION BY `latest_20`.`level` ORDER BY `latest_20`.`session_date` DESC, `level` ASC) AS lead,
     Dayname(Lead(`latest_20`.`session_date`) OVER (PARTITION BY `latest_20`.`level` ORDER BY `latest_20`.`session_date` DESC, `level` ASC)) AS lead_day 
  FROM
     (
        SELECT
           * 
        FROM
           view_performance_accuracy_pct 
        WHERE
           user_id = 1 AND `level` = 'Basic' 
        ORDER BY
           session_date DESC,
           `level` ASC LIMIT 20
    ) AS latest_20 
  ORDER BY latest_20.session_date ASC
) AS lead_table
ne5o7dgx

ne5o7dgx1#

请单独指定所有列名,而不是“选择*”。例如
选择列1,列2。。。从

相关问题