在mysql中查询的情况

时间:2014-11-18 09:36:56

标签: mysql sql

我想执行以下查询, 当date diff大于1时,如何在when子句中将其添加为diffdate在那里不可用。

select 
   CASE ( 
SELECT DATEDIFF('2014-11-30','2015-11-29') AS DiffDate
 )
   WHEN 1 THEN "1 Day"
   WHEN 7 THEN "Week"
   WHEN ??? THEN "Yearly"


   END;

1 个答案:

答案 0 :(得分:2)

使用else

select CASE DATEDIFF('2014-11-30','2015-11-29')
            WHEN 1 THEN '1 Day'
            WHEN 7 THEN '7 Days'
            ELSE 'Yearly'
       END;