从现有表创建一个新表

时间:2014-04-07 17:17:03

标签: oracle-sqldeveloper create-table

我正在使用多个文件中的这个单词表。我想计算每个单词显示的文件数量。我可以用下面的代码片段。但是当我使用CREATE TABLE语句嵌套它时,它将无法工作。下面的第二段代码是错误代码。

SELECT WORD, COUNT(*) FROM (select DISTINCT ABSTRACTID, WORD FROM NSFABSTRACTS)
GROUP BY WORD ORDER BY COUNT(*) DESC

CREATE TABLE DOC_FREQ (WORD, TOTALCOUNT) AS
(
  SELECT WORD, COUNT(*) FROM (select DISTINCT ABSTRACTID, WORD FROM NSFABSTRACTS)
  GROUP BY WORD ORDER BY COUNT(*));

以下是错误消息: SQL Error: ORA-00907: missing right parenthesis 00907. 00000 - "missing right parenthesis" *Cause:
*Action:
任何人都可以建议如何创建此表?谢谢。

1 个答案:

答案 0 :(得分:0)

当括号中包含查询时,您无法使用order by;至少如果该子句也在括号内:

create table t42 as (select * from dual order by dummy);

SQL Error: ORA-00907: missing right parenthesis

外面允许:

create table t42 as (select * from dual) order by dummy;

table T42 created.

您可以删除括号,因为它们根本不需要:

create table t42 as select * from dual order by dummy;

table T42 created.

或删除order by,因为order by声明usually makes little difference中的create并且不会影响数据的检索方式:

create table t42 as (select * from dual);

table T42 created.

或者最好是我的口味,两者:

create table t42 as select * from dual;

table T42 created.