instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total number of trees planted as part of climate communication initiatives in 2018? | CREATE TABLE climate_communication_data (id INT,initiative_name VARCHAR(50),year INT,trees_planted INT); INSERT INTO climate_communication_data (id,initiative_name,year,trees_planted) VALUES (1,'Tree Planting Initiative 1',2018,25000); INSERT INTO climate_communication_data (id,initiative_name,year,trees_planted) VALUES (2,'Climate Education Program 1',2019,15000); | SELECT SUM(trees_planted) FROM climate_communication_data WHERE initiative_name LIKE '%Tree Planting%' AND year = 2018; |
What is the average income of residents in urban areas who have completed higher education? | CREATE TABLE UrbanResidents (ResidentID INT,EducationLevel VARCHAR(20),Income FLOAT); CREATE TABLE HigherEducation (ResidentID INT,Degree VARCHAR(20)); INSERT INTO UrbanResidents VALUES (1,'Bachelor',60000),(2,'Master',75000),(3,'Associate',50000); INSERT INTO HigherEducation VALUES (1,'Bachelor'),(2,'Master'),(3,'Associate'); | SELECT AVG(UrbanResidents.Income) FROM UrbanResidents INNER JOIN HigherEducation ON UrbanResidents.ResidentID = HigherEducation.ResidentID WHERE UrbanResidents.EducationLevel = 'Bachelor' OR UrbanResidents.EducationLevel = 'Master'; |
What is the maximum number of followers for users in the 'celebrity' category from the 'users' table, who have posted in the 'music' category from the 'posts' table, in the past 90 days? | CREATE TABLE users (user_id INT,user_category VARCHAR(20),user_followers INT); CREATE TABLE posts (post_id INT,user_id INT,post_category VARCHAR(20),post_date DATE); | SELECT MAX(user_followers) FROM (SELECT user_followers FROM users WHERE user_category = 'celebrity' AND user_id IN (SELECT user_id FROM posts WHERE post_category = 'music' AND post_date >= CURDATE() - INTERVAL 90 DAY)) AS subquery; |
What is the total quantity of military equipment sold to 'African Union' by 'Alpha Corp' and 'Beta Corp' combined? | CREATE TABLE MilitaryEquipmentSales (seller VARCHAR(255),buyer VARCHAR(255),equipment_model VARCHAR(255),quantity INT,sale_date DATE); | SELECT SUM(quantity) FROM (SELECT quantity FROM MilitaryEquipmentSales WHERE seller = 'Alpha Corp' AND buyer = 'African Union' UNION ALL SELECT quantity FROM MilitaryEquipmentSales WHERE seller = 'Beta Corp' AND buyer = 'African Union') AS subquery; |
Delete all records of soldiers who were dishonorably discharged from the soldiers_personal_data table | CREATE TABLE soldiers_personal_data (soldier_id INT,name VARCHAR(50),rank VARCHAR(50),departure_date DATE,discharge_type VARCHAR(50)); | DELETE FROM soldiers_personal_data WHERE discharge_type = 'dishonorable'; |
Who are the top 3 organizations with the highest number of accessible technology patents, and what is their total number of patents? | CREATE TABLE organizations (id INT,name VARCHAR(50)); CREATE TABLE accessible_tech_patents (id INT,organization_id INT,patents INT); INSERT INTO organizations (id,name) VALUES (1,'Microsoft'),(2,'Google'),(3,'IBM'),(4,'Oracle'),(5,'SAP'); INSERT INTO accessible_tech_patents (id,organization_id,patents) VALUES (1,1,200),(2,1,300),(3,2,150),(4,2,250),(5,3,400),(6,4,100),(7,4,150),(8,5,200),(9,5,300); | SELECT organizations.name, SUM(accessible_tech_patents.patents) as total_patents FROM organizations INNER JOIN accessible_tech_patents ON organizations.id = accessible_tech_patents.organization_id GROUP BY organizations.name ORDER BY total_patents DESC LIMIT 3; |
How many unique volunteers contributed to each program in 2022? | CREATE TABLE Volunteers (volunteer_id INT,volunteer_name VARCHAR(50),program_id INT,volunteer_hours INT,volunteer_date DATE); INSERT INTO Volunteers (volunteer_id,volunteer_name,program_id,volunteer_hours,volunteer_date) VALUES (1,'Sophia',1,5,'2022-06-05'),(2,'James',2,8,'2022-04-12'),(3,'Leila',1,3,'2022-06-05'),(4,'Alex',3,6,'2022-12-25'),(5,'Jamila',1,2,'2022-06-05'); | SELECT program_id, COUNT(DISTINCT volunteer_id) as unique_volunteers_per_program_in_2022 FROM Volunteers WHERE volunteer_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY program_id; |
What's the total donation amount for each region, excluding the top 2 donors in each region? | CREATE TABLE donors (id INT,name TEXT,region TEXT,donation_amount DECIMAL(10,2)); INSERT INTO donors (id,name,region,donation_amount) VALUES (1,'John Smith','Asia-Pacific',500.00),(2,'Jane Doe','Europe',1500.00),(3,'James Lee','Middle East',3000.00),(4,'Fatima Al-Faisal','Middle East',4000.00),(5,'Tariq Al-Saadi','Middle East',5000.00),(6,'Sophia Wang','Asia-Pacific',600.00),(7,'Peter Johnson','Europe',700.00); | SELECT region, SUM(donation_amount) FROM donors d1 WHERE donation_amount < (SELECT DISTINCT donation_amount FROM donors d2 WHERE d1.region = d2.region ORDER BY donation_amount DESC LIMIT 2 OFFSET 1) GROUP BY region; |
Count the number of users who joined in the year 2021 and have a membership longer than 6 months. | CREATE TABLE Members (UserID INT,MemberSince DATE,MembershipLength INT); INSERT INTO Members (UserID,MemberSince,MembershipLength) VALUES (1,'2021-01-01',7),(2,'2021-02-01',6),(3,'2020-12-01',12); | SELECT COUNT(*) FROM Members WHERE YEAR(MemberSince) = 2021 AND MembershipLength > 6; |
Delete records of students who have not taken any courses | CREATE TABLE students (id INT PRIMARY KEY,name TEXT,age INT); INSERT INTO students (id,name,age) VALUES (1,'John Doe',18),(2,'Jane Smith',20); CREATE TABLE courses (id INT PRIMARY KEY,student_id INT,course_name TEXT); INSERT INTO courses (id,student_id,course_name) VALUES (1,1,'Math'),(2,1,'Science'),(3,NULL,'English'); | DELETE FROM students WHERE id NOT IN (SELECT student_id FROM courses); |
List all the unique research topics that faculty members in the 'Physics' department have published on. | CREATE TABLE Publications (PublicationID int,FacultyID int,Topic varchar(50)); INSERT INTO Publications (PublicationID,FacultyID,Topic) VALUES (1,1,'Quantum Mechanics'); INSERT INTO Publications (PublicationID,FacultyID,Topic) VALUES (2,2,'Particle Physics'); CREATE TABLE Faculty (FacultyID int,Department varchar(50)); INSERT INTO Faculty (FacultyID,Department) VALUES (1,'Physics'); INSERT INTO Faculty (FacultyID,Department) VALUES (2,'Mathematics'); | SELECT DISTINCT Publications.Topic FROM Publications INNER JOIN Faculty ON Publications.FacultyID = Faculty.FacultyID WHERE Faculty.Department = 'Physics'; |
Find the average donation amount per donor for donations made in the 'health' category. | CREATE TABLE donors (id INT,name VARCHAR(255)); INSERT INTO donors (id,name) VALUES (1,'Doctors Without Borders'),(2,'Heart Foundation'),(3,'Cancer Relief'); CREATE TABLE donation_details (donor_id INT,category VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO donation_details (donor_id,category,amount) VALUES (1,'health',1000),(1,'health',2000),(2,'health',500),(2,'health',1500),(3,'research',3000); | SELECT donors.name, AVG(donation_details.amount) AS avg_donation FROM donors INNER JOIN donation_details ON donors.id = donation_details.donor_id WHERE category = 'health' GROUP BY donors.id; |
What is the number of employees working in each country in the 'mining_operations' and 'workforce_diversity' tables? | CREATE TABLE mining_operations (employee_id INT,name VARCHAR(50),age INT,position VARCHAR(50),country VARCHAR(50)); INSERT INTO mining_operations (employee_id,name,age,position,country) VALUES (1,'John Doe',35,'Engineer','USA'); INSERT INTO mining_operations (employee_id,name,age,position,country) VALUES (2,'Jane Smith',28,'Operator','Canada'); CREATE TABLE workforce_diversity (employee_id INT,name VARCHAR(50),department VARCHAR(50),gender VARCHAR(10),age INT,country VARCHAR(50)); INSERT INTO workforce_diversity (employee_id,name,department,gender,age,country) VALUES (1,'John Doe','Engineering','Male',35,'USA'); INSERT INTO workforce_diversity (employee_id,name,department,gender,age,country) VALUES (2,'Jane Smith','Operations','Female',28,'Canada'); | SELECT mining_operations.country, COUNT(*) FROM mining_operations INNER JOIN workforce_diversity ON mining_operations.employee_id = workforce_diversity.employee_id GROUP BY mining_operations.country; |
What is the most popular mobile operating system in each country? | CREATE TABLE mobile_os (id INT,country VARCHAR(50),os_name VARCHAR(50),num_users INT); | SELECT country, os_name, MAX(num_users) FROM mobile_os GROUP BY country; |
What are the top 5 countries with the highest number of factories in the 'circular economy' sector? | CREATE TABLE factories_ext (id INT,name VARCHAR(50),country VARCHAR(50),sector VARCHAR(50),is_circular BOOLEAN); INSERT INTO factories_ext (id,name,country,sector,is_circular) VALUES (1,'Solar Factory','Germany','renewable energy',TRUE),(2,'Wind Factory','China','renewable energy',TRUE),(3,'Coal Factory','USA','non-renewable energy',FALSE); | SELECT country, COUNT(*) as factory_count FROM factories_ext WHERE is_circular = TRUE GROUP BY country ORDER BY factory_count DESC LIMIT 5; |
Delete all Green building projects in Australia that were implemented before 2018. | CREATE TABLE green_buildings (project_name VARCHAR(50),country VARCHAR(50),implementation_year INT); INSERT INTO green_buildings (project_name,country,implementation_year) VALUES ('ProjectA','Australia',2019),('ProjectB','Australia',2018),('ProjectC','Australia',2020); | DELETE FROM green_buildings WHERE country = 'Australia' AND implementation_year < 2018; |
What is the inventory turnover rate for each menu item? | CREATE TABLE inventory (menu_item VARCHAR(255),initial_inventory INT,final_inventory INT,COST DECIMAL(10,2)); INSERT INTO inventory (menu_item,initial_inventory,final_inventory,COST) VALUES ('Bruschetta',50,25,10.00),('Spaghetti Bolognese',100,50,20.00),('Cheesecake',75,55,15.00); | SELECT menu_item, (SUM(initial_inventory) + SUM(final_inventory))/2 as average_inventory, SUM(initial_inventory - final_inventory) as total_sold, SUM(initial_inventory - final_inventory) * COST as total_cost FROM inventory GROUP BY menu_item; |
Which ingredients have been sourced from non-organic farms for cosmetic products in the past year? | CREATE TABLE ingredient_sourcing (ingredient_name VARCHAR(255),sourcing_location VARCHAR(255),last_updated DATE); INSERT INTO ingredient_sourcing (ingredient_name,sourcing_location,last_updated) VALUES ('Palm Oil','Non-Organic Farm,Brazil','2022-03-01'),('Microplastics','Lab,USA','2022-02-15'),('Parabens','Lab,France','2022-04-05'); | SELECT ingredient_name FROM ingredient_sourcing WHERE sourcing_location NOT LIKE '%Organic Farm%' AND last_updated >= DATEADD(year, -1, GETDATE()); |
Show the number of cases handled by each legal organization in the justice system | CREATE TABLE legal_organizations (org_id INT,org_name VARCHAR(255),PRIMARY KEY (org_id)); CREATE TABLE org_cases (org_id INT,case_id INT,PRIMARY KEY (org_id,case_id),FOREIGN KEY (org_id) REFERENCES legal_organizations(org_id),FOREIGN KEY (case_id) REFERENCES cases(case_id)); INSERT INTO legal_organizations (org_id,org_name) VALUES (1,'Organization 1'),(2,'Organization 2'),(3,'Organization 3'); INSERT INTO org_cases (org_id,case_id) VALUES (1,1),(1,2),(2,3),(3,4); | SELECT o.org_name, COUNT(oc.org_id) FROM legal_organizations o INNER JOIN org_cases oc ON o.org_id = oc.org_id GROUP BY o.org_name; |
How many travel advisories were issued in 2021 and 2022? | CREATE TABLE travel_advisories (advisory_id INT,country TEXT,year INT,reason TEXT); INSERT INTO travel_advisories (advisory_id,country,year,reason) VALUES (1,'Canada',2021,'Health'),(2,'Mexico',2021,'Political'),(3,'USA',2021,'Safety'),(4,'Canada',2022,'Safety'),(5,'Mexico',2022,'Natural Disaster'); | SELECT YEAR, COUNT(*) FROM travel_advisories WHERE YEAR IN (2021, 2022) GROUP BY YEAR; |
What is the average length of songs (in seconds) in the pop genre? | CREATE TABLE songs (id INT,title TEXT,length FLOAT,genre TEXT); INSERT INTO songs (id,title,length,genre) VALUES (1,'Song1',245.6,'Pop'),(2,'Song2',189.3,'Rock'),(3,'Song3',215.9,'Pop'); | SELECT AVG(length) FROM songs WHERE genre = 'Pop'; |
What is the storage temperature for Nitric Acid? | CREATE TABLE chemical_storage (id INT PRIMARY KEY,chemical_name VARCHAR(255),storage_temperature FLOAT);INSERT INTO chemical_storage (id,chemical_name,storage_temperature) VALUES (2,'Nitric Acid',-20); | SELECT storage_temperature FROM chemical_storage WHERE chemical_name = 'Nitric Acid'; |
What is the total number of decentralized applications created by developers from India? | CREATE TABLE decentralized_applications (id INT,name VARCHAR,developer_country VARCHAR); INSERT INTO decentralized_applications (id,name,developer_country) VALUES (1,'DA1','India'),(2,'DA2','USA'),(3,'DA3','Germany'),(4,'DA4','Brazil'),(5,'DA5','India'),(6,'DA6','Nigeria'); | SELECT COUNT(*) FROM decentralized_applications WHERE developer_country = 'India'; |
What is the total mass of spacecraft manufactured by 'Cosmos Inc'? | CREATE TABLE Spacecrafts (Spacecraft_ID INT,Name VARCHAR(255),Manufacturer VARCHAR(255),Mass FLOAT); INSERT INTO Spacecrafts (Spacecraft_ID,Name,Manufacturer,Mass) VALUES (1,'Galactic Explorer','Galactic Instruments',4500.2),(2,'Nebula One','AstroTech',2000.5),(3,'Stellar Voyager','Cosmos Inc',6000.0),(4,'Starship Titan','Cosmos Inc',7500.5); | SELECT SUM(Mass) FROM Spacecrafts WHERE Manufacturer = 'Cosmos Inc'; |
What is the average budget for climate mitigation projects in the Caribbean? | CREATE TABLE climate_mitigation(project_name TEXT,country TEXT,budget FLOAT); INSERT INTO climate_mitigation(project_name,country,budget) VALUES ('Project E','Jamaica',100000.00),('Project F','Barbados',150000.00),('Project G','Cuba',120000.00),('Project H','Trinidad and Tobago',180000.00); | SELECT AVG(budget) FROM climate_mitigation WHERE country IN ('Jamaica', 'Barbados', 'Cuba', 'Trinidad and Tobago'); |
List all warehouse locations and their corresponding total inventory value, sorted by inventory value in descending order. | CREATE TABLE warehouse (id INT,location VARCHAR(20),total_inventory DECIMAL(10,2)); INSERT INTO warehouse (id,location,total_inventory) VALUES (1,'Atlanta',2000.00),(2,'Dallas',3000.00),(3,'Houston',1500.00); | SELECT location, total_inventory FROM warehouse ORDER BY total_inventory DESC; |
What is the minimum pollution level recorded in the Atlantic Ocean? | CREATE TABLE ocean_pollution (location VARCHAR(255),pollution_level FLOAT); INSERT INTO ocean_pollution (location,pollution_level) VALUES ('Pacific Ocean',7.5),('Atlantic Ocean',6.2); | SELECT MIN(pollution_level) FROM ocean_pollution WHERE location = 'Atlantic Ocean'; |
How many security incidents were reported in each region in the last month? | CREATE TABLE security_incidents (region VARCHAR(255),incident_date DATE); INSERT INTO security_incidents (region,incident_date) VALUES ('North America','2022-01-01'),('Europe','2022-02-01'),('Asia','2022-03-01'),('Asia','2022-04-01'),('Africa','2022-05-01'); | SELECT region, COUNT(*) as incident_count FROM security_incidents WHERE incident_date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY region; |
Calculate the total budget for support programs in the past year | CREATE TABLE support_programs (program_id INT,program_name VARCHAR(30),budget DECIMAL(10,2),initiation_date DATE); INSERT INTO support_programs (program_id,program_name,budget,initiation_date) VALUES (1,'Mobility Support',25000,'2021-01-01'),(2,'Assistive Technology',30000,'2020-06-15'),(3,'Note Taking',15000,'2021-12-01'),(4,'Diversity Training',40000,'2019-05-01'); | SELECT SUM(budget) FROM support_programs WHERE initiation_date >= '2021-01-01'; |
What is the maximum number of investments for high-risk accounts in the Latin America region? | CREATE TABLE investments (id INT,account_risk_level VARCHAR(10),region VARCHAR(20),num_investments INT); INSERT INTO investments (id,account_risk_level,region,num_investments) VALUES (1,'high','Latin America',3),(2,'medium','North America',2),(3,'low','Europe',1),(4,'high','Asia-Pacific',4); | SELECT MAX(num_investments) FROM investments WHERE account_risk_level = 'high' AND region = 'Latin America'; |
What is the total population of endangered animals in Africa? | CREATE TABLE animals (id INT,name VARCHAR(255),population INT,endangered BOOLEAN,region VARCHAR(255)); INSERT INTO animals (id,name,population,endangered,region) VALUES (1,'African Elephant',400000,true,'Africa'),(2,'Lion',20000,false,'Africa'); | SELECT SUM(population) FROM animals WHERE endangered = true AND region = 'Africa'; |
What are the total R&D expenses for vaccines with sales greater than $500 million? | CREATE TABLE rd_expenses (drug_name TEXT,rd_expenses INTEGER); INSERT INTO rd_expenses (drug_name,rd_expenses) VALUES ('Vac1',200000000),('Vac2',350000000),('Vac3',425000000); CREATE TABLE vaccine_sales (drug_name TEXT,sales INTEGER); INSERT INTO vaccine_sales (drug_name,sales) VALUES ('Vac1',600000000),('Vac2',400000000),('Vac3',550000000); | SELECT SUM(rd_expenses) FROM rd_expenses INNER JOIN vaccine_sales ON rd_expenses.drug_name = vaccine_sales.drug_name WHERE sales > 500000000; |
Show the number of training programs in each location from 'training_programs' | CREATE TABLE training_programs (id INT PRIMARY KEY,program_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE,capacity INT); INSERT INTO training_programs (id,program_name,location,start_date,end_date,capacity) VALUES (1,'SQL Fundamentals','New York City','2023-04-01','2023-04-05',50),(2,'Data Visualization','Chicago','2023-05-15','2023-05-19',40),(3,'Machine Learning','New York City','2023-06-01','2023-06-03',60); | SELECT location, COUNT(*) FROM training_programs GROUP BY location; |
Which brands have never had a non-compliant safety rating? | CREATE TABLE Brands (Brand_ID INT PRIMARY KEY,Brand_Name TEXT); CREATE TABLE Safety_Inspections (Inspection_ID INT PRIMARY KEY,Brand_ID INT,Inspection_Date DATE,Compliance_Rating TEXT); INSERT INTO Brands (Brand_ID,Brand_Name) VALUES (1,'Aromatica'),(2,'Herbivore'),(3,'Kora'),(4,'Lush'); INSERT INTO Safety_Inspections (Inspection_ID,Brand_ID,Inspection_Date,Compliance_Rating) VALUES (1,1,'2022-01-01','Compliant'),(2,1,'2022-02-01','Compliant'),(3,2,'2022-01-01','Non-Compliant'),(4,2,'2022-02-01','Compliant'),(5,3,'2022-01-01','Compliant'),(6,3,'2022-02-01','Compliant'),(7,4,'2022-01-01','Compliant'),(8,4,'2022-02-01','Non-Compliant'); | SELECT Brand_Name FROM Brands b WHERE NOT EXISTS (SELECT * FROM Safety_Inspections si WHERE b.Brand_ID = si.Brand_ID AND Compliance_Rating = 'Non-Compliant'); |
How many employees have been trained in the last 6 months? | CREATE TABLE EmployeeTraining (EmployeeID INT,TrainingDate DATE); INSERT INTO EmployeeTraining (EmployeeID,TrainingDate) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2021-12-01'); | SELECT COUNT(*) FROM EmployeeTraining WHERE TrainingDate >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
What is the maximum number of visitors at the "zoo_exhibits" table grouped by animal_type? | CREATE TABLE zoo_exhibits (exhibit_id INT,animal_type VARCHAR(255),num_visitors INT); INSERT INTO zoo_exhibits (exhibit_id,animal_type,num_visitors) VALUES (1,'Mammal',500),(2,'Bird',400),(3,'Reptile',600); | SELECT animal_type, MAX(num_visitors) FROM zoo_exhibits GROUP BY animal_type; |
What is the maximum project timeline for green building projects in New York? | CREATE TABLE project_timeline (id INT,project_name VARCHAR(50),state VARCHAR(50),timeline INT); INSERT INTO project_timeline (id,project_name,state,timeline) VALUES (1,'Solar Panel Installation','New York',50); INSERT INTO project_timeline (id,project_name,state,timeline) VALUES (2,'Wind Turbine Installation','New York',60); INSERT INTO project_timeline (id,project_name,state,timeline) VALUES (3,'Green Building','New York',70); | SELECT MAX(timeline) FROM project_timeline WHERE state = 'New York' AND project_name LIKE '%green%' |
Calculate the veteran unemployment rate for the last month | CREATE SCHEMA labor_schema; CREATE TABLE veteran_employment (employment_id INT PRIMARY KEY,veteran_status VARCHAR(255),employment_date DATE); INSERT INTO veteran_employment (employment_id,veteran_status,employment_date) VALUES (1,'unemployed','2022-01-01'); INSERT INTO veteran_employment (employment_id,veteran_status,employment_date) VALUES (2,'employed','2022-01-01'); INSERT INTO veteran_employment (employment_id,veteran_status,employment_date) VALUES (3,'unemployed','2022-02-01'); | SELECT (SUM(CASE WHEN veteran_status = 'unemployed' THEN 1 ELSE 0 END) / COUNT(*)) * 100 FROM veteran_employment WHERE employment_date >= LAST_DAY(CURRENT_DATE - INTERVAL 2 MONTH) + INTERVAL 1 DAY AND employment_date < LAST_DAY(CURRENT_DATE - INTERVAL 1 MONTH) + INTERVAL 1 DAY; |
What is the total amount of funds donated by each organization for the education sector in Latin America in 2020? | CREATE TABLE donors (donor_id INT,donor_name TEXT,donation_amount DECIMAL,donation_date DATE,sector TEXT,country TEXT); INSERT INTO donors (donor_id,donor_name,donation_amount,donation_date,sector,country) VALUES (1,'Save the Children',75000,'2020-01-01','education','Latin America'); | SELECT donor_name, SUM(donation_amount) as total_donation FROM donors WHERE country = 'Latin America' AND sector = 'education' GROUP BY donor_name; |
Calculate the total budget allocated for 'Healthcare' services in the 'North' region in Q1 2023. | CREATE TABLE Budget(Date DATE,Region VARCHAR(20),Department VARCHAR(20),Amount INT); INSERT INTO Budget(Date,Region,Department,Amount) VALUES ('2023-01-01','North','Healthcare',3000000),('2023-01-05','North','Healthcare',2500000),('2023-02-10','North','Healthcare',2000000); | SELECT SUM(Amount) FROM Budget WHERE Region = 'North' AND Department = 'Healthcare' AND Date BETWEEN '2023-01-01' AND '2023-03-31'; |
What is the average age of all male editors in the 'editors' table? | CREATE TABLE editors (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,experience INT); INSERT INTO editors (id,name,gender,age,experience) VALUES (1,'John Doe','Male',50,15); INSERT INTO editors (id,name,gender,age,experience) VALUES (2,'Jim Brown','Male',45,12); INSERT INTO editors (id,name,gender,age,experience) VALUES (3,'Samantha Johnson','Female',35,10); | SELECT AVG(age) FROM editors WHERE gender = 'Male' AND position = 'Editor'; |
Show the names of all defense diplomacy events with the word 'summit' in them from 2016 to 2018. | CREATE TABLE diplomacy (id INT,event VARCHAR(50),year INT); INSERT INTO diplomacy (id,event,year) VALUES (1,'Innovation Summit',2016); INSERT INTO diplomacy (id,event,year) VALUES (2,'Peace Summit',2018); | SELECT event FROM diplomacy WHERE event LIKE '%summit%' AND year BETWEEN 2016 AND 2018; |
list all autonomous vehicle models and their manufacturers | CREATE TABLE autonomous_vehicles (vehicle_id INT,model VARCHAR(255),manufacturer VARCHAR(255)); | SELECT model, manufacturer FROM autonomous_vehicles; |
Delete records in the 'ticket_sales' table where the price was below the average ticket price for a given event. | CREATE TABLE ticket_sales (ticket_id INT,event_id INT,price DECIMAL(5,2)); | DELETE FROM ticket_sales WHERE price < (SELECT AVG(price) FROM ticket_sales GROUP BY event_id); |
What is the total duration of strength training workouts in the last month for members over 30 years old? | CREATE TABLE Members (MemberID INT,Age INT,HasSmartwatch BOOLEAN); CREATE TABLE Workouts (WorkoutID INT,MemberID INT,WorkoutDate DATE,Duration INT,WorkoutType VARCHAR(10)); | SELECT SUM(Duration) FROM Workouts INNER JOIN Members ON Workouts.MemberID = Members.MemberID WHERE Members.Age > 30 AND WorkoutType = 'strength' AND WorkoutDate >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH); |
What is the average square footage of properties in the rural_neighborhoods view? | CREATE VIEW rural_neighborhoods AS SELECT * FROM properties WHERE neighborhood_type = 'rural'; | SELECT AVG(square_footage) FROM rural_neighborhoods; |
List the number of citizens providing feedback for each district in 2018 | CREATE TABLE Districts (District_ID INT,District_Name VARCHAR(50),Feedback_Count INT,Year INT); INSERT INTO Districts (District_ID,District_Name,Feedback_Count,Year) VALUES (1,'Downtown',500,2018),(2,'Uptown',300,2018),(3,'Harbor',400,2018),(4,'Beach',600,2018),(5,'Forest',700,2018); | SELECT District_Name, Feedback_Count FROM Districts WHERE Year = 2018; |
What is the maximum ocean pH, grouped by month and hemisphere? | CREATE TABLE ocean_ph_2 (id INT,month INT,ph FLOAT,hemisphere VARCHAR(255)); INSERT INTO ocean_ph_2 (id,month,ph,hemisphere) VALUES (1,1,8.1,'Northern'); INSERT INTO ocean_ph_2 (id,month,ph,hemisphere) VALUES (2,2,8.0,'Southern'); INSERT INTO ocean_ph_2 (id,month,ph,hemisphere) VALUES (3,3,7.9,'Northern'); | SELECT hemisphere, month, MAX(ph) FROM ocean_ph_2 GROUP BY hemisphere, month; |
What is the average donation amount and average volunteer hours for each category? | CREATE TABLE donors (id INT,name VARCHAR(50)); CREATE TABLE donations (id INT,donor_id INT,organization_id INT,amount DECIMAL(10,2)); CREATE TABLE volunteers (id INT,name VARCHAR(50)); CREATE TABLE volunteer_events (id INT,volunteer_id INT,organization_id INT,hours DECIMAL(10,2)); CREATE TABLE organizations (id INT,name VARCHAR(50),category VARCHAR(20)); INSERT INTO donors (id,name) VALUES (1,'Donor1'),(2,'Donor2'),(3,'Donor3'),(4,'Donor4'),(5,'Donor5'); INSERT INTO donations (id,donor_id,organization_id,amount) VALUES (1,1,1,500),(2,2,1,700),(3,3,2,1000),(4,4,2,1200),(5,5,3,800); INSERT INTO volunteers (id,name) VALUES (1,'Volunteer1'),(2,'Volunteer2'),(3,'Volunteer3'),(4,'Volunteer4'),(5,'Volunteer5'); INSERT INTO volunteer_events (id,volunteer_id,organization_id,hours) VALUES (1,1,1,2.5),(2,2,1,3.5),(3,3,2,5),(4,4,2,6),(5,5,3,4); INSERT INTO organizations (id,name,category) VALUES (1,'Org1','Health'),(2,'Org2','Health'),(3,'Org3','Arts & Culture'); | SELECT organizations.category, AVG(donations.amount) AS avg_donation, AVG(volunteer_events.hours) AS avg_volunteer_hours FROM organizations JOIN donations ON organizations.id = donations.organization_id JOIN volunteer_events ON organizations.id = volunteer_events.organization_id GROUP BY organizations.category; |
Which victims from Texas were involved in incidents in 2020? | CREATE TABLE victims (id INT,name VARCHAR(50),age INT,state VARCHAR(2)); CREATE TABLE incidents (id INT,incident_date DATE,location VARCHAR(50),victim_id INT,crime_id INT); | SELECT victims.name, incidents.incident_date FROM victims JOIN incidents ON victims.id = incidents.victim_id WHERE victims.state = 'TX' AND incidents.incident_date >= '2020-01-01' AND incidents.incident_date <= '2020-12-31'; |
What is the distribution of military budgets for countries in the European Union in 2022? | CREATE TABLE eu_military_budgets (country VARCHAR(50),year INT,budget FLOAT); INSERT INTO eu_military_budgets (country,year,budget) VALUES ('Germany',2022,49.3),('France',2022,41.2),('UK',2022,39.8),('Italy',2022,26.7),('Spain',2022,17.4),('Poland',2022,11.6),('Netherlands',2022,11.1),('Greece',2022,6.3); | SELECT country, budget FROM eu_military_budgets WHERE year = 2022; |
What is the total revenue from the 'Mobile' services in the 'Eastern' region? | CREATE TABLE Services (Service VARCHAR(20),Revenue INT); INSERT INTO Services (Service,Revenue) VALUES ('Mobile',50000),('Broadband',30000); CREATE TABLE Customers (CustomerID INT,Service VARCHAR(20),Region VARCHAR(20)); INSERT INTO Customers (CustomerID,Service,Region) VALUES (1,'Mobile','Eastern'),(2,'Broadband','Western'),(3,'Mobile','Eastern'); | SELECT SUM(s.Revenue) as TotalRevenue FROM Services s JOIN Customers c ON s.Service = c.Service WHERE c.Region = 'Eastern'; |
What is the average production rate of gold mines in the US? | CREATE TABLE gold_mines (id INT,name TEXT,location TEXT,production_rate FLOAT); INSERT INTO gold_mines (id,name,location,production_rate) VALUES (1,'Brewer Gold Mine','Nevada,USA',5000.0),(2,'Cortez Gold Mine','Nevada,USA',12000.0); | SELECT AVG(production_rate) FROM gold_mines WHERE location LIKE '%USA%'; |
What is the occupancy rate for hotels in the 'budget' segment over the last month? | CREATE TABLE hotel_occupancy (hotel_id INT,segment VARCHAR(20),occupancy INT,date DATE); | SELECT segment, AVG(occupancy) as avg_occupancy FROM hotel_occupancy WHERE segment = 'budget' AND date >= DATE(NOW()) - INTERVAL 1 MONTH GROUP BY segment; |
List the total waste generated per manufacturing plant | CREATE TABLE manufacturing_plants (plant_id INT,plant_name VARCHAR(255),waste_generated INT); INSERT INTO manufacturing_plants (plant_id,plant_name,waste_generated) VALUES (1,'Plant A',500),(2,'Plant B',700),(3,'Plant C',800); | SELECT plant_name, SUM(waste_generated) as total_waste FROM manufacturing_plants GROUP BY plant_name; |
How many unique users used the public bike-share system in the last week, grouped by day? | CREATE TABLE bike_share (user_id INT,bike_id INT,rental_start_time TIMESTAMP,rental_end_time TIMESTAMP); | SELECT DATE(rental_start_time) AS rental_day, COUNT(DISTINCT user_id) AS unique_users FROM bike_share WHERE rental_start_time >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) GROUP BY rental_day; |
What is the earliest founding year for companies with a female founder? | CREATE TABLE company (id INT,name TEXT,founding_year INT,founder_gender TEXT); INSERT INTO company (id,name,founding_year,founder_gender) VALUES (1,'Acme Inc',2010,'female'); INSERT INTO company (id,name,founding_year,founder_gender) VALUES (2,'Beta Corp',2015,'male'); | SELECT MIN(founding_year) FROM company WHERE founder_gender = 'female'; |
What is the average number of disability accommodations provided per individual with a disability in each region for the past year? | CREATE TABLE Disability_Accommodations (id INT,individual_id INT,region VARCHAR(50),accommodation_count INT,accommodation_date DATE); | SELECT region, AVG(accommodation_count) as avg_accommodation_count FROM Disability_Accommodations WHERE accommodation_date >= DATEADD(year, -1, GETDATE()) GROUP BY region; |
What is the maximum number of public transit trips in Beijing in a day? | CREATE TABLE if not exists PublicTransit (id INT,city VARCHAR(20),trips INT,date DATE); INSERT INTO PublicTransit (id,city,trips,date) VALUES (1,'Beijing',15000,'2022-03-15'),(2,'Beijing',18000,'2022-03-16'),(3,'Shanghai',12000,'2022-03-15'); | SELECT MAX(trips) FROM PublicTransit WHERE city = 'Beijing'; |
Who are the contacts for the 'community development' sector in Asia? | CREATE TABLE contacts (id INT,name TEXT,sector TEXT,region TEXT,email TEXT); INSERT INTO contacts (id,name,sector,region,email) VALUES (1,'John Doe','community development','Asia','john.doe@example.com'); INSERT INTO contacts (id,name,sector,region,email) VALUES (2,'Jane Doe','refugee support','Africa','jane.doe@example.com'); INSERT INTO contacts (id,name,sector,region,email) VALUES (3,'Jim Smith','community development','Europe','jim.smith@example.com'); | SELECT name, email FROM contacts WHERE sector = 'community development' AND region = 'Asia'; |
What is the minimum number of floors in commercial buildings in the state of New York? | CREATE TABLE building_info (building_id INT,building_type VARCHAR(50),floors INT,state VARCHAR(50)); INSERT INTO building_info (building_id,building_type,floors,state) VALUES (1,'Residential',3,'California'),(2,'Commercial',10,'New York'),(3,'Residential',4,'Texas'),(4,'Commercial',8,'New York'); | SELECT MIN(floors) FROM building_info WHERE building_type = 'Commercial' AND state = 'New York'; |
Which artist from the 'Cubism' movement has the most art pieces in the collection? | CREATE TABLE art_pieces (piece_id INT,artist_name VARCHAR(50),artist_gender VARCHAR(10),artist_ethnicity VARCHAR(20),movement VARCHAR(20)); INSERT INTO art_pieces (piece_id,artist_name,artist_gender,artist_ethnicity,movement) VALUES (1,'Pablo Picasso','Male','Spanish','Cubism'); INSERT INTO art_pieces (piece_id,artist_name,artist_gender,artist_ethnicity,movement) VALUES (2,'Georges Braque','Male','French','Cubism'); | SELECT artist_name, COUNT(*) as art_piece_count FROM art_pieces WHERE movement = 'Cubism' GROUP BY artist_name ORDER BY art_piece_count DESC LIMIT 1; |
What is the average number of volunteer hours in Brazil? | CREATE TABLE Volunteers (id INT,user_id INT,country VARCHAR(50),hours DECIMAL(10,2),volunteer_date DATE); INSERT INTO Volunteers (id,user_id,country,hours,volunteer_date) VALUES (4,204,'Brazil',2.00,'2021-10-01'); INSERT INTO Volunteers (id,user_id,country,hours,volunteer_date) VALUES (8,208,'Argentina',2.50,'2022-03-15'); | SELECT AVG(hours) FROM Volunteers WHERE country = 'Brazil'; |
Find the total construction labor hours per week in California, for each building type | CREATE TABLE labor_hours_3 (worker_id INT,state VARCHAR(20),building_type VARCHAR(20),hours_per_week DECIMAL(5,2)); INSERT INTO labor_hours_3 (worker_id,state,building_type,hours_per_week) VALUES (1,'CA','Residential',25.00),(2,'CA','Commercial',35.00),(3,'CA','Industrial',45.00); | SELECT state, building_type, SUM(hours_per_week) as total_hours FROM labor_hours_3 WHERE state = 'CA' GROUP BY state, building_type; |
What is the average price of rap songs? | CREATE TABLE Songs (song_id INT,title TEXT,genre TEXT,release_date DATE,price DECIMAL(5,2)); | SELECT AVG(Songs.price) FROM Songs WHERE Songs.genre = 'rap'; |
Delete records in the 'solar_plants' table where the 'capacity_mw' is less than 10 | CREATE TABLE solar_plants (id INT PRIMARY KEY,name VARCHAR(255),capacity_mw FLOAT,country VARCHAR(255)); | DELETE FROM solar_plants WHERE capacity_mw < 10; |
How many carbon offset initiatives were launched in the city of Tokyo in 2018? | CREATE TABLE carbon_offset_initiatives (id INT,name TEXT,city TEXT,launch_date DATE); INSERT INTO carbon_offset_initiatives (id,name,city,launch_date) VALUES (1,'Initiative 1','Tokyo','2018-01-01'); INSERT INTO carbon_offset_initiatives (id,name,city,launch_date) VALUES (2,'Initiative 2','Tokyo','2019-01-01'); INSERT INTO carbon_offset_initiatives (id,name,city,launch_date) VALUES (3,'Initiative 3','New York','2018-01-01'); | SELECT COUNT(*) FROM carbon_offset_initiatives WHERE city = 'Tokyo' AND launch_date <= '2018-12-31'; |
What is the total number of hospitals and clinics in the rural health database? | CREATE TABLE hospitals (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO hospitals (id,name,location) VALUES (1,'Rural Hospital A','Rural Town A'); INSERT INTO hospitals (id,name,location) VALUES (2,'Rural Hospital B','Rural Town B'); CREATE TABLE clinics (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO clinics (id,name,location) VALUES (1,'Rural Clinic A','Rural Town A'); INSERT INTO clinics (id,name,location) VALUES (2,'Rural Clinic B','Rural Town C'); | SELECT COUNT(*) FROM hospitals UNION SELECT COUNT(*) FROM clinics; |
How many professional development programs have been attended by teachers in the 'Suburbs' district? | CREATE TABLE teachers (teacher_id INT,teacher_name TEXT,district_id INT); INSERT INTO teachers (teacher_id,teacher_name,district_id) VALUES (1,'Mrs. Doe',1),(2,'Mr. Smith',2),(3,'Ms. Johnson',3); CREATE TABLE professional_development (program_id INT,program_name TEXT,teacher_id INT); INSERT INTO professional_development (program_id,program_name,teacher_id) VALUES (1,'Python for Educators',1),(2,'Data Science for Teachers',2),(3,'Inclusive Teaching',3),(4,'Open Pedagogy',3); | SELECT COUNT(*) FROM professional_development pd JOIN teachers t ON pd.teacher_id = t.teacher_id WHERE t.district_id = 3; |
What is the total number of investments in the education sector, broken down by year? | CREATE TABLE investments (investment_id INT,sector VARCHAR(50),investment_amount INT,investment_date DATE); INSERT INTO investments (investment_id,sector,investment_amount,investment_date) VALUES (1,'Education',500000,'2022-01-01'),(2,'Education',600000,'2023-02-01'),(3,'Education',400000,'2024-03-01'),(4,'Education',300000,'2025-04-01'),(5,'Education',700000,'2026-05-01'); | SELECT EXTRACT(YEAR FROM investment_date) as year, COUNT(*) as total_investments FROM investments WHERE sector = 'Education' GROUP BY year ORDER BY year ASC; |
What is the minimum number of nodes required to form a quorum on the Stellar network? | CREATE TABLE stellar_nodes (node_id VARCHAR(50),quorum_percentage DECIMAL(5,2)); | SELECT MIN(quorum_percentage) FROM stellar_nodes HAVING COUNT(*) >= (SELECT COUNT(*) FROM stellar_nodes) * 0.5; |
Find the volunteer with the highest number of hours volunteered in each program? | CREATE TABLE Volunteers (VolunteerID int,Name varchar(50),Program varchar(50),Hours numeric(5,2)); INSERT INTO Volunteers (VolunteerID,Name,Program,Hours) VALUES (1,'Alice','ProgramA',20.00),(2,'Bob','ProgramB',30.00); | SELECT Name, Program, MAX(Hours) OVER (PARTITION BY Program) AS MaxHours FROM Volunteers; |
What is the total number of employees in the Mining department and their average salary? | CREATE TABLE Employees (id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT,employment_status VARCHAR(50)); INSERT INTO Employees (id,name,department,salary,employment_status) VALUES (1,'John Doe','Mining',75000.00,'Full-time'),(2,'Jane Smith','HR',60000.00,'Full-time'),(3,'Mike Johnson','Mining',80000.00,'Full-time'),(4,'Sara Davis','HR',65000.00,'Full-time'),(5,'David Kim','IT',70000.00,'Part-time'); | SELECT department, COUNT(*), AVG(salary) FROM Employees WHERE department = 'Mining' GROUP BY department; |
Compare veteran employment statistics in the defense industry with the private sector | CREATE TABLE veteran_employment_defense (veteran_id INT,industry VARCHAR(50),employed BOOLEAN); INSERT INTO veteran_employment_defense (veteran_id,industry,employed) VALUES (1,'Defense',TRUE),(2,'Defense',FALSE); CREATE TABLE veteran_employment_private (veteran_id INT,industry VARCHAR(50),employed BOOLEAN); INSERT INTO veteran_employment_private (veteran_id,industry,employed) VALUES (1,'Private',TRUE),(2,'Private',TRUE),(3,'Private',FALSE); | SELECT SUM(employed) FROM veteran_employment_defense WHERE employed = TRUE; SELECT SUM(employed) FROM veteran_employment_private WHERE employed = TRUE; |
List all military technologies that were used in the last 2 military conflicts, including the technology type and conflict date. | CREATE TABLE military_tech_usage (id INT,tech_type TEXT,tech_usage_date DATE,conflict TEXT); INSERT INTO military_tech_usage (id,tech_type,tech_usage_date,conflict) VALUES (1,'Drones','2020-02-01','Conflict A'),(2,'Armored Vehicles','2019-11-15','Conflict B'); | SELECT mt.tech_type, mt.tech_usage_date FROM military_tech_usage mt WHERE mt.tech_usage_date >= '2019-01-01'; |
Retrieve the number of posts per day for the last 7 days | CREATE TABLE posts (id INT PRIMARY KEY,user_id INT,content TEXT,created_at TIMESTAMP); | SELECT DATE_TRUNC('day', created_at) AS day, COUNT(*) FROM posts WHERE created_at >= NOW() - INTERVAL '7 days' GROUP BY day; |
Insert a new row into the 'autonomous_driving_tests' table with the following values: 'Waymo', 'Phoenix', 'Level 4', '2022-05-01' | CREATE TABLE autonomous_driving_tests (company VARCHAR(255),city VARCHAR(255),autonomous_level VARCHAR(255),test_date DATE); | INSERT INTO autonomous_driving_tests (company, city, autonomous_level, test_date) VALUES ('Waymo', 'Phoenix', 'Level 4', '2022-05-01'); |
Which products in the products table have been certified by a specific certification in the labor_certifications table? | CREATE TABLE products (product_id INT,product_name VARCHAR(50)); CREATE TABLE labor_certifications (certification_id INT,certification_name VARCHAR(50)); CREATE TABLE product_labor_certifications (product_id INT,certification_id INT); INSERT INTO products (product_id,product_name) VALUES (1,'Eco Hoodie'),(2,'Sustainable Shoes'),(3,'Recycled Backpack'); INSERT INTO labor_certifications (certification_id,certification_name) VALUES (1,'Fair Trade'),(2,'Certified B Corporation'); INSERT INTO product_labor_certifications (product_id,certification_id) VALUES (1,1),(3,1); | SELECT p.product_name FROM products p INNER JOIN product_labor_certifications plc ON p.product_id = plc.product_id INNER JOIN labor_certifications lc ON plc.certification_id = lc.certification_id WHERE lc.certification_name = 'Fair Trade'; |
How many volunteers were registered in 'California' in the table 'Volunteers'? | CREATE TABLE Volunteers (volunteer_id INT,registration_date DATE,state VARCHAR(20)); INSERT INTO Volunteers (volunteer_id,registration_date,state) VALUES (1,'2022-01-01','California'),(2,'2022-01-02','Texas'); | SELECT COUNT(*) FROM Volunteers WHERE state = 'California'; |
What is the total number of network infrastructure investments made in the last quarter? | CREATE TABLE network_investments (investment_id INT,investment_date DATE,investment_amount FLOAT); INSERT INTO network_investments (investment_id,investment_date,investment_amount) VALUES (1,'2022-01-01',500000); INSERT INTO network_investments (investment_id,investment_date,investment_amount) VALUES (2,'2022-03-15',750000); | SELECT SUM(investment_amount) FROM network_investments WHERE investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH); |
What is the standard deviation of the age of players who play Action games? | CREATE TABLE Players (PlayerID INT,Age INT,GameType VARCHAR(10)); INSERT INTO Players (PlayerID,Age,GameType) VALUES (1,25,'Action'),(2,30,'RPG'),(3,22,'Action'),(4,28,'Action'),(5,20,'Action'); | SELECT STDDEV(Age) FROM Players WHERE GameType = 'Action'; |
List the names and Shariah-compliant loan amounts for customers who have received Shariah-compliant loans in February 2021. | CREATE TABLE shariah_compliant_loans (loan_id INT,customer_id INT,amount DECIMAL(10,2),issue_date DATE); INSERT INTO shariah_compliant_loans (loan_id,customer_id,amount,issue_date) VALUES (3,106,5500.00,'2021-02-15'),(4,107,6500.00,'2021-02-28'); | SELECT name, amount FROM customers c INNER JOIN shariah_compliant_loans s ON c.customer_id = s.customer_id WHERE MONTH(issue_date) = 2 AND YEAR(issue_date) = 2021; |
What is the total revenue generated from digital museum experiences in the last quarter? | CREATE TABLE DigitalExperiences (experience_id INT,date DATE,revenue DECIMAL(10,2)); INSERT INTO DigitalExperiences (experience_id,date,revenue) VALUES (1,'2022-01-01',50.00),(2,'2022-02-01',75.00),(3,'2022-03-01',100.00); | SELECT SUM(revenue) FROM DigitalExperiences WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH); |
List the top 5 countries with the highest number of fair trade certified factories. | CREATE TABLE FairTradeFactories (id INT,country VARCHAR(50),certification_date DATE); | SELECT country, COUNT(*) as num_factories FROM FairTradeFactories GROUP BY country ORDER BY num_factories DESC LIMIT 5; |
List all vessels and their corresponding fleet management officer's name, even if a vessel has no assigned officer. | CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50)); CREATE TABLE fleet_officers (officer_id INT,officer_name VARCHAR(50)); CREATE TABLE vessel_assignments (assignment_id INT,vessel_id INT,officer_id INT); | SELECT v.vessel_name, coalesce(fo.officer_name, 'Unassigned') as officer_name FROM vessels v LEFT JOIN vessel_assignments va ON v.vessel_id = va.vessel_id LEFT JOIN fleet_officers fo ON va.officer_id = fo.officer_id; |
What is the total revenue generated by 'hotels' in 'South America' that offer 'pool' facilities? | CREATE TABLE hotels(id INT,name TEXT,country TEXT,rating FLOAT,pool BOOLEAN,revenue FLOAT); | SELECT SUM(revenue) FROM hotels WHERE country = 'South America' AND pool = TRUE; |
What is the average number of players per eSports event in the 'Strategy' category? | CREATE TABLE EventPlayers (event VARCHAR(100),category VARCHAR(50),players INT); | SELECT AVG(players) FROM EventPlayers WHERE category = 'Strategy'; |
What is the total number of users from India and China? | CREATE TABLE users (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,city VARCHAR(50),country VARCHAR(50)); INSERT INTO users (id,name,gender,age,city,country) VALUES (1,'David','Male',20,'New York','USA'); INSERT INTO users (id,name,gender,age,city,country) VALUES (2,'Eva','Female',25,'Los Angeles','USA'); INSERT INTO users (id,name,gender,age,city,country) VALUES (3,'Fiona','Female',30,'Mumbai','India'); INSERT INTO users (id,name,gender,age,city,country) VALUES (4,'George','Male',35,'Beijing','China'); | SELECT country, COUNT(*) as total_users FROM users WHERE country IN ('India', 'China') GROUP BY country; |
Delete all records from the "tourist_sites" table where the "country" is "Brazil" and the "visitor_count" is less than 5000 | CREATE TABLE tourist_sites (id INT PRIMARY KEY,name TEXT,country TEXT,visitor_count INT); | DELETE FROM tourist_sites WHERE country = 'Brazil' AND visitor_count < 5000; |
Update the recycling rate for 'paper' to 48% in 'recycling_rates' table for Q3 2022. | CREATE TABLE recycling_rates (quarter TEXT,material TEXT,rate DECIMAL(3,2)); INSERT INTO recycling_rates (quarter,material,rate) VALUES ('Q1 2021','plastic',0.30),('Q1 2021','paper',0.45),('Q2 2022','plastic',0.31),('Q2 2022','paper',0.46),('Q3 2022','plastic',NULL),('Q3 2022','paper',NULL); | UPDATE recycling_rates SET rate = 0.48 WHERE quarter = 'Q3 2022' AND material = 'paper'; |
Get the total amount of water used and waste generated per month by 'XYZ Mining'. | CREATE TABLE TimePeriod (id INT,name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO TimePeriod (id,name,start_date,end_date) VALUES (1,'Month','2022-01-01','2022-01-31'); CREATE TABLE MiningWater (id INT,mining_company_id INT,time_period_id INT,quantity INT); INSERT INTO MiningWater (id,mining_company_id,time_period_id,quantity) VALUES (1,2,1,15000); CREATE TABLE MiningWaste (id INT,mining_company_id INT,time_period_id INT,quantity INT); INSERT INTO MiningWaste (id,mining_company_id,time_period_id,quantity) VALUES (1,2,1,5000); | SELECT t.name, SUM(w.quantity) AS water_quantity, SUM(wa.quantity) AS waste_quantity FROM TimePeriod t, MiningWater w, MiningWaste wa, MiningCompany mc WHERE t.id = w.time_period_id AND t.id = wa.time_period_id AND mc.id = w.mining_company_id AND mc.id = wa.mining_company_id AND mc.name = 'XYZ Mining' GROUP BY t.name; |
How many military bases are there in California? | CREATE TABLE bases (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO bases (id,name,state) VALUES (1,'Fort Irwin','California'),(2,'Edwards AFB','California'); | SELECT COUNT(*) FROM bases WHERE state = 'California'; |
What is the average arrival age of visitors for each continent? | CREATE TABLE if not exists visitor_stats (visitor_id INT,arrival_age INT,continent VARCHAR(10)); INSERT INTO visitor_stats (visitor_id,arrival_age,continent) VALUES (1,35,'Europe'),(2,28,'Asia'),(3,42,'Americas'),(4,22,'Africa'),(5,31,'Australia'); | SELECT AVG(arrival_age) as avg_age, continent FROM visitor_stats GROUP BY continent; |
Identify the number of marine species in the Southern Ocean by taxonomic class. | CREATE TABLE SouthernOcean (species_name TEXT,taxonomic_class TEXT); INSERT INTO SouthernOcean (species_name,taxonomic_class) VALUES ('Krill','Crustacea'),('Blue Whale','Mammalia'); CREATE TABLE Taxonomy (taxonomic_class TEXT,class_count INTEGER); INSERT INTO Taxonomy (taxonomic_class,class_count) VALUES ('Crustacea',10),('Mammalia',5); | SELECT Taxonomy.taxonomic_class, Taxonomy.class_count FROM Taxonomy INNER JOIN SouthernOcean ON Taxonomy.taxonomic_class = SouthernOcean.taxonomic_class; |
What is the average production volume of coal per mine in the United States? | CREATE TABLE mines (id INT,name TEXT,location TEXT,product TEXT,production_volume INT); INSERT INTO mines (id,name,location,product,production_volume) VALUES (1,'Black Thunder','United States','Coal',20000); | SELECT AVG(production_volume) FROM mines WHERE location = 'United States' AND product = 'Coal'; |
Delete transactions from clients living in the United States. | CREATE TABLE clients (client_id INT,name TEXT,country TEXT,transaction_amount DECIMAL); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (1,'John Doe','United States',500.00); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (2,'Jane Smith','Canada',350.00); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (3,'Mike Johnson','Mexico',400.00); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (4,'Sara Doe','United States',600.00); | DELETE FROM clients WHERE country = 'United States'; |
Which restaurants have had a food safety violation in the past year? | CREATE TABLE restaurants(id INT,name VARCHAR(255),last_inspection_date DATE); INSERT INTO restaurants (id,name,last_inspection_date) VALUES (1,'Restaurant A','2021-06-01'),(2,'Restaurant B','2022-03-15'),(3,'Restaurant C','2021-11-30'); | SELECT name FROM restaurants WHERE last_inspection_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE AND FIND_IN_SET('violation', inspection_details) > 0; |
Avg. ESG score for European sustainable infrastructure? | CREATE TABLE infrastructure_details(infrastructure_id INT,esg_score FLOAT,region VARCHAR(10)); | SELECT AVG(esg_score) FROM infrastructure_details WHERE region = 'Europe'; |
What is the total carbon pricing revenue in the European Union and the UK, and what is the percentage contribution of each? | CREATE TABLE carbon_pricing (country VARCHAR(20),revenue INT); INSERT INTO carbon_pricing (country,revenue) VALUES ('European Union',50000),('UK',30000); | SELECT c1.country, c1.revenue, (c1.revenue * 100.0 / SUM(c1.revenue)) as percentage FROM carbon_pricing c1 WHERE c1.country IN ('European Union', 'UK') GROUP BY c1.country; |
What is the average size of all marine protected areas in the Pacific Ocean? | CREATE TABLE marine_protected_areas (name VARCHAR(255),area_size FLOAT,ocean VARCHAR(255)); INSERT INTO marine_protected_areas (name,area_size,ocean) VALUES ('Hawaiian Islands',137030,'Pacific'); | SELECT AVG(area_size) FROM marine_protected_areas WHERE ocean = 'Pacific'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.