在PostgreSQL中,我想用不同的标准做两个不同的select
。然后我希望每个的结果都插入到同一个临时表中,而不需要更改它们的顺序。
我该怎么做?我想出了这个
create temp table mytable as
select * from test where bc=true order by date desc;
select * into mytable from test where bc=false order by date asc;
select * from mytable;
但我得到ERROR: relation "mytable" already exists
我想举个例子
"one" , -600
"two", -500
从第一个选择然后
"three", 1200
"four", 1300
来自第二个表,然后mytable
将有
"one" , -600
"two", -500
"three", 1200
"four", 1300
我该怎么做?
答案 0 :(得分:1)
试试union all
。您的into
语法让人联想到SQL Server。只是做:
create temp table mytable as
select * from test where bc = true union all
select * from test where bc = false;