2016-07-29 49 views
0

我有這個case語句:MySQL的正確case語句覆蓋第一申報價值

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年5月20日23:59 :59「應該等於NULL。現在它只顯示「乾燥季節」。我認爲它只是讀取第一個場景。謝謝你的回覆。

回答

1

試試這個:

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" 
+0

第二個是做自己的工作,但它的時間太長..;) –