当前位置:网站首页>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 ).
边栏推荐
- Addition, deletion, modification and query of ThinkPHP database
- 2020ccpc Weihai J - Steins; Game (SG function, linear basis)
- 如何成为一名高级数字 IC 设计工程师(5-2)理论篇:ULP 低功耗设计技术精讲(上)
- 14th test
- CDZSC_2022寒假个人训练赛21级(2)
- Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
- Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
- Liunx command
- H5网页播放器EasyPlayer.js如何实现直播视频实时录像?
- 印象笔记终于支持默认markdown预览模式
猜你喜欢
![[untitled]](/img/5b/61efbaded29250bc8d921b0cf087c8.png)
[untitled]

Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat

Esp8266 uses TF card and reads and writes data (based on Arduino)

基于智慧城市与储住分离数字家居模式垃圾处理方法

What development models did you know during the interview? Just read this one

面试被问到了解哪些开发模型?看这一篇就够了

字节跳动 Kitex 在森马电商场景的落地实践

20排位赛3

【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本

Garbage disposal method based on the separation of smart city and storage and living digital home mode
随机推荐
Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
Sqlplus garbled code problem, find the solution
thinkphp3.2信息泄露
企业实战|复杂业务关系下的银行业运维指标体系建设
Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
细说Mysql MVCC多版本控制
nlohmann json
Huffman encoded compressed file
JS逆向教程第一发
第一讲:寻找矩阵的极小值
csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用
2016 CCPC Hangzhou Onsite
NETCORE 3.1 solves cross domain problems
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力
[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
[4G/5G/6G专题基础-146]: 6G总体愿景与潜在关键技术白皮书解读-1-总体愿景
基于智慧城市与储住分离数字家居模式垃圾处理方法
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
Oracle installation enhancements error
Vs2013 generate solutions super slow solutions