How do I use properly CASE..WHEN in MySQL

后端 未结 6 1201
我在风中等你
我在风中等你 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 16:03

    I think part of it is that you're stating the value you're selecting after CASE, and then using WHEN x = y syntax afterward, which is a combination of two different methods of using CASE. It should either be

    CASE X
      WHEN a THEN ...
      WHEN b THEN ...
    

    or

    CASE
      WHEN x = a THEN ...
      WHEN x = b THEN ...
    

提交回复
热议问题