Who has exactly 1 friend?
select name from personfriend group by name having count(*) = 1
What about more than 1?
select name from personfriend group by name having count(*) > 1
Who has a friend who is at least 40 years old?
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 do not also have a friend 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) except 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)