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

前端 未结 30 1799
梦如初夏
梦如初夏 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

    You can find some nice examples in The Power of SQL CASE Statements, and I think the statement that you can use will be something like this (from 4guysfromrolla):

    SELECT
        FirstName, LastName,
        Salary, DOB,
        CASE Gender
            WHEN 'M' THEN 'Male'
            WHEN 'F' THEN 'Female'
        END
    FROM Employees
    

提交回复
热议问题