input
stringlengths 236
16.9k
| output
stringlengths 19
805
|
---|---|
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- Find the number of matches in different competitions.
| SELECT count(*) , Competition FROM MATCH GROUP BY Competition; |
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- For each competition, count the number of matches.
| SELECT count(*) , Competition FROM MATCH GROUP BY Competition; |
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- List venues of all matches in the order of their dates starting from the most recent one.
| SELECT venue FROM MATCH ORDER BY date DESC; |
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- What are the venues of all the matches? Sort them in the descending order of match date.
| SELECT venue FROM MATCH ORDER BY date DESC; |
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- what is the GDP of the city with the largest population.
| SELECT gdp FROM city ORDER BY Regional_Population DESC LIMIT 1; |
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- Find the GDP of the city with the largest regional population.
| SELECT gdp FROM city ORDER BY Regional_Population DESC LIMIT 1; |
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- What are the GDP and population of the city that already served as a host more than once?
| SELECT t1.gdp , t1.Regional_Population FROM city AS T1 JOIN hosting_city AS T2 ON T1.city_id = T2.host_city GROUP BY t2.Host_City HAVING count(*) > 1; |
-- Database schema
| city : City_ID [ INT ] primary_key , City [ TEXT ] , Hanzi [ TEXT ] , Hanyu_Pinyin [ TEXT ] , Regional_Population [ INT ] , GDP [ INT ] | match : Match_ID [ INT ] primary_key , Date [ TEXT ] , Venue [ TEXT ] , Score [ TEXT ] , Result [ TEXT ] , Competition [ TEXT ] | temperature : City_ID [ INT ] primary_key temperature.City_ID = city.City_ID , Jan [ INT ] , Feb [ INT ] , Mar [ INT ] , Apr [ INT ] , Jun [ INT ] , Jul [ INT ] , Aug [ INT ] , Sep [ INT ] , Oct [ INT ] , Nov [ INT ] , Dec [ INT ] | hosting_city : Year [ INT ] primary_key , Match_ID [ INT ] hosting_city.Match_ID = match.Match_ID , Host_City [ TEXT ] hosting_city.Host_City = city.City_ID |
-- -- Which cities have served as host cities more than once? Return me their GDP and population.
| SELECT t1.gdp , t1.Regional_Population FROM city AS T1 JOIN hosting_city AS T2 ON T1.city_id = T2.host_city GROUP BY t2.Host_City HAVING count(*) > 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- List every individual's first name, middle name and last name in alphabetical order by last name.
| SELECT individual_first_name , individual_middle_name , individual_last_name FROM individuals ORDER BY individual_last_name; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the first, middle, and last names of all individuals, ordered by last name?
| SELECT individual_first_name , individual_middle_name , individual_last_name FROM individuals ORDER BY individual_last_name; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- List all the types of forms.
| SELECT DISTINCT form_type_code FROM forms; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the different types of forms?
| SELECT DISTINCT form_type_code FROM forms; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the name of the most popular party form.
| SELECT t1.form_name FROM forms AS t1 JOIN party_forms AS t2 ON t1.form_id = t2.form_id GROUP BY t2.form_id ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What is the name of the party form that is most common?
| SELECT t1.form_name FROM forms AS t1 JOIN party_forms AS t2 ON t1.form_id = t2.form_id GROUP BY t2.form_id ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the payment method and phone of the party with email "[email protected]".
| SELECT payment_method_code , party_phone FROM parties WHERE party_email = "[email protected]"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What is the payment method code and party phone of the party with the email '[email protected]'?
| SELECT payment_method_code , party_phone FROM parties WHERE party_email = "[email protected]"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the emails of parties with the most popular party form.
| SELECT t1.party_email FROM parties AS t1 JOIN party_forms AS t2 ON t1.party_id = t2.party_id WHERE t2.form_id = (SELECT form_id FROM party_forms GROUP BY form_id ORDER BY count(*) DESC LIMIT 1); |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the party emails associated with parties that used the party form that is the most common?
| SELECT t1.party_email FROM parties AS t1 JOIN party_forms AS t2 ON t1.party_id = t2.party_id WHERE t2.form_id = (SELECT form_id FROM party_forms GROUP BY form_id ORDER BY count(*) DESC LIMIT 1); |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- List all the name of organizations in order of the date formed.
| SELECT organization_name FROM organizations ORDER BY date_formed ASC; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the names of organizations, ordered by the date they were formed, ascending?
| SELECT organization_name FROM organizations ORDER BY date_formed ASC; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the name of the youngest organization.
| SELECT organization_name FROM organizations ORDER BY date_formed DESC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What is the name of the organization that was formed most recently?
| SELECT organization_name FROM organizations ORDER BY date_formed DESC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the last name of the latest contact individual of the organization "Labour Party".
| SELECT t3.individual_last_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id = t2.organization_id JOIN individuals AS t3 ON t2.individual_id = t3.individual_id WHERE t1.organization_name = "Labour Party" ORDER BY t2.date_contact_to DESC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What is the last name of the contact individual from the Labour party organization who was contacted most recently?
| SELECT t3.individual_last_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id = t2.organization_id JOIN individuals AS t3 ON t2.individual_id = t3.individual_id WHERE t1.organization_name = "Labour Party" ORDER BY t2.date_contact_to DESC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the last name of the first ever contact person of the organization with the highest UK Vat number.
| SELECT t3.individual_last_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id = t2.organization_id JOIN individuals AS t3 ON t2.individual_id = t3.individual_id WHERE t1.uk_vat_number = (SELECT max(uk_vat_number) FROM organizations) ORDER BY t2.date_contact_to ASC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What is the last name of the first individual contacted from the organization with the maximum UK Vat number across all organizations?
| SELECT t3.individual_last_name FROM organizations AS t1 JOIN organization_contact_individuals AS t2 ON t1.organization_id = t2.organization_id JOIN individuals AS t3 ON t2.individual_id = t3.individual_id WHERE t1.uk_vat_number = (SELECT max(uk_vat_number) FROM organizations) ORDER BY t2.date_contact_to ASC LIMIT 1; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- How many services are there?
| SELECT count(*) FROM services; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Count the number of services.
| SELECT count(*) FROM services; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find name of the services that has never been used.
| SELECT service_name FROM services EXCEPT SELECT t1.service_name FROM services AS t1 JOIN party_services AS t2 ON t1.service_id = t2.service_id; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the names of the services that have never been used?
| SELECT service_name FROM services EXCEPT SELECT t1.service_name FROM services AS t1 JOIN party_services AS t2 ON t1.service_id = t2.service_id; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the name of all the cities and states.
| SELECT town_city FROM addresses UNION SELECT state_province_county FROM addresses; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the names of all cities and states?
| SELECT town_city FROM addresses UNION SELECT state_province_county FROM addresses; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- How many cities are there in state "Colorado"?
| SELECT count(*) FROM addresses WHERE state_province_county = "Colorado"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Count the number of cities in the state of Colorado.
| SELECT count(*) FROM addresses WHERE state_province_county = "Colorado"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the payment method code used by more than 3 parties.
| SELECT payment_method_code FROM parties GROUP BY payment_method_code HAVING count(*) > 3; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the payment method codes that have been used by more than 3 parties?
| SELECT payment_method_code FROM parties GROUP BY payment_method_code HAVING count(*) > 3; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the name of organizations whose names contain "Party".
| SELECT organization_name FROM organizations WHERE organization_name LIKE "%Party%"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the names of organizations that contain the word "Party"?
| SELECT organization_name FROM organizations WHERE organization_name LIKE "%Party%"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- How many distinct payment methods are used by parties?
| SELECT count(DISTINCT payment_method_code) FROM parties; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Count the number of different payment method codes used by parties.
| SELECT count(DISTINCT payment_method_code) FROM parties; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Which is the email of the party that has used the services the most number of times?
| 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; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Return the party email that has used party services the greatest number of times.
| 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; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Which state can address "6862 Kaitlyn Knolls" possibly be in?
| SELECT state_province_county FROM addresses WHERE line_1_number_building LIKE "%6862 Kaitlyn Knolls%"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Give the state corresponding to the line number building "6862 Kaitlyn Knolls".
| SELECT state_province_county FROM addresses WHERE line_1_number_building LIKE "%6862 Kaitlyn Knolls%"; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What is the name of organization that has the greatest number of contact individuals?
| 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; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Return the name of the organization which has the most contact individuals.
| 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; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- Find the last name of the individuals that have been contact individuals of an organization.
| SELECT DISTINCT t1.individual_last_name FROM individuals AS t1 JOIN organization_contact_individuals AS t2 ON t1.individual_id = t2.individual_id; |
-- Database schema
| Addresses : address_id [ INT ] primary_key , line_1_number_building [ TEXT ] , town_city [ TEXT ] , zip_postcode [ TEXT ] , state_province_county [ TEXT ] , country [ TEXT ] | Services : service_id [ INT ] primary_key , service_type_code [ TEXT ] , service_name [ TEXT ] , service_descriptio [ TEXT ] | Forms : form_id [ INT ] primary_key , form_type_code [ TEXT ] , service_id [ INT ] Forms.service_id = Services.service_id , form_number [ TEXT ] , form_name [ TEXT ] , form_description [ TEXT ] | Individuals : individual_id [ INT ] primary_key , individual_first_name [ TEXT ] , individual_middle_name [ TEXT ] , inidividual_phone [ TEXT ] , individual_email [ TEXT ] , individual_address [ TEXT ] , individual_last_name [ TEXT ] | Organizations : organization_id [ INT ] primary_key , date_formed [ TEXT ] , organization_name [ TEXT ] , uk_vat_number [ TEXT ] | Parties : party_id [ INT ] primary_key , payment_method_code [ TEXT ] , party_phone [ TEXT ] , party_email [ TEXT ] | Organization_Contact_Individuals : individual_id [ INT ] primary_key Organization_Contact_Individuals.individual_id = Individuals.individual_id , organization_id [ INT ] Organization_Contact_Individuals.organization_id = Organizations.organization_id , date_contact_from [ TEXT ] , date_contact_to [ TEXT ] | Party_Addresses : party_id [ INT ] primary_key Party_Addresses.party_id = Parties.party_id , address_id [ INT ] Party_Addresses.address_id = Addresses.address_id , date_address_from [ TEXT ] , address_type_code [ TEXT ] , date_address_to [ TEXT ] | Party_Forms : party_id [ INT ] primary_key Party_Forms.party_id = Parties.party_id , form_id [ INT ] Party_Forms.form_id = Forms.form_id , date_completion_started [ TEXT ] , form_status_code [ TEXT ] , date_fully_completed [ TEXT ] | Party_Services : booking_id [ INT ] , customer_id [ INT ] Party_Services.customer_id = Parties.party_id , service_id [ INT ] Party_Services.service_id = Services.service_id , service_datetime [ TEXT ] , booking_made_date [ TEXT ] |
-- -- What are the last names of individuals who have been contact individuals for an organization?
| SELECT DISTINCT t1.individual_last_name FROM individuals AS t1 JOIN organization_contact_individuals AS t2 ON t1.individual_id = t2.individual_id; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- How many drivers are there?
| SELECT count(*) FROM driver; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the name, home city, and age for all drivers.
| SELECT name , home_city , age FROM driver; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the party and the number of drivers in each party.
| SELECT party , count(*) FROM driver GROUP BY party; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the name of drivers in descending order of age.
| SELECT name FROM driver ORDER BY age DESC; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show all different home cities.
| SELECT DISTINCT home_city FROM driver; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the home city with the most number of drivers.
| SELECT home_city FROM driver GROUP BY home_city ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the party with drivers from Hartford and drivers older than 40.
| SELECT party FROM driver WHERE home_city = 'Hartford' AND age > 40; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show home city where at least two drivers older than 40 are from.
| SELECT home_city FROM driver WHERE age > 40 GROUP BY home_city HAVING count(*) >= 2; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show all home cities except for those having a driver older than 40.
| SELECT home_city FROM driver EXCEPT SELECT home_city FROM driver WHERE age > 40; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the names of the drivers without a school bus.
| SELECT name FROM driver WHERE driver_id NOT IN (SELECT driver_id FROM school_bus); |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the types of schools that have two schools.
| SELECT TYPE FROM school GROUP BY TYPE HAVING count(*) = 2; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the school name and driver name for all school buses.
| SELECT T2.school , T3.name FROM school_bus AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id JOIN driver AS T3 ON T1.driver_id = T3.driver_id; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- What is the maximum, minimum and average years spent working on a school bus?
| SELECT max(years_working) , min(years_working) , avg(years_working) FROM school_bus; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the school name and type for schools without a school bus.
| SELECT school , TYPE FROM school WHERE school_id NOT IN (SELECT school_id FROM school_bus); |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- Show the type of school and the number of buses for each type.
| SELECT T2.type , count(*) FROM school_bus AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id GROUP BY T2.type; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- How many drivers are from Hartford city or younger than 40?
| SELECT count(*) FROM driver WHERE home_city = 'Hartford' OR age < 40; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- List names for drivers from Hartford city and younger than 40.
| SELECT name FROM driver WHERE home_city = 'Hartford' AND age < 40; |
-- Database schema
| driver : Driver_ID [ INT ] primary_key , Name [ TEXT ] , Party [ TEXT ] , Home_city [ TEXT ] , Age [ INT ] | school : School_ID [ INT ] primary_key , Grade [ TEXT ] , School [ TEXT ] , Location [ TEXT ] , Type [ TEXT ] | school_bus : School_ID [ INT ] primary_key school_bus.School_ID = school.School_ID , Driver_ID [ INT ] school_bus.Driver_ID = driver.Driver_ID , Years_Working [ INT ] , If_full_time [ TEXT ] |
-- -- find the name of driver who is driving the school bus with the longest working history.
| SELECT t1.name FROM driver AS t1 JOIN school_bus AS t2 ON t1.driver_id = t2.driver_id ORDER BY years_working DESC LIMIT 1; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- How many flights have a velocity larger than 200?
| SELECT count(*) FROM flight WHERE velocity > 200; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- List the vehicle flight number, date and pilot of all the flights, ordered by altitude.
| SELECT vehicle_flight_number , date , pilot FROM flight ORDER BY altitude ASC; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- List the id, country, city and name of the airports ordered alphabetically by the name.
| SELECT id , country , city , name FROM airport ORDER BY name; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What is maximum group equity shareholding of the companies?
| SELECT max(group_equity_shareholding) FROM operate_company; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What is the velocity of the pilot named 'Thompson'?
| SELECT avg(velocity) FROM flight WHERE pilot = 'Thompson'; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What are the names and types of the companies that have ever operated a flight?
| SELECT T1.name , T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What are the names of the airports which are not in the country 'Iceland'?
| SELECT name FROM airport WHERE country != 'Iceland'; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What are the distinct types of the companies that have operated any flights with velocity less than 200?
| SELECT DISTINCT T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T2.velocity < 200; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What are the ids and names of the companies that operated more than one flight?
| SELECT T1.id , T1.name FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id GROUP BY T1.id HAVING count(*) > 1; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What is the id, name and IATA code of the airport that had most number of flights?
| SELECT T1.id , T1.name , T1.IATA FROM airport AS T1 JOIN flight AS T2 ON T1.id = T2.airport_id GROUP BY T2.id ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What are the different pilot names who had piloted a flight in the country 'United States' or in the airport named 'Billund Airport'?
| SELECT DISTINCT T2.pilot FROM airport AS T1 JOIN flight AS T2 ON T1.id = T2.airport_id WHERE T1.country = 'United States' OR T1.name = 'Billund Airport'; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- What is the most common company type, and how many are there?
| SELECT TYPE , count(*) FROM operate_company GROUP BY TYPE ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- How many airports haven't the pilot 'Thompson' driven an aircraft?
| SELECT count(*) FROM airport WHERE id NOT IN ( SELECT airport_id FROM flight WHERE pilot = 'Thompson' ); |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- List the name of the pilots who have flied for both a company that mainly provide 'Cargo' services and a company that runs 'Catering services' activities.
| SELECT T2.pilot FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T1.principal_activities = 'Cargo' INTERSECT SELECT T2.pilot FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T1.principal_activities = 'Catering services'; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- Which of the airport names contains the word 'international'?
| SELECT name FROM airport WHERE name LIKE '%international%'; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- How many companies operates airlines in each airport?
| SELECT T3.id , count(*) FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id JOIN airport AS T3 ON T2.airport_id = T3.id GROUP BY T3.id; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- how many airports are there in each country?
| SELECT count(*) , country FROM airport GROUP BY country; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- which countries have more than 2 airports?
| SELECT country FROM airport GROUP BY country HAVING count(*) > 2; |
-- Database schema
| airport : id [ INT ] primary_key , City [ TEXT ] , Country [ TEXT ] , IATA [ TEXT ] , ICAO [ TEXT ] , name [ TEXT ] | operate_company : id [ INT ] primary_key , name [ TEXT ] , Type [ TEXT ] , Principal_activities [ TEXT ] , Incorporated_in [ TEXT ] , Group_Equity_Shareholding [ INT ] | flight : id [ INT ] primary_key , Vehicle_Flight_number [ TEXT ] , Date [ TEXT ] , Pilot [ TEXT ] , Velocity [ INT ] , Altitude [ INT ] , airport_id [ INT ] flight.airport_id = airport.id , company_id [ INT ] flight.company_id = operate_company.id |
-- -- which pilot is in charge of the most number of flights?
| SELECT pilot FROM flight GROUP BY pilot ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- How many accounts do we have?
| SELECT count(*) FROM Accounts; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- Count the number of accounts.
| SELECT count(*) FROM Accounts; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- Show all account ids and account details.
| SELECT account_id , account_details FROM Accounts; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- What are the ids and details of all accounts?
| SELECT account_id , account_details FROM Accounts; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- How many statements do we have?
| SELECT count(*) FROM Statements; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- Count the number of statements.
| SELECT count(*) FROM Statements; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- List all statement ids and statement details.
| SELECT STATEMENT_ID , statement_details FROM Statements; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- What are the ids and details of all statements?
| SELECT STATEMENT_ID , statement_details FROM Statements; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- Show statement id, statement detail, account detail for accounts.
| SELECT T1.statement_id , T2.statement_details , T1.account_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- What are the statement ids, statement details, and account details, for all accounts?
| SELECT T1.statement_id , T2.statement_details , T1.account_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- Show all statement id and the number of accounts for each statement.
| SELECT STATEMENT_ID , count(*) FROM Accounts GROUP BY STATEMENT_ID; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- What are the different statement ids on accounts, and the number of accounts for each?
| SELECT STATEMENT_ID , count(*) FROM Accounts GROUP BY STATEMENT_ID; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- Show the statement id and the statement detail for the statement with most number of accounts.
| SELECT T1.statement_id , T2.statement_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id GROUP BY T1.statement_id ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- What are the statement id and statement detail for the statement that has the most corresponding accounts?
| SELECT T1.statement_id , T2.statement_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id GROUP BY T1.statement_id ORDER BY count(*) DESC LIMIT 1; |
-- Database schema
| Ref_Document_Types : Document_Type_Code [ TEXT ] primary_key , Document_Type_Name [ TEXT ] , Document_Type_Description [ TEXT ] | Ref_Budget_Codes : Budget_Type_Code [ TEXT ] primary_key , Budget_Type_Description [ TEXT ] | Projects : Project_ID [ INT ] primary_key , Project_Details [ TEXT ] | Documents : Document_ID [ INT ] primary_key , Document_Type_Code [ TEXT ] Documents.Document_Type_Code = Ref_Document_Types.Document_Type_Code , Project_ID [ INT ] Documents.Project_ID = Projects.Project_ID , Document_Date [ TEXT ] , Document_Name [ TEXT ] , Document_Description [ TEXT ] , Other_Details [ TEXT ] | Statements : Statement_ID [ INT ] primary_key Statements.Statement_ID = Documents.Document_ID , Statement_Details [ TEXT ] | Documents_with_Expenses : Document_ID [ INT ] primary_key Documents_with_Expenses.Document_ID = Documents.Document_ID , Budget_Type_Code [ TEXT ] Documents_with_Expenses.Budget_Type_Code = Ref_Budget_Codes.Budget_Type_Code , Document_Details [ TEXT ] | Accounts : Account_ID [ INT ] primary_key , Statement_ID [ INT ] Accounts.Statement_ID = Statements.Statement_ID , Account_Details [ TEXT ] |
-- -- Show the number of documents.
| SELECT count(*) FROM Documents; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.