SQL查询案例语句

时间:2012-08-06 19:38:32

标签: sql oracle oracle11gr2

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

有人可以帮忙吗?

1 个答案:

答案 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,符合您的要求。