错误:未知列'状态'在'字段列表'

时间:2016-09-23 07:59:48

标签: mysql

SELECT item_number, item_name, description, status, active_date, inactive_date, creation_date, creation_by, last_updated_date, last_updated_by, 
(CASE WHEN inactive_date IS NULL THEN 
    CASE WHEN active_date <= curdate() THEN 'ACTIVE' ELSE 'FUTURE ACTIVE' END
 ELSE  
     CASE WHEN active_date = inactive_date THEN 'INACTIVE'
          WHEN active_date <= curdate() AND inactive_date > curdate() THEN 'ACTIVE'
          WHEN active_date >  curdate() AND inactive_date > curdate() THEN 'FUTURE ACTIVE' 
     ELSE 'INACTIVE' END 
 END) as status

请帮帮我。我是mysql的新手。

2 个答案:

答案 0 :(得分:0)

在您的SELECT中,您已包含status

SELECT item_number, item_name, description, status

由于您将status定义为AS作为新列,因此我怀疑您的表本身没有status列。移除status并将该行转为

SELECT item_number, item_name, description, active_date, inactive_date, creation_date, creation_by, last_updated_date, last_updated_by, 

答案 1 :(得分:0)

select移除状态如果是case

的结果,则不需要它
SELECT item_number, item_name, description, active_date, inactive_date, creation_date, creation_by, last_updated_date, last_updated_by, 
(CASE WHEN inactive_date IS NULL THEN 
    CASE WHEN active_date <= curdate() THEN 'ACTIVE' ELSE 'FUTURE ACTIVE' END
 ELSE  
     CASE WHEN active_date = inactive_date THEN 'INACTIVE'
          WHEN active_date <= curdate() AND inactive_date > curdate() THEN 'ACTIVE'
          WHEN active_date >  curdate() AND inactive_date > curdate() THEN 'FUTURE ACTIVE' 
     ELSE 'INACTIVE' END 
 END) as Status

还缺少from课程。