MySQL-分组排序后取前3条

EXPLAIN SELECT a.*
FROM
(
SELECT a.*, IF(@tmpgid = strategy_stockid, @rank := @rank+1, @rank := 0) AS rank, 
@tmpgid := strategy_stockid, @number := @number+1, @rank, @tmpgid
FROM
(SELECT * FROM web_strategy_stockdetail ORDER BY strategy_stockid, high_profit DESC) a, 
(SELECT @rank :=0, @number :=0, @tmpgid := '') b) a
WHERE rank < 3;




发布了59 篇原创文章 · 获赞 2 · 访问量 8089
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览