2013-10-08 86 views
-3

我有兩個表,即history和errorlist。 歷史記錄包含具有詳細信息的交易記錄。其中之一是錯誤代碼。即錯誤列表表包含錯誤代碼和描述的列表。現在我想從兩個表中選擇結果,顯示歷史記錄表中出現不同錯誤代碼的次數以及錯誤列表表中相同錯誤代碼的相關錯誤描述。請幫忙。使用oracle從兩個表中選擇

+0

使用Oracle DBMS中 – RahulMuk07

+0

SELECT COUNT(*)作爲ERROR_COUNT,c.errorno,e.errordesc從HIST℃的內部通過c.errorno – RahulMuk07

+0

加入errorlist EON c.errorno = e.errorcode組,但這並不工作 – RahulMuk07

回答

0

假設你想要一個內部聯接的兩個表:

select errorcode, errordescription, count(*) 
from error, history 
where history.errorcode = error.code 
group by history.errorcode, history.errordescription 

編輯:

假設的錯誤代碼是在錯誤表中是唯一,並使用您所提供的字段名稱:

select h.errorcode, count(*) as count 
from history h 
group by h.errorcode 

如果您需要說明,太那麼你可能需要包括一個子查詢:

select z.errorcode, (select errordesc from error where errorcode = z.errorcode), z.count 
from (
select h.errorcode, count(*) as count 
from history h 
group by h.errorcode 
) z 
+0

我想也有錯誤描述爲相應的錯誤代碼顯示在相同的結果集 – RahulMuk07

+0

它應該像errorcount,errorcode,errordescription – RahulMuk07

+0

那該怎麼辦? –