MBO SQL - Assessment - 30questions
MBO SQL - Assessment - 30questions
MBO SQL - Assessment - 30questions
1. Given a table SELLERS with 3 column SELLER_ID, COUNTRY and JOINING_DATE, write a query to identify number of sellers per
country and order it in descending order of no. of sellers
2. For the table in question 1 write a query to extract all sellers who joined on a Monday.
3. Given a table EMPLOYEE with two columns EMP_ID and SALARY, how can we extract alternate rows from a table?
4. Given a table EMPLOYEE with two columns EMP_ID and SALARY, extract the employees with the 3 rd highest salary.
5. What is wrong with this SQL query? Correct it so it executes properly.
SELECT ID, YEAR(BILLINGDATE) BILLINGYEAR
FROM INVOICES
WHERE BILLINGYEAR >= 2010;
6. Assume a schema of EMP ( ID, NAME, DEPTID ) , DEPT ( ID, NAME).
If there are 10 records in the EMP table and 5 records in the DEPT table, how many rows will be displayed in the result of the
following SQL query:
SELECT * FROM EMP, DEPT
7. What is the difference between Having and Where clause?
8. Consider a table EMPLOYEE with columns EMP_ID and SALARY with unknown number of records. Write a query to extract top
25% of the records based on salary?
9. Consider a table EMPLOYEE with columns EMP_ID, DEPT_NO and SALARY. Write a query to extract all employees who have
salaries higher than the avg. of their department.
10. Consider a table EMPLOYEE with columns EMP_ID and SALARY. Write a select query to output a rank against each record. The
rank must be based on the salary(rank 1 for the highest salary)
11. Given two table SELLER(Seller_ID, Country_code) Country (Country_code , Country_name), write a query that outputs Seller_ID,
Country_Name. For country_codes that do not exist in Country table the output must print “NA”.
12. For the tables in question 11, write a query to extract seller_id s that do not have a matching country_code in country table.
13. Consider a table Sellers with columns (Seller_ID, Country, Month, Sales), write a query to extract top 10 sellers by sales for each
country.
14. If the table in question 13 has data for first 6 months in year 2015 for each seller, write a query to extract data in the following
format
Seller_i Jan_sales Feb_sales Mar_sales
d
34521 5000 45000 35000
15. For the table in question 13, write a query to extract the total sales, month in which minimum sales occurs and month in which
maximum sales occurs by country.
16. Write a query to calculate time difference (in days) between current and previous order of each customer for every row? What is
the avg time difference between two orders for every customer?
Customer_i Order_id Order_time
d
1 A 2017/02/12 10:09:24
1 B 2017/06/01 14:07:30
1 C 2017/09/11 01:01:01
2 D 2016/01/01 12:00:00
2 E 2017/10/01 08:00:00
3 F 2017/03/01 05:00:01
3 G 2017/06/17 20:00:50
MLP - SQL ASSESSMENT
17. Write a query to populate number of orders in the same month as a separate column in each row of the input table?
Input table:
Date Order ID
2017/01/02 A
2017/01/31 B
2017/02/01 C
2017/09/01 D
Output table:
MLP - SQL ASSESSMENT
MLP - SQL ASSESSMENT
Date Order ID Number of order in
the same month
2017/01/02 A
2017/01/31 B
2017/02/01 C
2017/09/01 D
18. Perform a join between the two tables to map country to each URL in table 1
URL Suffix Country
www.amazon.com .com United States
www.amazon.ca .uk United Kingdom
www.amazon.uk .in India
www.amazon.in .ca Canada
19. Given tables as below, write SQL queries to return results as requested.
Orders (Order_id, Package_count, Order_time, promised_delivery_time)
Routes (Plan_id, Route_id, Order_id, Route_Length)
Plans (Warehouse, Plan_id, Route_id, plan_creation_time)
Relations
Plans => Routes : 1 to many
Routes => Orders : 1 to many
A. How Many Orders did warehouse 'ABC' plan yesterday?
B. How many orders were in the last plan yesterday for each warehouse?