CREATE TABLE Addresses (
    address_id NUMBER PRIMARY KEY,
    line_1_number_building TEXT,
    town_city TEXT,
    zip_postcode TEXT,
    state_province_county TEXT,
    country TEXT
);
CREATE TABLE Services (
    service_id NUMBER PRIMARY KEY,
    service_type_code TEXT,
    service_name TEXT,
    service_descriptio TEXT
);
CREATE TABLE Forms (
    form_id NUMBER PRIMARY KEY,
    form_type_code TEXT,
    service_id NUMBER,
    form_number TEXT,
    form_name TEXT,
    form_description TEXT,
    FOREIGN KEY ("service_id") REFERENCES Services("service_id")
);
CREATE TABLE Individuals (
    individual_id NUMBER PRIMARY KEY,
    individual_first_name TEXT,
    individual_middle_name TEXT,
    inidividual_phone TEXT,
    individual_email TEXT,
    individual_address TEXT,
    individual_last_name TEXT
);
CREATE TABLE Organizations (
    organization_id NUMBER PRIMARY KEY,
    date_formed TIME,
    organization_name TEXT,
    uk_vat_number TEXT
);
CREATE TABLE Parties (
    party_id NUMBER PRIMARY KEY,
    payment_method_code TEXT,
    party_phone TEXT,
    party_email TEXT
);
CREATE TABLE Organization_Contact_Individuals (
    individual_id NUMBER PRIMARY KEY,
    organization_id NUMBER,
    date_contact_from TIME,
    date_contact_to TIME,
    FOREIGN KEY ("individual_id") REFERENCES Individuals("individual_id"),
    FOREIGN KEY ("organization_id") REFERENCES Organizations("organization_id")
);
CREATE TABLE Party_Addresses (
    party_id NUMBER PRIMARY KEY,
    address_id NUMBER,
    date_address_from TIME,
    address_type_code TEXT,
    date_address_to TIME,
    FOREIGN KEY ("party_id") REFERENCES Parties("party_id"),
    FOREIGN KEY ("address_id") REFERENCES Addresses("address_id")
);
CREATE TABLE Party_Forms (
    party_id NUMBER PRIMARY KEY,
    form_id NUMBER,
    date_completion_started TIME,
    form_status_code TEXT,
    date_fully_completed TIME,
    FOREIGN KEY ("form_id") REFERENCES Forms("form_id"),
    FOREIGN KEY ("party_id") REFERENCES Parties("party_id")
);
CREATE TABLE Party_Services (
    booking_id NUMBER,
    customer_id NUMBER,
    service_id NUMBER,
    service_datetime TIME,
    booking_made_date TIME,
    FOREIGN KEY ("customer_id") REFERENCES Parties("party_id"),
    FOREIGN KEY ("service_id") REFERENCES Services("service_id")
);

Question: Find the payment method code used by more than 3 parties.
SQL: SELECT payment_method_code FROM parties GROUP BY payment_method_code HAVING count(*)  >  3

Question: What are the payment method codes that have been used by more than 3 parties?
SQL: SELECT payment_method_code FROM parties GROUP BY payment_method_code HAVING count(*)  >  3

Question: Find the name of organizations whose names contain "Party".
SQL: SELECT organization_name FROM organizations WHERE organization_name LIKE "%Party%"

Question: What are the names of organizations that contain the word "Party"?
SQL: SELECT organization_name FROM organizations WHERE organization_name LIKE "%Party%"

Question: How many distinct payment methods are used by parties?
SQL: SELECT count(DISTINCT payment_method_code) FROM parties

Question: Count the number of different payment method codes used by parties.
SQL: SELECT count(DISTINCT payment_method_code) FROM parties

Question: Which is the email of the party that has used the services the most number of times?
SQL: SELECT t1.party_email FROM parties AS t1 JOIN party_services AS t2 ON t1.party_id  =  t2.customer_id GROUP BY t1.party_email ORDER BY count(*) DESC LIMIT 1

Question: Return the party email that has used party services the greatest number of times.
SQL: SELECT t1.party_email FROM parties AS t1 JOIN party_services AS t2 ON t1.party_id  =  t2.customer_id GROUP BY t1.party_email ORDER BY count(*) DESC LIMIT 1

Question: Which state can address "6862 Kaitlyn Knolls" possibly be in?
SQL: SELECT state_province_county FROM addresses WHERE line_1_number_building LIKE "%6862 Kaitlyn Knolls%"

Question: Give the state corresponding to the line number building "6862 Kaitlyn Knolls".
SQL: SELECT state_province_county FROM addresses WHERE line_1_number_building LIKE "%6862 Kaitlyn Knolls%"

Question: What is the name of organization that has the greatest number of contact individuals?
SQL: SELECT t1.organization_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id  =  t2.organization_id GROUP BY t1.organization_name ORDER BY count(*) DESC LIMIT 1

Question: Return the name of the organization which has the most contact individuals.
SQL: SELECT t1.organization_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id  =  t2.organization_id GROUP BY t1.organization_name ORDER BY count(*) DESC LIMIT 1

Question: Find the last name of the individuals that have been contact individuals of an organization.
SQL: SELECT DISTINCT t1.individual_last_name FROM individuals AS t1 JOIN organization_contact_individuals AS t2 ON t1.individual_id  =  t2.individual_id

Question: What are the last names of individuals who have been contact individuals for an organization?
SQL: SELECT DISTINCT t1.individual_last_name FROM individuals AS t1 JOIN organization_contact_individuals AS t2 ON t1.individual_id  =  t2.individual_id