human
Schema:
Customer_Master_Index (master_customer_id, cmi_details)
CMI_Cross_References (cmi_cross_ref_id, master_customer_id, source_system_code)
Council_Tax (council_tax_id, cmi_cross_ref_id)
Business_Rates (business_rates_id, cmi_cross_ref_id)
Benefits_Overpayments (council_tax_id, cmi_cross_ref_id)
Parking_Fines (council_tax_id, cmi_cross_ref_id)
Rent_Arrears (council_tax_id, cmi_cross_ref_id)
Electoral_Register (electoral_register_id, cmi_cross_ref_id)
Please answer with SQL.
assistant
Sure, I understand.
human
How many business rates are there?
assistant
SELECT COUNT( * ) FROM Business_Rates;
human
What are the distinct cmi cross reference ids in those business rates?
assistant
SELECT cmi_cross_ref_id FROM Business_Rates GROUP BY cmi_cross_ref_id;
human
Show me the number of business rates related to each of them.
assistant
SELECT cmi_cross_ref_id , COUNT( * ) FROM Business_Rates GROUP BY cmi_cross_ref_id;
human
Include the master customer id too.
assistant
SELECT T2.cmi_cross_ref_id , T2.master_customer_id , COUNT( * ) FROM Business_Rates AS T1 JOIN CMI_Cross_References AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id GROUP BY T2.cmi_cross_ref_id ;