select phone,count(order_id) as c from table_record
group by phone
order by c desc

SELECT
CASE
WHEN (age >= 10 AND age <= 20) THEN
'10-20'
WHEN (age >= 21 AND age <= 30) THEN
'21-30'
ELSE
'30-'
END 'eag_layer',
count(*) emps
FROM
address_book
GROUP BY
CASE
WHEN (age >= 10 AND age <= 20) THEN
'10-20'
WHEN (age >= 21 AND age <= 30) THEN
'21-30'
ELSE
'30-'
END
ORDER BY
1;

SELECT '10-20' 年龄段, COUNT(*) 人数
FROM [Table]
WHERE [年龄] BETWEEN 10 AND 20
UNION ALL
SELECT '21-30' 年龄段, COUNT(*) 人数
FROM [Table]
WHERE [年龄] BETWEEN 21 AND 30
UNION ALL
SELECT '31' 年龄段, COUNT(*) 人数
FROM [Table]
WHERE [年龄] > 30

select case when [年龄] BETWEEN 10 AND 20 then '10-20'
when [年龄] BETWEEN 20 AND 30 then '20-30'
when [年龄] > 30 then '30以上' end as '年龄段',
count(*) as '人数' FROM [Table]

先将年龄除10取整

select floor(年龄/10) as age from 表
1
再根据年龄整数分组统计

select age ,count(age) from
(
select floor(年龄/10) as age from 表
)
group by age

这样基本效果就出来了,达到楼主的要求就要加如函数计算了

sql语法

select convert(varchar,age*10)+'--'+convert(varchar,(age+1)*10) ,count(age) from
(
select floor(年龄/10) as age from 表
)
group by age

https://stackoverflow.com/questions/10423781/sql-data-range-min-max-category的更多相关文章

  1. https://stackoverflow.com/questions/51751426/failed-to-run-the-da-platform-trial-vm

    https://stackoverflow.com/questions/51751426/failed-to-run-the-da-platform-trial-vm {  "annotat ...

  2. https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error

    https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error 0down votefavo ...

  3. https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflection

    https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflectio ...

  4. 国外的非常好的开发提问回答的网站https://stackoverflow.com/questions

    https://stackoverflow.com/questions 可以进行搜索,在页面顶部,有搜索输入框

  5. https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth

    https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth p.p ...

  6. LINQ to SQL Count/Sum/Min/Max/Avg Join

    public class Linq { MXSICEDataContext Db = new MXSICEDataContext(); // LINQ to SQL // Count/Sum/Min/ ...

  7. JS中Float类型加减乘除 修复 JQ 操作 radio、checkbox 、select LINQ to SQL:Where、Select/Distinct LINQ to SQL Count/Sum/Min/Max/Avg Join

    JS中Float类型加减乘除 修复   MXS&Vincene  ─╄OvЁ  &0000027─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄Ov ...

  8. IIS Express 域认证问题(https://stackoverflow.com/questions/4762538/iis-express-windows-authentication)

    option-1: edit \My Documents\IISExpress\config\applicationhost.config file and enable windowsAuthent ...

  9. del|append()|insert()|pop()|remove()|sort()|sorted|reverse()|len()|range()|min()|max()|sum()|[:]|区分两种列表复制|

    fruit = ['apple','banana','peach'] print fruit[0],fruit[-1] fruit_1 =[] fruit_1.append('orange') pri ...

随机推荐

  1. centos7 安装curl-7.51.0

    curl简介curl是一个广泛使用的用来上传和下载的命令行工具,当然严格来讲,它还可以有别的用途.对于测试来讲,它是Web相关测试非常实用的工具,包括debugging,使用起来非常方便.而且另一方面 ...

  2. hive set 常用参数汇总

    1. set hive.auto.convert.join = true; mapJoin的主要意思就是,当链接的两个表是一个比较小的表和一个特别大的表的时候,我们把比较小的table直接放到内存中去 ...

  3. eclipse工具中使用Data Source Explorer连接数据库(MySQL)

    1.进入Eclipse工具,打开Data Source Explorer.Window==>Show View==>Data Source Explorer(注:如果找不到请选择Other ...

  4. 原创科幻短篇《Bug》

    这回不是纯科幻,夹了点玄幻. 以下正文: 大一的时候,李双休谈了个女朋友,俩人学校相距不远,周末约一起看电影.那是李双休第一次自己坐公交,坐反了,绕城一周,电影开始后一个小时才到,就赶上看了个片尾彩蛋 ...

  5. blender show normals

    https://blenderartists.org/forum/showthread.php?193096-Blender-2-5-how-to-show-normals-in-viewport

  6. why deep learning works

    https://medium.com/towards-data-science/deep-learning-for-object-detection-a-comprehensive-review-73 ...

  7. Super expression must either be null or a function, not undefined

    按照之前买的用JavaScript开发移动应用的例子来编写的,然后报了这个错.我的头部声明是这样的 var React = require('react-native'); var { Text, V ...

  8. shell脚本自动登录服务器

    #!/bin/sh function trapper(){ trap 'exit 1' EXIT QUIT; } serverArr=( guard-boot-001,10.1.17.12 guard ...

  9. 字节输入流:io包中的InputStream为所有字节输入流的父类。

    字节输入流:io包中的InputStream为所有字节输入流的父类. Int read();读入一个字节(每次一个): 可先使用new  byte[]=数组,调用read(byte[] b) read ...

  10. [踩坑日记]spring mvc

    目录 找不到javax.servlet.ServletException的类文件 idea 清除tomcat缓存 IOException parsing XML document from Servl ...