--统计 小计 合计 create table trade_flow (user_code varchar2(12),trans_time date,trans_amount number); insert into trade_flow values('321000',to_date('2015-09-08 11:50:37','yyyy-mm-dd hh24:mi:ss'),300); insert into trade_flow values('321000',to_date('2015-09-08 18:47:20','yyyy-mm-dd hh24:mi:ss'),210); insert into trade_flow values('321002',to_date('2015-09-09 16:41:05','yyyy-mm-dd hh24:mi:ss'),190); insert into trade_flow values('321002',to_date('2015-09-09 20:11:15','yyyy-mm-dd hh24:mi:ss'),90); insert into trade_flow values('321000',to_date('2015-09-10 09:00:07','yyyy-mm-dd hh24:mi:ss'),100); insert into trade_flow values('321000',to_date('2015-09-10 10:30:25','yyyy-mm-dd hh24:mi:ss'),270); insert into trade_flow values('321000',to_date('2015-09-10 15:06:32','yyyy-mm-dd hh24:mi:ss'),50); insert into trade_flow values('321002',to_date('2015-09-10 12:33:45','yyyy-mm-dd hh24:mi:ss'),150); insert into trade_flow values('321002',to_date('2015-09-10 17:23:55','yyyy-mm-dd hh24:mi:ss'),350); select * from trade_flow order by 2; select user_code,TRUNC(trans_time),SUM(trans_amount), grouping(user_code),grouping(TRUNC(trans_time)) from trade_flow GROUP BY ROLLUP(user_code,TRUNC(trans_time)) ORDER by user_code,TRUNC(trans_time); select CASE WHEN (grouping(TRUNC(trans_time))=1 AND grouping(user_code)=1) THEN '总计' WHEN grouping(TRUNC(trans_time))=1 THEN '小计' ELSE user_code END user_code, TRUNC(trans_time),SUM(trans_amount), grouping(user_code),grouping(TRUNC(trans_time)) from trade_flow GROUP BY ROLLUP(user_code,TRUNC(trans_time)) ORDER by TRUNC(trans_time); select CASE WHEN (grouping(TRUNC(trans_time))=1 AND grouping(user_code)=1) THEN '总计' WHEN grouping(TRUNC(trans_time))=1 THEN '小计' ELSE user_code END user_code, TRUNC(trans_time),SUM(trans_amount), grouping(user_code),grouping(TRUNC(trans_time)), GROUPING_id(user_code,TRUNC(trans_time)),--是否都为空 GROUPING_id(user_code,TRUNC(trans_time)) from trade_flow GROUP BY ROLLUP(user_code,TRUNC(trans_time)) ORDER by user_code,TRUNC(trans_time); select CASE WHEN (grouping(trans_amount)=1 ) THEN '小计' --WHEN (grouping(TRUNC(trans_time))=0 AND grouping(user_code)=1) THEN user_code /*WHEN grouping(TRUNC(trans_time))=1 THEN '小计' */ ELSE user_code END user_code, TRUNC(trans_time),SUM(trans_amount), grouping(user_code),grouping(TRUNC(trans_time)),grouping(trans_amount) from trade_flow GROUP BY GROUPING SETS((user_code,TRUNC(trans_time),trans_amount), (user_code,TRUNC(trans_time))); select decode(grouping(trans_amount),1,'小计',0,user_code) user_code, TRUNC(trans_time),SUM(trans_amount), grouping(user_code),grouping(TRUNC(trans_time)),grouping(trans_amount), GROUPING_id(user_code,TRUNC(trans_time)),--是否都为空 GROUPING_id(trans_amount,TRUNC(trans_time)) from trade_flow GROUP BY GROUPING SETS((user_code,TRUNC(trans_time),trans_amount), (user_code,TRUNC(trans_time))); select * from trade_flow order by 2; select decode(grouping(trans_amount),1,'小计',0,user_code) user_code, TRUNC(trans_time),SUM(trans_amount), grouping(user_code),grouping(TRUNC(trans_time)),grouping(trans_amount) from trade_flow GROUP BY GROUPING SETS((user_code,TRUNC(trans_time),trans_amount), (user_code,TRUNC(trans_time))); select t.user_code,t.trans_time,t.trans_amount from trade_flow t WHERE t.user_code=321000; SELECT * FROM ( select t.user_code,t.trans_time,t.trans_amount from trade_flow t WHERE t.user_code=321000) PIVOT ( MAX(t.trans_time) FOR fieldname IN ( '300', '210', '100', '270', '50' ) ) ORDER BY 1
统计合计函数
原创
©著作权归作者所有:来自51CTO博客作者kinwar的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:datagrid使用
下一篇:VS快捷键整理(转载)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
使用shell脚本统计文件中ip出现的次数
https://b
ip地址 数据 倒序 -
html调用js的function函数 html调用js文件中的函数
问题描述在 js 中,无论是函数, 还是方法, 还是事件, 还是构造器...这些东西的本质都是函数,其中的区别只是所处的位置不同。根据函数内部this的指向不同,可以将函数的调用模式分成4种:函数模式、方法模式、构造器模式和上下文模式等四种不同的调用模式。解决方法首先先来分析this指向问题:1、任何函数都有属于自己的this2、this的指向和函数的调用模式相关,意味着this的指向在
html调用js的function函数 html调用js函数 html调用js文件函数 java 调用htm中js函数 使用this调用已有的有参构造函数 -
js函数中嵌套java js内嵌函数
javascript之内嵌函数篇 你了解javascript的内嵌函数吗?我们不防先做个小测试,你认为下面的代码运行结果会是什么呢? < script > function outerFn(firNum) { var firNum=firNum; &
js函数中嵌套java javascript ViewUI 局部变量 字符串