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:
There are total [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.
the table is
occupations( name varchar(45), occupation varchar(25))
QUERY:
select concat(name,'(',left(occupation,1),')')
from occupations
order by name;
select concat('There are total ',count(occupation),' ',lower(occupation),'s','.')
from occupations
group by occupation
order by count(occupation),occupation;
output:
Aamina(D)
Ashley(P)
Belvet(P)
Britney(P)
Christeen(S)
Eve(A)
Jane(S)
Jennifer(A)
Jenny(S)
Julia(D)
Ketty(A)
Kristeen(S)
Maria(P)
Meera(P)
Naomi(P)
Priya(D)
Priyanka(P)
Samantha(A)
There are total 3 doctors.
There are total 4 actors.
There are total 4 singers.
There are total 7 professors.
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:
There are total [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.
the table is
occupations( name varchar(45), occupation varchar(25))
QUERY:
select concat(name,'(',left(occupation,1),')')
from occupations
order by name;
select concat('There are total ',count(occupation),' ',lower(occupation),'s','.')
from occupations
group by occupation
order by count(occupation),occupation;
output:
Aamina(D)
Ashley(P)
Belvet(P)
Britney(P)
Christeen(S)
Eve(A)
Jane(S)
Jennifer(A)
Jenny(S)
Julia(D)
Ketty(A)
Kristeen(S)
Maria(P)
Meera(P)
Naomi(P)
Priya(D)
Priyanka(P)
Samantha(A)
There are total 3 doctors.
There are total 4 actors.
There are total 4 singers.
There are total 7 professors.
No comments:
Post a Comment