当前位置:网站首页>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 ).
边栏推荐
- PLC信号处理系列之开关量信号防抖FB
- Impression notes finally support the default markdown preview mode
- Elaborate on MySQL mvcc multi version control
- Switching value signal anti shake FB of PLC signal processing series
- 2016 CCPC Hangzhou Onsite
- Guys, how can mysql-cdc convert the upsert message to append only
- Write it into the SR table in the way of flinksql. It is found that the data to be deleted has not been deleted. Refer to the document https://do
- 2016 CCPC Hangzhou Onsite
- 20排位赛3
- 14th test
猜你喜欢
[bw16 application] Anxin can realize mqtt communication with bw16 module / development board at instruction
一大波开源小抄来袭
沙龙预告|GameFi 领域的瓶颈和解决方案
基础篇:带你从头到尾玩转注解
Software modeling and analysis
What development models did you know during the interview? Just read this one
JS reverse tutorial second issue - Ape anthropology first question
H5 web player easyplayer How does JS realize live video real-time recording?
Use 3 in data modeling σ Eliminate outliers for data cleaning
csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用
随机推荐
14th test
Applet popup half angle mask layer
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
The difference between viewpager2 and viewpager and the implementation of viewpager2 in the rotation chart
Liunx command
CDZSC_ 2022 winter vacation personal training match level 21 (1)
JS reverse tutorial second issue - Ape anthropology first question
农牧业未来发展蓝图--垂直农业+人造肉
Garbage disposal method based on the separation of smart city and storage and living digital home mode
thinkphp3.2信息泄露
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
VSCode+mingw64+cmake
CDZSC_ 2022 winter vacation personal training match level 21 (2)
大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
2016 CCPC Hangzhou Onsite
H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
内存==c语言1
Dynamics 365online applicationuser creation method change
大佬们,请问 MySQL-CDC 有什么办法将 upsert 消息转换为 append only 消