db_id
stringclasses
127 values
query
stringlengths
20
523
question
stringlengths
16
224
schema
stringclasses
127 values
e_government
SELECT organization_name FROM organizations ORDER BY date_formed DESC LIMIT 1
Find the name of the youngest organization.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT organization_name FROM organizations ORDER BY date_formed DESC LIMIT 1
What is the name of the organization that was formed most recently?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
Find the last name of the latest contact individual of the organization "Labour Party".
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
What is the last name of the contact individual from the Labour party organization who was contacted most recently?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
Find the last name of the first ever contact person of the organization with the highest UK Vat number.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
What is the last name of the first individual contacted from the organization with the maximum UK Vat number across all organizations?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT count(*) FROM services
How many services are there?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT count(*) FROM services
Count the number of services.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
Find name of the services that has never been used.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
What are the names of the services that have never been used?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT town_city FROM addresses UNION SELECT state_province_county FROM addresses
Find the name of all the cities and states.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT town_city FROM addresses UNION SELECT state_province_county FROM addresses
What are the names of all cities and states?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT count(*) FROM addresses WHERE state_province_county = "Colorado"
How many cities are there in state "Colorado"?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT count(*) FROM addresses WHERE state_province_county = "Colorado"
Count the number of cities in the state of Colorado.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT payment_method_code FROM parties GROUP BY payment_method_code HAVING count(*) > 3
Find the payment method code used by more than 3 parties.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT payment_method_code FROM parties GROUP BY payment_method_code HAVING count(*) > 3
What are the payment method codes that have been used by more than 3 parties?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT organization_name FROM organizations WHERE organization_name LIKE "%Party%"
Find the name of organizations whose names contain "Party".
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT organization_name FROM organizations WHERE organization_name LIKE "%Party%"
What are the names of organizations that contain the word "Party"?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT count(DISTINCT payment_method_code) FROM parties
How many distinct payment methods are used by parties?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT count(DISTINCT payment_method_code) FROM parties
Count the number of different payment method codes used by parties.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
Which is the email of the party that has used the services the most number of times?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
Return the party email that has used party services the greatest number of times.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT state_province_county FROM addresses WHERE line_1_number_building LIKE "%6862 Kaitlyn Knolls%"
Which state can address "6862 Kaitlyn Knolls" possibly be in?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT state_province_county FROM addresses WHERE line_1_number_building LIKE "%6862 Kaitlyn Knolls%"
Give the state corresponding to the line number building "6862 Kaitlyn Knolls".
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
What is the name of organization that has the greatest number of contact individuals?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
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
Return the name of the organization which has the most contact individuals.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT DISTINCT t1.individual_last_name FROM individuals AS t1 JOIN organization_contact_individuals AS t2 ON t1.individual_id = t2.individual_id
Find the last name of the individuals that have been contact individuals of an organization.
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
e_government
SELECT DISTINCT t1.individual_last_name FROM individuals AS t1 JOIN organization_contact_individuals AS t2 ON t1.individual_id = t2.individual_id
What are the last names of individuals who have been contact individuals for an organization?
CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1_number_building` VARCHAR(80), `town_city` VARCHAR(50), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50) ); CREATE TABLE `Services` ( `service_id` INTEGER PRIMARY KEY, `service_type_code` VARCHAR(15) NOT NULL, `service_name` VARCHAR(80), `service_descriptio` VARCHAR(255) ); CREATE TABLE `Forms` ( `form_id` INTEGER PRIMARY KEY, `form_type_code` VARCHAR(15) NOT NULL, `service_id` INTEGER, `form_number` VARCHAR(50), `form_name` VARCHAR(80), `form_description` VARCHAR(255), FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ) ); CREATE TABLE `Individuals` ( `individual_id` INTEGER PRIMARY KEY, `individual_first_name` VARCHAR(80), `individual_middle_name` VARCHAR(80), `inidividual_phone` VARCHAR(80), `individual_email` VARCHAR(80), `individual_address` VARCHAR(255), `individual_last_name` VARCHAR(80) ); CREATE TABLE `Organizations` ( `organization_id` INTEGER PRIMARY KEY, `date_formed` DATETIME, `organization_name` VARCHAR(255), `uk_vat_number` VARCHAR(20) ); CREATE TABLE `Parties` ( `party_id` INTEGER PRIMARY KEY, `payment_method_code` VARCHAR(15) NOT NULL, `party_phone` VARCHAR(80), `party_email` VARCHAR(80) ); CREATE TABLE `Organization_Contact_Individuals` ( `individual_id` INTEGER NOT NULL, `organization_id` INTEGER NOT NULL, `date_contact_from` DATETIME NOT NULL, `date_contact_to` DATETIME, PRIMARY KEY (`individual_id`,`organization_id` ), FOREIGN KEY (`organization_id` ) REFERENCES `Organizations`(`organization_id` ), FOREIGN KEY (`individual_id` ) REFERENCES `Individuals`(`individual_id` ) ); CREATE TABLE `Party_Addresses` ( `party_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, PRIMARY KEY (`party_id`, `address_id`), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ) ); CREATE TABLE `Party_Forms` ( `party_id` INTEGER NOT NULL, `form_id` INTEGER NOT NULL, `date_completion_started` DATETIME NOT NULL, `form_status_code` VARCHAR(15) NOT NULL, `date_fully_completed` DATETIME, PRIMARY KEY (`party_id`, `form_id`), FOREIGN KEY (`party_id` ) REFERENCES `Parties`(`party_id` ), FOREIGN KEY (`form_id` ) REFERENCES `Forms`(`form_id` ) ); CREATE TABLE `Party_Services` ( `booking_id` INTEGER NOT NULL , `customer_id` INTEGER NOT NULL, `service_id` INTEGER NOT NULL, `service_datetime` DATETIME NOT NULL, `booking_made_date` DATETIME, FOREIGN KEY (`service_id` ) REFERENCES `Services`(`service_id` ), FOREIGN KEY (`customer_id` ) REFERENCES `Parties`(`party_id` ) ); INSERT INTO Addresses (`address_id`, `line_1_number_building`, `town_city`, `zip_postcode`, `state_province_county`, `country`) VALUES (1, '25518 Ortiz Centers', 'West Stacy', '193', 'NorthCarolina', 'USA'); INSERT INTO Services (`service_id`, `service_type_code`, `service_name`, `service_descriptio`) VALUES (1, 'Education', 'Education', 'Education'); INSERT INTO Forms (`form_id`, `form_type_code`, `service_id`, `form_number`, `form_name`, `form_description`) VALUES (1, 'Basic', 13, '8069', 'SSN Application', 'Form for SSN Application'); INSERT INTO Individuals (`individual_id`, `individual_first_name`, `individual_middle_name`, `inidividual_phone`, `individual_email`, `individual_address`, `individual_last_name`) VALUES (1, 'Oscar', 'Hosea', '1-925-696-5232', '[email protected]', '6956 Lia Plaza', 'Maggio'); INSERT INTO Organizations (`organization_id`, `date_formed`, `organization_name`, `uk_vat_number`) VALUES (1, '2016-08-24 23:52:48', 'Labour Party', '2157'); INSERT INTO Parties (`party_id`, `payment_method_code`, `party_phone`, `party_email`) VALUES (1, 'Cheque', '05374656172', '[email protected]'); INSERT INTO Organization_Contact_Individuals (`individual_id`, `organization_id`, `date_contact_from`, `date_contact_to`) VALUES (13, 1, '2016-08-16 22:09:11', '2018-03-25 10:27:18'); INSERT INTO Party_Addresses (`party_id`, `address_id`, `date_address_from`, `address_type_code`, `date_address_to`) VALUES (10, 8, '2016-04-08 22:40:02', 'Residence', '2018-02-28 23:14:41'); INSERT INTO Party_Forms (`party_id`, `form_id`, `date_completion_started`, `form_status_code`, `date_fully_completed`) VALUES (2, 4, '2017-12-17 11:29:47', 'Completed', '2018-02-11 16:46:10'); INSERT INTO Party_Services (`booking_id`, `customer_id`, `service_id`, `service_datetime`, `booking_made_date`) VALUES (1, 10, 12, '2018-03-10 22:43:12', '2018-03-23 23:56:51');
school_bus
SELECT count(*) FROM driver
How many drivers are there?
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT name , home_city , age FROM driver
Show the name, home city, and age for all drivers.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT party , count(*) FROM driver GROUP BY party
Show the party and the number of drivers in each party.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT name FROM driver ORDER BY age DESC
Show the name of drivers in descending order of age.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT DISTINCT home_city FROM driver
Show all different home cities.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT home_city FROM driver GROUP BY home_city ORDER BY count(*) DESC LIMIT 1
Show the home city with the most number of drivers.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT party FROM driver WHERE home_city = 'Hartford' AND age > 40
Show the party with drivers from Hartford and drivers older than 40.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT home_city FROM driver WHERE age > 40 GROUP BY home_city HAVING count(*) >= 2
Show home city where at least two drivers older than 40 are from.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT home_city FROM driver EXCEPT SELECT home_city FROM driver WHERE age > 40
Show all home cities except for those having a driver older than 40.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT name FROM driver WHERE driver_id NOT IN (SELECT driver_id FROM school_bus)
Show the names of the drivers without a school bus.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT TYPE FROM school GROUP BY TYPE HAVING count(*) = 2
Show the types of schools that have two schools.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
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
Show the school name and driver name for all school buses.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT max(years_working) , min(years_working) , avg(years_working) FROM school_bus
What is the maximum, minimum and average years spent working on a school bus?
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT school , TYPE FROM school WHERE school_id NOT IN (SELECT school_id FROM school_bus)
Show the school name and type for schools without a school bus.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT T2.type , count(*) FROM school_bus AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id GROUP BY T2.type
Show the type of school and the number of buses for each type.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT count(*) FROM driver WHERE home_city = 'Hartford' OR age < 40
How many drivers are from Hartford city or younger than 40?
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
SELECT name FROM driver WHERE home_city = 'Hartford' AND age < 40
List names for drivers from Hartford city and younger than 40.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
school_bus
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
find the name of driver who is driving the school bus with the longest working history.
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") ); INSERT INTO "driver" VALUES ("1","Matthew Ritter","Dem","Hartford",40); INSERT INTO "school" VALUES (1,"Kindergarten","Noelani Elementary School","Honolulu, Hawaii","Public"); INSERT INTO "school_bus" VALUES (1,10,10,"F");
flight_company
SELECT count(*) FROM flight WHERE velocity > 200
How many flights have a velocity larger than 200?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT vehicle_flight_number , date , pilot FROM flight ORDER BY altitude ASC
List the vehicle flight number, date and pilot of all the flights, ordered by altitude.
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT id , country , city , name FROM airport ORDER BY name
List the id, country, city and name of the airports ordered alphabetically by the name.
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT max(group_equity_shareholding) FROM operate_company
What is maximum group equity shareholding of the companies?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT avg(velocity) FROM flight WHERE pilot = 'Thompson'
What is the velocity of the pilot named 'Thompson'?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT T1.name , T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id
What are the names and types of the companies that have ever operated a flight?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT name FROM airport WHERE country != 'Iceland'
What are the names of the airports which are not in the country 'Iceland'?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT DISTINCT T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T2.velocity < 200
What are the distinct types of the companies that have operated any flights with velocity less than 200?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
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
What are the ids and names of the companies that operated more than one flight?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
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
What is the id, name and IATA code of the airport that had most number of flights?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
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'
What are the different pilot names who had piloted a flight in the country 'United States' or in the airport named 'Billund Airport'?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT TYPE , count(*) FROM operate_company GROUP BY TYPE ORDER BY count(*) DESC LIMIT 1
What is the most common company type, and how many are there?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT count(*) FROM airport WHERE id NOT IN ( SELECT airport_id FROM flight WHERE pilot = 'Thompson' );
How many airports haven't the pilot 'Thompson' driven an aircraft?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
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'
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.
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT name FROM airport WHERE name LIKE '%international%'
Which of the airport names contains the word 'international'?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
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
How many companies operates airlines in each airport?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT count(*) , country FROM airport GROUP BY country
how many airports are there in each country?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT country FROM airport GROUP BY country HAVING count(*) > 2
which countries have more than 2 airports?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
flight_company
SELECT pilot FROM flight GROUP BY pilot ORDER BY count(*) DESC LIMIT 1
which pilot is in charge of the most number of flights?
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, primary key("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, primary key ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, primary key ("id"), foreign key ("airport_id") references `airport`("id"), foreign key ("company_id") references `operate_company`("id") ); INSERT INTO "airport" VALUES (1,"Akureyri","Iceland","AEY","BIAR","Akureyri Airport"); INSERT INTO "operate_company" VALUES (1, "Air China","Corporate","Airline","China","18.77"); INSERT INTO "flight" VALUES (1,"M2-F1 #0","March 1, 1963","Thompson","135","0", 1,2);
cre_Docs_and_Epenses
SELECT count(*) FROM Accounts
How many accounts do we have?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT count(*) FROM Accounts
Count the number of accounts.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT account_id , account_details FROM Accounts
Show all account ids and account details.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT account_id , account_details FROM Accounts
What are the ids and details of all accounts?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT count(*) FROM Statements
How many statements do we have?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT count(*) FROM Statements
Count the number of statements.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT STATEMENT_ID , statement_details FROM Statements
List all statement ids and statement details.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT STATEMENT_ID , statement_details FROM Statements
What are the ids and details of all statements?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
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
Show statement id, statement detail, account detail for accounts.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
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
What are the statement ids, statement details, and account details, for all accounts?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT STATEMENT_ID , count(*) FROM Accounts GROUP BY STATEMENT_ID
Show all statement id and the number of accounts for each statement.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT STATEMENT_ID , count(*) FROM Accounts GROUP BY STATEMENT_ID
What are the different statement ids on accounts, and the number of accounts for each?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
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
Show the statement id and the statement detail for the statement with most number of accounts.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
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
What are the statement id and statement detail for the statement that has the most corresponding accounts?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT count(*) FROM Documents
Show the number of documents.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT count(*) FROM Documents
Count the number of documents.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_type_code , document_name , document_description FROM Documents WHERE document_name = 'Noel CV' OR document_name = 'King Book'
List the document type code, document name, and document description for the document with name 'Noel CV' or name 'King Book'.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_type_code , document_name , document_description FROM Documents WHERE document_name = 'Noel CV' OR document_name = 'King Book'
What are the type come, name, and description of the document that has either the name 'Noel CV' or 'King Book'?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_id , document_name FROM Documents
Show the ids and names of all documents.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_id , document_name FROM Documents
What are the ids and names for each of the documents?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_name , document_id FROM Documents WHERE document_type_code = "BK"
Find names and ids of all documents with document type code BK.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_name , document_id FROM Documents WHERE document_type_code = "BK"
What are the names and ids of documents that have the type code BK?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT count(*) , project_id FROM Documents WHERE document_type_code = "BK" GROUP BY project_id
How many documents are with document type code BK for each product id?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT count(*) , project_id FROM Documents WHERE document_type_code = "BK" GROUP BY project_id
Count the number of documents with the type code BK that correspond to each product id.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_name , document_date FROM Documents AS T1 JOIN projects AS T2 ON T1.project_id = T2.project_id WHERE T2.project_details = 'Graph Database project'
Show the document name and the document date for all documents on project with details 'Graph Database project'.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_name , document_date FROM Documents AS T1 JOIN projects AS T2 ON T1.project_id = T2.project_id WHERE T2.project_details = 'Graph Database project'
What are the names and dates for documents corresponding to project that has the details 'Graph Database project'?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT project_id , count(*) FROM Documents GROUP BY project_id
Show project ids and the number of documents in each project.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT project_id , count(*) FROM Documents GROUP BY project_id
How many documents correspond with each project id?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT project_id FROM Documents GROUP BY project_id ORDER BY count(*) ASC LIMIT 1
What is the id of the project with least number of documents?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT project_id FROM Documents GROUP BY project_id ORDER BY count(*) ASC LIMIT 1
Return the id of the project that has the fewest corresponding documents.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT project_id FROM Documents GROUP BY project_id HAVING count(*) >= 2
Show the ids for projects with at least 2 documents.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT project_id FROM Documents GROUP BY project_id HAVING count(*) >= 2
What are project ids of projects that have 2 or more corresponding documents?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_type_code , count(*) FROM Documents GROUP BY document_type_code
List document type codes and the number of documents in each code.
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_type_code , count(*) FROM Documents GROUP BY document_type_code
How many documents are there of each type?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');
cre_Docs_and_Epenses
SELECT document_type_code FROM Documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1
What is the document type code with most number of documents?
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( Statement_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (Statement_ID), FOREIGN KEY (Statement_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, Statement_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (Statement_ID) REFERENCES Statements (Statement_ID) ); INSERT INTO Ref_Budget_Codes (`Budget_Type_Code`, `Budget_Type_Description`) VALUES ('GV', 'Government'); INSERT INTO Ref_Document_Types (`Document_Type_Code`, `Document_Type_Name`, `Document_Type_Description`) VALUES ('BK', 'Book', 'excellent'); INSERT INTO Projects (`Project_ID`, `Project_Details`) VALUES (30, 'Society Research project'); INSERT INTO Documents (`Document_ID`, `Document_Type_Code`, `Project_ID`, `Document_Date`, `Document_Name`, `Document_Description`, `Other_Details`) VALUES (29, 'CV', 30, '2004-08-28 06:59:19', 'Review on UK files', NULL, NULL); INSERT INTO Statements (`Statement_ID`, `Statement_Details`) VALUES (57, 'Open Project'); INSERT INTO Documents_with_Expenses (`Document_ID`, `Budget_Type_Code`, `Document_Details`) VALUES (57, 'GV', 'government'); INSERT INTO Accounts (`Account_ID`, `Statement_ID`, `Account_Details`) VALUES (7, 57, '495.063');