Algorithm/SQL Query test
[MySQL] The PADS
๊ฐ์ ๐ฅ
2021. 7. 22. 23:05
๋ฐ์ํ
Generate the following two result sets:
- Query an alphabetically ordered list of all names in OCCUPATIONS, immediately followed by the first letter of each profession as a parenthetical (i.e.: enclosed in parentheses). For example: AnActorName(A), ADoctorName(D), AProfessorName(P), and ASingerName(S).
- Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format:
- where [occupation_count] is the number of occurrences of an occupation in OCCUPATIONS and [occupation] is the lowercase occupation name. If more than one Occupation has the same [occupation_count], they should be ordered alphabetically.
Note: There will be at least two entries in the table for each type of occupation.
์ ๋ต
SELECT CONCAT(NAME, '(', LEFT(OCCUPATION,1), ')')
FROM OCCUPATIONS
ORDER BY NAME;
SELECT CONCAT('There are a total of ', COUNT(OCCUPATION),' ',LOWER(OCCUPATION),'s.')
FROM OCCUPATIONS
GROUP BY OCCUPATION
ORDER BY COUNT(OCCUPATION), OCCUPATION;
๋ง๋๋ต์ ์ฐ๊ณ ๋ ์ ์๊พธ ์๋๋ ํ๋ฉด์ ๋ค๋ฅธ ๋ต๋ค์ ์ฐพ์๋ณด๋๋ฐ, ๋ด ๋ต๊ณผ ๋ค๋ฅผ ๊ฒ์ด์์๋ค. ๋๋ฌด ๋ต๋ตํด์ ๋ญ๊ฐ ์๋ชป๋์ง ํ๋ ์๊ฐ ๋์๋ค์ด์จ ';' !!!!
์ฟผ๋ฆฌ๋ฅผ ๋๊ฐ ์
๋ ฅํด์ผํด์ ; ๋ก ๋ฌด์กฐ๊ฑด ์ฟผ๋ฆฌ๊ฐ ๋๋ฌ๋ค๊ณ ํ์ํด์ค์ผํ๋ค. ํด~!~!
๋ฐ์ํ