2013-10-08 85 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

那该怎么办? –