gpt4 book ai didi

postgresql - 存储过程中的建表语句怎么写

转载 作者:行者123 更新时间:2023-11-29 13:13:58 30 4
gpt4 key购买 nike

如何在 postgresql 的存储过程中编写以下查询?

 create table data1 as
select A.*,
case when score >=940 then 1
when score between 600 and 746 then 2
when bureau_score between 599 and 630 then 4 else 5 end as score_level,
case when band between -1 and 5 then 1
when band between 6 and 20 then 2
when band between 21 and 35 then 3 else 4 end as band_level
from data A;

最佳答案

Postgresql 本身没有存储过程,只有函数,所以。

如果它是简单的 SQL,您可以简单地将其包装在 SQL 函数定义中。

create or replace function foo () returns void language sql as $$

create table data1 as
select A.*,
case when score >=940 then 1
when score between 600 and 746 then 2
when bureau_score between 599 and 630 then 4 else 5 end as score_level,
case when band between -1 and 5 then 1
when band between 6 and 20 then 2
when band between 21 and 35 then 3 else 4 end as band_level
from data A;

$$;

调用它 SELECT foo();

关于postgresql - 存储过程中的建表语句怎么写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51451334/

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