November 4, 2017 at 7:02 am
Hi Experts,
I am taking a puzzle challenge from a popular website. For the below scenarios,as mentioned in the website i am getting the exact output for my queries .But I am getting error "Your code did not pass this test case". I want to where I am getting wrong.
Puzzle URL
https://www.hackerrank.com/challenges/the-pads/problem
My Query:
select
case
when occupation='doctor' then name1
when occupation='singer' then name1
when occupation='actor' then name1
when occupation='professor' then name1
else null end as professions
from (
select occupation,name,concat(name,concat('(',(substring(occupation,1,1)),')')) as name1
from occupations)
a
union
select
concat(description,' ', summary,' ', profession)as office from
(select
description,occupation,profession,count(profession) as summary
from (
select
occupation,name,
'There are a total of' as description,
concat(occupation,'s') as profession
from occupations
)a
group by description,occupation,profession
)
b
Scenario:
Generate the following two result sets:
AnActorName(A)
, ADoctorName(D)
, AProfessorName(P)
, and ASingerName(S)
.There are a total of [occupation_count] [occupation]s.
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.
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)
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 then alphabetically by profession.
Regards,
Saravanan
Saravanan
November 4, 2017 at 9:40 am
It's asking you to generate two result sets, and you're only generating one. In trying to combine the two into one, you've added unnecessary complexity to the query.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 4, 2017 at 11:05 pm
Thanks Allen...
Can you kindly tell me how to generate two result sets...
Regards,
Saravanan
Saravanan
November 5, 2017 at 3:50 am
saravanatn - Saturday, November 4, 2017 11:05 PMThanks Allen...
Can you kindly tell me how to generate two result sets...
Regards,
Saravanan
Use 2 SELECT statements in the same query.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
November 5, 2017 at 6:30 am
Thanks Thorn. If possible can you kindly explain with a example...
Regards,
Saravanan
Saravanan
November 5, 2017 at 10:08 am
Thanks Thorn.. It worked....
Saravanan
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply