0

私はこのサイトでこのクエリを見つけました(少し変更しましたが)、それは問題なく動作します。ただし、結果セットには、count(*)が0の範囲間隔が表示されません。左関節と一緒にNVL関数を使用しようとしましたが、機能しませんでした。何か案は?(以下のクエリを参照)

ありがとう

select
    count(*) "# PRs Created",to_char(date_created, 'yyyy-mm-dd') as "Date Created",
    to_char(date_created, 'hh24') || ':00:00 - ' || to_char(date_created + 1/24, 'hh24') || ':00:00' RANGE 
    FROM pr
    where date_created between to_date(SYSDATE - 1000)and to_date(SYSDATE)
    and 1 * to_char(date_created, 'hh24') between 0 and 24
    group by to_char(date_created, 'hh24'), to_char(date_created + 1/24, 'hh24'),to_char(date_created, 'yyyy-mm-dd')
    order by to_char(date_created, 'yyyy-mm-dd'), RANGE  desc
4

1 に答える 1

0

You won't get a zero entry for non-existent intervals because there's nothing to count. To get this to work, you'll need to outer join to a table of date times:

with dates as (
  select trunc(sysdate)-1000 + (rownum-1)/24 dt
  from   dual
  connect by level <= 1000 * 24
)
select dates.dt, count(pr.date_created) from pr, dates
where  trunc(pr.date_created (+), 'hh24')= dates.dt
group  by dates.dt;

The with clause creates a "table" of data containing every hour from sysdate-1000 and today (the condition in your query). You need to outer join pr to this to see a row for intervals that have no entry in pr.

于 2013-01-29T14:21:53.613 に答える