我正在尝试为这200个单词创建一个关键表。下面是我的代码,SQL不断给我一个错误消息Error report:
SQL Error: ORA-00918: column ambiguously defined
00918. 00000 - "column ambiguously defined"
。该错误指向SELECT *
。
但是,当我将单词列表从200切换到前3时,它会生成表格但是给我这个错误Error report:
SQL Command: table FINAL_PIVOTTEST
Failed: Warning: execution completed with warning
。感谢您的帮助!
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'));
我用来生成此数据透视表的表格如下所示:
READSCALE QUESID SENTID WORDID WORD
2 a00001 1 1 book
3 a00002 1 2 library
... ... ... ... ...
答案 0 :(得分:1)
尝试为IN内的每个值指定别名,并为COUNT(单词)指定别名:
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
..............
答案 1 :(得分:1)
您要转移的单词列表包含重复项 - 因为您指示数据库将IN()语句中的每个单词转换为列名,您收到错误,因为您正在尝试创建一个包含多列的表同名。
相反,请使用以下代码(确保我正确地填写了所有单词):
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'
)
);
点击此处查看SQL Fiddle