在这里输入图像描述我试图将这两个查询合并在同一个显示结果中,但是Mysql系统一直说UNION不能在这个位置。如果联合不起作用,我如何组合这两个查询?
P粉3294258392024-04-03 11:58:44
https://dev.mysql.com/doc/refman /8.0/en/union.html 说:
就您而言,它看起来像这样:
(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 <= 3