Database: network_1

Question: How many high schoolers are there in grade 9 or 10?
SQL: SELECT count(*) FROM Highschooler WHERE grade  =  9 OR grade  =  10

Question: Which grade has the most high schoolers?
SQL: SELECT grade FROM Highschooler GROUP BY grade ORDER BY count(*) DESC LIMIT 1

Question: Show me all grades that have at least 4 students.
SQL: SELECT grade FROM Highschooler GROUP BY grade HAVING count(*)  >=  4

Question: Show the names of high school students and their corresponding number of friends.
SQL: SELECT T2.name, count(*) FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id GROUP BY T1.student_id

Question: What is the name of the high schooler who has the greatest number of friends?
SQL: SELECT T2.name FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id GROUP BY T1.student_id ORDER BY count(*) DESC LIMIT 1

Question: Show the names of high schoolers who have at least 3 friends.
SQL: SELECT T2.name FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id GROUP BY T1.student_id HAVING count(*)  >=  3

Question: Show the names of all of the high schooler Kyle's friends.
SQL: SELECT T3.name FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id JOIN Highschooler AS T3 ON T1.friend_id  =  T3.id WHERE T2.name  =  "Kyle"

Question: How many friends does the high school student Kyle have?
SQL: SELECT count(*) FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id WHERE T2.name  =  "Kyle"

Question: Show ids of all students who do not have any friends.
SQL: SELECT id FROM Highschooler EXCEPT SELECT student_id FROM Friend

Question: Show names of all high school students who do not have any friends.
SQL: SELECT name FROM Highschooler EXCEPT SELECT T2.name FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id

Question: Show the ids of high schoolers who have friends and are also liked by someone else.
SQL: SELECT student_id FROM Friend INTERSECT SELECT liked_id FROM Likes

Question: Show name of all students who have some friends and also are liked by someone else.
SQL: SELECT T2.name FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id INTERSECT SELECT T2.name FROM Likes AS T1 JOIN Highschooler AS T2 ON T1.liked_id  =  T2.id

Question: Show the names of high schoolers who have likes, and numbers of likes for each.
SQL: SELECT T2.name ,  count(*) FROM Likes AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id GROUP BY T1.student_id

Question: What is the name of the high schooler who has the greatest number of likes?
SQL: SELECT T2.name FROM Likes AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id GROUP BY T1.student_id ORDER BY count(*) DESC LIMIT 1

Question: Show the names of students who have at least 2 likes.
SQL: SELECT T2.name FROM Likes AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id GROUP BY T1.student_id HAVING count(*)  >=  2

Question: Show the names of students who have a grade higher than 5 and have at least 2 friends.
SQL: SELECT T2.name FROM Friend AS T1 JOIN Highschooler AS T2 ON T1.student_id  =  T2.id WHERE T2.grade  >  5 GROUP BY T1.student_id HAVING count(*)  >=  2