Write a query identifying the type of each record in the TRIANGLES table using its three side lengths. Output one of the following statements for each record in the table:
Equilateral: It's a triangle with sides of equal length.
Isosceles: It's a triangle with sides of equal length.
Scalene: It's a triangle with sides of differing lengths.
Not A Triangle: The given values of A, B, and C don't form a triangle.
SELECT CASE WHEN A+B <= C OR A+C <= B OR B+C <= A THEN 'Not A Triangle'
WHEN A = B AND B = C THEN 'Equilateral'
WHEN A = B OR B = C OR A = C THEN 'Isosceles'
WHEN A != B AND B != C AND A != C THEN 'Scalene'
END
FROM TRIANGLES;
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:
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.
SELECT Name || '(' || CASE WHEN Occupation = 'Actor' THEN 'A'
WHEN Occupation = 'Doctor' THEN 'D'
WHEN Occupation = 'Professor' THEN 'P'
WHEN Occupation = 'Singer' THEN 'S' END || ')'
FROM OCCUPATIONS
ORDER BY Name;
SELECT 'There are a total of ' || count(Occupation) || ' '|| LOWER(Occupation) || 's.'
FROM OCCUPATIONS
GROUP BY Occupation
ORDER BY count(Occupation), Occupation;
Pivot the Occupation column in OCCUPATIONS so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be Doctor, Professor, Singer, and Actor, respectively.
Note: Print NULL when there are no more names corresponding to an occupation.
SELECT MAX(DECODE(OCCUPATION, 'Doctor', NAME)) Doctor
, MAX(DECODE(OCCUPATION, 'Professor', NAME)) Professor
, MAX(DECODE(OCCUPATION, 'Singer', NAME)) Singer
, MAX(DECODE(OCCUPATION, 'Actor', NAME)) Actor
FROM (
SELECT OCCUPATION, NAME
, ROW_NUMBER() OVER(PARTITION BY OCCUPATION ORDER BY NAME) Rownumber
FROM OCCUPATIONS
)
GROUP BY Rownumber
ORDER BY doctor, Professor, Singer, Actor
;