Group by ALL
来源:互联网 发布:地图软件下载 编辑:程序博客网 时间:2024/05/22 18:34
Group by ALL 。和不加ALL差别就是加了ALL后包含所有组和结果集,甚至包含那些其中任何行都不满足 WHERE 子句指定的搜索条件的组和结果集。注意的是指定了 ALL,将对组中不满足搜索条件的汇总列返回空值。declare @t table(id int,col char(2))insert @t select 1,'a'insert @t select 1,'a'insert @t select 2,'a'insert @t select 3,'a'insert @t select 3,'a'insert @t select 4,'a'insert @t select 5,'a'insert @t select 5,'a'insert @t select 5,'a'--1select id,COUNT(1)from @tgroup by id--2select id,COUNT(1)from @twhere id < 3group by id针对上面的数据我们可以得到显而意见的结果 :/*id ----------- -----------1 22 13 24 15 3(5 行受影响)id ----------- -----------1 22 1(2 行受影响)*/ 那么如果我们想要得到如下结果呢?/*id ----------- -----------1 22 13 04 05 0*/--显然大家一看就知道我的意思了吧,常规有人一定会union联合、子查询什么的吧,有没有想过其实可以简单点呀,看看下面的语法:--3select id,COUNT(1)from @twhere id < 3group by all id 结果大家自己运行一下就有答案了。最后后续版本的 Microsoft SQL Server 将删除该功能。请避免在新的开发工作中使用该功能,如果以后的项目里有使用的话还是着手修改当前还在使用该功能的应用程序吧。另外还得注意三点:1、CUBE 或 ROLLUP 运算符不能和ALL同时使用。2、如果在访问远程表的查询中还有 WHERE 子句,则该查询不支持 GROUP BY ALL。3、对于具有 FILESTREAM 属性的列,GROUP BY ALL将不被支持。
0 0
- Group by ALL
- Group By All [expressions] :
- 分组查询 Group by , Group by all , Having
- GROUP BY 子句和 ALL 关键字
- Group by 及GrOUP by ALL ,HAVING,WHERE的区别和运用
- 带all、cube和rollup的Group By查询
- Group by all | with cube | with rollup 的3用法
- union all 和 group by 的顺序问题
- Group by all | with cube | with rollup 的用法
- sql server查询SQL备忘(1)- group by all
- union union all group by 优化一例
- group by
- group by
- group by
- group by
- group by
- group by
- GROUP BY
- u-boot的编译及配置 mkconfig
- 图像分割_区域分裂合并
- layoutSubviews总结
- 找出数组中一个(两个,三个)只出现一次的数字
- 一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如6=1+2+3.编程找出1000以内的所有完数。
- Group by ALL
- 《Systems Performance: Enterprise and the Cloud》读书笔记系列(五) —— 第二章(四)
- Apache Mina v2.0.8 API手册
- jQuery性能优化
- Python 的join函数
- 策略模式C++实现
- Android5.0网络子系统
- 图像处理中各种边缘检测的微分算子简单比较(Sobel,Robert, Prewitt,Laplacian,Canny)
- unity文档---简单的清单,使你的发布版本尽可能的小