How does MySQL CASE work?

前端 未结 3 1367
野性不改
野性不改 2020-11-29 02:03

I know that SQL\'s CASE syntax is as follows:

CASE
    WHEN search_condition THEN statement_list
    [WHEN search_condition THEN statement_list]         


        
3条回答
  •  遥遥无期
    2020-11-29 02:42

    I wanted a simple example of the use of case that I could play with, this doesn't even need a table. This returns odd or even depending whether seconds is odd or even

    SELECT CASE MOD(SECOND(NOW()),2) WHEN 0 THEN 'odd' WHEN 1 THEN 'even' END;
    

提交回复
热议问题