原表
要求:
每天的取最大值cnt的前三个top 3
代码实现:
SELECT
a.*
FROM
city_top a
LEFT JOIN city_top b ON a.date = b.date
AND a.cnt < b.cnt
GROUP BY
a.date,
a.city,
a.cnt
HAVING
count(b.date) < 3
ORDER BY
a.date,
a.cnt DESC;
此类表必须有别名关联比较,防止查询过程中表信息在对比条件中混乱。