首先我们创建一个示例表: Create table test_group (v_name varchar2(4) ,v_size varchar2(4) ,v_color varchar2(4) ,n_num number(4) ); --插入数据 insert into test_group select '桌子','大','红',10 from dual union all select '桌子','大','绿',10 from dual union all select '桌子','小',…
干oracle 047文章12当问题,经验group by 声明.因此邂逅group by rollup,decode,grouping,nvl,nvl2,nullif,RATIO_TO_REPORT等一下. 1. decode 与if...then,case...when...这类流数据语句功能差点儿相同 decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值) 该函数的含义例如以下: IF 条件=值1 THEN RETURN(值1) ELSIF 条件=值2 TH…
Rollup与group by组合使用,可对分组结果进行进一步的汇总. 创建数据表 select * from emp_test (1) rollup单个字段 如按照country字段进行分组,并在最后追加一条汇总所有country的值 ) from emp_test group by rollup (COUNTRY) (2) rollup多个字段 按照gender,country字段进行分组,并针对每一个country追加一条汇总值,并在最后追加一条所有country汇总 ) from emp…
group by rollup() 按分组合计 select grouping(status),status,owner,object_type,count(*) from dba_objects where owner not in ('SYS','SYSTEM') group by rollup (status,owner,object_type) order by status,owner,object_type; 经典分类查询语句: select object_type,count(*)…
例1: hive -e" select type ,status ,count(1) from usr_info where pt='2015-09-14' group by type,status grouping sets ((type,status),( type),()); ">one.txt Grouping sets按照各种指定聚类汇总方式,如group by type,status grouping sets ((type,status),( type),()) 表…