与over函数结合的几个函数

create table #tab(A varchar(), B varchar())
insert into #tab
select 'A1', 'B1' union all
select 'A1', 'B2' union all
select 'A1', 'B3' union all
select 'A2', 'B4' union all
select 'A2', 'B5' union all
select 'A2', 'B6' union all
select 'A3', 'B7' union all
select 'A3', 'B8' union all
select 'A3', 'B9'

row_number() over() :

select row_number()over(order by A) as id ,* from #tab;

partition by:

按A分组,按A排序

select row_number()over(order by A) as id,
*,
row_number()over(partition by A order by A)Num
from #tab;

按A分组,组内按B倒序

select row_number()over(order by A) as id,
*,
row_number()over(partition by A order by B desc)Num
from #tab;

rank()over()

http://www.cnblogs.com/mycoding/archive/2010/05/29/1747065.html

select *,rank()over(order by A)from #tab;

select *,rank()over(partition by A order by A) from #tab;

select *,rank()over(partition by A order by B) from #tab;

也可以按多列分组,具体的看链接。

dense_rank()over()

select *,dense_rank()over(order by A)from #tab;

sum() over():

create table #tab(A varchar(), B varchar(),C int)
insert into #tab
select 'A1', 'B1' , union all
select 'A1', 'B2' ,10union all
select 'A1', 'B3' , union all
select 'A2', 'B4' , union all
select 'A2', 'B5' ,20union all
select 'A2', 'B6' ,20union all
select 'A3', 'B7' ,30union all
select 'A3', 'B8', union all
select 'A3', 'B9',
select *,sum(C)over(partition by A)from #tab;

select *,sum(C)over()from #tab;

http://hi.baidu.com/s__wind/item/a20107fa4eb6631ca6298858

http://www.cnblogs.com/85538649/archive/2011/08/13/2137370.html

http://www.cnblogs.com/lanzi/archive/2010/10/26/1861338.html

SQL Over的更多相关文章

  1. 最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目

    最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目 最近一个来自重庆的客户找到走起君,客户的业务是做移动互联网支付,是微信支付收单渠道合作伙伴,数据库里存储的是支付流水和交易流水 ...

  2. SQL Server 大数据搬迁之文件组备份还原实战

    一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 解决方案(Solution) 搬迁步骤(Procedure) 搬迁脚本(SQL Codes) ...

  3. Sql Server系列:分区表操作

    1. 分区表简介 分区表在逻辑上是一个表,而物理上是多个表.从用户角度来看,分区表和普通表是一样的.使用分区表的主要目的是为改善大型表以及具有多个访问模式的表的可伸缩性和可管理性. 分区表是把数据按设 ...

  4. SQL Server中的高可用性(2)----文件与文件组

        在谈到SQL Server的高可用性之前,我们首先要谈一谈单实例的高可用性.在单实例的高可用性中,不可忽略的就是文件和文件组的高可用性.SQL Server允许在某些文件损坏或离线的情况下,允 ...

  5. EntityFramework Core Raw SQL

    前言 本节我们来讲讲EF Core中的原始查询,目前在项目中对于简单的查询直接通过EF就可以解决,但是涉及到多表查询时为了一步到位就采用了原始查询的方式进行.下面我们一起来看看. EntityFram ...

  6. 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)

    从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...

  7. 从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)

    从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...

  8. 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)

    从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://w ...

  9. 从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点)

    从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...

  10. SQL Server on Linux 理由浅析

    SQL Server on Linux 理由浅析 今天的爆炸性新闻<SQL Server on Linux>基本上在各大科技媒体上刷屏了 大家看到这个新闻都觉得非常震精,而美股,今天微软开 ...

随机推荐

  1. 【Pyton】【小甲鱼】爬虫4-XXOO

    import urllib.request import os def open_url(url): req=urllib.request.Request(url) req.add_header('U ...

  2. 教你在Android手机上使用全局代理

    前言:在Android上使用系统自带的代理,限制灰常大,仅支持系统自带的浏览器.这样像QQ.飞信.微博等这些单独的App都不能使用系统的代理.如何让所有软件都能正常代理呢?ProxyDroid这个软件 ...

  3. spring用注解简化bean配置

    组件扫描: <context:component-scan base-package="com"/> 容器启动后如果发现配置文件有上面的标签会自动扫描对应的包及子包,如 ...

  4. Build-in Function:abs(),all(),any(),assii(),bin(),issubclass(),bytearray(),isinstance()

    print('abs():输出绝对值,是absolute的缩写--------------') print(abs(-1)) print('all()与any()------------------- ...

  5. [LeetCode] 560. Subarray Sum Equals K_Medium

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  6. Codeforces Round #247 (Div. 2) C D

    这题是一个背包问题 这样的 在一个k子树上 每个节点都有自己的k个孩子 然后 从原点走 走到 某个点的 和为 N 且每条的 长度不小于D 就暂停问这样的 路有多少条,  呵呵 想到了 这样做没有把他敲 ...

  7. ac1066

    经过分析后的二分 题目是 Josnch星球是一个赌博之风盛行的星球.每个人一出生就有一定数额的钱,之后的所有收入只能由赌博获得(OMG,如果RP不好,输光了所有的 钱...)假设赌博公司的某场赌博有N ...

  8. Ignite集群管理——基于Zookeeper的节点发现

    Ignite支持基于组播,静态IP,Zookeeper,JDBC等方式发现节点,本文主要介绍基于Zookeeper的节点发现. 环境准备,两台笔记本电脑A,B.A笔记本上使用VMware虚拟机安装了U ...

  9. Linux下DNS服务器配置

    一步:yum install -y bind bind-utils bind-chroot yum install bind* //安装DNS服务 第二步:systemctl stop firewal ...

  10. sql server数据库备份单个表的结构和数据生成脚本

    1.使用场景:sql server数据库备份单个表的结构和数据,在我们要修改正式系统的数据的一天或者多条某些数据时候,要执行update语句操作,安全稳健考虑,最好先做好所修改的表的结构和数据备份! ...