繁体   English   中英

Oracle SQL-将两个查询的两个结果合并为一个

[英]Oracle SQL - Combine Two Results from Two Queries Into One

我有两个独立的查询:

查询1

select '2013-03-03' As "Week_Of",
count(player_id) as cohort_size
from player
where trunc(create_dtime) > To_Date('2013-Mar-03','yyyy-mon-dd')-7
and trunc(create_dtime) <= To_Date('2013-Mar-03','yyyy-mon-dd')
and world_flag != '1'
;

哪个输出:

Week_of      Cohort_size
2013-03-03      18183

查询2

select '2013-03-03' As "Week_Of", 
count(player_id) as Day_0_Ret
from player
where trunc(init_dtime)-trunc(create_dtime) >= 0
and trunc(create_dtime) > To_Date('2013-Mar-03','yyyy-mon-dd')-7
and trunc(create_dtime) <= To_Date('2013-Mar-03','yyyy-mon-dd')
and world_flag != '1'
;

哪些输出:

Week_of      Day_0_Ret
2013-03-03      15684

我想将这两个查询放在一起,所以我有一个查询输出:

Week_of         Cohort_Size     Day_0_Ret
2013-03-03       18183              15684

使用case语句进行条件计数:

select '2013-03-03' As "Week_Of",
count(player_id) as cohort_size ,
count(case 
        when trunc(init_dtime)-trunc(create_dtime) >= 0 
        then player_id 
      end) as Day_0_Ret
from player
where trunc(create_dtime) > To_Date('2013-Mar-03','yyyy-mon-dd')-7
and trunc(create_dtime) <= To_Date('2013-Mar-03','yyyy-mon-dd')
and world_flag != '1'
;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM