Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.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_Oracle Sqldeveloper - Fatal编程技术网

SQL——将两个结果相除

SQL——将两个结果相除,sql,oracle,oracle-sqldeveloper,Sql,Oracle,Oracle Sqldeveloper,我在下面有两个查询,都是从同一张玩家桌上输入的。我想用查询1除以查询2得到一个相关的百分比。我对更详细的SQL查询以及在论坛上发布信息相对较新,但如果您对如何结合这些信息以获得相关百分比结果有任何建议,请告诉我 1. 2. 你可以说 select sysdate, count((init_dtime)) / sum((Create_Dtime)) * 100 as percentage from Player p where Trunc(Init_Dtime) > Tr

我在下面有两个查询,都是从同一张玩家桌上输入的。我想用查询1除以查询2得到一个相关的百分比。我对更详细的SQL查询以及在论坛上发布信息相对较新,但如果您对如何结合这些信息以获得相关百分比结果有任何建议,请告诉我

1. 2. 你可以说

select sysdate,
       count((init_dtime)) / sum((Create_Dtime)) * 100 as percentage
  from Player p
 where Trunc(Init_Dtime) > Trunc(Sysdate) - 7 
   and Trunc(Create_Dtime) >= To_Date('2012-mar-01','yyyy-mon-dd')
   and trunc(create_dtime) < to_date('2015-sep-9','yyyy-mon-dd')
   order by percentage asc
编辑: 如果where条款不同:

select sysdate, 
       (
           (select count((init_dtime))
             from player p
            where trunc(Init_Dtime) > trunc(Sysdate) - 7 
              and Trunc(Create_Dtime) >= To_Date('2012-mar-01','yyyy-mon-dd')
              and trunc(create_dtime) < to_date('2015-sep-9','yyyy-mon-dd'))
            / 
           (select count((Create_Dtime))
              from player P
             where trunc(Create_Dtime) >= To_Date('2012-mar-01','yyyy-mon-dd')
               and trunc(Create_Dtime) < To_Date('2015-sep-9','yyyy-mon-dd'))
       ) * 100 as percentage
from dual

他们有不同的WHERE从句,迈克-没错。。虽然所有的东西都是从玩家表中输入的,但这两个查询是根据不同的where条件构建的。我可以手动地将这两个查询分开,但其中的乐趣何在!?我想我应该开始使用这个论坛来扩展我的自动化功能。@MichaelBerkowski没有注意到这一点。将更新答案。Nivas-感谢您的快速回复。但它说SQL命令没有正确结束。我试着在末尾加一个括号,但我得到的是相同的区域。有什么东西不见了吗?可能是分组,因为当我试图单独运行分子时,它说它需要包含一个groupby函数。再次感谢您的帮助@斯图亚夫:我刚刚看到一件事:当你说sumCountinit\u dtime时,你想做什么?你已经有了两个答案,这让我很惊讶,因为我不理解这个问题。你想要一个号码还是每个玩家一个号码?如果答案不是您想要的,那么请尝试发布玩家表中的原始数据集、预期结果集以及转换的解释。@Rob van Wijk-很抱歉不够清晰。我正试图得到所有球员的总数。玩家表中有很多列,但这里重要的是:1创建时间是特定玩家创建帐户的日期,2初始时间是特定玩家登录的最新日期。对于某个日期范围内的所有玩家,我想将查询1过去7天内所有活动玩家(2012年3月1日之后创建帐户的用户)除以查询2在2012年3月1日之后创建帐户的用户总数
select sysdate,
       count((init_dtime)) / sum((Create_Dtime)) * 100 as percentage
  from Player p
 where Trunc(Init_Dtime) > Trunc(Sysdate) - 7 
   and Trunc(Create_Dtime) >= To_Date('2012-mar-01','yyyy-mon-dd')
   and trunc(create_dtime) < to_date('2015-sep-9','yyyy-mon-dd')
   order by percentage asc
select player_id, count(…)
  from …
 where …
group by player_id
select sysdate, 
       (
           (select count((init_dtime))
             from player p
            where trunc(Init_Dtime) > trunc(Sysdate) - 7 
              and Trunc(Create_Dtime) >= To_Date('2012-mar-01','yyyy-mon-dd')
              and trunc(create_dtime) < to_date('2015-sep-9','yyyy-mon-dd'))
            / 
           (select count((Create_Dtime))
              from player P
             where trunc(Create_Dtime) >= To_Date('2012-mar-01','yyyy-mon-dd')
               and trunc(Create_Dtime) < To_Date('2015-sep-9','yyyy-mon-dd'))
       ) * 100 as percentage
from dual