先把没有访问量的筛掉,
再用date_format(create_time,'%y%m')函数按月份分组(不要用month,不然应付不了跨年),
再用count或者row_number筛出来前三,
select * from news t1
where pv > 0 and date_format(now(),'%y%m') < date_format(DATE_ADD(create_time, interval 6 MONTH),'%y%m') and (
select count(*) from news t2 where pv > 0 and date_format(t1.create_time,'%y%m') = date_format(t2.create_time,'%y%m') and create_time < t1.create_time
) < 3
row_number的更简洁,思路上也都差不多,楼上已经写了
然而这么写效率非常低,工程上基本没有这么用的,与其这么写还不如每个月单独查