select datatime, sum(case when xingji = '2星级' then 1 else 0 end) 2星, sum(case when xingji = '3星级' then 1 else 0 end) 3星, sum(case when xingji = '4星级' then 1 else 0 end) 4星, sum(case when xingji = '5星级' then 1 else 0 end) 5星 from information GROUP BY datatime
-- mysql 8.0版本支持开窗函数 select t1.`name`, t1.xingji, t1.orders, (case when t1.ranks<=c1.c*0.5 then 'A' else 'B' end) 标签 from (select *, row_number() over(ORDER BY orders desc) ranks from information ) t1, (select count(1) c from information) c1