我有以下查询
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
答案 0 :(得分: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
答案 1 :(得分:0)
不需要大字段的GroupBy ...只需使用下面的简单查询.. [你的sql] 分组1 按Device_Model排序
这意味着您在选择查询中按字段1进行分组..或者尝试给出别名... 按别名分组 按device_model排序