FAANG SQL INTERVIEW Question | Return IDs who has the highest rating

 DROP TABLE IF EXISTS Friends


CREATE TABLE Friends (

    id INT,

    friend_id INT 

);



DROP TABLE IF EXISTS Ratings


CREATE TABLE Ratings (

    id INT PRIMARY KEY,

    rating INT

);




INSERT INTO Friends (id, friend_id)

VALUES

(1, 2),

(1, 3),

(2, 3),

(3, 4),

(4, 1),

(4, 2),

(5,NULL),

(6,NULL);



INSERT INTO Ratings (id, rating)

VALUES

(1, 85),

(2, 90),

(3, 75),

(4, 88),

(5, 82),

(6, 91)



SELECT * FROM Friends


SELECT * FROM Ratings


-- Retrieve all Ids of a person whose rating is greater than friend's id

-- If person does not have any friend, retrieve only their id only if rating greater than 85

Comments

Popular posts from this blog

Mu Sigma SQL INTERVIEW QUESTION | Consecutive events count - Dataset 1

How to find all the customers who placed orders on three consecutive days | SQL Scenario questions

NTT DATA SQL INTERVIEW QUESTION | Solve 80/20 Pareto rule