Given a table containing date, post_id, relationship (e.g. Friend, Group, Page), interaction (like, share etc.) and a table containing poster id and post id, calculate: how many likes were made on friend posts yesterday
Anonymous
first I would ask the following clarification: - do we want to know the total number of likes over all friend post or do we want the total like per poster_id? next I'll mention the "why?" are we answering that question: - I believe that the reason behind that question is for Facebook to measure the engagement level between friends when it comes to posts. Therefore, counting the number of likes between friends will give Facebook a good intuition about how much engagement there is between friends via posts. the following step would be the answer based on the clarification we got from our interviewer: select * from `interactions_table` where date = DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) and interaction = 'like' and relationship = 'friend' -- if we want per poster select poster_id, sum(interaction) as num_likes from ( select poster_id, post_id, interaction from `interactions_table` left join `postings_table` using (post_id) ) -- if we want total likes over all posts yesterday select sum(interaction) as num_likes from ( select post_id, interaction from `interactions_table` left join `postings_table` using (post_id) )
Check out your Company Bowl for anonymous work chats.