怎样进行分组?

taotaoqi 2006-12-22 05:22:03
怎样进行分组?

有100个数字,从1到100
按照 1-10 ,11-20, 21-30,31-40,41-50 。。。分组,计算出和

分组 求和
1-10 :51
11-60 :203
61-90 :44
>90 :1444
...全文
262 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sasacat 2006-12-25
  • 打赏
  • 举报
回复
晕,怎么今天老写错字

select xx,count(*)
from (select (case when (age>= 0 and age<= 10) then '0-10'
when (age>= 11 and age<= 60) then '11-60'
when (age>= 61 and age<= 90) then '60-90'
else '>90' end) as xx from tab
)
group by xx
sasacat 2006-12-25
  • 打赏
  • 举报
回复
select xx,count(*)
from (select (case when (age>= 0 and age<= 10) then '0-10'
when (age>= 3 and age< 7) then '11-20'
..........
else '>90' end) as xx from tab
)
group by xx
yryeyrye 2006-12-25
  • 打赏
  • 举报
回复
select '<10' age,count(*),sum(...from t where age <10 union all
select '11-60' age, count(*),sum(...from t where age between 11 and 60 union all
select '60-90' age, count(*),sum(...from t where age between 60 and 90 union all
select '>90' age, count(*), sum(...from t where age >90
taotaoqi 2006-12-25
  • 打赏
  • 举报
回复
union all 查询很慢
山林73 2006-12-25
  • 打赏
  • 举报
回复
select '<10' age,count(*),sum(... from t where age <10 union all
select '11-60'age,count(*),sum(... from t where age >= 11 and age< 60 union all
select '60-90'age,count(*),sum(... from t where age between 60 and 90 union all
select '>90' age,count(*),sum(... from t where age >90
taotaoqi 2006-12-25
  • 打赏
  • 举报
回复
字段age 的值 从1 到100,按不同年龄组分组.
如:
<10岁
11-60岁
60-90岁
>90岁

计算出不同年龄组的人数
Punk_Dog 2006-12-25
  • 打赏
  • 举报
回复
不明白楼主是什么意思
Quebradawill 2006-12-25
  • 打赏
  • 举报
回复
分组用group by子句吧。
baojianjun 2006-12-24
  • 打赏
  • 举报
回复
你 说的要求和你举的例子不一样
 到底要求是如何的

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧