mysql 分組取每個組的前幾名的問題

流火行者發表於2018-07-09
select *
from hotel_addition_orders a
where (select count(*)
from hotel_addition_orders
where hotel_order_id = a.hotel_order_id and type > a.type)<2
order by a.hotel_order_id asc, a.type desc;
#班級排名----比我分數高的人少於2,那我就排第二名
select *
from hotel_addition_orders where type = 2;



select *
from hotel_addition_orders a
where
(select count(0) from hotel_addition_orders b where b.hotel_order_id = a.hotel_order_id and type in(1,2,5)) = 3
group by hotel_order_id order by hotel_order_id desc;

相關文章