我在下面有这个查询:
Select
count(CDT) as Actions
From Player_Tapjoy
Where
Trunc(CDT) >= To_Date('2012-sep-01','yyyy-mon-dd')
And Trunc(CDT) < To_Date('2012-sep-12','yyyy-mon-dd')
Union All
Select
Count(CDT) As Actions
From Player_aux_pt
Where
Site = 'AppCircle' And
Trunc(CDT) >= To_Date('2012-sep-01','yyyy-mon-dd')
And Trunc(CDT) < To_Date('2012-sep-12','yyyy-mon-dd')
这个输出给了我两行,每个选择函数一行。如何组合这些以获得两个选择函数的总和?最重要的是,我如何按CDT(日期)对其进行分组?
答案 0 :(得分:1)
我认为你正在寻找类似的东西,按日期分组:
select cdt, sum(actions) as actions_sum
from ( select trunc(cdt) as cdt, count(cdt) as actions
from player_tapjoy
where trunc(cdt) >= to_date('2012-sep-01', 'yyyy-mon-dd') and
trunc(cdt) < to_date('2012-sep-12', 'yyyy-mon-dd')
group by trunc(cdt)
union all
select trunc(cdt) as cdt, count(cdt) as actions
from player_aux_pt
where site = 'AppCircle' and
trunc(cdt) >= to_date('2012-sep-01', 'yyyy-mon-dd') and
trunc(cdt) < to_date('2012-sep-12', 'yyyy-mon-dd')
group by trunc(cdt))
group by cdt