当前位置:网站首页>pgsql查询分组中某个字段最大或者最小的一条数据
pgsql查询分组中某个字段最大或者最小的一条数据
2022-06-24 13:02:00 【GodSure0914】
如下图所示,左连接之后出现了一对多的情况,我要从这个"多" 里面取price最大的一条数据:
解决办法,在查询参数中新加一行:ROW_NUMBER() OVER(PARTITION by b.parent_charge_id ORDER BY c.price desc)idx
说明:
1.ROW_NUMBER:该函数可以对分组进行编号
2.PARTITION by :对parent_charge_id这个字段进行分组
这时的查询结果为:
可以看到数据已经按id进行了分组,并且进行了编号,编号为1的就是我们想要的最大值,再把值为1的取出来即可得到我们想要的结果:
边栏推荐
- 返回新列表
- 详解kubernetes备份恢复利器 Velero | 深入了解Carina系列第三期
- Record various sets of and or of mongotemplate once
- HarmonyOS. two
- English writing of Mathematics -- Basic Chinese and English vocabulary (common vocabulary of geometry and trigonometry)
- Research on MySQL composite index
- SAP Marketing Cloud 功能概述(四)
- Google waymo proposed r4d: remote distance estimation using reference target
- Return to new list
- 龙蜥开发者说:首次触电,原来你是这样的龙蜥社区? | 第 8 期
猜你喜欢

居家办公更要高效-自动化办公完美提升摸鱼时间 | 社区征文

puzzle(016.2)指画星河

Getting to know cloud native security for the first time: the best guarantee in the cloud Era

markdown/LaTeX中在字母下方输入圆点的方法

P2pdb white paper

Baidu map API drawing points and tips

谷歌WayMo提出R4D: 采用参考目标做远程距离估计

【从零开始学zabbix】一丶Zabbix的介绍与部署Zabbix
![Jerry's serial port receiving IO needs to set the digital function [chapter]](/img/04/48e7da42101a53827463d479952f67.png)
Jerry's serial port receiving IO needs to set the digital function [chapter]

专精特新“小巨人”再启动,“企业上云”数字赋能
随机推荐
puzzle(016.2)指画星河
[learn ZABBIX from scratch] I. Introduction and deployment of ZABBIX
Method of inputting dots under letters in markdown/latex
v-for 中 key的作用和原理
conda和pip命令
90% of the project managers have skipped the pit. Are you still in the pit?
Record various sets of and or of mongotemplate once
Promotion of Project Manager
pip uninstall all packages except builtin package
远程办公之:在家露营办公小工具| 社区征文
2022 construction elevator driver (construction special type of work) examination questions and online simulation examination
kotlin 共享可变状态和并发性
【环境搭建】zip 分卷压缩
v-if 和 v-show 的区别
Jericho After sleep, the system will wake up regularly and continue to run without resetting [chapter]
win10系统问题
ASCII code table extracted from tanhaoqiang's C program design (comparison table of common characters and ASCII codes)
HarmonyOS-3
居家办公更要高效-自动化办公完美提升摸鱼时间 | 社区征文
pip uninstall all packages except builtin package