SQL Assessment - Answer Sheet
SQL Assessment - Answer Sheet
SQL Assessment - Answer Sheet
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.
Write an SQL query to print the FIRST_NAME from Worker table after replacing ‘a’ with
2
‘A’
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’?
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 *
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.
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.
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.
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
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 Email
from Person
group by Email
having count(Email) > 1;
Login ID : abharnad