mysql分组排序后取第二条,帮忙看看,急急急!

qingtingnayongheng 2017-07-05 04:29:21
我的查询sql 如下:
select a.users_id,a.product_id,a.`insert_time`,a.`in_money` ,@rownum:= 1 +@rownum as rownum from investors a
where (a.users_id,a.product_id) in (select users_id,product_id from investors group by users_id,product_id having count(*)>1 )
and a.`product_id` IN ( SELECT id FROM product where `product_type` IN ('0','2','3'))
ORDER BY a.`users_id`, a.`product_id`,a.`insert_time`

得出的结果集合:如图片所示

我想获取标记中的数据,这sql应该怎么写?
...全文
1862 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复 1
SELECT * FROM a ORDER BY a.x DESC LIMIT 1,1 a是你上边sql语句查出的视图 x随意定一个字段 limit1,1 第一个1是取一条的意思 第二1是取(第一条+1 )条 limit1,n n是取(第一条+n)条

2,089

社区成员

发帖
与我相关
我的任务
社区描述
在线培训学习经验交流分享、优质课程资源共享。
社区管理员
  • IT课程大本营社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧