求sql语句:分组中的最大值

yl113 2005-12-28 08:10:07
type name date
1 a 15
2 b 16
1 cd 18
1 cc 19
2 ddf 19


结果要求为
type name date
1 cc 19
2 ddf 19


语句不能为 select * from (selct * from) where 这种形势

...全文
509 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
子陌红尘 2005-12-29
  • 打赏
  • 举报
回复
select
t.*
from
test t
where
not exists(select * from test where type=t.type and date>t.date)
atsoftworld 2005-12-29
  • 打赏
  • 举报
回复
select * from test where date=(select Max(date) as date from test)
PL/SQL测试通过
space6212 2005-12-29
  • 打赏
  • 举报
回复
SQL> select * from test;

TYPE NAME MYDATE
--------------------------------------- ---------- ---------------------------------------
1 a 15
2 b 16
1 cd 18
1 cc 19
2 ddf 19

SQL> select * from test where rowid in (select rowid from (select row_number() over (partition by type order by mydate desc) n from test) where n=1)
2 ;

TYPE NAME MYDATE
--------------------------------------- ---------- ---------------------------------------
1 cc 19
2 ddf 19
xiaoxian0411 2005-12-29
  • 打赏
  • 举报
回复
SELECT AVG(type),MAX(date),MAX(name) FROM table GROUP BY type
yl113 2005-12-29
  • 打赏
  • 举报
回复
还是不行啊
超叔csdn 2005-12-29
  • 打赏
  • 举报
回复
select type,first_value( name)over(partition by type order by date desc),max( date )over(partition by type)
from tablename
group by type
black_dragon 2005-12-29
  • 打赏
  • 举报
回复
space6212() 的sql对是对了,不过绕了个圈,效率低了,改进一下
select type,name,date from
(select type,name,date,row_number() over (partition by type order by date desc) rn from tablename)
where rn=1;
如果表中最大值的行重复的话
select type,name,date from
(select type,name,date,max(date) over (partition by type) max_date from tablename)
where date=max_date;
synico 2005-12-28
  • 打赏
  • 举报
回复
select type_name,data from table_name where data in (select max(date) from table_name)

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧