ORA-00907: 创建 table 时缺少右括号

ORA-00907: missing right parenthesis when creating a table

我的以下查询运行良好并生成了正确的结果

select id, sum(item_stock)
from seller
group by id
order by id ASC;

当我尝试使用上述查询创建 table 时

CREATE TABLE total_stock
AS (
select id, sum(item_stock)
from seller
group by id
order by id ASC );

我收到以下错误

SQL 错误:ORA-00907:缺少右括号

如能提供任何帮助说明为什么这不起作用,我们将不胜感激

您的问题是由 ORDER BY.

子句引起的

你必须:

  1. 为您的 "sum" 字段添加别名
  2. 创建另一个子查询以便 "remove" ORDER BY 子句
CREATE TABLE total_stock
AS (
    select id, item_stock
    from (
         select id, sum(item_stock) as item_stock
         from seller
         group by id
         order by id ASC 
         )
)