WITH UNION ALL unable to use ORDER BY

后端 未结 4 619
栀梦
栀梦 2021-01-26 08:12

When I am running

SELECT concat(name,\'(\',substring(occupation,1,1),\')\')  
FROM  occupations    
UNION ALL 
SELECT concat(\'There are total \',count(occupati         


        
4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 08:41

    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
    

    there is no column named name being returned in the above query.

    You can use this instead.

    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
    

提交回复
热议问题