0% found this document useful (0 votes)
240 views

SQL Assessment PDF

The document provides 19 questions on MySQL queries including: 1) Writing queries to identify number of sellers per country and extract sellers who joined on Mondays from a table. 2) Writing queries to extract alternate rows, employees with 3rd highest salary from tables. 3) Correcting a SQL query and describing the result of a join between two tables. 4) Writing advanced queries involving joins, aggregation, and conditional logic.

Uploaded by

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

SQL Assessment PDF

The document provides 19 questions on MySQL queries including: 1) Writing queries to identify number of sellers per country and extract sellers who joined on Mondays from a table. 2) Writing queries to extract alternate rows, employees with 3rd highest salary from tables. 3) Correcting a SQL query and describing the result of a join between two tables. 4) Writing advanced queries involving joins, aggregation, and conditional logic.

Uploaded by

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

MySQL Assignment

https://ksrconsultantservices.com/

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 3rd 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_id Jan_sales Feb_sales Mar_sales


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.

85275 06810, 9916961234 [email protected]


MySQL Assignment

https://ksrconsultantservices.com/

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_id Order_id Order_time


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

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: Output table:


Date Order ID Date Order Number of order in
2017/01/02 A ID the same month
2017/01/31 B 2017/01/02 A
2017/02/01 C 2017/01/31 B
2017/09/01 D 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.ksrconsultantservices.com .com United States
www.elezemns.ca .uk United Kingdom
www.elezemns.uk .in India
www.elezemn s.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?

85275 06810, 9916961234 [email protected]


MySQL Assignment

https://ksrconsultantservices.com/

Multiple Choice Questions


20. What type of join is needed when you wish to include rows that do not have matching values?

A. Equi-join B. Natural join


C. Outer join D. All of the above.
21. A CASE SQL statement is which of the following?

A. A way to establish an IF-THEN-ELSE in SQL. B. A way to establish a loop in SQL.


C. A way to establish a data definition in SQL. D. All of the above.
22. The following SQL is which type of join: SELECT CUSTOMER_T. CUSTOMER_ID, ORDER_T. CUSTOMER_ID, NAME,
ORDER_ID FROM CUSTOMER_T,ORDER_T WHERE CUSTOMER_T. CUSTOMER_ID = ORDER_T. CUSTOMER_ID
A. Equi-join B. Natural join
C. Outer join D. Cartesian join
23. A UNION query is which of the following?

A. Combines the output from no more than two queries and must include the same number of columns.
B. Combines the output from no more than two queries and does not include the same number of columns.

C. Combines the output from multiple queries and must include the same number of columns.

D. Combines the output from multiple queries and does not include the same number of columns.

24. Which of the following is a correlated subquery?

A. Uses the result of an inner query to determine the processing of an outer query.
B. Uses the result of an outer query to determine the processing of an inner query.

C. Uses the result of an inner query to determine the processing of an inner query.

D. Uses the result of an outer query to determine the processing of an outer query.
25. What is returned by INSTR(‘Elezemns India, ‘I’)?

A. 8 B. 10
C. Elezemns D. India
26. Q 8 - Which of the following code will remove all the rows from the table LOCATIONS?

A. DROP TABLE locations C. TRUNCATE TABLE locations


B. DELETE TABLE D. None of the above.
locations
27. What is returned by

MOD(1000,30)?

A. 33 B. 30
C. 3 D. 10

85275 06810, 9916961234 [email protected]


MySQL Assignment

https://ksrconsultantservices.com/

28. Which of the following query would display all the students where the second letter in the first name is ‘i’?

A. SELECT FIRST_NAME FROM STUDENTS WHERE FIRST_NAME LIKE ‘_i%’

B. SELECT FIRST_NAME FROM STUDENTS WHERE FIRST_NAME LIKE ‘%i_’;

C. SELECT FIRST_NAME FROM STUDENTS WHERE FIRST_NAME LIKE ‘%i%’;

D. SELECT FIRST_NAME FROM STUDENTS WHERE FIRST_NAME LIKE ‘_i_’;


29. Which code snippet will alter the table LOCATIONS and add a column named Address, with datatype VARCHAR2(100)?

A. ALTER TABLE locations ADD (address varchar2(100));

B. ALTER TABLE locations ADD COLUMN(address varchar2(100));

C. MODIFY TABLE locations ADD COLUMN (address varchar2(100));


D. None of the above.

85275 06810, 9916961234 [email protected]

You might also like