Database schema:
CREATE TABLE Agencies (
  agency_id NUMBER PRIMARY KEY,
  agency_details TEXT
);
CREATE TABLE Staff (
  staff_id NUMBER PRIMARY KEY,
  agency_id NUMBER,
  staff_details TEXT
);
CREATE TABLE Clients (
  client_id NUMBER PRIMARY KEY,
  agency_id NUMBER,
  sic_code TEXT,
  client_details TEXT,
  FOREIGN KEY (agency_id) REFERENCES Agencies(agency_id)
);
CREATE TABLE Invoices (
  invoice_id NUMBER PRIMARY KEY,
  client_id NUMBER,
  invoice_status TEXT,
  invoice_details TEXT,
  FOREIGN KEY (client_id) REFERENCES Clients(client_id)
);
CREATE TABLE Meetings (
  meeting_id NUMBER PRIMARY KEY,
  client_id NUMBER,
  meeting_outcome TEXT,
  meeting_type TEXT,
  billable_yn TEXT,
  start_date_time TIME,
  end_date_time TIME,
  purpose_of_meeting TEXT,
  other_details TEXT,
  FOREIGN KEY (client_id) REFERENCES Clients(client_id)
);
CREATE TABLE Payments (
  payment_id NUMBER,
  invoice_id NUMBER,
  payment_details TEXT,
  FOREIGN KEY (invoice_id) REFERENCES Invoices(invoice_id)
);
CREATE TABLE Staff_in_Meetings (
  meeting_id NUMBER,
  staff_id NUMBER,
  FOREIGN KEY (staff_id) REFERENCES Staff(staff_id),
  FOREIGN KEY (meeting_id) REFERENCES Meetings(meeting_id)
);

Question: Show the agency ids and the number of staff in each agent?
SQL: SELECT agency_id ,  count(*) FROM Staff GROUP BY agency_id

Question: How many payments are there for each invoice?
SQL: SELECT invoice_id ,  count(*) FROM Payments GROUP BY invoice_id

Question: Show ids, status codes, and details for all invoices for clients.
SQL: SELECT invoice_id ,  invoice_status ,  invoice_details FROM Invoices

Question: What is the invoice status code with most number of invoices.
SQL: SELECT invoice_status FROM Invoices GROUP BY invoice_status ORDER BY count(*) DESC LIMIT 1

Question: Count the number of staff.
SQL: SELECT count(*) FROM Staff

Question: Count the number of staff in each meeting by meeting id.
SQL: SELECT meeting_id ,  count(*) FROM Staff_in_meetings GROUP BY meeting_id

Question: What is the staff id of the staff who attended the least meetings but attended some meeting?
SQL: SELECT staff_id ,  count(*) FROM Staff_in_meetings GROUP BY staff_id ORDER BY count(*) ASC LIMIT 1;

Question: Return the number of distinct staff who have attended a meeting?
SQL: SELECT count(DISTINCT staff_id) FROM Staff_in_meetings

Question: What are the invoice status, invoice details, and corresponding client ids and details and agency id and details?
SQL: SELECT T1.invoice_status ,  T1.invoice_details ,  T2.client_id ,  T2.client_details ,  T3.agency_id ,  T3.agency_details FROM Invoices AS T1 JOIN Clients AS T2 ON T1.client_id  =  T2.client_id JOIN Agencies AS T3 ON T2.agency_id  =  T3.agency_id

Question: What is the agency id and details with most number of clients?
SQL: SELECT T1.agency_id ,  T1.agency_details FROM Agencies AS T1 JOIN Clients AS T2 ON T1.agency_id  =  T2.agency_id GROUP BY T1.agency_id ORDER BY count(*) DESC LIMIT 1

Question: Show all invoice status codes and details and the corresponding client id and details and agency id and details.
SQL: SELECT T1.invoice_status ,  T1.invoice_details ,  T2.client_id ,  T2.client_details ,  T3.agency_id ,  T3.agency_details FROM Invoices AS T1 JOIN Clients AS T2 ON T1.client_id  =  T2.client_id JOIN Agencies AS T3 ON T2.agency_id  =  T3.agency_id

Question: Show agency details for client with detail 'Mac'.
SQL: SELECT T2.agency_details FROM Clients AS T1 JOIN Agencies AS T2 ON T1.agency_id  =  T2.agency_id WHERE T1.client_details  =  'Mac'

Question: Show the meeting type codes and the number of meeting for each client.
SQL: SELECT meeting_type ,  count(*) FROM Meetings GROUP BY meeting_type

Question: List the client ids and the number of meeting for each client.
SQL: SELECT client_id ,  count(*) FROM Meetings GROUP BY client_id

Question: What are the client details for each client and the corresponding details of their agencies?
SQL: SELECT T1.client_details ,  T2.agency_details FROM Clients AS T1 JOIN Agencies AS T2 ON T1.agency_id  =  T2.agency_id

Question: Show all sic codes and the number of clients with each code.
SQL: SELECT sic_code ,  count(*) FROM Clients GROUP BY sic_code

Question: How many clients are there for each sic code?
SQL: SELECT sic_code ,  count(*) FROM Clients GROUP BY sic_code

Question: Show all client ids and details with sic code "Bad".
SQL: SELECT client_id ,  client_details FROM Clients WHERE sic_code  =  "Bad";

Question: What are client ids for clients with at least 2 invoices.
SQL: SELECT client_id FROM Invoices GROUP BY client_id HAVING count(*)  >=  2

Question: List all payment ids and its corresponding invoice ids and details.
SQL: SELECT payment_id ,  invoice_id ,  payment_details FROM Payments

Question: What are the client ideas and details for clients with the sic code Bad?
SQL: SELECT client_id ,  client_details FROM Clients WHERE sic_code  =  "Bad";

Question: Return the invoice ids, statuses, and details for invoices with the most payments?
SQL: SELECT T1.invoice_id ,  T2.invoice_status ,  T2.invoice_details FROM Payments AS T1 JOIN Invoices AS T2 ON T1.invoice_id  =  T2.invoice_id GROUP BY T1.invoice_id ORDER BY count(*) DESC LIMIT 1

Question: What are the client id and details for the client with the most invoices?
SQL: SELECT T1.client_id ,  T2.client_details FROM Invoices AS T1 JOIN Clients AS T2 ON T1.client_id  =  T2.client_id GROUP BY T1.client_id ORDER BY count(*) DESC LIMIT 1

Question: What are the ids and details of the staff who have attended at least 1 meetings and have the detail with letter 's'?
SQL: SELECT staff_id ,  staff_details FROM staff WHERE staff_details LIKE "%s%" GROUP BY staff_id HAVING count(*)  >=  1

Question: Return the invoice status that has the most invoices.
SQL: SELECT invoice_status FROM Invoices GROUP BY invoice_status ORDER BY count(*) DESC LIMIT 1

Question: What are the ids, statuses, and details for all invoices?
SQL: SELECT invoice_id ,  invoice_status ,  invoice_details FROM Invoices

Question: Show all agency ids and details.
SQL: SELECT agency_id ,  agency_details FROM Agencies

Question: Return the agency ids and number of staff in each.
SQL: SELECT agency_id ,  count(*) FROM Staff GROUP BY agency_id

Question: What are the meeting ids, meeting outcomes, meeting types, and client details for all meetings?
SQL: SELECT T1.meeting_id ,  T1.meeting_outcome ,  T1.meeting_type ,  T2.client_details FROM meetings AS T1 JOIN clients AS T2 ON T1.client_id  =  T2.client_id

Question: How many invoices are there for each client id?
SQL: SELECT client_id ,  count(*) FROM Invoices GROUP BY client_id

Question: What is the invoice id, status code, and details for the invoice with most number of payments.
SQL: SELECT T1.invoice_id ,  T2.invoice_status ,  T2.invoice_details FROM Payments AS T1 JOIN Invoices AS T2 ON T1.invoice_id  =  T2.invoice_id GROUP BY T1.invoice_id ORDER BY count(*) DESC LIMIT 1

Question: Count the number of staff who did not attend any meeting.
SQL: SELECT count(*) FROM Staff WHERE staff_id NOT IN ( SELECT staff_id FROM Staff_in_meetings )

Question: How many payments do we have?
SQL: SELECT count(*) FROM Payments

Question: Show the staff id and the number of meetings attended by the staff who attended some meeting but had the lowest attendance.
SQL: SELECT staff_id ,  count(*) FROM Staff_in_meetings GROUP BY staff_id ORDER BY count(*) ASC LIMIT 1;

Question: What are all the client ids and details?
SQL: SELECT client_id ,  client_details FROM Clients

Question: Count the number of agencies.
SQL: SELECT count(*) FROM Agencies

Question: Show all client ids and the number of invoices for each client.
SQL: SELECT client_id ,  count(*) FROM Invoices GROUP BY client_id

Question: Show agency ids and details with at least 2 clients.
SQL: SELECT T1.agency_id ,  T1.agency_details FROM Agencies AS T1 JOIN Clients AS T2 ON T1.agency_id  =  T2.agency_id GROUP BY T1.agency_id HAVING count(*)  >=  2