我有一个以select
开头的 huge_query_that_runs_fine_alone 。
我想将该查询结果插入到现有表中,但是普通的SQL语句行不通。
我尝试过:将值( huge_query_that_runs_fine_alone )插入到test_ds.test_tbl(field1,…,fieldN)中,但是查询编辑器告诉我select
关键字在意外的位置;
这:从( huge_query_that_runs_fine_alone )中的test_ds.test_tbl中选择*,但是查询编辑器告诉我这个Syntax error: Unexpected keyword INTO at [1:10]
;
该怎么办?
P.S。完整查询...
insert into test_bq_dataset.test_tbl (Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo, AmountPromo, SumPromo, AmountNoPromo, SumNoPromo) values (select promos.Naimenovanie_SKU, promos.Naimenovanie_TT, promos.MonthNo, promos.YearNo, AmountPromo, SumPromo, AmountNoPromo, SumNoPromo from
(select Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo, sum(Prodazhi_Litry) as AmountPromo, sum(Prodazhi_Summa_s_NDS) as SumPromo from IACloud0539_Calc.Data2_PROMO where Promo = false group by Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo) promos
left join
(select Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo, sum(Prodazhi_Litry) as AmountNoPromo, sum(Prodazhi_Summa_s_NDS) as SumNoPromo from IACloud0539_Calc.Data2_PROMO where Promo = true group by Naimenovanie_SKU, Naimenovanie_TT, MonthNo, YearNo) nopromos
on
promos.Naimenovanie_SKU = nopromos.Naimenovanie_SKU
and
promos.Naimenovanie_TT = nopromos.Naimenovanie_TT
and
promos.MonthNo = nopromos.MonthNo
and
promos.YearNo = nopromos.YearNo);
Syntax error: Unexpected keyword SELECT at [1:149]
答案 0 :(得分:2)
您可以在INSERT子句下面放置一个SELECT查询,它将正常工作
例如:
创建表temp.mytest5(col1 STRING,col2 STRING);
插入:
插入temp.mytest5(col1,col2) 选择“ record1”,“ record2”