zoukankan      html  css  js  c++  java
  • 利用partition分组查询 查询每个分组第一条数据

    利用partition分组查询 查询每个分组第一条数据

    数据库:sqlserver (其他数据库没有尝试)

    row_number() over(partition by year(createtime),month(createtime),day(createtime),glsort ORDER BY createtime DESC)

    over(partition by 分组条件)

    row_number() over(partition by year(createtime),month(createtime),day(createtime),glsort ORDER BY createtime DESC)

    over(partition by 分组条件 order by 排序条件(必须))
    select * from
    (
        select glsort,createtime, sort,id,
        row_number() over(partition by year(createtime),month(createtime),day(createtime),glsort ORDER BY createtime DESC) as new_index 
        from BusinessInformation 
        where isExamine=1
    )
    a where a.new_index = 1 ORDER BY a.sort desc, year(a.createtime)desc ,month(a.createtime) desc,day(a.createtime) desc
  • 相关阅读:
    python023
    python019
    python018
    python017
    python016
    python013
    python012
    数据库,盘它!!!!
    网络编程
    面向对象简述
  • 原文地址:https://www.cnblogs.com/OleRookie/p/5292566.html
Copyright © 2011-2022 走看看