instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What are the total running times of movies by genre in the Media database? | CREATE TABLE GenreRunningTimes (MovieTitle VARCHAR(50),Genre VARCHAR(50),RunningTime INT); INSERT INTO GenreRunningTimes (MovieTitle,Genre,RunningTime) VALUES ('The Godfather','Crime',175),('The Shawshank Redemption','Drama',142),('The Godfather: Part II','Crime',202),('The Dark Knight','Crime',152),('Star Wars: Episode IV - A New Hope','Sci-Fi',121); | SELECT Genre, SUM(RunningTime) as TotalRunningTime FROM GenreRunningTimes GROUP BY Genre; |
What is the total number of customer complaints for each type of service? | CREATE TABLE customer_complaints (id INT,service VARCHAR(20),complaint_reason VARCHAR(30)); INSERT INTO customer_complaints (id,service,complaint_reason) VALUES (1,'mobile','coverage'),(2,'mobile','data_speed'),(3,'broadband','coverage'),(4,'broadband','data_speed'),(5,'mobile','customer_service'); | SELECT service, COUNT(*) FROM customer_complaints GROUP BY service; |
Who is the oldest female reporter in the 'reporters' table? | CREATE TABLE reporters (id INT,name VARCHAR(50),gender VARCHAR(10),age INT); INSERT INTO reporters (id,name,gender,age) VALUES (1,'Alice','Female',40),(2,'Bob','Male',30); | SELECT name FROM reporters WHERE gender = 'Female' ORDER BY age DESC LIMIT 1; |
What is the percentage of total donations for each program? | CREATE TABLE program (id INT,name VARCHAR(50)); INSERT INTO program (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donation (id INT,amount DECIMAL(10,2),program_id INT); | SELECT d.program_id, (SUM(d.amount) / (SELECT SUM(d2.amount) FROM donation d2)) * 100 as pct_total_donations FROM donation d GROUP BY d.program_id; |
List all underwater volcanoes in the Arctic region with a depth greater than 3000 meters. | CREATE TABLE underwater_volcanoes (id INT,name VARCHAR(255),region VARCHAR(50),depth INT); INSERT INTO underwater_volcanoes (id,name,region,depth) VALUES (1,'Jan Mayen Volcano','Arctic',3200),(2,'Erebus Volcano','Antarctic',3794); | SELECT name FROM underwater_volcanoes WHERE region = 'Arctic' AND depth > 3000; |
Show the number of safety inspections per vessel in the Mediterranean sea. | CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(255),region VARCHAR(255)); CREATE TABLE safety_inspections (inspection_id INT,vessel_id INT,inspection_date DATE); INSERT INTO vessels (vessel_id,vessel_name,region) VALUES (1,'Sea Tiger','Mediterranean'),(2,'Ocean Wanderer','Atlantic'); INSERT INTO safety_inspections (inspection_id,vessel_id,inspection_date) VALUES (1,1,'2022-01-01'),(2,1,'2022-02-01'),(3,2,'2022-03-01'); | SELECT vessels.vessel_name, COUNT(safety_inspections.inspection_id) FROM vessels INNER JOIN safety_inspections ON vessels.vessel_id = safety_inspections.vessel_id WHERE vessels.region = 'Mediterranean' GROUP BY vessels.vessel_name; |
Insert a new donor with donor_id 8, donation amount $5000 in 2022, and gender 'intersex'. | CREATE TABLE donors (donor_id INT,donation_amount DECIMAL(10,2),donation_year INT,gender VARCHAR(255)); | INSERT INTO donors (donor_id, donation_amount, donation_year, gender) VALUES (8, 5000.00, 2022, 'intersex'); |
Count the number of events per game | CREATE TABLE esports_events (event_id INT PRIMARY KEY,name VARCHAR(50),date DATE,game VARCHAR(50),location VARCHAR(50)); | SELECT game, COUNT(*) as event_count FROM esports_events GROUP BY game; |
Find the total hours played by players in a specific game title | CREATE TABLE GameSessions (PlayerID INT,GameTitle VARCHAR(50),HoursPlayed DECIMAL(5,2)); INSERT INTO GameSessions (PlayerID,GameTitle,HoursPlayed) VALUES (1,'GameA',10.5),(2,'GameA',5.3),(3,'GameB',7.2); | SELECT SUM(HoursPlayed) FROM GameSessions WHERE GameTitle = 'GameA'; |
What is the average total spending by players from North America in the 'gaming_facts' table? | CREATE TABLE gaming_facts (player_id INT,country VARCHAR(50),total_spending FLOAT); INSERT INTO gaming_facts (player_id,country,total_spending) VALUES (1,'USA',450.25),(2,'Canada',520.35),(3,'Mexico',399.83),(4,'China',420.65),(5,'Japan',375.89); | SELECT AVG(total_spending) as avg_north_america_spending FROM gaming_facts WHERE country IN ('USA', 'Canada', 'Mexico'); |
What is the average citizen feedback score for public libraries in the state of Illinois and Michigan? | CREATE TABLE Feedback (library VARCHAR(50),state VARCHAR(20),score INT); INSERT INTO Feedback (library,state,score) VALUES ('LibraryA','Illinois',8),('LibraryB','Illinois',9),('LibraryC','Michigan',7); | SELECT AVG(score) FROM Feedback WHERE state IN ('Illinois', 'Michigan') AND library LIKE '%Library%'; |
How many distinct suppliers provided Dysprosium in 2018? | CREATE TABLE supply_data (year INT,element VARCHAR(10),supplier VARCHAR(20)); INSERT INTO supply_data VALUES (2015,'Dysprosium','Supplier A'),(2016,'Dysprosium','Supplier B'),(2017,'Dysprosium','Supplier C'),(2018,'Dysprosium','Supplier D'),(2018,'Dysprosium','Supplier E'); | SELECT COUNT(DISTINCT supplier) FROM supply_data WHERE year = 2018 AND element = 'Dysprosium'; |
What's the total number of properties in each city with inclusive housing policies? | CREATE TABLE properties (property_id INT,price DECIMAL(10,2),size INT,city VARCHAR(50),inclusive_policy BOOLEAN); INSERT INTO properties (property_id,price,size,city,inclusive_policy) VALUES (1,500000,2000,'Oakland',true),(2,600000,2500,'San Francisco',false),(3,450000,1000,'Oakland',true); | SELECT city, COUNT(*) FROM properties WHERE inclusive_policy = true GROUP BY city; |
What is the total installed capacity of wind farms in the state of 'California'? | CREATE TABLE wind_farms (id INT,name VARCHAR(50),state VARCHAR(50),capacity FLOAT); INSERT INTO wind_farms (id,name,state,capacity) VALUES (1,'Wind Farm A','California',150.5),(2,'Wind Farm B','Texas',200.0); | SELECT SUM(capacity) FROM wind_farms WHERE state = 'California'; |
Display the product names and supplier names for products that are not supplied by 'Green Cotton Inc.'. | CREATE TABLE products (id INT,name VARCHAR(50),price DECIMAL(5,2),supplier_id INT); INSERT INTO products (id,name,price,supplier_id) VALUES (1,'Organic Cotton Shirt',29.99,1),(2,'Hemp Tote Bag',19.99,2),(3,'Recycled Sweater',39.99,3),(4,'Bamboo T-Shirt',24.99,1),(5,'Eco-Leather Jacket',89.99,4); CREATE TABLE suppliers (id INT,name VARCHAR(50),country VARCHAR(50),sustainability_rating INT); INSERT INTO suppliers (id,name,country,sustainability_rating) VALUES (1,'Green Cotton Inc.','India',90),(2,'Happy Hemp Farms','Nepal',95),(3,'Eco Rubber Co.','Malaysia',85),(4,'Bamboo Textiles','China',80); | SELECT p.name, s.name FROM products p JOIN suppliers s ON p.supplier_id = s.id WHERE p.supplier_id != 1; |
List the suppliers that provide materials for both product A and product C. | CREATE TABLE products (product_id INT,product_name TEXT); CREATE TABLE materials (material_id INT,material_name TEXT,product_id INT,supplier_id INT); INSERT INTO products (product_id,product_name) VALUES (1,'Product A'),(2,'Product B'),(3,'Product C'); INSERT INTO materials (material_id,material_name,product_id,supplier_id) VALUES (1,'Material 1',1,101),(2,'Material 2',1,102),(3,'Material 3',2,103),(4,'Material 4',3,101),(5,'Material 5',3,102); | SELECT supplier_id FROM materials WHERE product_id = 1 INTERSECT SELECT supplier_id FROM materials WHERE product_id = 3; |
Add the name 'Hubble Space Telescope' to the satellites table | CREATE TABLE satellites (id INT,name VARCHAR(255),international_designator VARCHAR(20)); INSERT INTO satellites (id,name,international_designator) VALUES (1,'Spitzer Space Telescope','979F'); | INSERT INTO satellites (name) VALUES ('Hubble Space Telescope'); |
Find the total mass of all space debris in Geostationary Orbit (GSO) that originate from defunct satellites. | CREATE TABLE gso_debris (id INT,name VARCHAR(50),type VARCHAR(50),orbit VARCHAR(50),mass FLOAT,source VARCHAR(50)); INSERT INTO gso_debris (id,name,type,orbit,mass,source) VALUES (1,'Debris1','Panel','GSO',50.3,'Defunct Satellite'),(2,'Debris2','Bolt','GSO',0.05,'Rocket Body'),(3,'Debris3','Rod','GSO',2.8,'Defunct Satellite'); | SELECT SUM(mass) FROM gso_debris WHERE orbit = 'GSO' AND source = 'Defunct Satellite'; |
What is the maximum cost of a rover mission? | CREATE TABLE rover_missions (id INT,name VARCHAR(50),cost INT); INSERT INTO rover_missions (id,name,cost) VALUES (1,'Mars Rover 2001',5000000),(2,'Moon Rover 2020',10000000),(3,'Titan Rover 2030',20000000); | SELECT name, MAX(cost) as max_cost FROM rover_missions WHERE name LIKE '%Rover%'; |
What is the total cost of all space missions? | CREATE TABLE space_missions (id INT,mission_name VARCHAR(255),country VARCHAR(255),cost FLOAT); INSERT INTO space_missions (id,mission_name,country,cost) VALUES (1,'Apollo 11','USA',25500000),(2,'Mars Orbiter Mission','India',73000000),(3,'Chandrayaan-1','India',79000000),(4,'Grail','USA',496000000); | SELECT SUM(cost) FROM space_missions; |
Which countries are the source of unsuccessful login attempts on system S009, and what are their respective counts? | CREATE TABLE unsuccessful_logins (id INT,login_country VARCHAR(20),system_target VARCHAR(5)); INSERT INTO unsuccessful_logins (id,login_country,system_target) VALUES (1,'France','S009'),(2,'Brazil','S009'),(3,'India','S010'),(4,'Australia','S009'),(5,'USA','S009'); | SELECT login_country, COUNT(*) as count FROM unsuccessful_logins WHERE system_target = 'S009' GROUP BY login_country; |
What is the minimum distance traveled by autonomous vehicles in the 'autonomous_vehicles' table, grouped by their 'vehicle_type'? | CREATE TABLE autonomous_vehicles (id INT,vehicle_type VARCHAR(255),manufacturer VARCHAR(255),distance_traveled INT); | SELECT vehicle_type, MIN(distance_traveled) FROM autonomous_vehicles GROUP BY vehicle_type; |
What is the total quantity of garments sold in each country in 2022? | CREATE TABLE sales_country (sale_id INT,country VARCHAR(50),sale_date DATE,total_quantity INT); | SELECT country, SUM(total_quantity) FROM sales_country WHERE sale_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY country; |
What is the total quantity of garments sold per category for the current year? | CREATE TABLE garment_sales_data(sale_id INT,garment_id INT,sale_date DATE,category VARCHAR(255),quantity INT,price FLOAT); INSERT INTO garment_sales_data(sale_id,garment_id,sale_date,category,quantity,price) VALUES (1,1,'2022-03-01','Tops',4,20),(2,2,'2022-04-15','Bottoms',6,30),(3,3,'2022-05-05','Outerwear',8,45); | SELECT category, SUM(quantity) FROM garment_sales_data WHERE YEAR(sale_date) = YEAR(CURRENT_DATE) GROUP BY category; |
Select the average age of policyholders | CREATE TABLE Policyholders (PolicyholderID INT,Age INT,Gender VARCHAR(10)); INSERT INTO Policyholders (PolicyholderID,Age,Gender) VALUES (1,34,'Female'),(2,45,'Male'),(3,52,'Male'); | SELECT AVG(Age) FROM Policyholders; |
How many vessels are in the 'vessels' table? | CREATE TABLE vessels (id INT,name TEXT,type TEXT); INSERT INTO vessels (id,name,type) VALUES (1,'Cargo Ship 1','Cargo'),(2,'Tanker 1','Tanker'); | SELECT COUNT(*) FROM vessels; |
Update recycling_rates table, setting the recycling_rate to 55 where the region is 'EU' | CREATE TABLE recycling_rates (region VARCHAR(50),recycling_rate INT); INSERT INTO recycling_rates (region,recycling_rate) VALUES ('Asia',45),('EU',50); | UPDATE recycling_rates SET recycling_rate = 55 WHERE region = 'EU'; |
What is the recycling rate of plastic in the residential sector in the state of New York? | CREATE TABLE recycling_rates_city (sector VARCHAR(20),city VARCHAR(20),material VARCHAR(20),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates_city (sector,city,material,recycling_rate) VALUES ('residential','New York City','plastic',0.25),('commercial','New York City','plastic',0.30),('residential','New York City','paper',0.45),('commercial','New York City','paper',0.50),('residential','Los Angeles','plastic',0.20),('commercial','Los Angeles','plastic',0.35),('residential','Los Angeles','paper',0.40),('commercial','Los Angeles','paper',0.50); | SELECT recycling_rate FROM recycling_rates_city WHERE sector = 'residential' AND material = 'plastic' AND city = 'New York City'; |
Calculate the average daily water usage in cubic meters for each city in the 'water_usage' table | CREATE TABLE water_usage (city VARCHAR(50),water_usage FLOAT,meter_type VARCHAR(50),date DATE); | SELECT city, AVG(water_usage) as avg_daily_water_usage FROM water_usage GROUP BY city; |
What is the average water consumption for wastewater treatment plants in Texas from 2017 to 2019? | CREATE TABLE wastewater_plants (id INT,state_id INT,year INT,water_consumption FLOAT); INSERT INTO wastewater_plants (id,state_id,year,water_consumption) VALUES (1,1,2017,200),(2,1,2018,220),(3,1,2019,250),(4,2,2017,150),(5,2,2018,170),(6,2,2019,190),(7,3,2017,280),(8,3,2018,300),(9,3,2019,320); | SELECT AVG(water_consumption) FROM wastewater_plants WHERE state_id = 1 AND year BETWEEN 2017 AND 2019; |
Which regions had a precipitation amount higher than 850 in the years they experienced droughts? | CREATE TABLE precipitation (region VARCHAR(255),year INT,precipitation_amount INT); INSERT INTO precipitation (region,year,precipitation_amount) VALUES ('North',2018,800),('North',2019,850),('North',2020,900),('South',2018,750),('South',2019,700),('South',2020,720); CREATE TABLE drought_info (region VARCHAR(255),year INT,severity INT); INSERT INTO drought_info (region,year,severity) VALUES ('North',2018,3),('North',2019,5),('South',2018,2),('South',2019,4); | SELECT p.region FROM precipitation p JOIN drought_info d ON p.region = d.region WHERE p.precipitation_amount > 850 AND d.year = p.year AND d.severity > 0; |
List the top 3 countries with the highest total calories burned in workouts. | CREATE TABLE workouts (id INT,user_id INT,workout_date DATE,calories INT,country VARCHAR(50)); INSERT INTO workouts (id,user_id,workout_date,calories,country) VALUES (1,123,'2022-01-01',300,'USA'); INSERT INTO workouts (id,user_id,workout_date,calories,country) VALUES (2,456,'2022-01-02',400,'Canada'); | SELECT country, SUM(calories) AS total_calories FROM workouts GROUP BY country ORDER BY total_calories DESC LIMIT 3; |
What is the average heart rate for each user during spin classes? | CREATE TABLE workouts (id INT,user_id INT,workout_type VARCHAR(20),heart_rate INT); INSERT INTO workouts (id,user_id,workout_type,heart_rate) VALUES (1,101,'Spin',120),(2,102,'Spin',145),(3,103,'Spin',130),(4,104,'Yoga',85); | SELECT user_id, AVG(heart_rate) as avg_heart_rate FROM workouts WHERE workout_type = 'Spin' GROUP BY user_id; |
List all the agricultural innovation projects in Central America that have received funding from both the World Bank and the Inter-American Development Bank. | CREATE TABLE AgriculturalInnovations (id INT,project_name TEXT,location TEXT,funder TEXT); INSERT INTO AgriculturalInnovations (id,project_name,location,funder) VALUES (1,'AgriTech Central America','Central America','World Bank'); INSERT INTO AgriculturalInnovations (id,project_name,location,funder) VALUES (2,'Smart Farm Central America','Central America','Inter-American Development Bank'); INSERT INTO AgriculturalInnovations (id,project_name,location,funder) VALUES (3,'Farm Innovation Central America','Central America','Government of Central America'); | SELECT project_name, location FROM AgriculturalInnovations WHERE funder IN ('World Bank', 'Inter-American Development Bank') AND location = 'Central America' GROUP BY project_name HAVING COUNT(DISTINCT funder) = 2; |
What is the average water temperature for marine finfish farms in Norway during June? | CREATE TABLE marinefinfish (country VARCHAR(20),month INTEGER,avg_temp FLOAT); INSERT INTO marinefinfish (country,month,avg_temp) VALUES ('Norway',6,12.3),('Norway',6,11.9),('Norway',7,13.1); | SELECT AVG(avg_temp) FROM marinefinfish WHERE country = 'Norway' AND month = 6; |
What is the maximum water temperature for aquatic farms in the 'South China Sea' region? | CREATE TABLE aquatic_farms (id INT,name TEXT,region TEXT); INSERT INTO aquatic_farms (id,name,region) VALUES (1,'Farm D','South China Sea'),(2,'Farm E','Mediterranean Sea'),(3,'Farm F','South China Sea'); CREATE TABLE temperature_readings (id INT,farm_id INT,temperature FLOAT); INSERT INTO temperature_readings (id,farm_id,temperature) VALUES (1,1,29.5),(2,1,29.6),(3,2,18.2); | SELECT MAX(temperature_readings.temperature) FROM temperature_readings INNER JOIN aquatic_farms ON temperature_readings.farm_id = aquatic_farms.id WHERE aquatic_farms.region = 'South China Sea'; |
What is the percentage of organic certified fish farms in the Mediterranean in 2021? | CREATE TABLE fish_farms (farm_id INT,region VARCHAR(50),certification_status VARCHAR(50),year INT); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM fish_farms WHERE year = 2021)) as percentage FROM fish_farms WHERE region = 'Mediterranean' AND certification_status = 'organic' AND year = 2021; |
How many artworks were created by artists from each country, joined with the "artworks" and "artists" tables, between 2010 and 2021? | CREATE TABLE artworks (artwork_id INT,artwork_name VARCHAR(50),artist_id INT,artwork_year INT); CREATE TABLE artists (artist_id INT,artist_name VARCHAR(50),country VARCHAR(50)); | SELECT a.country, COUNT(DISTINCT aw.artwork_id) as total_artworks FROM artworks aw INNER JOIN artists a ON aw.artist_id = a.artist_id WHERE aw.artwork_year BETWEEN 2010 AND 2021 GROUP BY a.country; |
What is the percentage of attendees at 'Family Day' events who are children under 12? | CREATE TABLE AgeDistribution (event_name VARCHAR(50),attendee_age INT,age_distribution_children BOOLEAN); INSERT INTO AgeDistribution (event_name,attendee_age,age_distribution_children) VALUES ('Family Day',5,TRUE); INSERT INTO AgeDistribution (event_name,attendee_age,age_distribution_children) VALUES ('Family Day',35,FALSE); INSERT INTO AgeDistribution (event_name,attendee_age,age_distribution_children) VALUES ('Family Day',7,TRUE); INSERT INTO AgeDistribution (event_name,attendee_age,age_distribution_children) VALUES ('Family Day',12,FALSE); | SELECT attendee_age, age_distribution_children, age_distribution_children * 100.0 / SUM(age_distribution_children) OVER() AS percentage FROM AgeDistribution WHERE event_name = 'Family Day' AND attendee_age < 12; |
What was the total donation amount by returning donors in Q1 2022? | CREATE TABLE Donors (DonorID int,DonationDate date,DonationAmount numeric); INSERT INTO Donors VALUES (1,'2022-01-01',50),(2,'2022-02-01',100),(3,'2022-03-01',200),(1,'2022-02-01',150),(4,'2022-01-01',200); | SELECT SUM(DonationAmount) FROM (SELECT DonationAmount FROM Donors WHERE DonorID IN (SELECT DonorID FROM Donors GROUP BY DonorID HAVING COUNT(*) > 1) AND EXTRACT(MONTH FROM DonationDate) BETWEEN 1 AND 3 AND EXTRACT(YEAR FROM DonationDate) = 2022) |
How has user viewership of movies and TV shows changed over time? | CREATE TABLE MovieWatchHistory (UserId INT,WatchTime DATETIME,MediaType VARCHAR(50),MediaId INT); INSERT INTO MovieWatchHistory (UserId,WatchTime,MediaType,MediaId) VALUES (1,'2021-05-01 15:00:00','Movie',1),(2,'2021-05-02 10:00:00','TVShow',2),(3,'2021-05-03 18:00:00','Movie',3); | SELECT DATEPART(YEAR, WatchTime) AS Year, DATEPART(MONTH, WatchTime) AS Month, MediaType, COUNT(*) AS WatchCount FROM MovieWatchHistory GROUP BY Year, Month, MediaType; |
What is the average 'adaptation fund' spent by 'India' per 'month' in the 'adaptation' table? | CREATE TABLE adaptation (country VARCHAR(255),fund DECIMAL(10,2),date DATE); | SELECT AVG(fund) FROM adaptation WHERE country = 'India' GROUP BY EXTRACT(MONTH FROM date); |
What is the total number of climate communication campaigns launched in Africa since 2010? | CREATE TABLE climate_communication (id INT,campaign VARCHAR(255),location VARCHAR(255),launch_year INT); | SELECT SUM(*) FROM climate_communication WHERE location LIKE '%Africa%' AND launch_year >= 2010; |
Which healthcare facilities offer mental health services in City D? | CREATE TABLE Facilities (ID INT,Name TEXT,Location TEXT,Services TEXT); INSERT INTO Facilities (ID,Name,Location,Services) VALUES (1,'Hospital W','City D','General,Mental Health'); INSERT INTO Facilities (ID,Name,Location,Services) VALUES (2,'Clinic V','City D','Pediatrics'); | SELECT DISTINCT Name FROM Facilities WHERE Location = 'City D' AND Services LIKE '%Mental Health%'; |
What is the total funding amount received by companies founded by LGBTQ+ entrepreneurs in the transportation industry? | CREATE TABLE Companies (id INT,name TEXT,founders TEXT,industry TEXT); INSERT INTO Companies (id,name,founders,industry) VALUES (1,'MoveFast','LGBTQ+,Male','Transportation'); 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,1000000,1); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (1,1500000,2); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (2,3000000,1); | SELECT SUM(r.funding_amount) FROM Companies c JOIN Investment_Rounds r ON c.id = r.company_id WHERE c.founders LIKE '%LGBTQ+%' AND c.industry = 'Transportation'; |
What is the minimum conservation status score of marine species in the Atlantic Ocean? | CREATE TABLE conservation_status_scores (id INT,species_id INT,score FLOAT,location TEXT,PRIMARY KEY (id,species_id),FOREIGN KEY (species_id) REFERENCES marine_species(id)); INSERT INTO conservation_status_scores (id,species_id,score,location) VALUES (1,1,60.0,'Atlantic Ocean'),(2,2,85.0,'Pacific Ocean'),(3,3,35.0,'Indian Ocean'); | SELECT MIN(score) FROM conservation_status_scores WHERE location = 'Atlantic Ocean'; |
how many tree species are there in each continent? | CREATE TABLE trees (id INT,species VARCHAR(255),continent VARCHAR(255)); | SELECT continent, COUNT(DISTINCT species) as num_species FROM trees GROUP BY continent; |
What is the total revenue of skincare products from the natural cosmetics line? | CREATE TABLE Natural_Cosmetics (product_id INT,product_name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2),revenue DECIMAL(10,2)); INSERT INTO Natural_Cosmetics (product_id,product_name,category,price,revenue) VALUES (1,'Skincare 1','Skincare',19.99,0),(2,'Skincare 2','Skincare',29.99,0),(3,'Skincare 3','Skincare',39.99,0); | SELECT SUM(revenue) FROM Natural_Cosmetics WHERE category = 'Skincare'; |
What percentage of products are rated 5 stars in Spain? | CREATE TABLE Products (ProductID INT,ProductName VARCHAR(100),Rating INT); INSERT INTO Products (ProductID,ProductName,Rating) VALUES (1,'Product A',5),(2,'Product B',3),(3,'Product C',4),(4,'Product D',5),(5,'Product E',2); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM Products WHERE Country = 'Spain') FROM Products WHERE Country = 'Spain' AND Rating = 5; |
Insert a new record with an incident_type of 'theft', location of '123 Main St', and occurred_on date of '2022-10-15' into the 'incidents' table | CREATE TABLE incidents (id INT,incident_type VARCHAR(255),location VARCHAR(255),occurred_on DATE); | INSERT INTO incidents (incident_type, location, occurred_on) VALUES ('theft', '123 Main St', '2022-10-15'); |
What is the average emergency response time by region for fire incidents? | CREATE TABLE Regions (RegionID INT,RegionName VARCHAR(255)); CREATE TABLE Incidents (IncidentID INT,IncidentType VARCHAR(255),RegionID INT,ResponseTime INT); | SELECT AVG(ResponseTime) as AvgResponseTime, RegionName FROM Incidents i JOIN Regions r ON i.RegionID = r.RegionID WHERE IncidentType = 'Fire' GROUP BY RegionName; |
What was the average response time for emergency calls in the 'downtown' precinct for the month of July 2021? | CREATE TABLE emergency_calls (id INT,precinct VARCHAR(20),response_time INT,call_date DATE); INSERT INTO emergency_calls (id,precinct,response_time,call_date) VALUES (1,'downtown',12,'2021-07-01'); | SELECT AVG(response_time) FROM emergency_calls WHERE precinct = 'downtown' AND call_date BETWEEN '2021-07-01' AND '2021-07-31'; |
Calculate the number of military equipment maintenance records for each month | CREATE TABLE monthly_maintenance (id INT,equipment_type VARCHAR(255),maintenance_date DATE); | SELECT YEAR(maintenance_date), MONTH(maintenance_date), COUNT(*) FROM monthly_maintenance GROUP BY YEAR(maintenance_date), MONTH(maintenance_date); |
Add new military equipment to 'military_equipment' table | CREATE TABLE military_equipment (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255)); INSERT INTO military_equipment (id,name,type,country) VALUES (1,'M1 Abrams','Tank','USA'); | INSERT INTO military_equipment (id, name, type, country) VALUES (2, 'Leopard 2', 'Tank', 'Germany'); |
What is the total number of peacekeeping personnel contributed by each country in the 'peacekeeping_personnel' and 'countries' tables? | CREATE TABLE countries (country_id INT,country_name VARCHAR(50)); CREATE TABLE peacekeeping_personnel (personnel_id INT,personnel_count INT,country_id INT); INSERT INTO countries VALUES (1,'USA'),(2,'China'),(3,'India'); INSERT INTO peacekeeping_personnel VALUES (1,500,1),(2,800,2),(3,1000,3); | SELECT c.country_name, SUM(pp.personnel_count) as total_personnel FROM countries c JOIN peacekeeping_personnel pp ON c.country_id = pp.country_id GROUP BY c.country_name; |
Get the details of vessels that departed from the Port of New York between June 15 and June 30, 2019. | CREATE TABLE vessel (vessel_name VARCHAR(255),vessel_type VARCHAR(255),departed_date DATE); INSERT INTO vessel VALUES ('Container Ship','New York','2019-06-16'); INSERT INTO vessel VALUES ('Bulk Carrier','New York','2019-06-30'); CREATE TABLE port (port_name VARCHAR(255)); INSERT INTO port VALUES ('New York'); | SELECT v.vessel_name, v.vessel_type, v.departed_date, p.port_name FROM vessel v INNER JOIN port p ON v.port_id = p.id WHERE p.port_name = 'New York' AND v.departed_date BETWEEN '2019-06-15' AND '2019-06-30'; |
Which suppliers in the 'EthicalManufacturing' table have not been updated in the past year? | CREATE TABLE EthicalManufacturing (SupplierID INT,LastUpdate DATETIME); | SELECT SupplierID FROM EthicalManufacturing WHERE LastUpdate < DATEADD(year, -1, GETDATE()); |
Find sites in 'european_sites' with more than 15 artifacts | CREATE TABLE european_sites (id INT,site_name VARCHAR(50),artifact_name VARCHAR(50)); | SELECT site_name FROM european_sites GROUP BY site_name HAVING COUNT(artifact_name) > 15; |
Identify counties in New Mexico with increasing healthcare costs over the past 4 years. | CREATE TABLE costs (county_id INT,year INT,cost INT); | SELECT county_id, COUNT(*) AS years FROM costs WHERE costs[ROW_NUMBER() OVER (PARTITION BY county_id ORDER BY year) - 1] < cost GROUP BY county_id HAVING COUNT(*) = 4 AND county_id IN (SELECT county_id FROM costs WHERE state = 'New Mexico'); |
List all cybersecurity strategies in the strategies table that were implemented in the year 2018. | CREATE TABLE strategies (name TEXT,description TEXT,year INT); INSERT INTO strategies (name,description,year) VALUES ('Intrusion Detection Systems','Monitor network traffic for suspicious activity.',2018),('Multi-Factor Authentication','Require users to provide multiple forms of authentication.',2016),('Penetration Testing','Test systems for vulnerabilities.',2019); | SELECT name FROM strategies WHERE year = 2018; |
What was the total amount donated in each region, along with the corresponding number of donors, in the year 2021? | CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonorRegion TEXT,DonationAmount FLOAT); INSERT INTO Donors (DonorID,DonorName,DonorRegion,DonationAmount) VALUES (1,'John Doe','North',5000.00),(2,'Jane Smith','South',3500.00); | SELECT DonorRegion, SUM(DonationAmount) as TotalDonated, COUNT(DISTINCT DonorID) as DonorCount FROM Donors WHERE YEAR(DonationDate) = 2021 GROUP BY DonorRegion; |
What is the average lifelong learning progress for students in each school? | CREATE TABLE lifelong_learning (student_id INT,school_id INT,progress INT); INSERT INTO lifelong_learning (student_id,school_id,progress) VALUES (1,100,25),(2,100,50),(3,101,75),(4,101,100); CREATE TABLE schools (school_id INT,name VARCHAR(20)); INSERT INTO schools (school_id,name) VALUES (100,'Maple'),(101,'Oak'); | SELECT s.school_id, s.name, AVG(ll.progress) as avg_progress FROM lifelong_learning ll JOIN schools s ON ll.school_id = s.school_id GROUP BY s.school_id, s.name; |
How many hours of diversity and inclusion training have been completed by employees in the 'IT' department? | CREATE TABLE Training (Employee_ID INT,Training_Type VARCHAR(50),Hours_Spent DECIMAL(5,2)); INSERT INTO Training (Employee_ID,Training_Type,Hours_Spent) VALUES (1,'Technical Skills',10.00),(1,'Leadership',5.00),(2,'Diversity and Inclusion',6.00),(3,'Technical Skills',8.00),(4,'Diversity and Inclusion',4.00),(4,'Cybersecurity',7.00); | SELECT SUM(Hours_Spent) FROM Training WHERE Employee_ID IN (SELECT Employee_ID FROM Employee WHERE Department = 'IT') AND Training_Type = 'Diversity and Inclusion'; |
How many wells are there in the 'offshore' category with a production quantity greater than 1500? | CREATE TABLE wells (id INT,name VARCHAR(255),category VARCHAR(255),production_quantity INT); INSERT INTO wells (id,name,category,production_quantity) VALUES (1,'Well A','onshore',1000),(2,'Well B','offshore',2000),(3,'Well C','onshore',1500),(4,'Well D','offshore',2500); | SELECT COUNT(*) FROM wells WHERE category = 'offshore' AND production_quantity > 1500; |
List the wells with daily production rate greater than 125 | CREATE TABLE wells (id INT,well_name VARCHAR(255),location VARCHAR(255),drill_year INT,company VARCHAR(255),daily_production_rate DECIMAL(5,2)); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (1,'Well001','Texas',2020,'CompanyA',100.50); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (2,'Well002','Colorado',2019,'CompanyB',150.25); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (3,'Well003','California',2019,'CompanyC',200.00); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (4,'Well004','Oklahoma',2018,'CompanyD',175.25); | SELECT * FROM wells WHERE daily_production_rate > 125; |
How many yellow cards were given to 'Bayern Munich' players in the 'Champions League'? | CREATE TABLE teams (team_id INT,name TEXT); INSERT INTO teams (team_id,name) VALUES (1,'Bayern Munich'),(2,'Manchester United'); CREATE TABLE yellow_cards (card_id INT,team_id INT,cards INT); INSERT INTO yellow_cards (card_id,team_id,cards) VALUES (1,1,3),(2,1,2),(3,2,1); CREATE TABLE games (game_id INT,team_id INT,tournament TEXT); INSERT INTO games (game_id,team_id,tournament) VALUES (1,1,'Champions League'),(2,1,'Champions League'),(3,2,'Champions League'); | SELECT SUM(cards) FROM yellow_cards JOIN games ON yellow_cards.team_id = games.team_id WHERE games.tournament = 'Champions League' AND yellow_cards.team_id = 1; |
Which basketball players in the 'ncaa_players' table are taller than 7 feet? | CREATE TABLE ncaa_players (player_id INT,player_name VARCHAR(50),height INT,position VARCHAR(20),team_name VARCHAR(50)); | SELECT player_name FROM ncaa_players WHERE height > 96; |
What is the average number of refugees helped per disaster in each country? | CREATE TABLE disasters (disaster_id INT,country VARCHAR(50),refugees_helped INT); INSERT INTO disasters (disaster_id,country,refugees_helped) VALUES (1,'Country A',300),(2,'Country B',500),(3,'Country C',250),(4,'Country A',400),(5,'Country C',350),(6,'Country B',600); | SELECT country, AVG(refugees_helped) AS avg_refugees_per_disaster FROM disasters GROUP BY country |
What was the total amount spent on 'food aid' and 'water aid' in 2018? | CREATE TABLE expenses (id INT,category TEXT,year INT,amount FLOAT); INSERT INTO expenses (id,category,year,amount) VALUES (1,'Food Aid',2018,5000.00); INSERT INTO expenses (id,category,year,amount) VALUES (2,'Water Aid',2018,3000.00); INSERT INTO expenses (id,category,year,amount) VALUES (3,'Clothing',2019,4000.00); | SELECT SUM(amount) FROM expenses WHERE (category = 'Food Aid' OR category = 'Water Aid') AND year = 2018; |
List all unique bus stops and their respective routes in the 'madrid' schema. | CREATE TABLE madrid.bus_stops (id INT,stop_name VARCHAR); CREATE TABLE madrid.stop_routes (id INT,stop_id INT,route_number INT); | SELECT DISTINCT madrid.bus_stops.stop_name, madrid.stop_routes.route_number FROM madrid.bus_stops INNER JOIN madrid.stop_routes ON madrid.bus_stops.id = madrid.stop_routes.stop_id; |
What is the average daily fare collection for the light rail line in the city of Los Angeles? | CREATE TABLE light_rail_lines (line_id INT,line_name VARCHAR(255),city VARCHAR(255)); INSERT INTO light_rail_lines (line_id,line_name,city) VALUES (1,'Line 1','Los Angeles'),(2,'Line 2','Los Angeles'); CREATE TABLE light_rail_fares (fare_id INT,line_id INT,fare_amount DECIMAL(5,2),fare_date DATE); INSERT INTO light_rail_fares (fare_id,line_id,fare_amount,fare_date) VALUES (1,1,2.00,'2022-01-01'),(2,1,2.00,'2022-01-02'),(3,2,3.00,'2022-01-01'),(4,2,3.00,'2022-01-02'); | SELECT AVG(lrf.fare_amount) FROM light_rail_fares lrf JOIN light_rail_lines lrl ON lrf.line_id = lrl.line_id WHERE lrl.city = 'Los Angeles'; |
What is the average distance covered by route type 'Light Rail'? | CREATE TABLE routes (id INT,route_name VARCHAR(255),type VARCHAR(255),length FLOAT,frequency INT); INSERT INTO routes (id,route_name,type,length,frequency) VALUES (106,'Riverfront - Northside','Light Rail',15.0,12),(107,'Southside - Airport','Bus',25.0,20); | SELECT type, AVG(length) as avg_length FROM routes WHERE type = 'Light Rail'; |
What percentage of factories in Bangladesh follow fair labor practices? | CREATE TABLE factories (factory_id INT,name VARCHAR(255),location VARCHAR(255),follows_fair_practices BOOLEAN); INSERT INTO factories (factory_id,name,location,follows_fair_practices) VALUES (1,'Green Factory','Bangladesh',true),(2,'Blue Factory','Bangladesh',false); | SELECT (COUNT(*) FILTER (WHERE follows_fair_practices = true)) * 100.0 / COUNT(*) FROM factories WHERE location = 'Bangladesh'; |
What is the minimum number of likes for posts made by users located in the United Kingdom, in the last month? | CREATE TABLE users (id INT,location VARCHAR(50)); CREATE TABLE posts (id INT,user_id INT,likes INT,created_at DATETIME); | SELECT MIN(posts.likes) FROM posts INNER JOIN users ON posts.user_id = users.id WHERE users.location = 'United Kingdom' AND posts.created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH); |
What is the total number of unique users in Australia and New Zealand who have interacted with at least one ad, and what was the total engagement time for these users, broken down by day? | CREATE TABLE ad_interactions (user_id INT,ad_id INT,country VARCHAR(2),interaction_date DATE,interaction_time FLOAT); INSERT INTO ad_interactions (user_id,ad_id,country,interaction_date,interaction_time) VALUES (1,1001,'AU','2022-02-01',25.3),(2,1002,'NZ','2022-02-02',30.5),(1,1003,'AU','2022-02-01',15.6); | SELECT interaction_date, COUNT(DISTINCT user_id) as total_users, SUM(interaction_time) as total_engagement_time FROM ad_interactions WHERE country IN ('AU', 'NZ') GROUP BY interaction_date ORDER BY interaction_date DESC LIMIT 7; |
How many financially capable clients have a loan? | CREATE TABLE clients (client_id INT,is_financially_capable BOOLEAN); INSERT INTO clients (client_id,is_financially_capable) VALUES (1,true),(2,false),(3,true),(4,true),(5,false); CREATE TABLE loans (loan_id INT,client_id INT); INSERT INTO loans (loan_id,client_id) VALUES (1001,1),(1002,3),(1003,4),(1004,5); | SELECT COUNT(*) FROM clients INNER JOIN loans ON clients.client_id = loans.client_id WHERE clients.is_financially_capable = true; |
What is the total number of new and returning volunteers in each program in each month? | CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,ProgramID INT,VolunteerDate DATE,IsReturning BOOLEAN); INSERT INTO Volunteers (VolunteerID,VolunteerName,ProgramID,VolunteerDate,IsReturning) VALUES (6,'David Kim',1,'2022-03-01',FALSE),(7,'Emily Chen',2,'2022-03-15',TRUE),(8,'James Lee',2,'2022-04-01',FALSE),(9,'Grace Park',3,'2022-04-15',TRUE),(10,'Daniel Kim',1,'2022-04-01',FALSE); | SELECT ProgramID, EXTRACT(MONTH FROM VolunteerDate) AS Month, SUM(CASE WHEN IsReturning THEN 1 ELSE 0 END) OVER (PARTITION BY ProgramID, EXTRACT(MONTH FROM VolunteerDate) ORDER BY ProgramID, EXTRACT(MONTH FROM VolunteerDate)) + COUNT(DISTINCT VolunteerID) OVER (PARTITION BY ProgramID, EXTRACT(MONTH FROM VolunteerDate) ORDER BY ProgramID, EXTRACT(MONTH FROM VolunteerDate)) AS TotalVolunteers FROM Volunteers; |
List all suppliers who supply ingredients to restaurants with an 'Organic' rating? | CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50)); INSERT INTO suppliers VALUES (1,'Green Earth'),(2,'Farm Fresh'),(3,'Local Harvest'); CREATE TABLE restaurants (restaurant_id INT,restaurant_name VARCHAR(50),rating VARCHAR(50)); INSERT INTO restaurants VALUES (1,'Organic Bistro','Organic'),(2,'Gourmet Delight','Fine Dining'); CREATE TABLE ingredients (ingredient_id INT,ingredient_name VARCHAR(50),supplier_id INT,restaurant_id INT); INSERT INTO ingredients VALUES (1,'Spinach',1,1),(2,'Tomatoes',2,1),(3,'Beef',3,2); | SELECT s.supplier_name FROM suppliers s INNER JOIN ingredients i ON s.supplier_id = i.supplier_id INNER JOIN restaurants r ON i.restaurant_id = r.restaurant_id WHERE r.rating = 'Organic'; |
Get the number of warehouses in 'City Y' with a capacity greater than 100,000? | CREATE TABLE Warehouses (id INT,name VARCHAR(255),city VARCHAR(255),capacity INT); INSERT INTO Warehouses (id,name,city,capacity) VALUES (1,'Warehouse A','City A',100000); INSERT INTO Warehouses (id,name,city,capacity) VALUES (2,'Warehouse B','City B',120000); INSERT INTO Warehouses (id,name,city,capacity) VALUES (3,'Warehouse C','City C',155000); INSERT INTO Warehouses (id,name,city,capacity) VALUES (4,'Warehouse D','City Y',180000); | SELECT COUNT(id) FROM Warehouses WHERE city = 'City Y' AND capacity > 100000; |
What is the average annual income for each household type in a given city? | CREATE TABLE household_data (city VARCHAR(255),household_type VARCHAR(255),annual_income FLOAT); INSERT INTO household_data (city,household_type,annual_income) VALUES ('City X','Single',30000,),('City X','Married',60000),('City X','Retiree',40000),('City Y','Single',35000),('City Y','Married',70000),('City Y','Retiree',45000); | SELECT s1.household_type, AVG(s1.annual_income) as avg_annual_income FROM household_data s1 GROUP BY s1.household_type; |
What is the total number of mental health clinics that are in compliance with mental health parity regulations and located in neighborhoods with high health equity metrics? | CREATE TABLE MentalHealthClinics (ClinicID INT,Location VARCHAR(50),Type VARCHAR(20),ParityCompliance DATE,HealthEquityMetrics INT); CREATE TABLE Neighborhoods (NeighborhoodID INT,Location VARCHAR(50),HealthEquityMetrics INT); INSERT INTO MentalHealthClinics (ClinicID,Location,Type,ParityCompliance,HealthEquityMetrics) VALUES (1,'123 Main St','Psychiatric','2022-01-01',80); INSERT INTO Neighborhoods (NeighborhoodID,Location,HealthEquityMetrics) VALUES (1,'123 Main St',80); INSERT INTO Neighborhoods (NeighborhoodID,Location,HealthEquityMetrics) VALUES (2,'456 Elm St',60); | SELECT COUNT(*) FROM MentalHealthClinics INNER JOIN Neighborhoods ON MentalHealthClinics.Location = Neighborhoods.Location WHERE ParityCompliance IS NOT NULL AND HealthEquityMetrics >= 70; |
What is the average occupancy rate per hotel in New York City, ordered by occupancy rate in descending order? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,occupancy_rate DECIMAL(5,2)); INSERT INTO hotels (hotel_id,hotel_name,city,occupancy_rate) VALUES (1,'Hotel A','New York City',0.85),(2,'Hotel B','New York City',0.78),(3,'Hotel C','New York City',0.92); | SELECT AVG(occupancy_rate) AS avg_occupancy_rate, hotel_name FROM hotels WHERE city = 'New York City' GROUP BY hotel_name ORDER BY avg_occupancy_rate DESC; |
Identify language preservation programs and their respective annual budgets. | CREATE TABLE lang_preservation(id INT,program_name TEXT,annual_budget INT); INSERT INTO lang_preservation VALUES (1,'Endangered Languages Fund',200000),(2,'The Living Tongues Institute for Endangered Languages',150000); | SELECT program_name, annual_budget FROM lang_preservation; |
What are the names of the top 3 countries with the most heritage sites, and how many heritage sites do they have? | CREATE TABLE heritagesites (name VARCHAR(255),country VARCHAR(255)); INSERT INTO heritagesites (name,country) VALUES ('Taj Mahal','India'); INSERT INTO heritagesites (name,country) VALUES ('Machu Picchu','Peru'); | SELECT country, COUNT(name) OVER (PARTITION BY country) as num_sites FROM heritagesites ORDER BY num_sites DESC FETCH FIRST 3 ROWS ONLY; |
How many infrastructure projects are there for each 'state'? | CREATE TABLE InfrastructureProjects (id INT,name TEXT,state TEXT,category TEXT,budget FLOAT); INSERT INTO InfrastructureProjects (id,name,state,category,budget) VALUES (1,'Highway 12 Expansion','California','Transportation',2000000); INSERT INTO InfrastructureProjects (id,name,state,category,budget) VALUES (2,'Bridgewater Park Pedestrian Path','New York','Parks',500000); INSERT INTO InfrastructureProjects (id,name,state,category,budget) VALUES (3,'Railway Crossing Upgrade','Texas','Transportation',1500000); INSERT INTO InfrastructureProjects (id,name,state,category,budget) VALUES (4,'New Community Center','Florida','Community',3000000); INSERT INTO InfrastructureProjects (id,name,state,category,budget) VALUES (5,'Wastewater Treatment Plant','Louisiana','Waste Management',1200000); | SELECT state, COUNT(*) FROM InfrastructureProjects GROUP BY state; |
How many public works projects are there in 'Sydney' and 'Melbourne' combined? | CREATE TABLE PublicWorksC(id INT,city VARCHAR(20),project VARCHAR(30)); INSERT INTO PublicWorksC(id,city,project) VALUES (1,'Sydney','Park Renovation'),(2,'Melbourne','Sidewalk Repair'); | SELECT COUNT(*) FROM (SELECT city FROM PublicWorksC WHERE city = 'Sydney' UNION ALL SELECT city FROM PublicWorksC WHERE city = 'Melbourne') AS Total; |
What was the change in tourist numbers between 2017 and 2018 for destinations in Central America? | CREATE TABLE central_america_tourism (country VARCHAR(255),year INT,visitors INT); INSERT INTO central_america_tourism (country,year,visitors) VALUES ('Costa Rica',2017,5000),('Guatemala',2017,3000),('Belize',2017,2000),('Costa Rica',2018,5500),('Guatemala',2018,3200),('Belize',2018,2100); | SELECT a.country, (b.visitors - a.visitors) as visitor_change FROM central_america_tourism a JOIN central_america_tourism b ON a.country = b.country WHERE a.year = 2017 AND b.year = 2018; |
What is the minimum age of an offender who participated in a restorative justice program? | CREATE TABLE restorative_justice_programs (offender_id INT,age INT,program_type VARCHAR(20)); | SELECT MIN(age) FROM restorative_justice_programs; |
Find the top 5 media outlets by number of fact-checked articles in 2021. | CREATE TABLE media_outlets (outlet_id INT,outlet_name VARCHAR(100),outlet_type VARCHAR(50)); CREATE TABLE fact_checks (fact_check_id INT,fact_check_date DATE,outlet_id INT,is_true BOOLEAN); INSERT INTO media_outlets (outlet_id,outlet_name,outlet_type) VALUES (1,'Snopes','Fact-checking website'); INSERT INTO fact_checks (fact_check_id,fact_check_date,outlet_id,is_true) VALUES (1,'2021-01-01',1,TRUE); | SELECT o.outlet_name, COUNT(*) as num_fact_checked_articles FROM media_outlets o INNER JOIN fact_checks f ON o.outlet_id = f.outlet_id WHERE f.fact_check_date >= '2021-01-01' AND f.fact_check_date < '2022-01-01' GROUP BY o.outlet_name ORDER BY num_fact_checked_articles DESC LIMIT 5; |
What are the items with low stock levels and their cost that are not supplied by 'XYZ Corporation'? | CREATE TABLE Suppliers (SupplierID INT,Name VARCHAR(50),Item VARCHAR(50),Quantity INT,Cost DECIMAL(5,2)); CREATE VIEW LowStock AS SELECT SupplierID,Item FROM Suppliers WHERE Quantity < 10; | SELECT Suppliers.Item, Suppliers.Cost FROM Suppliers JOIN LowStock ON Suppliers.SupplierID = LowStock.SupplierID WHERE Suppliers.Name != 'XYZ Corporation'; |
List the defense projects that have a contract value over $10 million and a start date after 2018 for Boeing. | CREATE TABLE DefenseProjects (project_id INT,contractor VARCHAR(50),contract_value FLOAT,start_date DATE); INSERT INTO DefenseProjects (project_id,contractor,contract_value,start_date) VALUES (1,'Boeing',15000000,'2019-01-01'),(2,'Boeing',12000000,'2017-01-01'),(3,'Lockheed Martin',20000000,'2020-01-01'),(4,'Boeing',11000000,'2021-01-01'); | SELECT * FROM DefenseProjects WHERE contractor = 'Boeing' AND contract_value > 10000000 AND start_date > '2018-01-01'; |
What is the total revenue of military equipment sales for the US in the year 2020? | CREATE TABLE MilitaryEquipmentSales (sale_id INT,country VARCHAR(50),amount FLOAT,year INT); INSERT INTO MilitaryEquipmentSales (sale_id,country,amount,year) VALUES (1,'USA',1500000,2020); INSERT INTO MilitaryEquipmentSales (sale_id,country,amount,year) VALUES (2,'USA',1200000,2019); | SELECT SUM(amount) FROM MilitaryEquipmentSales WHERE country = 'USA' AND year = 2020; |
What is the maximum number of workers in a single mine, for mines that are of the 'Open Pit' type? | CREATE TABLE mine (id INT,name VARCHAR(255),type VARCHAR(255),workers INT); INSERT INTO mine (id,name,type,workers) VALUES (1,'Arizona Copper Mine','Open Pit',300),(2,'Nevada Silver Mine','Open Pit',250),(3,'California Gold Mine','Underground',150); | SELECT MAX(workers) as max_workers FROM mine WHERE type = 'Open Pit'; |
Find the top 3 news article titles with the highest word count from 'CBS News'? | CREATE TABLE cbs_news (article_id INT,title TEXT,word_count INT,publish_date DATE); INSERT INTO cbs_news (article_id,title,word_count,publish_date) VALUES (1,'Article Title 1 with many words',500,'2022-01-01'),(2,'Article Title 2 with fewer words',250,'2022-01-02'),(3,'Article Title 3 with medium words',350,'2022-01-03'); | SELECT title FROM cbs_news ORDER BY word_count DESC LIMIT 3 |
List organizations with more than 200 volunteers, and their average donation amounts, excluding donations less than $10. | CREATE TABLE organizations (org_id INT,org_name TEXT,social_impact_score INT);CREATE TABLE volunteers (vol_id INT,org_id INT,vol_country TEXT);CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount INT,donation_date DATE); | SELECT o.org_name, AVG(donation_amount) AS avg_donation_amount FROM organizations o JOIN volunteers v ON o.org_id = v.org_id JOIN donations don ON o.org_id = don.org_id WHERE donation_amount >= 10 GROUP BY o.org_name HAVING COUNT(v.vol_id) > 200; |
What is the total amount donated to a specific cause? | CREATE TABLE causes (id INT,name TEXT); CREATE TABLE donations (id INT,donor_id INT,cause_id INT,donation_amount DECIMAL(10,2)); INSERT INTO causes (id,name) VALUES (1,'Cause A'),(2,'Cause B'); INSERT INTO donations (id,donor_id,cause_id,donation_amount) VALUES (1,1,1,50.00),(2,2,1,100.00); | SELECT SUM(donation_amount) FROM donations JOIN causes ON donations.cause_id = causes.id WHERE causes.name = 'Cause A'; |
How many donors have made recurring donations in each region? | CREATE TABLE Donors (DonorID INT,Region VARCHAR(50),RecurringDonor BOOLEAN); | SELECT Region, COUNT(DonorID) FROM Donors WHERE RecurringDonor = TRUE GROUP BY Region; |
What's the maximum donation amount in the last 6 months? | CREATE TABLE donations_time (donation_time DATETIME,donation_amount DECIMAL(10,2)); INSERT INTO donations_time (donation_time,donation_amount) VALUES ('2022-01-01 12:00:00',500.00),('2022-06-01 15:00:00',1000.00); | SELECT MAX(donation_amount) FROM donations_time WHERE donation_time >= DATE_SUB(NOW(), INTERVAL 6 MONTH); |
What are the top 3 countries with the most players? | CREATE TABLE Players (PlayerID INT,Country VARCHAR(20));INSERT INTO Players (PlayerID,Country) VALUES (1,'USA'),(2,'Canada'),(3,'USA'),(4,'Mexico'); | SELECT Country, COUNT(PlayerID) AS PlayerCount FROM Players GROUP BY Country ORDER BY PlayerCount DESC LIMIT 3; |
Create a table named 'ticket_sales' to store ticket sales data | CREATE TABLE ticket_sales (sale_id INT,event_date DATE,team VARCHAR(50),section VARCHAR(50),price DECIMAL(5,2),quantity INT); | CREATE TABLE ticket_sales (sale_id INT, event_date DATE, team VARCHAR(50), section VARCHAR(50), price DECIMAL(5,2), quantity INT); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.