mysql如何统计每个专业分数段的人数
发表于:2024-11-11 作者:千家信息网编辑
千家信息网最后更新 2024年11月11日,mysql如何统计每个专业分数段的人数的呢?下面由小编给大家详细的介绍;1.我的表结构student_info| id |name |profession|score||--|--|--|--||id
千家信息网最后更新 2024年11月11日mysql如何统计每个专业分数段的人数
mysql如何统计每个专业分数段的人数的呢?下面由小编给大家详细的介绍;
1.我的表结构
student_info| id |name |profession|score||--|--|--|--||id|姓名|分数|专业|
2.按分数段统计
400到500人数,300到400人数
selectcount(case when score between 400 and 500 then 1 end) as 400到500,count(case when score between 300 and 400 then 1 end) as 300到400from student_info;
3.按分数段和专业统计
400到500人数,300到400人数
selectcount(case when score between 400 and 500 then 1 end) as 400到500,count(case when score between 300 and 400 then 1 end) as 300到400from student_info GROUP BY profession;
4.sql动态拼接生成
int start = 200; int end = 700; int inter = 10; int count = (end-start)/inter; StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append("select "); for(int i =1;i<=count;i++){ int next = start+inter-1; System.out.println(start + " \t" + next); sqlBuilder.append(" count(case when admission_score between ").append(start).append(" and ").append(next).append(" then 1 end) as ").append(start).append("到").append(next); if(i!=count){ sqlBuilder.append(", "); } start += inter; } sqlBuilder.append(" from z_student_info"); System.out.println(sqlBuilder.toString());
5.输出sql
select count(case when admission_score between 200 and 209 then 1 end) as 200到209, count(case when admission_score between 210 and 219 then 1 end) as 210到219, count(case when admission_score between 220 and 229 then 1 end) as 220到229, count(case when admission_score between 230 and 239 then 1 end) as 230到239, count(case when admission_score between 240 and 249 then 1 end) as 240到249, count(case when admission_score between 250 and 259 then 1 end) as 250到259, count(case when admission_score between 260 and 269 then 1 end) as 260到269, count(case when admission_score between 270 and 279 then 1 end) as 270到279, count(case when admission_score between 280 and 289 then 1 end) as 280到289, count(case when admission_score between 290 and 299 then 1 end) as 290到299, count(case when admission_score between 300 and 309 then 1 end) as 300到309, count(case when admission_score between 310 and 319 then 1 end) as 310到319, count(case when admission_score between 320 and 329 then 1 end) as 320到329, count(case when admission_score between 330 and 339 then 1 end) as 330到339, count(case when admission_score between 340 and 349 then 1 end) as 340到349, count(case when admission_score between 350 and 359 then 1 end) as 350到359, count(case when admission_score between 360 and 369 then 1 end) as 360到369, count(case when admission_score between 370 and 379 then 1 end) as 370到379, count(case when admission_score between 380 and 389 then 1 end) as 380到389, count(case when admission_score between 390 and 399 then 1 end) as 390到399, count(case when admission_score between 400 and 409 then 1 end) as 400到409, count(case when admission_score between 410 and 419 then 1 end) as 410到419, count(case when admission_score between 420 and 429 then 1 end) as 420到429, count(case when admission_score between 430 and 439 then 1 end) as 430到439, count(case when admission_score between 440 and 449 then 1 end) as 440到449, count(case when admission_score between 450 and 459 then 1 end) as 450到459, count(case when admission_score between 460 and 469 then 1 end) as 460到469, count(case when admission_score between 470 and 479 then 1 end) as 470到479, count(case when admission_score between 480 and 489 then 1 end) as 480到489, count(case when admission_score between 490 and 499 then 1 end) as 490到499, count(case when admission_score between 500 and 509 then 1 end) as 500到509, count(case when admission_score between 510 and 519 then 1 end) as 510到519, count(case when admission_score between 520 and 529 then 1 end) as 520到529, count(case when admission_score between 530 and 539 then 1 end) as 530到539, count(case when admission_score between 540 and 549 then 1 end) as 540到549, count(case when admission_score between 550 and 559 then 1 end) as 550到559, count(case when admission_score between 560 and 569 then 1 end) as 560到569, count(case when admission_score between 570 and 579 then 1 end) as 570到579, count(case when admission_score between 580 and 589 then 1 end) as 580到589, count(case when admission_score between 590 and 599 then 1 end) as 590到599, count(case when admission_score between 600 and 609 then 1 end) as 600到609, count(case when admission_score between 610 and 619 then 1 end) as 610到619, count(case when admission_score between 620 and 629 then 1 end) as 620到629, count(case when admission_score between 630 and 639 then 1 end) as 630到639, count(case when admission_score between 640 and 649 then 1 end) as 640到649, count(case when admission_score between 650 and 659 then 1 end) as 650到659, count(case when admission_score between 660 and 669 then 1 end) as 660到669, count(case when admission_score between 670 and 679 then 1 end) as 670到679, count(case when admission_score between 680 and 689 then 1 end) as 680到689, count(case when admission_score between 690 and 699 then 1 end) as 690到699 from z_student_info
以上就是mysql如何统计每个专业分数段人数的详细介绍,如果想了解更多请关注其它相关文章!
人数
分数
专业
分数段
统计
动态
姓名
就是
文章
更多
结构
生成
输出
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络技术属于电子信息工程
pg数据库 copy to
幼儿网络安全手抄报图片
小姐姐服务器
服务器emal是什么
c 使用udl连接数据库
一部关于网络技术的电影
星路谷物语服务器没有
第五人格是否服务器崩了
光猫桥接一直服务器无响应
数据库中的索引都有哪些
415网络安全教育
为什么需要数据模型数据库简答题
数据库检索技术中
见薇数据库
大连新龙网络技术有限公司
香河网络安全
上海万想互联网科技发展
网络安全法渗透测试规定
千米红包区块链软件开发
db2指定用户连接数据库
网络安全执法监督检查
自己怎么组装一台服务器
数据库类型及应用场景
新疆访问不了自己的服务器怎么办
如何搞好本单位网络安全
数据库用户表空间过大
软件开发估算过程
数据库优化视频
xsgo怎么连接不了服务器