Tuesday, November 8, 2022

Product base SQL intreview question


---------Write a query to find PersonID,Name,Number of friends, and sum of marks of person who have friends with total score greater then 100-----------


-------------------START----------------------------------------------------------------------------

select * from [ Person_Table]


SELECT * FROM [dbo].[Friend]



WITH CTE1 AS
(
SELECT A.PersonID, count (A.PersonID) as "No of friends", SUM(B.Score) as "Total Marks"
FROM [dbo].[Friend] A
INNER JOIN [ Person_Table] B ON A.FriendID = B.PersonID
group by  A.PersonID
Having SUM(B.Score) >100
)
SELECT P.*,CTE1.[No of friends],CTE1.[Total Marks]
FROM [ Person_Table] P
INNER JOIN CTE1 ON CTE1.PersonID=P.PersonID



--------------END----------------------------------------------------------------------------------------------------



No comments:

Post a Comment

"🚀 Delta Lake's Vectorized Delete: The Secret to 10x Faster Data Operations!"

"🚀 Delta Lake's Vectorized Delete: The Secret to 10x Faster Data Operations!" Big news for data engineers! Delta Lake 2.0+ in...