gpt4 book ai didi

SQL查询案例语句

转载 作者:行者123 更新时间:2023-12-04 18:15:29 26 4
gpt4 key购买 nike

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

任何人都可以帮忙吗?

最佳答案

select  ...
, case when profile = 'admin' then 'self' end as admin
, case when coalesce(profile,'') <> 'admin' then 'self' end as user
from table.users
case 的默认值为空,满足你的要求。

关于SQL查询案例语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11834782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com