Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

SQL Assessment

S.no Question
Consider a table name - requests.
1 Columns- (request_id, created_time, dept).
Write a sql query to find the no of request_id per dept.

SELECT COUNT (request_id) FROM requests;

Write an SQL query to print the FIRST_NAME from Worker table after replacing ‘a’ with
2
‘A’

Select REPLACE(FIRST_NAME,'a','A') from Worker

Given a table EMPLOYEE with two columns EMP_ID and EMP_NAME, write a SQL query to
3
find name of employees which start with ‘N’?

Select * EMPLOYEE WHERE EMP_NAME LIKE ‘N%’;

Consider Table – requests. Columns- (created_date, id, Employee).

where created_date is a date column, id is an integer column, and employee is a string


column.
Write a SQL query to extract the day, month, and year of the created_date values in
separate columns
4
Example – created_ date
14/12/2022
Expected output – created_ date |day |month | year
14/12/2022 |14 | 12 | 2022

SELECT FROM request


EXTRACT (day from create_date) as day,
EXTRACT (month from create_date) as month,
EXTRACT (year from create_date) as year
FROM request
Table: Customers
Columns (id, name)

id is the primary key column for this table.


Each row of this table indicates the ID and name of a customer.

Table: Orders
Coulmns (id, customer_Id , total_value)
5
id is the primary key column for this table.
Customer_Id is a foreign key of the ID from the Customers table.
Each row of this table indicates the ID of an order , the ID of the customer who ordered it
and total_value.

Write an SQL query to report all customers who never ordered anything.

SELECT customer_Id AS 'Customers'


FROM Customers c
LEFT JOIN Orders o
ON c.Id = o.order_id
WHERE o.Order_Id IS NULL
For above customers and orders table in question 5 .
6 Write a sql query to Display the name and total number of orders for customers who
have placed orders with a total value greater than $1000.

Select *
from orders a
WHERE total_value > $1000

Consider a table EMPLOYEE with columns EMP_ID, DEPT_NO and SALARY. Write a query
7
to extract all employees who have salaries higher than the avg. of their department.

SELECT
DEPT_NO,
Avg(tblEMP_ID.Salary) AS DeptAvgSalary
FROM tblEmployeeInfo
GROUP BY DEPT_NO;
8 Write an SQL query to show only odd rows from a table worker.

SELECT * FROM worker WHERE mod(column_name,2) = 0;

Given table Student with columns student_id, DOB, gender. Write a query find number of
9 students whose DOB is between 02/05/1999 to 31/12/2001 and are grouped according to
gender.

Select DOB , gender ,count (Student) from Student Where DOB is between 02/05/1999 AND
31/12/2001 GROUP BY gender ;

Table - Employee
Columns ( id, name, salary, departmentId)
id is the primary key column for this table.
departmentId is a foreign key of the ID from the Department table.
Each row of this table indicates the ID, name, and salary of an employee. It also contains
the ID of their department.

Table: Department
10 Columns (id, name)
id is the primary key column for this table.
Each row of this table indicates the ID of a department and its name.

Write a sql query to find employees who earns the second highest salary in their
department

If the second highest salary is earned by multiple employees it should fetch multiple
employee details
SELECT MAX(SALARY) FROM Employee WHERE SALARY < (SELECT MAX(SALARY) FROM Employee);

Consider a table Sellers with columns (Seller_ID, Country, Month, Sales), write a query to
11
extract top 10 sellers by sales for each country.

SELECT Sellers, COUNT(SELLER_ID) AS SELLER_COUNT FROM SELLERS GROUP BY SALES ORDER BY 10


DESC

Consider a table that stores entry exit information for employees. Emp_log (Emp_id,
DateTime, Status). Status can be either in/out. Every time someone swipes his or her card
12
to enter or exit the building a new entry is created. Write a query to output how many
people are inside the building currently.

Select COUNT (Emp_id) from employees where Status is ‘in’ ;

You have a table called "products" with the following columns: id, name, price, and
13 quantity . write a SQL queries to return only the product names and prices where the
price is greater than 10

Select FROM products where price > 10 ;

14 Write a SQL query that adds the values in the first_name and last_name columns from
the customers table, separates them with a space, and stores the resulting string in a new
column called full_name.

SELECT first_name || ‘ ‘ || last_name AS full_name


FROM student;

Table – person, columns(id, email)


id is the primary key column for this table.
15 Each row of this table contains an email. The emails will not contain uppercase letters.

Write an SQL query to report all the duplicate emails

select Email
from Person
group by Email
having count(Email) > 1;

Login ID : abharnad

You might also like