https://stackoverflow.com/questions/10423781/sql-data-range-min-max-category
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的更多相关文章
- 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 ...
- https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error
https://stackoverflow.com/questions/40949967/running-storm-from-intellij-nimbus-error 0down votefavo ...
- https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflection
https://stackoverflow.com/questions/16130292/java-lang-outofmemoryerror-permgen-space-java-reflectio ...
- 国外的非常好的开发提问回答的网站https://stackoverflow.com/questions
https://stackoverflow.com/questions 可以进行搜索,在页面顶部,有搜索输入框
- 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 ...
- LINQ to SQL Count/Sum/Min/Max/Avg Join
public class Linq { MXSICEDataContext Db = new MXSICEDataContext(); // LINQ to SQL // Count/Sum/Min/ ...
- 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 ...
- IIS Express 域认证问题(https://stackoverflow.com/questions/4762538/iis-express-windows-authentication)
option-1: edit \My Documents\IISExpress\config\applicationhost.config file and enable windowsAuthent ...
- 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 ...
随机推荐
- P Invoke struct结构
一.获取Struct CHCNetSDK.NET_DVR_PTZPOS pos = new CameraTest.CHCNetSDK.NET_DVR_PTZPOS(); int size = Mars ...
- 如何在IIS上发布网站 在阿里云服务器windows server2012r iis上部署.net网站
如何在IIS上发布网站 本片博客记录一下怎么用IIS发布一个网站,以我自己电脑上一个已经开发完成的网站为例: 1.打开项目 这是我电脑上的一个项目,现在我记录一下将这个项目发布到iis上的整个过程 ...
- Atitit uke公司简介与基本制度建设草案v11 r66 .docx
Atitit uke公司简介与基本制度建设草案v11 r66 .docx Uke org prj Author撰写人: 作者:: 绰号:老哇的爪子claw of Eagle 偶像破坏者Iconocl ...
- 【基础篇】elasticsearch之索引模板Template[转]
一,模板简述:template大致分成setting和mappings两部分:索引可使用预定义的模板进行创建,这个模板称作Index templates.模板设置包括settings和mappings ...
- Asp.Net WebApi上传图片
webapi using System; using System.Collections; using System.Collections.Generic; using System.Diagno ...
- Replication基础(六) 复制中的三个线程(IO/SQL/Dump)
Reference: https://blog.csdn.net/sun_ashe/article/details/82181811?utm_source=blogxgwz1 简介在MySQL复制技 ...
- Java线程生命周期
当你需要使用Java线程在多线程环境下进行编程时,理解Java的线程周期与线程的状态是非常重要的.通过实现Runnale接口或者继承Thread类,我们可以创建线程,为了启动一个线程,我们需要创建一个 ...
- oneNote2016代码高亮插件
下载地址:https://github.com/elvirbrk/NoteHighlight2016/releases 安装插件前必须安装oneNote笔记. NoteHighlight插件有32位和 ...
- python3 使用ldap3来作为django认证后台
首先先使用ldap3测试ldap服务是否正常 我们先要拿到dc的数据,以及连接ldap的密码,还有搜索的字段(search_filter), 一般来说search_filter 这个是从负责ldap运 ...
- Redis 数据结构的实现
Redis 数据结构的实现 先看个对照关系: Redis数据结构 实现一 实现二 string 整数(如果value能够表示为整数) 字符串 hash 压缩列表(只包含少量键值对, 并且每个键值对的键 ...