instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the change in CO2 emissions per manufacturing process between 2021 and 2022? | CREATE TABLE process (process_id INT,process_name VARCHAR(50),year INT); CREATE TABLE co2 (co2_id INT,process_id INT,co2_amount DECIMAL(5,2)); INSERT INTO process (process_id,process_name,year) VALUES (1,'Process 1',2021),(2,'Process 2',2021),(3,'Process 1',2022),(4,'Process 2',2022); INSERT INTO co2 (co2_id,process_id,co2_amount) VALUES (1,1,100),(2,1,105),(3,2,75),(4,2,78),(5,3,110),(6,3,115),(7,4,80),(8,4,83); | SELECT a.process_name, (b.co2_amount - a.co2_amount) AS co2_change FROM (SELECT process_name, co2_amount, year FROM process JOIN co2 ON process.process_id = co2.process_id WHERE year = 2021) AS a JOIN (SELECT process_name, co2_amount, year FROM process JOIN co2 ON process.process_id = co2.process_id WHERE year = 2022) AS b ON a.process_name = b.process_name; |
Show the average policy duration and number of claims, by policy type, for policyholders in Florida. | CREATE TABLE Claim (ClaimId INT,PolicyId INT,ClaimDate DATE); CREATE TABLE Policy (PolicyId INT,PolicyType VARCHAR(50),IssueDate DATE,ExpirationDate DATE,Region VARCHAR(50)); | SELECT Policy.PolicyType, AVG(DATEDIFF(day, IssueDate, ExpirationDate)) as AveragePolicyDuration, COUNT(Claim.ClaimId) as NumberOfClaims FROM Policy LEFT JOIN Claim ON Policy.PolicyId = Claim.PolicyId WHERE Policy.Region = 'Florida' GROUP BY Policy.PolicyType; |
Display the names of all countries that have held AI safety conferences and the number of such conferences. | CREATE TABLE countries (id INT,name TEXT); INSERT INTO countries (id,name) VALUES (1,'USA'),(2,'Canada'),(3,'UK'),(4,'Australia'); CREATE TABLE conferences (id INT,country_id INT,name TEXT,topic TEXT); INSERT INTO conferences (id,country_id,name,topic) VALUES (1,1,'Conf1','AI Safety'),(2,1,'Conf2','AI Safety'),(3,3,'Conf3','AI Safety'),(4,4,'Conf4','AI Safety'); | SELECT countries.name, COUNT(conferences.id) as conferences_count FROM countries INNER JOIN conferences ON countries.id = conferences.country_id WHERE conferences.topic = 'AI Safety' GROUP BY countries.name; |
What is the difference in total donations between the animal welfare and global health sectors? | CREATE TABLE total_donations (sector VARCHAR(50),total_donations DECIMAL(10,2)); INSERT INTO total_donations (sector,total_donations) VALUES ('Animal Welfare',25000.00),('Global Health',40000.00),('Education',30000.00),('Environment',35000.00),('Human Rights',45000.00); | SELECT (a.total_donations - b.total_donations) AS difference FROM total_donations a, total_donations b WHERE a.sector = 'Global Health' AND b.sector = 'Animal Welfare'; |
What is the average ESG score of companies in the technology sector? | CREATE TABLE companies (id INT,sector VARCHAR(255),ESG_score FLOAT); INSERT INTO companies (id,sector,ESG_score) VALUES (1,'technology',72.5); | SELECT AVG(ESG_score) FROM companies WHERE sector = 'technology'; |
Find the number of eco-certified accommodations in each country | CREATE TABLE accommodations (id INT,country VARCHAR(50),is_eco_certified BOOLEAN); INSERT INTO accommodations (id,country,is_eco_certified) VALUES (1,'France',TRUE),(2,'Italy',FALSE),(3,'Japan',TRUE),(4,'Germany',TRUE),(5,'Spain',TRUE),(6,'Canada',FALSE); | SELECT country, COUNT(*) FROM accommodations WHERE is_eco_certified = TRUE GROUP BY country; |
How many flight accidents has each airline had in the last 10 years? | CREATE TABLE flight_safety (accident_id INT,airline TEXT,accident_date DATE); INSERT INTO flight_safety (accident_id,airline,accident_date) VALUES (1,'Delta Airlines','2019-01-05'),(2,'Delta Airlines','2015-07-31'),(3,'American Airlines','2018-04-17'),(4,'American Airlines','2013-07-06'),(5,'Lufthansa','2017-03-28'); | SELECT airline, COUNT(*) as accident_count FROM flight_safety WHERE accident_date >= DATEADD(year, -10, GETDATE()) GROUP BY airline; |
What is the minimum amount of humanitarian assistance provided by the UN in a single year for the Middle East? | CREATE SCHEMA humanitarian_assistance;CREATE TABLE un_assistance (assistance_amount INT,year INT,region VARCHAR(50));INSERT INTO un_assistance (assistance_amount,year,region) VALUES (500000,2015,'Middle East'),(700000,2016,'Middle East'),(900000,2017,'Middle East'),(600000,2018,'Middle East'),(800000,2019,'Middle East'),(1000000,2020,'Middle East'); | SELECT MIN(assistance_amount) FROM humanitarian_assistance.un_assistance WHERE region = 'Middle East'; |
What is the total funding raised by biotech startups in the US? | CREATE SCHEMA if not exists biotech;CREATE TABLE biotech.startups (id INT,name VARCHAR(50),country VARCHAR(50),total_funding DECIMAL(10,2));INSERT INTO biotech.startups (id,name,country,total_funding) VALUES (1,'StartupA','USA',15000000.00),(2,'StartupB','USA',22000000.00),(3,'StartupC','Canada',11000000.00); | SELECT SUM(total_funding) FROM biotech.startups WHERE country = 'USA'; |
What is the percentage of tourists who visited South American world heritage sites located in urban areas? | CREATE TABLE world_heritage_sites (country VARCHAR(20),site VARCHAR(50),location VARCHAR(20),visitors INT); INSERT INTO world_heritage_sites (country,site,location,visitors) VALUES ('Brazil','Rio de Janeiro','urban',2000000),('Peru','Machu Picchu','rural',1500000),('Brazil','Rio de Janeiro','urban',2200000); | SELECT country, (SUM(CASE WHEN location = 'urban' THEN visitors ELSE 0 END) * 100.0 / SUM(visitors)) as urban_percentage FROM world_heritage_sites GROUP BY country; |
What is the number of families who received humanitarian aid in South America, grouped by disaster type, ordered by the number of families? | CREATE TABLE aid_distribution_s_america (family_id INT,region VARCHAR(20),disaster_type VARCHAR(20)); INSERT INTO aid_distribution_s_america (family_id,region,disaster_type) VALUES (1,'South America','Flood'),(2,'South America','Earthquake'),(3,'South America','Flood'),(4,'South America','Tsunami'),(5,'South America','Tornado'); CREATE TABLE disaster_type (disaster_type VARCHAR(20) PRIMARY KEY); INSERT INTO disaster_type (disaster_type) VALUES ('Flood'),('Earthquake'),('Tsunami'),('Tornado'); | SELECT disaster_type, COUNT(family_id) as num_families FROM aid_distribution_s_america JOIN disaster_type ON aid_distribution_s_america.disaster_type = disaster_type.disaster_type GROUP BY disaster_type ORDER BY num_families; |
Count the number of mining sites in Russia and Peru with more than 20 machines each. | CREATE TABLE machines (id INT PRIMARY KEY,mine_site_id INT,machine_name VARCHAR(255)); CREATE TABLE mine_sites (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),type VARCHAR(255)); | SELECT COUNT(DISTINCT ms.id) as num_sites FROM mine_sites ms JOIN machines m ON ms.id = m.mine_site_id WHERE ms.location IN ('Russia', 'Peru') GROUP BY ms.location HAVING COUNT(m.id) > 20; |
What were the total sales of each drug in the Southeast region in Q2 2021? | CREATE TABLE drugs (drug_id INT,drug_name VARCHAR(255)); INSERT INTO drugs (drug_id,drug_name) VALUES (1,'DrugA'),(2,'DrugB'); CREATE TABLE sales (sale_id INT,drug_id INT,region VARCHAR(255),sales_amount DECIMAL(10,2),quarter INT,year INT); INSERT INTO sales (sale_id,drug_id,region,sales_amount,quarter,year) VALUES (1,1,'Southeast',15000,2,2021),(2,2,'Southeast',20000,2,2021); | SELECT d.drug_name, SUM(s.sales_amount) as total_sales FROM drugs d JOIN sales s ON d.drug_id = s.drug_id WHERE s.region = 'Southeast' AND s.quarter = 2 AND s.year = 2021 GROUP BY d.drug_name; |
Insert new records for 2 chemical compounds, 'Styrene', 'Ethylene Glycol', with safety_ratings 6, 7 respectively, and manufacturing_location 'USA' for both | CREATE TABLE chemical_compounds (id INT PRIMARY KEY,name VARCHAR(255),safety_rating INT,manufacturing_location VARCHAR(255)); | INSERT INTO chemical_compounds (name, safety_rating, manufacturing_location) VALUES ('Styrene', 6, 'USA'), ('Ethylene Glycol', 7, 'USA'); |
What is the success rate of the DBT treatment approach for patients with borderline personality disorder? | CREATE TABLE PatientTreatmentOutcomes (PatientID INT,Condition VARCHAR(50),Treatment VARCHAR(50),Success BOOLEAN); | SELECT 100.0 * SUM(Success) / COUNT(*) AS SuccessRate FROM PatientTreatmentOutcomes WHERE Condition = 'borderline personality disorder' AND Treatment = 'DBT'; |
What is the total amount of socially responsible loans issued by AltruisticBank in Q1 2021? | CREATE TABLE AltruisticBank (id INT,loan_type VARCHAR(20),loan_amount INT,issue_date DATE); INSERT INTO AltruisticBank (id,loan_type,loan_amount,issue_date) VALUES (1,'Socially Responsible',7000,'2021-01-05'); | SELECT SUM(loan_amount) FROM AltruisticBank WHERE loan_type = 'Socially Responsible' AND QUARTER(issue_date) = 1 AND YEAR(issue_date) = 2021; |
What is the total production output of the plant located in 'CityA'? | CREATE TABLE plants (plant_id INT,plant_name VARCHAR(50),city VARCHAR(50),production_output INT); INSERT INTO plants (plant_id,plant_name,city,production_output) VALUES (1,'PlantA','CityA',500),(2,'PlantB','CityB',700),(3,'PlantC','CityC',600); | SELECT SUM(production_output) FROM plants WHERE city = 'CityA'; |
What is the ratio of co-owned properties to total properties in each city? | CREATE TABLE cities (id INT,name VARCHAR(255)); INSERT INTO cities (id,name) VALUES (1,'Barcelona'),(2,'Berlin'),(3,'Vienna'); CREATE TABLE properties (id INT,city_id INT,size INT,coowners INT); INSERT INTO properties (id,city_id,size,coowners) VALUES (1,1,800,2),(2,1,1200,1),(3,2,1000,3),(4,2,1500,1),(5,3,700,1),(6,3,1100,2),(7,3,1300,2); | SELECT city_id, AVG(CASE WHEN coowners > 1 THEN 1.0 ELSE 0.0 END) / COUNT(*) as coowners_ratio FROM properties GROUP BY city_id; |
Delete records for properties with inclusive housing policies that do not have 'affordable' in the policy_text. | CREATE TABLE UrbanPolicies (id INT,policy_id INT,city VARCHAR(50),state VARCHAR(2),policy_text TEXT); CREATE VIEW InclusivePolicies AS SELECT policy_id,city,state FROM UrbanPolicies WHERE policy_text LIKE '%inclusive%' AND policy_text LIKE '%affordable%'; | DELETE FROM InclusivePolicies WHERE policy_id NOT IN (SELECT policy_id FROM UrbanPolicies WHERE policy_text LIKE '%affordable%'); |
How many labor rights violations were reported in 'California' and 'New York'? | CREATE TABLE violations (id INT,location TEXT,type TEXT,date DATE); INSERT INTO violations (id,location,type,date) VALUES (1,'California','wage theft','2021-01-01'),(2,'New York','unsafe working conditions','2021-02-01'); | SELECT COUNT(*) FROM violations WHERE location IN ('California', 'New York'); |
What is the maximum number of publications for graduate students in the Physics program? | CREATE TABLE students (id INT,name VARCHAR(50),gender VARCHAR(10),program VARCHAR(50),publications INT); INSERT INTO students (id,name,gender,program,publications) VALUES (1,'Charlie','Non-binary','Arts',2),(2,'Dana','Female','Physics',5),(3,'Eli','Male','Engineering',0),(4,'Fatima','Female','Physics',3); | SELECT MAX(s.publications) FROM students s WHERE s.program = 'Physics'; |
What is the average fare for ferries in the 'Oceanview' region? | CREATE TABLE Ferries (ferry_id INT,region VARCHAR(20),fare DECIMAL(5,2)); INSERT INTO Ferries (ferry_id,region,fare) VALUES (701,'Oceanview',6.00),(702,'Oceanview',7.00),(703,'Oceanview',8.00); | SELECT AVG(fare) FROM Ferries WHERE region = 'Oceanview'; |
Who are the developers who have contributed to the Ethereum codebase? | CREATE TABLE developers (developer_id INT,name VARCHAR(100),contributions INT); INSERT INTO developers (developer_id,name,contributions) VALUES (1,'Developer1',500),(2,'Developer2',350),(3,'Developer3',250),(4,'Developer4',175),(5,'Developer5',100); | SELECT name FROM developers ORDER BY contributions DESC; |
What are the top 3 countries with the most virtual tours? | CREATE TABLE Countries (CountryName TEXT);CREATE TABLE VirtualTours (CountryName TEXT,TourID INTEGER); INSERT INTO Countries ('CountryName') VALUES ('Italy'),('France'),('Spain'),('Japan'),('Brazil'); INSERT INTO VirtualTours (CountryName,TourID) VALUES ('Italy',1001),('Italy',1002),('France',2001),('France',2002),('Spain',3001),('Japan',4001),('Brazil',5001); | SELECT CountryName, COUNT(TourID) as NumTours FROM VirtualTours GROUP BY CountryName ORDER BY NumTours DESC LIMIT 3; |
How many artworks have been created by artists from each country, grouped by country? | CREATE TABLE artists (id INT,name VARCHAR(255),country VARCHAR(255),year_of_birth INT); CREATE TABLE artworks (id INT,artist_id INT,title VARCHAR(255),year_of_creation INT); | SELECT country, COUNT(*) FROM artists a JOIN artworks aw ON a.id = aw.artist_id GROUP BY country; |
Find total donation amount and number of donors from 'young' donors in 2021. | CREATE TABLE donors (id INT,name VARCHAR,age INT,donation_amount DECIMAL,donation_date DATE); | SELECT SUM(donation_amount) as total_donation_amount, COUNT(DISTINCT donors.id) as num_donors FROM donors |
What is the total number of aquaculture facilities in Asia? | CREATE TABLE aquaculture_facilities (id INT,facility_name VARCHAR(50),location VARCHAR(50),facility_type VARCHAR(50)); INSERT INTO aquaculture_facilities (id,facility_name,location,facility_type) VALUES (1,'Facility A','Asia','Fish Farm'),(2,'Facility B','Europe','Hatchery'),(3,'Facility C','Asia','Hatchery'); | SELECT COUNT(*) FROM aquaculture_facilities WHERE location = 'Asia'; |
Calculate the total revenue for each producer in the South, considering their quantity, price, and the corresponding dispensary's sales, grouped by product type. | CREATE TABLE producers (id INT PRIMARY KEY,name TEXT,region TEXT,product TEXT,quantity INT,price FLOAT); INSERT INTO producers (id,name,region,product,quantity,price) VALUES (1,'South Growers','South','Cannabis Oil',800,20),(2,'Southern Harvest','South','Cannabis Capsules',500,25); CREATE TABLE dispensaries (id INT PRIMARY KEY,name TEXT,region TEXT,sales INT); INSERT INTO dispensaries (id,name,region,sales) VALUES (1,'South Dispensary','South',3000); | SELECT producers.product, dispensaries.name, SUM(producers.quantity * dispensaries.sales * producers.price) as total_revenue FROM producers INNER JOIN dispensaries ON producers.region = dispensaries.region GROUP BY producers.product, dispensaries.name; |
What is the total budget for each community engagement event at the specified heritage site? | CREATE TABLE CommunityEngagements (id INT,event VARCHAR(255),budget DECIMAL(10,2),heritage_site VARCHAR(255)); INSERT INTO CommunityEngagements (id,event,budget,heritage_site) VALUES (1,'Music Festival',15000,'Petra'),(2,'Art Exhibition',12000,'Petra'),(3,'Dance Competition',8000,'Petra'); | SELECT event, SUM(budget) as total_budget FROM CommunityEngagements WHERE heritage_site = 'Petra' GROUP BY event; |
Which organizations provided medical supplies in 'Asia' in 2019? | CREATE TABLE organizations (id INT,name VARCHAR(255)); INSERT INTO organizations (id,name) VALUES (1,'WHO'),(2,'MSF'),(3,'IFRC'); CREATE TABLE medical_supplies (id INT,organization_id INT,medical_supply VARCHAR(255),quantity INT,distribution_date DATE,location VARCHAR(255)); INSERT INTO medical_supplies (id,organization_id,medical_supply,quantity,distribution_date,location) VALUES (1,1,'Vaccines',500,'2019-01-01','Asia'),(2,1,'Medical Equipment',300,'2019-02-01','Africa'),(3,2,'Vaccines',700,'2019-03-01','Asia'),(4,2,'Medical Equipment',400,'2019-04-01','Europe'),(5,3,'Vaccines',600,'2019-05-01','Asia'); | SELECT DISTINCT organization_id FROM medical_supplies WHERE YEAR(distribution_date) = 2019 AND location = 'Asia'; |
Count the number of threat intelligence metrics reported in the Middle East in the last year. | CREATE TABLE threat_intelligence (metric_id INT,metric_date DATE,region VARCHAR(255)); INSERT INTO threat_intelligence (metric_id,metric_date,region) VALUES (1,'2022-01-01','Middle East'),(2,'2021-06-15','Europe'),(3,'2022-02-14','Middle East'); | SELECT COUNT(*) FROM threat_intelligence WHERE region = 'Middle East' AND metric_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
List the policy numbers, policyholder names, and car makes for policyholders who have a policy effective date on or after '2022-01-01' | CREATE TABLE policyholders (policy_number INT,policyholder_name VARCHAR(50),car_make VARCHAR(20),policy_effective_date DATE); | SELECT policy_number, policyholder_name, car_make FROM policyholders WHERE policy_effective_date >= '2022-01-01'; |
Find the total number of unique users who have streamed any hip-hop or R&B songs, without listing users more than once. | CREATE TABLE user_streams (user_id INT,song_id INT); CREATE TABLE songs (song_id INT,genre VARCHAR(10)); | SELECT COUNT(DISTINCT user_id) FROM user_streams JOIN songs ON user_streams.song_id = songs.song_id WHERE genre IN ('hip-hop', 'R&B'); |
Insert new record into 'manufacturing_process' table for 'leather_tanning' with 'emission_rating' of 60 | CREATE TABLE manufacturing_process (id INT PRIMARY KEY,process VARCHAR(50),emission_rating INT); INSERT INTO manufacturing_process (id,process,emission_rating) VALUES (1,'Dyeing',50),(2,'Cutting',40); | INSERT INTO manufacturing_process (process, emission_rating) VALUES ('leather_tanning', 60); |
What is the total revenue of 'Hotel Ritz' from all sources? | CREATE TABLE revenue (hotel_id INT,revenue_source VARCHAR(50),revenue INT); INSERT INTO revenue (hotel_id,revenue_source,revenue) VALUES (1,'Room revenue',10000),(1,'Food and beverage',5000),(1,'Other revenue',2000); | SELECT SUM(revenue) FROM revenue WHERE hotel_id = (SELECT hotel_id FROM hotels WHERE name = 'Hotel Ritz'); |
What is the total number of defense projects with Boeing and Raytheon combined? | CREATE TABLE boeing_defense_projects (project_id INT,project_name VARCHAR(50),country VARCHAR(50)); CREATE TABLE raytheon_defense_projects (project_id INT,project_name VARCHAR(50),country VARCHAR(50)); | SELECT COUNT(*) FROM (SELECT * FROM boeing_defense_projects UNION ALL SELECT * FROM raytheon_defense_projects) AS combined_projects; |
Insert a new agricultural innovation project with an ID of 6, a budget of 100000, and a project_category of 'Precision Agriculture' in district 13. | CREATE TABLE agri_projects (project_id INT,district_id INT,budget FLOAT,project_category VARCHAR(50)); | INSERT INTO agri_projects (project_id, district_id, budget, project_category) VALUES (6, 13, 100000, 'Precision Agriculture'); |
What is the total fish weight for each species per year? | CREATE TABLE Species_Year (Species_Name TEXT,Year INT,Fish_Weight FLOAT); INSERT INTO Species_Year (Species_Name,Year,Fish_Weight) VALUES ('Salmon',2019,400000),('Trout',2019,300000),('Shrimp',2019,600000),('Salmon',2020,500000),('Trout',2020,350000),('Shrimp',2020,700000); | SELECT Species_Name, Year, SUM(Fish_Weight) OVER (PARTITION BY Species_Name) AS Total_Fish_Weight FROM Species_Year; |
What is the total quantity of products manufactured by each factory, grouped by region and month? | CREATE TABLE factories (factory_id INT,factory_name TEXT,region TEXT); INSERT INTO factories (factory_id,factory_name,region) VALUES (1,'Factory A','North'),(2,'Factory B','South'),(3,'Factory C','East'); CREATE TABLE products (product_id INT,factory_id INT,production_month DATE,quantity INT); INSERT INTO products (product_id,factory_id,production_month,quantity) VALUES (1,1,'2022-01-01',500),(2,1,'2022-02-01',600),(3,2,'2022-01-01',700),(4,2,'2022-02-01',800),(5,3,'2022-01-01',900),(6,3,'2022-02-01',1000); | SELECT region, EXTRACT(MONTH FROM production_month) AS month, SUM(quantity) AS total_quantity FROM factories JOIN products ON factories.factory_id = products.factory_id GROUP BY region, EXTRACT(MONTH FROM production_month); |
What is the most expensive menu item in the Asian cuisine category? | CREATE TABLE menu (menu_id INT,menu_name TEXT,menu_type TEXT,price DECIMAL,daily_sales INT,cuisine TEXT); | SELECT menu_name, MAX(price) FROM menu WHERE cuisine = 'Asian'; |
List the countries that had a decrease in visitors between 2020 and 2021. | CREATE TABLE VisitorCounts (Country VARCHAR(20),Year INT,VisitorCount INT); INSERT INTO VisitorCounts (Country,Year,VisitorCount) VALUES ('Japan',2020,1000),('Japan',2021,800),('Canada',2020,1500),('Canada',2021,1200); | SELECT Country FROM VisitorCounts WHERE Year IN (2020, 2021) GROUP BY Country HAVING COUNT(*) = 2 AND MAX(VisitorCount) < MIN(VisitorCount); |
How many riders used each route in the last week of June 2021? | CREATE TABLE route_planning (id INT,route VARCHAR(20),route_date DATE,num_riders INT); INSERT INTO route_planning (id,route,route_date,num_riders) VALUES (1,'Route 1','2021-06-21',150),(2,'Route 2','2021-06-23',200),(3,'Route 3','2021-06-25',250); | SELECT route, SUM(num_riders) as total_riders FROM route_planning WHERE route_date BETWEEN '2021-06-21' AND '2021-06-27' GROUP BY route; |
Add a new column 'manufacturer' to the 'workout_equipment' table | CREATE TABLE workout_equipment (equipment_id INT,equipment_name VARCHAR(50),quantity INT); | ALTER TABLE workout_equipment ADD manufacturer VARCHAR(50); |
What is the total investment in network infrastructure for each technology in the Western region? | CREATE TABLE network_investments (investment_id INT,technology VARCHAR(20),region VARCHAR(50),investment_amount INT); INSERT INTO network_investments (investment_id,technology,region,investment_amount) VALUES (1,'4G','North',10000),(2,'5G','North',20000),(3,'3G','South',15000),(4,'5G','East',25000),(5,'Fiber','West',30000),(6,'Cable','West',20000),(7,'DSL','East',18000); | SELECT technology, SUM(investment_amount) AS total_investment FROM network_investments WHERE region = 'West' GROUP BY technology; |
Find the number of inclusion efforts in each region | CREATE TABLE inclusion_efforts (effort_id INT,effort_name VARCHAR(30),region VARCHAR(20)); INSERT INTO inclusion_efforts (effort_id,effort_name,region) VALUES (1,'Accessible Buildings','North'),(2,'Diversity Training','South'),(3,'Inclusive Hiring','East'),(4,'Community Outreach','West'); | SELECT region, COUNT(*) FROM inclusion_efforts GROUP BY region; |
Insert a new sustainable sourcing record for Restaurant C using local produce. | CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(255)); CREATE TABLE sourcing (sourcing_id INT,restaurant_id INT,produce VARCHAR(255),local BOOLEAN); | INSERT INTO sourcing (sourcing_id, restaurant_id, produce, local) VALUES (1, (SELECT restaurant_id FROM restaurants WHERE name = 'Restaurant C'), 'local produce', TRUE); |
List all unique 'types' in the 'organizations' table | CREATE TABLE organizations (id INT,name VARCHAR(50),type VARCHAR(50),country VARCHAR(50)); INSERT INTO organizations (id,name,type,country) VALUES (1,'Accessible AI','Non-profit','USA'),(2,'Tech for Social Good','Non-governmental','India'),(3,'Digital Divide Initiative','Non-profit','Brazil'); | SELECT DISTINCT type FROM organizations; |
List all military innovation projects initiated after 2015 | CREATE TABLE military_innovation (id INT,project_name VARCHAR(255),initiator VARCHAR(255),start_date DATE); INSERT INTO military_innovation (id,project_name,initiator,start_date) VALUES (1,'Project S','USA','2016-03-14'),(2,'Project M','China','2017-06-23'); | SELECT * FROM military_innovation WHERE start_date > '2015-12-31'; |
What is the average age of volunteers who have volunteered for more than 20 hours in the last 6 months? | CREATE TABLE volunteers(id INT,name TEXT,age INT);CREATE TABLE volunteer_hours(id INT,volunteer_id INT,hours INT,volunteer_date DATE); | SELECT AVG(volunteers.age) as avg_age FROM volunteers JOIN volunteer_hours ON volunteers.id = volunteer_hours.volunteer_id WHERE volunteer_hours.volunteer_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND CURDATE() GROUP BY volunteers.id HAVING SUM(volunteer_hours.hours) > 20; |
Update 'emergency_response' table to set all response times above 60 minutes to 60 minutes | CREATE TABLE emergency_response (id INT,incident_id INT,response_time INT,PRIMARY KEY(id)); | UPDATE emergency_response SET response_time = 60 WHERE response_time > 60; |
What is the average number of visitors to each Australian cultural site per month? | CREATE TABLE cultural_sites (country VARCHAR(20),site VARCHAR(50),visitors INT,month INT); INSERT INTO cultural_sites (country,site,visitors,month) VALUES ('Australia','Sydney Opera House',250000,1),('Australia','Uluru',150000,1),('Australia','Sydney Opera House',220000,2),('Australia','Uluru',140000,2); | SELECT site, AVG(visitors) as avg_visitors FROM cultural_sites WHERE country = 'Australia' GROUP BY site; |
List all suppliers with no reported food safety violations | CREATE TABLE suppliers (supplier_id INT,name VARCHAR(50),safety_violations INT); INSERT INTO suppliers (supplier_id,name,safety_violations) VALUES (1,'Green Earth Farms',0),(2,'Sunny Harvest',2),(3,'Organic Roots',1); | SELECT * FROM suppliers WHERE safety_violations = 0; |
CREATE TABLE Underwater_Species(id INT, year INT, location VARCHAR(50), species VARCHAR(50), population INT, vulnerable_status VARCHAR(50)); | CREATE TABLE Underwater_Species(id INT,year INT,location VARCHAR(50),species VARCHAR(50),population INT,vulnerable_status VARCHAR(50));INSERT INTO Underwater_Species(id,year,location,species,population,vulnerable_status) VALUES (1,2021,'Mediterranean Sea','Coral X',200,'Endangered'); | SELECT location, species, SUM(population) AS Total_Population FROM Underwater_Species WHERE vulnerable_status = 'Endangered' GROUP BY location, species; |
What is the total cargo weight for vessels arriving in India in September 2022? | CREATE TABLE vessel_performance (id INT,name TEXT,speed DECIMAL(5,2),arrived_date DATE,country TEXT,cargo_weight INT); INSERT INTO vessel_performance (id,name,speed,arrived_date,country,cargo_weight) VALUES (1,'Vessel S',19.2,'2022-09-04','India',7000),(2,'Vessel T',20.6,'2022-09-18','India',8000),(3,'Vessel U',22.4,'2022-09-29','India',9000); | SELECT SUM(cargo_weight) FROM vessel_performance WHERE YEAR(arrived_date) = 2022 AND MONTH(arrived_date) = 9 AND country = 'India'; |
Delete all records in the 'Organizations' table where the category is 'Education' | CREATE TABLE Organizations (id INT PRIMARY KEY,organization_name VARCHAR(255),country VARCHAR(255),category VARCHAR(255)); | DELETE FROM Organizations WHERE category = 'Education'; |
What is the name of the biotech startup in Boston with the least funding? | CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(100),funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','Boston',12000000.0),(2,'StartupB','Boston',10000000.0),(3,'StartupC','Boston',11000000.0); | SELECT name FROM biotech.startups WHERE location = 'Boston' ORDER BY funding LIMIT 1; |
What is the total military expenditure by non-NATO countries in the last 5 years? | CREATE TABLE military_expenditure (expenditure_id INT,country TEXT,year INT,amount FLOAT); INSERT INTO military_expenditure (expenditure_id,country,year,amount) VALUES (1,'United States',2017,610),(2,'United States',2018,649),(3,'United Kingdom',2017,47),(4,'Germany',2018,43),(6,'Russia',2017,66),(7,'Russia',2018,69); | SELECT SUM(amount) FROM military_expenditure WHERE year >= (SELECT YEAR(GETDATE()) - 5) AND country NOT IN (SELECT member_state FROM nato_members); |
What is the total number of immunization clinics in the Western region? | CREATE TABLE immunization_clinics (id INT,region TEXT,clinic_type TEXT); INSERT INTO immunization_clinics (id,region,clinic_type) VALUES (1,'East','Flu Shot Clinic'),(2,'West','Immunization Clinic'); | SELECT COUNT(*) FROM immunization_clinics WHERE region = 'West'; |
What is the total R&D expenditure for drugs approved by the MHRA in 2020? | CREATE TABLE drug_approval (drug_name VARCHAR(255),approval_body VARCHAR(255),approval_year INT); CREATE TABLE rd_expenditure (drug_name VARCHAR(255),rd_expenditure FLOAT); INSERT INTO drug_approval (drug_name,approval_body,approval_year) VALUES ('DrugA','FDA',2019),('DrugB','MHRA',2018),('DrugC','MHRA',2020),('DrugD','MHRA',2021),('DrugE','EMA',2020); INSERT INTO rd_expenditure (drug_name,rd_expenditure) VALUES ('DrugA',40000000),('DrugB',30000000),('DrugC',50000000),('DrugD',60000000),('DrugE',25000000); | SELECT SUM(rd_expenditure) FROM rd_expenditure INNER JOIN drug_approval ON rd_expenditure.drug_name = drug_approval.drug_name WHERE drug_approval.approval_body = 'MHRA' AND drug_approval.approval_year = 2020; |
What is the total number of fans who attended football games in the South region last season? | CREATE TABLE Stadiums(id INT,name TEXT,location TEXT,sport TEXT,capacity INT); CREATE VIEW FootballStadiums AS SELECT * FROM Stadiums WHERE sport = 'Football'; | SELECT SUM(attendance) FROM (SELECT stadium_id, COUNT(ticket_id) AS attendance FROM TicketSales WHERE season = 'Last' AND stadium_id IN (SELECT id FROM FootballStadiums WHERE location = 'South')) AS GameAttendance |
How many students with mobility impairments have not received any accommodations in the mathematics department? | CREATE TABLE students (id INT,mobility_impairment BOOLEAN,department VARCHAR(255)); INSERT INTO students (id,mobility_impairment,department) VALUES (1,true,'science'),(2,false,'engineering'),(3,true,'science'),(4,true,'mathematics'),(5,false,'science'),(6,true,'mathematics'); CREATE TABLE accommodations (id INT,student_id INT,year INT); INSERT INTO accommodations (id,student_id,year) VALUES (1,1,2018),(2,1,2019),(3,3,2018),(4,3,2019),(5,3,2020),(6,4,2020),(7,5,2018),(8,5,2019),(9,5,2020); | SELECT COUNT(*) FROM students s WHERE s.mobility_impairment = true AND s.department = 'mathematics' AND s.id NOT IN (SELECT student_id FROM accommodations); |
Delete records for Gadolinium Oxide from the reo_production table for the year 2021 | CREATE TABLE reo_production (id INT PRIMARY KEY,reo_type VARCHAR(50),production_quantity INT,production_year INT); | DELETE FROM reo_production WHERE reo_type = 'Gadolinium Oxide' AND production_year = 2021; |
Find bioprocess engineering projects that have sensors. | CREATE TABLE projects (id INT,project_name VARCHAR(50),sensors VARCHAR(50)); INSERT INTO projects (id,project_name,sensors) VALUES (3,'Cell Culture','Sensor X'); INSERT INTO projects (id,project_name,sensors) VALUES (4,'Fermentation','Sensor Y'); | SELECT project_name FROM projects WHERE sensors IS NOT NULL; |
Delete all nutrition data for menu items without a category assigned | CREATE TABLE menu_items (id INT,name VARCHAR(255),category VARCHAR(255)); | DELETE FROM nutrition_data WHERE menu_item IN (SELECT name FROM menu_items WHERE category IS NULL); |
What is the average number of research grants awarded per department? | CREATE TABLE grad_students (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO grad_students VALUES (1,'John Doe','Physics'); INSERT INTO grad_students VALUES (2,'Jane Smith','Mathematics'); CREATE TABLE research_grants (id INT,student_id INT,year INT,amount DECIMAL(10,2)); INSERT INTO research_grants VALUES (1,1,2021,10000); INSERT INTO research_grants VALUES (2,2,2020,12000); INSERT INTO research_grants VALUES (3,1,2021,15000); | SELECT g.department, AVG(r.id) FROM grad_students g JOIN research_grants r ON g.id = r.student_id GROUP BY g.department; |
List the programs that have both volunteer and donor data. | CREATE TABLE Programs (id INT,name TEXT); INSERT INTO Programs (id,name) VALUES (1,'Youth Education'),(2,'Women Empowerment'),(3,'Clean Water'),(4,'Refugee Support'); CREATE TABLE Volunteers (id INT,program INT,hours INT); INSERT INTO Volunteers (id,program,hours) VALUES (1,1,20),(2,2,30),(3,3,15),(4,4,25); CREATE TABLE Donors (id INT,program INT,amount DECIMAL(10,2)); INSERT INTO Donors (id,program,amount) VALUES (1,1,100),(2,2,150),(3,3,75),(5,4,200); | SELECT Programs.name FROM Programs INNER JOIN Volunteers ON Programs.id = Volunteers.program INNER JOIN Donors ON Programs.id = Donors.program; |
What are the publication topics and corresponding faculty members in the 'Biology' department? | CREATE TABLE Publications (PublicationID int,FacultyID int,Topic varchar(50)); INSERT INTO Publications (PublicationID,FacultyID,Topic) VALUES (3,3,'Genetics'); CREATE TABLE Faculty (FacultyID int,Name varchar(50),Department varchar(50)); INSERT INTO Faculty (FacultyID,Name,Department) VALUES (3,'Alice Johnson','Biology'); | SELECT Publications.Topic, Faculty.Name FROM Publications INNER JOIN Faculty ON Publications.FacultyID = Faculty.FacultyID WHERE Faculty.Department = 'Biology'; |
Retrieve smart contracts written in Solidity with a version of 0.5.x. | CREATE TABLE if not exists smart_contracts (id INT PRIMARY KEY,name TEXT,language TEXT,version TEXT); INSERT INTO smart_contracts (id,name,language,version) VALUES (1,'CryptoKitties','Solidity','0.4.24'),(2,'UniswapV2','Vyper','0.2.6'),(3,'Gnosis','Solidity','0.5.12'); | SELECT * FROM smart_contracts WHERE language = 'Solidity' AND version LIKE '0.5.%'; |
What is the total quantity of products sold by each supplier in the ethical labor practice category? | CREATE TABLE suppliers (supplier_id INT,ethical_practice_category VARCHAR(50)); CREATE TABLE sales (sale_id INT,supplier_id INT,quantity_sold INT); INSERT INTO suppliers (supplier_id,ethical_practice_category) VALUES (1,'Ethical'),(2,'Unethical'),(3,'Ethical'); INSERT INTO sales (sale_id,supplier_id,quantity_sold) VALUES (1,1,100),(2,1,200),(3,2,300),(4,3,400),(5,3,500); | SELECT suppliers.ethical_practice_category, SUM(sales.quantity_sold) AS total_quantity_sold FROM suppliers INNER JOIN sales ON suppliers.supplier_id = sales.supplier_id GROUP BY suppliers.ethical_practice_category; |
How many unique donors made donations in each quarter of 2022? | CREATE TABLE donations (id INT,donor TEXT,donation_date DATE); | SELECT DATE_FORMAT(donation_date, '%Y-%V') as quarter, COUNT(DISTINCT donor) as unique_donors FROM donations WHERE donation_date >= '2022-01-01' AND donation_date < '2023-01-01' GROUP BY quarter; |
Which dispensaries in California have the highest average transaction value for edibles? | CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT);CREATE TABLE Transactions (id INT,dispensary_id INT,product_type TEXT,transaction_value DECIMAL); | SELECT D.name FROM Dispensaries D JOIN (SELECT dispensary_id, AVG(transaction_value) AS avg_value FROM Transactions WHERE product_type = 'edibles' GROUP BY dispensary_id ORDER BY avg_value DESC LIMIT 1) T ON D.id = T.dispensary_id; |
Update records in the 'Donors' table where the donor's name is 'John Smith' and change the last donation date to '2022-01-01' | CREATE TABLE Donors (id INT PRIMARY KEY,donor_name VARCHAR(255),last_donation DATE,donation_amount FLOAT); | UPDATE Donors SET last_donation = '2022-01-01' WHERE donor_name = 'John Smith'; |
What is the average age of readers who prefer technology news? | CREATE TABLE readers (id INT,name VARCHAR(50),age INT,preference VARCHAR(50)); INSERT INTO readers (id,name,age,preference) VALUES (1,'John Doe',25,'technology'),(2,'Jane Smith',32,'politics'); | SELECT AVG(age) FROM readers WHERE preference = 'technology'; |
How many members joined in Q1 2021 who have not attended any class yet? | CREATE TABLE Members (MemberID int,JoinDate date); INSERT INTO Members (MemberID,JoinDate) VALUES (1,'2021-01-05'); CREATE TABLE Classes (ClassID int,ClassDate date,MemberID int); INSERT INTO Classes (ClassID,ClassDate,MemberID) VALUES (1,'2021-02-01',1); | SELECT COUNT(MemberID) FROM Members m WHERE YEAR(m.JoinDate) = 2021 AND QUARTER(m.JoinDate) = 1 AND m.MemberID NOT IN (SELECT MemberID FROM Classes); |
Which games belong to the same genres as 'GameF' EXCEPT 'Action' and 'GameE'? | CREATE TABLE GameGenres (GameID int,GameName varchar(100),Genre varchar(50)); INSERT INTO GameGenres VALUES (6,'GameF','Action'),(8,'GameH','RPG'),(9,'GameI','Simulation'),(10,'GameJ','Strategy'); | SELECT GameName, Genre FROM GameGenres WHERE Genre IN (SELECT Genre FROM GameGenres WHERE GameName = 'GameF') EXCEPT (SELECT GameName, 'Action' FROM GameGenres WHERE GameName = 'GameF' UNION SELECT 'GameE', Genre FROM GameGenres WHERE GameName = 'GameE'); |
What is the total water usage for each drought category in the southern region in 2018?' | CREATE TABLE drought_impact (region VARCHAR(255),drought_category VARCHAR(255),month DATE,usage INT); INSERT INTO drought_impact (region,drought_category,month,usage) VALUES ('Southern','Moderate','2018-01-01',8000); | SELECT region, drought_category, SUM(usage) FROM drought_impact WHERE region = 'Southern' AND YEAR(month) = 2018 GROUP BY region, drought_category; |
How many workers are employed in factories with fair labor practices in South America? | CREATE TABLE FactoryWorkers (factory_id INT,number_of_workers INT,has_fair_labor_practices BOOLEAN); INSERT INTO FactoryWorkers (factory_id,number_of_workers,has_fair_labor_practices) VALUES (1,200,true),(2,300,false),(3,150,true); CREATE TABLE Factories (factory_id INT,region VARCHAR(50)); INSERT INTO Factories (factory_id,region) VALUES (1,'South America'),(2,'North America'),(3,'South America'); | SELECT COUNT(FactoryWorkers.number_of_workers) FROM FactoryWorkers INNER JOIN Factories ON FactoryWorkers.factory_id = Factories.factory_id WHERE Factories.region = 'South America' AND FactoryWorkers.has_fair_labor_practices = true; |
Which female clients have a total asset greater than $300,000 and have invested in real estate? | CREATE TABLE clients (client_id INT,name TEXT,age INT,gender TEXT,total_assets DECIMAL(10,2)); INSERT INTO clients VALUES (1,'John Doe',35,'Male',250000.00),(2,'Jane Smith',45,'Female',500000.00),(3,'Bob Johnson',50,'Male',800000.00),(4,'Alice Lee',40,'Female',320000.00); CREATE TABLE investments (client_id INT,investment_type TEXT); INSERT INTO investments VALUES (1,'Stocks'),(1,'Bonds'),(2,'Stocks'),(2,'Mutual Funds'),(3,'Mutual Funds'),(3,'Real Estate'),(4,'Real Estate'); | SELECT c.name, c.total_assets FROM clients c INNER JOIN investments i ON c.client_id = i.client_id WHERE c.gender = 'Female' AND i.investment_type = 'Real Estate' AND c.total_assets > 300000.00; |
What is the release date and revenue for songs released before 2010? | CREATE TABLE Releases (ReleaseID int,SongID int,ReleaseDate date); INSERT INTO Releases (ReleaseID,SongID,ReleaseDate) VALUES (1,1,'2009-01-01'),(2,2,'2008-05-15'),(3,3,'2012-07-25'); | SELECT Songs.SongName, Releases.ReleaseDate, Sales.Revenue FROM Songs INNER JOIN Releases ON Songs.SongID = Releases.SongID INNER JOIN Sales ON Songs.SongID = Sales.SongID WHERE Releases.ReleaseDate < '2010-01-01'; |
Find the average points scored by the top 5 players in the NBA for the current season | CREATE TABLE players (id INT PRIMARY KEY,name TEXT,team TEXT,position TEXT,points_per_game FLOAT); INSERT INTO players (id,name,team,position,points_per_game) VALUES (1,'Kevin Durant','Brooklyn Nets','Forward',26.9),(2,'Giannis Antetokounmpo','Milwaukee Bucks','Forward',29.5),(3,'Joel Embiid','Philadelphia 76ers','Center',30.6),(4,'Luka Doncic','Dallas Mavericks','Guard',28.8),(5,'Trae Young','Atlanta Hawks','Guard',25.3),(6,'LeBron James','Los Angeles Lakers','Forward',25.0); | SELECT AVG(points_per_game) FROM (SELECT points_per_game FROM players ORDER BY points_per_game DESC LIMIT 5) AS top_five_players; |
What is the total weight of each component in the spacecraft? | CREATE TABLE spacecraft_weight (component VARCHAR(20),weight INT); INSERT INTO spacecraft_weight (component,weight) VALUES ('Propulsion System',2000),('Avionics',1500),('Structure',4000); | SELECT component, weight FROM spacecraft_weight; |
What is the total budget of departments that have implemented open data initiatives and have created more than 5 evidence-based policies? | CREATE TABLE departments (id INT,name VARCHAR(50),budget INT,open_data BOOLEAN); INSERT INTO departments (id,name,budget,open_data) VALUES (1,'Education',15000000,true),(2,'Transportation',20000000,true); CREATE TABLE policies (id INT,department_id INT,title VARCHAR(50),evidence_based BOOLEAN); INSERT INTO policies (id,department_id,title,evidence_based) VALUES (1,1,'Safe Routes to School',true),(2,2,'Mass Transit Expansion',true),(3,2,'Bike Lane Expansion',true); | SELECT SUM(budget) as total_budget FROM departments d WHERE open_data = true AND (SELECT COUNT(*) FROM policies p WHERE d.id = p.department_id AND evidence_based = true) > 5; |
Find the difference in years between the birth of an artist and the creation of their first painting. | CREATE TABLE artists (id INT,name VARCHAR(50),birth_date DATE); INSERT INTO artists (id,name,birth_date) VALUES (1,'Claude Monet','1840-11-14'); CREATE TABLE paintings (id INT,artist_id INT,year INT); INSERT INTO paintings (id,artist_id,year) VALUES (1,1,1865); | SELECT a.name, DATEDIFF(year, a.birth_date, MIN(p.year)) as age_at_first_painting FROM artists a JOIN paintings p ON a.id = p.artist_id GROUP BY a.name, a.birth_date; |
How many transactions were made by clients with a last name starting with 'S' in Q3 2022? | CREATE TABLE clients (client_id INT,name VARCHAR(50),last_transaction_date DATE);CREATE TABLE transactions (transaction_id INT,client_id INT,transaction_date DATE); | SELECT COUNT(*) FROM transactions t INNER JOIN clients c ON t.client_id = c.client_id WHERE SUBSTRING(c.name, 1, 1) = 'S' AND t.transaction_date BETWEEN '2022-07-01' AND '2022-09-30' |
Identify the number of wells drilled in each country by state-owned companies between 2018 and 2020 | CREATE TABLE wells_state_owned (id INT,well_name VARCHAR(50),location VARCHAR(50),company VARCHAR(50),num_drills INT,drill_date DATE,is_state_owned BOOLEAN); INSERT INTO wells_state_owned VALUES (1,'Well G','Norway','Norwegian Oil',4,'2019-04-01',true); INSERT INTO wells_state_owned VALUES (2,'Well H','Texas','Texas Oil',6,'2018-09-15',false); INSERT INTO wells_state_owned VALUES (3,'Well I','Alaska','Alaskan Oil',7,'2020-07-22',true); | SELECT location, SUM(num_drills) FROM wells_state_owned WHERE is_state_owned = true AND drill_date BETWEEN '2018-01-01' AND '2020-12-31' GROUP BY location; |
How many dance performances have been held in each country, and what is the average attendance for each country? | CREATE TABLE Performances (Id INT,PerformanceName VARCHAR(50),LocationCountry VARCHAR(50),Attendance INT);CREATE TABLE DancePerformances (Id INT,PerformanceId INT); | SELECT LocationCountry, AVG(Attendance) as AvgAttendance, COUNT(*) as TotalPerformances FROM Performances P INNER JOIN DancePerformances DP ON P.Id = DP.PerformanceId GROUP BY LocationCountry; |
Find the number of unique patients enrolled in 'prevention' and 'treatment' programs in 'northeast' regions. | CREATE TABLE public_health (id INT,patient_id INT,name TEXT,region TEXT,program_type TEXT); INSERT INTO public_health (id,patient_id,name,region,program_type) VALUES (1,1,'Initiative A','northeast','prevention'); INSERT INTO public_health (id,patient_id,name,region,program_type) VALUES (2,2,'Initiative B','central','treatment'); INSERT INTO public_health (id,patient_id,name,region,program_type) VALUES (3,1,'Initiative C','northeast','treatment'); | SELECT COUNT(DISTINCT patient_id) FROM public_health WHERE region = 'northeast' AND program_type IN ('prevention', 'treatment'); |
What is the total number of emergency incidents in each borough? | CREATE TABLE borough (id INT,name VARCHAR(50)); INSERT INTO borough (id,name) VALUES (1,'Manhattan'),(2,'Brooklyn'),(3,'Queens'),(4,'Bronx'),(5,'Staten Island'); CREATE TABLE incident (id INT,borough_id INT,type VARCHAR(50),timestamp TIMESTAMP); | SELECT borough_id, COUNT(*) as total_incidents FROM incident GROUP BY borough_id; |
How many tickets were sold for the "Chicago Bulls" games in the first quarter of 2022? | CREATE TABLE ticket_sales(id INT,team VARCHAR(50),game_date DATE,ticket_type VARCHAR(10),quantity INT);INSERT INTO ticket_sales(id,team,game_date,ticket_type,quantity) VALUES (1,'Chicago Bulls','2022-01-01','Regular',300),(2,'Chicago Bulls','2022-01-02','VIP',200),(3,'Chicago Bulls','2022-03-15','Regular',400); | SELECT SUM(quantity) FROM ticket_sales WHERE team = 'Chicago Bulls' AND game_date BETWEEN '2022-01-01' AND '2022-03-31'; |
What is the average CO2 emissions reduction for projects using carbon capture technology? | CREATE TABLE co2_emissions (project_id INT,co2_reduction INT); INSERT INTO co2_emissions (project_id,co2_reduction) VALUES (1,5000),(2,6000),(3,7000),(4,4000),(5,8000); | SELECT AVG(co2_reduction) FROM co2_emissions WHERE project_id IN (SELECT project_id FROM carbon_capture); |
Delete all records of clients who have never invested in any market. | CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(50));CREATE TABLE investments (investment_id INT,client_id INT,market VARCHAR(50),value INT);INSERT INTO clients (client_id,name,region) VALUES (1,'John Doe','North America'),(2,'Jane Smith','Asia');INSERT INTO investments (investment_id,client_id,market,value) VALUES (1,1,'US',50000),(2,2,'Japan',100000); | DELETE FROM clients c WHERE c.client_id NOT IN (SELECT i.client_id FROM investments i); |
What is the impact of drought on crop yields in Texas? | CREATE TABLE crops (id INT,name TEXT,state TEXT,yield FLOAT,drought_index FLOAT); INSERT INTO crops (id,name,state,yield,drought_index) VALUES (1,'Corn','Texas',120,5),(2,'Wheat','Texas',80,3),(3,'Soybeans','Texas',90,2); | SELECT name, yield, drought_index, yield/drought_index as impact FROM crops WHERE state = 'Texas'; |
What is the average age of visitors who attended virtual events in 2020, broken down by event type? | CREATE TABLE Visitors (VisitorID INT,Age INT,EventID INT,EventType VARCHAR(255)); INSERT INTO Visitors (VisitorID,Age,EventID,EventType) VALUES (1,32,1,'Virtual Conference'); INSERT INTO Visitors (VisitorID,Age,EventID,EventType) VALUES (2,45,2,'Webinar'); INSERT INTO Visitors (VisitorID,Age,EventID,EventType) VALUES (3,50,3,'Virtual Exhibition'); | SELECT EventType, AVG(Age) as AverageAge FROM Visitors WHERE YEAR(EventDate) = 2020 GROUP BY EventType; |
What is the average life expectancy for each gender in Europe? | CREATE TABLE LifeExpectancy (Gender VARCHAR(255),Continent VARCHAR(255),LifeExpectancy FLOAT); INSERT INTO LifeExpectancy (Gender,Continent,LifeExpectancy) VALUES ('Male','Europe',74.1),('Female','Europe',81.1); | SELECT Gender, AVG(LifeExpectancy) FROM LifeExpectancy WHERE Continent = 'Europe' GROUP BY Gender; |
Determine the total revenue for the year 2022 | CREATE TABLE sales (id INT PRIMARY KEY,date DATE,amount DECIMAL(10,2)); INSERT INTO sales (id,date,amount) VALUES (1,'2022-01-01',1000.00),(2,'2022-02-01',2000.00),(3,'2023-01-01',3000.00); | SELECT SUM(amount) FROM sales WHERE YEAR(date) = 2022; |
Display the total calories for each dish category in the menu_categories and menu tables. | CREATE TABLE menu_categories (category_id INT,category_name TEXT); CREATE TABLE menu (menu_id INT,category_id INT,dish_name TEXT,calories INT); | SELECT menu_categories.category_name, SUM(menu.calories) FROM menu INNER JOIN menu_categories ON menu.category_id = menu_categories.category_id GROUP BY menu_categories.category_name; |
What is the total number of volunteers who joined in Q1 2021 and are from Latin America? | CREATE TABLE volunteers (id INT,name TEXT,country TEXT,join_date DATE); INSERT INTO volunteers (id,name,country,join_date) VALUES (1,'Carlos Rodriguez','Mexico','2021-01-10'); INSERT INTO volunteers (id,name,country,join_date) VALUES (2,'Ana Silva','Brazil','2021-03-15'); INSERT INTO volunteers (id,name,country,join_date) VALUES (3,'Juan Garcia','Argentina','2021-01-20'); | SELECT COUNT(*) FROM volunteers WHERE join_date BETWEEN '2021-01-01' AND '2021-03-31' AND country IN ('Mexico', 'Brazil', 'Argentina', 'Colombia', 'Peru', 'Chile'); |
Find the number of accessible technology products released in 2019 and 2020 that were developed by companies based in North America or Europe. | CREATE TABLE accessible_tech (product_id INT,product_release_year INT,company_region VARCHAR(15));INSERT INTO accessible_tech (product_id,product_release_year,company_region) VALUES (1,2019,'North America'),(2,2020,'Europe'),(3,2018,'Asia'); | SELECT COUNT(*) FROM accessible_tech WHERE product_release_year BETWEEN 2019 AND 2020 AND company_region IN ('North America', 'Europe'); |
What is the average population of orangutans in Southeast Asian habitats? | CREATE TABLE habitats (name VARCHAR(255),region VARCHAR(255),animal_type VARCHAR(255),population INT); INSERT INTO habitats (name,region,animal_type,population) VALUES ('borneo','Southeast Asia','orangutan',200); INSERT INTO habitats (name,region,animal_type,population) VALUES ('sumatra','Southeast Asia','orangutan',250); | SELECT AVG(population) FROM habitats WHERE region = 'Southeast Asia' AND animal_type = 'orangutan'; |
Delete all records from the 'maintenance_data' table where the 'equipment_id' is less than 100 | CREATE TABLE maintenance_data (maintenance_id INT,equipment_id INT); | DELETE FROM maintenance_data WHERE equipment_id < 100; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.