Java数据统计的实现方法是什么?动力节点小编来告诉大家。
1. 创建对应的表
CREATE TABLE "NETPORTVIEW"
("GRP" CHAR(5),
"VIEWDATE" CHAR(10),
"PORT" CHAR(4),
"NUM1" NUMBER(10,2),
"NUM2" NUMBER(10,2),
"NUM3" NUMBER(10,2)
)
2. 插入数据
insert into netportview (GRP, VIEWDATE, PORT, NUM1, NUM2, NUM3)
values ('pvc ', '2011-02-12', '5200', 50000.00, 1000.00, 10.00);
insert into netportview (GRP, VIEWDATE, PORT, NUM1, NUM2, NUM3)
values ('pvc ', '2011-02-03', '6969', 100000.00, 2000.00, 10.00);
insert into netportview (GRP, VIEWDATE, PORT, NUM1, NUM2, NUM3)
values ('pvc ', '2011-02-09', '6969', 50000.00, 1000.00, 10.00);
insert into netportview (GRP, VIEWDATE, PORT, NUM1, NUM2, NUM3)
values ('pvc ', '2011-02-01', '5200', 80000.00, 2000.00, 8.00);
3. 查询
select * from (
select t.grp,t.viewdate,t.port,t.num1, t.num2, t.num3 from netportview t
union
select '小计' as GRP,null,t.port,sum(num1),null,sum(num3) from netportview t group by t.grp,port
union
select '总计' as GRP,null,'9999',sum(num1),null,sum(num3) from netportview t
)
order by port,viewdate
你适合学Java吗?4大专业测评方法
代码逻辑 吸收能力 技术学习能力 综合素质
先测评确定适合在学习