Reputation: 961
So I am having a big table of AbstractID, SentenceID, WordID, and Word. Some words show in multiple files. I would like to count how many files every word shows, and then create a new table of with Word and Count. Below is a piece of my data.
My sql query is below:
CREATE TABLE WORDLIST(WORD, TOTALCOUNT) AS
(
SELECT WORD FROM ASSIGNMENT2 WHERE
(
SELECT WORD, COUNT(*) FROM (select DISTINCT FILEID, WORD FROM ASSIGNMENT2)
GROUP BY WORD ORDER BY COUNT(*) DESC));
It is giving me an error:
"Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:"
How do I correct this? Thanks.
Upvotes: 0
Views: 186
Reputation: 191570
You're rather overcomplicating the query. The error is because your outer where
clause doesn't have a condition; you're selecting multiple things, which isn't right anyway, but then not comparing those to anything. And you don't need to enclose the query in a set of parentheses.
You can just do:
CREATE TABLE WORDLIST (WORD, TOTALCOUNT) AS
SELECT WORD, COUNT(DISTINCT FILEID)
FROM ASSIGNMENT2
GROUP BY WORD;
There's no point ordering the query as it won't affect future queries against the new table - you still have to order those, as there is no inherent order of rows within the table. (And I think an order by
will cause an error in a create-as statement, but can't immediately check that).
Creating a table to hold this information seems odd though as it will go out of date quickly. Perhaps you wanted a view really?
Upvotes: 1