2012-11-28 64 views
0

我有這個疑問應該:甲骨文,無效的標識符錯誤

create a listing that identifies different items in the inventory table on the number of colors available for each option

但我發現了一個錯誤說:

Error at Command Line:167 Column:66 Error report: SQL Error: ORA-00904: "INV"."ITEM_ID": invalid identifier 00904. 00000 - "%s: invalid identifier"

SELECT inv.inv_id, 
item1.item_id, 
(SELECT COUNT(*) 
FROM (SELECT DISTINCT i.color FROM inventory i WHERE i.item_id = inv.item_id)) 
FROM inventory inv 
INNER JOIN item item1 
ON item1.item_id = inv.item_id 
GROUP BY inv.inv_id, item1.item_id; 
+1

我已經使用[這個工具](http://decapitalize.eu/)來解決你的問題。 – 2012-11-28 17:27:56

回答

2

這聽起來像你只是想

SELECT inv.inv_id, 
     item1.item_id, 
     COUNT(distinct inv.color) 
    FROM inventory inv 
     JOIN item item1 ON (item1.item_id = inv.item_id) 
GROUP BY inv.inv_id, item1.item_id 

似乎沒有任何理由打inventory表再次在子查詢中。