sum over使用方法,以及与group by的差别
1、sum over使用方法
sum(col1) over(partition by col2 order by col3 )
以上的函数能够理解为:按col2 进行分组(partition ),每组以col3 进行排序(order),并进行连续加总(sum)
表a,内容例如以下:
B C D
02 02 1
02 03 2
02 04 3
02 05 4
02 01 5
02 06 6
02 07 7
02 03 5
02 02 12
02 01 2
02 01 23
运行:SELECT b, c, d, SUM(d) OVER(PARTITION BY b,c ORDER BY d) e FROM a
得到结果:
B C E
02 01 2
02 01 7
02 01 30
02 02 1
02 02 13
02 03 2
02 03 7
02 04 3
02 05 4
02 06 6
02 07 7
能够看到,E列的值是累加和。
2、与group by 的差别
相同的a表:select b,c,sum(d) e from a group by b,c
B C E
02 01 30
02 02 13
02 03 7
02 04 3
02 05 4
02 06 6
02 07 7
差别非常明显。
sum over使用方法,以及与group by的差别的更多相关文章
- Ubuntu Hash Sum mismatch 解决方法
有时候通过校园网对Ubuntu14.04进行更新时,会出现以下问题: W: Failed to fetch http://xxxxxxx Hash Sum mismatch 解决方法:打开搜索 → ...
- Ubuntu apt-get "Hash Sum mismatch" 问题解决方法
参考:ubuntu: apt-get update的时候遇到"Hash Sum mismatch"错误 在安装Mininet的时候,apt-get update的时候遇到了这个问题 ...
- Hive中笔记 :三种去重方法,distinct,group by与ROW_Number()窗口函数
一.distinct,group by与ROW_Number()窗口函数使用方法 1. Distinct用法:对select 后面所有字段去重,并不能只对一列去重. (1)当distinct应用到多个 ...
- python正则表达式02--findall()和search()方法区别,group()方法
import re st = 'asxxixxsaefxxlovexxsdwdxxyouxxde' #search()和 findall()的区别 a = re.search('xx(.*?)xxsa ...
- ubuntu 安装时遇到 hash sum mismatch 处理方法
ubuntu安装大软件时,下载经常容易出错,hash sum mismatch是其中一种,说到底还是网络不好,重试很多遍都是这个错误,最后的解决方案是把mismatch说的那个链接用firefox打开 ...
- 微擎 人人商城 增加营收比统计(即每个订单支持多少,收入多少,总得统计)多表联合查询, sum统计一对多总和 联合 group by 进行查询
在公司要求增加一项统计,即营收比, 每个订单收入多少 支出多少,盈利多少,盈利比都详细记录下来. 在做完针对单个订单的营收比之后(支出储存在 ewei_shop_order_external_pay ...
- 163源报错Hash Sum mismatch 解决方法
Ubuntu server 用的163的源,报错: W: Failed to fetch http://mirrors.163.com/ubuntu/dists/precise-updates/mai ...
- vue-methods方法与computed计算属性的差别
好吧,我就是单纯的举个例子:实现显示变量 message 的翻转字符串 第一种:methods:我们可以通过在表达式中调用方法来达到同样的效果: 第二种:computed:计算属性 上面的2中方法都实 ...
- group by与avg(),max(),min(),sum()函数的关系
数据库表: create table pay_report( rdate varchar(8), --日期 region_id varchar(4), --地市 ...
随机推荐
- 无聊的我写了一个代码 。。。P1605 迷宫
搜索水题 哎 直接不行了 . #include <ctype.h> #include <cstdio> void read(int &x) { x=;char ch=g ...
- boostrapvalidator
一个例子 <%@ page contentType="text/html;charset=UTF-8" language="java" %> < ...
- autorun - 自动装载/卸载CDROMs并在装载后执行/path/to/cdrom/autorun
总览 autorun [-lmqv?V] [-a EXEC] [-c CDPLAYER] [-e STRING] [-i MILLISEC] [-n STRING] [-t STRING] [--au ...
- gearman的安装
#gearman服务的安装与使用 #-- set -x set -e #安装开发依赖库 yum install gcc gcc-c++ make automake glibc libgomp libs ...
- webpack的详细介绍和使用
// 一个常见的`webpack`配置文件 const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-we ...
- 十六进制字符串转byte (无符号字符串);
方法一: unsigned char* hexstr_to_char(const char* hexstr) { size_t len = strlen(hexstr); IF_ASSERT(len ...
- 网络爬虫之框架(Scrapy)
Scrapy爬虫框架 爬虫框架是实现爬虫功能的一个软件结构和功能组件集合. 爬虫框架是一个半成品,能够帮助用户实现专业网络爬虫. Scrapy爬虫框架结构:
- python 获取路径
获取目录路径和文件路径 import osfor root, dirs, files in os.walk(".", topdown=False): # ‘.’为获取脚本所在路径下 ...
- 关于Map的遍历
想起之前有人问过我这个,那就顺手写一下Map的遍历 Map<Integer, String> map = new HashMap<Integer, String>(); map ...
- Sql语句的一些事(二)
与sql语句的书写顺序并不是一样的,而是按照下面的顺序来执行 from--where--group by--having--select--order by, from:需要从哪个数据表检索数据 wh ...