(select customer_id, points, state from customers where state = 'CA' order by points desc limit 3)
union
(select customer_id, points, state from customers where state = 'FL' order by points desc limit 3)
select customer_id, points, state
from (
select customer_id, points, state,
row_number() over (partition by state order by points desc) as rownum
from customers where state in ('CA','FL')
) as t
where rownum
https://dev.mysql.com/doc/refman /8.0/en/union.html 说:
就您而言,它看起来像这样:
您可能还想了解窗口函数一个>: