How do I perform an IF…THEN in an SQL SELECT?

前端 未结 30 1873
梦如初夏
梦如初夏 2020-11-21 22:50

How do I perform an IF...THEN in an SQL SELECT statement?

For example:

SELECT IF(Obsolete = \'N\' OR InStock = \'Y\' ? 1 :          


        
30条回答
  •  無奈伤痛
    2020-11-21 23:10

    case statement some what similar to if in SQL server
    
    SELECT CASE 
                WHEN Obsolete = 'N' or InStock = 'Y' 
                   THEN 1 
                   ELSE 0 
           END as Saleable, * 
    FROM Product
    

提交回复
热议问题