码迷,mamicode.com
首页 > 其他好文 > 详细

如何查询每个分组中的一条数据

时间:2016-10-12 10:48:46      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

SELECT ROW_NUMBER() OVER(PARTITION BY a.id ORDER BY 排序字段 desc,排序字段 desc)

FROM 表名

 

项目源码:

SELECT *  FROM (SELECT ROW_NUMBER() OVER(PARTITION BY a.id ORDER BY a.point_num desc,a.last_update_date desc) rn,
        a.a_id as aId,a.id as id,q.q_name as qName,a.a_details as aDetails,
        a.point_num as pointNum,u.user_name as userName,a.created_by as createdBy,
        a.creation_date as creationDate,a.last_update_date as lastUpdateDate
        FROM XXUN_QUESTIONS q,xxun_questions_answers a,xxun_user u  where  q.id=a.id and
        a.created_by=u.created_by and a.enable_flag=‘Y‘ order by a.point_num desc,a.last_update_date desc )
        WHERE rn = 1

如何查询每个分组中的一条数据

标签:

原文地址:http://www.cnblogs.com/sjm-com/p/5951609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!