------------------------------------------------有id,name,createDate的一张表testTable--根据name分组,获取每组中createDate最大的那条记录(整条)查询 ...
方法一 selectt .a,t .b,t .c fromtestt innerjoin seelcta,max b asbfromtestgroupbya t ont .a t .aandt .b t .b 方法二 select from select t. , row number over partition by 分组字段 order by 排序字段 desc rnfrom tablena ...
2016-12-01 19:35 0 1928 推荐指数:
------------------------------------------------有id,name,createDate的一张表testTable--根据name分组,获取每组中createDate最大的那条记录(整条)查询 ...
SQL 分组后获取其中一个字段最大值的整条记录 方法一:(效率最高)select * from test as a where typeindex = (select max(b.typeindex) from test as b where a.type = b.type ...
方法一:(效率最高)select * from test as a where typeindex = (select max(b.typeindex) from test as b where ...
--有id,name,createDate的一张表testTable--根据name分组,获取每组中createDate最大的那条记录(整条)查询出来---------------------------------------------- 创建一张表,语句如下: CREATE TABLE ...
select * from ( select last_comment, row_number() over(partition by employeeid,roadline,stationname ...
场景:sql server 2008 目标: select COUNT(*) from ID group by code 产生code列唯一的3行数据,并显示最小的D列数据 方案1: select code,MIN(D)from ID group ...
获取分组后取某字段最大一条记录方法一:(效率最高)select * from test as awhere typeindex = (select max(b.typeindex)from test as bwhere a.type = b.type );方法二:(效率次之)selecta. ...
sqlserver2005前: --分组取最大最小常用sql--测试环境if OBJECT_ID('tb') is not null drop table tb;gocreate table tb( col1 int, col2 int, Fcount int)insert ...