Você está na página 1de 11

Assignment 2

1. Display the first three highest prod_price with product_details.


2. Display the first three highest prod_price of product where Product_id is Null
with product Details.

Product_ID Company_Name Product_Type Product_Name Prod_Price


Null Ashok Leyland Null 3118T 8x4 1058608
Null Ashok Leyland Null Captain 1507056
Null Ashok Leyland Null U-Truck 1164131

3. Display all first 2 Prod_price from Product_details for each company_Name


with all the product details.

Product_ID Company_Name Product_Type Product_Name Prod_Price


1010 Ashok Leyland Truck JanBus 1507056
1005 Ashok Leyland Bus Eagle 1499708
2025 Videocon Group Mobile Videocon Infinium 14877
Z54
2018 Videocon Group DTH D2H 14705

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)

7. 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 and
predict the output for the same.

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.

Product_ID Company_Name Product_Type Product_Name Prod_Price


1001 Ashok Leyland Bus 12M 744643
1002 Ashok Leyland Bus 12M FESLF 1346136
1003 Ashok Leyland Bus Viking 879128
1004 Ashok Leyland Bus Cheetah 713266
1005 Ashok Leyland Bus Eagle 1499708

Bus Avarage_prod_price 1036576.2

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

Same result should display for all Product type.


Note: Use Co-related sub query and Analytical function.

11.Display maximum and minimum price for each product together from product
details table as below.

Company_Name Product_Type Prod_Price


Ashok Leyland Bus 713266
Ashok Leyland Bus 1499708
Ashok Leyland Truck 628910
Ashok Leyland Truck 1507056
Ashok Leyland Van 536129
Ashok Leyland Van 1237364
Videocon Group DTH 9111
Videocon Group DTH 14705
Videocon Group Mobile 11445
Videocon Group Mobile 14877
Videocon Group Retail 9923
Videocon Group Retail 13513
Ashok Leyland Null 573245
Ashok Leyland Null 1507056
Videocon Group Null 7000
Videocon Group Null 9000
12.State the difference between Max and min as below.
Note: Use Lead/Lag function.

Company_Name Product_Type Prod_Price Difference_Max_min


Ashok Leyland Bus 713266 786442
Ashok Leyland Bus 1499708 0
Ashok Leyland Truck 628910 878146
Ashok Leyland Truck 1507056 0
Ashok Leyland Van 536129 701235
Ashok Leyland Van 1237364
Videocon Group DTH 9111 difference
Videocon Group DTH 14705
Videocon Group Mobile 11445 difference
Videocon Group Mobile 14877
Videocon Group Retail 9923 difference
Videocon Group Retail 13513
Ashok Leyland Null 573245 difference
Ashok Leyland Null 1507056
Videocon Group Null 7000 difference
Videocon Group Null 9000

13.Display the customer details who have order the product which is not present
in product detail table as below.

Cust_id First_name Last_Name Product_id Quantity


5030 Jane Fisher 5050 8
5031 Jane Giba 6060 3
5032 Jane Fisher 7070 2
5033 Jane Emily 8080 1

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.

Existing Cust table Existing Customer_new Table


Cust Customer_New
ID Nm Cust_id Cust_Name
101 Faith 101 Faith
103 Felicity 101 Felicity
102 Fiona 101 Fiona
104 Emma 103 Emma
105 Emily 104 Emma
106 Faith 106 Faith
107 Felicity 107 Felicity
108 Mellissa 109 Fiona
109 Lina 109 Emma
110 Lavina 102 Emma
111 Perry 102 Null

Expected Customer_new Table


Customer_New
Cust_id Cust_Name
101 Faith
101 Faith
101 Faith
103 Felicity
104 Emma
106 Faith
107 Felicity
109 Lina
109 Lina
102 Fiona
102 Fiona
17.Delete the duplicate Records from Customer_New table 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

Note:Salary – first salary of each department.


25. What is the difference between WHERE and HAVING clause explain with the help of
example.
26. Display the hire_date of-currunt date (how many years working in company) employee
details.
27. Display the employee details along with firstname and lastname that has join after
current employee.
28. What is the role in Oracle explain with example.
29. What is the SQL * Loader in Oracle Explain with the help of example.
30. Explain the Self Join with example.
31. Display 5th record to 50 record from employee_details table.
32. Display 22nd ,52nd and 12th Record from Employee_details table.
33. Display 15 minimum salary from Employee details table.
34. What is difference between Rank and dense_Rank function explain with the help of
example.
35. Display records from updated_product_price where prod_price should be less than
minimum prod_price of curr_product_price and prod_price should not greater than
maximum prod_price of curr_product_price as below.

Curr_Prod_Price Updated Prod Price


Product_Type Prod_Price Product_Type Prod_Price
505 713266 101 70000
60 1099708 Max sal 105 1599708
666 628910 108 628910
303 150705 110 89000
202 536129 120 536129
202 989560 180 123000
303 9111 Min Sal 190 5010
505 14705 220 1470
404 11445 225 11445
808 14877 230 1877
707 9923 245 9923
909 13513 275 135130

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;

40.Predict the output of below query and understand it by executing.


SELECT first_name, job_id FROM employees
WHERE ( department_id, salary ) IN (
SELECT department_id, max( salary )
FROM employees GROUP BY department_id);

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

45.Write a query to generate sequence numbers from 1 to the specified number N?


Note: Use Connect By level clause(Hierarchical query).

Você também pode gostar