UNION 无法将两个结果与同一列合并
P粉647504283
P粉647504283 2024-04-03 00:23:39
0
1
463

在这里输入图像描述我试图将这两个查询合并在同一个显示结果中,但是Mysql系统一直说UNION不能在这个位置。如果联合不起作用,我如何组合这两个查询?

P粉647504283
P粉647504283

全部回复(1)
P粉329425839

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 
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!