0

我有以下查询

Select 
case upper(device_model)
        when 'IPHONE' then 'iOS - iPhone'
        when 'IPAD' then 'iOS - iPad'
        when 'IPOD TOUCH' then 'iOS - iPod Touch'
        Else 'Android'
        End As Device_Model,
count(create_dtime) as Installs_Oct17_Oct30
From Player
Where Create_Dtime >= To_Date('2012-Oct-17','yyyy-mon-dd')
And Create_Dtime <= To_Date('2012-Oct-30','yyyy-mon-dd')
Group By Device_Model
Order By Device_Model

这会吐出多行显示为“Android”的结果....我希望只有 4 个结果行,每个案例一个....所以结果如下:

Device_Model     Installs_Oct17_Oct30
Android            987
iOS - iPad         12003
iOS - iPhone       8563
iOS- iPod Touch    3482
4

2 回答 2

4

您按字段 device_model 分组,而不是您的表达式:

Select 
case upper(device_model)
    when 'IPHONE' then 'iOS - iPhone'
    when 'IPAD' then 'iOS - iPad'
    when 'IPOD TOUCH' then 'iOS - iPod Touch'
    Else 'Android'
    End As Device_Model,
count(create_dtime) as Installs_Oct17_Oct30
From Player
Where Create_Dtime >= To_Date('2012-Oct-17','yyyy-mon-dd')
And Create_Dtime <= To_Date('2012-Oct-30','yyyy-mon-dd')
Group By
case upper(device_model)
    when 'IPHONE' then 'iOS - iPhone'
    when 'IPAD' then 'iOS - iPad'
    when 'IPOD TOUCH' then 'iOS - iPod Touch'
    Else 'Android'
    End
Order By Device_Model
于 2012-10-31T22:59:35.823 回答
0

无需按大字段分组...只需使用下面的简单查询.. [您的 sql] Group By 1 Order By Device_Model

这意味着您在选择查询中按字段 1 进行分组。或者尝试给出别名。按 device_model 的别名顺序分组

于 2013-04-30T18:23:59.887 回答