当前位置:网站首页>The combination of over clause and aggregate function in SQL Server
The combination of over clause and aggregate function in SQL Server
2022-07-07 09:54:00 【knight_ hf】
Here is an example from the Internet :
use tempdb
go
if (object_id ('tb' ) is not null )
drop table tb
go
create table tb (name varchar (10 ), val int )
go
insert into tb
select 'aa' , 10
union all select 'aa' , 20
union all select 'aa' , 20
union all select 'aa' , 30
union all select 'bb' , 55
union all select 'bb' , 45
union all select 'bb' , 0
select *
, ranking = rank ()over (partition by name order by val )
, Proportion = cast (val * 1.0 / sum (val )over (partition by name ) as decimal (2 , 2 ))
, Maximum distance = val - max (val )over (partition by name )
, Minimum distance = val - min (val )over (partition by name )
, Distance average = val - avg (val )over (partition by name )
from tb
Through the example above , My own experience ( Not necessarily right , It's just convenient for you to understand ):
On the basis of the above example , If used directly select max(val) from tb group by name The query , return 2 That's ok .
If you use select max(val) over(partition by name) from tb Then return to 7 That's ok .
That is, after using the aggregate function , The window was opened again ( All the original rows in the table return ).
边栏推荐
- 高斯消元
- Hcip first day notes sorting
- Sqlplus garbled code problem, find the solution
- Applet popup half angle mask layer
- Unity shader (pass user data to shader)
- 小程序滑动、点击切换简洁UI
- [4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
- Software modeling and analysis
- First issue of JS reverse tutorial
- Can flycdc use SqlClient to specify mysqlbinlog ID to execute tasks
猜你喜欢
# Arthas 简单使用说明
小程序实现页面多级来回切换支持滑动和点击操作
Deep understanding of UDP, TCP
【无标题】
Lesson 1: finding the minimum of a matrix
一大波开源小抄来袭
[4g/5g/6g topic foundation -147]: Interpretation of the white paper on 6G's overall vision and potential key technologies -2-6g's macro driving force for development
Detailed explanation of diffusion model
Dynamics 365online applicationuser creation method change
iNFTnews | 时尚品牌将以什么方式进入元宇宙?
随机推荐
asp. How to call vb DLL function in net project
基于智慧城市与储住分离数字家居模式垃圾处理方法
2020ccpc Weihai J - Steins; Game (SG function, linear basis)
Liunx command
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
哈夫曼编码压缩文件
sql 里面使用中文字符判断有问题,哪位遇到过?比如value<>`无`
How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
H5 web player easyplayer How does JS realize live video real-time recording?
IIS redirection redirection appears eurl axd
Arthas simple instructions
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
Communication mode between processes
Main (argc, *argv[]) details
EXT2 file system
AI从感知走向智能认知
Impression notes finally support the default markdown preview mode
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
Dynamics 365Online ApplicationUser创建方式变更
VSCode+mingw64+cmake