instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average monthly data usage for postpaid mobile users? | CREATE TABLE mobile_subscribers (subscriber_id INT,plan_type VARCHAR(10),monthly_data_usage INT); | SELECT AVG(monthly_data_usage) FROM mobile_subscribers WHERE plan_type = 'postpaid'; |
What is the total number of 5G base stations in the APAC region, and how many of them are in rural areas? | CREATE TABLE base_stations (station_id INT,tech VARCHAR(10),location VARCHAR(20)); INSERT INTO base_stations (station_id,tech,location) VALUES (1,'5G','urban'),(2,'4G','rural'); CREATE TABLE locations (location VARCHAR(20),region VARCHAR(10)); INSERT INTO locations (location,region) VALUES ('urban','APAC'),('rural','APAC'); | SELECT SUM(bs.tech = '5G') AS total_5G, SUM(bs.tech = '5G' AND bs.location = 'rural') AS rural_5G FROM base_stations bs JOIN locations l ON bs.location = l.location WHERE l.region = 'APAC'; |
Create a view named "top_five_artists_by_donations" that displays the top 5 artists with the highest total donations to museums. | CREATE TABLE museum_donations (donor_artist_id INT,museum_id INT,donation_value DECIMAL(10,2)); | CREATE VIEW top_five_artists_by_donations AS SELECT donor_artist_id, SUM(donation_value) AS total_donated FROM museum_donations GROUP BY donor_artist_id ORDER BY total_donated DESC FETCH FIRST 5 ROWS ONLY; |
Delete all players who are under 18 years old | CREATE TABLE players (id INT PRIMARY KEY,name VARCHAR(50),age INT); INSERT INTO players (id,name,age) VALUES (1,'John Doe',25),(2,'Jane Smith',17),(3,'Marie Lee',28); | DELETE FROM players WHERE age < 18; |
What is the total number of students who have improved their mental health scores in the past year and their average improvement score? | CREATE TABLE students (student_id INT,mental_health_score INT,improvement_1year INT); INSERT INTO students (student_id,mental_health_score,improvement_1year) VALUES (1,60,5),(2,70,10),(3,50,0),(4,80,-2),(5,40,15); | SELECT SUM(improvement_1year), AVG(improvement_1year) FROM students WHERE improvement_1year > 0; |
List unique mental health parity laws by state. | CREATE TABLE MentalHealthParity (MHPId INT,Law VARCHAR(255),State VARCHAR(50)); INSERT INTO MentalHealthParity (MHPId,Law,State) VALUES (1,'Parity Act 2020','California'),(2,'Mental Health Equity Act 2018','Texas'),(3,'Parity Law 2019','Florida'); | SELECT DISTINCT State, Law FROM MentalHealthParity; |
List all timber production sites located in 'Asia' or 'Africa' regions. | CREATE TABLE timber_production (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO timber_production (id,name,region) VALUES (1,'Timber Inc.','Asia'),(2,'WoodCo','Africa'),(3,'Forest Ltd.','North America'); | SELECT name FROM timber_production WHERE region IN ('Asia', 'Africa'); |
What is the average production (in metric tons) of staple crops (rice, wheat, corn) in Southeast Asia and how many farms produce them? | CREATE TABLE StapleCropProduction (id INT,crop VARCHAR(50),region VARCHAR(50),production DECIMAL(10,2)); INSERT INTO StapleCropProduction (id,crop,region,production) VALUES (1,'Rice','Southeast Asia',5.0); INSERT INTO StapleCropProduction (id,crop,region,production) VALUES (2,'Wheat','Southeast Asia',3.5); | SELECT AVG(production), COUNT(DISTINCT farm_id) FROM (SELECT farm_id, crop, production FROM StapleCropProduction WHERE region = 'Southeast Asia' AND crop IN ('Rice', 'Wheat', 'Corn')) AS subquery; |
What is the average number of military personnel in the Navy, Marines, and AirForce? | CREATE TABLE MilitaryPersonnel (branch TEXT,num_personnel INTEGER); INSERT INTO MilitaryPersonnel (branch,num_personnel) VALUES ('Army',500000),('Navy',350000),('AirForce',300000),('Marines',200000); | SELECT AVG(num_personnel) FROM MilitaryPersonnel WHERE branch IN ('Navy', 'Marines', 'AirForce'); |
What is the average R&D expenditure per drug in the last 12 months, ordered by the highest average expenditure first? | CREATE TABLE rd_expenses (drug_name VARCHAR(255),expense_date DATE,expenditure DECIMAL(10,2)); INSERT INTO rd_expenses (drug_name,expense_date,expenditure) VALUES ('Drug 1','2022-01-01',5000),('Drug 2','2022-02-03',7000),('Drug 3','2022-07-15',6000),('Drug 4','2022-11-22',8000); | SELECT drug_name, AVG(expenditure) as avg_expenditure FROM rd_expenses WHERE expense_date >= DATEADD(month, -12, GETDATE()) GROUP BY drug_name ORDER BY avg_expenditure DESC; |
Delete all workouts of users from Sydney with avg_heart_rate below 80. | CREATE TABLE workouts (id INT,user_location VARCHAR(50),workout_date DATE,avg_heart_rate INT); INSERT INTO workouts (id,user_location,workout_date,avg_heart_rate) VALUES (1,'Sydney','2022-01-01',85),(2,'Sydney','2022-01-02',75); | DELETE FROM workouts WHERE user_location = 'Sydney' AND avg_heart_rate < 80; |
What is the total waste generation in e-waste category for each country in 2021?' | CREATE TABLE ewaste (country VARCHAR(50),year INT,amount INT); INSERT INTO ewaste (country,year,amount) VALUES ('USA',2021,50000),('Canada',2021,40000),('Mexico',2021,30000); | SELECT country, SUM(amount) as total_ewaste FROM ewaste WHERE year = 2021 GROUP BY country; |
Number of TV shows by production company? | CREATE TABLE TVShows (ShowID INT,Title VARCHAR(100),ProductionCompany VARCHAR(100)); | SELECT ProductionCompany, COUNT(*) as Num_Shows FROM TVShows GROUP BY ProductionCompany; |
What is the maximum depth a marine species can be found in the 'deep_sea_species' table? | CREATE TABLE deep_sea_species (species_id INTEGER,species_name TEXT,max_depth FLOAT); INSERT INTO deep_sea_species (species_id,species_name,max_depth) VALUES (1,'Anglerfish',3000.0),(2,'Giant Squid',3000.0),(3,'Vampire Squid',2000.0); | SELECT MAX(max_depth) FROM deep_sea_species; |
What is the average sales figure for each drug in the oncology department? | CREATE TABLE drugs (id INT,name VARCHAR(50),department VARCHAR(50),sales FLOAT); INSERT INTO drugs (id,name,department,sales) VALUES (1,'DrugA','Oncology',100000),(2,'DrugB','Oncology',150000),(3,'DrugC','Cardiology',120000),(4,'DrugD','Cardiology',160000); | SELECT department, name, AVG(sales) as avg_sales FROM drugs WHERE department = 'Oncology' GROUP BY department, name; |
What was the total R&D expenditure for 'DrugL''s clinical trials in 2020? | CREATE TABLE clinical_trials (drug_name TEXT,rd_expenditure FLOAT,year INT); INSERT INTO clinical_trials (drug_name,rd_expenditure,year) VALUES ('DrugL',9000000.0,2020),('DrugL',7000000.0,2019); | SELECT drug_name, SUM(rd_expenditure) FROM clinical_trials WHERE drug_name = 'DrugL' AND year = 2020; |
What is the total number of network devices in each region and the total investment made in each region? | CREATE TABLE regions (region_id INT,region_name VARCHAR(50),number_of_devices INT); INSERT INTO regions (region_id,region_name,number_of_devices) VALUES (1,'North',600),(2,'South',400); CREATE TABLE region_investments (investment_id INT,region_id INT,investment_amount DECIMAL(10,2)); INSERT INTO region_investments (investment_id,region_id,investment_amount) VALUES (1,1,1200000.00),(2,1,1800000.00),(3,2,900000.00); | SELECT r.region_name, SUM(r.number_of_devices) as total_devices, SUM(ri.investment_amount) as total_investment FROM regions r JOIN region_investments ri ON r.region_id = ri.region_id GROUP BY r.region_name; |
What is the total biomass for fish in each country? | CREATE TABLE country (id INT,name VARCHAR(255)); CREATE TABLE fish_stock (country_id INT,species_id INT,biomass DECIMAL(10,2)); INSERT INTO country (id,name) VALUES (1,'Norway'),(2,'Chile'),(3,'Canada'); INSERT INTO fish_stock (country_id,species_id,biomass) VALUES (1,1,3000.0),(1,2,2000.0),(2,1,4000.0),(2,2,1000.0),(3,1,2500.0),(3,2,1500.0); | SELECT c.name, SUM(fs.biomass) AS total_biomass FROM country c JOIN fish_stock fs ON c.id = fs.country_id GROUP BY c.id, c.name; |
What is the total economic impact of rural development projects in the 'rural_development' database, grouped by the region they are located in? | CREATE TABLE projects (project_id INT,project_name VARCHAR(50),budget INT,region VARCHAR(50)); CREATE TABLE economic_impact (project_id INT,impact INT); INSERT INTO projects (project_id,project_name,budget,region) VALUES (1,'Road Construction',500000,'Midwest'),(2,'Bridge Building',700000,'Southeast'); INSERT INTO economic_impact (project_id,impact) VALUES (1,800000),(2,1000000); | SELECT region, SUM(budget) + SUM(impact) FROM projects INNER JOIN economic_impact ON projects.project_id = economic_impact.project_id GROUP BY region; |
List the names and completion dates of flood mitigation projects in the 'disaster_prevention' schema | CREATE SCHEMA IF NOT EXISTS disaster_prevention; CREATE TABLE disaster_prevention.projects (id INT,name VARCHAR(100),completed_date DATE,type VARCHAR(50)); INSERT INTO disaster_prevention.projects (id,name,completed_date,type) VALUES (1,'Flood Mitigation Infrastructure','2022-01-10','flood mitigation'),(2,'Earthquake Resistant Building','2021-06-25','earthquake'),(3,'Hurricane Proofing','2022-04-15','hurricane'); | SELECT name, completed_date FROM disaster_prevention.projects WHERE type = 'flood mitigation'; |
Find the average points scored by each team in their last five matches. | CREATE TABLE teams (id INT,name TEXT); CREATE TABLE matches (id INT,home_team INT,visiting_team INT,home_points INT,visiting_points INT,date DATE); | SELECT t.name, AVG(m.home_points + m.visiting_points) as avg_points FROM teams t INNER JOIN matches m ON t.id IN (m.home_team, m.visiting_team) WHERE m.date >= DATEADD(day, -30, CURRENT_DATE) GROUP BY t.name ORDER BY avg_points DESC LIMIT 5; |
What is the average mental health score of students who have participated in professional development programs? | CREATE TABLE students (student_id INT,mental_health_score INT,participated_in_pd BOOLEAN); INSERT INTO students (student_id,mental_health_score,participated_in_pd) VALUES (1,75,true),(2,80,false),(3,60,true); | SELECT AVG(mental_health_score) FROM students WHERE participated_in_pd = true; |
Count the number of smart city projects in each continent | CREATE TABLE continent (id INT,location TEXT,country TEXT); | SELECT continent.location, COUNT(*) FROM continent JOIN smart_cities ON continent.country = smart_cities.location GROUP BY continent.location; |
Retrieve the number of public works projects in Texas | CREATE TABLE Infrastructure (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255),is_public_works BOOLEAN); INSERT INTO Infrastructure (id,name,type,location,is_public_works) VALUES (1,'Road A','Road','Texas',TRUE); INSERT INTO Infrastructure (id,name,type,location,is_public_works) VALUES (2,'Bridge B','Bridge','California',FALSE); | SELECT COUNT(*) FROM Infrastructure WHERE is_public_works = TRUE AND location = 'Texas'; |
Insert a record for a salmon farm in Maine, USA | CREATE TABLE farm_locations (location_id INT PRIMARY KEY,location_name VARCHAR(255),country VARCHAR(255),ocean VARCHAR(255)); | INSERT INTO farm_locations (location_id, location_name, country, ocean) VALUES (1, 'Maine Salmon Farm', 'United States', 'Atlantic Ocean'); |
What is the minimum case duration for cases in the civil category? | CREATE TABLE cases (case_id INT,category VARCHAR(255),case_duration INT); INSERT INTO cases (case_id,category,case_duration) VALUES (1,'Family',30),(2,'Civil',20),(3,'Criminal',60),(4,'Family',45),(5,'Civil',10); | SELECT MIN(case_duration) FROM cases WHERE category = 'Civil'; |
How many unique donors did we have in each quarter of 2021? | CREATE TABLE donors (id INT,name TEXT,donation_date DATE); | SELECT DATE_FORMAT(donation_date, '%Y-%V') as quarter, COUNT(DISTINCT name) as unique_donors FROM donors WHERE donation_date >= '2021-01-01' AND donation_date < '2022-01-01' GROUP BY quarter; |
Calculate the percentage of customers in each region who have a socially responsible loan | CREATE TABLE customers (customer_id INT,region VARCHAR(255),has_socially_responsible_loan BOOLEAN); | SELECT region, (COUNT(*) FILTER (WHERE has_socially_responsible_loan = TRUE)) * 100.0 / COUNT(*) as percentage FROM customers GROUP BY region; |
Update the budget of the 'Solar Power' project to $450,000 in the 'renewable_energy_projects' table. | CREATE TABLE renewable_energy_projects (id INT,project_name VARCHAR(50),budget FLOAT); INSERT INTO renewable_energy_projects (id,project_name,budget) VALUES (1,'Solar Power',350000.00),(2,'Wind Power',500000.00); | UPDATE renewable_energy_projects SET budget = 450000.00 WHERE project_name = 'Solar Power'; |
What is the maximum retail price of eco-friendly denim jackets sold worldwide? | CREATE TABLE garments (id INT,category VARCHAR(255),subcategory VARCHAR(255),sustainability VARCHAR(50),price DECIMAL(10,2),country VARCHAR(50)); INSERT INTO garments (id,category,subcategory,sustainability,price,country) VALUES (1,'Outerwear','Jackets','Eco-Friendly',79.99,'United States'); INSERT INTO garments (id,category,subcategory,sustainability,price,country) VALUES (2,'Outerwear','Jackets','Eco-Friendly',89.99,'France'); | SELECT MAX(price) FROM garments WHERE category = 'Outerwear' AND subcategory = 'Jackets' AND sustainability = 'Eco-Friendly'; |
List all players who joined after a specific date | CREATE TABLE player_demographics (player_id INT PRIMARY KEY,age INT,gender VARCHAR(10),location VARCHAR(50),join_date DATE); | SELECT * FROM player_demographics WHERE join_date > '2022-01-01'; |
What is the average word count for articles by 'John Doe'? | CREATE TABLE news (title VARCHAR(255),author VARCHAR(255),word_count INT,category VARCHAR(255)); INSERT INTO news (title,author,word_count,category) VALUES ('Sample News','John Doe',500,'Politics'); | SELECT AVG(word_count) FROM news WHERE author = 'John Doe'; |
What is the average income in each state? | CREATE TABLE Country (Id INT,Name VARCHAR(50),StateId INT); INSERT INTO Country (Id,Name,StateId) VALUES (1,'CountryA',1); INSERT INTO Country (Id,Name,StateId) VALUES (2,'CountryB',2); CREATE TABLE State (Id INT,Name VARCHAR(50),Income FLOAT); INSERT INTO State (Id,Name,Income) VALUES (1,'StateA',45000); INSERT INTO State (Id,Name,Income) VALUES (2,'StateB',55000); | SELECT s.Name AS StateName, AVG(s.Income) AS AverageIncome FROM State s JOIN Country c ON s.Id = c.StateId GROUP BY s.Name; |
How many medical conditions are reported in each rural county? | use rural_health; CREATE TABLE medical_conditions (id int,patient_id int,county text,condition text); INSERT INTO medical_conditions (id,patient_id,county,condition) VALUES (1,1,'Green','Diabetes'); INSERT INTO medical_conditions (id,patient_id,county,condition) VALUES (2,1,'Green','Hypertension'); INSERT INTO medical_conditions (id,patient_id,county,condition) VALUES (3,2,'Blue','Asthma'); | SELECT county, COUNT(DISTINCT condition) as condition_count FROM rural_health.medical_conditions GROUP BY county; |
What is the distribution of vulnerabilities by severity level in the last week? | CREATE TABLE vulnerabilities (id INT,severity TEXT,severity_score INT,discovered_at TIMESTAMP); INSERT INTO vulnerabilities (id,severity,severity_score,discovered_at) VALUES (1,'low',2,'2021-02-01 12:00:00'),(2,'medium',5,'2021-02-04 14:30:00'),(3,'high',8,'2021-02-05 10:15:00'),(4,'critical',10,'2021-02-06 16:45:00'); | SELECT severity, COUNT(*) AS vulnerability_count FROM vulnerabilities WHERE discovered_at >= NOW() - INTERVAL '1 week' GROUP BY severity; |
How many aircraft accidents occurred in the European Union between 2017 and 2020? | CREATE TABLE aircraft_accidents (id INT,country VARCHAR(50),accident_date DATE); INSERT INTO aircraft_accidents (id,country,accident_date) VALUES (1,'France','2017-01-10'),(2,'Germany','2018-03-22'),(3,'Italy','2019-05-15'),(4,'Spain','2020-07-02'); | SELECT COUNT(*) as total_accidents FROM aircraft_accidents WHERE country IN ('France', 'Germany', 'Italy', 'Spain') AND YEAR(accident_date) BETWEEN 2017 AND 2020; |
What is the name and description of the waste type with ID 3? | CREATE TABLE WasteTypes (waste_type_id INT PRIMARY KEY,name VARCHAR,description VARCHAR); | SELECT name, description FROM WasteTypes WHERE waste_type_id = 3; |
What is the maximum salary of faculty members in the Humanities department? | CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),gender VARCHAR(10),position VARCHAR(20),salary DECIMAL(10,2)); | SELECT MAX(salary) FROM faculty WHERE department = 'Humanities'; |
What is the average property price for properties with a pool? | CREATE TABLE Properties (id INT,price INT,has_pool BOOLEAN); INSERT INTO Properties (id,price,has_pool) VALUES (1,500000,TRUE),(2,400000,FALSE),(3,700000,TRUE),(4,600000,FALSE); | SELECT AVG(price) AS avg_price_with_pool FROM Properties WHERE has_pool = TRUE; |
Update the 'housing_subsidies' table to reflect a new policy effective from '2023-01-01'. | CREATE TABLE housing_subsidies (id INT,policy_name TEXT,start_date DATE,end_date DATE); | UPDATE housing_subsidies SET start_date = '2023-01-01'; |
Who are the top 3 donors by total donation amount in descending order? | CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount FLOAT); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationAmount) VALUES (1,1,'2022-01-01',200.00),(2,2,'2022-02-14',150.00),(3,3,'2022-03-05',100.00),(4,1,'2022-04-01',250.00); CREATE TABLE Donors (DonorID INT,DonorName TEXT); INSERT INTO Donors (DonorID,DonorName) VALUES (1,'John Smith'),(2,'Jane Doe'),(3,'Bob Brown'); | SELECT DonorName, SUM(DonationAmount) AS TotalDonation FROM Donations INNER JOIN Donors ON Donations.DonorID = Donors.DonorID GROUP BY DonorName ORDER BY TotalDonation DESC LIMIT 3; |
What is the average cost of sustainable building materials used in projects initiated in California since 2020? | CREATE TABLE Sustainable_Materials (project_id INT,material_type VARCHAR(50),cost DECIMAL(10,2),material_origin VARCHAR(50),project_state VARCHAR(50)); INSERT INTO Sustainable_Materials (project_id,material_type,cost,material_origin,project_state) VALUES (1,'Recycled steel',800.00,'USA','California'); INSERT INTO Sustainable_Materials (project_id,material_type,cost,material_origin,project_state) VALUES (2,'Bamboo flooring',12.50,'Asia','California'); | SELECT AVG(cost) FROM Sustainable_Materials WHERE project_state = 'California' AND YEAR(project_initiation_date) >= 2020; |
What are the total number of security incidents in the incident_responses table for each country represented in the table? (Assuming the 'country' column exists in the incident_responses table) | CREATE TABLE incident_responses (country VARCHAR(50),incident VARCHAR(50),status VARCHAR(15)); INSERT INTO incident_responses (country,incident,status) VALUES ('USA','Incident 1','Resolved'),('Canada','Incident 2','In Progress'),('Brazil','Incident 3','Resolved'),('Mexico','Incident 4','In Progress'),('USA','Incident 5','Assessed'); | SELECT country, COUNT(*) AS num_incidents FROM incident_responses GROUP BY country; |
Update the country of astronaut John Herrington to United States. | CREATE TABLE Astronauts (id INT,name VARCHAR(255),country VARCHAR(255),age INT); INSERT INTO Astronauts (id,name,country,age) VALUES (1,'Rodolfo Neri Vela','Mexico',74); INSERT INTO Astronauts (id,name,country,age) VALUES (2,'Iván Bella','Argentina',53); INSERT INTO Astronauts (id,name,country,age) VALUES (3,'Marcos Pontes','Brazil',59); INSERT INTO Astronauts (id,name,country,age) VALUES (4,'John Herrington','Canada',60); | UPDATE Astronauts SET country = 'United States' WHERE id = 4; |
Insert new game design data for the popular mobile game 'Galactic Run'. | CREATE TABLE GameDesign (GameName VARCHAR(100),Genre VARCHAR(50),Developer VARCHAR(100)); INSERT INTO GameDesign VALUES ('Galactic Run','Runner','Space Corp'); | INSERT INTO GameDesign (GameName, Genre, Developer) VALUES ('Galactic Run', 'Runner', 'Space Corp'); |
Delete the 'Community Education' record in the 'conservation_efforts' table | CREATE TABLE conservation_efforts (id INT PRIMARY KEY,location VARCHAR(50),start_date DATE,end_date DATE,effort_description VARCHAR(255)); | DELETE FROM conservation_efforts WHERE effort_description = 'Community Education'; |
Update the location of 'Bus Stop 123' | CREATE TABLE bus_stops (stop_id INT PRIMARY KEY,stop_name TEXT,location TEXT); | UPDATE bus_stops SET location = 'New Location' WHERE stop_name = 'Bus Stop 123'; |
How many research grants were awarded to each faculty member in the Electrical Engineering department? | CREATE TABLE Faculty_2 (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO Faculty_2 (id,name,department) VALUES (1,'Carlos','Electrical Engineering'); CREATE TABLE Research_Grants_2 (id INT,faculty_id INT,grant_number INT,amount INT); INSERT INTO Research_Grants_2 (id,faculty_id,grant_number,amount) VALUES (1,1,12345,75000); | SELECT Faculty_2.name, COUNT(Research_Grants_2.id) FROM Faculty_2 JOIN Research_Grants_2 ON Faculty_2.id = Research_Grants_2.faculty_id WHERE Faculty_2.department = 'Electrical Engineering' GROUP BY Faculty_2.name; |
Find the top 2 energy efficiency upgrades by cost for each type. | CREATE TABLE upgrades (id INT,cost FLOAT,type TEXT); INSERT INTO upgrades (id,cost,type) VALUES (1,500,'Insulation'),(2,1000,'Insulation'),(3,1500,'Insulation'),(4,50,'HVAC'),(5,100,'HVAC'),(6,150,'HVAC'); | SELECT type, cost FROM (SELECT type, cost, RANK() OVER (PARTITION BY type ORDER BY cost DESC) as rn FROM upgrades) sub WHERE rn <= 2; |
Which public swimming pools in the city of Chicago were built before 2000? | CREATE TABLE public_pools (name TEXT,city TEXT,build_year INT); INSERT INTO public_pools (name,city,build_year) VALUES ('Pool A','Chicago',1998),('Pool B','Chicago',2005); | SELECT name FROM public_pools WHERE city = 'Chicago' AND build_year < 2000; |
Display dishes with a price range of $10-$20 | CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),price DECIMAL(5,2)); INSERT INTO dishes (dish_id,dish_name,price) VALUES (1,'Margherita Pizza',12.99),(2,'Chicken Alfredo',15.99),(3,'Caesar Salad',9.99),(4,'Garden Burger',11.99),(5,'Spaghetti Bolognese',19.99); | SELECT dish_id, dish_name, price FROM dishes WHERE price BETWEEN 10 AND 20; |
What is the total transaction value per week for the past year for customers in the 'Institutional' customer type? | CREATE TABLE customers (customer_id INT,customer_type VARCHAR(20)); INSERT INTO customers (customer_id,customer_type) VALUES (1,'Retail'),(2,'Wholesale'),(3,'Institutional'); CREATE TABLE transactions (transaction_date DATE,customer_id INT,transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_date,customer_id,transaction_value) VALUES ('2022-01-01',1,500.00),('2022-01-02',1,750.00),('2022-01-03',2,3000.00),('2022-01-04',3,15000.00),('2021-01-05',1,200.00),('2021-01-06',2,1200.00),('2021-01-07',3,800.00); | SELECT WEEK(transactions.transaction_date) as week, YEAR(transactions.transaction_date) as year, SUM(transactions.transaction_value) as total_transaction_value FROM transactions JOIN customers ON transactions.customer_id = customers.customer_id WHERE transactions.transaction_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND customers.customer_type = 'Institutional' GROUP BY week, year; |
What is the average price per square foot for each building type? | CREATE TABLE building_data (building_id INT,building_type VARCHAR(50),price_per_sq_ft FLOAT); INSERT INTO building_data (building_id,building_type,price_per_sq_ft) VALUES (1,'Residential',300.0),(2,'Commercial',500.0),(3,'Residential',400.0),(4,'Commercial',600.0),(5,'Residential',350.0); | SELECT building_type, AVG(price_per_sq_ft) FROM building_data GROUP BY building_type; |
List all suppliers from India that provide organic ingredients. | CREATE TABLE suppliers (id INT,name VARCHAR(50),country VARCHAR(50),organic BOOLEAN); INSERT INTO suppliers (id,name,country,organic) VALUES (1,'Supplier A','India',true),(2,'Supplier B','USA',false); | SELECT suppliers.name FROM suppliers WHERE suppliers.country = 'India' AND suppliers.organic = true; |
List the number of rural hospitals and clinics in each state, ordered by the number of rural hospitals and clinics. | CREATE TABLE hospitals (hospital_id INT,name TEXT,type TEXT,rural BOOLEAN); CREATE TABLE states (state_code TEXT,state_name TEXT); INSERT INTO hospitals (hospital_id,name,type,rural) VALUES (1,'Rural General Hospital','Hospital',TRUE),(2,'Rural Clinic','Clinic',TRUE); INSERT INTO states (state_code,state_name) VALUES ('NY','New York'),('TX','Texas'); | SELECT states.state_name, SUM(CASE WHEN hospitals.type = 'Hospital' THEN 1 ELSE 0 END) as num_hospitals, SUM(CASE WHEN hospitals.type = 'Clinic' THEN 1 ELSE 0 END) as num_clinics, SUM(CASE WHEN hospitals.type IN ('Hospital', 'Clinic') THEN 1 ELSE 0 END) as total_rural_healthcare_services FROM hospitals INNER JOIN states ON TRUE WHERE hospitals.rural = TRUE GROUP BY states.state_name ORDER BY num_hospitals + num_clinics DESC; |
What is the minimum revenue earned from AI-powered hotel recommendations in the last quarter? | CREATE TABLE ai_recommendations (id INT,recommendation_type TEXT,revenue FLOAT,recommendation_date DATE); INSERT INTO ai_recommendations (id,recommendation_type,revenue,recommendation_date) VALUES (1,'AI Hotel',700,'2022-01-03'),(2,'AI Recommendation',800,'2022-02-05'); | SELECT MIN(revenue) FROM ai_recommendations WHERE recommendation_type = 'AI Hotel' AND recommendation_date >= DATE_SUB(NOW(), INTERVAL 3 MONTH); |
What is the total fare collected from passengers on trains in the NYC subway system? | CREATE TABLE train_routes (id INT,route_name VARCHAR(255),fare DECIMAL(5,2)); INSERT INTO train_routes (id,route_name,fare) VALUES (1,'Route A',2.75),(2,'Route B',3.50); | SELECT SUM(fare) FROM train_routes WHERE route_name LIKE 'Route%'; |
What is the average selling price of organic fruits sold by vendors located in California? | CREATE TABLE vendors (vendor_id INT,vendor_name TEXT,location TEXT); INSERT INTO vendors (vendor_id,vendor_name,location) VALUES (1,'ABC Organics','California'); CREATE TABLE products (product_id INT,product_name TEXT,price DECIMAL(5,2),vendor_id INT); INSERT INTO products (product_id,product_name,price,vendor_id) VALUES (1,'Organic Apples',2.99,1); INSERT INTO products (product_id,product_name,price,vendor_id) VALUES (2,'Organic Bananas',1.99,1); | SELECT AVG(price) FROM products JOIN vendors ON products.vendor_id = vendors.vendor_id WHERE products.product_name LIKE '%organic fruit%' AND vendors.location = 'California'; |
What is the average property price for co-owned properties in the city of Seattle? | CREATE TABLE properties (id INT,price FLOAT,city VARCHAR(20),coowners INT); INSERT INTO properties (id,price,city,coowners) VALUES (1,750000,'Seattle',2),(2,850000,'Seattle',1),(3,650000,'Seattle',3),(4,950000,'Portland',1),(5,550000,'Seattle',2); | SELECT AVG(price) FROM properties WHERE city = 'Seattle' AND coowners > 1; |
What is the total quantity of garments sold to customers in the US? | CREATE TABLE sales(id INT PRIMARY KEY,garment_type VARCHAR(50),quantity INT,sale_date DATE,customer_country VARCHAR(50)); INSERT INTO sales(id,garment_type,quantity,sale_date,customer_country) VALUES (1,'t-shirt',10,'2022-01-01','USA'),(2,'jeans',8,'2022-02-01','Canada'),(3,'dress',5,'2022-03-01','USA'); | SELECT SUM(quantity) FROM sales WHERE customer_country = 'USA'; |
How many hybrid vehicles were sold in the 'CarSales' database in 2022? | CREATE TABLE CarSales (Id INT,Vehicle VARCHAR(50),Year INT,QuantitySold INT); CREATE TABLE HybridVehicles (Id INT,Make VARCHAR(50),Model VARCHAR(50),Year INT,Horsepower INT); | SELECT COUNT(*) FROM CarSales WHERE Vehicle IN (SELECT Model FROM HybridVehicles WHERE Year = 2022); |
Calculate the percentage of total production for each well in a given country. | CREATE TABLE wells (well_id INT,country VARCHAR(50),production INT); INSERT INTO wells (well_id,country,production) VALUES (1,'USA',1000000),(2,'USA',2000000),(3,'Canada',1500000); | SELECT well_id, country, production, ROUND(100.0 * production / (SELECT SUM(production) FROM wells w2 WHERE w2.country = w.country) , 2) as pct_of_total FROM wells w; |
Find the total number of wells drilled in the year 2020 | CREATE TABLE wells (id INT,well_name VARCHAR(50),drill_year INT,location VARCHAR(50)); INSERT INTO wells (id,well_name,drill_year,location) VALUES (1,'Well A',2020,'Region A'); INSERT INTO wells (id,well_name,drill_year,location) VALUES (2,'Well B',2019,'Region B'); INSERT INTO wells (id,well_name,drill_year,location) VALUES (3,'Well C',2020,'Region C'); | SELECT COUNT(*) FROM wells WHERE drill_year = 2020; |
Find the top 5 products with the highest revenue in Asia. | CREATE TABLE products (id INT,name TEXT,price DECIMAL(5,2)); INSERT INTO products (id,name,price) VALUES (1,'Product X',100.00),(2,'Product Y',150.00),(3,'Product Z',80.00),(4,'Product W',120.00); CREATE TABLE sales (id INT,product TEXT,quantity INT,region TEXT); INSERT INTO sales (id,product,quantity,region) VALUES (1,'Product X',100,'Asia'),(2,'Product Y',150,'Asia'),(3,'Product Z',80,'Asia'),(4,'Product W',120,'Europe'); | SELECT products.name, SUM(sales.quantity * products.price) as revenue FROM sales INNER JOIN products ON sales.product = products.name WHERE sales.region = 'Asia' GROUP BY sales.product ORDER BY revenue DESC LIMIT 5; |
What is the total revenue of games with a rating of 9 or higher? | CREATE TABLE Games (GameID INT,Name VARCHAR(50),ReleaseYear INT,Revenue INT,Rating INT); INSERT INTO Games (GameID,Name,ReleaseYear,Revenue,Rating) VALUES (1,'Game1',2019,50000,8); INSERT INTO Games (GameID,Name,ReleaseYear,Revenue,Rating) VALUES (2,'Game2',2020,60000,9); CREATE TABLE GameRatings (GameID INT,Rating INT); INSERT INTO GameRatings (GameID,Rating) VALUES (1,8); INSERT INTO GameRatings (GameID,Rating) VALUES (2,9); | SELECT SUM(Games.Revenue) FROM Games INNER JOIN GameRatings ON Games.GameID = GameRatings.GameID WHERE Games.Rating >= 9; |
What is the minimum funding received by startups in the 'FinTech' sector founded after 2017? | CREATE TABLE startups(id INT,name TEXT,industry TEXT,funding FLOAT,founding_year INT); INSERT INTO startups VALUES (1,'StartupD','FinTech',4000000,2018); | SELECT MIN(funding) FROM startups WHERE industry = 'FinTech' AND founding_year > 2017; |
How many public meetings have taken place in the Education department since 2015? | CREATE TABLE meetings (id INT,department TEXT,date DATE); INSERT INTO meetings (id,department,date) VALUES (1,'Education','2015-01-01'); INSERT INTO meetings (id,department,date) VALUES (2,'Education','2016-01-01'); INSERT INTO meetings (id,department,date) VALUES (3,'Finance','2015-01-01'); | SELECT COUNT(*) FROM meetings WHERE department = 'Education' AND date >= '2015-01-01'; |
What are the maximum wildlife habitat amounts in Oceania? | CREATE TABLE wildlife_habitats (id INT,country VARCHAR(255),region VARCHAR(255),habitat_amount INT); | SELECT MAX(habitat_amount) FROM wildlife_habitats WHERE region = 'Oceania'; |
How many renewable energy projects were installed each year? | CREATE TABLE renewable_projects (project_id INT,project_name VARCHAR(50),source_id INT,installation_year INT); INSERT INTO renewable_projects (project_id,project_name,source_id,installation_year) VALUES (1,'Solar Farm A',1,2015),(2,'Wind Farm B',2,2018),(3,'Hydro Plant C',3,2012); | SELECT installation_year, COUNT(*) as num_projects FROM renewable_projects GROUP BY installation_year; |
Insert data into 'artists' table from a CSV file | CREATE TABLE artists (name VARCHAR(255),birth_year INT,death_year INT); | INSERT INTO artists (name, birth_year, death_year) SELECT * FROM csv_file('artists.csv') AS t(name VARCHAR(255), birth_year INT, death_year INT); |
How many unique customers made purchases from circular economy stores in the last month? | CREATE TABLE customers (id INT,last_purchase_date DATE); INSERT INTO customers (id,last_purchase_date) VALUES (1,'2022-03-15'),(2,'2022-02-10'),(3,'2022-03-28'); CREATE TABLE purchases (id INT,customer_id INT,store_type VARCHAR(20)); INSERT INTO purchases (id,customer_id,store_type) VALUES (1,1,'Circular Economy'),(2,2,'Second-Hand'),(3,3,'Circular Economy'); | SELECT COUNT(DISTINCT c.id) FROM customers c JOIN purchases p ON c.id = p.customer_id WHERE p.store_type = 'Circular Economy' AND c.last_purchase_date >= DATEADD(MONTH, -1, GETDATE()); |
What is the recycling rate for metal in 2018 and 2019? | CREATE TABLE recycling_rates (id INT,material VARCHAR(20),year INT,recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (id,material,year,recycling_rate) VALUES (1,'plastic',2017,0.25),(2,'plastic',2018,0.28),(3,'plastic',2019,0.31),(4,'paper',2017,0.60),(5,'paper',2018,0.63),(6,'paper',2019,0.66),(7,'glass',2017,0.35),(8,'glass',2018,0.37),(9,'glass',2019,0.39),(10,'metal',2017,0.45),(11,'metal',2018,0.47),(12,'metal',2019,0.49); | SELECT recycling_rate FROM recycling_rates WHERE material = 'metal' AND (year = 2018 OR year = 2019); |
Calculate the total quantity of waste generated in the city of Sydney in 2019. | CREATE TABLE waste_generation (city VARCHAR(20),year INT,quantity INT); INSERT INTO waste_generation (city,year,quantity) VALUES ('Sydney',2019,150),('Sydney',2019,250); | SELECT SUM(quantity) AS total_waste_generated FROM waste_generation WHERE city = 'Sydney' AND year = 2019; |
What is the total R&D expenditure for oncology drugs in the USA and UK in 2018 and 2019? | CREATE TABLE rd_expenditure (drug_name TEXT,therapy_area TEXT,country TEXT,year NUMERIC,expenditure NUMERIC); INSERT INTO rd_expenditure (drug_name,therapy_area,country,year,expenditure) VALUES ('Drug1','Oncology','USA',2018,5000000),('Drug2','Oncology','UK',2019,7000000),('Drug3','Cardiology','USA',2018,3000000),('Drug4','Oncology','UK',2018,4000000),('Drug5','Oncology','USA',2019,6000000); | SELECT country, therapy_area, SUM(expenditure) FROM rd_expenditure WHERE country IN ('USA', 'UK') AND therapy_area = 'Oncology' AND year IN (2018, 2019) GROUP BY country, therapy_area; |
List all the mining sites located in California with their respective environmental impact scores. | CREATE TABLE MiningSites (SiteID INT,SiteName VARCHAR(50),Location VARCHAR(50),EnvironmentalImpactScore INT); | SELECT SiteName, EnvironmentalImpactScore FROM MiningSites WHERE Location = 'California'; |
Find the average number of hours played per day by players | CREATE TABLE Players (PlayerID INT,HoursPlayed INT,DaysPlayed INT); INSERT INTO Players (PlayerID,HoursPlayed,DaysPlayed) VALUES (1,50,25); INSERT INTO Players (PlayerID,HoursPlayed,DaysPlayed) VALUES (2,100,50); | SELECT AVG(HoursPlayed / DaysPlayed) FROM Players; |
Show a pivot table of the number of users by country and their last login date in the 'global_tech_users' table | CREATE TABLE global_tech_users (id INT PRIMARY KEY,user_name VARCHAR(50),country VARCHAR(50),last_login DATETIME); | SELECT country, last_login, COUNT(*) as user_count FROM global_tech_users GROUP BY country, last_login ORDER BY last_login; |
What percentage of tourists visiting Cape Town speak Afrikaans? | CREATE TABLE language_stats_2 (id INT,city VARCHAR(20),country VARCHAR(10),language VARCHAR(10),num_tourists INT); INSERT INTO language_stats_2 (id,city,country,language,num_tourists) VALUES (1,'Cape Town','South Africa','Afrikaans',25000),(2,'Cape Town','Germany','German',15000),(3,'Cape Town','Netherlands','Dutch',10000); | SELECT (SUM(CASE WHEN language = 'Afrikaans' THEN num_tourists ELSE 0 END) * 100.0 / SUM(num_tourists)) AS percentage FROM language_stats_2 WHERE city = 'Cape Town'; |
Get the details of the urban agriculture systems in Africa. | CREATE TABLE AgricultureSystems (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50)); INSERT INTO AgricultureSystems (id,name,location,type) VALUES (1,'Urban Vertical Farms','Africa','Urban Agriculture'); | SELECT * FROM AgricultureSystems WHERE location = 'Africa' AND type = 'Urban Agriculture'; |
Find the total waste produced by each manufacturing process, ordered by the highest waste amount. | CREATE TABLE process (process_id INT,process_name VARCHAR(50)); CREATE TABLE waste (waste_id INT,process_id INT,waste_amount DECIMAL(5,2)); INSERT INTO process (process_id,process_name) VALUES (1,'Process 1'),(2,'Process 2'),(3,'Process 3'); INSERT INTO waste (waste_id,process_id,waste_amount) VALUES (1,1,50),(2,1,55),(3,2,45),(4,3,30),(5,3,32); | SELECT process_name, SUM(waste_amount) AS total_waste FROM waste JOIN process ON waste.process_id = process.process_id GROUP BY process_name ORDER BY total_waste DESC; |
What is the total cost of infrastructure projects in New York and Los Angeles, grouped by project type and year? | CREATE TABLE Infrastructure (Id INT,City VARCHAR(50),Type VARCHAR(50),Cost FLOAT,Year INT); INSERT INTO Infrastructure (Id,City,Type,Cost,Year) VALUES (1,'New York','Bridge',2000000,2010); INSERT INTO Infrastructure (Id,City,Type,Cost,Year) VALUES (2,'Los Angeles','Road',5000000,2015); | SELECT City, Type, SUM(Cost) as Total_Cost, Year FROM Infrastructure GROUP BY City, Type, Year; |
What is the average age of community health workers by state, ranked by the number of workers? | CREATE TABLE CommunityHealthWorkers (WorkerID INT,Age INT,Gender VARCHAR(10),State VARCHAR(20)); INSERT INTO CommunityHealthWorkers (WorkerID,Age,Gender,State) VALUES (1,34,'Female','California'),(2,42,'Male','Texas'),(3,50,'Female','California'),(4,48,'Non-binary','New York'); | SELECT State, AVG(Age) as AvgAge FROM (SELECT WorkerID, Age, Gender, State, ROW_NUMBER() OVER(PARTITION BY State ORDER BY Age) as rn FROM CommunityHealthWorkers) tmp WHERE rn = 1 GROUP BY State ORDER BY COUNT(*) DESC; |
What is the average donation amount for recurring donors? | CREATE TABLE Donors (donor_id INT,name VARCHAR(255),country VARCHAR(255),recurring BOOLEAN); CREATE TABLE Donations (donation_id INT,donor_id INT,event_id INT,amount DECIMAL(10,2)); | SELECT AVG(amount) FROM Donations D JOIN Donors DD ON D.donor_id = DD.donor_id WHERE DD.recurring = TRUE; |
How many community events were organized by the museum in 2021? | CREATE TABLE Museums (museum_id INT,museum_name VARCHAR(255),city VARCHAR(255),country VARCHAR(255)); INSERT INTO Museums (museum_id,museum_name,city,country) VALUES (1,'Museum of Art','New York','USA'); CREATE TABLE Events (event_id INT,museum_id INT,event_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO Events (event_id,museum_id,event_name,start_date,end_date) VALUES (1,1,'Art Showcase','2021-05-01','2021-05-31'),(2,1,'Community Day','2021-07-04','2021-07-04'); | SELECT COUNT(*) FROM Events WHERE museum_id = 1 AND YEAR(start_date) = 2021 AND YEAR(end_date) = 2021 AND event_name LIKE '%community%'; |
What is the total number of fraudulent transactions and their total value for the month of July 2021? | CREATE TABLE transactions (transaction_id INT,is_fraudulent BOOLEAN,transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,is_fraudulent,transaction_value) VALUES (1,FALSE,100.00),(2,TRUE,500.00),(3,FALSE,200.00),(4,TRUE,300.00),(5,FALSE,150.00); | SELECT COUNT(transaction_id) as total_fraudulent_transactions, SUM(transaction_value) as total_fraudulent_transaction_value FROM transactions WHERE transaction_date BETWEEN '2021-07-01' AND '2021-07-31' AND is_fraudulent = TRUE; |
How many units of the "Regular" fabric were produced in August 2021? | CREATE TABLE production_data (fabric_type VARCHAR(20),month VARCHAR(10),units_produced INT); INSERT INTO production_data (fabric_type,month,units_produced) VALUES ('Eco-friendly','August',5500),('Regular','August',7500); | SELECT SUM(units_produced) FROM production_data WHERE fabric_type = 'Regular' AND month = 'August'; |
Update the collective bargaining agreement expiration date for a specific union affiliation. | CREATE TABLE union_info (id INT,union_affiliation TEXT,collective_bargaining_agreement_expiration DATE); INSERT INTO union_info (id,union_affiliation,collective_bargaining_agreement_expiration) VALUES (1,'Union A','2022-12-31'),(2,'Union B','2023-06-30'),(3,'Union C','2024-01-31'); | UPDATE union_info SET collective_bargaining_agreement_expiration = '2025-01-31' WHERE union_affiliation = 'Union A'; |
What is the maximum depth of any marine protected area in the Atlantic Ocean? | CREATE TABLE marine_protected_areas (id INT,name VARCHAR(50),location VARCHAR(50),avg_depth FLOAT); INSERT INTO marine_protected_areas (id,name,location,avg_depth) VALUES (1,'MPA1','Pacific Ocean',3500),(2,'MPA2','Atlantic Ocean',4200),(3,'MPA3','Indian Ocean',2700); | SELECT MAX(avg_depth) FROM marine_protected_areas WHERE location = 'Atlantic Ocean'; |
What is the number of primary care physicians per 100,000 people in each rural county? | CREATE TABLE physicians (physician_id INT,physician_name VARCHAR,specialty VARCHAR,rural_county VARCHAR,state VARCHAR); INSERT INTO physicians (physician_id,physician_name,specialty,rural_county,state) VALUES (1,'Dr. Smith','Primary Care','County A','Ohio'); INSERT INTO physicians (physician_id,physician_name,specialty,rural_county,state) VALUES (2,'Dr. Johnson','Primary Care','County B','Texas'); CREATE TABLE population (county VARCHAR,state VARCHAR,population INT); INSERT INTO population (county,state,population) VALUES ('County A','Ohio',50000); INSERT INTO population (county,state,population) VALUES ('County B','Texas',75000); | SELECT rural_county, state, COUNT(*) * 100000.0 / (SELECT population FROM population WHERE county = hospitals.rural_county AND state = hospitals.state) AS physicians_per_100k FROM physicians GROUP BY rural_county, state; |
Insert a new record into the "threat_intelligence" table with a threat_id of 67890, a threat_source of "NATO", a threat_level of "high", a threat_description of "Cyber attack", and a threat_date of '2022-02-15' | CREATE TABLE threat_intelligence (threat_id INT,threat_source VARCHAR(50),threat_level VARCHAR(50),threat_description VARCHAR(50),threat_date DATE); | INSERT INTO threat_intelligence (threat_id, threat_source, threat_level, threat_description, threat_date) VALUES (67890, 'NATO', 'high', 'Cyber attack', '2022-02-15'); |
What is the total value of properties owned by people with disabilities? | CREATE TABLE Property_Value (Property_ID INT,Owner_Disability VARCHAR(10),Property_Value INT); INSERT INTO Property_Value (Property_ID,Owner_Disability,Property_Value) VALUES (1,'Yes',1000000),(2,'No',800000),(3,'Yes',1200000),(4,'No',900000); | SELECT SUM(Property_Value) FROM Property_Value WHERE Owner_Disability = 'Yes'; |
What is the total quantity of copper extracted by the Jade Juliet mine for each year? | CREATE TABLE extraction_stats (year INT,mine_name TEXT,material TEXT,quantity INT); INSERT INTO extraction_stats (year,mine_name,material,quantity) VALUES (2015,'Aggromine A','Gold',1200),(2015,'Aggromine A','Silver',2500),(2016,'Borax Bravo','Boron',18000),(2016,'Borax Bravo','Copper',3000),(2017,'Carbon Cat','Coal',12300),(2017,'Carbon Cat','Diamonds',250),(2018,'Diamond Delta','Graphite',1500),(2018,'Diamond Delta','Graphite',1800),(2019,'Emerald Echo','Emerald',2000),(2019,'Emerald Echo','Emerald',2200),(2020,'Jade Juliet','Copper',4000),(2020,'Jade Juliet','Copper',4500); | SELECT year, mine_name, SUM(quantity) as total_copper_quantity FROM extraction_stats WHERE mine_name = 'Jade Juliet' AND material = 'Copper' GROUP BY year; |
How many articles were published in 2020 about climate change by authors from underrepresented communities? | CREATE TABLE articles (id INT,title TEXT,publication_year INT,topic TEXT,author TEXT); INSERT INTO articles (id,title,publication_year,topic,author) VALUES (1,'Article1',2020,'Climate Change','Underrepresented Author1'); INSERT INTO articles (id,title,publication_year,topic,author) VALUES (2,'Article2',2019,'Politics','Underrepresented Author2'); | SELECT COUNT(*) FROM articles WHERE publication_year = 2020 AND topic = 'Climate Change' AND author IN (SELECT author FROM authors WHERE underrepresented = true); |
What is the total number of military aircrafts in South America? | CREATE TABLE MilitaryAircrafts (Country VARCHAR(50),NumberOfAircrafts INT); INSERT INTO MilitaryAircrafts (Country,NumberOfAircrafts) VALUES ('Brazil',600),('Argentina',350),('Colombia',250),('Peru',150),('Venezuela',200); | SELECT SUM(NumberOfAircrafts) FROM MilitaryAircrafts WHERE Country IN ('Brazil', 'Argentina', 'Colombia', 'Peru', 'Venezuela'); |
What is the total number of ethical partners in the 'home goods' category? | CREATE TABLE labor_partners (product_id INT,category VARCHAR(20),partner_id INT,is_ethical BOOLEAN); INSERT INTO labor_partners (product_id,category,partner_id,is_ethical) VALUES (1,'home goods',100,true),(1,'home goods',101,false),(2,'home goods',102,true); | SELECT COUNT(*) FROM labor_partners WHERE category = 'home goods' AND is_ethical = true; |
Create a view to display all conditions with a description longer than 200 characters | CREATE VIEW long_description_conditions AS SELECT condition_id,name,description FROM conditions WHERE LENGTH(description) > 200; | CREATE VIEW long_description_conditions AS SELECT condition_id, name, description FROM conditions WHERE LENGTH(description) > 200; |
How many volunteers participated in educational programs in Texas? | CREATE TABLE VolunteerEvents (EventID INT,EventName TEXT,Location TEXT,EventType TEXT); INSERT INTO VolunteerEvents (EventID,EventName,Location,EventType) VALUES (1,'Tutoring Session','Texas','Education'),(2,'Coding Workshop','New York','Education'); | SELECT COUNT(DISTINCT VolunteerID) FROM VolunteerEvents JOIN VolunteerHours ON VolunteerEvents.EventID = VolunteerHours.EventID WHERE VolunteerEvents.Location = 'Texas' AND VolunteerEvents.EventType = 'Education'; |
What is the yearly variation in carbon prices in the European Union Emissions Trading System (EU ETS)? | CREATE TABLE carbon_prices (date DATE,eu_ets FLOAT,primary key (date)); INSERT INTO carbon_prices (date,eu_ets) VALUES ('2010-01-01',15),('2010-01-02',15.5),('2011-01-01',18),('2011-01-02',17.5),('2012-01-01',16.5),('2012-01-02',17); | SELECT date, eu_ets, LAG(eu_ets) OVER (ORDER BY date) as prev_year_price FROM carbon_prices WHERE date BETWEEN '2010-01-01' AND '2012-12-31' ORDER BY date |
Which astronauts are part of a space mission with a manufacturer from Japan or Russia and have conducted astrobiology experiments? | CREATE TABLE Astronauts (Name TEXT,Age INT,Gender TEXT,Nationality TEXT); INSERT INTO Astronauts (Name,Age,Gender,Nationality) VALUES ('Yuri Ivanov',50,'Male','Russian'); CREATE TABLE Spacecraft (Name TEXT,Manufacturer TEXT,LaunchDate DATE); INSERT INTO Spacecraft (Name,Manufacturer,LaunchDate) VALUES ('Soyuz-2.1b','Roscosmos','2022-03-18'); CREATE TABLE Mission_Astronauts (Astronaut TEXT,Spacecraft TEXT); INSERT INTO Mission_Astronauts (Astronaut,Spacecraft) VALUES ('Yuri Ivanov','Soyuz-2.1b'); CREATE TABLE Research_Data (Astronaut TEXT,Experiment TEXT,Result TEXT); INSERT INTO Research_Data (Astronaut,Experiment,Result) VALUES ('Yuri Ivanov','Astrobiology','Positive'); | SELECT Astronaut FROM Mission_Astronauts WHERE Manufacturer IN ('JAXA', 'Roscosmos') INTERSECT SELECT Astronaut FROM Research_Data WHERE Experiment = 'Astrobiology'; |
What is the minimum donation amount received in 2021 by a donor from the LGBTQ+ community? | CREATE TABLE Donations2021 (DonationID int,DonorType varchar(50),DonationAmount decimal(10,2),DonorCommunity varchar(50)); INSERT INTO Donations2021 (DonationID,DonorType,DonationAmount,DonorCommunity) VALUES (1,'Corporation',500,'LGBTQ+'); INSERT INTO Donations2021 (DonationID,DonorType,DonationAmount,DonorCommunity) VALUES (2,'Foundation',1000,'None'); | SELECT MIN(DonationAmount) FROM Donations2021 WHERE DonorType = 'Individual' AND DonorCommunity = 'LGBTQ+' AND YEAR(DonationDate) = 2021; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.