Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/SQL Query test

[MySQL] The PADS

๊ฐ์ž ๐Ÿฅ” 2021. 7. 22. 23:05
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ๋งํฌ

Generate the following two result sets:

  1. 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).
  2. Query the number of ocurrences of each occupation in OCCUPATIONS. Sort the occurrences in ascending order, and output them in the following format:

 

  1. 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;

๋งž๋Š”๋‹ต์„ ์“ฐ๊ณ ๋„ ์™œ ์ž๊พธ ์•ˆ๋˜๋ƒ ํ•˜๋ฉด์„œ ๋‹ค๋ฅธ ๋‹ต๋“ค์„ ์ฐพ์•„๋ณด๋Š”๋ฐ, ๋‚ด ๋‹ต๊ณผ ๋‹ค๋ฅผ ๊ฒƒ์ด์—†์—ˆ๋‹ค. ๋„ˆ๋ฌด ๋‹ต๋‹ตํ•ด์„œ ๋ญ๊ฐ€ ์ž˜๋ชป๋์ง€ ํ•˜๋Š” ์ˆœ๊ฐ„ ๋ˆˆ์—๋“ค์–ด์˜จ ';' !!!! 
์ฟผ๋ฆฌ๋ฅผ ๋‘๊ฐœ ์ž…๋ ฅํ•ด์•ผํ•ด์„œ ; ๋กœ ๋ฌด์กฐ๊ฑด ์ฟผ๋ฆฌ๊ฐ€ ๋๋‚ฌ๋‹ค๊ณ  ํ‘œ์‹œํ•ด์ค˜์•ผํ•œ๋‹ค. ํœด~!~! 

๋ฐ˜์‘ํ˜•