SQL Assignments

SQL Assignments



Here are five basic-level SQL assignments to help you practice fundamental database querying skills:

**Assignment 1: Selecting Data**

Write a SQL query to retrieve all columns from the "employees" table.

**Assignment 2: Filtering Data**

Retrieve the names and ages of employees from the "employees" table who are older than 30.

**Assignment 3: Sorting Data**

Retrieve the names and salaries of employees from the "employees" table, sorted in descending order based on their salaries.

**Assignment 4: Aggregating Data**

Calculate the average salary of employees in the "employees" table.

**Assignment 5: Joining Tables**

Consider two tables, "employees" and "departments," with a common column "department_id." Write a query to retrieve the names of employees along with their corresponding department names.

Feel free to use a sample database or create your own tables to practice these assignments. Each assignment is designed to reinforce different aspects of SQL querying, from basic `SELECT` statements to filtering, sorting, aggregation, and joining tables. Happy querying!


Sample Data

CREATE TABLE employees (
    employee_id INT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    age INT,
    salary DECIMAL(10, 2),
    department_id INT
);

INSERT INTO employees VALUES
(1, 'Aryan', 'Sharma', 32, 60000.00, 1),
(2, 'Priya', 'Patel', 28, 55000.00, 2),
(3, 'Rahul', 'Verma', 35, 70000.00, 1),
(4, 'Aishwarya', 'Desai', 29, 60000.00, 2),
(5, 'Vikram', 'Reddy', 31, 65000.00, 1),
(6, 'Ananya', 'Chopra', 26, 50000.00, 2),
(7, 'Siddharth', 'Gupta', 33, 75000.00, 1),
(8, 'Tanvi', 'Kumar', 27, 58000.00, 2),
(9, 'Amit', 'Nair', 34, 72000.00, 1),
(10, 'Sneha', 'Rajput', 30, 67000.00, 2);

Contact us for software training, education or development










 

Post a Comment

0 Comments