在Redshift中将值存储在变量中

DJo*_*DJo 0 postgresql amazon-redshift

我试图在tw变量中存储两个变量.

例如:

var1=$(select max(columnA) from table)
var2=$(select min(columnA) from table)
Run Code Online (Sandbox Code Playgroud)

我可以组合上述语句并执行相同的一次并将最大值存储在var2中的var1和min值中吗?

我正在使用Redshift DB.

小智 5

我知道这个问题已经过时了,但我也需要找到问题的解决方案.经过多次游戏后,我提出了解决方案.

-- Create a temp table for storing the variables
create temp table tmp_vars (
  x int,
  y date
);

-- Store the values in the temp table
insert into tmp_vars (x, y) values
  ((select max(id) from table1), 
   (select max(date) from table2));  

-- Use the variable in a query
select *
from some_table
where date >= (select y from tmp_vars limit 1);

-- Drop the temp table
drop table tmp_vars;
Run Code Online (Sandbox Code Playgroud)