HackerRank/SQL

[hackerrank] The PADS

예쁜꽃이피었으면 2022. 8. 17. 15:58

[hackerrank] Prepare > SQL > Advanced Select > The PADS

 

[문제]

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:
    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.
  3. There are a total of [occupation_count] [occupation]s.

Note: There will be at least two entries in the table for each type of occupation.

Input Format

The OCCUPATIONS table is described as follows: 

 Occupation will only contain one of the following values: Doctor, Professor, Singer or Actor.

Sample Input

An OCCUPATIONS table that contains the following records:

Sample Output

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.

Explanation

The results of the first query are formatted to the problem description's specifications.
The results of the second query are ascendingly ordered first by number of names corresponding to each profession (), and then alphabetically by profession (, and ).

 

[MYSQL]

 

 

[ORCALE]

select name || '(' || substr(Occupation,0,1) || ')'
from OCCUPATIONS 
order by name asc;

select temp
from (
        select 'There are a total of ' || count(*) ||' '|| LOWER(Occupation) || 's.' temp ,Occupation, count(*) cnt
        from OCCUPATIONS 
        group by Occupation
    )
order by cnt asc,Occupation asc;

계속 뭐가 문제지 ..했는데 직업 첫글자만 소문자..

 

 

반응형

'HackerRank > SQL' 카테고리의 다른 글

[hackerrank] New Companies  (0) 2022.08.22
[hackerrank] Binary Tree Nodes  (0) 2022.08.18
[hackerrank] type of triangle  (0) 2022.08.17
[hackerrank] Binary Tree Nodes  (0) 2022.08.09
[hackerrank] Employee Salaries  (0) 2022.08.09