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的新手。
答案 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
课程。