count(casewhen score between 400 and500 then 1 end) as400到500,
count(casewhen score between 300 and400 then 1 end) as300到400
from student_info;
按分数段和专业统计
400到500人数,300到400人数
1
2
3
4
select
count(casewhen score between 400 and500 then 1 end) as400到500,
count(casewhen score between 300 and400 then 1 end) as300到400
from student_info GROUP BY profession;
sql动态拼接生成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int start = 200;
int end= 700;
int inter = 10;
int count= (end-start)/inter;
StringBuilder sqlBuilder = newStringBuilder();
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);