mysql 试图解决一个hackerhank挑战(PADS),我做错了什么?

kx5bkwkv  于 2023-03-17  发布在  Mysql
关注(0)|答案(1)|浏览(96)

我想要这个输出:

Ashely(P)
Christeen(P)
Jane(A)
Jenny(D)
Julia(A)
Ketty(P)
Maria(A)
Meera(S)
Priya(S)
Samantha(D)
There are a total of 2 doctors.
There are a total of 2 singers.
There are a total of 3 actors.
There are a total of 3 professors.

这是一个查询:

select concat(name,'(',left(occupation,1),')') 
from occupations
order by name;
select concat('There are a total of ', count(*),' ', occupation,'s') from occupations
group by occupation
order by count(occupation);

每次运行它时,我都会得到以下输出:

Aamina(D)
Ashley(P)
Belvet(P)
Britney(P)
Christeen(S)
Eve(A)
Jane(S)
Jennifer(A)
Jenny(S)
Julia(D)
Ketty(A)
Kristeen(S)
Maria(P)
Meera(P)
Naomi(P)
Priya(D)
Priyanka(P)
Samantha(A)
concat('There are a total of ', count(*),' ', occupation,'s')
There are a total of 3 Doctors
There are a total of 4 Actors
There are a total of 4 Singers
There are a total of 7 Professors

我做错了什么?

nqwrtyyt

nqwrtyyt1#

感谢您的帮助!它现在可以工作了。我已经将查询更改为:

SELECT CONCAT(NAME,'(',LEFT(OCCUPATION,1),')') AS RESPONSE  
FROM OCCUPATIONS 
UNION  
SELECT CONCAT('There are a total of ',COUNT(OCCUPATION),' ',LOWER(OCCUPATION),'s.') AS RESPONSE  
FROM OCCUPATIONS  
GROUP BY OCCUPATION 
ORDER BY RESPONSE ASC

相关问题