摘要: 1 --Rank()返回数据项的排名,排名相同时会出现名次跳跃的情况 2 --Dense_Rank()返回数据项的排名,排名相同不会出现跳跃的情况 3 select a.prd_type_id, 4 sum(a.amount), 5 rank() over(order by sum(a.amount) desc) /*rank函数*/, 6 dense_rank() over(order by sum(a.amount) desc) /*dense_rank函数*/ 7 from all_sales a 8 where a.year = 200... 阅读全文
posted @ 2012-11-04 17:09 原想 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 1 --Group_ID:用于消除Group By子句中的返回的重复记录,Group by子句不接受任何参数2 --如果某个特定的分组重复n次,那么GROUP_ID返回0—n-1之间的一个整数3 --下面是实例:4 select a.division_id, a.job_id, avg(a.salary), group_id()5 from employees2 a6 group by a.division_id, rollup(a.division_id, a.job_id)7 having group_id() = 0 /*用于消除重复*/8 order by a.divi... 阅读全文
posted @ 2012-11-04 16:06 原想 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 1 --1.Grouping_id 2 --Grouping_id借助having子句可以对记录进行过滤 3 --将不包含小计或者总计的记录过滤掉 4 --Grouping_id可以返回一列或者多列,返回Grouping位向量的十进制值 5 select grouping(a.division_id), 6 grouping(a.job_id), 7 grouping_id(a.division_id, a.job_id), 8 sum(a.salary) 9 from employees2 a10 group by cube(a.divisi... 阅读全文
posted @ 2012-11-04 16:00 原想 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 1 --1.Grouping 函数可以接受一列,返回0或者1 如果列值为空那么返回1 否则返回0 2 select grouping(a.division_id),a.division_id, sum(a.salary) 3 from employees2 a 4 group by rollup(a.division_id) 5 order by a.division_id 6 7 运行结果为: 8 GROUPING(A.DIVISION_ID) DIVISION_ID SUM(A.SALARY) 9 1 0 BUS 161000010 2 ... 阅读全文
posted @ 2012-11-04 11:43 原想 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 1 --1.单独使用Group By子句:每个分组返回一条记录2 select a.division_id, sum(a.salary)3 from employees2 a4 group by a.division_id5 order by a.division_id运行结果:1 DIVISION_ID SUM(A.SALARY)2 1 BUS 16100003 2 OPE 13200004 3 SAL 49360005 4 SUP 10150001 --2.扩展子句Rollup: 每个分组返回一条小计,最后返回一条总计2 ... 阅读全文
posted @ 2012-11-04 10:58 原想 阅读(398) 评论(0) 推荐(0) 编辑