Oracle SQL Discrepancy: COUNT(*) vs Actual Result Set -


i have application keeps track when file being “attempted” move 1 server another, when has “succeeded” or “failed.” "attempt" should paired "success" or "failure." however, there 63 “orphaned” attempts, meaning there have been attempts without success or failure reported. first query shows got 63 number begin with: take count of of attempts , subtract successes , failures-

select (     select count(*) e_table     e_comment '%attempt%'     , e_date >= '23-may-2016'     , e_date <= '26-may-2016' ) - (     select     (         select count(*) e_table         e_comment '%success%'         , e_date >= '23-may-2016'         , e_date <= '26-may-2016'     )     +     (         select count(*) e_table         e_comment '%failure%'         , e_date >= '23-may-2016'         , e_date <= '26-may-2016'     ) dual ) orphaned_attempts dual; 

so second query specific e_id of 63 attempts follows:

select * (     select e_id e_table     e_comment '%attempt%'     , e_date >= '23-may-2016'     , e_date <= '26-may-2016' ) minus (     select e_id e_table     e_comment '%success%'     , e_date >= '23-may-2016'     , e_date <= '26-may-2016' ) minus (     select e_id e_table     e_comment '%failure%'     , e_date >= '23-may-2016'     , e_date <= '26-may-2016' ); 

what need (and expect based on first query’s result set) have 63-row result set 1 column containing e_id of orphaned attempts. instead, getting 49 rows second query. appreciated.

select     a.e_id,     coalesce(attempts, 0) attempts,     coalesce(successes, 0) successes,     coalesce(failures, 0) failures     (         select e_id, count(*) attempts e_table         e_comment '%attempt%' , e_date between '23-may-2016' , '26-may-2016'         group e_id     )     full outer join     (         select e_id, count(*) successes e_table         e_comment '%success%' , e_date between '23-may-2016' , '26-may-2016'         group e_id     ) s         on s.e_id = a.e_id     full outer join     (         select e_id, count(*) failures e_table         e_comment '%failure%' , e_date between '23-may-2016' , '26-may-2016'         group e_id     ) f         on f.e_id = coalesce(a.e_id, s.e_id)     coalesce(attempts, 0) <> coalesce(successes, 0) + coalesce(failures, 0) 

i changed full outer joins can verify there no successes and/or failures without matching attempt. should let find e_ids something's going wrong in logging. should easier start dealing finer numbers , not listings of id values.

others have pointed out potential multiple attempts on same id conceivable success , failure both recorded same way in kind of retry scenario? don't know full comments like. possible explanation, can single comment can contain more 1 of words "attempt", "success", "failure"?

here's else consider: sure success , failures events fall within same date window? in other words, there delay following attempt? might not have long if happens around midnight. may want widen success , failure ranges enough compensate (and change left outer joins.)

note: condition in where clause has been modified allow multiple attempts (as noted in comments) , looks balance in number of attempts vs. successes , failures.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo