SELECT rows.team, rows.date FROM (
SELECT team, date,
IF( @prev <> team, @rownum := 1, @rownum := @rownum+1 ) AS rownum,
@prev := team
FROM my_table
JOIN (SELECT @rownum := NULL, @prev := 0) AS init
ORDER BY team, date DESC
) AS rows
WHERE rownum <= 10
We make a temporary (virtual) table in the sub-query with rows ordered by team, date DESC and we start from the top giving an incrementing row number to each row and whenever team changes we reset the row number, then in the outer query we filter out any row that has row number greater than 10.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…