How do I use properly CASE..WHEN in MySQL

后端 未结 6 1183
我在风中等你
我在风中等你 2020-12-01 15:53

Here is a demo query, notice it is very simple, Fetches only where base_price is 0, And still, it chooses the condition 3:

SELECT
   CASE course_enrollment_s         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 15:56

    CASE case_value
        WHEN when_value THEN statements
        [WHEN when_value THEN statements]
        ELSE statements
    END 
    

    Or:

    CASE
    WHEN  THEN statements
    [WHEN  THEN statements] 
    ELSE statements
    END 
    

    here CASE is an expression in 2nd scenario search_condition will evaluate and if no search_condition is equal then execute else

    SELECT
       CASE course_enrollment_settings.base_price
        WHEN course_enrollment_settings.base_price = 0      THEN 1
    

    should be

    SELECT
       CASE 
        WHEN course_enrollment_settings.base_price = 0      THEN 1
    

提交回复
热议问题