• <bdo id='vDMry'></bdo><ul id='vDMry'></ul>

    1. <legend id='vDMry'><style id='vDMry'><dir id='vDMry'><q id='vDMry'></q></dir></style></legend>
      1. <tfoot id='vDMry'></tfoot>

        <small id='vDMry'></small><noframes id='vDMry'>

      2. <i id='vDMry'><tr id='vDMry'><dt id='vDMry'><q id='vDMry'><span id='vDMry'><b id='vDMry'><form id='vDMry'><ins id='vDMry'></ins><ul id='vDMry'></ul><sub id='vDMry'></sub></form><legend id='vDMry'></legend><bdo id='vDMry'><pre id='vDMry'><center id='vDMry'></center></pre></bdo></b><th id='vDMry'></th></span></q></dt></tr></i><div id='vDMry'><tfoot id='vDMry'></tfoot><dl id='vDMry'><fieldset id='vDMry'></fieldset></dl></div>

        Oracle SQL:在带有 Select 语句的插入中使用序列

        Oracle SQL: Use sequence in insert with Select Statement(Oracle SQL:在带有 Select 语句的插入中使用序列)

        <legend id='OBB4c'><style id='OBB4c'><dir id='OBB4c'><q id='OBB4c'></q></dir></style></legend>
        • <tfoot id='OBB4c'></tfoot>
            <i id='OBB4c'><tr id='OBB4c'><dt id='OBB4c'><q id='OBB4c'><span id='OBB4c'><b id='OBB4c'><form id='OBB4c'><ins id='OBB4c'></ins><ul id='OBB4c'></ul><sub id='OBB4c'></sub></form><legend id='OBB4c'></legend><bdo id='OBB4c'><pre id='OBB4c'><center id='OBB4c'></center></pre></bdo></b><th id='OBB4c'></th></span></q></dt></tr></i><div id='OBB4c'><tfoot id='OBB4c'></tfoot><dl id='OBB4c'><fieldset id='OBB4c'></fieldset></dl></div>

                <bdo id='OBB4c'></bdo><ul id='OBB4c'></ul>

                  <small id='OBB4c'></small><noframes id='OBB4c'>

                    <tbody id='OBB4c'></tbody>
                1. 本文介绍了Oracle SQL:在带有 Select 语句的插入中使用序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  基本上我想运行以下查询:

                  Basically I want to run the following query:

                  INSERT INTO historical_car_stats (historical_car_stats_id, year, month, make, model, region, avg_msrp, count)
                    SELECT
                      my_seq.nextval,
                      '2010',
                      '12',
                      'ALL',
                      'ALL',
                      region,
                      sum(avg_msrp * count) / sum(count),
                      sum(count)
                    FROM historical_car_stats
                    WHERE year = '2010'
                          AND month = '12'
                          AND make != 'ALL'
                    GROUP BY region;
                  

                  它不起作用,因为此处不允许使用序列号"SQL 错误.我怎么写才能让 Oracle 让我做我想做的事?

                  It doesn't work because "sequence number not allowed here" SQL error. How can I write this so Oracle will let me do what I want to do?

                  推荐答案

                  假设你想在用序列生成key之前对数据进行分组,听起来你想要像

                  Assuming that you want to group the data before you generate the key with the sequence, it sounds like you want something like

                  INSERT INTO HISTORICAL_CAR_STATS (
                      HISTORICAL_CAR_STATS_ID, 
                      YEAR,
                      MONTH, 
                      MAKE,
                      MODEL,
                      REGION,
                      AVG_MSRP,
                      CNT) 
                  SELECT MY_SEQ.nextval,
                         year,
                         month,
                         make,
                         model,
                         region,
                         avg_msrp,
                         cnt
                    FROM (SELECT '2010' year,
                                 '12' month,
                                 'ALL' make,
                                 'ALL' model,
                                 REGION,
                                 sum(AVG_MSRP*COUNT)/sum(COUNT) avg_msrp,
                                 sum(cnt) cnt
                            FROM HISTORICAL_CAR_STATS
                           WHERE YEAR = '2010' 
                             AND MONTH = '12'
                             AND MAKE != 'ALL' 
                           GROUP BY REGION)
                  

                  这篇关于Oracle SQL:在带有 Select 语句的插入中使用序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to redirect the output of DBMS_OUTPUT.PUT_LINE to a file?(如何将 DBMS_OUTPUT.PUT_LINE 的输出重定向到文件?)
                  How do I get column datatype in Oracle with PL-SQL with low privileges?(如何使用低权限的 PL-SQL 在 Oracle 中获取列数据类型?)
                  Get a list of all functions and procedures in an Oracle database(获取 Oracle 数据库中所有函数和过程的列表)
                  Why cannot I create triggers on objects owned by SYS?(为什么我不能在 SYS 拥有的对象上创建触发器?)
                  Returning result even for elements in IN list that don#39;t exist in table(即使对于表中不存在的 IN 列表中的元素也返回结果)
                  Reset Sequence in oracle 11g(oracle 11g 中的重置序列)
                    • <legend id='jSz6s'><style id='jSz6s'><dir id='jSz6s'><q id='jSz6s'></q></dir></style></legend>
                      • <bdo id='jSz6s'></bdo><ul id='jSz6s'></ul>

                          <tfoot id='jSz6s'></tfoot>

                            <i id='jSz6s'><tr id='jSz6s'><dt id='jSz6s'><q id='jSz6s'><span id='jSz6s'><b id='jSz6s'><form id='jSz6s'><ins id='jSz6s'></ins><ul id='jSz6s'></ul><sub id='jSz6s'></sub></form><legend id='jSz6s'></legend><bdo id='jSz6s'><pre id='jSz6s'><center id='jSz6s'></center></pre></bdo></b><th id='jSz6s'></th></span></q></dt></tr></i><div id='jSz6s'><tfoot id='jSz6s'></tfoot><dl id='jSz6s'><fieldset id='jSz6s'></fieldset></dl></div>

                            <small id='jSz6s'></small><noframes id='jSz6s'>

                              <tbody id='jSz6s'></tbody>