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: What are the payment ids, invoice ids, and payment details for all payments?
SQL: SELECT payment_id ,  invoice_id ,  payment_details FROM Payments

Question: What are all the agency ids and details?
SQL: SELECT agency_id ,  agency_details FROM Agencies

Question: Show all agency ids and details for agencies with a client.
SQL: SELECT T1.agency_id ,  T1.agency_details FROM Agencies AS T1 JOIN Clients AS T2 ON T1.agency_id  =  T2.agency_id

Question: Show details for all clients and the details of their corresponding agents.
SQL: SELECT T1.client_details ,  T2.agency_details FROM Clients AS T1 JOIN Agencies AS T2 ON T1.agency_id  =  T2.agency_id

Question: List the start time, end time of each meeting, and the corresponding client detail and staff detail.
SQL: SELECT T1.start_date_time ,  T1.end_date_time ,  T2.client_details ,  T4.staff_details FROM meetings AS T1 JOIN clients AS T2 ON T1.client_id  =  T2.client_id JOIN staff_in_meetings AS T3 ON T1.meeting_id  =  T3.meeting_id JOIN staff AS T4 ON T3.staff_id  =  T4.staff_id

Question: Return the ids and details of staff who have attended at least 1 meeting and have an s in their staff details?
SQL: SELECT staff_id ,  staff_details FROM staff WHERE staff_details LIKE "%s%" GROUP BY staff_id HAVING count(*)  >=  1

Question: What are the invoice ids and statuses for invoices without a payment?
SQL: SELECT invoice_id ,  invoice_status FROM Invoices EXCEPT SELECT T1.invoice_id ,  T1.invoice_status FROM Invoices AS T1 JOIN Payments AS T2 ON T1.invoice_id  =  T2.invoice_id

Question: What are all payment ids and payment details for invoices with status Working?
SQL: SELECT T1.payment_id ,  T1.payment_details FROM Payments AS T1 JOIN Invoices AS T2 ON T1.invoice_id  =  T2.invoice_id WHERE T2.invoice_status  =  'Working'

Question: Show agency ids and the number of clients for each agency.
SQL: SELECT agency_id ,  count(*) FROM Clients GROUP BY agency_id

Question: How many invoices are there for each status code?
SQL: SELECT invoice_status ,  count(*) FROM Invoices GROUP BY invoice_status

Question: Return the agency id and details for the agency with the greatest 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 the number of invoices with each status.
SQL: SELECT invoice_status ,  count(*) FROM Invoices GROUP BY invoice_status

Question: Return the id and detail for the agency with the most staff.
SQL: SELECT T1.agency_id ,  T2.agency_details FROM Staff AS T1 JOIN Agencies AS T2 ON T1.agency_id  =  T2.agency_id GROUP BY T1.agency_id ORDER BY count(*) DESC LIMIT 1

Question: How many clients does each agency have?
SQL: SELECT agency_id ,  count(*) FROM Clients GROUP BY agency_id

Question: Show all invoice ids and the number of payments for each invoice.
SQL: SELECT invoice_id ,  count(*) FROM Payments GROUP BY invoice_id

Question: How many meetings had each meeting outcome?
SQL: SELECT meeting_outcome ,  count(*) FROM Meetings GROUP BY meeting_outcome

Question: Show meeting outcome codes and the number of meeting in each outcome.
SQL: SELECT meeting_outcome ,  count(*) FROM Meetings GROUP BY meeting_outcome

Question: How many meetings are there for each meeting type?
SQL: SELECT meeting_type ,  count(*) FROM Meetings GROUP BY meeting_type

Question: What are all meeting types and other details?
SQL: SELECT meeting_type ,  other_details FROM meetings

Question: How many invoices do we have?
SQL: SELECT count(*) FROM Invoices

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

Question: Show all meeting outcomes and purposes.
SQL: SELECT meeting_outcome ,  purpose_of_meeting FROM meetings

Question: What are the agency ids and agency details for all agencies who have a client?
SQL: SELECT T1.agency_id ,  T1.agency_details FROM Agencies AS T1 JOIN Clients AS T2 ON T1.agency_id  =  T2.agency_id

Question: What are ids of agencies that do not have any clients?
SQL: SELECT agency_id FROM Agencies EXCEPT SELECT agency_id FROM Clients

Question: How many staff have attended a meeting?
SQL: SELECT count(DISTINCT staff_id) FROM Staff_in_meetings

Question: What are all meeting outcomes and purposes?
SQL: SELECT meeting_outcome ,  purpose_of_meeting FROM meetings