17,086
社区成员
发帖
与我相关
我的任务
分享
select decode(yy.grade,'A','2~5','B','6~8','C','large 8') as gradeClass,
count(yy.grade) as gradeCount
from (
select zz.userid,
case when (zz.price)>=2 and (zz.price)<=5
then 'A'
when (zz.price)>=6 and (zz.price)<=8
then 'B'
when zz.price > 8
then 'C'
end as grade
from (
select tt.userid,
sum(tt.price) as price
from tablename tt
group by tt.userid
)zz
)yy
group by yy.grade;