Re: [SQL ] 群组资料只显示max value row问题

楼主: cutekid (可爱小孩子)   2018-09-07 15:01:22
方法 1:
select t1.A,t1.B,t1.C
from table t1 inner join (
select A,max(C) as C
from table
group by A
) t2 on t1.A = t2.A and t1.C = t2.C
方法 2:
select A,B,C
from (
select A,B,C,
rank() over (partition by A order by C desc) as num
from table
) t1
where num = 1
方法 3:
select A,B,C
from table t1
where C = (
select max(C)
from table
where A = t1.A
)
※ 引述《oherman (qq)》之铭言:
: 数据库名称:sql server 2014
: 数据库版本:2016
: 内容/问题描述:
: 我的资料结构如下
: A栏 B栏 C栏
: =======================
: A 10 20180702
: A 10 20180801
: A 20 20180703
: B 20 20180706
: B 20 20180710
: B 20 20180711
: 我只要显示
: A栏 B栏 C栏
: =======================
: A 10 20180801
: B 20 20180711
: A栏group后的c栏最大值的那笔row data
: 请问要如何下语法?
作者: oherman (qq)   2018-09-10 17:45:00
感谢,可以

Links booklink

Contact Us: admin [ a t ] ucptt.com