MySQL select statement with CASE or IF ELSEIF? Not sure how to get the result

后端 未结 3 987
温柔的废话
温柔的废话 2020-11-27 15:37

I have a two tables. One has manufacturer information and includes the regions where they can sell. The other has their products for sale. We have to limit visibility of

3条回答
  •  温柔的废话
    2020-11-27 16:23

    Another way of doing this is using nested IF statements. Suppose you have companies table and you want to count number of records in it. A sample query would be something like this

    SELECT IF(
          count(*) > 15,
          'good',
          IF(
              count(*) > 10,
              'average',
              'poor'
            ) 
          ) as data_count 
          FROM companies
    

    Here second IF condition works when the first IF condition fails. So Sample Syntax of the IF statement would be IF ( CONDITION, THEN, ELSE). Hope it helps someone.

提交回复
热议问题