oracle - Displaying all the lines of a query even its a null value -


select a.hour,a.actual_count,b.expected_count  (     select extract(hour report_inquiry_dt) hour ,count(1) actual_count     sbe_rpt_inq_output     to_char(report_inquiry_dt,'yyyy-mm-dd')='2015-04-19'      group extract(hour report_inquiry_dt)     order extract(hour report_inquiry_dt) ) left outer join (     select extract(hour report_inquiry_dt) hour,         round(count(1)/4) expected_count     (         select *          sbe_rpt_inq_output         to_char(report_inquiry_dt,'yyyy-mm-dd')=to_char((select sysdate -7 dual),'yyyy-mm-dd')         union         select *          sbe_rpt_inq_output         to_char(report_inquiry_dt,'yyyy-mm-dd')=to_char((select sysdate -14 dual),'yyyy-mm-dd')         union         select *          sbe_rpt_inq_output         to_char(report_inquiry_dt,'yyyy-mm-dd')=to_char((select sysdate -21 dual),'yyyy-mm-dd')         union         select *          sbe_rpt_inq_output         to_char(report_inquiry_dt,'yyyy-mm-dd')=to_char((select sysdate -34 dual),'yyyy-mm-dd')      )     group extract(hour a.report_inquiry_dt)     order extract(hour a.report_inquiry_dt)  ) b on a.hour=b.hour; 

and answer getting.

hour actual_count expect_count 7    2            0 

i want display hourly transaction if not null.

i see strange in query, but, in absence of requirement description, can assume it's want extract exception you're not getting rows hours missing values.

so missing values try query:

with hours (         select rownum-1 hour         dual         connect rownum <= 24     ) select h.hour, count(*) hours h     left join (             select *             sbe_rpt_inq_output t              t.report_inquiry_dt >= (trunc(sysdate)-(34))                 , t.report_inquiry_dt < trunc(sysdate)         ) t         on (             mod(trunc(t.report_inquiry_dt)-trunc(sysdate)) in (7,14,21,34)             , hour = extract(hour report_inquiry_dt)         ) group h.hour 

anyway it's hard understand why don't want match occurrences of days ago between 0 6, 8 13, 15 20 , 22 33.

update

to count of hourly occurrences of current day , average hourly count past 4 weeks use other query

with hours (         select rn, mod(extract(hour systimestamp) + 24 - rn,24) hour         (                 select rownum-1 rn                 dual                 connect rownum <= 24             )     ) select sysdate, hour hour, nvl(avg,0) avg, nvl(current_count,0) current_count hours h     left join (             select extract(hour report_inquiry_dt) hour,                  count(case when t.report_inquiry_dt < trunc(sysdate) 1 end)/(4*7) avg,                 count(case when t.report_inquiry_dt >= trunc(sysdate) 1 end) current_count             sbe_rpt_inq_output t              t.report_inquiry_dt >= (trunc(sysdate)-(4*7))             group extract(hour report_inquiry_dt)         ) t using (hour) order rn 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -