0% found this document useful (0 votes)
5 views2 pages

Single

The document outlines SQL queries for various operations including single-row functions, group functions, subqueries, and joins. It provides examples for counting employees, calculating average salaries, and retrieving employee information based on specific conditions. The queries demonstrate the use of COUNT(), AVG(), INNER JOIN, and LEFT JOIN to manipulate and retrieve data from employee and department tables.

Uploaded by

jannatjunior9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Single

The document outlines SQL queries for various operations including single-row functions, group functions, subqueries, and joins. It provides examples for counting employees, calculating average salaries, and retrieving employee information based on specific conditions. The queries demonstrate the use of COUNT(), AVG(), INNER JOIN, and LEFT JOIN to manipulate and retrieve data from employee and department tables.

Uploaded by

jannatjunior9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Single-Row Functions

Query 1: Using COUNT() to count the number of employees

SELECT UPPER(first_name), LOWER(last_name)

FROM employees;

2 Query 2: Using AVG() to calculate the average salary

SELECT department_id, AVG(salary) AS average_salary

FROM employees

GROUP BY department_id;

3.Group Functions

Query 1: Using COUNT() to count the number of employees

sql
Copy code
SELECT department_id, COUNT(*) AS employee_count
FROM employees
GROUP BY department_id;

Query 2: Using AVG() to calculate the average salary

sql
Copy code
SELECT department_id, AVG(salary) AS average_salary
FROM employees
GROUP BY department_id;
2. Subqueries

Query 1: Subquery to find employees with a salary higher than the average salary

sql
Copy code
SELECT first_name, last_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);

Query 2: Subquery to find employees in departments with more than 10 employees

sql
Copy code
SELECT first_name, last_name, department_id
FROM employees
WHERE department_id IN (SELECT department_id FROM employees GROUP BY
department_id HAVING CO
3. Joins

Query 1: Inner Join to get employee names and their department names

sql
Copy code
SELECT e.first_name, e.last_name, d.department_name
FROM employees e
INNER JOIN departments d
ON e.department_id = d.department_id;

Query 2: Left Join to get employee names and their manager's name

sql
Copy code
SELECT e.first_name AS Employee, m.first_name AS Manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.employee_id;

You might also like