语法 GROUP BY GROUPING SETS( (…),(…),…) 功能 对GROUPING SETS 后面括号里的n 个字段或表达式分别做GROUP BY 操作,最 后将结果合并在一起。 详见下面的解释: GROUP BY GROUPING SETS (A,B,C) (A、B、C 代表语法中的“(…)”) 首先对(A)进行GROUP BY,然后对(B)进行GROUP BY,然后对(C)进行GROUP BY,最后将所有结果合并在一起(相当于UNION ALL 操作),如果n 个字段或表达 式中的一个或多个在某一分组中不出现在GROUP BY 后面,用NULL 代替不出现 的字段或表达式。 示例 示例1:GROUP BY GROUPING SETS(color_type,f_YearMonth) gbase> SELECT color_type,in_date,color_count FROM t3 ORDER BY color_type,in_date; +------------+------------+-------------+ | color_type | in_date | color_count |
GBase UP 产品手册 5 数据库管理指南 文档版本04(2021-04-21) 南大通用数据技术股份有限公司 577 +------------+------------+-------------+ | black | 2010-09-11 | 18 | | black | 2010-10-05 | 18 | | black | 2010-10-13 | 31 | | blue | 2010-09-21 | 23 | | blue | 2010-09-30 | 15 | | blue | 2010-10-11 | 62 | | red | 2010-09-12 | 41 | | red | 2010-10-01 | 12 | | red | 2010-10-05 | 11 | +------------+------------+-------------+ 9 rows in set
gbase> SELECT NVL(color_type,'') as color_type_show,DECODE(color_type,NULL,f_YearMonth || '合计 ',NVL(f_YearMonth,color_type || ' 小计')) AS f_YearMonth_show,SUM(color_count) FROM (SELECT color_type,DATE_FORMAT(in_date, '%Y-%m') as f_YearMonth,color_count FROM t3) t GROUP BY GROUPING SETS(color_type,f_YearMonth) ORDER BY color_type,f_YearMonth; +-----------------+------------------+------------------+ | color_type_show | f_YearMonth_show | SUM(color_count) | +-----------------+------------------+------------------+ | black | black 小计 | 67 | | blue | blue 小计 | 100 | | red | red 小计 | 64 | | | 2010-09 合计 | 97 | | | 2010-10 合计 | 134 | +-----------------+------------------+------------------+ 5 rows in set 非GROUP BY 类函数
PG_STATIO_USER_TABLES PG_STATIO_USER_TABLES 视图显示命名空间中所有用户关系表的IO 状态信息。 名称 类型 描述 relid oid 表OID。 schemaname name 该表模式名。 relname name 表名。 heap_blks_read bigint 从该表中读取的磁盘块数。 heap_blks_hit bigint 该表缓存命中数。 idx_blks_read bigint 从表中所有索引读取的磁盘块数。 idx_blks_hit bigint 表中所有索引命中缓存数。