Show how many friends each person in the set has.
select name, count(*) from personfriend group by name
Who has the most friends?
select name from personfriend group by name order by count(*) desc limit 1
Who is friends with someone who is above 40?
select t1.name from person as t1 join personfriend as t2 on t1.name = t2.name where t2.friend in (select name from person where age > 40)
Who among them is also friends with someone who is under 30?
select t1.name from person as t1 join personfriend as t2 on t1.name = t2.name where t2.friend in (select name from person where age > 40) intersect select t1.name from person as t1 join personfriend as t2 on t1.name = t2.name where t2.friend in (select name from person where age < 30)