代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
PLSQL
】
取分组最大值记录
作者:
Dezai.CN
/ 发布于
2012/7/16
/
996
取分组最大值记录
<div> <div>子查询:</div> <span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(223, 223, 223); -webkit-text-size-adjust: auto; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;">select * from 表 where (序号,名称) in (select max(序号),名称 from 表 group by 名称)</span> 分析函数: <span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">select 序号 , 名称 , 数量 from <br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">(select 序号 , 名称 , 数量 <br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">,row_number() over(partition by 名称 order by 序号 desc ) rn<br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">form tab_name )<br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">where rn=1<br style="word-wrap: break-word;" /> <br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">或<br style="word-wrap: break-word;" /> </span> <span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">select 序号 , 名称 , 数量 from <br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">(select 序号 , 名称 , 数量 <br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">, max(序号) over(partition by 名称) rn<br style="word-wrap: break-word;" /> </span><span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241);">form tab_name )<br style="word-wrap: break-word;" /> </span> <span style="font: 12px/18px verdana, arial, helvetica; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(241, 241, 241); -webkit-text-size-adjust: auto; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;">where rn=序号</span> 注意:max的字段只能是number类型字段,如果是date类型的,会提示错误。date类型用上面的row_number()来做就可以了。 <hr width="100%" size="2" /> <div><span style="font: bold 14px/26px Arial; text-align: left; color: rgb(46, 59, 0); text-transform: none; text-indent: 8px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(238, 235, 231); -webkit-text-size-adjust: auto; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;">Oracle 分组 取第一条记录</span></div> <div><span style="font: 14px/18px Arial; color: rgb(102, 102, 102); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(238, 235, 231); -webkit-text-size-adjust: auto; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;">id apply_id<br style="line-height: normal;" /> 1 1<br style="line-height: normal;" /> 2 1<br style="line-height: normal;" /> 3 1<br style="line-height: normal;" /> 4 2<br style="line-height: normal;" /> 5 2<br style="line-height: normal;" /> 6 3<br style="line-height: normal;" /> 7 3<br style="line-height: normal;" /> 8 3<br style="line-height: normal;" /> <br style="line-height: normal;" /> 取出<br style="line-height: normal;" /> id apply_id<br style="line-height: normal;" /> 3 1<br style="line-height: normal;" /> 5 2<br style="line-height: normal;" /> 8 3<br style="line-height: normal;" /> <br style="line-height: normal;" /> select alx_a.id<br style="line-height: normal;" /> from <br style="line-height: normal;" /> (select id,apply_id,rownum rid from 表) alx_a,<br style="line-height: normal;" /> (select id,apply_id,rownum rid from 表) alx_b<br style="line-height: normal;" /> where alx_a.apply_id = alx_b.apply_id and alx_a.id <= alx_b.id <br style="line-height: normal;" /> group by alx_a.id,alx_a.apply_id<br style="line-height: normal;" /> having count(*) = 1</span></div> </div>
试试其它关键字
分组最大值记录
同语言下
.
查看某张表的表结构
.
oracle 集合操作
.
for 循环中倒序 用reverse
.
Oracle 临时表空间收缩
.
查看session及其对应运行的sql
.
Oracle常用查看表结构命令
.
Oracle Connect By Prior用法(实现递归查询)
.
重置排序 SEQUENCE
.
创建一个trigger
.
批量替换字段中的字符
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3