Posts

Showing posts with the label Product base SQL intreview question

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----------------------------------------------------------------------------------------------------