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

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

    If you're inserting results into a table for the first time, rather than transferring results from one table to another, this works in Oracle 11.2g:

    INSERT INTO customers (last_name, first_name, city)
        SELECT 'Doe', 'John', 'Chicago' FROM dual
        WHERE NOT EXISTS 
            (SELECT '1' from customers 
                where last_name = 'Doe' 
                and first_name = 'John'
                and city = 'Chicago');
    

提交回复
热议问题