2

我有一个 insert into 语句,该语句将有一个子查询,它从中获取所有信息。我只有一个问题,我必须使用作为序列创建的主键索引。我只是不知道如何插入带有子查询的序列。任何帮助将非常感激。目前 insert into 语句不起作用,但这是我到目前为止所拥有的。

INSERT INTO data_plan_demand(data_demand_id, data_plan_name,product_demand,data_plan_inf)
 VALUES( seq_data_demand_id2.nextval ,

      (SELECT d.name, COUNT(u.data_id) AS product_demands, 
      d.information AS dataplan_information
      FROM users u, data_plans d
      WHERE u.data_id = d.data_plan_id
      GROUP BY d.name,d.information));
4

1 回答 1

3

您可以将序列放入您的选择中,简单易行。(编辑,whups,对不起,错过了你正在分组)

INSERT INTO data_plan_demand(data_demand_id, data_plan_name,product_demand,data_plan_inf)
select seq_data_demand_id2.nextval, ss.name, ss.product_demands, ss.dataplan_information
from(SELECT d.name, COUNT(u.data_id) AS product_demands, 
      d.information AS dataplan_information
      FROM users u, data_plans d
      WHERE u.data_id = d.data_plan_id
      GROUP BY d.name,d.information) ss;
于 2015-10-08T15:07:10.043 回答