Escolar Documentos
Profissional Documentos
Cultura Documentos
4. Display the Customer details who has purchase more than 1 product.
5. Diplay the Customer details who has purchase 1 product more than one.
6. Display the first_name and last_name from employee_details table who has
not purchase any product.(Set Operator/Not IN)
Cust Cust_Prod
ID Nm No Name Prod
101 Faith 108 Faith Planet M
Null Felicity Null Felicity Planet M
110 Fiona 101 Jan DigiWorld
103 Emma 103 Fisher DigiWorld
104 Emma 104 Emma Planet M
Null Faith Null Faith Planet M
102 Felicity 101 Faith DigiWorld
105 Fiona 105 Cornish DigiWorld
104 Emma 104 Null DigiWorld
Null Emma Null Emma DigiWorld
Null Null 101 Faith JanBus
Null Null U-Truck
8. Write a Query to perform joins (INNER, LEFT OUTER,RIGHT OUTER,FULL
OUTER,CROSS) below Cust and Cust_Prod table on id and No column as well
as Nm and Name column and predict the output for the same.
9. Write a queries to perform the all the set operators on id,nm and No,Name
column of Cust and Cust_prod table and predict the result.
10.Writer a query to get the product details where prod_price is greater than
average product price of respective product type.
Refere the below example.
Expected Result.
Product_ID Company_Name Product_Type Product_Name Prod_Price
1002 Ashok Leyland Bus 12M FESLF 1346136
1005 Ashok Leyland Bus Eagle 1499708
11.Display maximum and minimum price for each product together from product
details table as below.
13.Display the customer details who have order the product which is not present
in product detail table as below.
14.List out the product details which is not purchase by any customer.
15.Write a query to join on product_id of the 2nd half of data from
Product_details table with 1st half of data from Customer_details table.
16. Update Customer_Detail table with Cust table values as below.
Source Target
Customer_New Customer_New
Cust_id Cust_Name Cust_id Cust_Name
101 Faith 101 Faith
101 Faith 103 Felicity
101 Faith 104 Emma
103 Felicity 106 Faith
104 Emma 107 Felicity
106 Faith 109 Lina
107 Felicity 102 Fiona
109 Lina
109 Lina
102 Fiona
102 Fiona
18.State the difference between IN and EXISTS clause with the help of example.
19.Find out the employee details with salary who has purchase the bus .
Note :Use join on Customer_details, Employee_Details and Product on
appropriate columns.
20. List out Employee details who is not working in ‘Research and Development’,
‘Accounting and Finance’ and ‘Information Technology’ Department.
21. List out the Employee details who’s salary is greater than the (maximum
salary – minimum) salary.
22. Write a queries to perform the (INNER,LEFT OUTER,RIGHT,FULL OUTER JOIN
,CROSS JOIN ,NATURAL JOIN) on Tab1 and Tab2 table on both columns(id,
nm).
TAB1 TAB1
ID NM ID NM
1 V 1 A
1 B 1 B
3 V 2 V
3 V 3 V
0 V 0 V
null B null B
2 V 2 V
null A null B
1 A 1 A
null Null null null
Also predict the output for each join.
23. Write a queries to perform the Set Operation (UNION ,UNION
ALL,INTERSECT,MINUS) on Tab1 and Tab2 table on both columns(id, nm).
TAB1 TAB1
ID NM ID NM
1 V 1 A
1 B 1 B
3 V 2 V
3 V 3 V
0 V 0 V
null B null B
2 V 2 V
null A null B
1 A 1 A
null Null null null
Also predict the output for each set operation.
24. Write a query get the expected result as below.
Employee_Details
Emp_id First_name Last_Name Department_id Email_id Salary
101 Abigail Abraham 10_Prod Abigail_Abraham@priory.com 99446
102 Alexandra Allan 10_Prod Alexandra_Allan@priory.com 35106
103 Alison Alsop 10_Prod Alison_Alsop@priory.com 60137
104 Amanda Anderson 10_Prod Amanda_Anderson@priory.com 34888
105 Amelia Arnold 10_Prod Amelia_Arnold@priory.com 22362
106 Amy Avery 20_R&D Amy_Avery@priory.com 46237
107 Andrea Bailey 20_R&D Andrea_Bailey@priory.com 9347
108 Angela Baker 20_R&D Angela_Baker@priory.com 27937
109 Anna Ball 20_R&D Anna_Ball@priory.com 63958
110 Anne Bell 30_Purchase Anne_Bell@priory.com 25000
111 Audrey Berry 30_Purchase Audrey_Berry@priory.com 24070
112 Ava Black 20_R&D Ava_Black@priory.com 58388
113 Bella Blake 20_R&D Bella_Blake@priory.com 81680
114 Bernadette Bond 40_Marketing Bernadette_Bond@priory.com 68857
115 Carol Bower 40_Marketing Carol_Bower@priory.com 35346
116 Caroline Brown 40_Marketing Caroline_Brown@priory.com 80291
Employee_Details
Emp_id First_name Last_Name Department_id Salary Expected Salary
101 Abigail Abraham 10_Prod 99446 0
102 Alexandra Allan 10_Prod 35106 64340
103 Alison Alsop 10_Prod 60137 39309
104 Amanda Anderson 10_Prod 34888 64558
105 Amelia Arnold 10_Prod 22362 77084
106 Amy Avery 20_R&D 46237 0
107 Andrea Bailey 20_R&D 9347 36890
108 Angela Baker 20_R&D 27937 18300
109 Anna Ball 20_R&D 63958 -17721
110 Anne Bell 30_Purchase 25000 0
111 Audrey Berry 30_Purchase 24070 930
112 Ava Black 20_R&D 58388 -12151
113 Bella Blake 20_R&D 81680 -35443
114 Bernadette Bond 40_Marketing 68857 0
115 Carol Bower 40_Marketing 35346 33511
116 Caroline Brown 40_Marketing 80291 -11434
Expected Result
Updated Prod Price
Product_Type Prod_Price
108 628910
110 89000
120 536129
180 123000
225 11445
245 9923
275 135130
101 70000
36. Differerence between Row_number(),Rank() and Dense_Rank() explain with the help of
examples.
37. SELECT
COUNT(1),COUNT(null),AVG(prod_price),COUNT(prod_price),sum(product_type)
from curr_prod_price;
Predict the output of this query on below table.
Curr_Prod_Price
Product_Type Prod_Price
505 713266
60 80000
666 628910
303 150705
202 536129
202 90000
303 9111
505 14705
404 11445
808 14877
707 9923
909 13513
9080 Null
190 Null
180 Null
280 null
38.Find out the remaining target of salesman as below.
Salesman_Target Salesman_Sale
Name Target Name Sale
Claire 10000 Claire 2000
Tom 6000 Claire 4000
Amt 5000 Claire 2100
John 9000 John 3000
John 3400
John 2010
Tom 2300
Tom 150
Tom 300
Amt 200
Expected Result
Salesman_Remaining_Target
Name Remaing target
Claire 21900
Tom xxxxxxx
Amt xxxxxxx
John xxxxxxx
39.Predict the output of below query and try to understand by executing it.
SELECT
COUNT( CASE WHEN salary < 2000 THEN 1 ELSE NULL END ) count1,
COUNT( CASE WHEN salary BETWEEN 2001 AND 4000 THEN 1 ELSE NULL
END ) count2,
COUNT( CASE WHEN salary > 4000 THEN 1 ELSE NULL END ) count3
FROM employees;
41.What is the execution plan and how we can see the execution plan?
42.Get the top 3 highest paid employees for each dept.
43.List out the department where one or less than one employee working.
44.Writer a query to get the output as below.
Source
Department_Details
Department_Name Department_Id
Production 10_Prod
Research and Development 20_R&D
Purchasing 30_Purchase
Marketing 40_Marketing
Human Resource Management 50_HR
Accounting and Finance 60_Acc_Fin
Information Technology 70_IT
Sales 80_Sales
Expected Output
Department_Details
Department_Name Department_Id
Production Ten_Prod
Research and Development Twenty_R&D
Purchasing Thirty_Purchase
Marketing Fourty_Marketing
Human Resource Management Fifty_HR
Accounting and Finance Sixty_Acc_Fin
Information Technology Seventy_IT
Sales Eighty_Sales