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?