SQL2008避免出错(聚合函数+Over用法)
来源:互联网 发布:php获取字符串长度函数 编辑:程序博客网 时间:2024/06/06 07:01
--返回出错with CTEOrders as(select cast(1 as int) as OrderID, cast('3/1/2012' as date) as OrderDate, cast(10.00 as money) as OrderAmt, 'Joe' as CustomerNameunion select 2, '3/1/2012', 11.00, 'Sam'union select 3, '3/2/2012', 10.00, 'Beth'union select 4, '3/2/2012', 15.00, 'Joe'union select 5, '3/2/2012', 17.00, 'Sam'union select 6, '3/3/2012', 12.00, 'Joe'union select 7, '3/4/2012', 10.00, 'Beth'union select 8, '3/4/2012', 18.00, 'Sam'union select 9, '3/4/2012', 12.00, 'Joe'union select 10, '3/4/2012', 11.00, 'Beth'union select 11, '3/5/2012', 14.00, 'Sam'union select 12, '3/6/2012', 17.00, 'Beth'union select 13, '3/6/2012', 19.00, 'Joe'union select 14, '3/7/2012', 13.00, 'Beth'union select 15, '3/7/2012', 16.00, 'Sam')select sum(OrderAmt), sum(OrderAmt) over() from CTEOrders group by CustomerName /* 消息 155,级别 15,状态 1,第 24 行'CTEOrders' 不是可以识别的 GROUP BY 选项。*/ --这样用避免出错;with CTEOrders as(select cast(1 as int) as OrderID, cast('3/1/2012' as date) as OrderDate, cast(10.00 as money) as OrderAmt, 'Joe' as CustomerNameunion select 2, '3/1/2012', 11.00, 'Sam'union select 3, '3/2/2012', 10.00, 'Beth'union select 4, '3/2/2012', 15.00, 'Joe'union select 5, '3/2/2012', 17.00, 'Sam'union select 6, '3/3/2012', 12.00, 'Joe'union select 7, '3/4/2012', 10.00, 'Beth'union select 8, '3/4/2012', 18.00, 'Sam'union select 9, '3/4/2012', 12.00, 'Joe'union select 10, '3/4/2012', 11.00, 'Beth'union select 11, '3/5/2012', 14.00, 'Sam'union select 12, '3/6/2012', 17.00, 'Beth'union select 13, '3/6/2012', 19.00, 'Joe'union select 14, '3/7/2012', 13.00, 'Beth'union select 15, '3/7/2012', 16.00, 'Sam')select sum(OrderAmt), sum(sum(OrderAmt)) over() from CTEOrders group by CustomerName;/*61.0000205.000068.0000205.000076.0000205.0000*/
0 0
- SQL2008避免出错(聚合函数+Over用法)
- SQL2008聚合函数
- Over:窗口函数(滑动聚合)
- Oracle_number() over() 函数的基本用法
- ORACLE-over()函数用法
- sql中的 开窗函数over() 聚合函数 排名函数
- oracle中over() 函数用法
- sql开窗函数over()用法
- sum over 分析函数用法
- OVER(PARTITION BY)函数用法
- sum over 分析函数用法
- OVER(PARTITION BY)函数用法
- OVER(PARTITION BY)函数用法
- OVER(PARTITION BY)函数用法
- OVER(PARTITION BY)函数用法
- oracle row_number over()函数用法
- OVER(PARTITION BY)函数用法
- OVER(PARTITION BY)函数用法
- Stax处理XML(三)——XPath的使用和写文档、修改文档
- nagios添加监控模块
- 【设计模式基础】创建型模式 - 3 - 简单工厂(Simple Factory)
- git常用命令
- 配置heat AutoScalingMultiAZSample.template 模板
- SQL2008避免出错(聚合函数+Over用法)
- java处理日期时间 相加减
- poll函数
- EditText去掉边框
- 函数索引的妙用
- Test__IO流综合应用的小练习
- RK2926 平板跟PC机连接起来的时候,修改驱动,盘符相关显示
- LinuxサーバへTomcat 7.xを導入し、自動起動するように設定する。
- 零缺陷编程读书笔记(六)自己设计并使用断言(4)