문제

I am trying to create a pivort table for these 200 words. Below is my code, and SQL keeps giving me an error message Error report: SQL Error: ORA-00918: column ambiguously defined 00918. 00000 - "column ambiguously defined". The error points to SELECT *.

However, when I cut the word list from 200 to the first 3, it will generate the table but give me this error Error report: SQL Command: table FINAL_PIVOTTEST Failed: Warning: execution completed with warning. Appreciate your help!

    CREATE TABLE FINAL_PIVOTTEST AS;
    SELECT *
    FROM 
    (SELECT QUESID, WORD FROM FINAL_WORDLIST)
    PIVOT 
    (COUNT (WORD)
    FOR WORD IN (
    'article',
    'color',
    'icard',
    'icard',
    '400',
    'link',
    'stroke',
    'resume',
    'theories',
    'floppy',
    'semester',
    'justice',
    'rent',
    'receipt',
    'idnr',
    'bronze',
    'govdocument',
    'room',
    'means',
    'roomreservation',
    'checkout',
    'soil',
    'tour',
    'money',
    'grainger',
    'putting',
    'union',
    'microfiche',
    'disappeared',
    'explored',
    'returning',
    'returning',
    'replacement',
    'password',
    'homepage',
    'paper',
    'games',
    '1970s',
    'british',
    'board',
    'side',
    'leave',
    'electronically',
    'conversation',
    'message',
    'park',
    'next',
    '2013',
    'isnt',
    'today',
    'option',
    'citing',
    'job',
    'chemistry',
    'tomorrow',
    'citation ',
    'never',
    'availability',
    'availability',
    'mainstx',
    'mainstx',
    'personal',
    'alumni',
    'alumni',
    'test',
    'period',
    'undergraduate',
'medical',
'textbooks',
'missing',
'reserve',
'later',
'later',
'development',
'user',
'movie',
'visiting',
'refworks',
'refworks',
'talk',
'shelf',
'sciences',
'chapter',
'too',
'those',
'ebook',
'building',
'call',
'desk',
'wondered',
'scientist',
'during',
'ugl',
'ugl',
'ugl',
'problems',
'book',
'address',
'system',
'listed',
'location',
'free',
'site',
'bis',
'various',
'software',
'chat',
'phone',
'process',
'documenT',
'pdf',
'author',
'general',
'american',
'copies',
'newspaper',
'located',
'requested',
'particular',
'called',
'called',
'report',
'faculty',
'sshel',
'graduate',
'public',
'public',
'check',
'member'));

The table I am using to generate this pivot table looks like this:

READSCALE   QUESID     SENTID    WORDID    WORD
  2         a00001       1         1       book
  3         a00002       1         2      library
 ...         ...        ...       ...       ...
도움이 되었습니까?

해결책

Your list of words to pivot includes duplicates - since you are instructing the database to turn each word in the IN () statement into a column name, you are receiving an error because you are trying to create a table with multiple columns of the same name.

Instead, use the following code (make sure I got all the words correctly):

SELECT *
FROM 
(SELECT QUESID, WORD FROM FINAL_WORDLIST)
PIVOT 
(COUNT (WORD)
FOR WORD IN    
  (
    'fire',
    'dnr',
    'relay',
    'techloan',
    'calculator',
    'purse',
    'owner',
    'botanical',
    'chatted',
    'book',
    'safe',
    'serial',
    'decisions',
    'interviewing',
    'headphones',
    'keys',
    'sd',
    'prospective',
    'hr',
    'caller',
    'undergraduate',
    'directional',
    'habits',
    'discharge',
    'donating',
    'receipt',
    'bronze',
    'color',
    'addresses',
    'individuals',
    'tablet',
    'stations',
    'istc',
    'soil',
    'acquisition',
    'hiring',
    'retiree',
    'archival',
    'potential',
    'renewals',
    'release',
    'notes',
    'chapter',
    'camera',
    'apply',
    'discussion',
    'return',
    'provide',
    'sdc',
    'brief',
    'tour',
    'future',
    'mediacenter',
    'interview',
    'librarians',
    'courtesy',
    'overdue',
    'session',
    'message',
    'reports',
    'lib',
    'emailed',
    'numbers',
    'alumni',
    'printer',
    'building',
    'show',
    'recent',
    'returned',
    'availability',
    'talk',
    'scan',
    'job',
    'renew',
    'order',
    'scientist',
    'oakstr',
    'digital',
    'room',
    'reading',
    'media',
    'circ',
    'video',
    'call',
    'list',
    'open',
    'dvd',
    'lost',
    'card',
    'google',
    'graduate',
    'scanner',
    'phone',
    'policies',
    'before',
    'reserves',
    'called',
    'computer',
    'working',
    'location',
    'another',
    'full',
    'callnumber',
    'staff',
    'email',
    'collection',
    'campus',
    'showed',
    'checked',
    'contact',
    'research',
    'ugl',
    'ill',
    'item',
    'print',
    'journal',
    'request',
    'books',
    'library'
  )
);

Click here for SQL Fiddle

다른 팁

Try by specifying the the aliases for each value inside your IN, as well as for the COUNT(word) :

 CREATE TABLE FINAL_PIVOTTEST AS
 SELECT *
 FROM 
 (SELECT QUESID, WORD FROM FINAL_WORDLIST)
 PIVOT 
 (COUNT (WORD) wrd
 FOR WORD IN ('fire' as fire,
 'dnr' as dnr
 ..............
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top