instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total donation amount for each program in Japan? | CREATE TABLE Donations (id INT,donation_amount DECIMAL(10,2),donation_date DATE,program VARCHAR(50),country VARCHAR(50)); CREATE TABLE Programs (id INT,program VARCHAR(50),country VARCHAR(50)); INSERT INTO Donations (id,donation_amount,donation_date,program,country) VALUES (1,50.00,'2021-01-01','Education','Japan'); INSERT INTO Donations (id,donation_amount,donation_date,program,country) VALUES (2,100.00,'2021-01-02','Health','Japan'); INSERT INTO Programs (id,program,country) VALUES (1,'Education','Japan'); INSERT INTO Programs (id,program,country) VALUES (2,'Health','Japan'); | SELECT p.program, SUM(d.donation_amount) as total_donations FROM Donations d INNER JOIN Programs p ON d.program = p.program WHERE d.country = 'Japan' GROUP BY p.program; |
What is the total number of members who have attended a class in the past month and have a membership type of 'Elite'? | CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),MembershipType VARCHAR(20)); INSERT INTO Members (MemberID,Age,Gender,MembershipType) VALUES (1,35,'Female','Elite'),(2,45,'Male','Basic'),(3,28,'Female','Premium'),(4,32,'Male','Elite'),(5,48,'Female','Basic'); CREATE TABLE ClassAttendance (MemberID INT,Class VARCHAR(20),Date DATE); INSERT INTO ClassAttendance (MemberID,Class,Date) VALUES (1,'Cycling','2022-01-01'),(2,'Yoga','2022-01-02'),(3,'Cycling','2022-01-03'),(4,'Yoga','2022-01-04'),(5,'Pilates','2022-01-05'),(1,'Cycling','2022-01-06'),(2,'Yoga','2022-01-07'),(3,'Cycling','2022-01-08'),(4,'Yoga','2022-01-09'),(5,'Pilates','2022-01-10'); | SELECT COUNT(*) FROM Members JOIN ClassAttendance ON Members.MemberID = ClassAttendance.MemberID WHERE Members.MembershipType = 'Elite' AND ClassAttendance.Date >= DATEADD(month, -1, GETDATE()); |
What is the average monthly data usage for each mobile network type? | CREATE TABLE mobile_usage (network_type VARCHAR(20),data_usage FLOAT); INSERT INTO mobile_usage (network_type,data_usage) VALUES ('3G',2.5),('4G',4.2),('5G',5.9); | SELECT network_type, AVG(data_usage) FROM mobile_usage GROUP BY network_type; |
What is the total sales revenue for each drug in Q1 2020? | CREATE TABLE drugs (drug_id INT,drug_name TEXT); INSERT INTO drugs (drug_id,drug_name) VALUES (1001,'DrugA'),(1002,'DrugB'); CREATE TABLE sales (sale_id INT,drug_id INT,sale_date DATE,revenue FLOAT); INSERT INTO sales (sale_id,drug_id,sale_date,revenue) VALUES (1,1001,'2020-01-05',15000),(2,1001,'2020-03-18',22000),(3,1002,'2020-01-25',18000),(4,1002,'2020-02-14',19000); | SELECT drug_name, SUM(revenue) as Q1_2020_Revenue FROM sales JOIN drugs ON sales.drug_id = drugs.drug_id WHERE sale_date BETWEEN '2020-01-01' AND '2020-03-31' GROUP BY drug_name; |
Find the daily average revenue for 'Breakfast' and 'Lunch' menu categories in the last week. | CREATE TABLE daily_revenue(menu_category VARCHAR(20),revenue DECIMAL(10,2),order_date DATE); INSERT INTO daily_revenue(menu_category,revenue,order_date) VALUES ('Breakfast',4500,'2021-04-01'),('Lunch',5500,'2021-04-01'),('Breakfast',4000,'2021-04-02'),('Lunch',6000,'2021-04-02'); | SELECT menu_category, AVG(revenue) AS avg_daily_revenue FROM daily_revenue WHERE order_date >= (SELECT DATE(CURRENT_DATE - INTERVAL 7 DAY)) AND menu_category IN ('Breakfast', 'Lunch') GROUP BY menu_category; |
What is the total cost of reverse logistics for each month in the given data? | CREATE TABLE reverse_logistics (id INT,date DATE,cost FLOAT); INSERT INTO reverse_logistics (id,date,cost) VALUES [(1,'2022-01-01',500.0),(2,'2022-01-05',300.0),(3,'2022-01-10',200.0),(4,'2022-02-01',400.0),(5,'2022-02-05',350.0),(6,'2022-02-10',250.0),(7,'2022-03-01',600.0),(8,'2022-03-05',450.0),(9,'2022-03-10',300.0)]; | SELECT DATE_FORMAT(date, '%Y-%m') AS month, SUM(cost) AS total_cost FROM reverse_logistics GROUP BY month; |
Which type of support was provided the most in each region? | CREATE TABLE SupportByRegion (Id INT,Region VARCHAR(50),SupportType VARCHAR(50),SupportValue INT); INSERT INTO SupportByRegion (Id,Region,SupportType,SupportValue) VALUES (1,'Middle East','Food',100),(2,'Asia','Shelter',200),(3,'Middle East','Medical',150),(4,'South America','Food',250); | SELECT Region, SupportType, SUM(SupportValue) AS TotalSupportValue, RANK() OVER (PARTITION BY Region ORDER BY SUM(SupportValue) DESC) AS Rank FROM SupportByRegion GROUP BY Region, SupportType HAVING RANK() OVER (PARTITION BY Region ORDER BY SUM(SupportValue) DESC) = 1; |
Select all records from the 'mammals_view' view | CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(100),species VARCHAR(50),population INT); INSERT INTO animals (id,name,species,population) VALUES (1,'Giraffe','Mammal',30000),(2,'Elephant','Mammal',5000); CREATE VIEW mammals_view AS SELECT * FROM animals WHERE species = 'Mammal'; | SELECT * FROM mammals_view; |
What was the average donation amount by state? | CREATE TABLE Donations (id INT,state VARCHAR(2),donation_amount DECIMAL(10,2)); INSERT INTO Donations (id,state,donation_amount) VALUES (1,'NY',50.00),(2,'CA',75.00),(3,'TX',25.00); | SELECT AVG(donation_amount) as avg_donation, state FROM Donations GROUP BY state; |
What was the total water consumption in the residential sector in Q1 2021? | CREATE TABLE residential_water_consumption (year INT,quarter INT,sector VARCHAR(20),consumption FLOAT); INSERT INTO residential_water_consumption (year,quarter,sector,consumption) VALUES (2021,1,'residential',18000); INSERT INTO residential_water_consumption (year,quarter,sector,consumption) VALUES (2021,2,'residential',19000); | SELECT SUM(consumption) FROM residential_water_consumption WHERE year = 2021 AND sector = 'residential' AND quarter BETWEEN 1 AND 3; |
What is the distribution of mobile users by network type? | CREATE TABLE mobile_subscribers (subscriber_id INT,network_type VARCHAR(10)); | SELECT network_type, COUNT(*) FROM mobile_subscribers GROUP BY network_type; |
List all defense contracts and their negotiation dates for General Dynamics in South America. | CREATE TABLE General_Contracts (id INT,corporation VARCHAR(20),region VARCHAR(20),contract_name VARCHAR(20),negotiation_date DATE); INSERT INTO General_Contracts (id,corporation,region,contract_name,negotiation_date) VALUES (1,'General Dynamics','South America','Contract A','2022-03-15'); | SELECT contract_name, negotiation_date FROM General_Contracts WHERE corporation = 'General Dynamics' AND region = 'South America'; |
Which mobile plans were launched before April 2022? | CREATE TABLE mobile_plans (plan_name TEXT,launch_date DATE); | SELECT plan_name FROM mobile_plans WHERE launch_date < '2022-04-01'; |
Insert a new record into the 'suppliers' table with the following data: 'Supplier 5', 'New York', 'USA', 'sustainable_fabrics@email.com' | CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),city VARCHAR(50),country VARCHAR(50),email VARCHAR(50)); | INSERT INTO suppliers (supplier_name, city, country, email) VALUES ('Supplier 5', 'New York', 'USA', 'sustainable_fabrics@email.com'); |
What is the total CO2 emission for tourists visiting India? | CREATE TABLE tourism_emissions (visitor_country VARCHAR(255),co2_emission FLOAT); INSERT INTO tourism_emissions (visitor_country,co2_emission) VALUES ('India',2.5); | SELECT SUM(co2_emission) FROM tourism_emissions WHERE visitor_country = 'India'; |
What is the maximum and minimum funding received by biotech startups in each country? | CREATE SCHEMA if not exists biotech;USE biotech;CREATE TABLE if not exists startups (name VARCHAR(255),country VARCHAR(255),funding FLOAT);INSERT INTO startups (name,country,funding) VALUES ('Startup1','USA',5000000),('Startup2','Canada',7000000),('Startup3','USA',3000000),('Startup4','UK',8000000),('Startup5','USA',1000000),('Startup6','Canada',4000000); | SELECT country, MAX(funding) as max_funding, MIN(funding) as min_funding FROM startups GROUP BY country; |
Update the email address of the user with ID 98765 to 'new.email@example.com'. | CREATE TABLE users (id INT,name VARCHAR(255),email VARCHAR(255)); | UPDATE users SET email = 'new.email@example.com' WHERE id = 98765; |
What is the maximum dissolved oxygen level in the Atlantic Ocean? | CREATE TABLE location (location_id INT,location_name TEXT); INSERT INTO location (location_id,location_name) VALUES (1,'Atlantic Ocean'); CREATE TABLE measurement (measurement_id INT,location_id INT,dissolved_oxygen FLOAT); INSERT INTO measurement (measurement_id,location_id,dissolved_oxygen) VALUES (1,1,8.5),(2,1,8.2),(3,1,8.3),(4,1,8.8),(5,1,8.9); | SELECT MAX(dissolved_oxygen) FROM measurement WHERE location_id = (SELECT location_id FROM location WHERE location_name = 'Atlantic Ocean'); |
What is the total number of technology for social good initiatives in underrepresented communities? | CREATE TABLE social_good_underserved (initiative_name VARCHAR(100),community VARCHAR(50)); INSERT INTO social_good_underserved (initiative_name,community) VALUES ('Tech4All','Rural America'),('DigitalEmpowerment','Indigenous Australia'),('TechInclusion','Urban Poverty Europe'); | SELECT SUM(1) FROM social_good_underserved WHERE community IN ('Rural America', 'Indigenous Australia', 'Urban Poverty Europe'); |
Update the "area_covered" in the "irrigation_system" table where the "system_id" is 3 to 15.5 | CREATE TABLE irrigation_system (system_id INT,system_type TEXT,area_covered FLOAT,water_usage INT); | UPDATE irrigation_system SET area_covered = 15.5 WHERE system_id = 3; |
What is the maximum number of likes on posts from users aged 18-24, in the 'North America' region, in the past month? | CREATE TABLE users (id INT,age INT,country TEXT,posts TEXT); | SELECT MAX(likes) FROM (SELECT content, MAX(likes) AS likes FROM posts JOIN users ON posts.id = users.id WHERE users.age BETWEEN 18 AND 24 AND users.country IN (SELECT country FROM countries WHERE region = 'North America') AND posts.timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW() GROUP BY content) AS subquery; |
What is the number of unique patients served by community health workers in each region? | CREATE TABLE community_health_workers (worker_id INT,patient_id INT,region VARCHAR(10)); INSERT INTO community_health_workers (worker_id,patient_id,region) VALUES (1,100,'Northeast'),(1,101,'Northeast'),(2,102,'Southeast'),(3,103,'Midwest'),(3,104,'Midwest'),(3,105,'Midwest'); | SELECT region, COUNT(DISTINCT patient_id) as unique_patients FROM community_health_workers GROUP BY region; |
What is the minimum stay length in days for visitors from Oceania who visited adventure tourism destinations in 2022? | CREATE TABLE TourismDestinations (DestinationID INT,DestinationType VARCHAR(20)); INSERT INTO TourismDestinations (DestinationID,DestinationType) VALUES (1,'Adventure'); CREATE TABLE Visitors (VisitorID INT,Nationality VARCHAR(20),DestinationID INT,StayLength INT,VisitYear INT); INSERT INTO Visitors (VisitorID,Nationality,DestinationID,StayLength,VisitYear) VALUES (1,'Australian',1,21,2022),(2,'NewZealander',1,14,2022); | SELECT MIN(StayLength/7.0) FROM Visitors WHERE Nationality IN ('Australian', 'NewZealander') AND DestinationID = 1 AND VisitYear = 2022; |
What is the distribution of songs per album? | CREATE TABLE Albums (album_id INT,album_name VARCHAR(255)); INSERT INTO Albums (album_id,album_name) VALUES (1,'Album1'),(2,'Album2'),(3,'Album3'); CREATE TABLE Songs (song_id INT,album_id INT,song_name VARCHAR(255)); INSERT INTO Songs (song_id,album_id,song_name) VALUES (1,1,'Song1'),(2,1,'Song2'),(3,2,'Song3'),(4,3,'Song4'); | SELECT a.album_name, COUNT(s.song_id) AS song_count FROM Albums a JOIN Songs s ON a.album_id = s.album_id GROUP BY a.album_name; |
What is the average program impact score for the 'Indigenous' demographic in the 'Performing Arts' category? | CREATE SCHEMA if not exists arts_culture; CREATE TABLE if not exists arts_culture.programs(program_id INT,program_name VARCHAR(50),demographic VARCHAR(10),category VARCHAR(20),impact_score INT); | SELECT AVG(programs.impact_score) FROM arts_culture.programs WHERE programs.demographic = 'Indigenous' AND programs.category = 'Performing Arts'; |
How many volunteers signed up in each state in the USA in 2021? | CREATE TABLE volunteer_signups (signup_id INT,signup_date DATE,state VARCHAR(50)); INSERT INTO volunteer_signups VALUES (1,'2021-01-01','NY'),(2,'2021-02-01','CA'),(3,'2021-03-01','TX'),(4,'2021-04-01','FL'); | SELECT state, COUNT(*) as num_volunteers FROM volunteer_signups WHERE signup_date BETWEEN '2021-01-01' AND '2021-12-31' AND state IN ('NY', 'CA', 'TX', 'FL') GROUP BY state; |
What is the average sustainability score for each fabric, grouped by material type? | CREATE TABLE Fabrics (id INT,fabric_type VARCHAR(20),fabric VARCHAR(20),source_country VARCHAR(50),sustainability_score INT); INSERT INTO Fabrics (id,fabric_type,fabric,source_country,sustainability_score) VALUES (1,'Natural','Cotton','India',80),(2,'Synthetic','Polyester','China',50),(3,'Natural','Wool','Australia',90),(4,'Synthetic','Silk','China',60),(5,'Mixed','Denim','USA',70); | SELECT fabric_type, AVG(sustainability_score) FROM Fabrics GROUP BY fabric_type; |
List the number of investments made in companies founded by underrepresented minorities in the last 5 years. | CREATE TABLE investment (id INT,company_id INT,investor TEXT,year INT,amount FLOAT); INSERT INTO investment (id,company_id,investor,year,amount) VALUES (1,1,'Tiger Global',2022,10000000.0); CREATE TABLE company (id INT,name TEXT,industry TEXT,founder TEXT,PRIMARY KEY (id)); INSERT INTO company (id,name,industry,founder) VALUES (1,'InnoLabs','Biotech','Underrepresented Minority'); | SELECT COUNT(*) FROM investment i JOIN company c ON i.company_id = c.id WHERE c.founder = 'Underrepresented Minority' AND i.year >= (SELECT YEAR(CURRENT_DATE()) - 5); |
How many hospital beds are occupied by rural patients with mental health issues? | CREATE TABLE mental_health_patients (id INTEGER,hospital VARCHAR(255),location VARCHAR(255),beds INTEGER); | SELECT SUM(beds) FROM mental_health_patients WHERE location LIKE '%rural%' AND beds > 0; |
List all green-certified buildings in New York and their owners' names. | CREATE TABLE Buildings (BuildingID int,Certification varchar(20),City varchar(20)); CREATE TABLE Owners (OwnerID int,BuildingID int,Name varchar(50)); INSERT INTO Buildings (BuildingID,Certification,City) VALUES (1,'Green','New York'); INSERT INTO Owners (OwnerID,BuildingID,Name) VALUES (1,1,'John Doe'); | SELECT Buildings.Certification, Owners.Name FROM Buildings INNER JOIN Owners ON Buildings.BuildingID = Owners.BuildingID WHERE Buildings.City = 'New York' AND Buildings.Certification = 'Green'; |
What was the most recent Mars rover launch? | CREATE TABLE Mars_Rover_Launches (rover_name TEXT,launch_date DATE); INSERT INTO Mars_Rover_Launches (rover_name,launch_date) VALUES ('Sojourner','1996-12-04'),('Spirit','2003-06-10'),('Opportunity','2003-07-07'),('Curiosity','2011-11-26'),('Perseverance','2020-07-30'); | SELECT rover_name, launch_date FROM Mars_Rover_Launches ORDER BY launch_date DESC LIMIT 1; |
Identify states that have no mental health parity laws. | CREATE TABLE mental_health_parity (id INT,law_name TEXT,state TEXT); INSERT INTO mental_health_parity (id,law_name,state) VALUES (1,'Parity Act 1','NY'),(2,'Parity Act 2','CA'); | SELECT state FROM mental_health_parity WHERE law_name IS NULL GROUP BY state; |
What are the conservation efforts in the Arctic? | CREATE TABLE if not exists conservation_arctic (id INT PRIMARY KEY,organization VARCHAR(255),project VARCHAR(255),location VARCHAR(255)); | SELECT DISTINCT organization, project FROM conservation_arctic WHERE location = 'Arctic'; |
Determine the most frequently ordered dish that is not a drink. | CREATE TABLE orders (id INT,dish_id INT,order_date DATE); INSERT INTO orders (id,dish_id,order_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-01'),(3,1,'2022-01-02'),(4,3,'2022-01-02'),(5,1,'2022-01-03'),(6,4,'2022-01-03'),(7,2,'2022-01-04'),(8,5,'2022-01-04'),(9,6,'2022-01-05'),(10,1,'2022-01-05'); CREATE TABLE dishes (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO dishes (id,name,type) VALUES (1,'Chicken Curry','Entree'),(2,'Coke','Drink'),(3,'Beef Stew','Entree'),(4,'Water','Drink'),(5,'Tuna Salad','Entree'),(6,'Espresso','Drink'); | SELECT dishes.name, COUNT(orders.id) as times_ordered FROM dishes INNER JOIN orders ON dishes.id = orders.dish_id WHERE type != 'Drink' GROUP BY dishes.id ORDER BY times_ordered DESC LIMIT 1; |
What is the minimum donation amount for each donor_type in the 'Donors' table? | CREATE TABLE Donors (donor_id INT,name VARCHAR(50),donor_type VARCHAR(20),donation_amount DECIMAL(10,2)); | SELECT donor_type, MIN(donation_amount) FROM Donors GROUP BY donor_type; |
Which graduate programs have the highest acceptance rates? | CREATE TABLE grad_programs (program_id INT,program_name VARCHAR(50),num_applicants INT,num_accepted INT); INSERT INTO grad_programs (program_id,program_name,num_applicants,num_accepted) VALUES (1,'Computer Science',2000,1200),(2,'English',1500,800),(3,'Mathematics',1000,600); | SELECT program_name, (num_accepted * 1.0 / num_applicants) AS acceptance_rate FROM grad_programs ORDER BY acceptance_rate DESC; |
Find the total weight of satellites launched by SpaceTech Inc. since 2018 | CREATE TABLE Satellites (SatelliteID INT,SatelliteName VARCHAR(50),LaunchDate DATE,Manufacturer VARCHAR(50),Weight DECIMAL(10,2),Orbit VARCHAR(50)); INSERT INTO Satellites (SatelliteID,SatelliteName,LaunchDate,Manufacturer,Weight,Orbit) VALUES (1,'Sat1','2020-01-01','SpaceTech Inc.',500.00,'GEO'); | SELECT SUM(Weight) FROM Satellites WHERE Manufacturer = 'SpaceTech Inc.' AND YEAR(LaunchDate) >= 2018; |
Insert new agricultural innovation projects in South America with a budget greater than $50,000. | CREATE TABLE agri_innov (id INT,name VARCHAR(255),region VARCHAR(255),budget FLOAT); | INSERT INTO agri_innov (id, name, region, budget) VALUES (4, 'Precision Agriculture', 'South America', 75000.00); |
What are the average and total quantities of unsold garments by color? | CREATE TABLE unsold_garments (id INT,garment_type VARCHAR(20),color VARCHAR(20),quantity INT); | SELECT color, AVG(quantity) AS avg_quantity, SUM(quantity) AS total_quantity FROM unsold_garments GROUP BY color; |
What is the minimum rating of TV shows produced in the last 5 years, grouped by genre? | CREATE TABLE tv_shows (id INT,title VARCHAR(100),release_year INT,rating DECIMAL(2,1),genre VARCHAR(50)); INSERT INTO tv_shows (id,title,release_year,rating,genre) VALUES (1,'TVShow1',2018,7.8,'Drama'),(2,'TVShow2',2020,6.3,'Comedy'),(3,'TVShow3',2019,8.5,'Action'); | SELECT genre, MIN(rating) FROM tv_shows WHERE release_year >= YEAR(CURDATE()) - 5 GROUP BY genre; |
What is the most common type of open pedagogy resource used by students in the "Townside" school district? | CREATE TABLE resources (resource_id INT,district VARCHAR(20),type VARCHAR(20)); INSERT INTO resources (resource_id,district,type) VALUES (1,'Townside','Article'),(2,'Townside','Video'),(3,'Townside','Article'),(4,'Townside','Podcast'); | SELECT type, COUNT(*) FROM resources WHERE district = 'Townside' GROUP BY type ORDER BY COUNT(*) DESC LIMIT 1; |
What is the average production rate of silver mines in Mexico? | CREATE TABLE silver_mines (id INT,name TEXT,location TEXT,production_rate FLOAT); INSERT INTO silver_mines (id,name,location,production_rate) VALUES (1,'Fresnillo','Zacatecas,Mexico',12.6),(2,'Penasquito','Zacatecas,Mexico',10.2),(3,'Buenavista','Sonora,Mexico',7.5); | SELECT AVG(production_rate) FROM silver_mines WHERE location LIKE '%Mexico%'; |
What is the total CO2 emission for flights between New Zealand and Pacific Islands? | CREATE TABLE flights (id INT,origin TEXT,destination TEXT,co2_emission INT); INSERT INTO flights (id,origin,destination,co2_emission) VALUES (1,'New Zealand','Fiji',200),(2,'New Zealand','Tonga',250),(3,'Samoa','New Zealand',180); | SELECT SUM(f.co2_emission) as total_emission FROM flights f WHERE (f.origin = 'New Zealand' AND f.destination LIKE 'Pacific%') OR (f.destination = 'New Zealand' AND f.origin LIKE 'Pacific%'); |
List the number of hotels in each category that have a virtual tour. | CREATE TABLE category_virtualtours (category VARCHAR(255),has_virtualtour INT); INSERT INTO category_virtualtours (category,has_virtualtour) VALUES ('luxury',1); INSERT INTO category_virtualtours (category,has_virtualtour) VALUES ('economy',0); | SELECT category, has_virtualtour FROM category_virtualtours WHERE has_virtualtour = 1; |
How many songs are there in each language in the music catalog? | CREATE TABLE music_catalog (id INT,title VARCHAR(255),artist VARCHAR(100),language VARCHAR(50),release_year INT); INSERT INTO music_catalog (id,title,artist,language,release_year) VALUES (1,'Song4','Artist7','English',2021),(2,'Song5','Artist8','Spanish',2021),(3,'Song6','Artist9','French',2021); | SELECT language, COUNT(*) as songs_per_language FROM music_catalog GROUP BY language; |
Identify broadband subscribers with the highest data usage in regions where the average mobile data usage is above 3GB. | CREATE TABLE mobile_subscribers (subscriber_id INT,region_id INT,monthly_data_usage DECIMAL(10,2)); INSERT INTO mobile_subscribers (subscriber_id,region_id,monthly_data_usage) VALUES (1,1,3.2),(2,2,1.8),(3,3,4.5),(4,4,2.9),(5,1,3.6),(6,2,2.1),(7,3,4.9),(8,4,3.0); CREATE TABLE broadband_subscribers (subscriber_id INT,region_id INT,monthly_data_usage DECIMAL(10,2)); INSERT INTO broadband_subscribers (subscriber_id,region_id,monthly_data_usage) VALUES (9,1,12.0),(10,2,15.5),(11,3,8.7),(12,4,11.2),(13,1,10.0),(14,2,16.0),(15,3,9.5),(16,4,13.0); | SELECT subscriber_id, region_id, monthly_data_usage FROM broadband_subscribers b WHERE b.region_id IN (SELECT m.region_id FROM mobile_subscribers m GROUP BY m.region_id HAVING AVG(m.monthly_data_usage) > 3) ORDER BY b.monthly_data_usage DESC; |
Calculate the inventory cost for vegan dishes in the South region. | CREATE TABLE menu (menu_id INT,menu_name VARCHAR(255),is_vegan BOOLEAN,cost_ingredients DECIMAL(5,2)); CREATE TABLE inventory (menu_id INT,inventory_quantity INT,price_per_unit DECIMAL(5,2)); INSERT INTO menu (menu_id,menu_name,is_vegan,cost_ingredients) VALUES (1,'Vegan Tacos',TRUE,7.50),(2,'Chickpea Curry',TRUE,6.25),(3,'Beef Burger',FALSE,8.75),(4,'Fish and Chips',FALSE,9.25); INSERT INTO inventory (menu_id,inventory_quantity,price_per_unit) VALUES (1,50,2.00),(2,75,1.75),(3,30,2.50),(4,40,2.75); | SELECT SUM(cost_ingredients * inventory_quantity * price_per_unit) as inventory_cost FROM menu JOIN inventory ON menu.menu_id = inventory.menu_id WHERE is_vegan = TRUE AND region = 'South'; |
What is the earliest date an article about 'corruption' was published? | CREATE TABLE articles (id INT,title TEXT,category TEXT,published_at DATETIME); | SELECT MIN(published_at) FROM articles WHERE articles.category = 'corruption'; |
What is the average number of heritage sites per country in Africa? | CREATE TABLE HeritageSites (Country VARCHAR(255),Site VARCHAR(255)); INSERT INTO HeritageSites (Country,Site) VALUES ('Egypt','Pyramids of Giza'),('Egypt','Sphinx'),('Egypt','Temple of Karnak'),('Kenya','Masai Mara'),('Kenya','Amboseli'),('Morocco','Mediina of Fez'),('Morocco','Koutoubia Mosque'),('South Africa','Table Mountain'),('South Africa','Cape of Good Hope'),('Tunisia','Amphitheater of El Jem'),('Tunisia','Dougga'); | SELECT Country, COUNT(Site) as Num_Sites, AVG(COUNT(Site)) OVER() as Avg_Num_Sites FROM HeritageSites GROUP BY Country; |
Find the number of food safety inspections for each restaurant in the last 6 months. | CREATE TABLE restaurant (restaurant_id INTEGER,last_inspection_date DATE); INSERT INTO restaurant (restaurant_id,last_inspection_date) VALUES (1,'2022-11-01'),(2,'2023-01-01'),(3,'2023-03-15'); | SELECT restaurant_id, COUNT(*) AS num_inspections FROM restaurant WHERE last_inspection_date >= DATEADD(month, -6, CURRENT_DATE) GROUP BY restaurant_id; |
What is the maximum number of shares a single post received in the past week? | CREATE TABLE posts (id INT,user_id INT,timestamp TIMESTAMP,content TEXT,likes INT,shares INT); | SELECT MAX(shares) FROM posts WHERE timestamp BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 WEEK) AND CURRENT_TIMESTAMP; |
List all climate communication campaigns in the Pacific Islands and their budgets | CREATE TABLE climate_communication_campaigns (id INT,campaign VARCHAR(50),location VARCHAR(50),budget FLOAT); INSERT INTO climate_communication_campaigns (id,campaign,location,budget) VALUES (1,'Sea Level Rise Awareness','Pacific Islands',250000),(2,'Climate Change and Health','Asia',400000),(3,'Clean Energy Transition','Africa',350000); | SELECT campaign, budget FROM climate_communication_campaigns WHERE location = 'Pacific Islands'; |
What is the total transaction amount for all customers from India and Brazil? | CREATE TABLE transactions (customer_id INT,transaction_amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO transactions (customer_id,transaction_amount,country) VALUES (1,120.50,'India'),(2,75.30,'Brazil'),(3,150.00,'India'),(4,200.00,'Brazil'); | SELECT SUM(transaction_amount) FROM transactions WHERE country IN ('India', 'Brazil'); |
What is the population of Canada? | CREATE TABLE Countries (ID INT,Country VARCHAR(50),Population INT); INSERT INTO Countries (ID,Country,Population) VALUES (1,'Canada',38005238); | SELECT Population FROM Countries WHERE Country = 'Canada'; |
What is the average engagement time for virtual tours in Tokyo? | CREATE TABLE virtual_tours (tour_id INT,city TEXT,engagement_time FLOAT); INSERT INTO virtual_tours (tour_id,city,engagement_time) VALUES (1,'Tokyo',15.5),(2,'Tokyo',12.3),(3,'Osaka',18.1); | SELECT AVG(engagement_time) FROM virtual_tours WHERE city = 'Tokyo'; |
Calculate the total installed capacity (in MW) of Wind Farms in Germany | CREATE TABLE wind_farms (id INT,name VARCHAR(100),country VARCHAR(50),capacity_mw FLOAT); INSERT INTO wind_farms (id,name,country,capacity_mw) VALUES (1,'Windfarm 1','Germany',120.5),(2,'Windfarm 2','Germany',250.3); | SELECT SUM(capacity_mw) FROM wind_farms WHERE country = 'Germany' AND name LIKE 'Windfarm%'; |
What is the distribution of user interests based on their location? | CREATE TABLE user_location (user_id INT,location VARCHAR(255),interest VARCHAR(255)); INSERT INTO user_location (user_id,location,interest) VALUES (1,'NYC','Politics'),(2,'LA','Sports'),(3,'SF','Tech'); | SELECT location, interest, COUNT(*) as count FROM user_location GROUP BY location, interest; |
What are the top 3 countries with the highest number of excavated artifacts? | CREATE TABLE ArtifactsByCountry (Country TEXT,ArtifactCount INT); INSERT INTO ArtifactsByCountry (Country,ArtifactCount) VALUES ('Italy',250),('Egypt',500),('France',300),('Greece',400); | SELECT Country, ArtifactCount FROM ArtifactsByCountry ORDER BY ArtifactCount DESC LIMIT 3; |
What is the total installed solar panel capacity in 'SolarProjects' table, in each state, and the corresponding percentage of total capacity? | CREATE TABLE SolarProjects (project_id INT,state VARCHAR(50),capacity INT); | SELECT state, SUM(capacity) as total_capacity, (SUM(capacity) / (SELECT SUM(capacity) FROM SolarProjects)) * 100 as percentage_of_total FROM SolarProjects GROUP BY state; |
What is the average humanitarian assistance provided by each country in the African Union in 2020? | CREATE TABLE HumanitarianAssistance (Country VARCHAR(50),Assistance FLOAT,Region VARCHAR(50)); INSERT INTO HumanitarianAssistance (Country,Assistance,Region) VALUES ('South Africa',75.3,'African Union'),('Nigeria',68.5,'African Union'),('Egypt',59.7,'African Union'); | SELECT AVG(Assistance) as Avg_Assistance, Country FROM HumanitarianAssistance WHERE Year = 2020 AND Region = 'African Union' GROUP BY Country; |
What is the maximum tenure of employees in the engineering department who have completed diversity training? | CREATE TABLE employee_database (id INT,department TEXT,tenure INT,training_completed TEXT); INSERT INTO employee_database (id,department,tenure,training_completed) VALUES (1,'Engineering',5,'Diversity'),(2,'Engineering',3,'Inclusion'),(3,'Engineering',7,'None'); | SELECT MAX(tenure) as max_tenure FROM employee_database WHERE department = 'Engineering' AND training_completed = 'Diversity'; |
How many female attendees were there at the 'Theater for All' program? | CREATE TABLE ProgramAttendance (program_name VARCHAR(255),attendee_age INT,attendee_gender VARCHAR(50)); INSERT INTO ProgramAttendance (program_name,attendee_age,attendee_gender) VALUES ('Theater for All',22,'Female'),('Theater for All',27,'Male'),('Theater for All',32,'Female'),('Theater for All',45,'Non-binary'); | SELECT COUNT(*) FROM ProgramAttendance WHERE program_name = 'Theater for All' AND attendee_gender = 'Female'; |
What is the total funding received by biotech startups in India working on genetic research? | CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),total_funding FLOAT,research_area VARCHAR(255)); INSERT INTO biotech.startups (id,name,country,total_funding,research_area) VALUES (1,'Genetech India','India',3000000,'Genetic Research'); INSERT INTO biotech.startups (id,name,country,total_funding,research_area) VALUES (2,'BioInnovate India','India',4000000,'Bioprocess Engineering'); | SELECT SUM(total_funding) FROM biotech.startups WHERE country = 'India' AND research_area = 'Genetic Research'; |
Find the average production usage of sustainable materials per factory for factories located in urban areas. | CREATE TABLE Factory_Location (id INT,factory_id INT,area VARCHAR(255)); INSERT INTO Factory_Location (id,factory_id,area) VALUES (1,1001,'Urban'),(2,1002,'Rural'); CREATE TABLE Material_Production (id INT,factory_id INT,material VARCHAR(255),production_usage INT); INSERT INTO Material_Production (id,factory_id,material,production_usage) VALUES (1,1001,'Organic Cotton',500),(2,1002,'Recycled Polyester',750); | SELECT f.area, AVG(mp.production_usage) FROM Factory_Location f INNER JOIN Material_Production mp ON f.factory_id = mp.factory_id WHERE f.area = 'Urban' GROUP BY f.area; |
What was the average museum attendance on weekends? | CREATE TABLE attendance (attendance_id INT,museum_name VARCHAR(50),date DATE,visitors INT); INSERT INTO attendance (attendance_id,museum_name,date,visitors) VALUES (1,'Metropolitan Museum of Art','2021-09-04',5000); INSERT INTO attendance (attendance_id,museum_name,date,visitors) VALUES (2,'Metropolitan Museum of Art','2021-09-05',6000); | SELECT AVG(visitors) FROM attendance WHERE date BETWEEN '2021-01-01' AND '2021-12-31' AND EXTRACT(DAYOFWEEK FROM date) IN (1, 7); |
Update the revenue of the virtual tourism venue with ID 1 to 60000.00 in the virtual_tourism table. | CREATE TABLE virtual_tourism (venue_id INT,name TEXT,country TEXT,revenue DECIMAL(6,2)); INSERT INTO virtual_tourism (venue_id,name,country,revenue) VALUES (1,'Virtually NYC','USA',55000.00),(2,'Toronto 360','Canada',180000.00); | UPDATE virtual_tourism SET revenue = 60000.00 WHERE venue_id = 1; |
Show the tunnels in New York with a length less than or equal to 2 miles. | CREATE TABLE Tunnels(id INT,name TEXT,location TEXT,length FLOAT); INSERT INTO Tunnels(id,name,location,length) VALUES (1,'Holland Tunnel','New York',8564.0); | SELECT name FROM Tunnels WHERE location = 'New York' AND length <= 2 * 5280; |
List marine species and their conservation status in areas under the jurisdiction of the Northwest Atlantic Fisheries Organization (NAFO)? | CREATE TABLE Species (species_id INT,species_name VARCHAR(50),PRIMARY KEY(species_id)); INSERT INTO Species (species_id,species_name) VALUES (1,'Atlantic Cod'),(2,'Bluefin Tuna'); CREATE TABLE Jurisdiction (jurisdiction_id INT,jurisdiction_name VARCHAR(50),PRIMARY KEY(jurisdiction_id)); INSERT INTO Jurisdiction (jurisdiction_id,jurisdiction_name) VALUES (1,'NAFO'),(2,'NEAFC'); CREATE TABLE Conservation (species_id INT,jurisdiction_id INT,status VARCHAR(20),PRIMARY KEY(species_id,jurisdiction_id)); INSERT INTO Conservation (species_id,jurisdiction_id,status) VALUES (1,1,'Endangered'),(2,1,'Vulnerable'),(1,2,'Least Concern'),(2,2,'Near Threatened'); | SELECT Species.species_name, Conservation.status FROM Species JOIN Conservation ON Species.species_id = Conservation.species_id JOIN Jurisdiction ON Conservation.jurisdiction_id = Jurisdiction.jurisdiction_id WHERE Jurisdiction.jurisdiction_name = 'NAFO'; |
Find the total number of healthcare providers in urban and rural areas | CREATE TABLE healthcare_providers (id INT,name VARCHAR(50),area VARCHAR(10)); INSERT INTO healthcare_providers (id,name,area) VALUES (1,'Dr. Smith','Urban'),(2,'Dr. Johnson','Rural'),(3,'Dr. Williams','Rural'),(4,'Dr. Brown','Urban'),(5,'Dr. Davis','Rural'); | SELECT area, COUNT(*) FROM healthcare_providers GROUP BY area; |
What is the number of hospitals and their respective states, ordered by the number of hospitals in descending order? | CREATE TABLE hospitals (id INT,name TEXT,num_beds INT,city TEXT,state TEXT); INSERT INTO hospitals (id,name,num_beds,city,state) VALUES (1,'General Hospital',500,'New York','NY'); INSERT INTO hospitals (id,name,num_beds,city,state) VALUES (2,'City Hospital',300,'Los Angeles','CA'); INSERT INTO hospitals (id,name,num_beds,city,state) VALUES (3,'County Hospital',400,'Miami','FL'); | SELECT state, COUNT(*) as num_hospitals FROM hospitals GROUP BY state ORDER BY num_hospitals DESC; |
Who is the developer with the most smart contracts? | CREATE TABLE smart_contracts (id INT,name TEXT,developer TEXT); INSERT INTO smart_contracts (id,name,developer) VALUES (1,'Contract1','John Doe'),(2,'Contract2','John Doe'),(3,'Contract3','Jane Smith'); | SELECT developer, COUNT(*) as num_contracts FROM smart_contracts GROUP BY developer ORDER BY num_contracts DESC LIMIT 1; |
How many male, female, and non-binary employees work at each company? | CREATE TABLE Company (id INT,name VARCHAR(50)); INSERT INTO Company (id,name) VALUES (1,'Acme Inc'); INSERT INTO Company (id,name) VALUES (2,'Beta Corp'); INSERT INTO Company (id,name) VALUES (3,'Gamma Startup'); CREATE TABLE Diversity (company_id INT,gender VARCHAR(10),employee_count INT); INSERT INTO Diversity (company_id,gender,employee_count) VALUES (1,'Male',500); INSERT INTO Diversity (company_id,gender,employee_count) VALUES (1,'Female',300); INSERT INTO Diversity (company_id,gender,employee_count) VALUES (2,'Male',1000); INSERT INTO Diversity (company_id,gender,employee_count) VALUES (2,'Female',500); INSERT INTO Diversity (company_id,gender,employee_count) VALUES (3,'Non-binary',250); | SELECT company_id, gender, SUM(employee_count) as total FROM Diversity GROUP BY company_id, gender; |
What is the number of community policing events, by type, that occurred in each neighborhood, for the past month? | CREATE TABLE CommunityPolicingEvents (ID INT,Neighborhood VARCHAR(50),EventType VARCHAR(50),Date TIMESTAMP); INSERT INTO CommunityPolicingEvents (ID,Neighborhood,EventType,Date) VALUES (1,'NeighborhoodA','Meeting','2022-08-01 00:00:00'),(2,'NeighborhoodA','Patrol','2022-08-02 00:00:00'),(3,'NeighborhoodB','Meeting','2022-08-01 00:00:00'),(4,'NeighborhoodB','Patrol','2022-08-03 00:00:00'); | SELECT Neighborhood, EventType, COUNT(*) FROM CommunityPolicingEvents WHERE Date >= CURRENT_DATE - INTERVAL '1 month' GROUP BY Neighborhood, EventType; |
List all satellites launched by SpaceX before 2015 | CREATE TABLE satellites (satellite_name VARCHAR(255),launch_date DATE,manufacturer VARCHAR(255)); CREATE VIEW spacex_satellites AS SELECT * FROM satellites WHERE manufacturer = 'SpaceX'; | SELECT satellite_name FROM spacex_satellites WHERE launch_date < '2015-01-01'; |
How many hotels have adopted AI chatbots in each country? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT); INSERT INTO hotels (hotel_id,hotel_name,country) VALUES (1,'Hotel X','USA'),(2,'Hotel Y','Canada'),(3,'Hotel Z','Mexico'); CREATE TABLE ai_chatbots (hotel_id INT,chatbot_name TEXT); INSERT INTO ai_chatbots (hotel_id,chatbot_name) VALUES (1,'Chatbot A'),(3,'Chatbot B'); | SELECT country, COUNT(DISTINCT hotels.hotel_id) as num_hotels_with_chatbots FROM hotels INNER JOIN ai_chatbots ON hotels.hotel_id = ai_chatbots.hotel_id GROUP BY country; |
Add a column "last_updated" of type DATETIME to the "properties" table | CREATE TABLE properties (property_id INT,property_name VARCHAR(255),location VARCHAR(255),inclusive_housing BOOLEAN); | ALTER TABLE properties ADD COLUMN last_updated DATETIME; |
Find the number of teachers who have ever taught in each open pedagogy course. | CREATE TABLE open_pedagogy_courses (course_id INT,course_name VARCHAR(50)); INSERT INTO open_pedagogy_courses VALUES (1,'Course 1'),(2,'Course 2'),(3,'Course 3'); CREATE TABLE teacher_assignments (teacher_id INT,course_id INT); INSERT INTO teacher_assignments VALUES (1,1),(1,2),(2,2),(2,3),(3,1),(3,3),(4,2),(4,3),(5,1); | SELECT course_id, course_name, COUNT(DISTINCT teacher_id) as teaching_count FROM open_pedagogy_courses JOIN teacher_assignments ON open_pedagogy_courses.course_id = teacher_assignments.course_id GROUP BY course_id, course_name; |
What is the total number of employees hired before 2020? | CREATE TABLE Employees (EmployeeID int,HireDate date); INSERT INTO Employees (EmployeeID,HireDate) VALUES (1,'2019-01-01'),(2,'2018-05-15'),(3,'2020-12-31'); | SELECT COUNT(*) FROM Employees WHERE YEAR(HireDate) < 2020; |
What were the total sales for each drug by quarter in 2021? | CREATE TABLE sales_q (drug_name TEXT,quarter TEXT,year INTEGER,quantity INTEGER,sale_price NUMERIC(10,2)); INSERT INTO sales_q (drug_name,quarter,year,quantity,sale_price) VALUES ('DrugA','Q1',2021,250,120.50),('DrugA','Q2',2021,280,125.00),('DrugB','Q1',2021,220,150.75),('DrugB','Q2',2021,240,155.00); | SELECT drug_name, quarter, SUM(quantity * sale_price) as total_sales FROM sales_q WHERE year = 2021 GROUP BY drug_name, quarter; |
What is the total number of mobile customers and broadband customers in each state? | CREATE TABLE mobile_customers (customer_id INT,state VARCHAR(50)); CREATE TABLE broadband_customers (customer_id INT,state VARCHAR(50)); INSERT INTO mobile_customers (customer_id,state) VALUES (1,'NY'),(2,'NJ'),(3,'NY'),(4,'PA'),(5,'PA'); INSERT INTO broadband_customers (customer_id,state) VALUES (6,'NY'),(7,'NJ'),(8,'NY'),(9,'PA'),(10,'PA'); | SELECT state, COUNT(DISTINCT mobile_customers.customer_id) + COUNT(DISTINCT broadband_customers.customer_id) FROM mobile_customers FULL OUTER JOIN broadband_customers ON mobile_customers.state = broadband_customers.state GROUP BY state; |
What is the gender distribution of union members in the 'Teachers Union'? | CREATE TABLE UnionGender (MemberID INT,UnionID INT,Gender VARCHAR(10)); INSERT INTO UnionGender (MemberID,UnionID,Gender) VALUES (1,1,'Female'),(2,1,'Male'),(3,2,'Female'),(4,2,'Female'),(5,3,'Male'),(6,3,'Female'),(7,2,'Male'); | SELECT Gender, COUNT(*) as MembersCount FROM UnionGender WHERE UnionID = (SELECT UnionID FROM Unions WHERE UnionName = 'Teachers Union') GROUP BY Gender; |
Which regulatory frameworks are associated with the most decentralized applications? | CREATE TABLE regulatory_frameworks (id INT,name VARCHAR(255)); CREATE TABLE dapps (id INT,framework_id INT,name VARCHAR(255)); INSERT INTO regulatory_frameworks (id,name) VALUES (1,'FrameworkA'),(2,'FrameworkB'),(3,'FrameworkC'); INSERT INTO dapps (id,framework_id,name) VALUES (1,1,'DApp1'),(2,1,'DApp2'),(3,2,'DApp3'),(4,3,'DApp4'),(5,3,'DApp5'),(6,3,'DApp6'); | SELECT regulatory_frameworks.name AS Framework, COUNT(dapps.id) AS DApps_Count FROM regulatory_frameworks JOIN dapps ON regulatory_frameworks.id = dapps.framework_id GROUP BY regulatory_frameworks.name ORDER BY DApps_Count DESC; |
What is the distribution of virtual tour engagement times for hotels in the Caribbean? | CREATE TABLE hotel_virtual_tour (hotel_id INT,hotel_name TEXT,country TEXT,virtual_tour TEXT,engagement_time INT); INSERT INTO hotel_virtual_tour (hotel_id,hotel_name,country,virtual_tour,engagement_time) VALUES (1,'The Tropical Retreat','Bahamas','yes',250),(2,'The Seaside Inn','Jamaica','yes',200),(3,'The Island Resort','Puerto Rico','no',NULL),(4,'The Sunshine Hotel','Trinidad and Tobago','yes',220); | SELECT country, COUNT(hotel_id) AS total_hotels, AVG(engagement_time) AS avg_engagement_time, STDDEV(engagement_time) AS stddev_engagement_time FROM hotel_virtual_tour WHERE country = 'Caribbean' AND virtual_tour = 'yes' GROUP BY country |
Display the percentage of patients who have experienced cultural competency in healthcare services, by their ethnicity, in descending order. | CREATE TABLE patient (patient_id INT,ethnicity VARCHAR(255),experienced_cultural_competency BOOLEAN); INSERT INTO patient (patient_id,ethnicity,experienced_cultural_competency) VALUES (1,'Hispanic',TRUE),(2,'Asian',FALSE),(3,'White',TRUE),(4,'Black',TRUE); | SELECT ethnicity, 100.0 * SUM(experienced_cultural_competency) / COUNT(*) as percentage FROM patient GROUP BY ethnicity ORDER BY percentage DESC; |
What is the total number of agroecological plots in the 'plots' table, and how many of them are located in the 'Amazon' region? | CREATE TABLE plots (id INT,location TEXT,type TEXT); INSERT INTO plots (id,location,type) VALUES (1,'Amazon','Agroecological'); INSERT INTO plots (id,location,type) VALUES (2,'Andes','Agroforestry'); | SELECT COUNT(*) as total_plots, SUM(CASE WHEN location = 'Amazon' THEN 1 ELSE 0 END) as amazon_plots FROM plots WHERE type = 'Agroecological'; |
What are the total number of artworks in the 'Paintings' and 'Sculptures' tables? | CREATE TABLE Paintings (PaintingID INT,Title TEXT); INSERT INTO Paintings (PaintingID,Title) VALUES (1,'Guernica'),(2,'The Starry Night'); CREATE TABLE Sculptures (SculptureID INT,Title TEXT); INSERT INTO Sculptures (SculptureID,Title) VALUES (1,'David'),(2,'The Thinker'); | SELECT COUNT(*) FROM Paintings UNION ALL SELECT COUNT(*) FROM Sculptures; |
What is the average revenue per hotel in Spain that have adopted AI-based housekeeping systems? | CREATE TABLE hotel_revenue_data (hotel_id INT,country TEXT,revenue FLOAT,ai_housekeeping INT); INSERT INTO hotel_revenue_data (hotel_id,country,revenue,ai_housekeeping) VALUES (1,'Spain',120000,1),(2,'Spain',150000,1),(3,'Spain',180000,0),(4,'Italy',200000,1); | SELECT AVG(revenue) FROM hotel_revenue_data WHERE country = 'Spain' AND ai_housekeeping = 1; |
Which suppliers provided over 50% of the sustainable materials in 2022? | CREATE TABLE supplier_materials (supplier_id INT,material_type VARCHAR(255),sustainable BOOLEAN,supply_date DATE); | SELECT supplier_id, COUNT(*) FROM supplier_materials WHERE material_type = 'sustainable' AND sustainable = true GROUP BY supplier_id HAVING COUNT(*) > 0.5 * (SELECT COUNT(*) FROM supplier_materials WHERE material_type = 'sustainable' AND sustainable = true); |
What is the average response time for emergency calls in the city of Los Angeles for the year 2020? | CREATE TABLE emergency_calls (id INT,city VARCHAR(50),year INT,response_time INT); INSERT INTO emergency_calls (id,city,year,response_time) VALUES (1,'Los Angeles',2020,7); INSERT INTO emergency_calls (id,city,year,response_time) VALUES (2,'Los Angeles',2020,8); | SELECT AVG(response_time) FROM emergency_calls WHERE city = 'Los Angeles' AND year = 2020; |
What was the total quantity of products manufactured in the last week, grouped by day? | CREATE TABLE manufacturing (manufacturing_id INT,manufacture_date DATE,product_quantity INT); INSERT INTO manufacturing (manufacturing_id,manufacture_date,product_quantity) VALUES (1,'2022-01-03',500),(2,'2022-01-10',700),(3,'2022-01-15',600),(4,'2022-01-16',800),(5,'2022-01-17',900),(6,'2022-01-18',750); | SELECT DATE(manufacture_date) as manufacturing_day, SUM(product_quantity) as total_quantity FROM manufacturing WHERE manufacture_date >= DATE_SUB(NOW(), INTERVAL 1 WEEK) GROUP BY manufacturing_day; |
How many agricultural innovation projects were completed in Kenya in 2020? | CREATE TABLE agricultural_innovation (id INT,country VARCHAR(255),project VARCHAR(255),status VARCHAR(255),year INT); INSERT INTO agricultural_innovation (id,country,project,status,year) VALUES (1,'Kenya','New Seed Variety','completed',2020),(2,'Kenya','Drip Irrigation','in progress',2020),(3,'Tanzania','Precision Farming','completed',2020); | SELECT COUNT(*) FROM agricultural_innovation WHERE country = 'Kenya' AND status = 'completed' AND year = 2020; |
Delete all records with soil moisture above 80% in 'Plot3' for the month of July. | CREATE TABLE Plot3 (date DATE,soil_moisture FLOAT); | DELETE FROM Plot3 WHERE soil_moisture > 80 AND EXTRACT(MONTH FROM date) = 7; |
What is the average delivery time for freight forwarder 'FF1'? | CREATE TABLE FreightForwarders (FreightForwarder VARCHAR(50),DeliveryTime INT); INSERT INTO FreightForwarders (FreightForwarder,DeliveryTime) VALUES ('FF1',5),('FF1',7),('FF1',6),('FF2',4),('FF2',8); | SELECT AVG(DeliveryTime) FROM FreightForwarders WHERE FreightForwarder = 'FF1'; |
What is the percentage of ethical AI research papers published per year in EMEA? | CREATE TABLE ethical_ai_research (publication_year INT,num_papers INT,region VARCHAR(255)); INSERT INTO ethical_ai_research (publication_year,num_papers,region) VALUES (2018,250,'EMEA'),(2019,300,'EMEA'),(2020,350,'EMEA'),(2021,400,'EMEA'); | SELECT publication_year, num_papers, (num_papers / SUM(num_papers) OVER (PARTITION BY region)) * 100.0 AS pct_per_year FROM ethical_ai_research WHERE region = 'EMEA'; |
What is the total cost of medical supplies for the rural health clinic in California in the last 6 months? | CREATE TABLE MedicalSupplies (supplyID INT,purchase_date DATE,cost DECIMAL(10,2)); INSERT INTO MedicalSupplies (supplyID,purchase_date,cost) VALUES (1,'2022-01-05',150.50),(2,'2022-02-10',200.00),(3,'2021-12-12',125.25); | SELECT SUM(cost) FROM MedicalSupplies WHERE purchase_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND CURDATE() AND clinic_location = 'California'; |
What is the release year with the highest total number of streams? | CREATE TABLE Songs (id INT,title VARCHAR(100),release_year INT,genre VARCHAR(50),streams INT); | SELECT release_year, SUM(streams) as total_streams FROM Songs GROUP BY release_year ORDER BY total_streams DESC LIMIT 1; |
What was the total number of attendees at the "Theater Performance" event by age group? | CREATE TABLE performance_attendance_2 (event VARCHAR(255),age_group VARCHAR(255),attendees INT); INSERT INTO performance_attendance_2 (event,age_group,attendees) VALUES ('Theater Performance','18-34',250),('Theater Performance','35-54',300),('Art Exhibit','55+',150); | SELECT age_group, SUM(attendees) FROM performance_attendance_2 WHERE event = 'Theater Performance' GROUP BY age_group; |
What is the percentage of security incidents caused by each type of malware in the last 6 months? | CREATE TABLE security_incidents (id INT,timestamp TIMESTAMP,country VARCHAR(255),incident_type VARCHAR(255),malware_type VARCHAR(255)); INSERT INTO security_incidents (id,timestamp,country,incident_type,malware_type) VALUES (1,'2020-07-01 12:00:00','USA','Malware','Ransomware'),(2,'2020-08-05 10:30:00','Canada','Malware','Spyware'); | SELECT malware_type, 100.0 * COUNT(*) / (SELECT COUNT(*) FROM security_incidents WHERE timestamp >= NOW() - INTERVAL 6 MONTH AND incident_type = 'Malware') as percentage FROM security_incidents WHERE timestamp >= NOW() - INTERVAL 6 MONTH AND incident_type = 'Malware' GROUP BY malware_type; |
Identify the agricultural innovation projects in 'RuralDev' database with a status of 'Active' or 'Pilot'. | CREATE TABLE agricultural_innovation_status_2 (id INT,name VARCHAR(255),status VARCHAR(255)); INSERT INTO agricultural_innovation_status_2 (id,name,status) VALUES (1,'Precision Agriculture','Active'),(2,'Organic Farming','Pilot'),(3,'Genetic Engineering','Active'); | SELECT * FROM agricultural_innovation_status_2 WHERE status IN ('Active', 'Pilot'); |
What is the total number of policies and total claim amount for policies in Texas, grouped by coverage type? | CREATE TABLE policy (policy_id INT,coverage_type VARCHAR(20),issue_date DATE,zip_code INT,risk_score INT); CREATE TABLE claim (claim_id INT,policy_id INT,claim_amount INT); | SELECT coverage_type, COUNT(policy_id) as policy_count, SUM(claim_amount) as total_claim_amount FROM claim JOIN policy ON claim.policy_id = policy.policy_id WHERE zip_code = (SELECT zip_code FROM zip_codes WHERE state = 'TX' AND city = 'Dallas') GROUP BY coverage_type; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.