instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Add a new record to the 'transportation' table with id 8001, mode 'Electric Rail', country 'India', and energy_efficiency_index 0.85 | CREATE TABLE transportation (id INT PRIMARY KEY,mode VARCHAR(50),country VARCHAR(50),energy_efficiency_index FLOAT); | INSERT INTO transportation (id, mode, country, energy_efficiency_index) VALUES (8001, 'Electric Rail', 'India', 0.85); |
What is the average mass of exoplanets discovered by the TESS mission, and how many of these exoplanets are classified as super-Earths? | CREATE TABLE Exoplanets (id INT,mission VARCHAR(255),mass FLOAT,planet_type VARCHAR(255)); | SELECT AVG(mass) as avg_mass, SUM(CASE WHEN planet_type = 'Super-Earth' THEN 1 ELSE 0 END) as super_earth_count FROM Exoplanets WHERE mission = 'TESS'; |
What is the average distance to the nearest primary care clinic for residents in the "Navajo Nation" area? | CREATE TABLE Clinics (ClinicID INT,Name VARCHAR(50),Location POINT); INSERT INTO Clinics (ClinicID,Name,Location) VALUES (1,'Primary Care Clinic A',POINT(-108.6351,35.4674)); INSERT INTO Clinics (ClinicID,Name,Location) VALUES (2,'Primary Care Clinic B',POINT(-108.5123,35.6541)); CREATE TABLE Residents (ResidentID INT,... | SELECT AVG(ST_Distance(Residents.Location, Clinics.Location)) FROM Residents, Clinics WHERE ST_DWithin(Residents.Location, Clinics.Location, 50000) AND Residents.Location <> Clinics.Location AND Clinics.Name LIKE 'Primary Care%'; |
What is the total number of cases in the restorative_justice table, grouped by case_type? | CREATE TABLE restorative_justice (case_id INT,case_type VARCHAR(10),location VARCHAR(20),facilitator VARCHAR(20)); INSERT INTO restorative_justice (case_id,case_type,location,facilitator) VALUES (5,'community_conference','NY','John'),(6,'restitution_session','CA','Sarah'),(7,'community_conference','NY','Lisa'); | SELECT case_type, COUNT(*) FROM restorative_justice GROUP BY case_type; |
What is the minimum elevation for a tunnel in 'Australia'? | CREATE TABLE Tunnels (TunnelID int,Name varchar(100),Location varchar(100),Elevation decimal(10,2)); INSERT INTO Tunnels VALUES (1,'Tunnel A','Australia',250); INSERT INTO Tunnels VALUES (2,'Tunnel B','Australia',300); | SELECT MIN(Elevation) FROM Tunnels WHERE Location = 'Australia'; |
What is the total revenue of organic skincare products sold in the UK in 2021? | CREATE TABLE cosmetics_sales (product VARCHAR(255),country VARCHAR(255),sale_date DATE,revenue DECIMAL(10,2)); CREATE TABLE cosmetics (product VARCHAR(255),product_category VARCHAR(255),organic BOOLEAN); CREATE TABLE countries (country VARCHAR(255),continent VARCHAR(255)); INSERT INTO countries (country,continent) VALU... | SELECT SUM(revenue) FROM cosmetics_sales JOIN cosmetics ON cosmetics_sales.product = cosmetics.product JOIN countries ON cosmetics_sales.country = countries.country WHERE cosmetics.product_category = 'Skincare' AND cosmetics.organic = true AND countries.country = 'UK' AND YEAR(sale_date) = 2021; |
What is the number of fish in each farm, ranked by the most to least? | CREATE TABLE fish_farms (id INT,name VARCHAR(255)); INSERT INTO fish_farms (id,name) VALUES (1,'Farm A'),(2,'Farm B'),(3,'Farm C'); CREATE TABLE fish_inventory (id INT,farm_id INT,species_id INT,biomass FLOAT); INSERT INTO fish_inventory (id,farm_id,species_id,biomass) VALUES (1,1,1,1000),(2,1,2,800),(3,2,1,1200),(4,3,... | SELECT f.name, COUNT(fi.id) as num_fish FROM fish_inventory fi JOIN fish_farms f ON fi.farm_id = f.id GROUP BY f.name ORDER BY COUNT(fi.id) DESC; |
What is the total water consumption in the top 3 water-consuming continents in the past year? | CREATE TABLE water_consumption (continent VARCHAR(255),consumption FLOAT,date DATE); INSERT INTO water_consumption (continent,consumption,date) VALUES ('Asia',500000,'2022-01-01'); INSERT INTO water_consumption (continent,consumption,date) VALUES ('Africa',600000,'2022-01-01'); | SELECT continent, SUM(consumption) FROM (SELECT continent, consumption, ROW_NUMBER() OVER (PARTITION BY continent ORDER BY consumption DESC) as rank FROM water_consumption WHERE date >= '2021-01-01' GROUP BY continent, consumption) subquery WHERE rank <= 3 GROUP BY continent; |
How many electric bikes are there in total? | CREATE TABLE Bikeshare (id INT,station VARCHAR(30),bike_type VARCHAR(20),total_bikes INT,last_inspection DATE); INSERT INTO Bikeshare (id,station,bike_type,total_bikes,last_inspection) VALUES (3,'Harlem','Standard',8,'2022-01-04'),(4,'Brooklyn','Electric',6,'2022-01-03'); | SELECT bike_type, SUM(total_bikes) as total_ebikes FROM Bikeshare WHERE bike_type = 'Electric' GROUP BY bike_type; |
List all companies and their sustainable material usage in the 'Americas' region. | CREATE TABLE Companies (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO Companies (id,name,region) VALUES (1,'CompanyA','Asia-Pacific'),(2,'CompanyB','Europe'),(3,'CompanyD','Americas'); CREATE TABLE Materials (id INT,company_id INT,material VARCHAR(255),quantity INT); INSERT INTO Materials (id,company_id,ma... | SELECT Companies.name, SUM(Materials.quantity) FROM Companies JOIN Materials ON Companies.id = Materials.company_id WHERE Companies.region = 'Americas' GROUP BY Companies.name; |
What is the average improvement rate for the 'Physical Activity' program in each location? | CREATE TABLE HealthEquityMetrics (id INT,program VARCHAR(50),location VARCHAR(50),participants INT,improvementRate DECIMAL(3,2)); INSERT INTO HealthEquityMetrics (id,program,location,participants,improvementRate) VALUES (1,'Healthy Eating','Los Angeles',200,0.35),(2,'Physical Activity','San Francisco',150,0.40),(3,'Phy... | SELECT program, location, AVG(improvementRate) as 'AverageImprovementRate' FROM HealthEquityMetrics WHERE program = 'Physical Activity' GROUP BY program, location; |
Insert a new cargo record | cargo(cargo_id,cargo_name,weight,volume,description) | INSERT INTO cargo (cargo_id, cargo_name, weight, volume, description) VALUES (2002, 'Electronics', 500, 100, 'Consumer electronics'); |
Delete records of waste generation from the residential sector in New York City in 2021. | CREATE TABLE waste_generation (id INT,sector VARCHAR(20),location VARCHAR(20),amount DECIMAL(10,2),date DATE); INSERT INTO waste_generation (id,sector,location,amount,date) VALUES (1,'residential','New York City',500,'2021-01-01'); | DELETE FROM waste_generation WHERE sector = 'residential' AND location = 'New York City' AND date = '2021-01-01'; |
What is the percentage of hotels in the 'boutique' segment with virtual tours? | CREATE TABLE hotels_vt (id INT,segment TEXT,virtual_tour BOOLEAN); INSERT INTO hotels_vt (id,segment,virtual_tour) VALUES (1,'boutique',true),(2,'economy',false),(3,'boutique',true); | SELECT segment, ROUND(100.0 * COUNT(*) / (SELECT COUNT(*) FROM hotels_vt WHERE segment = 'boutique'), 2) as percentage FROM hotels_vt WHERE segment = 'boutique' AND virtual_tour = true GROUP BY segment; |
Which endangered species have been introduced to 'Conservation Area A'? | CREATE TABLE Habitats (HabitatID INT,HabitatName TEXT,Location TEXT); INSERT INTO Habitats (HabitatID,HabitatName,Location) VALUES (1,'Conservation Area A','Country A'); CREATE TABLE AnimalPopulation (AnimalID INT,AnimalName TEXT,HabitatID INT,Status TEXT); INSERT INTO AnimalPopulation (AnimalID,AnimalName,HabitatID,St... | SELECT AnimalName FROM AnimalPopulation WHERE HabitatID = 1 AND Status = 'Endangered'; |
What is the total weight of unsustainable materials used in production? | CREATE TABLE Production (item_id INT,material VARCHAR(255),weight DECIMAL(5,2),sustainable BOOLEAN); INSERT INTO Production (item_id,material,weight,sustainable) VALUES (1,'Organic Cotton',2.5,true),(1,'Polyester',1.5,false),(2,'Recycled Wool',3.0,true); | SELECT SUM(weight) FROM Production WHERE sustainable = false; |
Delete records in the fabrics table where the country is 'China' and material is 'silk' | CREATE TABLE fabrics (id INT PRIMARY KEY,material VARCHAR(255),country VARCHAR(255),quantity INT); INSERT INTO fabrics (id,material,country,quantity) VALUES (1,'cotton','Bangladesh',500),(2,'silk','China',300),(3,'wool','Australia',700); | DELETE FROM fabrics WHERE country = 'China' AND material = 'silk'; |
What is the total number of properties co-owned by women in urban areas? | CREATE TABLE property (id INT,co_owner1 VARCHAR(255),co_owner2 VARCHAR(255),area VARCHAR(255)); INSERT INTO property (id,co_owner1,co_owner2,area) VALUES (1,'Jane','Bob','urban'),(2,'Alex','Lisa','rural'),(3,'Sara','Mike','urban'),(4,'Tom','Emily','urban'); | SELECT COUNT(*) FROM property WHERE (co_owner1 = 'Jane' OR co_owner1 = 'Sara' OR co_owner1 = 'Emily' OR co_owner2 = 'Jane' OR co_owner2 = 'Sara' OR co_owner2 = 'Emily') AND area = 'urban'; |
Delete all mascaras with a sales volume lower than 500. | CREATE TABLE products (product_id INT,name VARCHAR(255),category VARCHAR(255),sales_volume INT); | DELETE FROM products WHERE category = 'mascara' AND sales_volume < 500; |
What is the total budget allocated to education programs in the last fiscal year? | CREATE TABLE Budget (FiscalYear INT,Program TEXT,Allocation DECIMAL); INSERT INTO Budget (FiscalYear,Program,Allocation) VALUES (2021,'Education',50000),(2021,'Healthcare',75000),(2022,'Education',60000); | SELECT SUM(Allocation) FROM Budget WHERE Program = 'Education' AND FiscalYear = 2021; |
Find the number of defendants who participated in restorative justice programs in 2020 | CREATE TABLE defendants (defendant_id INT,program_year INT,participated_restorative_program BOOLEAN); INSERT INTO defendants (defendant_id,program_year,participated_restorative_program) VALUES (1,2020,true),(2,2019,false),(3,2020,false),(4,2018,true); | SELECT COUNT(*) FROM defendants WHERE program_year = 2020 AND participated_restorative_program = true; |
What is the average citizen feedback score for transportation services in the South region in 2022? | CREATE TABLE Feedback (Year INT,Service VARCHAR(255),Region VARCHAR(255),Score DECIMAL(3,2)); INSERT INTO Feedback (Year,Service,Region,Score) VALUES (2022,'Bus','South',8.25),(2022,'Train','South',8.50),(2022,'Taxi','South',8.75); | SELECT AVG(Score) FROM Feedback WHERE Year = 2022 AND Region = 'South' AND Service IN ('Bus', 'Train'); |
Find the average amount of coal mined per day in the 'coal_mining' table for the month of July 2020. | CREATE TABLE coal_mining (id INT,mine_name VARCHAR(50),coal_amount INT,mining_date DATE); INSERT INTO coal_mining (id,mine_name,coal_amount,mining_date) VALUES (1,'ABC Mine',500,'2020-07-01'); INSERT INTO coal_mining (id,mine_name,coal_amount,mining_date) VALUES (2,'XYZ Mine',700,'2020-07-15'); | SELECT AVG(coal_amount) FROM coal_mining WHERE mining_date >= '2020-07-01' AND mining_date <= '2020-07-31'; |
What are the names of all agricultural projects in the 'rural_development' schema that have an 'id' greater than 3? | CREATE SCHEMA IF NOT EXISTS rural_development;CREATE TABLE IF NOT EXISTS rural_development.agriculture_projects (name VARCHAR(255),id INT);INSERT INTO rural_development.agriculture_projects (name,id) VALUES ('sustainable_farming',1),('organic_gardening',2),('livestock_support',3),('aquaculture_development',4); | SELECT name FROM rural_development.agriculture_projects WHERE id > 3; |
What is the maximum safety rating of trucks released in or after 2020? | CREATE TABLE TruckSafetyTesting (id INT,rating INT,release_year INT); INSERT INTO TruckSafetyTesting (id,rating,release_year) VALUES (1,4,2019),(2,5,2020),(3,5,2021),(4,4,2018),(5,3,2019),(6,5,2022); | SELECT MAX(rating) FROM TruckSafetyTesting WHERE release_year >= 2020; |
What is the average production budget for TV shows by genre? | CREATE TABLE TV_Shows (id INT,title VARCHAR(100),genre VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO TV_Shows (id,title,genre,budget) VALUES (1,'The Witcher','Fantasy',80000000.00),(2,'Stranger Things','Sci-fi',8000000.00),(3,'The Crown','Drama',130000000.00); | SELECT genre, AVG(budget) FROM TV_Shows GROUP BY genre; |
Who are the top 5 offenders by total fines in the last quarter in Texas? | CREATE TABLE Offenders (OffenderID INT,OffenderName TEXT,FineAmount DECIMAL(10,2),OffenseDate DATE); INSERT INTO Offenders (OffenderID,OffenderName,FineAmount,OffenseDate) VALUES (1,'John Doe',500,'2022-01-10'); INSERT INTO Offenders (OffenderID,OffenderName,FineAmount,OffenseDate) VALUES (2,'Jane Smith',800,'2022-02-1... | SELECT OffenderName, SUM(FineAmount) as TotalFines FROM Offenders WHERE OffenseDate BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND CURRENT_DATE GROUP BY OffenderName ORDER BY TotalFines DESC LIMIT 5; |
What's the total number of students from both public and private schools in the 'student_data' table? | CREATE TABLE student_data (student_id INT,school_type VARCHAR(10)); | SELECT COUNT(student_id) FROM student_data WHERE school_type IN ('public', 'private'); |
List the top 5 military equipment types with the highest maintenance costs | CREATE SCHEMA equipment_schema; CREATE TABLE equipment (equipment_id INT PRIMARY KEY,equipment_type VARCHAR(255)); CREATE TABLE maintenance (maintenance_id INT PRIMARY KEY,maintenance_cost INT,equipment_id INT,FOREIGN KEY (equipment_id) REFERENCES equipment(equipment_id)); INSERT INTO equipment (equipment_id,equipment_... | SELECT e.equipment_type, SUM(m.maintenance_cost) as total_cost FROM equipment e JOIN maintenance m ON e.equipment_id = m.equipment_id GROUP BY e.equipment_type ORDER BY total_cost DESC LIMIT 5; |
What is the average safety rating for vehicles manufactured in Italy and Spain? | CREATE TABLE Vehicles (ID INT,Manufacturer VARCHAR(255),SafetyRating FLOAT); INSERT INTO Vehicles (ID,Manufacturer,SafetyRating) VALUES (1,'Ferrari',4.5),(2,'Lamborghini',4.3),(3,'Seat',4.1),(4,'Skoda',4.2); | SELECT AVG(SafetyRating) FROM Vehicles WHERE Manufacturer IN ('Italy', 'Spain'); |
What is the total cost of all infrastructure projects in rural communities in Kenya, grouped by project type? | CREATE TABLE rural_communities (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO rural_communities (id,name,country) VALUES (1,'Makueni','Kenya'); CREATE TABLE infrastructure_projects (id INT,type VARCHAR(50),cost FLOAT,rural_community_id INT); INSERT INTO infrastructure_projects (id,type,cost,rural_community_... | SELECT i.type, SUM(i.cost) as total_cost FROM infrastructure_projects i INNER JOIN rural_communities r ON i.rural_community_id = r.id WHERE r.country = 'Kenya' GROUP BY i.type; |
What is the ratio of hospital beds to residents in rural county 'Glacier'? | CREATE TABLE hospitals (county TEXT,beds INTEGER); INSERT INTO hospitals (county,beds) VALUES ('Glacier',500); CREATE TABLE residents (county TEXT,population INTEGER); INSERT INTO residents (county,population) VALUES ('Glacier',10000); | SELECT (hospitals.beds / residents.population) * 100 AS bed_to_resident_ratio FROM hospitals JOIN residents ON hospitals.county = residents.county WHERE hospitals.county = 'Glacier'; |
Calculate the average budget for habitat preservation in 'habitat_preservation' table | CREATE TABLE habitat_preservation (id INT,region VARCHAR(50),budget DECIMAL(10,2)); | SELECT AVG(budget) FROM habitat_preservation; |
Which companies have manufactured more than 5 satellites of the type 'Earth Observation'? | CREATE TABLE Satellite (id INT,name VARCHAR(50),type VARCHAR(50),manufacturer VARCHAR(50),launch_date DATE); INSERT INTO Satellite (id,name,type,manufacturer,launch_date) VALUES (1,'Landsat 1','Earth Observation','Boeing','1972-07-23'); INSERT INTO Satellite (id,name,type,manufacturer,launch_date) VALUES (2,'Envisat','... | SELECT m.name, m.country, COUNT(s.id) as satellite_count FROM Manufacturer m INNER JOIN Satellite s ON m.name = s.manufacturer WHERE s.type = 'Earth Observation' GROUP BY m.name, m.country HAVING COUNT(s.id) > 5; |
Delete all records in the 'military_equipment' table where 'equipment_type' is 'aircraft' | CREATE TABLE military_equipment (equipment_id INT PRIMARY KEY,equipment_type VARCHAR(20),country VARCHAR(20),in_service BOOLEAN); | DELETE FROM military_equipment WHERE equipment_type = 'aircraft'; |
What is the total number of Union members in the Education sector? | CREATE TABLE UnionMembership (id INT,sector VARCHAR(255),members INT); INSERT INTO UnionMembership (id,sector,members) VALUES (1,'Education',5000); | SELECT SUM(members) FROM UnionMembership WHERE sector = 'Education'; |
What are the engineering design standards for drainage systems in the infrastructure database? | CREATE TABLE Design_Standards (Standard_ID INT,Standard_Name VARCHAR(50),Standard_Description TEXT); INSERT INTO Design_Standards (Standard_ID,Standard_Name,Standard_Description) VALUES (1,'Drainage_System_1','10-year design storm event'),(2,'Drainage_System_2','50-year design storm event'),(3,'Bridge_Design_1','Load R... | SELECT Standard_Description FROM Design_Standards WHERE Standard_Name LIKE '%Drainage%'; |
What is the total quantity of fair trade products sold in Europe? | CREATE TABLE Sales (SaleID INT,Product VARCHAR(20),Quantity INT,Region VARCHAR(20)); INSERT INTO Sales VALUES (1,'Fair Trade Coffee',200,'Europe'); INSERT INTO Sales VALUES (2,'Fair Trade Tea',300,'Europe'); | SELECT SUM(Quantity) FROM Sales WHERE Product LIKE '%Fair Trade%' AND Region = 'Europe'; |
What is the total transaction amount for 'BTC'? | CREATE TABLE digital_assets (asset_id varchar(10),asset_name varchar(10)); INSERT INTO digital_assets (asset_id,asset_name) VALUES ('ETH','Ethereum'),('BTC','Bitcoin'); CREATE TABLE transactions (transaction_id serial,asset_id varchar(10),transaction_amount numeric); INSERT INTO transactions (asset_id,transaction_amoun... | SELECT SUM(transaction_amount) FROM transactions WHERE asset_id = 'BTC'; |
What is the total revenue for bus and train rides in New York? | CREATE TABLE nyc_bus (ride_id INT,route_id INT,revenue INT); CREATE TABLE nyc_train (ride_id INT,route_id INT,revenue INT); | SELECT SUM(revenue) FROM nyc_bus WHERE route_id < 10 UNION ALL SELECT SUM(revenue) FROM nyc_train WHERE route_id < 5; |
Find the number of co-owned properties by each gender. | CREATE TABLE properties (property_id INT,price FLOAT,owner_id INT); CREATE TABLE owners (owner_id INT,name VARCHAR(255),gender VARCHAR(6)); INSERT INTO properties (property_id,price,owner_id) VALUES (1,500000,101),(2,600000,102),(3,700000,101); INSERT INTO owners (owner_id,name,gender) VALUES (101,'Alice','female'),(10... | SELECT owners.gender, COUNT(properties.property_id) FROM properties INNER JOIN owners ON properties.owner_id = owners.owner_id GROUP BY owners.gender; |
What is the total value of all real estate investments made by clients in California? | CREATE TABLE clients (id INT,state VARCHAR(2));CREATE TABLE investments (id INT,client_id INT,type VARCHAR(10),value FLOAT); INSERT INTO clients (id,state) VALUES (1,'CA'),(2,'NY'); INSERT INTO investments (id,client_id,type,value) VALUES (1,1,'real_estate',500000),(2,1,'stocks',300000),(3,2,'real_estate',700000),(4,2,... | SELECT SUM(value) FROM investments i JOIN clients c ON i.client_id = c.id WHERE c.state = 'CA' AND i.type = 'real_estate'; |
Show the names of all companies that have implemented industry 4.0 technologies and have a strong focus on workforce development. | CREATE TABLE companies (id INT,name TEXT,country TEXT,industry TEXT,industry_4_0 BOOLEAN,workforce_development BOOLEAN); INSERT INTO companies (id,name,country,industry,industry_4_0,workforce_development) VALUES (1,'ABC Corp','Germany','Manufacturing',TRUE,TRUE),(2,'DEF Corp','France','Manufacturing',FALSE,TRUE),(3,'GH... | SELECT name FROM companies WHERE industry_4_0 = TRUE AND workforce_development = TRUE; |
List the names and prices of dishes that are not in the appetizer category and cost more than 15 dollars. | CREATE TABLE dishes (id INT,name VARCHAR(50),category VARCHAR(50),price DECIMAL(5,2)); INSERT INTO dishes (id,name,category,price) VALUES (1,'Margherita Pizza','Pizza',9.99),(2,'Chicken Alfredo','Pasta',12.49),(3,'Vegetable Lasagna','Pasta',10.99),(4,'Eggplant Parmesan','Vegetarian',11.99),(5,'Cheese Burger','Burger',1... | SELECT name, price FROM dishes WHERE category != 'Appetizer' AND price > 15; |
Who are the top 3 consumers of cosmetic products in Mexico? | CREATE TABLE ConsumerPreference (ConsumerID INT,ProductID INT,ProductName VARCHAR(50),Country VARCHAR(50)); INSERT INTO ConsumerPreference (ConsumerID,ProductID,ProductName,Country) VALUES (6,301,'Lipstick','Mexico'),(7,302,'Mascara','Mexico'),(8,303,'Foundation','Mexico'),(9,304,'Eyeshadow','Mexico'),(10,305,'Blush','... | SELECT ConsumerName, COUNT(*) AS ProductCount FROM ConsumerPreference CP INNER JOIN Consumers C ON CP.ConsumerID = C.ConsumerID WHERE CP.Country = 'Mexico' GROUP BY ConsumerName ORDER BY ProductCount DESC LIMIT 3; |
How many innovative patents were filed by companies in the 'technology' sector? | CREATE TABLE company_innovation (company_id INT,sector VARCHAR(20),patent_count INT); INSERT INTO company_innovation (company_id,sector,patent_count) VALUES (1,'technology',3),(2,'healthcare',1),(3,'technology',2); | SELECT sector, SUM(patent_count) FROM company_innovation WHERE sector = 'technology' GROUP BY sector; |
What is the maximum number of daily visitors to the Louvre Museum in Paris in 2022? | CREATE TABLE daily_visitors (id INT,museum VARCHAR(20),daily_visitors INT,visit_date DATE); INSERT INTO daily_visitors (id,museum,daily_visitors,visit_date) VALUES (1,'Louvre',15000,'2022-01-01'),(2,'Louvre',18000,'2022-01-02'),(3,'Louvre',12000,'2022-01-03'); | SELECT MAX(daily_visitors) FROM daily_visitors WHERE museum = 'Louvre' AND visit_date BETWEEN '2022-01-01' AND LAST_DAY('2022-12-31'); |
What is the total revenue generated from esports events in the last 3 months? | CREATE TABLE EsportsEvents (EventID INT,EventDate DATE,Revenue INT); INSERT INTO EsportsEvents (EventID,EventDate,Revenue) VALUES (1,'2022-01-01',500000),(2,'2022-02-01',700000),(3,'2022-03-01',600000),(4,'2022-04-01',800000); | SELECT SUM(Revenue) FROM EsportsEvents WHERE EventDate >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH); |
Show the total number of IoT sensors deployed for each crop type | CREATE TABLE sensor_data (crop_type VARCHAR(20),num_sensors INT); INSERT INTO sensor_data (crop_type,num_sensors) VALUES ('Corn',500),('Soybeans',700),('Wheat',300); | SELECT crop_type, SUM(num_sensors) FROM sensor_data GROUP BY crop_type; |
What is the total number of volunteers for each project in Colombia? | CREATE TABLE projects (id INT,name TEXT,country TEXT); INSERT INTO projects VALUES (1,'Water Project','Colombia'); INSERT INTO projects VALUES (2,'Education Project','Colombia'); CREATE TABLE volunteers (id INT,project_id INT,number_of_volunteers INT); INSERT INTO volunteers VALUES (1,1,50); INSERT INTO volunteers VALU... | SELECT p.name, SUM(v.number_of_volunteers) as total_volunteers FROM projects p INNER JOIN volunteers v ON p.id = v.project_id WHERE p.country = 'Colombia' GROUP BY p.name; |
What is the total number of warehouses in each country? | CREATE TABLE Warehouses (warehouse_id INT,location VARCHAR(50)); CREATE TABLE Locations (location_id INT,country VARCHAR(50)); INSERT INTO Warehouses (warehouse_id,location) VALUES (1,'Los Angeles'); INSERT INTO Locations (location_id,country) VALUES (1,'United States'); INSERT INTO Warehouses (warehouse_id,location) V... | SELECT Locations.country, COUNT(Warehouses.warehouse_id) FROM Warehouses INNER JOIN Locations ON Warehouses.location = Locations.location_id GROUP BY Locations.country; |
How many articles were published by The New York Times in Q3 2017 and Q4 2017? | CREATE TABLE articles (id INT,title VARCHAR(100),publication_date DATE,publisher VARCHAR(50)); INSERT INTO articles (id,title,publication_date,publisher) VALUES (1,'Article1','2017-07-21','The New York Times'),(2,'Article2','2017-10-15','The New York Times'),(3,'Article3','2017-12-05','The New York Times'); | SELECT COUNT(*) FROM articles WHERE publication_date BETWEEN '2017-07-01' AND '2017-09-30' OR publication_date BETWEEN '2017-10-01' AND '2017-12-31' AND publisher = 'The New York Times'; |
What is the total number of artworks donated by each artist, ordered by the total count in descending order? | CREATE TABLE Artists (ArtistID int,ArtistName varchar(50),NumberOfArtworks int);INSERT INTO Artists (ArtistID,ArtistName,NumberOfArtworks) VALUES (1,'Pablo Picasso',500),(2,'Vincent Van Gogh',450),(3,'Claude Monet',350); | SELECT ArtistName, SUM(NumberOfArtworks) OVER (PARTITION BY ArtistID ORDER BY ArtistID) as TotalArtworksDonated FROM Artists ORDER BY TotalArtworksDonated DESC; |
How many female and male faculty members are there in the College of Science? | CREATE TABLE science_faculty (faculty_id INT,faculty_gender VARCHAR(10),faculty_department VARCHAR(50)); INSERT INTO science_faculty (faculty_id,faculty_gender,faculty_department) VALUES (1,'Female','Physics'),(2,'Male','Chemistry'),(3,'Female','Biology'),(4,'Male','Mathematics'); | SELECT faculty_gender, COUNT(*) FROM science_faculty WHERE faculty_department = 'College of Science' GROUP BY faculty_gender; |
List all the food justice organizations in Vancouver, Canada with their respective websites. | CREATE TABLE food_justice_orgs (org_id INT,name TEXT,location TEXT,website TEXT,city TEXT,state TEXT,country TEXT); INSERT INTO food_justice_orgs (org_id,name,location,website,city,state,country) VALUES (1,'Fair Food Society','321 Elm St','fairfoodsociety.ca','Vancouver','BC','Canada'); | SELECT name, website FROM food_justice_orgs WHERE city = 'Vancouver' AND country = 'Canada'; |
Count the number of socially responsible accounts in the Western region | CREATE TABLE socially_responsible_accounts (id INT,account_type VARCHAR(255),region VARCHAR(255)); | SELECT COUNT(*) FROM socially_responsible_accounts WHERE region = 'Western'; |
What is the total value of assets for clients who have made transactions in both USD and EUR? | CREATE TABLE clients (client_id INT,currency VARCHAR(10)); INSERT INTO clients (client_id,currency) VALUES (1,'USD'),(2,'EUR'),(3,'USD'),(4,'EUR'); CREATE TABLE assets (asset_id INT,client_id INT,value INT,currency VARCHAR(10)); INSERT INTO assets (asset_id,client_id,value,currency) VALUES (1,1,5000,'USD'),(2,1,7000,'E... | SELECT SUM(value) FROM assets WHERE client_id IN (SELECT client_id FROM clients INNER JOIN assets ON clients.client_id = assets.client_id WHERE currency IN ('USD', 'EUR') GROUP BY client_id HAVING COUNT(DISTINCT currency) = 2); |
List all customers and their transaction amounts for customers in the Western region. | CREATE TABLE customers (customer_id INT,name VARCHAR(50),region VARCHAR(20)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_amount DECIMAL(10,2)); INSERT INTO customers (customer_id,name,region) VALUES (1,'John Doe','West Coast'),(2,'Jane Smith','East Coast'); INSERT INTO transactions (trans... | SELECT c.name, t.transaction_amount FROM customers c JOIN transactions t ON c.customer_id = t.customer_id WHERE c.region = 'West Coast'; |
Update the 'inventory_data' table and set 'inventory_status' to 'low' for all records where 'product_name' is 'Acetone' | CREATE TABLE inventory_data (inventory_id INT,product_name VARCHAR(20),inventory_status VARCHAR(10)); | UPDATE inventory_data SET inventory_status = 'low' WHERE product_name = 'Acetone'; |
How many wildlife species are present in the 'Amazon Rainforest'? | CREATE TABLE AmazonRainforest (region VARCHAR(20),species_count INT); INSERT INTO AmazonRainforest (region,species_count) VALUES ('Amazon Rainforest',456); | SELECT species_count FROM AmazonRainforest WHERE region = 'Amazon Rainforest'; |
Who are the top 3 suppliers of organic cotton to Vietnam? | CREATE TABLE Suppliers (SupplierID INT,Product VARCHAR(20),Quantity INT,Country VARCHAR(20)); INSERT INTO Suppliers VALUES (1,'Organic Cotton',100,'Vietnam'); INSERT INTO Suppliers VALUES (2,'Organic Cotton',200,'Vietnam'); INSERT INTO Suppliers VALUES (3,'Organic Cotton',150,'Vietnam'); | SELECT SupplierID, Product, Quantity FROM Suppliers WHERE Product = 'Organic Cotton' AND Country = 'Vietnam' ORDER BY Quantity DESC LIMIT 3; |
What is the total revenue generated by restaurants with 'Organic' sourcing practices in the 'Asia-Pacific' region for the month of May 2022? | CREATE TABLE restaurant_revenue(restaurant_id INT,sourcing_practices VARCHAR(255),revenue DECIMAL(10,2),revenue_date DATE); CREATE VIEW restaurant_region AS SELECT restaurant_id,'Asia-Pacific' AS region FROM restaurant WHERE region = 'Asia-Pacific'; | SELECT SUM(revenue) FROM restaurant_revenue INNER JOIN restaurant_region ON restaurant_revenue.restaurant_id = restaurant_region.restaurant_id WHERE sourcing_practices = 'Organic' AND revenue_date BETWEEN '2022-05-01' AND '2022-05-31'; |
Which coaches are older than 50 and coach basketball? | CREATE TABLE Coaches (CoachID INT,Name VARCHAR(50),Sport VARCHAR(20),Age INT,Country VARCHAR(50)); INSERT INTO Coaches (CoachID,Name,Sport,Age,Country) VALUES (1,'Jane Smith','Soccer',45,'England'),(2,'Mateo Garcia','Basketball',52,'Argentina'),(3,'Svetlana Petrova','Basketball',48,'Russia'); | SELECT * FROM Coaches WHERE Age > 50 AND Sport = 'Basketball'; |
How many individuals have been incarcerated in the past month, broken down by the type of facility and the number of prior offenses? | CREATE TABLE incarceration_records (id INT,facility_type TEXT,num_prior_offenses INT,incarceration_date DATE); | SELECT facility_type, num_prior_offenses, COUNT(*) FROM incarceration_records WHERE incarceration_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY facility_type, num_prior_offenses; |
What is the total cost for each freight forwarder? | CREATE TABLE freight_costs (freight_forwarder VARCHAR(20),total_cost DECIMAL(10,2)); INSERT INTO freight_costs (freight_forwarder,total_cost) VALUES ('FF1',1000.00),('FF2',2000.00),('FF3',1500.00),('FF4',500.00),('FF5',2500.00); | SELECT freight_forwarder, total_cost FROM freight_costs; |
Which auto shows had the highest attendance in 2022 and were not held in the USA? | CREATE TABLE Auto_Show (id INT,name VARCHAR(50),year INT,location VARCHAR(50),attendance INT); INSERT INTO Auto_Show (id,name,year,location,attendance) VALUES (1,'New York Auto Show',2022,'USA',500000),(2,'Chicago Auto Show',2022,'USA',300000),(3,'Tokyo Auto Show',2022,'Japan',700000),(4,'Paris Auto Show',2022,'France'... | SELECT name, attendance FROM Auto_Show WHERE year = 2022 AND location <> 'USA' ORDER BY attendance DESC LIMIT 1; |
What is the total revenue for each sustainable sourcing method used by restaurant F for the quarter of Q1 2022? | CREATE TABLE Restaurants (RestaurantID int,Name varchar(50));CREATE TABLE SustainableSourcing (SourcingID int,RestaurantID int,SourcingMethod varchar(50),TotalRevenue decimal(10,2)); | SELECT SS.SourcingMethod, SUM(SS.TotalRevenue) as TotalRevenuePerMethod FROM SustainableSourcing SS INNER JOIN Restaurants R ON SS.RestaurantID = R.RestaurantID WHERE R.Name = 'F' AND QUARTER(SS.OrderDate) = 1 AND YEAR(SS.OrderDate) = 2022 GROUP BY SS.SourcingMethod; |
List all investors who have invested in companies with a high risk score (greater than 8). | CREATE TABLE investments (investor_id INT,company_id INT,risk_score INT); INSERT INTO investments (investor_id,company_id,risk_score) VALUES (1,1,9),(2,2,7),(3,3,8); CREATE TABLE companies (id INT,risk_score INT); INSERT INTO companies (id,risk_score) VALUES (1,10),(2,6),(3,8); | SELECT DISTINCT i.name FROM investments AS i JOIN companies AS c ON i.company_id = c.id WHERE c.risk_score > 8; |
What is the total area of sustainable urban projects in the city of "Chicago"? | CREATE TABLE sustainable_projects (project_id INT,area FLOAT,city_id INT,PRIMARY KEY (project_id)); INSERT INTO sustainable_projects (project_id,area,city_id) VALUES (1,5000.0,2),(2,7000.0,2),(3,3000.0,3); CREATE TABLE cities (city_id INT,city_name TEXT,PRIMARY KEY (city_id)); INSERT INTO cities (city_id,city_name) VAL... | SELECT SUM(area) FROM sustainable_projects JOIN cities ON sustainable_projects.city_id = cities.city_id WHERE cities.city_name = 'Chicago'; |
Recycling rates for all regions in 2020? | CREATE TABLE recycling_rates (region VARCHAR(50),year INT,rate DECIMAL(4,2)); INSERT INTO recycling_rates (region,year,rate) VALUES ('Africa',2020,0.35),('Asia',2020,0.47),('Europe',2020,0.60),('North America',2020,0.48),('South America',2020,0.42),('Oceania',2020,0.53); | SELECT region, rate FROM recycling_rates WHERE year = 2020; |
List all the forest types and their average carbon sequestration in 2019 | CREATE TABLE forest_types (type_id INT,type_name VARCHAR(50)); INSERT INTO forest_types (type_id,type_name) VALUES (1,'Pine'),(2,'Oak'),(3,'Maple'); CREATE TABLE carbon_sequestration (sequestration_id INT,type_id INT,year INT,sequestration DECIMAL(10,2)); INSERT INTO carbon_sequestration (sequestration_id,type_id,year,... | SELECT ft.type_name, AVG(cs.sequestration) as avg_sequestration FROM forest_types ft INNER JOIN carbon_sequestration cs ON ft.type_id = cs.type_id WHERE cs.year = 2019 GROUP BY ft.type_name; |
What is the average response time for emergency calls in the city of Austin? | CREATE TABLE emergency_calls (id INT,city VARCHAR(50),response_time INT); INSERT INTO emergency_calls (id,city,response_time) VALUES (1,'Austin',8); INSERT INTO emergency_calls (id,city,response_time) VALUES (2,'Austin',10); | SELECT AVG(response_time) FROM emergency_calls WHERE city = 'Austin'; |
Find the average temperature for each crop type in the 'crops' table. | CREATE TABLE crops (id INT,crop_type VARCHAR(255),temperature FLOAT); INSERT INTO crops (id,crop_type,temperature) VALUES (1,'corn',20.5),(2,'soybean',18.3),(3,'wheat',16.7); | SELECT crop_type, AVG(temperature) FROM crops GROUP BY crop_type; |
Calculate the total quantity of gold mined by each mine in Q1 2021 | CREATE TABLE mine (id INT,name TEXT,location TEXT);CREATE TABLE production (mine_id INT,date DATE,quantity INT); INSERT INTO mine VALUES (1,'Mine A','Country A'); INSERT INTO mine VALUES (2,'Mine B','Country B'); INSERT INTO production VALUES (1,'2021-01-01',100); INSERT INTO production VALUES (1,'2021-02-01',120); INS... | SELECT mine.name, SUM(production.quantity) AS total_qty FROM mine INNER JOIN production ON mine.id = production.mine_id WHERE production.date BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY mine.name; |
What is the maximum donation amount for each cause in the 'philanthropy.causes' table? | CREATE TABLE philanthropy.donation_amount_by_cause (donation_id INT,donor_id INT,cause_id INT,donation_amount DECIMAL); | SELECT c.cause_name, MAX(dam.donation_amount) FROM philanthropy.causes c JOIN philanthropy.donation_amount_by_cause dam ON c.cause_id = dam.cause_id GROUP BY c.cause_name; |
What is the total amount of research grants awarded to female graduate students? | CREATE TABLE graduate_students (student_id INT,name VARCHAR(50),gender VARCHAR(50)); INSERT INTO graduate_students (student_id,name,gender) VALUES (1,'Alice','Female'),(2,'Bob','Male'),(3,'Carlos','Male'); CREATE TABLE research_grants (grant_id INT,student_id INT,amount INT); INSERT INTO research_grants (grant_id,stude... | SELECT SUM(rg.amount) FROM research_grants rg JOIN graduate_students gs ON rg.student_id = gs.student_id WHERE gs.gender = 'Female'; |
What is the total number of marine pollution control initiatives in the 'Arctic' and 'Antarctic' regions? | CREATE TABLE marine_pollution_control (id INT,initiative_name TEXT,region TEXT);INSERT INTO marine_pollution_control (id,initiative_name,region) VALUES (1,'Ocean Cleanup Project','Arctic'),(2,'Coastal Waste Management','Antarctic'),(3,'Plastic Pollution Reduction','Atlantic'); | SELECT COUNT(*) FROM marine_pollution_control WHERE region IN ('Arctic', 'Antarctic'); |
List the top 2 employees with the highest salaries in the company. | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Salary FLOAT); INSERT INTO Employees (EmployeeID,Name,Department,Salary) VALUES (1,'John Doe','IT',75000.00),(2,'Jane Smith','IT',80000.00),(3,'Mike Johnson','HR',60000.00); | SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY Salary DESC) AS rn, EmployeeID, Name, Department, Salary FROM Employees) t WHERE rn <= 2; |
How many users streamed a song per day in 'music_streaming' table? | CREATE TABLE music_streaming (user_id INT,song_id INT,duration FLOAT,date DATE); | SELECT date, COUNT(DISTINCT user_id) as users_per_day FROM music_streaming GROUP BY date ORDER BY date; |
What is the average price of pottery from Indigenous artists in Canada? | CREATE TABLE ArtPieces (id INT,title VARCHAR(255),type VARCHAR(255),price DECIMAL(10,2),sale_year INT,artist_nationality VARCHAR(255)); INSERT INTO ArtPieces (id,title,type,price,sale_year,artist_nationality) VALUES (1,'Pottery1','Pottery',300,2021,'Canada - Indigenous'); | SELECT AVG(price) FROM ArtPieces WHERE type = 'Pottery' AND artist_nationality LIKE '%Canada - Indigenous%'; |
What is the total number of military personnel in the 'Air Force'? | CREATE TABLE MilitaryPersonnel (id INT,name VARCHAR(100),rank VARCHAR(50),service VARCHAR(50)); INSERT INTO MilitaryPersonnel (id,name,rank,service) VALUES (1,'John Doe','Colonel','Air Force'); INSERT INTO MilitaryPersonnel (id,name,rank,service) VALUES (2,'Jane Smith','Captain','Navy'); | SELECT COUNT(*) FROM MilitaryPersonnel WHERE service = 'Air Force'; |
What is the total value of Shariah-compliant loans issued to clients in the age group 20-30, ordered by loan date? | CREATE TABLE loan (loan_id INT,client_id INT,age INT,loan_amount DECIMAL(10,2),loan_date DATE); INSERT INTO loan (loan_id,client_id,age,loan_amount,loan_date) VALUES (3,3,23,6000.00,'2022-03-01'),(4,4,31,8000.00,'2022-04-01'); | SELECT SUM(loan_amount) total_loan_amount FROM loan WHERE age BETWEEN 20 AND 30 ORDER BY loan_date; |
What is the total number of volunteer hours contributed by volunteers in each quarter of 2021? | CREATE TABLE Volunteers (id INT,name TEXT,country TEXT,hours FLOAT,quarter TEXT,year INT); INSERT INTO Volunteers (id,name,country,hours,quarter,year) VALUES (1,'Alice','USA',5.0,'Q3',2021),(2,'Bob','Canada',7.5,'Q3',2021),(3,'Eve','Canada',3.0,'Q3',2021),(4,'Frank','USA',6.0,'Q2',2021),(5,'Grace','USA',8.0,'Q2',2021); | SELECT quarter, SUM(hours) FROM Volunteers GROUP BY quarter; |
Identify spacecraft with mass above 16000 kg | CREATE TABLE Spacecraft (id INT,name VARCHAR(30),mass FLOAT); INSERT INTO Spacecraft (id,name,mass) VALUES (1,'Apollo',14000.0); INSERT INTO Spacecraft (id,name,mass) VALUES (2,'Saturn V',16000.0); INSERT INTO Spacecraft (id,name,mass) VALUES (3,'Space Shuttle',12000.0); | SELECT name FROM Spacecraft WHERE mass > 16000; |
What is the average price of a pre-roll in each state, rounded to the nearest dollar? | CREATE TABLE PreRollPrices (state VARCHAR(255),price DECIMAL(10,2),product VARCHAR(255)); INSERT INTO PreRollPrices (state,price,product) VALUES ('CA',7.5,'Pre-roll'),('CO',6.5,'Pre-roll'),('OR',8.0,'Pre-roll'),('WA',7.0,'Pre-roll'),('NV',8.5,'Pre-roll'); | SELECT state, ROUND(AVG(price)) as average_price FROM PreRollPrices WHERE product = 'Pre-roll' GROUP BY state; |
Count the number of domestic and foreign vehicles, with a minimum mpg of 30 | CREATE TABLE vehicle_count (id INT,vehicle_make VARCHAR(50),mpg INT,is_domestic BOOLEAN); INSERT INTO vehicle_count (id,vehicle_make,mpg,is_domestic) VALUES (1,'Toyota',32,false),(2,'Honda',35,false),(3,'Ford',31,true),(4,'Chevy',28,true),(5,'Tesla',null,true); | SELECT is_domestic, COUNT(*) as count FROM vehicle_count WHERE mpg >= 30 GROUP BY is_domestic; |
Who are the top 3 targets of phishing attacks in the current month and their total number of attacks? | CREATE TABLE if not exists phishing_targets (target_id INT,target_name VARCHAR,attack_count INT); INSERT INTO phishing_targets (target_id,target_name,attack_count) VALUES (1,'David',12),(2,'Eva',18),(3,'Frank',8); | SELECT target_id, target_name, SUM(attack_count) as total_attacks FROM phishing_targets WHERE attack_date >= DATEADD(month, 0, GETDATE()) AND target_name IN ('David', 'Eva', 'Frank') GROUP BY target_id, target_name ORDER BY total_attacks DESC LIMIT 3; |
What is the average well depth for wells in the Caspian Sea, grouped by the year they were drilled? | CREATE TABLE wells (well_id INT,well_name TEXT,well_depth FLOAT,drill_year INT,region TEXT); INSERT INTO wells (well_id,well_name,well_depth,drill_year,region) VALUES (1,'Well A',10000,2018,'Caspian Sea'),(2,'Well B',15000,2019,'Caspian Sea'),(3,'Well C',8000,2020,'Caspian Sea'); | SELECT drill_year, AVG(well_depth) as avg_well_depth FROM wells WHERE region = 'Caspian Sea' GROUP BY drill_year; |
Find the number of unique users who have engaged with content in 'content_trends' table for the last week? | CREATE TABLE content_trends (content_id INT,user_id INT,user_country VARCHAR(50),user_engagement INT,engagement_date DATE); | SELECT COUNT(DISTINCT user_id) FROM content_trends WHERE engagement_date >= CURDATE() - INTERVAL 7 DAY AND user_engagement > 0; |
What are the top 3 countries with the highest R&D expenditures in the pharmaceuticals industry in 2020? | CREATE TABLE rd_expenditures (country VARCHAR(50),industry VARCHAR(50),amount NUMERIC,year INT); INSERT INTO rd_expenditures (country,industry,amount,year) VALUES ('USA','Pharmaceuticals',80000,2020),('Germany','Pharmaceuticals',55000,2020),('Japan','Pharmaceuticals',42000,2020); | SELECT country, SUM(amount) AS total_expenditure FROM rd_expenditures WHERE industry = 'Pharmaceuticals' AND year = 2020 GROUP BY country ORDER BY total_expenditure DESC LIMIT 3; |
What is the minimum budget for an infrastructure project? | CREATE TABLE infrastructure_projects (id INT,project_name VARCHAR(50),location VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO infrastructure_projects (id,project_name,location,budget) VALUES (1,'Highway 101 Expansion','California',5000000),(2,'Bridge Replacement','New York',3000000),(3,'Transit System Upgrade','Texas',... | SELECT MIN(budget) as min_budget FROM infrastructure_projects; |
How many clients have an investment greater than $3,000 in the "Equity" fund? | CREATE TABLE clients (client_id INT,name VARCHAR(50),investment FLOAT); CREATE TABLE fund_investments (client_id INT,fund_name VARCHAR(50),investment FLOAT); | SELECT COUNT(DISTINCT clients.client_id) FROM clients INNER JOIN fund_investments ON clients.client_id = fund_investments.client_id WHERE clients.investment > 3000 AND fund_investments.fund_name = 'Equity'; |
Find the names and maintenance dates of structures in New York with resilience scores below 60 | CREATE TABLE Infrastructure (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255),resilience_score INT); CREATE TABLE Maintenance (id INT,infrastructure_id INT,maintenance_date DATE); INSERT INTO Infrastructure (id,name,type,location,resilience_score) VALUES (1,'Road A','Road','New York',55); INSERT INTO In... | SELECT Infrastructure.name, Maintenance.maintenance_date FROM Infrastructure INNER JOIN Maintenance ON Infrastructure.id = Maintenance.infrastructure_id WHERE Infrastructure.location = 'New York' AND Infrastructure.resilience_score < 60; |
Who is the user with the most followers in Africa in the last week? | CREATE TABLE user_followers(username VARCHAR(30),region VARCHAR(20),followers INT,follow_date DATE); INSERT INTO user_followers(username,region,followers,follow_date) VALUES('Obi','Africa',1000,'2021-10-01'),('Pat','Africa',1200,'2021-10-02'),('Quin','Africa',1400,'2021-10-03'),('Ria','Africa',1600,'2021-10-04'); | SELECT username, MAX(followers) as max_followers FROM (SELECT username, followers, ROW_NUMBER() OVER (PARTITION BY username ORDER BY follow_date DESC) as rn FROM user_followers WHERE region = 'Africa' AND follow_date >= DATEADD(week, -1, CURRENT_DATE)) t GROUP BY username |
Update the email addresses of users who have subscribed to the newsletter in the last week in the users table | CREATE TABLE users (id INT,name VARCHAR(50),email VARCHAR(50),subscribed_to_newsletter BOOLEAN); | UPDATE users SET email = CONCAT(email, '_new') WHERE subscribed_to_newsletter = true AND signup_date > DATE_SUB(CURDATE(), INTERVAL 1 WEEK); |
Which students have not completed their mandatory mental health training? | CREATE TABLE students (id INT,name VARCHAR(255)); CREATE TABLE mental_health_training (id INT,student_id INT,completed_date DATE); INSERT INTO students (id,name) VALUES (1,'Student A'),(2,'Student B'),(3,'Student C'); INSERT INTO mental_health_training (id,student_id,completed_date) VALUES (1,1,'2021-06-01'),(2,2,NULL)... | SELECT s.name FROM students s LEFT JOIN mental_health_training m ON s.id = m.student_id WHERE m.completed_date IS NULL; |
How many municipalities in France have a recycling rate below 30%? | CREATE TABLE FrenchMunicipalities (municipality VARCHAR(50),recycling_rate FLOAT); INSERT INTO FrenchMunicipalities (municipality,recycling_rate) VALUES ('Paris',28.5),('Lyon',35.7),('Marseille',29.6),('Toulouse',32.8),('Nice',31.2); | SELECT COUNT(*) FROM FrenchMunicipalities WHERE recycling_rate < 30; |
What is the highest number of points scored in a single game in NFL history? | CREATE TABLE NFL_Matches (MatchID INT,HomeTeam VARCHAR(50),AwayTeam VARCHAR(50),HomeTeamScore INT,AwayTeamScore INT); INSERT INTO NFL_Matches (MatchID,HomeTeam,AwayTeam,HomeTeamScore,AwayTeamScore) VALUES (1,'Chicago Bears','Washington Redskins',73,0); | SELECT MAX(HomeTeamScore + AwayTeamScore) FROM NFL_Matches; |
Delete all claim records for policy number 8 from the claims table | CREATE TABLE claims (claim_number INT,policy_number INT,claim_amount INT,claim_date DATE); INSERT INTO claims (claim_number,policy_number,claim_amount,claim_date) VALUES (1,8,1000,'2018-06-20'); INSERT INTO claims (claim_number,policy_number,claim_amount,claim_date) VALUES (2,8,2000,'2019-01-01'); | DELETE FROM claims WHERE policy_number = 8; |
What is the total number of mental health facilities in each state that have a health equity rating below 5? | CREATE TABLE MentalHealthFacilities (Id INT,State VARCHAR(255),HealthEquityRating INT); INSERT INTO MentalHealthFacilities (Id,State,HealthEquityRating) VALUES (1,'California',9); INSERT INTO MentalHealthFacilities (Id,State,HealthEquityRating) VALUES (2,'Texas',7); INSERT INTO MentalHealthFacilities (Id,State,HealthEq... | SELECT State, COUNT(*) FROM MentalHealthFacilities WHERE HealthEquityRating < 5 GROUP BY State; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.