Sei sulla pagina 1di 4

Q1 (Enrollment)

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)

App usage data are kept in the following table:

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)

Consider the following table:

CREATE TABLE users (


id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL
);

The following query is used to paginate the table:

SELECT * FROM users ORDER BY username LIMIT 5 OFFSET 15;

Select all the true statements about this method of pagination.

(Select all acceptable answers.)

_ The query will return rows 5-15.


_ For the results of this query to be consistent, it must have an ​ORDER BY​ clause.
_ The OFFSET clause will have a negative performance impact when the offset value is large.
_ The LIMIT clause has a negative performance impact.

Q4 (Registrations)

Consider the following DDL statement:

CREATE TABLE registrations (


id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
create_date DATE NOT NULL,
last_activity DATE NOT NULL
);

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)

The output of ​crontab -l​ contains the following job definitions:

MAILTO=candidate@xyz.org,admin@xyz.org
0 0,12 1 */4 * df -h /

@hourly du -h / >> /var/log/disk_usage

0 6 1-12 * * /usr/bin/xyz_candidates

Select the statements about the job definitions and schedules that are correct.

(Select all acceptable answers.)

_ 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)

The following data definition defines an organization's employee hierarchy.

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.

Q7 (Users & Roles)

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.

Modify the provided SQLite ​create table​ statement so that:

● 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.

CREATE TABLE users_roles (


userId INTEGER,
roleId INTEGER
);
Q8 (Students)

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)

Information about pets is kept in two separate tables:

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

Write a query that select all distinct pet names.

Potrebbero piacerti anche