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: Count the number of payments.
SQL: SELECT count(*) FROM Payments

Question: Show all meeting ids, meeting outcomes, meeting types and the details of the client atttending it.
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: What are the agency details for clients with the 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: List all meeting type codes and details.
SQL: SELECT meeting_type ,  other_details FROM meetings

Question: List all client ids and client details.
SQL: SELECT client_id ,  client_details FROM Clients

Question: List the client id and detail with most number of 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: Show all agency ids without any client.
SQL: SELECT agency_id FROM Agencies EXCEPT SELECT agency_id FROM Clients

Question: What are the agency ids and details agencies 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

Question: Count the number of invoices.
SQL: SELECT count(*) FROM Invoices

Question: How many agencies do we have?
SQL: SELECT count(*) FROM Agencies

Question: Return the ids, sic codes, and agency ids of clients who have attended 1 meeting and had an invoice.
SQL: SELECT T1.client_id ,  T1.sic_code ,  T1.agency_id FROM clients AS T1 JOIN meetings AS T2 ON T1.client_id  =  T2.client_id GROUP BY T1.client_id HAVING count(*)  =  1 INTERSECT SELECT T1.client_id ,  T1.sic_code ,  T1.agency_id FROM clients AS T1 JOIN invoices AS T2 ON T1.client_id  =  T2.client_id

Question: What is the agent id and details for the agency with 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: Show the meeting ids and the number of staff in each meeting.
SQL: SELECT meeting_id ,  count(*) FROM Staff_in_meetings GROUP BY meeting_id

Question: How many staff do we have?
SQL: SELECT count(*) FROM Staff

Question: How many clients are there?
SQL: SELECT count(*) FROM Clients

Question: Return the ids and details of clients who have attended a meeting or had an invoice.
SQL: SELECT T1.client_id ,  T1.client_details FROM Clients AS T1 JOIN meetings AS T2 ON T1.client_id  =  T2.client_id UNION SELECT T1.client_id ,  T1.client_details FROM Clients AS T1 JOIN invoices AS T2 ON T1.client_id  =  T2.client_id

Question: What are the id, sic code and agency id of the client who has attended 1 meeting and has any invoice.
SQL: SELECT T1.client_id ,  T1.sic_code ,  T1.agency_id FROM clients AS T1 JOIN meetings AS T2 ON T1.client_id  =  T2.client_id GROUP BY T1.client_id HAVING count(*)  =  1 INTERSECT SELECT T1.client_id ,  T1.sic_code ,  T1.agency_id FROM clients AS T1 JOIN invoices AS T2 ON T1.client_id  =  T2.client_id

Question: Show all the different invoice ids and statuses of the payments
SQL: SELECT DISTINCT T1.invoice_id ,  T1.invoice_status FROM Invoices AS T1 JOIN Payments AS T2 ON T1.invoice_id  =  T2.invoice_id

Question: Show the number of clients.
SQL: SELECT count(*) FROM Clients

Question: Show all invoice ids and statuses 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 the start and end times of each meeting, as well as the corresponding client and staff details the attendees?
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: What are the distinct invoice ids and statuses for all payments?
SQL: SELECT DISTINCT T1.invoice_id ,  T1.invoice_status FROM Invoices AS T1 JOIN Payments AS T2 ON T1.invoice_id  =  T2.invoice_id

Question: What are the ids and details of the clients who have attended any meeting or have any invoice?
SQL: SELECT T1.client_id ,  T1.client_details FROM Clients AS T1 JOIN meetings AS T2 ON T1.client_id  =  T2.client_id UNION SELECT T1.client_id ,  T1.client_details FROM Clients AS T1 JOIN invoices AS T2 ON T1.client_id  =  T2.client_id

Question: How many staff did not attend any meeting?
SQL: SELECT count(*) FROM Staff WHERE staff_id NOT IN ( SELECT staff_id FROM Staff_in_meetings )

Question: Show all payment ids and details for invoices whose status is '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: Return the client ids for clients with two or more invoices?
SQL: SELECT client_id FROM Invoices GROUP BY client_id HAVING count(*)  >=  2