mysql 取分组前几数据
SELECT
product_flag,
time,
sum_value
FROM
( # 查询数据语句
SELECT * FROM test ) a
WHERE
EXISTS (
SELECT
count(*)
FROM
( # 查询数据语句
SELECT * FROM test ) b
WHERE# 分组字段,如果多个字段,则继续这里添加即可
a.time = b.time # 指定指标小于某个值,即按什么规则取前几
AND a.sum_value < b.sum_value
HAVING
(# 分组前几
count(*)) < 10
)
ORDER BY
a.sum_value DESC