gpt4 book ai didi

mysql - WITH UNION ALL 无法使用 ORDER BY

转载 作者:行者123 更新时间:2023-12-01 00:00:04 25 4
gpt4 key购买 nike

运行的时候

SELECT concat(name,'(',substring(occupation,1,1),')')  
FROM occupations
UNION ALL
SELECT concat('There are total ',count(occupation),' ', occupation,'.')
FROM occupations
GROUP BY occupation

查询工作正常,但是当我添加订单时

SELECT concat(name,'(',substring(occupation,1,1),')')  
FROM occupations
UNION ALL
SELECT concat('There are total ',count(occupation),' ', occupation,'.')
FROM occupations
GROUP BY occupation
ORDER BY name

这是显示错误:

Unknown column 'name' in 'order clause'

表职业字段名称,职业

最佳答案

为您的选择列添加别名:

SELECT CONCAT(name,'(', SUBSTRING(occupation,1,1),')') as name
FROM occupations
UNION ALL
SELECT CONCAT('There are total ', COUNT(occupation),' ', occupation,'.') as name
FROM occupations
GROUP BY occupation
ORDER BY name

关于mysql - WITH UNION ALL 无法使用 ORDER BY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38604907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com