instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Update the safety records of all vessels that have been involved in accidents in the South China Sea.
CREATE TABLE vessels (id INT,name TEXT,type TEXT,safety_record TEXT); INSERT INTO vessels (id,name,type,safety_record) VALUES (1,'Vessel E','Cargo','Good'); INSERT INTO vessels (id,name,type,safety_record) VALUES (2,'Vessel F','Tanker','Excellent'); CREATE TABLE incidents (id INT,vessel_id INT,location TEXT,incident_date DATE); INSERT INTO incidents (id,vessel_id,location,incident_date) VALUES (1,1,'South China Sea','2022-02-15'); INSERT INTO incidents (id,vessel_id,location,incident_date) VALUES (2,2,'East China Sea','2022-03-01');
UPDATE vessels SET safety_record = 'Poor' WHERE id IN (SELECT vessel_id FROM incidents WHERE location = 'South China Sea');
How many cultural competency trainings were conducted in 2022 in the cultural_competency schema?
CREATE TABLE cultural_competency_trainings (training_id INT,year INT,location VARCHAR(50)); INSERT INTO cultural_competency_trainings (training_id,year,location) VALUES (1,2022,'NYC'); INSERT INTO cultural_competency_trainings (training_id,year,location) VALUES (2,2021,'LA');
SELECT COUNT(*) FROM cultural_competency.cultural_competency_trainings WHERE year = 2022;
What is the change in the quantity of each ethically sourced product sold, compared to the previous day, for the last 14 days?
CREATE TABLE daily_sales (sale_date DATE,product_id INT,quantity INT,ethical_source BOOLEAN); INSERT INTO daily_sales VALUES ('2022-06-01',1,50,true),('2022-06-01',2,30,false),('2022-06-02',1,75,true),('2022-06-02',2,40,false),('2022-06-03',1,80,true),('2022-06-03',2,35,false),('2022-06-04',1,90,true),('2022-06-04',2,45,false);
SELECT sale_date, product_id, quantity, LAG(quantity, 1) OVER (PARTITION BY product_id, ethical_source ORDER BY sale_date) as prev_quantity, quantity - LAG(quantity, 1) OVER (PARTITION BY product_id, ethical_source ORDER BY sale_date) as quantity_change FROM daily_sales WHERE sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 14 DAY) AND ethical_source = true ORDER BY sale_date, product_id;
What is the average duration of legal aid cases in 'justice_legal_aid' table, for 'Civil' cases, in the last 6 months?
CREATE TABLE justice_legal_aid (id INT,case_id INT,case_type TEXT,duration INT,resolution_date DATE); INSERT INTO justice_legal_aid (id,case_id,case_type,duration,resolution_date) VALUES (1,1,'Civil',6,'2021-05-01'),(2,2,'Criminal',12,'2020-01-01'),(3,3,'Civil',3,'2021-03-15');
SELECT AVG(duration/30.0) FROM justice_legal_aid WHERE case_type = 'Civil' AND resolution_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
What is the average water waste per household in each city in 2021?
CREATE TABLE wastewater_treatment (household_id INT,city VARCHAR(30),year INT,waste_amount FLOAT);
SELECT city, AVG(waste_amount) FROM wastewater_treatment WHERE year=2021 GROUP BY city;
Insert new records for the languages 'Mapudungun' and 'Guarani' into the Languages table.
CREATE TABLE Languages (Language VARCHAR(50),Status VARCHAR(50));
INSERT INTO Languages (Language, Status) VALUES ('Mapudungun', 'Vulnerable'), ('Guarani', 'Vulnerable');
What percentage of the audience is female and prefers articles about politics in the Northeast region?
CREATE TABLE audience (id INT,gender VARCHAR(10),region VARCHAR(20)); CREATE TABLE interests (id INT,category VARCHAR(20)); INSERT INTO audience VALUES (1,'female','Northeast'); INSERT INTO interests VALUES (1,'politics');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM audience)) as percentage FROM audience INNER JOIN interests ON audience.id = interests.id WHERE audience.region = 'Northeast' AND interests.category = 'politics' AND audience.gender = 'female';
Calculate the average design life of water treatment plants in 'Texas'
CREATE TABLE water_treatment_plants (id INT,name VARCHAR(50),location VARCHAR(50),design_life INT); INSERT INTO water_treatment_plants (id,name,location,design_life) VALUES (1,'Central Water Treatment Plant','Texas',40);
SELECT AVG(design_life) FROM water_treatment_plants WHERE location = 'Texas';
What is the minimum weight of containers shipped from the Port of Tanjung Pelepas to Malaysia in Q3 of 2020?
CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT);CREATE TABLE shipments (shipment_id INT,shipment_weight INT,ship_date DATE,port_id INT); INSERT INTO ports VALUES (1,'Port of Tanjung Pelepas','Malaysia'),(2,'Port of Johor Bahru','Malaysia'); INSERT INTO shipments VALUES (1,1500,'2020-07-01',1),(2,1800,'2020-08-15',2);
SELECT MIN(shipment_weight) FROM shipments JOIN ports ON shipments.port_id = ports.port_id WHERE ports.country = 'Malaysia' AND ports.port_name IN ('Port of Tanjung Pelepas', 'Port of Johor Bahru') AND ship_date BETWEEN '2020-07-01' AND '2020-09-30';
What is the average claim amount for policies issued in the last quarter in California?
CREATE TABLE policy (policy_id INT,issue_date DATE,zip_code INT); CREATE TABLE claim (claim_id INT,policy_id INT,claim_amount INT);
SELECT AVG(claim_amount) FROM claim JOIN policy ON claim.policy_id = policy.policy_id WHERE policy.issue_date >= DATEADD(QUARTER, -1, GETDATE()) AND zip_code = (SELECT zip_code FROM zip_codes WHERE state = 'CA' AND city = 'Los Angeles');
What is the average duration of media contents produced in the USA?
CREATE TABLE media_contents (content_id INTEGER,title VARCHAR(255),duration INTEGER,production_country VARCHAR(100)); INSERT INTO media_contents (content_id,title,duration,production_country) VALUES (1,'Content1',120,'USA'),(2,'Content2',90,'Canada'),(3,'Content3',150,'USA');
SELECT AVG(duration) FROM media_contents WHERE production_country = 'USA';
Which conservation initiatives are specific to the Arctic region and do not involve the Dolphin species?
CREATE TABLE conservation_initiatives (id INT,initiative VARCHAR(255),species VARCHAR(255),region VARCHAR(255)); INSERT INTO conservation_initiatives (id,initiative,species,region) VALUES (1,'Ice Cap Mapping','Polar Bear','Arctic'),(2,'Beach Cleanup','Dolphin','Pacific'),(3,'Coral Restoration','Clownfish','Indian'),(4,'Fish Population Study','Cod','Atlantic'),(5,'Ocean Floor Mapping','Seal','Arctic');
SELECT initiative FROM conservation_initiatives WHERE region = 'Arctic' AND species != 'Dolphin';
What is the total number of employees by job category?
CREATE TABLE job_categories (id INT,name VARCHAR(255)); INSERT INTO job_categories (id,name) VALUES (1,'Manager'),(2,'Engineer'),(3,'Sales'); CREATE TABLE employees (id INT,name VARCHAR(255),job_category_id INT); INSERT INTO employees (id,name,job_category_id) VALUES (1,'Jane Doe',1),(2,'Alice Smith',2),(3,'Bob Johnson',3);
SELECT job_categories.name, COUNT(employees.id) as total FROM job_categories JOIN employees ON job_categories.id = employees.job_category_id GROUP BY job_categories.name;
List all unique case types in the 'West' region with a count of cases for each type.
CREATE TABLE case_data(case_id INT,region VARCHAR(10),case_type VARCHAR(10),case_status VARCHAR(10)); INSERT INTO case_data(case_id,region,case_type,case_status) VALUES (101,'East','civil','open'),(102,'West','criminal','closed'),(103,'West','civil','open'),(104,'East','divorce','closed'),(105,'West','divorce','open');
SELECT case_type, COUNT(*) FROM case_data WHERE region = 'West' GROUP BY case_type;
What is the maximum volunteer hours recorded in a single day?
CREATE TABLE VolunteerHours (HourID INT,VolunteerID INT,EventID INT,Hours INT,HourDate DATE); INSERT INTO VolunteerHours (HourID,VolunteerID,EventID,Hours,HourDate) VALUES (1,1,1,5,'2022-01-01'),(2,2,1,6,'2022-01-01');
SELECT MAX(Hours) FROM VolunteerHours WHERE VolunteerHours.HourDate = (SELECT MAX(HourDate) FROM VolunteerHours);
List startups that received funding in January 2018
CREATE TABLE funding_records (id INT PRIMARY KEY,startup_id INT,amount DECIMAL(10,2),funding_date DATE);
SELECT startup_id FROM funding_records WHERE funding_date BETWEEN '2018-01-01' AND '2018-01-31' GROUP BY startup_id;
Delete records from the trend_forecasting table that are older than 6 months.
CREATE TABLE trend_forecasting(id INT PRIMARY KEY,region VARCHAR(50),product_category VARCHAR(50),forecast_date DATE,forecast_units INT);
DELETE FROM trend_forecasting WHERE forecast_date < DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
Find the number of sustainable properties in each neighborhood, ordered from lowest to highest.
CREATE TABLE Neighborhoods (NeighborhoodID INT,NeighborhoodName VARCHAR(255)); CREATE TABLE Properties (PropertyID INT,NeighborhoodID INT,Size INT,Sustainable BOOLEAN);
SELECT NeighborhoodName, COUNT(*) AS SustainablePropertiesCount FROM Properties JOIN Neighborhoods ON Properties.NeighborhoodID = Neighborhoods.NeighborhoodID WHERE Sustainable = 1 GROUP BY NeighborhoodName ORDER BY SustainablePropertiesCount ASC;
Determine if there are healthcare providers with no mental health parity scores.
CREATE TABLE healthcare_providers (provider_id INT,name TEXT,state TEXT); INSERT INTO healthcare_providers (provider_id,name,state) VALUES (1,'Ms. Jessica Thompson','NY'),(2,'Mr. Ryan Adams','NY'); CREATE TABLE mental_health_parity (provider_id INT,score INT);
SELECT h.name FROM healthcare_providers h LEFT JOIN mental_health_parity m ON h.provider_id = m.provider_id WHERE m.score IS NULL;
Count the number of financial wellbeing programs in Asia by region.
CREATE TABLE programs (id INT PRIMARY KEY,program_name VARCHAR(255),region_id INT,is_financial_wellbeing BOOLEAN); CREATE TABLE regions (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); CREATE VIEW program_views AS SELECT programs.id,programs.program_name,programs.region_id,programs.is_financial_wellbeing,regions.country FROM programs INNER JOIN regions ON TRUE;
SELECT regions.country AS region, COUNT(programs.id) AS num_of_programs FROM program_views INNER JOIN regions ON program_views.region_id = regions.id WHERE program_views.is_financial_wellbeing = TRUE GROUP BY regions.country;
What are the names and locations of all Ytterbium mines in North America?
CREATE TABLE ytterbium_mines (mine_name VARCHAR(50),country VARCHAR(20)); INSERT INTO ytterbium_mines (mine_name,country) VALUES ('Y1 Mine','USA'),('Y2 Mine','Canada'),('Y3 Mine','Mexico');
SELECT mine_name, country FROM ytterbium_mines WHERE country IN ('USA', 'Canada', 'Mexico');
What's the average production budget for action movies released between 2000 and 2010, and their respective IMDb ratings?
CREATE TABLE movie (id INT,title VARCHAR(100),genre VARCHAR(20),production_budget INT,release_year INT,IMDb_rating DECIMAL(3,1)); INSERT INTO movie (id,title,genre,production_budget,release_year,IMDb_rating) VALUES (1,'Die Hard','Action',200000000,1988,7.2);
SELECT AVG(production_budget), AVG(IMDb_rating) FROM movie WHERE genre = 'Action' AND release_year BETWEEN 2000 AND 2010;
What is the average revenue of hotels in the US that offer virtual tours?
CREATE TABLE hotels (id INT,name TEXT,country TEXT,revenue FLOAT,virtual_tours BOOLEAN);
SELECT AVG(revenue) FROM hotels WHERE country = 'United States' AND virtual_tours = TRUE;
What is the average time taken for a tennis match to finish in the 'tennis_matches' table?
CREATE TABLE tennis_matches (id INT,player1 VARCHAR(50),player2 VARCHAR(50),location VARCHAR(50),date DATE,time_taken INT); INSERT INTO tennis_matches (id,player1,player2,location,date,time_taken) VALUES (1,'Novak Djokovic','Rafael Nadal','Melbourne','2022-01-15',240); INSERT INTO tennis_matches (id,player1,player2,location,date,time_taken) VALUES (2,'Serena Williams','Naomi Osaka','Melbourne','2022-01-16',180);
SELECT AVG(time_taken) FROM tennis_matches;
Find the top 5 products with the highest revenue and the lowest carbon footprint, and their corresponding revenues and carbon footprints.
CREATE TABLE product_sales (sale_id INT,product_id INT,revenue DECIMAL(10,2),carbon_footprint INT); INSERT INTO product_sales VALUES (1,1,100.00,50),(2,1,200.00,50),(3,2,300.00,70),(4,2,400.00,70),(5,3,500.00,80),(6,3,600.00,80);
SELECT product_id, SUM(revenue) as total_revenue, MIN(carbon_footprint) as min_carbon_footprint FROM product_sales GROUP BY product_id ORDER BY total_revenue DESC, min_carbon_footprint ASC LIMIT 5;
List the music genres that have more than 3000000 in revenue and the number of artists associated with those genres.
CREATE TABLE ArtistGenre (ArtistID INT,Genre VARCHAR(20),Revenue FLOAT); INSERT INTO ArtistGenre (ArtistID,Genre,Revenue) VALUES (1,'Pop','2500000'),(2,'Rock','4000000'),(3,'Jazz','3000000'),(4,'Hip Hop','6500000');
SELECT Genre, SUM(Revenue), COUNT(DISTINCT ArtistID) FROM ArtistGenre WHERE Revenue > 3000000 GROUP BY Genre;
Number of unique patients who attended therapy sessions per region?
CREATE TABLE patients_therapy (patient_id INT,therapy_attended CHAR(1),region VARCHAR(20)); INSERT INTO patients_therapy (patient_id,therapy_attended,region) VALUES (1,'Y','Asia'),(2,'Y','Europe'),(3,'Y','America'),(4,'N','Asia');
SELECT region, COUNT(DISTINCT patient_id) as unique_patients_attended FROM patients_therapy WHERE therapy_attended = 'Y' GROUP BY region;
Add a new record for an auto show with a specific date and location to the auto_show_information table.
CREATE TABLE auto_show_information (show_id INT,show_name VARCHAR(50),show_date DATE,show_location VARCHAR(50));
INSERT INTO auto_show_information (show_id, show_name, show_date, show_location) VALUES (456, 'New York Auto Show', '2023-04-14', 'New York City');
What are the top 5 most common vulnerabilities found in the 'Network' department?
CREATE TABLE vulnerabilities (vulnerability_id INT PRIMARY KEY,vulnerability_name VARCHAR(100),department VARCHAR(50)); INSERT INTO vulnerabilities (vulnerability_id,vulnerability_name,department) VALUES (1,'Cross-site scripting','Network'),(2,'SQL injection','Network'),(3,'Buffer overflow','Network'),(4,'Missing authentication','Admin'),(5,'Privilege escalation','Admin');
SELECT vulnerability_name, COUNT(*) FROM vulnerabilities WHERE department = 'Network' GROUP BY vulnerability_name ORDER BY COUNT(*) DESC LIMIT 5;
What is the average rating of lipsticks produced in the USA?
CREATE TABLE Cosmetics (product_id INT,product_name VARCHAR(100),rating FLOAT,country_of_origin VARCHAR(50)); INSERT INTO Cosmetics (product_id,product_name,rating,country_of_origin) VALUES (1,'Lipstick A',4.2,'USA'),(2,'Lipstick B',3.9,'France'),(3,'Lipstick C',4.5,'USA');
SELECT AVG(rating) as avg_rating FROM Cosmetics WHERE country_of_origin = 'USA' AND product_name LIKE '%lipstick%';
What are the top 2 countries with the most artists represented in museums in Tokyo?
CREATE TABLE Museums_Artists (museum VARCHAR(30),artist VARCHAR(30),country VARCHAR(20)); INSERT INTO Museums_Artists (museum,artist,country) VALUES ('Tokyo Museum','Hokusai','Japanese'),('Tokyo Museum','Yayoi','Japanese'),('Tokyo Museum','Van Gogh','Dutch'),('Tokyo Gallery','Monet','French'),('Tokyo Gallery','Picasso','Spanish');
SELECT country, COUNT(*) as count FROM Museums_Artists WHERE museum = 'Tokyo Museum' OR museum = 'Tokyo Gallery' GROUP BY country ORDER BY count DESC LIMIT 2;
What is the total donation amount for each program in '2021'?
CREATE TABLE program_donations (id INT,program TEXT,donation_date DATE,donation_amount DECIMAL); INSERT INTO program_donations (id,program,donation_date,donation_amount) VALUES (1,'Education','2021-12-31',1200.00); INSERT INTO program_donations (id,program,donation_date,donation_amount) VALUES (2,'Healthcare','2021-06-15',800.00);
SELECT program, SUM(donation_amount) FROM program_donations WHERE YEAR(donation_date) = 2021 GROUP BY program;
What is the total weight of all products delivered by distributor C after 2022-01-01?
CREATE TABLE Distributors (DistributorID varchar(10),DistributorName varchar(20)); INSERT INTO Distributors VALUES ('C','Distributor C'); CREATE TABLE Deliveries (DeliveryID int,DeliveryDate date,ProduceID varchar(10),StoreID int,DistributorID varchar(10),Weight int); INSERT INTO Deliveries VALUES (1,'2022-01-02','P001',1,'C',20),(2,'2022-01-03','P002',2,'C',30);
SELECT SUM(Weight) FROM Deliveries WHERE DistributorID = 'C' AND DeliveryDate > '2022-01-01';
Identify which suppliers have had deliveries delayed by more than a week in the last month, and the number of times this has occurred.
CREATE TABLE suppliers (id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE deliveries (id INT,supplier_id INT,delivery_date DATE,delivery_status VARCHAR(50));
SELECT suppliers.name, COUNT(*) AS delivery_delays FROM suppliers JOIN deliveries ON suppliers.id = deliveries.supplier_id WHERE deliveries.delivery_date < DATE(NOW()) - INTERVAL 1 MONTH AND deliveries.delivery_status = 'Delayed' GROUP BY suppliers.name HAVING delivery_delays > 1;
What is the ratio of coral reefs to seagrasses in marine protected areas?
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),coral_reefs INT,seagrasses INT); INSERT INTO marine_protected_areas (id,name,coral_reefs,seagrasses) VALUES (1,'Galapagos',5,3);
SELECT (SUM(coral_reefs) * 1.0 / SUM(seagrasses)) FROM marine_protected_areas
What is the percentage of autonomous buses in the Dubai public transportation system?
CREATE TABLE dubai_buses(id INT,bus_number INT,line VARCHAR(20),autonomous BOOLEAN);
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM dubai_buses) AS percentage FROM dubai_buses WHERE autonomous = TRUE;
What is the total number of bridges in the 'Bridges' table built before 2000?
CREATE TABLE Bridges (ID INT,Name VARCHAR(50),Location VARCHAR(50),DateAdded DATE); INSERT INTO Bridges (ID,Name,Location,DateAdded) VALUES (1,'Golden Gate Bridge','San Francisco,CA','1937-05-27'); INSERT INTO Bridges (ID,Name,Location,DateAdded) VALUES (2,'George Washington Bridge','New York,NY','1931-10-25'); INSERT INTO Bridges (ID,Name,Location,DateAdded) VALUES (3,'Chesapeake Bay Bridge-Tunnel','Virginia Beach,VA','1964-04-15');
SELECT COUNT(*) FROM Bridges WHERE DateAdded < '2000-01-01';
What is the average age of users who liked post 12345 in the music category?
CREATE TABLE users (user_id INT,age INT,gender VARCHAR(10)); INSERT INTO users (user_id,age,gender) VALUES (1,25,'Female'),(2,35,'Male'),(3,22,'Female'); CREATE TABLE post_likes (like_id INT,user_id INT,post_id INT,category VARCHAR(20)); INSERT INTO post_likes (like_id,user_id,post_id,category) VALUES (1,1,12345,'music'),(2,2,12345,'music'),(3,3,67890,'sports');
SELECT AVG(users.age) FROM users INNER JOIN post_likes ON users.user_id = post_likes.user_id WHERE post_likes.post_id = 12345 AND post_likes.category = 'music';
How many aircraft incidents occurred by incident type and manufacturer?
CREATE TABLE AircraftIncidents (IncidentID INT,ManufacturerID INT,IncidentType VARCHAR(50));CREATE TABLE AircraftManufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50));
SELECT IncidentType, ManufacturerName, COUNT(*) AS IncidentCount FROM AircraftIncidents AI INNER JOIN AircraftManufacturers AM ON AI.ManufacturerID = AM.ManufacturerID GROUP BY IncidentType, ManufacturerName;
What is the average time between train cleanings for each route in the city of Tokyo?
CREATE TABLE trains (id INT,route_id INT,clean_date DATE); INSERT INTO trains (id,route_id,clean_date) VALUES (1,101,'2022-01-01'),(2,102,'2022-01-02'),(3,103,'2022-01-03');
SELECT route_id, AVG(DATEDIFF('day', LAG(clean_date) OVER (PARTITION BY route_id ORDER BY clean_date), clean_date)) FROM trains WHERE city = 'Tokyo' GROUP BY route_id;
Rank the mining sites by the percentage of waste material reused in the past year.
CREATE TABLE WasteMaterial (SiteID INT,Date DATE,Material VARCHAR(255),Weight INT); INSERT INTO WasteMaterial (SiteID,Date,Material,Weight) VALUES (1,'2021-01-01','Rock',500),(1,'2021-02-01','Soil',300),(1,'2021-03-01','Rock',400),(1,'2021-04-01','Soil',200),(1,'2021-05-01','Rock',600),(1,'2021-06-01','Soil',400),(2,'2021-01-01','Rock',700),(2,'2021-02-01','Soil',500),(2,'2021-03-01','Rock',800),(2,'2021-04-01','Soil',600),(2,'2021-05-01','Rock',900),(2,'2021-06-01','Soil',700);
SELECT SiteID, SUM(CASE WHEN Material = 'Rock' THEN Weight ELSE 0 END) / SUM(Weight) OVER (PARTITION BY SiteID) as Percentage_Reused FROM WasteMaterial WHERE Date >= DATEADD(YEAR, -1, GETDATE()) GROUP BY SiteID, Material, Date;
Find the average CO2 emissions reduction achieved by climate adaptation initiatives in Europe.
CREATE TABLE co2_emissions (initiative_id INT,initiative_name VARCHAR(50),region VARCHAR(50),co2_emissions_reduction DECIMAL(5,2)); INSERT INTO co2_emissions (initiative_id,initiative_name,region,co2_emissions_reduction) VALUES (1,'Climate Adaptation Fund','Europe',12.50),(2,'Green Cities','Europe',15.00),(3,'Resilient Infrastructure','Europe',18.75);
SELECT AVG(co2_emissions_reduction) FROM co2_emissions WHERE region = 'Europe' AND initiative_name IN ('Climate Adaptation Fund', 'Green Cities', 'Resilient Infrastructure');
What is the total number of tourists who visited cultural heritage sites in India last year?
CREATE TABLE countries (country_id INT,country TEXT); INSERT INTO countries (country_id,country) VALUES (1,'India'); CREATE TABLE years (year_id INT,year TEXT); INSERT INTO years (year_id,year) VALUES (1,'2022'); CREATE TABLE tourism (tourist_id INT,country_id INT,year_id INT,site_type TEXT); INSERT INTO tourism (tourist_id,country_id,year_id,site_type) VALUES (1,1,1,'cultural_heritage'),(2,1,1,'beach'),(3,1,1,'cultural_heritage');
SELECT COUNT(*) FROM tourism WHERE country_id = (SELECT country_id FROM countries WHERE country = 'India') AND year_id = (SELECT year_id FROM years WHERE year = '2022') AND site_type = 'cultural_heritage';
Find the daily maximum response time for emergency calls in the 'harbor' precinct in January 2022.
CREATE TABLE emergency_calls (id INT,precinct VARCHAR(20),response_time INT,call_date DATE); INSERT INTO emergency_calls (id,precinct,response_time,call_date) VALUES (1,'harbor',15,'2022-01-01');
SELECT precinct, call_date, MAX(response_time) FROM emergency_calls WHERE precinct = 'harbor' AND call_date BETWEEN '2022-01-01' AND '2022-01-31' GROUP BY precinct, call_date;
What is the total volume of freight forwarded from the Tokyo warehouse in March 2022?
CREATE TABLE Freight (id INT,warehouse_id INT,forward_date DATE,volume FLOAT); INSERT INTO Freight (id,warehouse_id,forward_date,volume) VALUES (1,4,'2022-03-15',150.2),(2,4,'2022-03-27',120.8),(3,5,'2022-03-04',180.5); CREATE TABLE Warehouses (id INT,name TEXT,city TEXT,state TEXT); INSERT INTO Warehouses (id,name,city,state) VALUES (4,'Tokyo Warehouse','Tokyo','JP'),(5,'Seoul Warehouse','Seoul','KR');
SELECT SUM(volume) FROM Freight JOIN Warehouses ON Freight.warehouse_id = Warehouses.id WHERE Warehouses.name = 'Tokyo Warehouse' AND EXTRACT(MONTH FROM forward_date) = 3 AND EXTRACT(YEAR FROM forward_date) = 2022;
Insert a new aircraft model 'A380' with engine 'Engine Alliance GP7200'
CREATE TABLE aircraft (id INT PRIMARY KEY,model VARCHAR(50),engine VARCHAR(50));
INSERT INTO aircraft (id, model, engine) VALUES (106, 'A380', 'Engine Alliance GP7200');
What is the 'total_cost' for the project with the name 'Coastal Protection'?
CREATE TABLE infrastructure_projects (id INT,project_name VARCHAR(50),location VARCHAR(50),total_cost INT); INSERT INTO infrastructure_projects (id,project_name,location,total_cost) VALUES (1,'Road Widening','City A',500000),(2,'Coastal Protection','City B',700000);
SELECT total_cost FROM infrastructure_projects WHERE project_name = 'Coastal Protection';
Which countries have renewable energy projects with a combined capacity of at least 500 MW in the projects and project_capacity tables?
CREATE TABLE projects(id INT,project_name VARCHAR(50),project_type VARCHAR(50),country VARCHAR(50));CREATE TABLE project_capacity(project_id INT,capacity_mw FLOAT);
SELECT p.country FROM projects p INNER JOIN project_capacity pc ON p.id = pc.project_id GROUP BY p.country HAVING SUM(pc.capacity_mw) >= 500;
List all regulations for vessels operating in the port of Rotterdam?
CREATE TABLE Regulation (id INT PRIMARY KEY,name VARCHAR(50),description VARCHAR(50)); CREATE TABLE Vessel_Regulation (vessel_id INT,regulation_id INT,PRIMARY KEY (vessel_id,regulation_id),FOREIGN KEY (vessel_id) REFERENCES Vessel(id),FOREIGN KEY (regulation_id) REFERENCES Regulation(id)); CREATE TABLE Port (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE Vessel (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50),port_id INT,FOREIGN KEY (port_id) REFERENCES Port(id));
SELECT R.name FROM Regulation R JOIN Vessel_Regulation VR ON R.id = VR.regulation_id JOIN Vessel V ON VR.vessel_id = V.id JOIN Port P ON V.port_id = P.id WHERE P.name = 'Rotterdam';
What was the total number of volunteer hours for each program in Q1 2022?
CREATE TABLE Volunteer_Hours (id INT,program VARCHAR(50),hours DECIMAL(5,2),hour_date DATE); INSERT INTO Volunteer_Hours (id,program,hours,hour_date) VALUES (1,'Refugee Support',12.5,'2022-01-03'),(2,'Food Bank',17.0,'2022-01-05'),(3,'Refugee Support',18.5,'2022-01-10'),(4,'Food Bank',20.0,'2022-01-12');
SELECT program, DATE_FORMAT(hour_date, '%Y-%m') as quarter, SUM(hours) as total_hours FROM Volunteer_Hours WHERE hour_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY program, quarter;
Insert a new socially responsible lending initiative.
CREATE TABLE lending_initiatives (id INT,initiative_type VARCHAR(255),value DECIMAL(10,2));
INSERT INTO lending_initiatives (initiative_type, value) VALUES ('Socially Responsible', 12000.00);
Which menu category has the highest inventory value for non-organic items?
CREATE TABLE non_organic_categories (id INT,category VARCHAR(255),total_value DECIMAL(5,2)); INSERT INTO non_organic_categories (id,category,total_value) VALUES (1,'Proteins',199.00),(2,'Grains',74.25);
SELECT category, total_value FROM non_organic_categories ORDER BY total_value DESC LIMIT 1;
What is the total number of criminal cases processed by court location in the 'criminal_cases' table?
CREATE TABLE criminal_cases (case_id INT,case_number VARCHAR(20),case_type VARCHAR(30),court_location VARCHAR(30),processing_date DATE);
CREATE VIEW case_counts AS SELECT court_location, COUNT(*) AS case_count FROM criminal_cases GROUP BY court_location;
What is the average number of military personnel per base in 'Europe'?
CREATE TABLE MilitaryBases (ID INT,BaseName VARCHAR(50),Country VARCHAR(50),Personnel INT); INSERT INTO MilitaryBases (ID,BaseName,Country,Personnel) VALUES (1,'Base1','Europe',500); INSERT INTO MilitaryBases (ID,BaseName,Country,Personnel) VALUES (2,'Base2','Europe',700);
SELECT AVG(Personnel) FROM MilitaryBases WHERE Country = 'Europe';
What is the total number of contracts negotiated by each contractor in the defense project timelines table?
CREATE TABLE DefenseProjectTimelines (id INT PRIMARY KEY,contractor VARCHAR(50),project_start_date DATE,project_end_date DATE,project_status VARCHAR(50)); INSERT INTO DefenseProjectTimelines (id,contractor,project_start_date,project_end_date,project_status) VALUES (4,'Thales Group','2019-01-01','2021-12-31','Completed'); INSERT INTO DefenseProjectTimelines (id,contractor,project_start_date,project_end_date,project_status) VALUES (5,'Leonardo S.p.A.','2020-07-01','2023-06-30','In Progress');
SELECT DefenseProjectTimelines.contractor, COUNT(DefenseProjectTimelines.id) FROM DefenseProjectTimelines GROUP BY DefenseProjectTimelines.contractor;
What is the average horsepower of vehicles manufactured in Japan?
CREATE TABLE Vehicles (id INT,make VARCHAR(50),model VARCHAR(50),horsepower INT,country VARCHAR(50)); INSERT INTO Vehicles (id,make,model,horsepower,country) VALUES (1,'Toyota','Corolla',139,'Japan');
SELECT AVG(horsepower) FROM Vehicles WHERE country = 'Japan';
What is the average number of games played per day by users in the 'gaming' database?
CREATE TABLE user_game_activity (user_id INT,game_id INT,played_at TIMESTAMP); INSERT INTO user_game_activity (user_id,game_id,played_at) VALUES (1,1,'2021-01-01 10:00:00'),(2,1,'2021-01-02 11:00:00'),(3,2,'2021-01-03 12:00:00'),(4,2,'2021-01-04 13:00:00'),(5,3,'2021-01-05 14:00:00'),(6,1,'2021-01-06 15:00:00'),(6,2,'2021-01-07 16:00:00'),(6,3,'2021-01-08 17:00:00');
SELECT COUNT(DISTINCT user_id, game_id) as games_played, EXTRACT(DAY FROM played_at) as day FROM user_game_activity GROUP BY day
What is the total quantity of 'Veggie Wrap' sold last week?
CREATE TABLE sandwiches (id INT,name VARCHAR(255),qty_sold INT); INSERT INTO sandwiches (id,name,qty_sold) VALUES (1,'Veggie Wrap',300),(2,'Chicken Salad Sandwich',250),(3,'Turkey Club',200); CREATE TABLE date (id INT,date DATE); INSERT INTO date (id,date) VALUES (1,'2022-03-21'),(2,'2022-03-22'),(3,'2022-03-23');
SELECT SUM(qty_sold) AS total_qty_sold FROM sandwiches WHERE name = 'Veggie Wrap' AND date IN (SELECT date FROM date WHERE date BETWEEN DATE_SUB(NOW(), INTERVAL 1 WEEK) AND NOW());
What is the minimum rating of beauty products that are not tested on animals and were sold in Australia?
CREATE TABLE ratings_animal_testing (id INT,product VARCHAR(255),not_tested_on_animals BOOLEAN,rating FLOAT,country VARCHAR(255)); INSERT INTO ratings_animal_testing (id,product,not_tested_on_animals,rating,country) VALUES (1,'Shampoo',true,4.5,'Australia'),(2,'Conditioner',false,3.0,'Australia'),(3,'Lotion',true,4.0,'Australia');
SELECT MIN(rating) FROM ratings_animal_testing WHERE not_tested_on_animals = true AND country = 'Australia';
Which genetic research experiments resulted in the highest temperature increase?
CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.experiments (id INT,experiment_name VARCHAR(255),temperature_delta INT); INSERT INTO genetics.experiments (id,experiment_name,temperature_delta) VALUES (1,'CRISPR-Cas9',15),(2,'Gene Editing',22),(3,'Genetic Fusion',18);
SELECT experiment_name, temperature_delta FROM (SELECT experiment_name, temperature_delta, RANK() OVER (ORDER BY temperature_delta DESC) AS rank FROM genetics.experiments) ranked_experiments WHERE rank = 1;
What is the latest public outreach date for each site?
CREATE TABLE Sites (SiteID INT,SiteName VARCHAR(50),PublicOutreachDate DATE); INSERT INTO Sites (SiteID,SiteName,PublicOutreachDate) VALUES (1,'Site A','2011-05-01'),(2,'Site B','2009-03-15'),(3,'Site C','2013-07-22');
SELECT SiteName, MAX(PublicOutreachDate) OVER (PARTITION BY SiteID) AS LatestPublicOutreachDate FROM Sites;
What is the total revenue for each product category in 2022?
CREATE TABLE orders (order_id INT,order_date DATE,product_category VARCHAR(50),revenue FLOAT); INSERT INTO orders (order_id,order_date,product_category,revenue) VALUES (1,'2022-01-01','Clothing',25.5),(2,'2022-01-02','Electronics',30),(3,'2022-01-03','Furniture',15);
SELECT product_category, SUM(revenue) FROM orders WHERE EXTRACT(YEAR FROM order_date) = 2022 GROUP BY product_category;
What is the maximum number of shared scooters available in a single day for each company in the shared_scooters table?
CREATE TABLE shared_scooters (company VARCHAR(20),date DATE,num_scooters INT); INSERT INTO shared_scooters (company,date,num_scooters) VALUES ('Company A','2022-01-01',500),('Company A','2022-01-02',550),('Company B','2022-01-01',400),('Company B','2022-01-02',450);
SELECT company, MAX(num_scooters) FROM shared_scooters GROUP BY company;
What is the total workout duration per member from Germany in 2022, grouped by month?
CREATE TABLE members (id INT,country VARCHAR(50)); INSERT INTO members (id,country) VALUES (1,'Germany'); CREATE TABLE workouts (id INT,member_id INT,date DATE,duration INT); INSERT INTO workouts (id,member_id,date,duration) VALUES (1,1,'2022-01-01',30);
SELECT DATE_TRUNC('month', workouts.date) AS month, members.id, SUM(duration) AS total_duration FROM members JOIN workouts ON members.id = workouts.member_id WHERE members.country = 'Germany' AND YEAR(workouts.date) = 2022 GROUP BY month, members.id;
What is the total number of articles published per month in a specific language, grouped by day?
CREATE TABLE Dates (id INT PRIMARY KEY,date DATE); INSERT INTO Dates (id,date) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2022-03-01'); CREATE TABLE Articles (id INT PRIMARY KEY,title TEXT,language_id INT,date_id INT,FOREIGN KEY (language_id) REFERENCES Languages(id),FOREIGN KEY (date_id) REFERENCES Dates(id)); INSERT INTO Articles (id,title,language_id,date_id) VALUES (1,'Article 1',1,1),(2,'Article 2',2,2),(3,'Article 3',1,3);
SELECT l.language, DATE_FORMAT(d.date, '%Y-%m-%d') as date, COUNT(a.id) as num_articles FROM Articles a JOIN Languages l ON a.language_id = l.id JOIN Dates d ON a.date_id = d.id GROUP BY l.language, date;
Insert a new record for a volunteer with ID 4 who served 8 hours.
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,Hours FLOAT); INSERT INTO Volunteers (VolunteerID,Name,Hours) VALUES (1,'Alice',7.0),(2,'Bob',4.0),(3,'Charlie',6.0);
INSERT INTO Volunteers (VolunteerID, Hours) VALUES (4, 8.0);
What is the total number of polar bears in the Arctic Research Station 2 and 3?
CREATE TABLE Arctic_Research_Station_2 (id INT,species TEXT,population INT); CREATE TABLE Arctic_Research_Station_3 (id INT,species TEXT,population INT);
SELECT SUM(population) FROM Arctic_Research_Station_2 WHERE species = 'Polar Bear'; SELECT SUM(population) FROM Arctic_Research_Station_3 WHERE species = 'Polar Bear'; SELECT SUM(population) FROM (SELECT * FROM Arctic_Research_Station_2 WHERE species = 'Polar Bear' UNION ALL SELECT * FROM Arctic_Research_Station_3 WHERE species = 'Polar Bear') AS Polar_Bear_Population;
How many graduate students are enrolled in STEM programs who have published more than 5 papers?
CREATE TABLE GraduateStudents(Id INT,Name VARCHAR(100),Program VARCHAR(50),Publications INT); INSERT INTO GraduateStudents(Id,Name,Program,Publications) VALUES (1,'Charlie','Physics',3),(2,'David','Mathematics',10);
SELECT COUNT(*) FROM GraduateStudents WHERE Program LIKE 'STEM%' HAVING Publications > 5;
What's the maximum investment amount made in the 'renewable energy' sector?
CREATE TABLE sectors (sector_id INT,sector_name VARCHAR(20)); CREATE TABLE investments (investment_id INT,investor_id INT,sector_id INT,investment_amount FLOAT);
SELECT MAX(i.investment_amount) FROM investments i INNER JOIN sectors s ON i.sector_id = s.sector_id WHERE s.sector_name = 'renewable energy';
Show the number of employees for each mine, grouped by the mine's location.
CREATE TABLE mine_workforce (mine_id INT,mine_name TEXT,location TEXT,num_employees INT); INSERT INTO mine_workforce (mine_id,mine_name,location,num_employees) VALUES (1,'Emerald Enterprise','Wyoming,USA',500),(2,'Ruby Republic','Montana,USA',450),(3,'Sapphire Syndicate','Idaho,USA',400),(4,'Garnet Group','Utah,USA',350),(5,'Topaz Trust','Nevada,USA',300),(6,'Amethyst Association','Colorado,USA',250),(7,'Diamond Depot','Alberta,Canada',200),(8,'Onyx Operation','Ontario,Canada',150),(9,'Turquoise Territory','British Columbia,Canada',100);
SELECT location, SUM(num_employees) as total_employees FROM mine_workforce GROUP BY location;
What is the total installed capacity (in MW) for all wind projects in the 'renewable_projects' table?
CREATE TABLE renewable_projects (project_id INT,project_name VARCHAR(100),project_type VARCHAR(50),installed_capacity FLOAT); INSERT INTO renewable_projects (project_id,project_name,project_type,installed_capacity) VALUES (1,'Wind Farm A','Wind',50.0),(2,'Solar Farm B','Solar',75.0);
SELECT SUM(installed_capacity) FROM renewable_projects WHERE project_type = 'Wind';
What is the total number of models in each type?
CREATE TABLE ai_model (id INT,name VARCHAR,type VARCHAR,domain VARCHAR,accuracy FLOAT); INSERT INTO ai_model (id,name,type,domain,accuracy) VALUES (7,'ModelG','Reinforcement','Fairness',0.91); INSERT INTO ai_model (id,name,type,domain,accuracy) VALUES (8,'ModelH','Semi-supervised','Safety',0.98);
SELECT type, COUNT(*) as total FROM ai_model GROUP BY type;
What are the names of vessels that have not visited any ports in the European region?
CREATE TABLE vessels_port_visits (vessel_id INT,port_id INT,visit_date DATE); INSERT INTO vessels_port_visits VALUES (1,1,'2022-01-01'),(1,2,'2022-01-02'),(2,3,'2022-01-03'); CREATE TABLE ports_region (port_id INT,region TEXT); INSERT INTO ports_region VALUES (1,'Asia Pacific'),(2,'Americas'),(3,'Europe');
SELECT vessels.vessel_name FROM vessels WHERE vessels.vessel_id NOT IN (SELECT vessels_port_visits.vessel_id FROM vessels_port_visits INNER JOIN ports_region ON vessels_port_visits.port_id = ports_region.port_id WHERE ports_region.region = 'Europe');
What is the total quantity of gold extracted per country?
CREATE TABLE mine_sites (id INT,country VARCHAR(255),mineral VARCHAR(255),quantity INT); INSERT INTO mine_sites (id,country,mineral,quantity) VALUES (1,'Canada','Gold',500),(2,'Mexico','Gold',700),(3,'Australia','Gold',1200);
SELECT country, SUM(quantity) as total_gold_extracted FROM mine_sites WHERE mineral = 'Gold' GROUP BY country;
What is the genetic sequence of samples with startup funding over 500000?
CREATE TABLE genetic_data (id INT,sample_id VARCHAR(20),gene_sequence TEXT); CREATE TABLE startup_funding (id INT,sample_id VARCHAR(20),funding_amount FLOAT); INSERT INTO genetic_data (id,sample_id,gene_sequence) VALUES (1,'GD001','ATGCGA...'),(2,'GD002','ATGCGC...'); INSERT INTO startup_funding (id,sample_id,funding_amount) VALUES (1,'GD001',700000.0),(2,'GD002',300000.0);
SELECT gd.gene_sequence FROM genetic_data gd INNER JOIN startup_funding sf ON gd.sample_id = sf.sample_id WHERE sf.funding_amount > 500000;
What is the average co-ownership price for sustainable urbanism properties in CityA?
CREATE TABLE city (id INT,name VARCHAR(255)); INSERT INTO city (id,name) VALUES (1,'CityA'),(2,'CityB'); CREATE TABLE property (id INT,co_ownership_price DECIMAL(10,2),city_id INT,category VARCHAR(255)); INSERT INTO property (id,co_ownership_price,city_id,category) VALUES (1,500000,1,'sustainable urbanism'),(2,600000,1,'sustainable urbanism'),(3,450000,2,'inclusive housing');
SELECT AVG(p.co_ownership_price) AS avg_price FROM property p WHERE p.city_id = 1 AND p.category = 'sustainable urbanism';
List the train types with wheelchair accessibility.
CREATE TABLE Trains (id INT,type VARCHAR(255),wheelchair_accessible BOOLEAN);
SELECT type FROM Trains WHERE wheelchair_accessible = TRUE;
What is the total inventory value for each ingredient?
CREATE TABLE inventory (ingredient VARCHAR(255),quantity INT,unit_price DECIMAL(10,2)); INSERT INTO inventory VALUES ('Garlic',500,0.5); INSERT INTO inventory VALUES ('Tomatoes',2000,1.0);
SELECT ingredient, SUM(quantity * unit_price) AS total_inventory_value FROM inventory GROUP BY ingredient;
Which drugs were approved between Q2 2015 and Q1 2016?
CREATE TABLE approvals (drug_name TEXT,approval_date DATE); INSERT INTO approvals (drug_name,approval_date) VALUES ('DrugI','2015-07-01'); INSERT INTO approvals (drug_name,approval_date) VALUES ('DrugJ','2016-03-30');
SELECT drug_name FROM approvals WHERE EXTRACT(QUARTER FROM approval_date) BETWEEN 2 AND 1 AND EXTRACT(YEAR FROM approval_date) BETWEEN 2015 AND 2016;
What is the most common word in the titles of articles published by "The New Yorker" in 2021?
CREATE TABLE articles (id INT,title TEXT,content TEXT,publication_date DATE,newspaper TEXT); CREATE TABLE words (id INT,article_id INT,word TEXT);
SELECT word, COUNT(*) AS word_count FROM words w INNER JOIN articles a ON w.article_id = a.id WHERE a.newspaper = 'The New Yorker' AND a.publication_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY word ORDER BY word_count DESC LIMIT 1;
Identify which offenses have no restorative practices associated with them in the 'offenses_by_practice' table?
CREATE TABLE offenses_by_practice (practice_id INT,offense_id INT); CREATE TABLE offenses (offense_id INT,offense VARCHAR(255));
SELECT offense FROM offenses WHERE offense_id NOT IN (SELECT offense_id FROM offenses_by_practice);
What is the total number of users by gender?
CREATE TABLE users (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,city VARCHAR(50)); INSERT INTO users (id,name,gender,age,city) VALUES (1,'David','Male',20,'New York'); INSERT INTO users (id,name,gender,age,city) VALUES (2,'Eva','Female',25,'Los Angeles'); INSERT INTO users (id,name,gender,age,city) VALUES (3,'Fiona','Female',30,'Chicago'); INSERT INTO users (id,name,gender,age,city) VALUES (4,'George','Male',35,'New York');
SELECT gender, COUNT(*) as total_users FROM users GROUP BY gender;
What's the average gas price for smart contracts?
CREATE TABLE smart_contracts (id INT,gas_price DECIMAL(10,2)); INSERT INTO smart_contracts (id,gas_price) VALUES (1,20.5),(2,25.0),(3,18.7),(4,30.2),(5,22.9);
SELECT AVG(gas_price) FROM smart_contracts;
What is the total number of volunteers and total hours donated by them in '2018'?
CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(50),HoursDonated int,VolunteerYear int); INSERT INTO Volunteers (VolunteerID,VolunteerName,HoursDonated,VolunteerYear) VALUES (1,'Samantha Green',30,2018),(2,'Taylor White',20,2018),(3,'Uma Black',15,2018),(4,'Victor Red',25,2018);
SELECT COUNT(VolunteerName) as TotalVolunteers, SUM(HoursDonated) as TotalHours FROM Volunteers WHERE VolunteerYear = 2018;
Find the number of exoplanet discoveries made by the K2 and PLATO missions.
CREATE TABLE exoplanets (id INT,name VARCHAR(255),discovery_mission VARCHAR(255),discovery_date DATE); INSERT INTO exoplanets (id,name,discovery_mission,discovery_date) VALUES (1,'K2-18b','K2','2015-05-01'); INSERT INTO exoplanets (id,name,discovery_mission,discovery_date) VALUES (2,'PLATO-1b','PLATO','2025-06-08'); CREATE VIEW k2_exoplanets AS SELECT * FROM exoplanets WHERE discovery_mission = 'K2'; CREATE VIEW plato_exoplanets AS SELECT * FROM exoplanets WHERE discovery_mission = 'PLATO';
SELECT COUNT(*) as num_discoveries FROM exoplanets e INNER JOIN k2_exoplanets k ON e.id = k.id INNER JOIN plato_exoplanets p ON e.id = p.id;
What is the average lead time for each garment manufacturer?
CREATE TABLE manufacturing (manufacturing_id INT,manufacturer VARCHAR(50),lead_time INT);
SELECT manufacturer, AVG(lead_time) as avg_lead_time FROM manufacturing GROUP BY manufacturer;
What is the total funding received by startups founded by women in the Healthcare sector?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,total_funding FLOAT); INSERT INTO startups VALUES(1,'StartupA','Healthcare',15000000); INSERT INTO startups VALUES(2,'StartupB','Tech',20000000); INSERT INTO startups VALUES(3,'StartupC','Healthcare',12000000); INSERT INTO startups VALUES(4,'StartupD','Finance',30000000); INSERT INTO startups VALUES(5,'StartupE','Healthcare',8000000);
SELECT SUM(total_funding) FROM startups WHERE industry = 'Healthcare' AND founder = 'Woman';
Delete 'Tofu Scramble' from the breakfast menu.
CREATE TABLE menu (id INT,category VARCHAR(255),item VARCHAR(255)); INSERT INTO menu (id,category,item) VALUES (1,'breakfast','Pancakes'),(2,'breakfast','Tofu Scramble'),(3,'lunch','Quinoa Salad');
DELETE FROM menu WHERE category = 'breakfast' AND item = 'Tofu Scramble';
Show drought duration by region
CREATE TABLE drought_impact (id INT PRIMARY KEY,region VARCHAR(50),drought_duration INT);
SELECT region, drought_duration FROM drought_impact;
Find all records where the budget allocated for a public service is greater than 6000000
CREATE TABLE Public_Services(service_id INT PRIMARY KEY,service_name VARCHAR(255),location VARCHAR(255),budget FLOAT,created_date DATE); INSERT INTO Public_Services (service_id,service_name,location,budget,created_date) VALUES (1,'Road Maintenance','NYC',5000000.00,'2022-01-01'),(2,'Waste Management','NYC',7000000.00,'2022-01-02'),(3,'Street Lighting','San Francisco',3000000.00,'2022-01-03');
SELECT * FROM Public_Services WHERE budget > 6000000;
Delete an investment from the Investments table.
CREATE TABLE Investments (id INT,company_id INT,investment_amount INT,investment_date DATE); INSERT INTO Investments (id,company_id,investment_amount,investment_date) VALUES (1,1,1000000,'2022-01-01'); INSERT INTO Investments (id,company_id,investment_amount,investment_date) VALUES (2,2,2000000,'2022-02-01');
DELETE FROM Investments WHERE id = 1;
Update the annual income of the farmer with id 1 in the "farmers" table
CREATE TABLE farmers (id SERIAL PRIMARY KEY,name TEXT,region TEXT,annual_income INT); INSERT INTO farmers (name,region,annual_income) VALUES ('John','North America',40000),('Jane','Asia',50000),('Bob','Europe',60000);
UPDATE farmers SET annual_income = 45000 WHERE id = 1;
What is the total budget allocated for education and healthcare services in the state of 'California'?
CREATE TABLE budget (state VARCHAR(20),service VARCHAR(20),amount INT); INSERT INTO budget (state,service,amount) VALUES ('California','Education',50000),('California','Healthcare',70000);
SELECT SUM(amount) FROM budget WHERE state = 'California' AND service IN ('Education', 'Healthcare');
What is the minimum salary of employees in factories with a production output above a certain threshold?
CREATE TABLE factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),production_output INT); CREATE TABLE employees (employee_id INT,factory_id INT,name VARCHAR(100),position VARCHAR(100),salary INT); INSERT INTO factories (factory_id,name,location,production_output) VALUES (1,'ABC Factory','New York',5500),(2,'XYZ Factory','Los Angeles',4000),(3,'LMN Factory','Houston',6000),(4,'PQR Factory','Toronto',7000); INSERT INTO employees (employee_id,factory_id,name,position,salary) VALUES (1,1,'John Doe','Engineer',70000),(2,1,'Jane Smith','Manager',80000),(3,2,'Mike Johnson','Operator',60000),(4,3,'Sara Brown','Engineer',75000),(5,3,'David Williams','Manager',85000),(6,4,'Emily Davis','Engineer',90000);
SELECT MIN(employees.salary) FROM factories INNER JOIN employees ON factories.factory_id = employees.factory_id WHERE factories.production_output > 5000;
What is the minimum funding received by a startup founded by a person with a disability in the finance sector?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,founder_ability TEXT,funding FLOAT); INSERT INTO startups (id,name,industry,founder_ability,funding) VALUES (1,'FinanceAbility','Finance','Disabled',2000000);
SELECT MIN(funding) FROM startups WHERE industry = 'Finance' AND founder_ability = 'Disabled';
What is the maximum number of bikes rented in 'park1' and 'park2' on weekends?
CREATE TABLE bike_rentals (location VARCHAR(20),day_of_week VARCHAR(10),bikes_rented INT); INSERT INTO bike_rentals (location,day_of_week,bikes_rented) VALUES ('park1','Saturday',15),('park1','Sunday',20),('park2','Friday',10),('park2','Saturday',12),('park2','Sunday',18);
SELECT MAX(bikes_rented) FROM bike_rentals WHERE location IN ('park1', 'park2') AND day_of_week IN ('Saturday', 'Sunday');
Delete records of community meetings that took place in 'Downtown' district
CREATE TABLE community_policing (cp_id INT,did INT,meetings_this_year INT); INSERT INTO community_policing (cp_id,did,meetings_this_year) VALUES (1,1,5),(2,2,3),(3,3,7);
DELETE FROM community_policing WHERE did = 1;
What is the average carbon footprint of products manufactured in each country?
CREATE TABLE countries (id INT,name TEXT); CREATE TABLE manufacturers (id INT,name TEXT,country_id INT,carbon_footprint INT); INSERT INTO countries (id,name) VALUES (1,'Country 1'),(2,'Country 2'),(3,'Country 3'); INSERT INTO manufacturers (id,name,country_id,carbon_footprint) VALUES (1,'Manufacturer 1',1,50),(2,'Manufacturer 2',2,70),(3,'Manufacturer 3',3,30),(4,'Manufacturer 4',1,60),(5,'Manufacturer 5',2,40);
SELECT countries.name, AVG(manufacturers.carbon_footprint) FROM countries INNER JOIN manufacturers ON countries.id = manufacturers.country_id GROUP BY countries.name;
Calculate the revenue of organic skincare products sold in the West region
CREATE TABLE sales (product_type VARCHAR(20),region VARCHAR(10),revenue NUMERIC(10,2)); INSERT INTO sales (product_type,region,revenue) VALUES ('cleanser','West',700),('toner','East',800),('serum','West',900),('moisturizer','North',600),('sunscreen','South',500),('cleanser','South',400),('toner','North',300); CREATE TABLE products (product_type VARCHAR(20),organic BOOLEAN); INSERT INTO products (product_type,organic) VALUES ('cleanser',TRUE),('toner',FALSE),('serum',TRUE),('moisturizer',FALSE),('sunscreen',TRUE);
SELECT SUM(revenue) FROM sales INNER JOIN products ON sales.product_type = products.product_type WHERE products.organic = TRUE AND sales.region = 'West' AND sales.product_type = 'skincare';
Which members have a resting heart rate below 60?
CREATE TABLE member_hr (member_id INT,resting_heart_rate INT); INSERT INTO member_hr (member_id,resting_heart_rate) VALUES (1,75),(2,58),(3,65),(4,59),(5,72);
SELECT member_id FROM member_hr WHERE resting_heart_rate < 60;