1、INSERT INTO FROM語句
語句形式爲:INSERT INTO table2(field1,field2,…) SELECT value1,value2,… from table1 要求目標表table2必須存在。spa
一、建立臨時表:table
create temporary table tmp_idfa_fm (id bigserial primary key,idfa text, num int);select
二、插入數據:im
insert into tmp_idfa_fm (idfa, num) select idfa, count(idfa) as ct from nlogs where idfa!='' and sendtime>='2015-09-01 00:00:00' and sendtime<'2015-12-01 00:00:00' group by idfa order by ct desc ;數據
2、SELECT INTO FROM語句查詢
語句形式爲:SELECT vale1, value2 into table2 FROM table1tab
要求目標表table2不存在,由於在插入時會自動建立表table2,並將table1中指定字段數據複製到table2中。co
查詢語句:time
select idfa, recvtime into tmp_tb1 from nlogs where recvtime>='2015-09-01 00:00:00' and recvtime<'2015-09-03 00:00:00';ab