1つのSQLクエリを実行して、データベースからエラーコードごとのカウントを見つけようとしています。私は2つのテーブルを持っています
合計エラー数:-sw_sms_eventsからcount(*)を選択します。ここで、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を持つテーブルに複数の行があります。
以下は、最悪の場合の結果の1つです。
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を変更する方法です。
なぜ分析クエリを使用しているのかよくわかりません。単純group by
なだけでは十分ではありませんか?
select count(*), 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'
group by b.reason
order by count(*) desc
同じトランザクションIDを持つテーブルに複数の行があると言う場合、それはsw_events
テーブルのみ、またはテーブルsw_sms_events
とsw_events
テーブルの両方を意味しますか?
その場合、同じですべてのrawに対してデカルト積を実行しているため、イベントは複数回カウントされますtransaction_id
。より厳密な結合句を使用する必要があります。
次のような(かなり醜い)こともできます:
select count(distinct b.ROWID), 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'
group by b.reason
order by count(distinct b.ROWID) desc
各イベントが1回だけカウントされるようにします。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加