SQL SERVER中ROLLUP 运算符的用法
问题的提出:
现有表A,内容如下:
编码 仓库 数量
01 A 6
01 B 7
02 A 8
02 B 9
现在想按编码查询出这种格式:
--------------------
01 A 6
01 B 7
汇总小计: 13
02 A 8
02 B 9
汇总小计: 17
问:该如何实现?
乍一看,好像很容易,用group by好像能实现?但仔细研究下去,你又会觉得group by也是无能为力,总欠缺点什么,无从下手。那么,到底该如何做呢?别急,SQL Server早就帮我们做好了,下面,跟我来。
首先,让我们来看一段话:
在生成包含小计和合计的报表时,ROLLUP 运算符很有用。ROLLUP 运算符生成的结果集类似于 CUBE 运算符所生成的结果集。
========================
CUBE 运算符生成的结果集是多维数据集。多维数据集是事实数据的扩展,事实数据即记录个别事件的数据。扩展建立在用户打算分析的列上。这些列被称为维。多维数据集是一个结果集,其中包含了各维度的所有可能组合的交叉表格。
CUBE 运算符在 SELECT 语句的 GROUP BY 子句中指定。该语句的选择列表应包含维度列和聚合函数表达式。GROUP BY 应指定维度列和关键字 WITH CUBE。结果集将包含维度列中各值的所有可能组合,以及与这些维度值组合相匹配的基础行中的聚合值。
=========================
CUBE 和 ROLLUP 之间的区别在于:
CUBE 生成的结果集显示了所选列中值的所有组合的聚合。
ROLLUP 生成的结果集显示了所选列中值的某一层次结构的聚合。
&n
相关文档:
As a response for customer's question, I decided to write about using Like Operator in Linq to SQL queries.
Starting from a simple query from Northwind Database;
var query = from c in ctx.Customers
where c.City == "London"
&nbs ......
在 Oracle 10g 中
可以通过 http://localhost:5560/isqlplus 访问 isqlplus
在 isqlplus 中 可以执行 plsql
set serveroutput on size 100000 // 打开 服务器的输出 on 后面是 缓存的大小 范围是 (2000 至 1000000)
begin
dbms_output.put_line('hel ......
select f.tablespace_name,a.total,u.used,f.free,round((u.used/a.total)*100) "% used", round((f.free/a.total)*100) "% Free"
from
(select tablespace_name, sum(bytes/(1024*1024)) total
from dba_data_files group by tablespace_name) a,
(select tabl ......
The aspnet_Profile table contains the following fields: UserId, PropertyNames, PropertyValuesString, PropertyValuesBinary, and LastUpdatedDate. The PropertyNames field contains a string delimited with colons (:) that identify which profile fields are stored, what their datatype is and their of ......
要想成功访问 SQL Server 数据库中的数据,我们需要两个方面的授权:一、获得准许连接 SQL Server 服务器的权利;二、获得访问特定数据库中数据的权利(select, update, delete, create table ...)。假设,我们准备建立一个 dba 数据库帐户,用来管理数据库 mydb。
1. 首先在 SQL Server 服务器级别,创建登陆帐户(creat ......