instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average water temperature for each location in the Carps_Farming table?
CREATE TABLE Carps_Farming (Farm_ID INT,Farm_Name TEXT,Location TEXT,Water_Temperature FLOAT); INSERT INTO Carps_Farming (Farm_ID,Farm_Name,Location,Water_Temperature) VALUES (1,'Farm 1','China',22.5),(2,'Farm 2','China',23.3),(3,'Farm 3','Vietnam',24.7);
SELECT Location, AVG(Water_Temperature) FROM Carps_Farming GROUP BY Location;
What are the names and drilling dates of all wells in the 'DRILLING_HISTORY' table?
CREATE TABLE DRILLING_HISTORY (WELL_NAME VARCHAR(255),DRILL_DATE DATE);
SELECT WELL_NAME, DRILL_DATE FROM DRILLING_HISTORY;
Identify the health equity metrics that have been measured in the past year and their respective measurement dates.
CREATE TABLE Health_Equity_Metrics (Metric_ID INT,Metric_Name VARCHAR(255),Measurement_Date DATE); INSERT INTO Health_Equity_Metrics (Metric_ID,Metric_Name,Measurement_Date) VALUES (1,'Access to Care','2022-04-01'),(2,'Quality of Care','2022-03-15');
SELECT Metric_Name, Measurement_Date FROM Health_Equity_Metrics WHERE Measurement_Date >= DATEADD(year, -1, GETDATE());
What is the average budget for language preservation programs in Asia and South America?
CREATE TABLE budgets (program VARCHAR(255),region VARCHAR(255),amount INTEGER); INSERT INTO budgets (program,region,amount) VALUES ('Program A','Asia',10000); INSERT INTO budgets (program,region,amount) VALUES ('Program B','South America',15000);
SELECT AVG(amount) FROM budgets WHERE region IN ('Asia', 'South America') AND program LIKE 'language%'
List marine species impacted by climate change and their status in 2025.
CREATE TABLE marine_species (id INT PRIMARY KEY,name VARCHAR(50),habitat VARCHAR(50),population INT);CREATE TABLE climate_change_impact (id INT PRIMARY KEY,species_id INT,impact VARCHAR(50),year INT);
SELECT m.name, c.impact, c.year FROM marine_species m JOIN climate_change_impact c ON m.id = c.species_id WHERE c.impact = 'Impacted' AND c.year = 2025;
Update the 'bias' value to 6 for records with 'algorithm' = 'K-Nearest Neighbor' in the 'testing_data3' table
CREATE TABLE testing_data3 (id INT,algorithm VARCHAR(20),bias INT,fairness INT); INSERT INTO testing_data3 (id,algorithm,bias,fairness) VALUES (1,'K-Nearest Neighbor',4,7),(2,'K-Means',6,5),(3,'K-Nearest Neighbor',3,8);
UPDATE testing_data3 SET bias = 6 WHERE algorithm = 'K-Nearest Neighbor';
Get the names and number of languages preserved in each region, grouped by region.
CREATE TABLE LanguagePreservation (id INT PRIMARY KEY,region VARCHAR(255),language VARCHAR(255),preserved BOOLEAN); INSERT INTO LanguagePreservation (id,region,language,preserved) VALUES (1,'Region A','Language 1',TRUE),(2,'Region B','Language 2',FALSE),(3,'Region A','Language 3',TRUE),(4,'Region C','Language 4',TRUE);
SELECT region, COUNT(*) FROM LanguagePreservation WHERE preserved = TRUE GROUP BY region;
How many satellites have been launched by China since 2010?
CREATE TABLE SatelliteLaunches (id INT,name VARCHAR(255),launch_country VARCHAR(255),launch_year INT,satellites INT);
SELECT COUNT(*) FROM SatelliteLaunches WHERE launch_country = 'China' AND launch_year >= 2010;
Find the top 3 satellite images with the highest resolution for plot_id 456
CREATE TABLE satellite_image (image_id INT,plot_id INT,resolution INT); INSERT INTO satellite_image (image_id,plot_id,resolution) VALUES (1,456,1080),(2,456,1440),(3,456,2160),(4,456,720),(5,456,1080);
SELECT image_id, resolution FROM (SELECT image_id, resolution, ROW_NUMBER() OVER (ORDER BY resolution DESC) row_num FROM satellite_image WHERE plot_id = 456) tmp WHERE row_num <= 3;
What is the total number of open pedagogy courses offered by 'Acme U' in 'Fall' seasons?
CREATE TABLE open_pedagogy_courses (course_id INT,university VARCHAR(20),season VARCHAR(10)); INSERT INTO open_pedagogy_courses (course_id,university,season) VALUES (1,'Acme U','Fall'),(2,'Harvard U','Spring'),(3,'Acme U','Spring');
SELECT COUNT(*) FROM open_pedagogy_courses WHERE university = 'Acme U' AND season = 'Fall';
How many eco-friendly materials are sourced by country?
CREATE TABLE sourcing (country VARCHAR(255),material VARCHAR(255),eco_friendly BOOLEAN);
SELECT country, COUNT(*) as eco_friendly_materials_count FROM sourcing WHERE eco_friendly = TRUE GROUP BY country;
What is the total number of unique equipment types, grouped by their types, on farms in the South region?
CREATE TABLE equipment (id INT,date DATE,type VARCHAR(50),condition VARCHAR(50),farm_id INT,FOREIGN KEY (farm_id) REFERENCES farmers(id)); INSERT INTO equipment (id,date,type,condition,farm_id) VALUES (1,'2022-01-01','Tractors','Good',1),(2,'2022-01-02','Combine harvesters','Excellent',2),(3,'2022-01-03','Sprayers','Very good',5),(4,'2022-01-04','Seed drills','Good',6),(5,'2022-01-05','Tillage equipment','Fair',3); INSERT INTO farmers (id,name,region,age) VALUES (1,'James','South',50),(2,'Sophia','South',40),(3,'Mason','North',45),(4,'Lily','East',55),(5,'Olivia','South',60),(6,'Benjamin','East',48);
SELECT e.type, COUNT(DISTINCT e.id) as unique_equipment FROM equipment e JOIN farmers f ON e.farm_id = f.id WHERE f.region = 'South' GROUP BY e.type;
What is the average yield of crops for each farmer in the 'rural_development' database?
CREATE TABLE farmers (id INT PRIMARY KEY,name TEXT,location TEXT); INSERT INTO farmers (id,name,location) VALUES (1,'John Doe','Springfield'); INSERT INTO farmers (id,name,location) VALUES (2,'Jane Smith','Shelbyville'); CREATE TABLE crop_yields (farmer_id INT,year INT,yield INT); INSERT INTO crop_yields (farmer_id,year,yield) VALUES (1,2020,500); INSERT INTO crop_yields (farmer_id,year,yield) VALUES (1,2021,550); INSERT INTO crop_yields (farmer_id,year,yield) VALUES (2,2020,450); INSERT INTO crop_yields (farmer_id,year,yield) VALUES (2,2021,500);
SELECT f.name, AVG(cy.yield) as avg_yield FROM farmers f JOIN crop_yields cy ON f.id = cy.farmer_id GROUP BY f.id;
Which countries in the Middle East have the highest revenue from cultural heritage tourism?
CREATE TABLE tourism_revenue (country VARCHAR(50),sector VARCHAR(50),revenue DECIMAL(10,2)); INSERT INTO tourism_revenue (country,sector,revenue) VALUES ('Saudi Arabia','Cultural Heritage',15000.00),('Jordan','Cultural Heritage',12000.00),('Israel','Virtual Tourism',9000.00),('Turkey','Cultural Heritage',18000.00),('Egypt','Cultural Heritage',10000.00);
SELECT country, SUM(revenue) as total_revenue FROM tourism_revenue WHERE sector = 'Cultural Heritage' AND country LIKE 'Middle%' GROUP BY country ORDER BY total_revenue DESC LIMIT 1;
What is the name, country, and product of all cruelty-free suppliers from India?
CREATE TABLE supplier (id INT PRIMARY KEY,name VARCHAR(50),country VARCHAR(50),product VARCHAR(50),cruelty_free BOOLEAN);
SELECT supplier.name, supplier.country, product FROM supplier WHERE cruelty_free = TRUE AND country = 'India';
List the top 5 strains with the highest total sales in California dispensaries in Q3 2022.
CREATE TABLE Dispensaries (Dispensary_ID INT,Dispensary_Name TEXT,State TEXT); INSERT INTO Dispensaries (Dispensary_ID,Dispensary_Name,State) VALUES (1,'California Dream','CA'); CREATE TABLE Sales (Sale_ID INT,Dispensary_ID INT,Strain TEXT,Total_Sales DECIMAL); INSERT INTO Sales (Sale_ID,Dispensary_ID,Strain,Total_Sales) VALUES (1,1,'Blue Dream',1800.00);
SELECT Strain, SUM(Total_Sales) as Total FROM Sales JOIN Dispensaries ON Sales.Dispensary_ID = Dispensaries.Dispensary_ID WHERE State = 'CA' AND QUARTER(Sale_Date) = 3 GROUP BY Strain ORDER BY Total DESC LIMIT 5;
Find the total crime count for each type of crime in a given year.
CREATE TABLE crimes (id INT,type VARCHAR(255),year INT,count INT);
SELECT type, SUM(count) FROM crimes WHERE year = 2022 GROUP BY type;
What is the total amount of gold extracted in the year 2019 in the province "Ontario" in Canada?
CREATE TABLE gold_extraction (id INT,mine TEXT,province TEXT,country TEXT,year INT,amount INT); INSERT INTO gold_extraction (id,mine,province,country,year,amount) VALUES (1,'Gold Mine 1','Ontario','Canada',2018,1000); INSERT INTO gold_extraction (id,mine,province,country,year,amount) VALUES (2,'Gold Mine 2','Ontario','Canada',2019,1200);
SELECT SUM(amount) FROM gold_extraction WHERE province = 'Ontario' AND country = 'Canada' AND year = 2019;
Find the number of companies in each sector in Asia with ESG scores above 75.
CREATE TABLE sectors (id INT,company_id INT,sector TEXT); INSERT INTO sectors (id,company_id,sector) VALUES (1,3,'Renewable Energy'),(2,4,'Healthcare'),(3,5,'Finance');
SELECT sectors.sector, COUNT(DISTINCT companies.id) FROM companies INNER JOIN sectors ON companies.id = sectors.company_id WHERE companies.country LIKE 'Asia%' AND companies.ESG_score > 75 GROUP BY sectors.sector;
What is the average permit fee for residential buildings in the city of Seattle?
CREATE TABLE building_permit (permit_id INT,building_type VARCHAR(50),fee DECIMAL(10,2),city VARCHAR(50)); INSERT INTO building_permit (permit_id,building_type,fee,city) VALUES (1,'Residential',5000,'Seattle'),(2,'Commercial',12000,'Seattle'),(3,'Residential',4500,'Los Angeles');
SELECT AVG(fee) FROM building_permit WHERE building_type = 'Residential' AND city = 'Seattle';
What are the construction labor statistics for the state of California and New York?
CREATE TABLE Labor_Statistics (state TEXT,workers_employed INTEGER,hours_worked INTEGER,wage_per_hour FLOAT); INSERT INTO Labor_Statistics (state,workers_employed,hours_worked,wage_per_hour) VALUES ('California',5000,25000,30.5),('Texas',3000,18000,28.3),('New York',4000,20000,32.7);
SELECT * FROM Labor_Statistics WHERE state IN ('California', 'New York');
What is the total revenue for public transportation in Madrid on weekdays?
CREATE TABLE madrid_bus (ride_id INT,fare DECIMAL(5,2),ride_date DATE); CREATE TABLE madrid_train (ride_id INT,fare DECIMAL(5,2),ride_date DATE); CREATE TABLE madrid_subway (ride_id INT,fare DECIMAL(5,2),ride_date DATE);
SELECT SUM(fare) FROM (SELECT fare FROM madrid_bus WHERE DAYOFWEEK(ride_date) BETWEEN 2 AND 6 UNION ALL SELECT fare FROM madrid_train WHERE DAYOFWEEK(ride_date) BETWEEN 2 AND 6 UNION ALL SELECT fare FROM madrid_subway WHERE DAYOFWEEK(ride_date) BETWEEN 2 AND 6) AS weekday_fares;
What is the average price of digital assets in the 'Gaming' category?
CREATE TABLE digital_assets (id INT,name VARCHAR(255),type VARCHAR(50),price DECIMAL(10,2)); INSERT INTO digital_assets (id,name,type,price) VALUES (1,'Asset1','Crypto',10.5); INSERT INTO digital_assets (id,name,type,price) VALUES (2,'Asset2','Crypto',20.2); INSERT INTO digital_assets (id,name,type,price) VALUES (3,'Asset3','Security',50.0); INSERT INTO digital_assets (id,name,type,price) VALUES (4,'Asset4','Security',75.0); INSERT INTO digital_assets (id,name,type,price) VALUES (5,'Asset5','Gaming',15.0); INSERT INTO digital_assets (id,name,type,price) VALUES (6,'Asset6','Gaming',12.0); INSERT INTO digital_assets (id,name,type,price) VALUES (7,'Asset7','Gaming',22.0);
SELECT AVG(price) as avg_price FROM digital_assets WHERE type = 'Gaming';
Which sustainable materials are used by factories in South America?
CREATE TABLE Factories (factory_id INT,factory_name VARCHAR(50),country VARCHAR(50),certification VARCHAR(50)); CREATE TABLE Factory_Materials (factory_id INT,material_id INT); CREATE TABLE Materials (material_id INT,material_name VARCHAR(50),is_sustainable BOOLEAN); INSERT INTO Factories (factory_id,factory_name,country) VALUES (1,'GreenSouth','Argentina'),(2,'EcoCentral','Brazil'),(3,'SustainableNorth','Colombia'); INSERT INTO Materials (material_id,material_name,is_sustainable) VALUES (1,'Organic Cotton',true),(2,'Synthetic Fiber',false),(3,'Recycled Plastic',true),(4,'Bamboo Fiber',true); INSERT INTO Factory_Materials (factory_id,material_id) VALUES (1,1),(1,3),(2,1),(2,3),(3,3),(3,4);
SELECT m.material_name FROM Factories f INNER JOIN Factory_Materials fm ON f.factory_id = fm.factory_id INNER JOIN Materials m ON fm.material_id = m.material_id WHERE f.country IN ('Argentina', 'Brazil', 'Colombia', 'Peru', 'Chile') AND m.is_sustainable = true;
Which users are located in Brazil and have posted more than 5 comments?
CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(50),age INT,gender VARCHAR(10),location VARCHAR(50)); CREATE TABLE comments (id INT PRIMARY KEY,post_id INT,user_id INT,comment_text VARCHAR(100)); INSERT INTO users (id,name,age,gender,location) VALUES (1,'Maria',28,'Female','Brazil'); INSERT INTO users (id,name,age,gender,location) VALUES (2,'Joao',35,'Male','Brazil'); INSERT INTO comments (id,post_id,user_id,comment_text) VALUES (1,1,1,'Great post!'); INSERT INTO comments (id,post_id,user_id,comment_text) VALUES (2,2,2,'Thanks!'); INSERT INTO comments (id,post_id,user_id,comment_text) VALUES (3,1,1,'This is awesome!');
SELECT users.name FROM users INNER JOIN comments ON users.id = comments.user_id WHERE users.location = 'Brazil' GROUP BY users.name HAVING COUNT(comments.id) > 5;
Count the number of asteroid impacts on the Moon detected by the Lunar Reconnaissance Orbiter (LRO) in the year 2020.
CREATE TABLE Asteroid_Impacts (id INT,date DATE,impact_location VARCHAR(255),detected_by VARCHAR(255),size FLOAT);
SELECT COUNT(*) FROM Asteroid_Impacts WHERE date BETWEEN '2020-01-01' AND '2020-12-31' AND detected_by = 'Lunar Reconnaissance Orbiter';
List the names of workplaces in the United Kingdom that have implemented workplace safety measures and have had successful collective bargaining agreements.
CREATE TABLE uk_workplaces (id INT,name TEXT,country TEXT,workplace_safety BOOLEAN,collective_bargaining BOOLEAN); INSERT INTO uk_workplaces (id,name,country,workplace_safety,collective_bargaining) VALUES (1,'Workplace J','UK',true,true),(2,'Workplace K','UK',false,true),(3,'Workplace L','UK',true,false);
SELECT name FROM uk_workplaces WHERE workplace_safety = true AND collective_bargaining = true;
Which workout was the most popular among female members in March 2022?
CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),MembershipType VARCHAR(20)); INSERT INTO Members (MemberID,Age,Gender,MembershipType) VALUES (1,35,'Female','Premium'),(2,45,'Male','Basic'),(3,28,'Female','Premium'); CREATE TABLE ClassAttendance (MemberID INT,Class VARCHAR(20),Date DATE); INSERT INTO ClassAttendance (MemberID,Class,Date) VALUES (1,'Cycling','2022-01-01'),(2,'Yoga','2022-01-02'),(3,'Cycling','2022-03-03'),(4,'Yoga','2022-03-04'),(5,'Pilates','2022-03-05');
SELECT Class, COUNT(*) as AttendanceCount FROM Members JOIN ClassAttendance ON Members.MemberID = ClassAttendance.MemberID WHERE Members.Gender = 'Female' AND MONTH(ClassAttendance.Date) = 3 GROUP BY Class ORDER BY AttendanceCount DESC LIMIT 1;
What is the minimum number of containers handled in a single day by cranes in the Port of Singapore in February 2021?
CREATE TABLE Port_Singapore_Crane_Stats (crane_name TEXT,handling_date DATE,containers_handled INTEGER); INSERT INTO Port_Singapore_Crane_Stats (crane_name,handling_date,containers_handled) VALUES ('CraneA','2021-02-01',60),('CraneB','2021-02-02',50),('CraneC','2021-02-03',40),('CraneD','2021-02-04',70);
SELECT MIN(containers_handled) FROM Port_Singapore_Crane_Stats WHERE handling_date >= '2021-02-01' AND handling_date <= '2021-02-28';
What is the maximum salary paid by each factory to a 'senior' worker?
CREATE TABLE factories (factory_id INT,factory_name VARCHAR(20)); INSERT INTO factories VALUES (1,'Factory A'),(2,'Factory B'),(3,'Factory C'); CREATE TABLE roles (role_id INT,role_name VARCHAR(20)); INSERT INTO roles VALUES (1,'junior'),(2,'senior'),(3,'manager'); CREATE TABLE workers (worker_id INT,factory_id INT,role_id INT,salary DECIMAL(5,2)); INSERT INTO workers VALUES (1,1,2,35000.00),(2,1,2,36000.00),(3,2,2,45000.00),(4,3,2,55000.00),(5,3,2,65000.00);
SELECT f.factory_name, MAX(salary) FROM workers w INNER JOIN factories f ON w.factory_id = f.factory_id INNER JOIN roles r ON w.role_id = r.role_id WHERE r.role_name = 'senior' GROUP BY f.factory_name;
What is the average age of vessels with a construction country of 'China'?
CREATE TABLE Vessel_Age (ID INT,Vessel_Name VARCHAR(50),Construction_Country VARCHAR(50),Age INT); INSERT INTO Vessel_Age (ID,Vessel_Name,Construction_Country,Age) VALUES (1,'Vessel1','China',10); INSERT INTO Vessel_Age (ID,Vessel_Name,Construction_Country,Age) VALUES (2,'Vessel2','Japan',8); INSERT INTO Vessel_Age (ID,Vessel_Name,Construction_Country,Age) VALUES (3,'Vessel3','China',12);
SELECT AVG(Age) FROM Vessel_Age WHERE Construction_Country = 'China';
Calculate the average price of vegetarian dishes per category.
CREATE TABLE dishes (id INT,name TEXT,type TEXT,price FLOAT);
SELECT type, AVG(price) FROM dishes WHERE type LIKE '%vegetarian%' GROUP BY type;
List all energy efficiency stats for residential buildings in Texas.
CREATE TABLE energy_efficiency_stats (id INT PRIMARY KEY,building_type VARCHAR(255),building_location VARCHAR(255),energy_star_score INT,energy_consumption_kwh FLOAT);
SELECT * FROM energy_efficiency_stats WHERE building_type = 'Residential' AND building_location = 'Texas';
What is the latest artwork year?
CREATE TABLE artworks (id INT PRIMARY KEY,title VARCHAR(255),artist VARCHAR(255),year INT);
SELECT MAX(year) FROM artworks;
List the number of terbium mines in each country.
CREATE TABLE terbium_mines (country VARCHAR(20),num_mines INT); INSERT INTO terbium_mines (country,num_mines) VALUES ('China',12),('USA',5),('Australia',3);
SELECT country, num_mines FROM terbium_mines;
What is the total water conservation effort (in cubic meters) by each city in 2020?
CREATE TABLE city_water_conservation (city VARCHAR(50),year INT,conservation_volume INT); INSERT INTO city_water_conservation (city,year,conservation_volume) VALUES ('CityA',2019,100),('CityA',2020,200),('CityB',2019,150),('CityB',2020,250);
SELECT city, SUM(conservation_volume) AS total_conservation_volume FROM city_water_conservation WHERE year = 2020 GROUP BY city;
What was the total revenue for the 'Classical Music' genre in 2020?
CREATE TABLE events (event_id INT,genre VARCHAR(20),revenue FLOAT,event_date DATE); INSERT INTO events (event_id,genre,revenue,event_date) VALUES (1,'Classical Music',5000,'2020-01-01'); INSERT INTO events (event_id,genre,revenue,event_date) VALUES (2,'Classical Music',7000,'2020-02-03');
SELECT SUM(revenue) FROM events WHERE genre = 'Classical Music' AND event_date LIKE '2020-%';
What is the trend of community policing events in each neighborhood over time?
CREATE TABLE neighborhoods (neighborhood_id INT,neighborhood_name VARCHAR(255));CREATE TABLE community_policing (event_id INT,event_date DATE,neighborhood_id INT); INSERT INTO neighborhoods VALUES (1,'West Hill'),(2,'East End'); INSERT INTO community_policing VALUES (1,'2020-01-01',1),(2,'2020-02-01',2);
SELECT neighborhood_id, DATE_TRUNC('month', event_date) as month, COUNT(*) as num_events FROM community_policing GROUP BY neighborhood_id, month ORDER BY neighborhood_id, month
How many volunteers participated in each program in the last quarter?
CREATE TABLE Volunteers (id INT,volunteer_name TEXT,program TEXT,participation_date DATE); INSERT INTO Volunteers (id,volunteer_name,program,participation_date) VALUES (1,'Jane Doe','Feeding the Hungry','2022-01-05');
SELECT program, COUNT(*) as num_volunteers FROM Volunteers WHERE participation_date >= DATEADD(quarter, -1, GETDATE()) GROUP BY program;
Delete the 'green_buildings' table
CREATE TABLE green_buildings (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),energy_rating INT);
DROP TABLE green_buildings;
What is the average length of each route in the 'routes' table?
CREATE TABLE routes (route_id INT,route_name VARCHAR(255),length FLOAT,fare FLOAT);
SELECT route_name, AVG(length) as avg_length FROM routes GROUP BY route_name;
What is the average CO2 emission reduction in Latin America between 2015 and 2019?
CREATE TABLE co2_emissions (region VARCHAR(50),year INT,co2_emission_kg INT); INSERT INTO co2_emissions VALUES ('Latin America',2015,1000),('Latin America',2016,900),('Latin America',2017,850),('Latin America',2018,800),('Latin America',2019,750);
SELECT AVG(co2_emission_kg) FROM co2_emissions WHERE region = 'Latin America' AND year BETWEEN 2015 AND 2019;
Calculate the total energy efficiency improvements for each sector in Australia from 2017 to 2021.
CREATE TABLE energy_efficiency (sector VARCHAR(255),year INT,energy_improvement FLOAT); INSERT INTO energy_efficiency (sector,year,energy_improvement) VALUES ('Residential',2017,1.23),('Commercial',2017,2.34),('Industrial',2017,3.45),('Transportation',2017,4.56),('Residential',2021,6.78),('Commercial',2021,7.89),('Industrial',2021,8.90),('Transportation',2021,9.01);
SELECT sector, SUM(energy_improvement) FROM energy_efficiency WHERE year IN (2017, 2021) GROUP BY sector;
What is the percentage of the population in Texas that has received at least one dose of the COVID-19 vaccine?
CREATE TABLE vaccine_doses (patient_id INT,vaccine_name VARCHAR(255),administered_date DATE); INSERT INTO vaccine_doses VALUES (1,'Pfizer-BioNTech','2021-01-01'); INSERT INTO vaccine_doses VALUES (2,'Moderna','2021-01-15'); CREATE TABLE patients (patient_id INT,age INT,state VARCHAR(255)); INSERT INTO patients VALUES (1,35,'Texas'); INSERT INTO patients VALUES (2,42,'Texas'); CREATE TABLE census (state VARCHAR(255),population INT); INSERT INTO census VALUES ('Texas',29527956);
SELECT (COUNT(DISTINCT patients.patient_id) / census.population) * 100 AS percentage FROM patients INNER JOIN vaccine_doses ON patients.patient_id = vaccine_doses.patient_id CROSS JOIN census WHERE patients.state = 'Texas';
What is the earliest concert date for a specific artist in the 'concert_tours' table?
CREATE TABLE concert_tours (concert_id INT,concert_name TEXT,artist_id INT,location TEXT,date DATE);
SELECT MIN(date) FROM concert_tours WHERE artist_id = 1;
What is the number of products and their average price in each category, ranked by average price?
CREATE TABLE products (product_id int,product_category varchar(50),price decimal(5,2));
SELECT product_category, COUNT(*) as num_products, AVG(price) as avg_price, RANK() OVER (ORDER BY AVG(price) DESC) as rank FROM products GROUP BY product_category;
What is the number of new clients acquired each month in 2021?
CREATE TABLE clients (client_id INT,name VARCHAR(50),registration_date DATE); INSERT INTO clients VALUES (1,'John Doe','2021-01-05'),(2,'Jane Smith','2021-02-10'),(3,'Alice Johnson','2021-02-20'),(4,'Bob Williams','2021-03-03');
SELECT DATE_FORMAT(registration_date, '%Y-%m') AS month, COUNT(*) FROM clients WHERE YEAR(registration_date) = 2021 GROUP BY month;
List all autonomous vehicle research studies from '2018' in the 'autonomous_research' view.
CREATE VIEW autonomous_research AS SELECT * FROM research_data WHERE technology = 'autonomous'; INSERT INTO research_data (id,year,title,technology) VALUES (1,2016,'Study A','autonomous'),(2,2017,'Study B','autonomous'),(3,2018,'Study C','autonomous'),(4,2019,'Study D','autonomous');
SELECT * FROM autonomous_research WHERE year = 2018;
What is the total number of public parks and community gardens in 'City 1'?
CREATE TABLE cities (id INT,name VARCHAR(255)); INSERT INTO cities (id,name) VALUES (1,'City 1'),(2,'City 2'); CREATE TABLE parks (id INT,name VARCHAR(255),city_id INT); INSERT INTO parks (id,name,city_id) VALUES (1,'Park 1',1),(2,'Park 2',1),(3,'Park 3',2); CREATE TABLE community_gardens (id INT,name VARCHAR(255),city_id INT); INSERT INTO community_gardens (id,name,city_id) VALUES (1,'Community Garden 1',1),(2,'Community Garden 2',1),(3,'Community Garden 3',2);
SELECT COUNT(*) FROM parks WHERE city_id = (SELECT id FROM cities WHERE name = 'City 1'); SELECT COUNT(*) FROM community_gardens WHERE city_id = (SELECT id FROM cities WHERE name = 'City 1');
Which legal technology tools are most frequently used by region?
CREATE TABLE regions (region_id INT,region_name VARCHAR(255)); CREATE TABLE tool_usage (usage_id INT,region_id INT,tool_name VARCHAR(255));
SELECT region_name, tool_name, COUNT(*) as usage_count FROM regions JOIN tool_usage ON regions.region_id = tool_usage.region_id GROUP BY region_name, tool_name ORDER BY usage_count DESC;
List all museums in Italy with virtual tours and sustainable tourism certifications.
CREATE TABLE Museums (museum_id INT,museum_name VARCHAR(50),country VARCHAR(50),has_virtual_tour BOOLEAN,is_sustainable_tourism_certified BOOLEAN); INSERT INTO Museums (museum_id,museum_name,country,has_virtual_tour,is_sustainable_tourism_certified) VALUES (1,'VirtualUffizi Florence','Italy',true,true),(2,'LeonardoDaVinci Museum Milan','Italy',false,true),(3,'Colosseum Rome','Italy',false,false);
SELECT museum_name FROM Museums WHERE country = 'Italy' AND has_virtual_tour = true AND is_sustainable_tourism_certified = true;
Determine the number of unique garment types present in the 'GarmentSales' table.
CREATE TABLE GarmentSales (garment_type VARCHAR(50)); INSERT INTO GarmentSales (garment_type) VALUES ('T-Shirt'),('Jackets'),('Jeans');
SELECT COUNT(DISTINCT garment_type) FROM GarmentSales;
Update soil pH values for a specific farm
CREATE TABLE SoilTypes (id INT PRIMARY KEY,type VARCHAR(50),pH DECIMAL(3,1),farm_id INT); INSERT INTO SoilTypes (id,type,pH,farm_id) VALUES (1,'Sandy',6.5,1001);
UPDATE SoilTypes SET pH = 6.8 WHERE farm_id = 1001;
What is the minimum playtime in minutes for players who have achieved a rank of Bronze or higher in the game "Space Conquerors"?
CREATE TABLE SpaceConquerorsPlayers (PlayerID INT,PlayerName VARCHAR(50),PlaytimeMinutes INT,Rank VARCHAR(10)); INSERT INTO SpaceConquerorsPlayers VALUES (1,'CharlotteMiller',250,'Bronze'),(2,'JamesJohnson',350,'Bronze'),(3,'SophiaLopez',450,'Silver'),(4,'EthanGonzalez',550,'Gold');
SELECT MIN(PlaytimeMinutes) FROM SpaceConquerorsPlayers WHERE Rank IN ('Bronze', 'Silver', 'Gold', 'Platinum');
Which artists have released the most songs in the R&B genre?
CREATE TABLE ArtistSongData (ArtistID INT,ArtistName VARCHAR(100),Genre VARCHAR(50),SongID INT); INSERT INTO ArtistSongData (ArtistID,ArtistName,Genre,SongID) VALUES (1,'Beyoncé','R&B',1),(2,'Rihanna','R&B',2),(3,'Beyoncé','R&B',3);
SELECT ArtistName, COUNT(*) as SongCount FROM ArtistSongData WHERE Genre = 'R&B' GROUP BY ArtistName ORDER BY SongCount DESC;
Which farmers used organic fertilizers in the last 6 months?
CREATE TABLE farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,location VARCHAR(50)); INSERT INTO farmers (id,name,age,location) VALUES (1,'John Doe',35,'New York'); INSERT INTO farmers (id,name,age,location) VALUES (2,'Jane Smith',40,'Los Angeles'); CREATE TABLE fertilizers (id INT PRIMARY KEY,name VARCHAR(50),used_on DATE,used_by INT,FOREIGN KEY (used_by) REFERENCES farmers(id)); INSERT INTO fertilizers (id,name,used_on,used_by) VALUES (1,'Organic Fertilizer','2022-07-01',2); INSERT INTO fertilizers (id,name,used_on,used_by) VALUES (2,'Chemical Fertilizer','2022-02-01',1);
SELECT farmers.name FROM farmers INNER JOIN fertilizers ON farmers.id = fertilizers.used_by WHERE fertilizers.name = 'Organic Fertilizer' AND fertilizers.used_on >= (CURRENT_DATE - INTERVAL '6 months');
What is the minimum safety score for chemical plants in the midwest region, ordered by safety score?
CREATE TABLE plants (id INT,name TEXT,region TEXT,safety_score INT); INSERT INTO plants (id,name,region,safety_score) VALUES (1,'ChemCo','Midwest',85),(2,'EcoChem','Midwest',92),(3,'GreenChem','Southwest',88);
SELECT MIN(safety_score) AS min_safety_score FROM plants WHERE region = 'Midwest' ORDER BY safety_score;
What is the minimum and maximum price of eco-friendly products in each category?
CREATE TABLE Categories (CategoryID INT,CategoryName VARCHAR(50)); INSERT INTO Categories (CategoryID,CategoryName) VALUES (1,'CategoryA'),(2,'CategoryB'),(3,'CategoryC'); CREATE TABLE EcoFriendlyProducts (ProductID INT,ProductName VARCHAR(50),CategoryID INT,Price DECIMAL(5,2)); INSERT INTO EcoFriendlyProducts (ProductID,ProductName,CategoryID,Price) VALUES (1,'ProductA',1,15.50),(2,'ProductB',1,18.60),(3,'ProductC',2,20.70),(4,'ProductD',2,23.80),(5,'ProductE',3,25.90),(6,'ProductF',3,30.00);
SELECT CategoryName, MIN(Price) as MinPrice, MAX(Price) as MaxPrice FROM Categories c JOIN EcoFriendlyProducts efp ON c.CategoryID = efp.CategoryID GROUP BY CategoryName;
Calculate the average transaction amount for users in the ShariahCompliantTransactions table, grouped by month.
CREATE TABLE ShariahCompliantTransactions (transactionID INT,userID VARCHAR(20),transactionAmount DECIMAL(10,2),transactionDate DATE); INSERT INTO ShariahCompliantTransactions (transactionID,userID,transactionAmount,transactionDate) VALUES (1,'JohnDoe',500.00,'2022-01-01'),(2,'JaneDoe',300.00,'2022-01-02'),(3,'JohnDoe',600.00,'2022-02-01');
SELECT MONTH(transactionDate), AVG(transactionAmount) FROM ShariahCompliantTransactions GROUP BY MONTH(transactionDate);
List all environmental pollution incidents for vessels in the Baltic Sea, sorted by date.
CREATE TABLE environmental_incidents (id INT,vessel_id INT,incident_type VARCHAR(255),incident_date DATE); INSERT INTO environmental_incidents (id,vessel_id,incident_type,incident_date) VALUES (1,8,'Oil spill','2021-08-15'); INSERT INTO environmental_incidents (id,vessel_id,incident_type,incident_date) VALUES (2,9,'Garbage disposal','2021-06-28');
SELECT vessel_id, incident_type, incident_date FROM environmental_incidents WHERE latitude BETWEEN 54 AND 66 AND longitude BETWEEN 10 AND 30 ORDER BY incident_date;
How many esports events were held in Europe and North America, and what is the total prize money awarded in these regions?
CREATE TABLE EsportsEvents (EventID int,EventName varchar(25),Location varchar(20),PrizeMoney decimal(10,2)); INSERT INTO EsportsEvents (EventID,EventName,Location,PrizeMoney) VALUES (1,'Event1','Europe',50000.00); INSERT INTO EsportsEvents (EventID,EventName,Location,PrizeMoney) VALUES (2,'Event2','North America',75000.00);
SELECT SUM(CASE WHEN Location IN ('Europe', 'North America') THEN PrizeMoney ELSE 0 END) AS TotalPrizeMoney, COUNT(CASE WHEN Location IN ('Europe', 'North America') THEN 1 ELSE NULL END) AS EventCount FROM EsportsEvents;
How many glaciers are there in Iceland and Canada?
CREATE TABLE glaciers (country VARCHAR(255),glacier_name VARCHAR(255),count INT);
SELECT COUNT(DISTINCT glacier_name) FROM glaciers WHERE country IN ('Iceland', 'Canada');
What is the minimum production quantity for wells located in the 'North Sea'?
CREATE TABLE wells (id INT,name VARCHAR(255),location VARCHAR(255),production_quantity INT); INSERT INTO wells (id,name,location,production_quantity) VALUES (1,'Well A','North Sea',1000),(2,'Well B','Gulf of Mexico',2000),(3,'Well C','North Sea',1500);
SELECT MIN(production_quantity) FROM wells WHERE location = 'North Sea';
List the top 3 beauty products with the highest consumer preference score in the USA, ordered by the score in descending order.
CREATE TABLE consumer_preferences (product_id INT,preference_score DECIMAL(5,2),country VARCHAR(50)); INSERT INTO consumer_preferences (product_id,preference_score,country) VALUES (1001,4.8,'USA'),(1002,4.5,'USA'),(1003,4.9,'Canada'),(1004,4.7,'USA'),(1005,4.6,'Mexico');
SELECT product_id, preference_score FROM consumer_preferences WHERE country = 'USA' GROUP BY product_id ORDER BY preference_score DESC LIMIT 3;
How many solar panels are installed in California and Texas?
CREATE TABLE solar_panels (id INT,state VARCHAR(255),installed BOOLEAN); INSERT INTO solar_panels (id,state,installed) VALUES (1,'California',true),(2,'Texas',true),(3,'California',true),(4,'Texas',false),(5,'California',false);
SELECT state, COUNT(*) as total_installed FROM solar_panels WHERE installed = true GROUP BY state;
What is the total number of vegetarian dishes offered by each cuisine category?
CREATE TABLE cuisine (cuisine_id INT,cuisine_name VARCHAR(255)); INSERT INTO cuisine (cuisine_id,cuisine_name) VALUES (1,'Italian'),(2,'Mexican'),(3,'Indian'); CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),cuisine_id INT,is_vegetarian BOOLEAN); INSERT INTO dishes (dish_id,dish_name,cuisine_id,is_vegetarian) VALUES (1,'Margherita Pizza',1,true),(2,'Chiles Rellenos',2,false),(3,'Palak Paneer',3,true);
SELECT cuisine_name, COUNT(*) as total_veg_dishes FROM dishes d JOIN cuisine c ON d.cuisine_id = c.cuisine_id WHERE is_vegetarian = true GROUP BY cuisine_name;
List the 'incident_type' and 'location' for incidents that occurred between 2021-01-01 and 2021-06-30
CREATE TABLE incidents (incident_id INT,incident_type VARCHAR(50),location VARCHAR(50),date_time DATETIME);
SELECT incident_type, location FROM incidents WHERE date_time BETWEEN '2021-01-01' AND '2021-06-30';
What is the success rate of economic diversification efforts in Peru and Colombia?
CREATE TABLE success_rates (id INT,effort TEXT,country TEXT,success BOOLEAN); INSERT INTO success_rates (id,effort,country,success) VALUES (1,'Agro-processing','Peru',TRUE),(2,'Textiles','Colombia',FALSE);
SELECT COUNT(*) FILTER (WHERE success = TRUE) * 100.0 / COUNT(*) FROM success_rates WHERE country IN ('Peru', 'Colombia');
What is the total revenue for 'Restaurant E' from sustainable sourced ingredients in the year 2022?
CREATE TABLE revenue (restaurant_id INT,sustainable BOOLEAN,amount DECIMAL(10,2)); INSERT INTO revenue (restaurant_id,sustainable,amount) VALUES (5,true,1200.00),(5,false,800.00),(5,true,1500.00),(5,false,500.00);
SELECT SUM(amount) FROM revenue WHERE restaurant_id = 5 AND sustainable = true;
List all athletes who play basketball
CREATE TABLE sports (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE athletes (id INT PRIMARY KEY,name VARCHAR(255),age INT,sport_id INT,team VARCHAR(255),FOREIGN KEY (sport_id) REFERENCES sports(id)); INSERT INTO sports (id,name) VALUES (1,'Basketball'); INSERT INTO athletes (id,name,age,sport_id,team) VALUES (1,'John Doe',25,1,'Lakers'); INSERT INTO athletes (id,name,age,sport_id,team) VALUES (2,'Jane Smith',28,1,'Knicks');
SELECT athletes.name FROM athletes INNER JOIN sports ON athletes.sport_id = sports.id WHERE sports.name = 'Basketball';
What is the total waste generation by material type in the city of London in 2018?
CREATE TABLE waste_generation (city VARCHAR(20),year INT,material VARCHAR(20),weight FLOAT); INSERT INTO waste_generation (city,year,material,weight) VALUES ('London',2018,'Plastic',1800),('London',2018,'Paper',3000),('London',2018,'Glass',2000);
SELECT material, SUM(weight) as total_weight FROM waste_generation WHERE city = 'London' AND year = 2018 GROUP BY material;
How many community development projects were completed in rural areas in 2019?
CREATE TABLE projects (id INT,location VARCHAR(50),project_type VARCHAR(50),completion_date DATE); INSERT INTO projects (id,location,project_type,completion_date) VALUES (1,'India','community development','2019-05-01'),(2,'Brazil','rural infrastructure','2017-12-31'),(3,'Ghana','community development','2016-08-15'),(4,'India','community development','2018-09-05'),(5,'Tanzania','agricultural innovation','2014-11-23');
SELECT COUNT(*) FROM projects WHERE project_type = 'community development' AND location LIKE 'rural%' AND completion_date BETWEEN '2019-01-01' AND '2019-12-31';
What is the average recycling rate and the number of circular economy initiatives for each location and material, for the year 2021?
CREATE TABLE RecyclingRates (Date date,Location text,Material text,Rate real);CREATE TABLE CircularEconomyInitiatives (Location text,Initiative text,StartDate date);
SELECT rr.Location, rr.Material, AVG(rr.Rate) as AvgRecyclingRate, COUNT(DISTINCT cei.Initiative) as NumberOfInitiatives FROM RecyclingRates rr LEFT JOIN CircularEconomyInitiatives cei ON rr.Location = cei.Location WHERE rr.Date >= '2021-01-01' AND rr.Date < '2022-01-01' GROUP BY rr.Location, rr.Material;
Get the total number of wins for each player in the 'PlayerGames' table
CREATE TABLE PlayerGames (PlayerID INT,GameID INT,GameWon BOOLEAN);
SELECT PlayerID, SUM(GameWon) as TotalWins FROM PlayerGames WHERE GameWon = TRUE GROUP BY PlayerID;
What are the total assets of customers who don't have a savings account?
CREATE TABLE Accounts (CustomerID INT,AccountType VARCHAR(50),Balance DECIMAL(10,2)); INSERT INTO Accounts (CustomerID,AccountType,Balance) VALUES (1,'Savings',10000); INSERT INTO Accounts (CustomerID,AccountType,Balance) VALUES (2,'Checking',5000);
SELECT SUM(Balance) FROM Accounts WHERE AccountType != 'Savings'
How many donations were made in Q2 2021?
CREATE TABLE Donations (DonationID INT,DonorID INT,CauseID INT,Amount DECIMAL(10,2),Quarter INT,Year INT); INSERT INTO Donations (DonationID,DonorID,CauseID,Amount,Quarter,Year) VALUES (1,1,1,1000,2,2021),(2,2,2,1500,2,2021),(3,3,3,1200,2,2021),(4,4,4,1800,2,2021),(5,5,1,800,2,2021);
SELECT COUNT(*) FROM Donations WHERE Quarter = 2 AND Year = 2021;
What was the total donation amount and average donation amount per donor for each program in Q3 2019?
CREATE TABLE Donors (DonorID int,DonorName varchar(50),DonationDate date,DonationAmount decimal(10,2),Program varchar(50)); INSERT INTO Donors (DonorID,DonorName,DonationDate,DonationAmount,Program) VALUES (1,'John Doe','2019-07-02',50.00,'ProgramA'),(2,'Jane Smith','2019-08-15',100.00,'ProgramB'),(3,'Mike Johnson','2019-09-01',75.00,'ProgramA');
SELECT Program, SUM(DonationAmount) as TotalDonationAmount, AVG(DonationAmount) as AverageDonationAmountPerDonor FROM Donors WHERE DonationDate BETWEEN '2019-07-01' AND '2019-09-30' GROUP BY Program;
How many cruelty-free certifications were issued in the first half of 2021?
CREATE TABLE cruelty_free_certification (id INT PRIMARY KEY,product_name VARCHAR(255),certification_date DATE,certified_by VARCHAR(255)); INSERT INTO cruelty_free_certification (id,product_name,certification_date,certified_by) VALUES (1,'Organic Lipstick','2021-01-01','Leaping Bunny');
SELECT COUNT(*) as count FROM cruelty_free_certification WHERE certification_date BETWEEN '2021-01-01' AND '2021-06-30';
Show policy details and the number of claims filed for each policy
CREATE TABLE policies (policy_id INT,policyholder_id INT,policy_start_date DATE,policy_end_date DATE); CREATE TABLE claims_info (claim_id INT,policy_id INT,claim_date DATE); INSERT INTO policies VALUES (1,1,'2020-01-01','2021-01-01'); INSERT INTO policies VALUES (2,2,'2019-01-01','2020-01-01'); INSERT INTO claims_info VALUES (1,1,'2020-01-01'); INSERT INTO claims_info VALUES (2,1,'2020-06-01'); INSERT INTO claims_info VALUES (3,2,'2019-02-01');
SELECT policies.policy_id, policyholder_id, policy_start_date, policy_end_date, COUNT(claim_id) AS num_claims FROM policies INNER JOIN claims_info USING (policy_id) GROUP BY policies.policy_id, policyholder_id, policy_start_date, policy_end_date
What is the average time to complete a safety audit, partitioned by facility and ordered by the longest average times first?
CREATE TABLE safety_audit (audit_id INT,facility_id INT,audit_duration INT); CREATE TABLE facility (facility_id INT,facility_name VARCHAR(255));
SELECT facility_name, facility_id, AVG(audit_duration) AS avg_audit_time FROM safety_audit JOIN facility ON safety_audit.facility_id = facility.facility_id GROUP BY facility_id, facility_name ORDER BY avg_audit_time DESC;
Count the number of concerts where more than 1000 tickets were sold.
CREATE TABLE tickets_sold (concert_id INT,quantity INT); INSERT INTO tickets_sold (concert_id,quantity) VALUES (1,1500);
SELECT COUNT(*) FROM tickets_sold WHERE quantity > 1000;
Who are the top 3 authors with the most articles in the 'media_ethics' table?
CREATE TABLE media_ethics (article_id INT,author VARCHAR(50),title VARCHAR(100),published_date DATE,category VARCHAR(30)); INSERT INTO media_ethics (article_id,author,title,published_date,category) VALUES (1,'John Doe','Article 5','2021-01-05','Ethics'),(2,'Jane Smith','Article 6','2021-01-06','Ethics');
SELECT author, COUNT(article_id) AS total_articles FROM media_ethics GROUP BY author ORDER BY total_articles DESC LIMIT 3;
List all unique locations with readings
temperature_readings
SELECT DISTINCT location FROM temperature_readings;
Show the total number of marine species in the Indian Ocean.
CREATE TABLE marine_species (name TEXT,location TEXT,num_individuals INT); INSERT INTO marine_species (name,location,num_individuals) VALUES ('Clownfish','Indian Ocean','10000'),('Dolphin','Atlantic Ocean','20000');
SELECT SUM(num_individuals) FROM marine_species WHERE location = 'Indian Ocean';
What is the average distance in parsecs for elliptical galaxies?
CREATE TABLE Galaxies (id INT,name VARCHAR(255),type VARCHAR(255),right_ascension VARCHAR(255),declination VARCHAR(255),diameter_ly DECIMAL(10,2),distance_Mpc DECIMAL(10,2),distance_pc DECIMAL(10,2)); INSERT INTO Galaxies (id,name,type,right_ascension,declination,diameter_ly,distance_Mpc,distance_pc) VALUES (7,'Maffei 1','Elliptical','0h 55m 55.0s','59° 40′ 59″',70000,3.56,11600); INSERT INTO Galaxies (id,name,type,right_ascension,declination,diameter_ly,distance_Mpc,distance_pc) VALUES (8,'Maffei 2','Elliptical','0h 55m 12.0s','68° 36′ 59″',110000,4.42,14400);
SELECT type, AVG(distance_pc) as avg_distance_pc FROM Galaxies WHERE type = 'Elliptical' GROUP BY type;
How many hours of news content are produced in Asia per day?
CREATE TABLE content (content_id INT,content_type VARCHAR(20),country VARCHAR(50),hours_produced FLOAT,production_date DATE); INSERT INTO content VALUES (1,'news','India',24,'2022-01-01');
SELECT SUM(hours_produced) FROM content WHERE country IN ('India', 'China', 'Japan') AND content_type = 'news' AND production_date = '2022-01-01';
What is the maximum installed capacity (in MW) for renewable energy projects in 'Europe' region?
CREATE TABLE renewable_energy_projects_europe (id INT,project_name VARCHAR(255),region VARCHAR(255),installed_capacity FLOAT); INSERT INTO renewable_energy_projects_europe (id,project_name,region,installed_capacity) VALUES (1,'Solar Farm A','Europe',50.0),(2,'Wind Farm B','Europe',100.0);
SELECT MAX(installed_capacity) FROM renewable_energy_projects_europe WHERE region = 'Europe';
What is the maximum funding amount received by a company founded by a woman of color in the healthcare industry?
CREATE TABLE Companies (id INT,name TEXT,founders TEXT,industry TEXT); INSERT INTO Companies (id,name,founders,industry) VALUES (1,'HealFast','Female,African American','Healthcare'); INSERT INTO Companies (id,name,founders,industry) VALUES (2,'TechBoost','Asian,Male','Technology'); CREATE TABLE Investment_Rounds (company_id INT,funding_amount INT,round_number INT); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (1,800000,1); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (1,1200000,2); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (2,3000000,1);
SELECT MAX(r.funding_amount) FROM Companies c JOIN Investment_Rounds r ON c.id = r.company_id WHERE c.founders LIKE '%Female%' AND c.founders LIKE '%African American%' AND c.industry = 'Healthcare';
What is the average sea ice extent for each month in the Arctic?
CREATE TABLE arctic_month (month_id INT,month_name VARCHAR(255)); INSERT INTO arctic_month (month_id,month_name) VALUES (1,'January'),(2,'February'),(3,'March'); CREATE TABLE sea_ice (year INT,month_id INT,extent FLOAT); INSERT INTO sea_ice (year,month_id,extent) VALUES (2000,1,14.5),(2000,2,13.2),(2000,3,12.9),(2001,1,15.1),(2001,2,13.6),(2001,3,12.5),(2002,1,14.3),(2002,2,12.8),(2002,3,12.1);
SELECT month_id, AVG(extent) as avg_extent FROM sea_ice GROUP BY month_id;
Update the "conservation_status" column to "Endangered" for all records in the "marine_species" table where the "species_name" is "Blue Whale"
CREATE TABLE marine_species (id INT PRIMARY KEY,species_name VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO marine_species (id,species_name,conservation_status) VALUES (1,'Blue Whale','Vulnerable'); INSERT INTO marine_species (id,species_name,conservation_status) VALUES (2,'Dolphin','Least Concern');
UPDATE marine_species SET conservation_status = 'Endangered' WHERE species_name = 'Blue Whale';
What is the total grant value for grants in the 'AI Safety' domain, grouped by recipient country and filtered for countries with a count of 4 or more grants?
CREATE TABLE ai_research_grants (grant_id INT PRIMARY KEY,grant_name VARCHAR(100),grant_value INT,domain VARCHAR(50),recipient_country VARCHAR(50)); INSERT INTO ai_research_grants (grant_id,grant_name,grant_value,domain,recipient_country) VALUES (1,'AI Safety Research',500000,'AI Safety','Germany'),(2,'AI Fairness Research',600000,'Algorithmic Fairness','USA');
SELECT recipient_country, SUM(grant_value) as total_grant_value FROM ai_research_grants WHERE domain = 'AI Safety' GROUP BY recipient_country HAVING COUNT(*) >= 4;
List all donations made by a specific individual.
CREATE TABLE donations (id INT,donor_name VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO donations (id,donor_name,amount) VALUES (1,'John Doe',50.00),(2,'Jane Smith',75.00),(3,'John Doe',100.00);
SELECT * FROM donations WHERE donor_name = 'John Doe';
Delete fish farming records with no species information?
CREATE TABLE FishFarming (FarmID INT,Location VARCHAR(50),Date DATE,Species VARCHAR(50));
DELETE FROM FishFarming WHERE Species IS NULL;
What is the maximum response time for disaster calls?
CREATE TABLE disaster_calls (call_id INT,call_date DATE,response_time INT); INSERT INTO disaster_calls (call_id,call_date,response_time) VALUES (1,'2022-01-01',30),(2,'2022-02-03',45);
SELECT MAX(response_time) FROM disaster_calls;
Identify the farms with the highest and lowest water temperatures for Salmon.
CREATE TABLE FarmTemperature (FarmID INT,Species VARCHAR(255),WaterTemp FLOAT); INSERT INTO FarmTemperature (FarmID,Species,WaterTemp) VALUES (1,'Salmon',12.3),(2,'Salmon',13.1),(3,'Salmon',11.9),(4,'Salmon',12.8);
SELECT FarmID, WaterTemp FROM FarmTemperature WHERE Species = 'Salmon' AND WaterTemp IN (SELECT MAX(WaterTemp), MIN(WaterTemp) FROM FarmTemperature WHERE Species = 'Salmon');
How many graduate students in the Chemistry department have not published any papers in the year 2020?
CREATE TABLE GraduateStudents (StudentID INT,Name VARCHAR(50),Department VARCHAR(50),Publications INT,PublicationYear INT);
SELECT COUNT(StudentID) FROM GraduateStudents WHERE Department = 'Chemistry' AND Publications = 0 AND PublicationYear = 2020;
What is the total revenue from ads in the last month, broken down by the ad's country of origin?
CREATE TABLE if not exists ad (ad_id int,ad_country varchar(2),start_date date,end_date date,revenue decimal(10,2));
SELECT ad_country, SUM(revenue) as total_revenue FROM ad WHERE start_date <= DATEADD(day, -30, GETDATE()) AND end_date >= DATEADD(day, -30, GETDATE()) GROUP BY ad_country;
What is the total tonnage of construction waste recycled in Australia in 2017?
CREATE TABLE Waste_Management (Waste_ID INT,Waste_Type VARCHAR(50),Tonnage DECIMAL(10,2),Year INT,Country VARCHAR(50));
SELECT SUM(Tonnage) FROM Waste_Management WHERE Waste_Type = 'Construction Waste' AND Year = 2017 AND Country = 'Australia';
What is the percentage of patients with a specific diagnosis code by ethnicity?
CREATE TABLE diagnoses (id INT,patient_id INT,code VARCHAR(10),ethnicity VARCHAR(50)); INSERT INTO diagnoses (id,patient_id,code,ethnicity) VALUES (1,1,'A01','Caucasian'),(2,1,'B01','Caucasian'),(3,2,'A01','African American'),(4,3,'C01','Hispanic');
SELECT ethnicity, code, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM diagnoses WHERE code = 'A01') AS percentage FROM diagnoses WHERE code = 'A01' GROUP BY ethnicity;
What is the total number of electric and autonomous vehicles sold in 'sales_data' view?
CREATE VIEW sales_data AS SELECT id,vehicle_type,avg_speed,sales FROM vehicle_sales WHERE sales > 20000;
SELECT SUM(sales) FROM sales_data WHERE vehicle_type LIKE '%electric%' OR vehicle_type LIKE '%autonomous%';