How does mysql count the number of people in each major score segment?
How does mysql count the number of people in each major score segment? The following will be introduced in detail by the editor.
1. My watch structure
Student_info | id | name | profession | score | |-| id | name | score | Specialty |
two。 Statistics by fractional segment
400 to 500 people, 300 to 400 people
Selectcount (case when score between 400 and 500 then 1 end) as 400 to 500 and count (case when score between 300 and 400 then 1 end) as 300 to 400from student_info
3. Statistics by score segment and specialty
400 to 500 people, 300 to 400 people
Selectcount (case when score between 400 and 500 then 1 end) as 400 to 500 and count (case when score between 300 and 400 then 1 end) as 300 to 400from student_info GROUP BY profession
4.sql dynamic splicing generation
Int start = 200; int end = 700; int inter = 10; int count = (end-start) / inter; StringBuilder sqlBuilder = new StringBuilder (); sqlBuilder.append ("select"); for (int I = 1teri