0% found this document useful (0 votes)
7 views

Exercises Query SQL

The document contains four SQL exercises involving queries on multiple schemas representing data about students and classes, police data, employee data, and art/artist data. The exercises involve writing queries to retrieve aggregated data, filter on specific conditions, and join across multiple tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Exercises Query SQL

The document contains four SQL exercises involving queries on multiple schemas representing data about students and classes, police data, employee data, and art/artist data. The exercises involve writing queries to retrieve aggregated data, filter on specific conditions, and join across multiple tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Course: 2023/2024

Data Base
Bachelor in Data Science and Engineering
SUBJECT: 2 Exercises (Topic 2.2: Queries. SQL)

1.- Consider the following schema:

The meaning of these relations is straightforward; for example, enrolled has one
record per student-class pair such that the student is enrolled in the class.
Write the following queries in SQL.
a. Select the Level and the average age of students for that Level, for each Level.
b. Select the Level and the average age of students for that Level, for all Levels
except JR.
c. Select the names of students who are not enrolled in any class.

2.- Consider the following schema:

POLICE_STATION (District, Address, Phone)

BELONGS (District CodePoliceOfficer, StartDate, EndDate *)


(DC,UC) (DC,UC)

POLICE_OFFICER (Code, ID, Name)

CRIMINALS (Code, Name, Alias, Type)

COMMON (Code, Zone, Address)


(DC,UC)

NONCOMMON (Code, Description)


(DC,UC)

RECORD (CodeCriminal, Number, Description, StartDate, Status)


(DC,UC)

CRIMINAL.Type={common, noncommon}
RECORD.Status ={open, close}

1
Write the following queries in SQL.
a. Select criminals (code and number) from open records of non-common
criminals.
b. Select for each police station: district and the number of police officers
ordered by the name.
c. Select for each criminal: code, name, alias, type and the number of records
associated.

3.- Consider the following schema:

EMPLOYEES (employee_id, last_name, dept_id, job_id)

DEPARTMENTS (department_id, dept_name, location_id)

JOB (job_id, job_title)

Write the following queries in SQL.


a. Select first_name, last_name, job_id, job_title of the employees with their
department greater than 80.
b. Select first_name, last_name, department_id, department_name from
employees.
c. Select first_name, last_name, department_id, department_name of the
employees who’s last_name is 'Higgins';
d. Select the last_name and job_title of the employees
e. Select the last_name and job_title of the employees who’s last_names start with
H.
f. Select the lastname, department_id and de_department_name of the
employees, including those that are not assigned to any department.
g. Select the lastname, department_id and de_department_name of the
employees, including those departments without associated employees.
h. Select the lastname, department_id and de_department_name of the
employees, including employees with no assigned department, and
departments without assigned employee

4.- Consider the following schema:


• The database keeps the information about artists, their names (unique),
birthplaces, ages, and art style.
• The information about a piece of artwork, such as the year each piece was
made, its unique title, the type of art (e.g., painting, lithograph, sculpture,
photography) and the price for each piece of artwork must be stored.
• Pieces of artwork are also classified into groups of various kinds, such as, for
example, portraits; still, life, or works of the 19th century; any given piece may

2
belong to more than one group. Each group is identified by a name that
describes the group.
• Finally, the database keeps the information about customers. For each
customer, the database stores that person’s unique name, address, the total
amount of dollars spent in the gallery and the artists and groups of art that the
customer tends to like.
A possible solution is:

ARTWORK. Type={painting, lithograph, sculpture, photography}

Following last scheme, make the following queries:


a. List of the artworks indicating the title, year and name of the artist
b. List the names of the groups indicating how many artworks they have.
c. List of artists that any customer does not like.
d. List of artworks that the client "Mary" likes grouped by the name of the artist.

You might also like