我正在尝试重命名我具有只读访问权限的数据库的一列的值。我还想将其中两个值合二为一。我正在使用 SQL CASE 查询,但它不正确地转换值。这是我的 SQL:
SELECT
DATE(appraisal.created_time),
appraisal_steps.title,
Count(appraisal.appraisal_id),
case appraisal_steps.title
when "archive" then "A_Archived"
when "on_sale" then "J_Selling"
when "under_evaluation" then "F_Evaluating"
when "evaluated" then "H_Appraisal Complete"
when "pending" then "B_Pending"
when "crap" then "C_Not For Lofty"
when "waiting_internal_expert_evaluation" then "D_Unclaimed"
when ("expert_needs_information" OR "admin_needs_information") then "E_Waiting"
when "seller_answered_to_expert_question" then "G_Needs_Attn"
when "ready_to_be_sold" then "I_Ready"
else "wtf"
end as Status
FROM
appraisal
INNER JOIN appraisal_steps ON appraisal.`status` = appraisal_steps.step_id
WHERE
appraisal.powersale = 0
GROUP BY
DATE(appraisal.created_time),
appraisal_steps.title
ORDER BY
appraisal_steps.title DESC, status
某些状态的结果是正确的(是复数状态吗?:),但卖主回答到专家问题被转换为“E_Waiting”,这是不正确的。
如果我更改“When”子句的顺序,则不同的 stati 有效且无效。
我究竟做错了什么?