#272 SQL Queries for Employees and Exercises
The following tables are given:
CREATE TABLE employees (
id INT PRIMARY KEY,
head_id INT,
name VARCHAR(1000),
age INT,
CONSTRAINT employees_head_fk
FOREIGN KEY (head_id) REFERENCES employees(id)
);
CREATE TABLE exercises (
id INT PRIMARY KEY,
name VARCHAR(1000),
employee_id INT,
created_at DATE,
CONSTRAINT exercises_employee_fk
FOREIGN KEY (employee_id) REFERENCES employees(id)
);
It is necessary to:
-
Get all employees whose
namebegins withIvanovorPetrovand whoseageis greater than 18. - Count the number of exercises during the last 6 months for each employee. Consider only employees aged from 25 to 35. Display the manager name, employee name, and exercise count. Skip employees with fewer than three exercises. Sort by exercise count in descending order.
-
Get the three latest exercises for every employee:
id,employee_name,exercise_name, andcreated_at.
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor