0% found this document useful (0 votes)
40 views5 pages

SQL Learning Hub

Uploaded by

Richard Smith
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)
40 views5 pages

SQL Learning Hub

Uploaded by

Richard Smith
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/ 5

NAMASTESQL - DAY 55

100 DAY CODING PROBLEMS


NAMASTESQL - DAY 55

Step - 1 : Problem Statement

🤔𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭:

53 - LinkedIn Recommendation
The marketing team wants to send one recommendation post to each user . Write an SQL to find
out that one post id for each user that is liked by the most number of users that they follow.
Display user id, post id and no of likes.

Please note that team do not want to recommend a post which is already liked by the user. If for
any user, 2 or more posts are liked by equal number of users that they follow then select the
smallest post id, display the output in ascending order of user id.

Difficult Level : HARD

100 DAY CODING PROBLEMS


NAMASTESQL - DAY 55

Step - 2 : Identifying The Input Data And Expected


Output
INPUT
post

USER_ID POST_ID

1 100

2 100

3 200

4 300

5 300

1 300

2 300

3 400

4 400

5 400

1 400

post_likes

USER_ID FOLLOWS_USER_ID

1 2

1 3

1 4

2 1

2 3

2 4

3 1

3 2

4 1

100 DAY CODING PROBLEMS


NAMASTESQL - DAY 55
4 2

OUTPUT

USER_ID POST_ID NO_OF_LIKES

1 200 1

2 400 3

3 100 2

4 100 2

Step - 3 : Writing the sql query to solve the


problem

100 DAY CODING PROBLEMS


NAMASTESQL - DAY 55

100 DAY CODING PROBLEMS

You might also like