https://*.com/questions/10423781/sql-data-range-min-max-category

时间:2022-04-23 06:13:30

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://*.com/questions/10423781/sql-data-range-min-max-category的更多相关文章

  1. https&colon;&sol;&sol;*&period;com&sol;questions&sol;51751426&sol;failed-to-run-the-da-platform-trial-vm

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

  2. https&colon;&sol;&sol;*&period;com&sol;questions&sol;40949967&sol;running-storm-from-intellij-nimbus-error

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

  3. https&colon;&sol;&sol;*&period;com&sol;questions&sol;16130292&sol;java-lang-outofmemoryerror-permgen-space-java-reflection

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

  4. 国外的非常好的开发提问回答的网站https&colon;&sol;&sol;*&period;com&sol;questions

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

  5. https&colon;&sol;&sol;*&period;com&sol;questions&sol;3232943&sol;update-value-of-a-nested-dictionary-of-varying-depth

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

  6. LINQ to SQL Count&sol;Sum&sol;Min&sol;Max&sol;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&colon;Where、Select&sol;Distinct LINQ to SQL Count&sol;Sum&sol;Min&sol;Max&sol;Avg Join

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

  8. IIS Express 域认证问题&lpar;https&colon;&sol;&sol;*&period;com&sol;questions&sol;4762538&sol;iis-express-windows-authentication&rpar;

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

  9. del&vert;append&lpar;&rpar;&vert;insert&lpar;&rpar;&vert;pop&lpar;&rpar;&vert;remove&lpar;&rpar;&vert;sort&lpar;&rpar;&vert;sorted&vert;reverse&lpar;&rpar;&vert;len&lpar;&rpar;&vert;range&lpar;&rpar;&vert;min&lpar;&rpar;&vert;max&lpar;&rpar;&vert;sum&lpar;&rpar;&vert;&lbrack;&colon;&rsqb;&vert;区分两种列表复制&vert;

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

随机推荐

  1. thinkphp加载第三方类库

    http://www.cnblogs.com/jiqing9006/p/5041389.html

  2. Silverlight项目笔记5&colon;Oracle归档模式引起的异常&amp&semi;&amp&semi;表格控件绑定按钮

    1.Oracle归档模式产生日志文件引起数据库异常 连接数据库失败,提示监听错误,各种检查监听配置文件,删除再添加监听,无果. sqlplus下重启数据库数据库依然无果,期间碰到多个错误提示: ORA ...

  3. &lbrack;老老实实学WCF&rsqb; 第一篇 Hello WCF

    老老实实学WCF  第一篇 Hello WCF WCF(Windows Communication Foundation)是微软公司推出的面向服务技术的集大成者,涵盖继承了其之前发布的所有的分布式应用 ...

  4. 30个HTML5学习资源

    早在几个星期前,Adobe就发布了Dreamweaver CS5 HTML5 Pack的预览版下载.众所周知,HTML5在互联网领域掀起了一场大论战,并让Adobe的日子很难熬.HTML5致力于为前端 ...

  5. char &ast;s &equals; getpass&lpar;&rpar;屏幕不回显示 &comma;返回输入的字符

    char *s = getpass(“please input you name:”)屏幕不回显示 ,返回输入的字符

  6. 阐述linux IPC(五岁以下儿童):system V共享内存

    [版权声明:尊重原创.转载请保留源:blog.csdn.net/shallnet 要么 .../gentleliu,文章学习交流,不用于商业用途]         system V共享内存和posix ...

  7. 使用DataFlow表达ControlFlow的一些思考

    一.控制流 从接触面向过程语言开始,使用控制流编程的概念已是司空见惯. if (condition) { // do something } else { // do something else } ...

  8. SpringMVC 使用JSR-303进行校验 &commat;Valid

    注意:1 public String save(@ModelAttribute("house") @Valid House entity, BindingResult result ...

  9. &lbrack;转&rsqb;urllib模块urlretrieve方法

    直接将远程数据下载到本地 info: urllib.urlretrieve(url[, filename[, reporthook[, data]]])参数说明:url:外部或者本地urlfilena ...

  10. spring web应用

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...