id | mtype | ntype | qtype|
1 | 1 |1 |1 |
2 | 2 |2 |2 |
3 | 3 |3 3 |
4 | 4 |4 |5 |
5 | 5 |1 |3 |
6 | 2 |2 |1 |
7 | 2 |1 |1 |
8 | 3 |1 |1 |
9 | 1 |1 |1 |
10 | 1 |1 |1 |
数据库表如上:
要求得到结果在页面上显示为
mtype ntype qtype
1(30%) 1(60%) 1(60%)
2(30%) 2(20%) 3(20%)
3(20%) (其他20%) 其他(20%)
其他(20%)
[code="java"]
select count(mtype) from t_test;//这是mtype这个字段的总记录数!
select count(*) from t_test t where t.mtype = 1;//这个是mtype=1的总记录数
//这里是计算百分比
double size = (double)a/b;
NumberFormat nf = NumberFormat.getPercentInstance();
nf.setMinimumFractionDigits(0);//0指保留小数点后0位
System.out.println(nf.format(size));
//求出来就把这个值传到页面去就OK了
[/code]
我觉得这个要分成3张表吧,在一张里面记录条数都不等