我有一个生成表的SQL查询
SELECT DISTINCT
concat(table.column, '.test.com) "User Login",
concat(concat(table.columnname, ' '), lastname) "Full Name",
'N' "Admin (Y/N)",
table.profile "Profile",
'Self' "admin",
'Self' "user",
FROM table.users
我想在上面的查询中添加一个case语句。
If (table.profile == admin){
admin = self;
user = null;
}
else{
admin = null;
user = self;
}
有人可以帮忙吗?
答案 0 :(得分:4)
select ...
, case when profile = 'admin' then 'self' end as admin
, case when coalesce(profile,'') <> 'admin' then 'self' end as user
from table.users
case
的默认值为null,符合您的要求。