UNION cannot combine two results with the same column
P粉6475042832024-04-03 00:23:39
0
1
492
Enter image description here I tried to combine these two queries in the same display result, but the Mysql system keeps saying that UNION cannot be at this location. If union doesn't work, how can I combine these two queries?
(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 said:
In your case it would look like this:
You may also want to knowWindow functions一个>: