SELECT uploaddate
        ,ptnumber
        ,instcount
  FROM   (
             SELECT ROW_NUMBER() OVER(
                        PARTITION BY uploaddate ORDER BY uploaddate DESC
                       ,instcount DESC
                    )  AS row
                   ,*
             FROM   (
                        SELECT uploaddate
                              ,ptnumber
                              ,COUNT(*) instcount
                        FROM   LtblLog.dbo.instlog201408
                        GROUP BY
                               uploaddate
                              ,ptnumber
                    )  AS T
         ) a
  WHERE  row<= 10

 执行结果:

MS SQL 取分组后的几条数据

 

另一条简单的语句:

select * from (select row_number() over(partition by login_name order by login_count) as rownum, * from (select a.*,(select count(*) from lit_test as b where a.login_name=b.login_name) as login_count from lit_test as a) as Z) as T where T.rownum = 1

 

相关文章:

  • 2022-12-23
  • 2021-07-05
  • 2022-02-22
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2022-01-01
  • 2021-12-10
  • 2022-12-23
  • 2021-04-18
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
相关资源
相似解决方案