加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

Sqlserver 获取每组中的第一条记录

发布时间:2020-12-12 14:09:17 所属栏目:MsSql教程 来源:网络整理
导读:例子 ?id? grp ? data ? createtime ? ? 1 ? g1 ? 10 ? 2011-9-1 ? 2 ? 11 ? 2011-9-2 ? 3 ? g2? ? 111 ? 2011-10-12 ? 4 ? g2 ? 12 ? 2011-12-20 ?5 ? g3 ?12 ?2011-12-20 我们要从上面获得的有效数据为: 对应的sql: select * from t1 t where id = (selec
? 1 ? g1 ? 10 ? 2011-9-1 ? 2 ? 11 ? 2011-9-2 ? 3 ? g2? ? 111 ? 2011-10-12 ? 4 ? g2 ? 12 ? 2011-12-20 ?5 ? g3 ?12 ?2011-12-20

我们要从上面获得的有效数据为:


对应的sql:

select * from t1 t where id = (select top 1 id from t1 where grp = t.grp order by createtime desc )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

例子

?id? grp ? data ? createtime ?
    推荐文章
      热点阅读