gpt4 book ai didi

postgresql - 使用 CASE WHEN 选择两列

转载 作者:行者123 更新时间:2023-11-29 14:15:19 25 4
gpt4 key购买 nike

我想选择三列(id_produkt、313、314)所以我尝试了:

select id_produkt, 
case when bp_stan_produkt.id_stan_produkt = 313
then 'TAK'
else 'NIE'
end as "313"
from bp_stan_produkt where data_do is not null

union

select id_produkt,
case when bp_stan_produkt.id_stan_produkt = 314
then 'TAK'
else 'NIE'
end as "314"
from bp_stan_produkt where data_do is not null

但它只返回两列:id_produkt 和 313。如何获得带有别名的三列?

最佳答案

试试这个 SQL 代码

select id_produkt, 
case when id_stan_produkt = 313 then 'TAK'
else 'NIE'
end as "313",
case when id_stan_produkt = 314 then 'TAK'
else 'NIE'
end as "314"
from bp_stan_produkt where data_do is null

关于postgresql - 使用 CASE WHEN 选择两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50700679/

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