HackerRank MySQL - The PADS




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:



  1. /*
  2. Enter your query here and follow these instructions:
  3. 1. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error.
  4. 2. The AS keyword causes errors, so follow this convention: "Select t.Field From table1 t" instead of "select t.Field From table1 AS t"
  5. 3. Type your code immediately after comment. Don't leave any blank line.
  6. */
  7. SELECT NAME || '(' || SUBSTR(OCCUPATION, 1, 1) || ')'
  8. FROM OCCUPATIONS
  9. ORDER BY NAME;
  10. SELECT 'There are a total of ' || X.O_COUNT || ' ' || LOWER(X.OCCUPATION) || 's.'
  11. FROM
  12. (SELECT OCCUPATION,
  13. COUNT(OCCUPATION) AS O_COUNT
  14. FROM OCCUPATIONS
  15. GROUP BY OCCUPATION) X
  16. ORDER BY X.O_COUNT,
  17. X.OCCUPATION;




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube