【发布时间】:2015-07-27 12:35:04
【问题描述】:
我正在尝试运行一个 SQL 查询以从数据库中找出每个错误代码的计数。我有两张桌子
- sw_sms_events 存储发送的事务 ID 和短信。
- sw_events 其中事务 ID 和错误原因,如果失败则存储,否则原因始终为“成功发送 TariffText”。
错误总数:- select count(*) from sw_sms_events where sms_text like '%Welkom in het buitenland%'
每个错误原因的错误总数:-
select distinct count(*) over (partition by b.reason) , b.reason
from sw_sms_events a, sw_events b
where a.transaction_id= b.transaction_id
and a.sms_text like '%Welkom in het buitenland%'
and b.reason !='Successfully Sent TariffText'
order by (count(*) over (partition by b.reason)) desc
通常,这些查询会给出相同的结果,即单个错误计数的总和 = 错误总数。但在最坏的情况下,同一事务被多次重试,结果并不相同。即我们在表中有多个具有相同事务 ID 的行。
以下是最坏情况下的结果之一:
Name 24-07-2015
Total Number of SMSWelcome Sent 156788
Total Number of Error SMSWelcome 1738
Total Number of SMSWelcome Sent with null Tariffs 286
Error Reason Error Count
Unknown error received :BEA-380000 , ErrorMessage : BSL-99999 1829
Backend system not available , ErrorMessage : BSL-50002 641
Remote Error 527
NativeQuery.executeQuery failed , ErrorMessage : BSL-11009 41
This service is available only for active products , ErrorMessage : BSL-15024 30
Unknown error received :BEA-382556 , ErrorMessage : BSL-99999 18
Customer information: Not retrieved. This action cannot continue without customer information. Please try later or contact your system administrator. , ErrorMessage : BSL-10004 13
OMS login failure: Problem in OMS UAMS login - Nested Exception/Error: java.net.ConnectException: Tried all: '1' addresses, but could not connect over HTTP to server: '195.233.102.177', port: '40123' , 12
t3://195.233.102.171:30101: Bootstrap to: 195.233.102.171/195.233.102.171:30101' over: 't3' got an error or timed out , ErrorMessage : BSL-11000 5
getTariffsAndAddOns, status: Failure , ErrorCode : An internal error occured , ErrorMessage : BSL-14005 3
Authorization failed of dealer market restrictions , ErrorMessage : BSL-50005 2
com.amdocs.cih.exception.InvalidUsageException: The input parameter AssignedProductRef is invalid. , ErrorMessage : BSL-10004 1
我的问题是我如何修改当前的 sql,使得当我们遇到同一事务在表中多次出现的情况时,错误的总计数应始终等于单个错误计数的总和
【问题讨论】:
-
问题在最后更新