Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A table containing the students enrolled in a yearly course has incorrect data in records with ids
between 20 and 100 (inclusive).
TABLE enrollments
id INTEGER NOT NULL PRIMARY KEY
year INTEGER NOT NULL
studentId INTEGER NOT NULL
Write a query that updates the field 'year' of every faulty record to 2015.
Q2 (Sessions)
TABLE sessions
id INTEGER PRIMARY KEY,
userId INTEGER NOT NULL,
duration DECIMAL NOT NULL
Write a query that selects userId and average session duration for each user who has more
than one session.
Q3 (Paginate Users)
Q4 (Registrations)
Fill in the blanks so that the following select returns all registrations that were last active at least
30 days after being created.
SELECT name, create_date, last_activity FROM registrations WHERE ____ >= ____ (____,
INTERVAL 30 DAY);
Q5 (Cron)
MAILTO=candidate@xyz.org,admin@xyz.org
0 0,12 1 */4 * df -h /
0 6 1-12 * * /usr/bin/xyz_candidates
Select the statements about the job definitions and schedules that are correct.
_ The df command is executed at midday and midnight on the first day of every 4th month.
_ The df command is executed 12 times, each hour, between midday and midnight on the 1st of
April.
_ The MAILTO variable tells cron to email the output of df -h / to candidate@xyz.org and
admin@xyz.org.
_ Every hour of every day the current disk usage is appended to the /var/log/disk_usage log file.
_ The /usr/bin/xyz_candidates binary is executed at 6:00am every day.
Q6 (Workers)
An employee is a manager if any other employee has their managerId set to the first employees
id. An employee who is a manager may or may not also have a manager.
TABLE employees
id INTEGER NOT NULL PRIMARY KEY
managerId INTEGER REFERENCES employees(id)
name VARCHAR(30) NOT NULL
Write a query that selects the names of employees who are not managers.
The following two tables are used to define users and their respective roles:
TABLE users
id INTEGER NOT NULL PRIMARY KEY,
userName VARCHAR(50) NOT NULL
TABLE roles
id INTEGER NOT NULL PRIMARY KEY,
role VARCHAR(20) NOT NULL
The users_roles table should contain the mapping between each user and their roles. Each user
can have many roles, and each role can have many users.
● Only users from the users table can exist within users_roles.
● Only roles from the roles table can exist within users_roles.
● A user can only have a specific role once.
Given the following data definition, write a query that returns the number of students whose first
name is John. String comparisons should be case sensitive.
TABLE students
id INTEGER PRIMARY KEY,
firstName VARCHAR(30) NOT NULL,
lastName VARCHAR(30) NOT NULL
Q9 (Web Shop)
Each item in a web shop belongs to a seller. To ensure service quality, each seller has a rating.
The data are kept in the following two tables:
TABLE sellers
id INTEGER PRIMARY KEY,
name VARCHAR(30) NOT NULL,
rating INTEGER NOT NULL
TABLE items
id INTEGER PRIMARY KEY,
name VARCHAR(30) NOT NULL,
sellerId INTEGER REFERENCES sellers(id)
Write a query that selects the item name and the name of its seller for each item that belongs to
a seller with a rating greater than 4. The query should return the name of the item as the first
column and name of the seller as the second column.
Q10 (Pets)
TABLE dogs
id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL
TABLE cats
id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL