Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL——填写没有结果的日期_Sql_Oracle - Fatal编程技术网

SQL——填写没有结果的日期

SQL——填写没有结果的日期,sql,oracle,Sql,Oracle,我有一个疑问: Select Trunc(Create_Dtime),Count(Trunc(Create_Dtime)) as Day_0 From Player Group By Trunc(Create_Dtime) Order By Trunc(Create_Dtime) Asc 它会返回日期,但如果某个日期没有任何结果,则会跳过该日期。我想填写从8-05-12到现在的所有日期,如果这些日期没有任何值,只需在结果中填入0即可 根据要创建行的方式,您可以创建一个或使用Oracle语法动态

我有一个疑问:

Select Trunc(Create_Dtime),Count(Trunc(Create_Dtime)) as Day_0 From Player
Group By Trunc(Create_Dtime)
Order By Trunc(Create_Dtime) Asc

它会返回日期,但如果某个日期没有任何结果,则会跳过该日期。我想填写从8-05-12到现在的所有日期,如果这些日期没有任何值,只需在结果中填入0即可

根据要创建行的方式,您可以创建一个或使用Oracle语法动态生成行

或者,刚刚注意到你的约会限制:

with the_dates as (
  select to_date('07-05-2012','dd-mm-yyyy') + level as the_date
    from dual
 connect by level <= trunc(to_date('07-05-2012','dd-mm-yyyy') - sysdate)
         )
 select td.the_date, count(trunc(p.create_dtime))
   from the_dates td
   left outer join player p
     on td.the_date = trunc(p.create_dtime)
  group by td.the_date
  order by td.the_date

对于所有这些,我建议在您的玩家表上的trunccreate\u dtime上创建一个索引。

Ben,感谢您检查这些,但上面的任何一项都不起作用。我不确定您所说的索引是什么意思,我的SQL级别是非常新手。你能不能再扩展一点?什么不起作用?对于索引,我只能建议你或谷歌一点;它们基本上是访问表的一种快速方式,但有许多复杂之处。
with the_dates as (
  select max(trunc(Create_Dtime)) as max_date
       , min(trunc(Create_Dtime)) as min_date
    from player 
         )
select c.the_date, count(trunc(p.Create_Dtime))
  from calender c
  join the_dates td
    on c.the_date between td.min_date and td.max_date
  left outer join join player p
    on c.the_date = trunc(p.Create_Dtime)
 group by c.the_date
 order by c.the_date
with the_dates as (
  select to_date('07-05-2012','dd-mm-yyyy') + level as the_date
    from dual
 connect by level <= trunc(to_date('07-05-2012','dd-mm-yyyy') - sysdate)
         )
 select td.the_date, count(trunc(p.create_dtime))
   from the_dates td
   left outer join player p
     on td.the_date = trunc(p.create_dtime)
  group by td.the_date
  order by td.the_date