当前位置:网站首页>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 ).
边栏推荐
- How will fashion brands enter the meta universe?
- [Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
- CDZSC_2022寒假个人训练赛21级(2)
- Natapp intranet penetration
- 洛谷P2482 [SDOI2010]猪国杀
- 进程间的通信方式
- 终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
- H5 web player easyplayer How does JS realize live video real-time recording?
- NETCORE 3.1 solves cross domain problems
猜你喜欢
First issue of JS reverse tutorial
Flex flexible layout
农牧业未来发展蓝图--垂直农业+人造肉
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
iNFTnews | 时尚品牌将以什么方式进入元宇宙?
[untitled]
Elaborate on MySQL mvcc multi version control
基础篇:带你从头到尾玩转注解
How does mongodb realize the creation and deletion of databases, the creation of deletion tables, and the addition, deletion, modification and query of data
Esp8266 uses TF card and reads and writes data (based on Arduino)
随机推荐
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
进程和线程的区别
第一讲:包含min函数的栈
沙龙预告|GameFi 领域的瓶颈和解决方案
Luogu p2482 [sdoi2010] zhuguosha
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
[Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
JS逆向教程第一发
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
Strategic cooperation subquery becomes the secret weapon of Octopus web browser
thinkphp3.2信息泄露
小程序滑动、点击切换简洁UI
Scratch crawler mysql, Django, etc
sql 里面使用中文字符判断有问题,哪位遇到过?比如value<>`无`
Application of C # XML
CDZSC_2022寒假个人训练赛21级(2)
Detailed explanation of diffusion model
Dynamics 365online applicationuser creation method change
thinkphp数据库的增删改查
PostgreSQL reports an error when creating a trigger,