Documente Academic
Documente Profesional
Documente Cultură
II. Views
A view is a logical (or virtual) table based on one or more tables or views. A view contains no data itself. The
SELECT statement associated with the view is executed when the view is opened. Queries can use not only
physical tables but also views as data sources (tables found in the FROM clause).
Views in MySQL:
Q6. Create a view that determines the top 5 busiest actors (based on the number of films that they
have appeared in). Indicate the name of the view and SQL statement used in the view.
Heading of the view: actor_id, last_name, first_name, numfilms
Required: first and last rows
Q7. Using the view created above and other relevant tables in the sakila schema, provide the SQL
statement that displays the films of these 5 actors.
Heading: actor_id, last_name, first_name, title
Result: 199 rows
Required: 5th row
Q8. Create a view displays all countries along with the languages spoken in these countries and the
corresponding speaking population for each spoken language. The number of speakers should be
expressed (rounded up) as whole numbers.
Heading of the view: Country, Language, NumSpeakers
Result: 984 rows
Required: Name of the view and the SQL statement used in the view
Q9. Using the view above, provide the SQL statement that displays the total number of speakers for a
given language. The list should be sorted by the total number of speakers (in descending order).
Heading: Language Total Number of Speakers
Result: 457
Required: In what row is English found and what is its total speaking population?
Q10. Using the view in Q8 as the data source, create another view that determines, for each country,
its largest speaking population for a spoken language. Include only aggregate values that are
greater than 0 (use the HAVING clause).
Heading of the view: Country, NumSpeakers
Result: 213 rows
Required: Name of the view and the SQL statement used in the view
Q11. Using the two views created in Q8 and Q10, provide the SQL statement (use the appropriate join
operation) that will display the top spoken languages for each country, along with its speaking
population.
Heading of the view: Country, Language, NumSpeakers
Result: 213 rows; 1st row - Afghanistan, Pashto, 11905280
Required: 10th row
Views in Oracle
Q12. Create a view that provides information on all employees and their corresponding managers. All
employees should be included in the results generated from the view.
Heading of the view: EmpLast, EmpFirst, Salary, MgrLast, MgrFirst
Result: 107 rows
Required: Name of the view and the SQL statement used in the view
Q13. Using the view in Q12, provide the SQL statement that determines the employee under King who
gets the lowest salary.
Heading: EmpLast, EmpFirst, Salary
Required: resulting row