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
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
List the branch name and city without any registered members.
assistant
SELECT name , city FROM branch WHERE branch_id NOT IN (SELECT branch_id FROM membership_register_branch)
human
Show name, address road, and city for all branches sorted by open year.
assistant
SELECT name , address_road , city FROM branch ORDER BY open_year
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
Show all branch names with the number of members in each branch registered after 2015.
assistant
SELECT T2.name , count(*) FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id WHERE T1.register_year > 2015 GROUP BY T2.branch_id
human
Show all member names and registered branch names sorted by register year.
assistant
SELECT T3.name , 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 ORDER BY T1.register_year ;