当前位置:首页 >> sql 分组取每组第一条 >>

sql 分组取每组第一条

select 星期,max(字母) As 字母 from 表 group by 星期

用row_number函数可以解决。 1、创建测试表及插入数据: create table test(id int,name varchar(10),score int,classname varchar(20));insert into test values (1,'张三',100,'一班');insert into test values (2,'李四',89,'一班');insert i...

在分组中使用max()函数即可。例图中表格:按b列分组,求D列最大值:select b,max(d) from a group by b如果是最小,则可以使用 min()函数

with A as (SELECT department.dept_name , empl_no ,empl_name , pa101_03, pa012.pa012_02 ,pa101_06 ,pa101_07_dd , pa101_01_dd, pa101_02, pa232.pa23203 as '合同开始时间', pa232.pa23204 as '合同结束时间' FROM pa101 INNER JOIN depar...

select m, nfrom ( select row_number () over (partition by m order by n desc) rn,--以m分组,分组内以n倒序排列求每组中各自的序号 m, n from table where ...) wwhere w.rn

select r.regionName 区域,sum(case when d.sate = 1 then 1 else 0 end) 在线数量,sum(case when d.sate = 0 then 1 else 0 end) 离线数量from region r,organize o,devInfo dwhere r.regionId = o.regionIdand o.organziedId = d.organzieIdgr...


Database SQL 例句 可以对应用程序进行配置,使其静态地运行数据库SQL,而不会影响编程或用户体验。 Applications can be configured to run the database SQL statically without any change in programming or user experience.

select userid,ranking,username from table where userid+ranking in ( select userid+max(ranking) from table group by userid )

SQL2005写法。 例如求出每个部门最高薪酬的人员信息。跟你每组第一行的要求很类似吧! Declare @Employee table (ID int ,Dept int ,Salary decimal(10,2)) insert into @Employee values(1,10,5500.00) insert into @Employee values(2,10,4500...

网站首页 | 网站地图
All rights reserved Powered by
copyright ©right 2010-2021。