sql---partition的使用

partition分组函数,简化分组

原来语句

select ROUND(SUM(TIV_2016),2) TIV_2016
from (select a.*,b.TIV_2015_count,c.LAT_LON_count from insurance a
left join (select TIV_2015,count(*) TIV_2015_count from insurance group by TIV_2015) b
on a.TIV_2015=b.TIV_2015
left join (select CONCAT(LAT,LON) LAT_LON,count(*) LAT_LON_count from insurance group by LAT,LON) c
on CONCAT(a.LAT,a.LON)=c.LAT_LON ) d
where d.TIV_2015_count>1 and d.LAT_LON_count=1

使用分组函数

select ROUND(sum(TIV_2016),2) as TIV_2016 from(
select *,
count(PID) over (partition by TIV_2015) as num_tiv,
count(PID) over(partition by LAT,LON) as num_city
from insurance)h
where h.num_tiv >1 and num_city=1

posted on   新freedom  阅读(211)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示