mssql sqlserver 关键字 GROUPING用法简介及说明

转自: http://www.maomao365.com/?p=6208  

摘要:
GROUPING 用于区分列是否由 ROLLUP、CUBE 或 GROUPING SETS 聚合而产生的行
如果是原生态的行聚合,则返回0 ,新增的行数据就返回1



grouping 语法简介 :
GROUPING (<列名>)
参数列名:

返回值
tinyint
<hr />
grouping 应用举例:
 

create table test(info varchar(30))
go
insert into test (info)values('a'),
('b'),('a'),('c'),('d'),('d') 
go

select info,count_big(info),grouping(info)
from test group by info 
WITH ROLLUP

go
drop table test 
----输出----
ifno 无列名 无列名
a    2    0
b    1    0
c    1    0
d    2    0
NULL    6    1
原文地址:https://www.cnblogs.com/lairui1232000/p/9431348.html