1.统计各个星级酒店数 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 2.给6家酒店打标签,把订单数量排名前50%的酒店记为A类酒店,其余记为B类酒店,输出字段为“酒店名称、星级、标签” -- 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