2017-05-31 72 views
0

我有我的sql表中的列。如果值爲1,則應該返回管理資產,否則返回非管理資產。這是我的sql代碼。我想如果其他條件在我的sql

select asset_master_id, 
    am_name as aname, 
    am_serial_number as number, 
    (CASE adm_admin_flag 
     WHEN 1 
     THEN "Admin Asset" 
     ELSE "Non Admin Asset" 
    END AS am_admin_flag) 
FROM asset_master; 

我試過上面的代碼,但沒有爲我工作。

回答

2

您的CASE語法錯誤。

SELECT 
    CASE 
     WHEN am_admin_flag = 1 
     THEN "Admin Asset" 
     ELSE "Non Admin Asset" 
    END AS am_admin_flag 
    FROM 
    asset_master