我有以下案例陈述:

CASE
WHEN CI.season = 1 THEN "Wet Season"
WHEN CI.season = 2 THEN "Early Wet Season"
WHEN CI.season = 3 THEN "Late Wet Season"
WHEN CI.season = 4 THEN "Dry Season"
WHEN CI.season = 4 and R.date_accessed > "2016-05-20 23:59:59" THEN "NULL"
ELSE "NULL" END as "Season" ,


如何显示如果季节值是4并且访问的日期大于“ 2016-05-20 23:59:59”应等于NULL。目前,它仅显示“干旱季节”。我认为它只读取第一种情况。谢谢你们的回复。

最佳答案

尝试这个:

CASE
WHEN CI.season = 1 THEN "Wet Season"
WHEN CI.season = 2 THEN "Early Wet Season"
WHEN CI.season = 3 THEN "Late Wet Season"
WHEN CI.season = 4 and R.date_accessed > "2016-05-20 23:59:59" THEN "NULL"
WHEN CI.season = 4 THEN "Dry Season"
ELSE "NULL" END as "Season"


要么

CASE
WHEN CI.season = 1 THEN "Wet Season"
WHEN CI.season = 2 THEN "Early Wet Season"
WHEN CI.season = 3 THEN "Late Wet Season"
WHEN CI.season = 4 THEN
    CASE WHEN R.date_accessed > "2016-05-20 23:59:59" THEN "NULL" ELSE "Dry Season" END
ELSE "NULL" END as "Season"

关于mysql - MySQL正确的Case语句覆盖第一个声明的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38653760/

10-15 19:49