human
Schema:
member (Member_ID, Card_Number, Name, Hometown, Level)
branch (Branch_ID, Name, Open_year, Address_road, City, membership_amount)
membership_register_branch (Member_ID, Branch_ID, Register_Year)
purchase (Member_ID, Branch_ID, Year, Total_pounds)
Please answer with SQL.
assistant
Sure, I understand.
human
Find the name of branches where have some members whose hometown is in Louisville, Kentucky and some in Hiram, Georgia.
assistant
SELECT T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id JOIN member AS T3 ON T1.member_id = T3.member_id WHERE T3.Hometown = 'Louisville , Kentucky' INTERSECT SELECT T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id JOIN member AS T3 ON T1.member_id = T3.member_id WHERE T3.Hometown = 'Hiram , Georgia'
human
How many branches where have more than average number of memberships are there?
assistant
SELECT count(*) FROM branch WHERE membership_amount > (SELECT avg(membership_amount) FROM branch)
human
Show the member name and hometown who registered a branch in 2016.
assistant
SELECT T2.name , T2.hometown FROM membership_register_branch AS T1 JOIN member AS T2 ON T1.member_id = T2.member_id WHERE T1.register_year = 2016
human
What are names for top three branches with most number of membership?
assistant
SELECT name FROM branch ORDER BY membership_amount DESC LIMIT 3
human
Show member names without any registered branch.
assistant
SELECT name FROM member WHERE member_id NOT IN (SELECT member_id FROM membership_register_branch)
human
What are the names and cities of the branches that do not have any registered members?
assistant
SELECT name , city FROM branch WHERE branch_id NOT IN ( SELECT branch_id FROM membership_register_branch ) ;