mysql 按分數段,每個專業分數段統計人數

来源:https://www.cnblogs.com/qingmiaokeji/archive/2020/03/15/12500240.html
-Advertisement-
Play Games

我的表結構 student_info | id |name |profession|score| | | | | | |id|姓名|分數|專業| 按分數段統計 400到500人數,300到400人數 按分數段和專業統計 400到500人數,300到400人數 sql動態拼接生成 輸出sql ...


我的表結構

student_info
| id |name |profession|score|
|--|--|--|--|
|id|姓名|分數|專業|

按分數段統計

400到500人數,300到400人數

select
count(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到400
from student_info;

在這裡插入圖片描述

按分數段和專業統計

400到500人數,300到400人數

select
count(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到400
from student_info GROUP BY profession;

在這裡插入圖片描述

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());

輸出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

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • [linux內核分析———SLAB原理及實現 ](https://blog.csdn.net/chenxiancool/article/details/7638804) Slab原理及實現 1. 整體關係圖 ! 註:SLAB,SLOB,SLUB都是內核提供的分配器,其前端介面都是一致的,其中SLAB ...
  • 最近使用brew update時,發現homebrew更新緩慢;於是進行更換為國內源; 晚上這種教程很多,我選擇的是中科大的源;當然清華的源也是可以的,這取決於你當前所處的地理位置,這樣有更通暢的網路鏈接; https://mirrors.ustc.edu.cn/help/brew.git.html ...
  • turtle庫的學習筆記(python) turtle(海龜)是Python重要的標準庫之一,它能夠進行基本的圖形繪製。turtle圖形繪製的概念誕生於1969年,成功應用於LOGO編程語言。turtle庫繪製圖形有一個基本框架:一個小海龜在坐標系中爬行,其爬行軌跡形成了繪製圖形。剛開始繪製時,小海 ...
  • 原文鏈接: "https://xiaoheidiannao.com/articles/Vim For Chrome.html" "Chrome瀏覽器" 有很多強大的擴展程式,其中我最喜歡的就是Vimium,其他的擴展程式都可以不安裝,但就是這個一定要安裝,用過以後你就會發現你已經離不開它了! Vim ...
  • 背景 最近公司系統還原用戶時偶爾會出現部分用戶信息未還原成功的問題,最為開發人員,最頭疼的不是代碼存在bug,而是測試發現了bug,但一旦我去重現,它就不見了。Are you kidding me? 經過漫長的溝通與嘗試,終於發現了端倪,這個問題只有在多人同時操作修改同一用戶信息時才會出現。 哦,那 ...
  • 介紹MySQL Integer類型的幾種分類,以及INT(11)中11數字表達的意思 ...
  • MySQL可以運行在不同的模式下,而且可以在不同的場景下運行不同的模式,這主要取決於系統變數 sql_mode 的值。本文主要介紹一下這個值的查看與設置,主要在Mac系統下。 對於每個模式的意義和作用,網上很容易找到,本文不做介紹。 按作用區域和時間可分為3個級別,分別是會話級別,全局級別,配置(永 ...
  • 在業界廣泛流傳著一句話:數據和特征決定了機器學習的上限,而模型和演算法只是逼近這個上限而已。 由此可見,數據和特征是多麼的重要,而在數據大多數場景下,數據已經就緒,不同人對於同樣的數據處理得到的特征卻千差萬別,最終得到的建模效果也是高低立現。從數據到特征這就要從特征工程說起了... ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...