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
How many membership registrations are there in 2016?
assistant
SELECT COUNT( * ) FROM membership_register_branch WHERE register_year = 2016;
human
What about for each branch?
assistant
SELECT branch_id , COUNT( * ) FROM membership_register_branch WHERE register_year = 2016 GROUP BY branch_id;
human
Show me the name of branch with the most of them.
assistant
SELECT T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id WHERE T1.register_year = 2016 GROUP BY T2.branch_id ORDER BY COUNT( * ) DESC LIMIT 1;
human
What about its open year?
assistant
SELECT T2.name , T2.open_year FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id WHERE T1.register_year = 2016 GROUP BY T2.branch_id ORDER BY COUNT( * ) DESC LIMIT 1 ;