2

我在下面有这个查询:

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(日期)对其进行分组?

4

1 回答 1

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
于 2012-09-13T18:36:22.850 回答