instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average age of community health workers by their race/ethnicity? | CREATE TABLE CommunityHealthWorkers (WorkerID INT,Age INT,RaceEthnicity VARCHAR(255)); INSERT INTO CommunityHealthWorkers (WorkerID,Age,RaceEthnicity) VALUES (1,35,'Latinx'); INSERT INTO CommunityHealthWorkers (WorkerID,Age,RaceEthnicity) VALUES (2,42,'African American'); INSERT INTO CommunityHealthWorkers (WorkerID,Ag... | SELECT RaceEthnicity, AVG(Age) FROM CommunityHealthWorkers GROUP BY RaceEthnicity; |
What is the maximum number of comments on a single post, from users in the 'athlete' category? | CREATE TABLE posts (post_id INT,user_id INT,comment_count INT); INSERT INTO posts (post_id,user_id,comment_count) VALUES (1,1,100),(2,2,50),(3,3,150); | SELECT MAX(comment_count) FROM posts JOIN users ON posts.user_id = users.user_id WHERE users.category = 'athlete'; |
Update the 'status' column to 'completed' for the project with ID 3 in the 'Road_Construction' table. | CREATE TABLE Road_Construction (project_id INT,project_name VARCHAR(100),status VARCHAR(20)); INSERT INTO Road_Construction (project_id,project_name,status) VALUES (1,'Highway Expansion','in_progress'),(3,'Bridge Replacement','pending'); | UPDATE Road_Construction SET status = 'completed' WHERE project_id = 3; |
What is the number of public schools in New York City? | CREATE TABLE public_schools (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255)); INSERT INTO public_schools (id,name,city,state) VALUES (1,'School 1','New York City','NY'); INSERT INTO public_schools (id,name,city,state) VALUES (2,'School 2','New York City','NY'); | SELECT COUNT(*) FROM public_schools WHERE city = 'New York City' AND state = 'NY'; |
What is the average safety rating of ingredients sourced from the United States? | CREATE TABLE Ingredients (id INT,name VARCHAR(50),origin VARCHAR(50),safety_rating DECIMAL(3,2)); INSERT INTO Ingredients (id,name,origin,safety_rating) VALUES (1,'Aloe Vera','USA',9.75),(2,'Argan Oil','Morocco',9.50),(3,'Cocoa Butter','Ghana',9.25); | SELECT AVG(i.safety_rating) as avg_safety_rating FROM Ingredients i WHERE i.origin = 'USA'; |
What are the top 5 ingredients sourced from sustainable suppliers for cosmetic products in the European Union? | CREATE TABLE ingredient_sources (product_id INT,ingredient TEXT,supplier_sustainability_rating INT,region TEXT); CREATE VIEW sustainable_suppliers AS SELECT supplier,AVG(supplier_sustainability_rating) as avg_rating FROM ingredient_sources GROUP BY supplier; | SELECT ingredient FROM ingredient_sources INNER JOIN sustainable_suppliers ON ingredient_sources.supplier = sustainable_suppliers.supplier WHERE region = 'European Union' GROUP BY ingredient ORDER BY avg_rating DESC LIMIT 5; |
How many companies have an ESG rating of 'A' or higher? | CREATE TABLE companies (id INT,name VARCHAR(50),esg_rating VARCHAR(1)); INSERT INTO companies (id,name,esg_rating) VALUES (1,'ABC Inc.','A'); INSERT INTO companies (id,name,esg_rating) VALUES (2,'DEF Inc.','B'); INSERT INTO companies (id,name,esg_rating) VALUES (3,'XYZ Inc.','C'); | SELECT COUNT(*) FROM companies WHERE esg_rating IN ('A', 'B', 'C+', 'A-'); |
Determine the number of factories with fair labor practices in Spain. | CREATE TABLE labor_practices (factory_id INT,location TEXT,fair_labor_practices BOOLEAN); INSERT INTO labor_practices (factory_id,location,fair_labor_practices) VALUES (1,'Spain',true),(2,'Portugal',false); | SELECT COUNT(factory_id) FROM labor_practices WHERE location = 'Spain' AND fair_labor_practices = true; |
Delete all TV shows with a production budget over 5 million and a rating below 7 | CREATE TABLE tv_shows (title VARCHAR(255),genre VARCHAR(50),budget INT,rating INT); INSERT INTO tv_shows (title,genre,budget,rating) VALUES ('Show1','Comedy',6000000,6),('Show2','Drama',4000000,8),('Show3','Action',7000000,5); | DELETE FROM tv_shows WHERE budget > 5000000 AND rating < 7; |
What is the total number of tries scored by the All Blacks Rugby Union Team? | CREATE TABLE all_blacks_stats (player TEXT,tries INT); INSERT INTO all_blacks_stats (player,tries) VALUES ('Beauden Barrett',41); INSERT INTO all_blacks_stats (player,tries) VALUES ('Aaron Smith',35); | SELECT SUM(tries) FROM all_blacks_stats; |
Find the total digital engagement for exhibitions related to African history. | CREATE TABLE Digital_Engagement (id INT,visitor_id INT,exhibition_id INT,platform VARCHAR(255),views INT,clicks INT); CREATE TABLE Exhibitions (id INT,name VARCHAR(255),theme VARCHAR(255)); INSERT INTO Digital_Engagement (id,visitor_id,exhibition_id,platform,views,clicks) VALUES (1,1001,1,'Website',100,50),(2,1002,2,'S... | SELECT SUM(views + clicks) FROM Digital_Engagement de JOIN Exhibitions e ON de.exhibition_id = e.id WHERE e.theme LIKE '%African%'; |
What is the total funding received by arts education programs? | CREATE TABLE Programs (Id INT,Name VARCHAR(50),Category VARCHAR(50),Funding DECIMAL(10,2)); | SELECT SUM(Funding) FROM Programs WHERE Category = 'Arts Education'; |
Identify the number of mental health providers who speak a language other than English, by region, in descending order of the number of providers. | CREATE TABLE MentalHealthProviders (ProviderID INT,Region VARCHAR(255),Language VARCHAR(255)); INSERT INTO MentalHealthProviders (ProviderID,Region,Language) VALUES (1,'North','English'),(2,'South','Spanish'),(3,'East','Mandarin'),(4,'West','English'); | SELECT Region, COUNT(*) as Count FROM MentalHealthProviders WHERE Language <> 'English' GROUP BY Region ORDER BY Count DESC; |
Which employees in the Manufacturing department have a salary above the average salary in the Safety department? | CREATE TABLE Employees (EmployeeID INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (5,'Charlie','Brown','Manufacturing',58000.00); INSERT INTO Employees (EmployeeID,FirstName,LastName,... | SELECT Employees.FirstName, Employees.LastName, Employees.Department, Employees.Salary FROM Employees, (SELECT AVG(Salary) AS AverageSalary FROM Employees WHERE Department = 'Safety') AS SafetyAverage WHERE Employees.Department = 'Manufacturing' AND Employees.Salary > SafetyAverage.AverageSalary; |
What is the total billing amount for each attorney? | CREATE TABLE attorneys (attorney_id INT,attorney_name VARCHAR(255)); INSERT INTO attorneys (attorney_id,attorney_name) VALUES (1,'John Smith'),(2,'Jane Doe'); CREATE TABLE billing (bill_id INT,attorney_id INT,amount DECIMAL(10,2)); INSERT INTO billing (bill_id,attorney_id,amount) VALUES (1,1,500.00),(2,1,250.00),(3,2,7... | SELECT a.attorney_name, SUM(b.amount) as total_billing FROM attorneys a INNER JOIN billing b ON a.attorney_id = b.attorney_id GROUP BY a.attorney_id, a.attorney_name; |
What is the distribution of mobile data usage by hour of the day, for the past 7 days? | CREATE TABLE mobile_data_usage (id INT,user_id INT,data_usage FLOAT,usage_time DATETIME); INSERT INTO mobile_data_usage (id,user_id,data_usage,usage_time) VALUES (1,1,3.5,'2021-08-01 12:30:00'); INSERT INTO mobile_data_usage (id,user_id,data_usage,usage_time) VALUES (2,2,5.2,'2021-08-02 16:45:00'); INSERT INTO mobile_d... | SELECT DATEPART(hour, usage_time) as hour, AVG(data_usage) as avg_data_usage FROM mobile_data_usage WHERE usage_time >= DATEADD(day, -7, GETDATE()) GROUP BY hour ORDER BY hour; |
What is the prevalence of diabetes in rural Alabama? | CREATE TABLE diabetes (id INT,state VARCHAR(20),rural BOOLEAN,prevalence FLOAT); INSERT INTO diabetes (id,state,rural,prevalence) VALUES (1,'Alabama',true,12.3),(2,'Alabama',false,9.8),(3,'Georgia',true,10.5); | SELECT prevalence FROM diabetes WHERE state = 'Alabama' AND rural = true; |
Who are the top 5 offenders by total number of offenses? | CREATE TABLE offenders (offender_id INT,offender_name VARCHAR(255)); CREATE TABLE offenses (offense_id INT,offender_id INT,offense_date DATE); | SELECT offender_name, COUNT(*) as total_offenses FROM offenders JOIN offenses ON offenders.offender_id = offenses.offender_id GROUP BY offender_name ORDER BY total_offenses DESC LIMIT 5; |
How many AI safety incidents were reported in the last month? | CREATE TABLE incidents (id INT,date DATE,type TEXT); | SELECT COUNT(*) as num_incidents FROM incidents WHERE date >= (CURRENT_DATE - INTERVAL '1 month'); |
List all aircraft with more than 100 orders by manufacturer and year of production | CREATE TABLE aircraft_orders (order_id INT,aircraft_id INT,manufacturer VARCHAR(50),production_year INT); CREATE TABLE aircraft (aircraft_id INT,manufacturer VARCHAR(50)); | SELECT manufacturer, production_year, COUNT(aircraft_id) as num_orders FROM aircraft_orders JOIN aircraft ON aircraft_orders.aircraft_id = aircraft.aircraft_id GROUP BY manufacturer, production_year HAVING COUNT(aircraft_id) > 100; |
List all unique users who played game 'B' between January 1, 2021 and January 7, 2021 | CREATE TABLE game_sessions (user_id INT,game_name VARCHAR(10),login_date DATE); INSERT INTO game_sessions (user_id,game_name,login_date) VALUES (1,'A','2021-01-01'),(2,'B','2021-01-02'),(3,'B','2021-01-03'),(4,'C','2021-01-04'); | SELECT DISTINCT user_id FROM game_sessions WHERE game_name = 'B' AND login_date BETWEEN '2021-01-01' AND '2021-01-07'; |
How many whale sightings were recorded in the 'marine_life_sightings' table for each type of whale? | CREATE TABLE marine_life_sightings (sighting_id INTEGER,species TEXT,sighting_date DATE); INSERT INTO marine_life_sightings (sighting_id,species,sighting_date) VALUES (1,'Blue Whale','2022-01-01'),(2,'Humpback Whale','2022-01-02'),(3,'Blue Whale','2022-01-03'); | SELECT species, COUNT(*) FROM marine_life_sightings WHERE species IN ('Blue Whale', 'Humpback Whale') GROUP BY species; |
Find the percentage of total biomass for each species in marine farms. | CREATE TABLE marine_farms_biomass (farm_id INT,species VARCHAR(20),biomass FLOAT); INSERT INTO marine_farms_biomass (farm_id,species,biomass) VALUES (1,'Tuna',1200.5),(2,'Swordfish',800.3),(3,'Shrimp',1500.2); | SELECT species, SUM(biomass) total_biomass, 100.0 * SUM(biomass) / (SELECT SUM(biomass) FROM marine_farms_biomass) percentage FROM marine_farms_biomass GROUP BY species; |
Find total tickets sold for all hip-hop concerts | CREATE TABLE concerts (concert_id INT PRIMARY KEY,artist_name VARCHAR(100),concert_date DATE,location VARCHAR(100),tickets_sold INT,genre VARCHAR(50)); INSERT INTO concerts (concert_id,artist_name,concert_date,location,tickets_sold,genre) VALUES (1,'Eminem','2023-06-15','New York City',15000,'Hip-Hop'); INSERT INTO con... | SELECT SUM(tickets_sold) FROM concerts WHERE genre = 'Hip-Hop'; |
What is the maximum donation amount for donors from Africa? | CREATE TABLE donors (id INT,name VARCHAR(50),continent VARCHAR(50),donation DECIMAL(10,2)); | SELECT MAX(donation) FROM donors WHERE continent = 'Africa'; |
What is the average salary of government employees in the state of Texas, and what is the mode salary? | CREATE TABLE GovernmentEmployees (EmployeeID INT,Salary DECIMAL(10,2),State VARCHAR(100)); INSERT INTO GovernmentEmployees (EmployeeID,Salary,State) VALUES (1,45000.00,'Texas'),(2,50000.00,'Texas'),(3,55000.00,'Texas'),(4,60000.00,'Texas'),(5,65000.00,'Texas'); | SELECT AVG(Salary) as AverageSalary, MAX(Salary) as ModeSalary FROM GovernmentEmployees WHERE State = 'Texas' GROUP BY Salary HAVING COUNT(*) > 1; |
Delete records for products that have not been sold for the last 4 months in stores located in 'Utah' and 'Arizona' | CREATE TABLE Stores (store_id INT,store_name VARCHAR(50),state VARCHAR(50)); INSERT INTO Stores (store_id,store_name,state) VALUES (1,'Eco-Market','Utah'),(2,'Green Vista','Arizona'); CREATE TABLE Inventory (inventory_id INT,product_id INT,product_name VARCHAR(50),store_id INT,last_sale_date DATE); INSERT INTO Inventor... | DELETE FROM Inventory WHERE last_sale_date < DATE_SUB(CURRENT_DATE, INTERVAL 4 MONTH) AND store_id IN (SELECT store_id FROM Stores WHERE state IN ('Utah', 'Arizona')); |
What is the average age of readers who prefer digital subscriptions, grouped by their country of residence? | CREATE TABLE Readers (ReaderID INT,Age INT,Country VARCHAR(50),SubscriptionType VARCHAR(50)); INSERT INTO Readers (ReaderID,Age,Country,SubscriptionType) VALUES (1,35,'USA','Digital'),(2,45,'Canada','Print'),(3,25,'Mexico','Digital'); | SELECT Country, AVG(Age) as AvgAge FROM Readers WHERE SubscriptionType = 'Digital' GROUP BY Country; |
What is the total revenue generated from the sales of sustainable products in Europe and Africa for the last quarter? | CREATE TABLE sales (sale_id INT,product_type VARCHAR(50),country VARCHAR(50),revenue DECIMAL(10,2)); INSERT INTO sales (sale_id,product_type,country,revenue) VALUES (1,'sustainable','France',500.00),(2,'non-sustainable','Nigeria',400.00),(3,'sustainable','Germany',600.00),(4,'sustainable','Kenya',550.00),(5,'non-sustai... | SELECT SUM(sales.revenue) FROM sales WHERE sales.product_type = 'sustainable' AND sales.country IN ('Europe', 'Africa') AND sales.date BETWEEN '2022-01-01' AND '2022-03-31'; |
How many drought-affected areas were there in the year 2020 and what was the average water consumption in those areas? | CREATE TABLE drought_areas (id INT,area VARCHAR(50),event_date DATE,water_consumption FLOAT); INSERT INTO drought_areas (id,area,event_date,water_consumption) VALUES (1,'Area1','2020-01-01',1200),(2,'Area2','2020-02-01',1500),(3,'Area3','2020-03-01',1800); | SELECT area, AVG(water_consumption) as avg_water_consumption FROM drought_areas WHERE YEAR(event_date) = 2020 GROUP BY area; |
How many clinical trials were conducted in Asia for vaccines? | CREATE TABLE clinical_trials (country TEXT,drug_class TEXT,trial_count INTEGER); | SELECT SUM(trial_count) FROM clinical_trials WHERE country = 'Asia' AND drug_class = 'vaccines'; |
What is the total revenue generated by each mobile network in Japan for the year 2021? | CREATE TABLE revenue_data (year INT,country VARCHAR(15),network VARCHAR(15),revenue FLOAT); INSERT INTO revenue_data (year,country,network,revenue) VALUES (2021,'Japan','NTT Docomo',15000000),(2021,'Japan','Softbank',12000000),(2021,'Japan','KDDI',13000000); | SELECT network, SUM(revenue) as total_revenue FROM revenue_data WHERE country = 'Japan' AND year = 2021 GROUP BY network; |
What is the number of nodes in the Algorand network? | CREATE TABLE network_nodes (node_id INT,network VARCHAR(50),nodes_count INT); INSERT INTO network_nodes (node_id,network,nodes_count) VALUES (1,'Algorand',1234); | SELECT nodes_count FROM network_nodes WHERE network = 'Algorand'; |
What is the minimum temperature and humidity for each crop type in the past month? | CREATE TABLE crop_temperature (crop_type TEXT,temperature INTEGER,timestamp TIMESTAMP);CREATE TABLE crop_humidity (crop_type TEXT,humidity INTEGER,timestamp TIMESTAMP); | SELECT ct.crop_type, MIN(ct.temperature) as min_temp, MIN(ch.humidity) as min_humidity FROM crop_temperature ct JOIN crop_humidity ch ON ct.timestamp = ch.timestamp WHERE ct.timestamp BETWEEN DATEADD(month, -1, CURRENT_TIMESTAMP) AND CURRENT_TIMESTAMP GROUP BY ct.crop_type; |
What is the total quantity of electronics shipped from each warehouse per country? | CREATE TABLE Shipments (id INT,WarehouseId INT,Product VARCHAR(50),Quantity INT,Destination VARCHAR(50),ShippedDate DATE); INSERT INTO Shipments (id,WarehouseId,Product,Quantity,Destination,ShippedDate) VALUES (1,1,'Laptop',50,'New York','2022-01-01'); INSERT INTO Shipments (id,WarehouseId,Product,Quantity,Destination,... | SELECT WarehouseId, Country, SUM(Quantity) AS TotalQuantity FROM (SELECT WarehouseId, Product, Quantity, Destination, SUBSTRING(Destination, 1, INSTR(Destination, ',') - 1) AS Country FROM Shipments) AS ShippedData GROUP BY WarehouseId, Country; |
What is the maximum quantity of a single organic product delivered in the DELIVERY table? | CREATE TABLE DELIVERY (id INT,supplier_id INT,product_id INT,is_organic BOOLEAN,quantity INT); | SELECT MAX(quantity) FROM DELIVERY WHERE is_organic = true; |
Identify the top 3 manufacturers with the highest total weight of chemicals produced, and rank them based on the date of their founding (earliest to latest) | CREATE TABLE manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),country VARCHAR(50),founding_date DATE); INSERT INTO manufacturers (manufacturer_id,manufacturer_name,country,founding_date) VALUES (1,'ABC Chemicals','USA','1950-01-01'),(2,'XYZ Chemicals','Canada','1980-01-01'),(3,'DEF Chemicals','USA','200... | SELECT manufacturer_id, manufacturer_name, SUM(weight) as total_weight, RANK() OVER (ORDER BY SUM(weight) DESC) as rank FROM chemicals JOIN manufacturers ON chemicals.manufacturer_id = manufacturers.manufacturer_id GROUP BY manufacturer_id, manufacturer_name ORDER BY rank ASC, founding_date ASC; |
Which members in the North region have completed a workout of type 'Spin' with a duration of more than 60 minutes? | CREATE TABLE memberships (id INT,member_type VARCHAR(50),region VARCHAR(50)); CREATE TABLE workout_data (member_id INT,workout_type VARCHAR(50),duration INT,heart_rate_avg INT,calories_burned INT,workout_date DATE); | SELECT m.id FROM memberships m JOIN workout_data w ON m.id = w.member_id WHERE m.region = 'North' AND w.workout_type = 'Spin' AND w.duration > 60 GROUP BY m.id; |
What is the total number of military personnel assigned to cybersecurity operations in Europe? | CREATE TABLE personnel_by_region(personnel_id INT,assignment VARCHAR(255),region VARCHAR(255)); INSERT INTO personnel_by_region(personnel_id,assignment,region) VALUES (1,'Cybersecurity','Europe'),(2,'Intelligence','Asia-Pacific'),(3,'Logistics','North America'),(4,'Cybersecurity','Europe'),(5,'Cybersecurity','North Ame... | SELECT COUNT(*) FROM personnel_by_region WHERE assignment = 'Cybersecurity' AND region = 'Europe'; |
What is the average age of patients who have received therapy sessions in the state of California? | CREATE TABLE therapists (therapist_id INT,therapist_name TEXT,state TEXT); CREATE TABLE therapy_sessions (session_id INT,patient_age INT,therapist_id INT); INSERT INTO therapists (therapist_id,therapist_name,state) VALUES (1,'Alice Johnson','California'); INSERT INTO therapy_sessions (session_id,patient_age,therapist_i... | SELECT AVG(therapy_sessions.patient_age) FROM therapy_sessions JOIN therapists ON therapy_sessions.therapist_id = therapists.therapist_id WHERE therapists.state = 'California'; |
Delete all routes associated with vessels that have a license_number of a captain who is under 30 years old. | CREATE TABLE Vessel (id INT,name VARCHAR(50),type VARCHAR(50),length FLOAT); CREATE TABLE Captain (id INT,name VARCHAR(50),age INT,license_number VARCHAR(50),VesselId INT); CREATE TABLE Route (id INT,departure_port VARCHAR(50),arrival_port VARCHAR(50),distance FLOAT,VesselId INT); | DELETE FROM Route WHERE VesselId IN (SELECT VesselId FROM Captain WHERE age < 30); |
What is the number of employees working on ethical manufacturing initiatives at the 'Responsible Production' plant? | CREATE TABLE Initiatives (id INT,name VARCHAR(255),plant_id INT,employees INT); INSERT INTO Initiatives (id,name,plant_id,employees) VALUES (4,'Ethical Manufacturing',7,50); CREATE TABLE Plants (id INT,name VARCHAR(255)); INSERT INTO Plants (id,name) VALUES (7,'Responsible Production'); | SELECT employees FROM Initiatives WHERE name = 'Ethical Manufacturing' AND plant_id = 7; |
What is the average number of mental health conditions treated by providers in each region? | CREATE TABLE regions (region_id INT,region_name VARCHAR(50)); INSERT INTO regions (region_id,region_name) VALUES (1,'Northeast'),(2,'Southeast'),(3,'Midwest'),(4,'Southwest'),(5,'West'); CREATE TABLE providers (provider_id INT,provider_name VARCHAR(50),region_id INT); INSERT INTO providers (provider_id,provider_name,re... | SELECT p.region_id, AVG(pp.condition_count) as avg_conditions FROM providers p JOIN (SELECT provider_id, COUNT(DISTINCT condition_id) as condition_count FROM provider_patients GROUP BY provider_id) pp ON p.provider_id = pp.provider_id GROUP BY p.region_id; |
Delete records in the 'carbon_prices' table where the 'price_usd_per_ton' is greater than 50 | CREATE TABLE carbon_prices (country VARCHAR(255) PRIMARY KEY,price_usd_per_ton FLOAT); | DELETE FROM carbon_prices WHERE price_usd_per_ton > 50; |
Update the record in the 'community_engagement' table with an engagement ID of 7 to reflect a total of 150 social media shares | CREATE TABLE community_engagement (engagement_id INT,engagement_type VARCHAR(10),total_shares INT); | UPDATE community_engagement SET total_shares = 150 WHERE engagement_id = 7; |
What is the total number of policies and their corresponding policy types for policyholders aged 30 or younger? | CREATE TABLE Policyholders (PolicyholderID INT,Age INT,PolicyType VARCHAR(20)); INSERT INTO Policyholders (PolicyholderID,Age,PolicyType) VALUES (1,25,'Auto'),(2,32,'Home'),(3,19,'Life'); | SELECT COUNT(*) as TotalPolicies, PolicyType FROM Policyholders WHERE Age <= 30 GROUP BY PolicyType; |
Find the total donations and number of donors for each disaster type. | CREATE TABLE DonorDisaster (DonorID INT,DisasterType VARCHAR(25),Amount DECIMAL(10,2)); INSERT INTO DonorDisaster (DonorID,DisasterType,Amount) VALUES (1,'Earthquake',100.00),(1,'Flood',50.00); | SELECT DisasterType, SUM(Amount) as TotalDonations, COUNT(DISTINCT DonorID) as NumDonors FROM DonorDisaster GROUP BY DisasterType; |
Find the third highest account balance for Shariah-compliant finance customers, and identify the customer's name. | CREATE TABLE shariah_compliant_finance(customer_id INT,name VARCHAR(50),account_balance DECIMAL(10,2)); INSERT INTO shariah_compliant_finance VALUES (1,'Hassan Ahmed',10000),(2,'Aisha Bibi',12000),(3,'Muhammad Ali',15000),(4,'Fatima Khan',11000); | SELECT name, account_balance FROM (SELECT customer_id, name, account_balance, ROW_NUMBER() OVER (ORDER BY account_balance DESC) AS rn FROM shariah_compliant_finance) t WHERE rn = 3; |
List all the dams along with their heights from the 'dam_info' and 'dam_heights' tables. | CREATE TABLE dam_info (dam_id INT,dam_name VARCHAR(50)); CREATE TABLE dam_heights (dam_id INT,dam_height INT); INSERT INTO dam_info (dam_id,dam_name) VALUES (1,'Hoover Dam'),(2,'Grand Coulee Dam'),(3,'Oroville Dam'); INSERT INTO dam_heights (dam_id,dam_height) VALUES (1,726),(2,550),(3,770); | SELECT dam_info.dam_name, dam_heights.dam_height FROM dam_info INNER JOIN dam_heights ON dam_info.dam_id = dam_heights.dam_id; |
What are the total sales for each drug in Q1 2020? | CREATE TABLE drugs (drug_id INT,drug_name TEXT); INSERT INTO drugs (drug_id,drug_name) VALUES (1001,'Ibuprofen'),(1002,'Paracetamol'),(1003,'Aspirin'); 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',1500.0),(2,... | SELECT drug_name, SUM(revenue) as total_sales 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; |
How many research grants have been awarded to graduate students in the Humanities department? | CREATE TABLE students (student_id INT PRIMARY KEY,name VARCHAR(50),department VARCHAR(50),grant_recipient BOOLEAN); INSERT INTO students (student_id,name,department,grant_recipient) VALUES (1,'David','Humanities',TRUE); CREATE TABLE grants (grant_id INT PRIMARY KEY,student_id INT,amount FLOAT); INSERT INTO grants (gran... | SELECT COUNT(*) FROM grants g INNER JOIN students s ON g.student_id = s.student_id WHERE s.department = 'Humanities' AND s.grant_recipient = TRUE; |
What is the total amount donated by each donor in the 'donors' table, joined with their corresponding city information from the 'cities' table? | CREATE TABLE donors (donor_id INT,donor_name TEXT,donation_amount DECIMAL,city_id INT); CREATE TABLE cities (city_id INT,city_name TEXT); | SELECT donors.donor_name, SUM(donation_amount) FROM donors INNER JOIN cities ON donors.city_id = cities.city_id GROUP BY donor_name; |
Which water treatment plants have water usage above the average? | CREATE TABLE water_treatment_plants (id INT,name TEXT,water_usage FLOAT); INSERT INTO water_treatment_plants (id,name,water_usage) VALUES (1,'Plant A',1000000),(2,'Plant B',1500000),(3,'Plant C',800000); | SELECT name FROM water_treatment_plants WHERE water_usage > (SELECT AVG(water_usage) FROM water_treatment_plants); |
What is the average broadband speed in each country in Europe? | CREATE TABLE broadband_speeds (location VARCHAR(20),speed FLOAT,country VARCHAR(20)); INSERT INTO broadband_speeds (location,speed,country) VALUES ('Madrid',120.4,'Spain'); INSERT INTO broadband_speeds (location,speed,country) VALUES ('Barcelona',150.6,'Spain'); | SELECT country, AVG(speed) FROM broadband_speeds GROUP BY country; |
What are the names and types of renewable energy projects in the city of Seattle? | CREATE TABLE renewable_projects (project_name VARCHAR(255),project_type VARCHAR(255),city VARCHAR(255)); | SELECT project_name, project_type FROM renewable_projects WHERE city = 'Seattle'; |
List the top 3 most affordable cities for first-time home buyers. | CREATE TABLE city_data (city VARCHAR(50),median_home_price FLOAT,first_time_buyer_friendly INT); INSERT INTO city_data (city,median_home_price,first_time_buyer_friendly) VALUES ('CityA',200000,1),('CityB',300000,0),('CityC',150000,1),('CityD',400000,1),('CityE',250000,0); | SELECT city, median_home_price FROM (SELECT city, median_home_price, RANK() OVER (ORDER BY median_home_price ASC) AS rank FROM city_data WHERE first_time_buyer_friendly = 1) AS subquery WHERE rank <= 3; |
Update the email addresses for donors with missing domain information ('@' symbol is missing). | CREATE TABLE donor_emails (id INT,donor_id INT,email VARCHAR(50)); INSERT INTO donor_emails (id,donor_id,email) VALUES (1,1,'johndoe'),(2,2,'janesmith'),(3,3,'alicej'); | UPDATE donor_emails SET email = CONCAT(email, '@example.org') WHERE email NOT LIKE '%@%'; |
What is the maximum speed of electric vehicles produced by Tesla? | CREATE TABLE ElectricVehicles (Id INT,Make VARCHAR(50),Model VARCHAR(50),MaxSpeed FLOAT); INSERT INTO ElectricVehicles (Id,Make,Model,MaxSpeed) VALUES (1,'Tesla','Model S',261),(2,'Tesla','Model 3',225),(3,'Tesla','Model X',250),(4,'Tesla','Model Y',217); | SELECT MAX(MaxSpeed) FROM ElectricVehicles WHERE Make = 'Tesla' AND Model LIKE 'Model%' |
What is the total number of pallets with a temperature above 30 degrees Celsius stored in warehouses located in Asia? | CREATE TABLE WarehouseTemperature (id INT,temperature FLOAT,location VARCHAR(20)); INSERT INTO WarehouseTemperature (id,temperature,location) VALUES (1,35,'Asia'),(2,20,'Europe'); | SELECT COUNT(*) FROM WarehouseTemperature WHERE location LIKE '%Asia%' AND temperature > 30; |
How many animals are there in the 'animal_habitat' table? | CREATE TABLE animal_habitat (habitat_id INT,habitat_name VARCHAR(50),animal_name VARCHAR(50),acres FLOAT); INSERT INTO animal_habitat (habitat_id,habitat_name,animal_name,acres) VALUES (1,'African Savannah','Lion',5000.0),(2,'Asian Rainforest','Tiger',2000.0),(3,'African Rainforest','Elephant',3000.0); | SELECT COUNT(*) FROM animal_habitat; |
How many energy storage projects are there in California, Texas, and New York? | CREATE TABLE energy_storage (state TEXT,num_projects INTEGER); INSERT INTO energy_storage (state,num_projects) VALUES ('California',563),('Texas',357),('New York',256),('Florida',152),('Illinois',140),('Pennsylvania',137),('Ohio',128),('North Carolina',127),('Michigan',122),('New Jersey',118); | SELECT num_projects FROM energy_storage WHERE state IN ('California', 'Texas', 'New York') |
Delete records from the "users" table where the country is "Canada" and the "ai_familiarity" score is less than 4 | CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(50),country VARCHAR(50),ai_familiarity INT); INSERT INTO users (id,name,country,ai_familiarity) VALUES (1,'John Doe','Canada',3); INSERT INTO users (id,name,country,ai_familiarity) VALUES (2,'Jane Smith','USA',5); | DELETE FROM users WHERE country = 'Canada' AND ai_familiarity < 4; |
What are the primary genres and the number of artists for each, for artists with more than 5 million followers? | CREATE TABLE artist (artist_id INT,artist_name VARCHAR(50),num_followers INT,primary_genre VARCHAR(30)); INSERT INTO artist (artist_id,artist_name,num_followers,primary_genre) VALUES (1,'DJ Khalid',3500000,'Hip Hop'); INSERT INTO artist (artist_id,artist_name,num_followers,primary_genre) VALUES (2,'Taylor Swift',680000... | SELECT primary_genre, COUNT(artist_id) as num_artists FROM artist WHERE num_followers > 5000000 GROUP BY primary_genre; |
What is the total revenue of games with a "racing" genre in North America? | CREATE TABLE Games (GameID INT,GameName VARCHAR(100),Genre VARCHAR(50),AdoptionRevenue DECIMAL(10,2),Country VARCHAR(50)); INSERT INTO Games (GameID,GameName,Genre,AdoptionRevenue,Country) VALUES (1,'Racing Game A','racing',300.00,'USA'),(2,'RPG Game B','RPG',400.00,'Canada'),(3,'Strategy Game C','strategy',500.00,'Mex... | SELECT SUM(AdoptionRevenue) FROM Games WHERE Genre = 'racing' AND Country = 'North America'; |
What is the total number of hours spent by indigenous communities on AI training programs in universities in Oceania? | CREATE TABLE communities_indigenous (community_id INT,community_name VARCHAR(100),region VARCHAR(50)); INSERT INTO communities_indigenous VALUES (1,'Indigenous Australian STEM','Oceania'),(2,'Maori AI Learners','Oceania'); CREATE TABLE university_programs (program_id INT,program_name VARCHAR(100),community_id INT); INS... | SELECT SUM(hours) FROM participation INNER JOIN university_programs ON participation.program_id = university_programs.program_id INNER JOIN communities_indigenous ON university_programs.community_id = communities_indigenous.community_id WHERE communities_indigenous.region = 'Oceania'; |
Provide the total number of heritage sites in the Asia-Pacific region, not including UNESCO World Heritage Sites. | CREATE TABLE HeritageSites (SiteID INT,SiteName VARCHAR(100),Country VARCHAR(50),Region VARCHAR(50),IsUNESCOWorldHeritageSite BOOLEAN,UNIQUE (SiteID)); | SELECT COUNT(*) FROM HeritageSites WHERE Region = 'Asia-Pacific' AND IsUNESCOWorldHeritageSite = FALSE; |
Calculate the average CO2 emissions for each garment category in 2020. | CREATE TABLE garment_manufacturing (garment_category VARCHAR(255),manufacturing_date DATE,co2_emissions INT); | SELECT garment_category, AVG(co2_emissions) FROM garment_manufacturing WHERE manufacturing_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY garment_category; |
What is the change in the number of access to justice petitions per month? | CREATE TABLE AccessToJusticePetitions (id INT,petition_date DATE,petitions INT); INSERT INTO AccessToJusticePetitions (id,petition_date,petitions) VALUES (1,'2022-01-01',1000),(2,'2022-02-01',1500),(3,'2022-03-01',1800),(4,'2022-04-01',2000),(5,'2022-05-01',2500); | SELECT EXTRACT(MONTH FROM petition_date) as month, (LEAD(petitions) OVER (ORDER BY petition_date) - petitions) as change FROM AccessToJusticePetitions; |
What is the total amount donated by each donor in descending order? | CREATE TABLE Donors (DonorID INT,DonorName TEXT,TotalDonation DECIMAL); | SELECT DonorName, SUM(TotalDonation) OVER (PARTITION BY DonorName ORDER BY SUM(TotalDonation) DESC) AS TotalDonation FROM Donors; |
What is the most popular game genre among players aged 18 or above? | CREATE TABLE PlayerGameGenre (PlayerID INT,Age INT,GameGenre VARCHAR(30)); INSERT INTO PlayerGameGenre (PlayerID,Age,GameGenre) VALUES (1,16,'FPS'),(2,20,'RPG'),(3,18,'FPS'),(4,25,'Simulation'); | SELECT GameGenre, COUNT(*) as GameCount FROM PlayerGameGenre WHERE Age >= 18 GROUP BY GameGenre ORDER BY GameCount DESC LIMIT 1; |
Which policies have been updated in the last 30 days? Provide the output in the format: policy_name, last_updated_date. | CREATE TABLE policies (id INT,policy_name VARCHAR(255),last_updated_date DATE); INSERT INTO policies (id,policy_name,last_updated_date) VALUES (1,'Access Control','2022-01-01'),(2,'Incident Response','2022-01-15'),(3,'Data Privacy','2022-02-10'),(4,'Network Security','2022-03-05'); | SELECT policy_name, last_updated_date FROM policies WHERE last_updated_date >= DATE(NOW()) - INTERVAL 30 DAY; |
How many unique donors have made donations to organizations focused on human rights, categorized by continent? | CREATE TABLE donors (id INT,name TEXT,country TEXT); CREATE TABLE donations (id INT,donor_id INT,organization_id INT); CREATE TABLE organizations (id INT,name TEXT,cause_area TEXT,country TEXT); CREATE TABLE countries (id INT,name TEXT,continent TEXT); | SELECT c.continent, COUNT(DISTINCT d.id) as num_unique_donors FROM donors d INNER JOIN donations ON d.id = donations.donor_id INNER JOIN organizations o ON donations.organization_id = o.id INNER JOIN countries ON d.country = countries.name WHERE o.cause_area = 'human rights' GROUP BY c.continent; |
In which peacekeeping operations did the US participate the most? | CREATE TABLE peacekeeping_operations (operation_name VARCHAR(50),country VARCHAR(50),years_participated INT); INSERT INTO peacekeeping_operations (operation_name,country,years_participated) VALUES ('MINUSTAH','United States',13),('MONUSCO','United States',8),('UNMISS','United States',10),('UNAMID','United States',7),('... | SELECT operation_name, SUM(years_participated) as total_years_participated FROM peacekeeping_operations WHERE country = 'United States' GROUP BY operation_name ORDER BY total_years_participated DESC LIMIT 1; |
What is the maximum 'renewable energy capacity' added by 'China' in a single 'year' from the 'mitigation' table? | CREATE TABLE mitigation (country VARCHAR(255),capacity INT,year INT); | SELECT MAX(capacity) FROM mitigation WHERE country = 'China' GROUP BY year; |
What is the number of academic publications per graduate student from Africa? | CREATE TABLE graduate_students (student_id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO graduate_students (student_id,name,country) VALUES (1,'Alice','Egypt'),(2,'Bob','Canada'),(3,'Carlos','Mexico'),(4,'Diana','South Africa'),(5,'Eli','Nigeria'); CREATE TABLE academic_publications (publication_id INT,student... | SELECT gs.country, COUNT(ap.publication_id) AS num_publications FROM graduate_students gs JOIN academic_publications ap ON gs.student_id = ap.student_id WHERE gs.country IN ('Egypt', 'South Africa', 'Nigeria') GROUP BY gs.country; |
Delete the carbon offset program with id 4 | CREATE TABLE carbon_offset_programs (id INT,name TEXT,start_date DATE,end_date DATE); INSERT INTO carbon_offset_programs (id,name,start_date,end_date) VALUES (1,'Trees for the Future','2020-01-01','2022-12-31'); INSERT INTO carbon_offset_programs (id,name,start_date,end_date) VALUES (2,'Clean Oceans','2019-07-01','2021... | DELETE FROM carbon_offset_programs WHERE id = 4; |
How many items were produced in the 'autumn 2021' collection with a production cost above 30? | CREATE TABLE production_costs (item_type VARCHAR(20),collection VARCHAR(20),cost NUMERIC(10,2),quantity INT); INSERT INTO production_costs (item_type,collection,cost,quantity) VALUES ('cashmere sweater','autumn 2021',32.99,100),('cashmere scarf','autumn 2021',35.99,75),('cotton t-shirt','autumn 2021',12.99,250),('cotto... | SELECT COUNT(*) FROM production_costs WHERE collection = 'autumn 2021' AND cost > 30; |
Update the music genre for 'SongE' to 'Pop' in the Music table. | CREATE TABLE Music (song_id INT,title TEXT,genre TEXT); INSERT INTO Music (song_id,title,genre) VALUES (1,'SongA','Rock'),(2,'SongB','Jazz'),(3,'SongC','Hip-Hop'),(4,'SongD','Country'),(5,'SongE','RnB'); | UPDATE Music SET genre = 'Pop' WHERE title = 'SongE'; |
Which artworks were exhibited in both Paris and New York? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name VARCHAR(255),Nationality VARCHAR(255)); CREATE TABLE Artworks (ArtworkID INT PRIMARY KEY,Title VARCHAR(255),ArtistID INT,Year INT); CREATE TABLE Exhibitions (ExhibitionID INT PRIMARY KEY,Name VARCHAR(255),StartDate DATE,EndDate DATE,City VARCHAR(255)); CREATE TABLE Ex... | SELECT Artworks.Title FROM Artworks INNER JOIN ExhibitionArtworks ON Artworks.ArtworkID = ExhibitionArtworks.ArtworkID INNER JOIN Exhibitions ON ExhibitionArtworks.ExhibitionID = Exhibitions.ExhibitionID WHERE Exhibitions.City IN ('Paris', 'New York') GROUP BY Artworks.Title HAVING COUNT(DISTINCT Exhibitions.City) = 2; |
Select all records from trends table where region='Asia' and forecast='Spring' | CREATE TABLE trends (id INT,trend_name VARCHAR(50),region VARCHAR(50),forecast VARCHAR(50),popularity INT); | SELECT * FROM trends WHERE region = 'Asia' AND forecast = 'Spring'; |
What is the maximum number of open pedagogy projects completed by students in each school? | CREATE TABLE schools (school_id INT,school_name TEXT,num_students INT); CREATE TABLE projects (project_id INT,project_name TEXT,school_id INT,student_id INT,num_projects INT); INSERT INTO schools (school_id,school_name,num_students) VALUES (1,'Innovation School',100),(2,'Creativity School',120),(3,'Discovery School',15... | SELECT school_name, MAX(num_projects) as max_projects FROM schools JOIN projects ON schools.school_id = projects.school_id GROUP BY school_name; |
What is the total quantity of ethically sourced products sold by region? | CREATE TABLE sales (product_id INT,region VARCHAR(255),quantity INT,ethical_source BOOLEAN); INSERT INTO sales (product_id,region,quantity,ethical_source) VALUES (1,'North',100,true),(2,'South',200,false),(3,'East',150,true); | SELECT region, ethical_source, SUM(quantity) AS total_quantity FROM sales GROUP BY region, ethical_source; |
What is the total donation amount per program in the last 3 months? | CREATE TABLE Donations (DonationID INT,DonationDate DATE,DonationAmount DECIMAL(10,2),ProgramID INT); INSERT INTO Donations (DonationID,DonationDate,DonationAmount,ProgramID) VALUES (10,'2022-05-01',550.00,1),(11,'2022-05-15',650.00,1),(12,'2022-05-01',750.00,2),(13,'2022-05-15',850.00,2),(14,'2022-06-01',950.00,3); | SELECT ProgramID, SUM(DonationAmount) OVER (PARTITION BY ProgramID ORDER BY DonationDate ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) AS TotalDonationInLast3Months FROM Donations; |
Find the average safety score of AI models created by African researchers since 2020. | CREATE TABLE ModelScores (model_id INT,score FLOAT,dev_region VARCHAR(255),model_year INT); INSERT INTO ModelScores (model_id,score,dev_region,model_year) VALUES (1,8.5,'Africa',2020),(2,9.2,'Asia',2021),(3,8.8,'Europe',2022); | SELECT AVG(score) FROM ModelScores WHERE dev_region = 'Africa' AND model_year >= 2020; |
What is the total military equipment sales revenue for 'ABC Corp' from 2019 to 2021? | CREATE TABLE defense_contractors_3 (corp varchar(255),year int,sales int); INSERT INTO defense_contractors_3 (corp,year,sales) VALUES ('ABC Corp',2019,800000),('ABC Corp',2020,900000),('ABC Corp',2021,1000000); | SELECT SUM(sales) FROM defense_contractors_3 WHERE corp = 'ABC Corp' AND year BETWEEN 2019 AND 2021; |
Find the number of community policing interactions for each interaction type in the Downtown neighborhood | CREATE TABLE community_policing_interactions (id SERIAL PRIMARY KEY,neighborhood_id INTEGER,interaction_type VARCHAR(255),interaction_count INTEGER); CREATE TABLE neighborhoods (id SERIAL PRIMARY KEY,name VARCHAR(255),location POINT,radius INTEGER); INSERT INTO neighborhoods (name,location,radius) VALUES ('Downtown','(... | SELECT interaction_type, SUM(interaction_count) as total_interactions FROM community_policing_interactions cpi JOIN neighborhoods n ON n.id = cpi.neighborhood_id WHERE n.name = 'Downtown' GROUP BY interaction_type; |
Find the number of water conservation initiatives implemented in 'Sydney' before 2018 | CREATE TABLE conservation_initiatives (region VARCHAR(50),date DATE,initiative VARCHAR(50)); INSERT INTO conservation_initiatives (region,date,initiative) VALUES ('Sydney','2017-01-01','Rainwater harvesting'),('Sydney','2016-01-01','Greywater reuse'),('Sydney','2015-01-01','Smart irrigation'); | SELECT COUNT(*) FROM conservation_initiatives WHERE region = 'Sydney' AND date < '2018-01-01'; |
What is the total amount donated by each donor from the United States, including their contact information? | CREATE TABLE Donors (DonorID INT,FirstName TEXT,LastName TEXT,Country TEXT); INSERT INTO Donors (DonorID,FirstName,LastName,Country) VALUES (1,'John','Doe','USA'),(2,'Jane','Smith','USA'); CREATE TABLE Donations (DonationID INT,DonorID INT,Amount DECIMAL); INSERT INTO Donations (DonationID,DonorID,Amount) VALUES (1,1,5... | SELECT D.FirstName, D.LastName, D.Country, SUM(DON.Amount) AS TotalDonated FROM Donors D INNER JOIN Donations DON ON D.DonorID = DON.DonorID WHERE D.Country = 'USA' GROUP BY D.DonorID; |
Delete all records from the 'sports_team_performance' table where the 'team_name' is 'Los Angeles Lakers' | CREATE TABLE sports_team_performance (team_name VARCHAR(20),wins INT,losses INT); INSERT INTO sports_team_performance (team_name,wins,losses) VALUES ('Los Angeles Lakers',55,27),('Boston Celtics',48,34); | DELETE FROM sports_team_performance WHERE team_name = 'Los Angeles Lakers'; |
List the top 5 donors by total donation amount in the year 2019, showing their total donation amount, state, and country. | CREATE TABLE Donors (DonorID INT,DonorName TEXT,State TEXT,Country TEXT,TotalDonation DECIMAL); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL); | SELECT D.DonorName, SUM(D.DonationAmount) as TotalDonation, D.State, D.Country FROM Donations D JOIN Donors DON ON D.DonorID = DON.DonorID WHERE YEAR(D.DonationDate) = 2019 GROUP BY D.DonorName, D.State, D.Country ORDER BY TotalDonation DESC LIMIT 5; |
What are the names of UNESCO heritage sites in Europe and their types? | CREATE TABLE UNESCO_SITES (id INT PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),type VARCHAR(255)); INSERT INTO UNESCO_SITES (id,name,region,type) VALUES (1,'Colosseum','Europe','Cultural'); | SELECT name, type FROM UNESCO_SITES WHERE region = 'Europe'; |
What is the total number of missions for astronauts from Russia? | CREATE TABLE astronauts (astronaut_id INT,name VARCHAR(255),gender VARCHAR(255),age INT,country VARCHAR(255),missions INT); INSERT INTO astronauts (astronaut_id,name,gender,age,country,missions) VALUES (1,'Yuri Gagarin','Male',41,'Russia',1); | SELECT country, SUM(missions) as total_missions FROM astronauts WHERE country = 'Russia' GROUP BY country; |
What is the total number of reindeer in Norway's Finnmark County? | CREATE TABLE ReindeerData (reindeer_name VARCHAR(50),county VARCHAR(50),population INT); INSERT INTO ReindeerData (reindeer_name,county,population) VALUES ('Finnmark Reindeer','Finnmark County',15000),('Sami Reindeer','Finnmark County',20000); | SELECT county, SUM(population) FROM ReindeerData WHERE reindeer_name IN ('Finnmark Reindeer', 'Sami Reindeer') GROUP BY county; |
What is the average score for students who have received extended time accommodation? | CREATE TABLE Students (StudentID INT,Name VARCHAR(50),Disability VARCHAR(50)); CREATE TABLE StudentAccommodations (StudentID INT,AccommodationID INT,StartDate DATE,EndDate DATE); CREATE TABLE Accommodations (AccommodationID INT,Accommodation VARCHAR(100),Description TEXT); CREATE TABLE ExamResults (ExamID INT,StudentID... | SELECT AVG(er.Score) as AverageScore FROM ExamResults er JOIN Students s ON er.StudentID = s.StudentID JOIN StudentAccommodations sa ON s.StudentID = sa.StudentID JOIN Accommodations a ON sa.AccommodationID = a.AccommodationID WHERE a.Accommodation = 'Extended time'; |
Which museum has the most international visitors in the last 6 months? | CREATE TABLE museums (id INT,name TEXT,city TEXT);CREATE TABLE museum_visitors (id INT,visitor_id INT,museum_id INT,country TEXT);CREATE TABLE visitors (id INT,name TEXT); | SELECT m.name, COUNT(mv.visitor_id) as num_visitors FROM museums m JOIN museum_visitors mv ON m.id = mv.museum_id JOIN visitors v ON mv.visitor_id = v.id WHERE v.country != 'USA' AND mv.visit_date >= DATEADD(month, -6, GETDATE()) GROUP BY m.name ORDER BY num_visitors DESC LIMIT 1; |
What is the average rating of tours in Asia with a vegetarian meal option? | CREATE TABLE if NOT EXISTS tours (id INT,name TEXT,rating FLOAT,vegetarian_meal BOOLEAN); INSERT INTO tours (id,name,rating,vegetarian_meal) VALUES (1,'Mountain Biking Adventure',4.5,true),(2,'Historic City Tour',4.2,false); | SELECT AVG(rating) FROM tours WHERE vegetarian_meal = true AND country = 'Asia'; |
Calculate the average calories burned per day for all users who participated in 'Zumba' classes. | CREATE TABLE user_calories (user_id INT,date DATE,calories INT,class VARCHAR(50)); INSERT INTO user_calories (user_id,date,calories,class) VALUES (1,'2022-01-01',300,'Zumba'),(1,'2022-01-02',350,'Zumba'),(2,'2022-01-01',250,'Yoga'),(2,'2022-01-02',200,'Yoga'),(1,'2022-01-03',400,'Zumba'); | SELECT AVG(calories) FROM user_calories WHERE class = 'Zumba'; |
How many Olympic medals has Usain Bolt won? | CREATE TABLE olympic_athletes (athlete_id INT,name VARCHAR(50),country VARCHAR(50),medals INT); INSERT INTO olympic_athletes (athlete_id,name,country,medals) VALUES (1,'Usain Bolt','Jamaica',8); | SELECT medals FROM olympic_athletes WHERE name = 'Usain Bolt'; |
What is the total value of military equipment sales to each country in the current year? | CREATE TABLE equipment_sales (id INT,country VARCHAR(50),equipment_type VARCHAR(50),year INT,sales INT); INSERT INTO equipment_sales (id,country,equipment_type,year,sales) VALUES (1,'USA','Tanks',2018,5000000),(2,'USA','Aircraft',2018,12000000),(3,'China','Tanks',2018,800000),(4,'China','Aircraft',2018,1500000),(5,'Fra... | SELECT country, SUM(sales) as total_sales FROM equipment_sales WHERE year = YEAR(CURRENT_TIMESTAMP) GROUP BY country; |
Which properties in the 'property_co_ownership' table are co-owned by a person with id 5? | CREATE TABLE property_co_ownership (id INT,property_id INT,co_owner_id INT,agreement_start_date DATE,agreement_end_date DATE); | SELECT property_id FROM property_co_ownership WHERE co_owner_id = 5; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.