Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

SQL Queries Interview Questions - Oracle Part 4

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

SQL Queries Interview Questions - Oracle Part 4

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

11/29/2018 SQL Queries Interview Questions - Oracle Part 4

Home Data Warehouse Informatica Informatica Scenarios Informatica Cloud Oracle Unix Hadoop

Search... Search
SQL Queries Interview Questions - Oracle Part 4
1. Consider the following friends table as the source
Popular Posts

Informatica Scenario Based Interview Questions with


Answers - Part 1

Name, Friend_Name Unix Sed Command to Delete Lines in File - 15 Examples


-----------------
sam, ram String Functions in Hive

sam, vamsi
Top Examples of Awk Command in Unix
vamsi, ram
vamsi, jhon Sed Command in Unix and Linux Examples
ram, vijay
ram, anand Design/Implement/Create SCD Type 2 Effective Date
Mapping in Informatica

Date Functions in Hive


Here ram and vamsi are friends of sam; ram and jhon are friends of vamsi and so on. Now write
SQL Queries Interview Questions - Oracle Part 1
a query to find friends of friends of sam. For sam; ram,jhon,vijay and anand are friends of
friends. The output should look as Top Unix Interview Questions - Part 1

Update Strategy Transformation in Informatica

Name, Friend_of_Firend
----------------------
Have Questions? Follow Me
sam, ram
sam, jhon
sam, vijay
sam, anand

https://www.folkstalk.com/2011/11/oracle-scenario-based-questions-part-2.html 1/6
11/29/2018 SQL Queries Interview Questions - Oracle Part 4

vijay bhaskar
Solution: Add to circles

SELECT f1.name,
f2.friend_name as friend_of_friend
FROM friends f1,
friends f2
WHERE f1.name = 'sam'
AND f1.friend_name = f2.name;

2. This is an extension to the problem 1. In the output, you can see ram is displayed as friends of
friends. This is because, ram is mutual friend of sam and vamsi. Now extend the above query to
exclude mutual friends. The outuput should look as
994 have me in circles View all

Name, Friend_of_Friend
----------------------
sam, jhon
sam, vijay
sam, anand

Solution:

SELECT f1.name,
f2.friend_name as friend_of_friend
FROM friends f1,
friends f2
WHERE f1.name = 'sam'
AND f1.friend_name = f2.name
AND NOT EXISTS
(SELECT 1 FROM friends f3

https://www.folkstalk.com/2011/11/oracle-scenario-based-questions-part-2.html 2/6
11/29/2018 SQL Queries Interview Questions - Oracle Part 4

WHERE f3.name = f1.name


AND f3.friend_name = f2.friend_name);

3. Write a query to get the top 5 products based on the quantity sold without using the
row_number analytical function? The source data looks as

Products, quantity_sold, year


-----------------------------
A, 200, 2009
B, 155, 2009
C, 455, 2009
D, 620, 2009
E, 135, 2009
F, 390, 2009
G, 999, 2010
H, 810, 2010
I, 910, 2010
J, 109, 2010
L, 260, 2010
M, 580, 2010

Solution:

SELECT products,
quantity_sold,
year
FROM
(
SELECT products,
quantity_sold,
year,
rownum r
from t
https://www.folkstalk.com/2011/11/oracle-scenario-based-questions-part-2.html 3/6
11/29/2018 SQL Queries Interview Questions - Oracle Part 4

ORDER BY quantity_sold DESC


)A
WHERE r <= 5;

4. This is an extension to the problem 3. Write a query to produce the same output using
row_number analytical function?

Solution:

SELECT products,
quantity_sold,
year
FROM
(
SELECT products,
quantity_sold,
year,
row_number() OVER(
ORDER BY quantity_sold DESC) r
from t
)A
WHERE r <= 5;

5. This is an extension to the problem 3. write a query to get the top 5 products in each year
based on the quantity sold?

Solution:

SELECT products,
quantity_sold,
year
FROM
(
https://www.folkstalk.com/2011/11/oracle-scenario-based-questions-part-2.html 4/6
11/29/2018 SQL Queries Interview Questions - Oracle Part 4

SELECT products,
quantity_sold,
year,
row_number() OVER(
PARTITION BY year
ORDER BY quantity_sold DESC) r
from t
)A
WHERE r <= 5;

Recommended Posts:

SQL Queries Interview Questions - Oracle Part 1


SQL Queries Interview Questions - Oracle Part 2
SQL Queries Interview Questions - Oracle Part 3
SQL Queries Interview Questions - Oracle Part 4
SQL Queries Interview Questions - Oracle Part 5

No comments:

Post a Comment

Enter your comment...

Comment as: Google Accoun

Publish Preview

https://www.folkstalk.com/2011/11/oracle-scenario-based-questions-part-2.html 5/6
11/29/2018 SQL Queries Interview Questions - Oracle Part 4

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

https://www.folkstalk.com/2011/11/oracle-scenario-based-questions-part-2.html 6/6

You might also like