2

我有一个生成表的 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;
}

任何人都可以帮忙吗?

4

1 回答 1

4
select  ...
,       case when profile = 'admin' then 'self' end as admin
,       case when coalesce(profile,'') <> 'admin' then 'self' end as user
from    table.users

a的默认值为casenull,符合您的要求。

于 2012-08-06T19:44:35.030 回答