instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Identify vessels that visited multiple ports in a single journey, and provide their journey start and end dates. | CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50),flag_state VARCHAR(50)); CREATE TABLE ports_visited (id INT,vessel_id INT,port_id INT,visit_date DATE); | SELECT v1.vessel_name, v1.visit_date as journey_start, v2.visit_date as journey_end FROM ports_visited v1 JOIN ports_visited v2 ON v1.vessel_id = v2.vessel_id AND v1.visit_date < v2.visit_date WHERE NOT EXISTS (SELECT 1 FROM ports_visited v3 WHERE v3.vessel_id = v1.vessel_id AND v3.visit_date > v1.visit_date AND v3.visit_date < v2.visit_date); |
List the top 2 most sustainable fabric suppliers in 'Europe' based on the sustainability_rating? | CREATE TABLE europe_suppliers(name VARCHAR(50),location VARCHAR(50),sustainability_rating INT); INSERT INTO europe_suppliers (name,location,sustainability_rating) VALUES ('GreenFabrics','France',97); INSERT INTO europe_suppliers (name,location,sustainability_rating) VALUES ('EcoWeave','Germany',95); INSERT INTO europe_suppliers (name,location,sustainability_rating) VALUES ('SustainSupply','Italy',94); | SELECT name, sustainability_rating FROM europe_suppliers WHERE location = 'Europe' ORDER BY sustainability_rating DESC LIMIT 2; |
Find the number of successful contract negotiations with Saudi Arabia for each year since 2015. | CREATE TABLE contract_negotiations(id INT,country VARCHAR(50),contractor VARCHAR(50),negotiation_date DATE,status VARCHAR(50)); INSERT INTO contract_negotiations(id,country,contractor,negotiation_date,status) VALUES (1,'Saudi Arabia','ABC Corp','2015-01-01','Successful'); INSERT INTO contract_negotiations(id,country,contractor,negotiation_date,status) VALUES (2,'Saudi Arabia','XYZ Inc.','2016-01-01','Successful'); | SELECT YEAR(negotiation_date), COUNT(*) FROM contract_negotiations WHERE country = 'Saudi Arabia' AND status = 'Successful' GROUP BY YEAR(negotiation_date); |
What is the minimum production of a well in 'Saudi Arabia'? | CREATE TABLE OilWells (WellID VARCHAR(10),Production FLOAT,Location VARCHAR(50)); | SELECT MIN(Production) FROM OilWells WHERE Location = 'Saudi Arabia'; |
What is the total number of renewable energy projects and their total installed capacity for each energy type? | CREATE TABLE EnergyTypes (TypeID int,TypeName varchar(50)); CREATE TABLE RenewableProjects (ProjectID int,TypeID int,InstalledCapacity int); | SELECT EnergyTypes.TypeName, COUNT(RenewableProjects.ProjectID) as TotalProjects, SUM(RenewableProjects.InstalledCapacity) as TotalCapacity FROM EnergyTypes INNER JOIN RenewableProjects ON EnergyTypes.TypeID = RenewableProjects.TypeID GROUP BY EnergyTypes.TypeName; |
What is the average CO2 emission of textile suppliers, per continent? | CREATE TABLE TextileSuppliers (SupplierID INT,SupplierName VARCHAR(255),Continent VARCHAR(255),CO2Emission INT); INSERT INTO TextileSuppliers (SupplierID,SupplierName,Continent,CO2Emission) VALUES (1,'Supplier1','Asia',500); | SELECT AVG(CO2Emission) as AverageCO2Emission, Continent FROM TextileSuppliers GROUP BY Continent; |
Which brands have the highest sales of natural hair care products? | CREATE TABLE sales (sale_id INT,product_id INT,brand VARCHAR(100),sales_volume INT); CREATE TABLE products (product_id INT,product_name VARCHAR(100),is_natural BOOLEAN,product_type VARCHAR(50)); | SELECT brand, SUM(sales_volume) as total_sales FROM sales JOIN products ON sales.product_id = products.product_id WHERE is_natural = TRUE AND product_type = 'hair care' GROUP BY brand ORDER BY total_sales DESC LIMIT 5; |
Which sustainable sourcing certifications are most common among the restaurants? | CREATE TABLE sourcing (restaurant_id INT,certification TEXT); INSERT INTO sourcing (restaurant_id,certification) VALUES (1,'Seafood Watch'),(1,'Fair Trade'),(2,'Rainforest Alliance'),(2,'Marine Stewardship Council'),(3,'Seafood Watch'),(3,'Fair Trade'),(4,'Rainforest Alliance'),(4,'Marine Stewardship Council'),(4,'Seafood Watch'); | SELECT certification, COUNT(*) FROM sourcing GROUP BY certification ORDER BY COUNT(*) DESC; |
What was the average journey speed (in knots) for all vessels in the month of July 2021? | CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(255)); CREATE TABLE Journeys (JourneyID INT,VesselID INT,JourneySpeed DECIMAL(5,2),JourneyDate DATETIME); INSERT INTO Vessels (VesselID,VesselName) VALUES (1,'Oceanus'),(2,'Neptune'),(3,'Poseidon'); INSERT INTO Journeys (JourneyID,VesselID,JourneySpeed,JourneyDate) VALUES (1,1,15.5,'2021-07-01 10:00:00'),(2,1,17.2,'2021-07-05 14:00:00'),(3,2,19.8,'2021-07-03 08:00:00'),(4,2,20.0,'2021-07-10 16:00:00'),(5,3,18.5,'2021-07-07 11:00:00'),(6,3,18.0,'2021-07-15 09:00:00'); | SELECT AVG(JourneySpeed) AS AvgJourneySpeed FROM Journeys WHERE MONTH(JourneyDate) = 7; |
What is the total volume of wastewater treated in Jakarta, Indonesia in 2019 and 2020? | CREATE TABLE jakarta_wastewater (year INT,treatment_volume INT); INSERT INTO jakarta_wastewater (year,treatment_volume) VALUES (2019,500000),(2020,550000); | SELECT jakarta_wastewater.year, SUM(jakarta_wastewater.treatment_volume) as total_treatment_volume FROM jakarta_wastewater WHERE jakarta_wastewater.year IN (2019, 2020) GROUP BY jakarta_wastewater.year; |
Get the total number of smart city projects in 'South America' | CREATE TABLE smart_cities (id INT,name VARCHAR(100),location VARCHAR(50),description TEXT,region VARCHAR(10)); INSERT INTO smart_cities (id,name,location,description,region) VALUES (1,'Smart City A','Buenos Aires','Smart city project','South America'); INSERT INTO smart_cities (id,name,location,description,region) VALUES (2,'Smart City B','Rio de Janeiro','Smart city initiative','South America'); | SELECT COUNT(*) FROM smart_cities WHERE region = 'South America'; |
What is the average delivery time for aircraft manufactured by country? | CREATE SCHEMA Aerospace;CREATE TABLE Aerospace.AircraftManufacturing (manufacturer VARCHAR(50),country VARCHAR(50),delivery_time INT);INSERT INTO Aerospace.AircraftManufacturing (manufacturer,country,delivery_time) VALUES ('Boeing','USA',18),('Airbus','Europe',24),('Comac','China',30); | SELECT country, AVG(delivery_time) FROM Aerospace.AircraftManufacturing GROUP BY country; |
What is the average cost of disability accommodations per student for students with visual impairments? | CREATE TABLE accommodations (id INT,student_id INT,type TEXT,cost INT); INSERT INTO accommodations (id,student_id,type,cost) VALUES (1,1,'screen reader',200); INSERT INTO accommodations (id,student_id,type,cost) VALUES (2,2,'note taker',500); | SELECT AVG(cost) FROM accommodations WHERE type IN ('screen reader', 'braille display', 'large print materials') GROUP BY student_id; |
What is the average financial wellbeing score of individuals in the United States who have a high financial literacy level? | CREATE TABLE financial_literacy (individual_id TEXT,financial_literacy TEXT,wellbeing_score NUMERIC); INSERT INTO financial_literacy (individual_id,financial_literacy,wellbeing_score) VALUES ('33333','high',85); INSERT INTO financial_literacy (individual_id,financial_literacy,wellbeing_score) VALUES ('44444','high',90); | SELECT AVG(wellbeing_score) FROM financial_literacy WHERE financial_literacy = 'high' AND country = 'United States'; |
How many socially responsible loans were issued to women in the last year? | CREATE TABLE lenders (lender_id INT,name VARCHAR(255),address VARCHAR(255)); CREATE TABLE loans (loan_id INT,lender_id INT,date DATE,amount DECIMAL(10,2),socially_responsible BOOLEAN,gender VARCHAR(255)); | SELECT lenders.name, COUNT(loans.loan_id) as count FROM lenders INNER JOIN loans ON lenders.lender_id = loans.lender_id WHERE loans.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE AND loans.socially_responsible = TRUE AND loans.gender = 'Female' GROUP BY lenders.name; |
List the number of unique mental health providers in the 'treatment' table who treated patients in January 2022. | CREATE TABLE treatment (treatment_id INT,patient_id INT,condition VARCHAR(50),provider VARCHAR(50),date DATE); INSERT INTO treatment (treatment_id,patient_id,condition,provider,date) VALUES (1,1,'Anxiety Disorder','Dr. Jane','2021-01-01'); INSERT INTO treatment (treatment_id,patient_id,condition,provider,date) VALUES (2,1,'PTSD','Dr. Bob','2021-02-01'); INSERT INTO treatment (treatment_id,patient_id,condition,provider,date) VALUES (3,2,'Anxiety Disorder','Dr. Bob','2021-03-01'); INSERT INTO treatment (treatment_id,patient_id,condition,provider,date) VALUES (4,3,'Depression','Dr. Jane','2022-01-15'); | SELECT COUNT(DISTINCT provider) FROM treatment WHERE date BETWEEN '2022-01-01' AND '2022-01-31'; |
Find the number of AI models with a fairness score above 85, excluding those from the education sector. | CREATE TABLE ai_models (model_name TEXT,fairness_score INTEGER,sector TEXT); INSERT INTO ai_models (model_name,fairness_score,sector) VALUES ('Model1',90,'Healthcare'),('Model2',80,'Education'),('Model3',88,'Finance'); | SELECT COUNT(*) FROM ai_models WHERE fairness_score > 85 AND sector != 'Education'; |
What is the total number of accessible technology projects in Asia? | CREATE TABLE accessible_tech_projects (id INT,country VARCHAR(2),project_accessibility VARCHAR(10)); INSERT INTO accessible_tech_projects (id,country,project_accessibility) VALUES (1,'CN','yes'),(2,'IN','no'),(3,'JP','yes'),(4,'KR','yes'),(5,'SG','no'),(6,'VN','yes'),(7,'ID','no'),(8,'TH','yes'),(9,'PH','no'),(10,'MY','yes'); | SELECT COUNT(*) FROM accessible_tech_projects WHERE country IN ('CN', 'IN', 'JP', 'KR', 'SG', 'VN', 'ID', 'TH', 'PH', 'MY') AND project_accessibility = 'yes'; |
Delete all pollution control initiatives that have not been updated in the last 2 years. | CREATE TABLE pollution_control_initiatives (id INT,initiative VARCHAR(50),last_updated TIMESTAMP); | DELETE FROM pollution_control_initiatives WHERE last_updated < NOW() - INTERVAL 2 YEAR; |
Compare the number of heritage sites in Africa and South America. | CREATE TABLE heritagesites (id INT,site_name VARCHAR(100),location VARCHAR(50)); INSERT INTO heritagesites (id,site_name,location) VALUES (1,'Machu Picchu','South America'),(2,'Great Zimbabwe','Africa'); | SELECT COUNT(*) FROM heritagesites WHERE location = 'Africa' INTERSECT SELECT COUNT(*) FROM heritagesites WHERE location = 'South America'; |
Which TV shows have the highest and lowest viewership within their genre? | CREATE TABLE TVShows (ShowId INT,ShowName VARCHAR(50),Seasons INT,Genre VARCHAR(50),Viewers INT); INSERT INTO TVShows (ShowId,ShowName,Seasons,Genre,Viewers) VALUES (1,'ShowA',3,'Drama',500000),(2,'ShowB',2,'Comedy',700000),(3,'ShowC',4,'Drama',600000); | SELECT ShowName, Genre, Viewers, RANK() OVER(PARTITION BY Genre ORDER BY Viewers DESC) AS Rank FROM TVShows; |
Add a new record to the 'clean_energy_policy' table with id 6001, policy_name 'Feed-in Tariff', country 'Spain', and year_implemented 2007 | CREATE TABLE clean_energy_policy (id INT PRIMARY KEY,policy_name VARCHAR(100),country VARCHAR(50),year_implemented INT); | INSERT INTO clean_energy_policy (id, policy_name, country, year_implemented) VALUES (6001, 'Feed-in Tariff', 'Spain', 2007); |
What is the average number of lifetime learning hours per student up to '2022'? | CREATE TABLE lifelong_learning (student_name VARCHAR(20),learning_hours INT,learning_date DATE); INSERT INTO lifelong_learning (student_name,learning_hours,learning_date) VALUES ('Student A',10,'2017-09-01'),('Student A',8,'2018-02-14'),('Student B',12,'2019-06-22'),('Student B',15,'2020-12-31'),('Student C',11,'2021-07-04'),('Student C',7,'2022-02-15'); | SELECT AVG(total_hours) as avg_hours FROM (SELECT student_name, SUM(learning_hours) as total_hours FROM lifelong_learning WHERE learning_date <= '2022-12-31' GROUP BY student_name) as subquery; |
Update the total number of passengers for the NYC subway line 6 | CREATE TABLE subway_lines (id INT PRIMARY KEY,line_number INT,line_name VARCHAR(255),city VARCHAR(255),total_passengers INT); | UPDATE subway_lines SET total_passengers = 850000 WHERE line_number = 6 AND city = 'NYC'; |
What is the most common art medium in the 'art_pieces' table? | CREATE TABLE art_pieces (piece_id INT,title VARCHAR(50),year_created INT,artist_id INT,medium VARCHAR(20)); | SELECT medium, COUNT(medium) as count FROM art_pieces GROUP BY medium ORDER BY count DESC LIMIT 1; |
How many new members joined each month in the past year? | CREATE TABLE members(id INT,join_date DATE); INSERT INTO members(id,join_date) VALUES (1,'2021-01-03'),(2,'2021-02-15'),(3,'2021-03-27'),(4,'2021-05-09'),(5,'2021-06-21'),(6,'2021-07-04'),(7,'2021-08-12'),(8,'2021-09-26'),(9,'2021-10-08'),(10,'2021-11-20'),(11,'2021-12-31'),(12,'2022-02-14'); | SELECT MONTH(join_date) AS month, COUNT(*) AS members_joined FROM members WHERE join_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY month ORDER BY month; |
Update the insurance type of policyholders who have both a home and auto insurance policy, and live in Florida to Comprehensive. | CREATE TABLE Policyholders (PolicyholderID INT,Address VARCHAR(100),State VARCHAR(2)); CREATE TABLE HomeInsurance (PolicyholderID INT,HomeAddress VARCHAR(100),InsuranceType VARCHAR(50)); CREATE TABLE AutoInsurance (PolicyholderID INT,AutoAddress VARCHAR(100),InsuranceType VARCHAR(50)); | UPDATE HomeInsurance SET InsuranceType = 'Comprehensive' WHERE PolicyholderID IN (SELECT PolicyholderID FROM Policyholders WHERE State = 'FL'); UPDATE AutoInsurance SET InsuranceType = 'Comprehensive' WHERE PolicyholderID IN (SELECT PolicyholderID FROM Policyholders WHERE State = 'FL'); |
What is the average network infrastructure investment per year for the 'rural' region? | CREATE TABLE investments (id INT,region VARCHAR(10),year INT,amount INT); INSERT INTO investments (id,region,year,amount) VALUES (1,'rural',2020,80000),(2,'urban',2019,110000),(3,'suburban',2021,120000),(4,'rural',2019,70000),(5,'rural',2021,90000); | SELECT region, AVG(amount) FROM investments WHERE region = 'rural' GROUP BY region, year HAVING COUNT(*) > 1; |
What is the average coal production per machine in Queensland? | CREATE TABLE mines (id INT,state VARCHAR(20),machine_type VARCHAR(20),coal_production FLOAT); INSERT INTO mines (id,state,machine_type,coal_production) VALUES (1,'Queensland','TypeA',120.5),(2,'Queensland','TypeB',150.3),(3,'NewSouthWales','TypeA',135.0); | SELECT state, AVG(coal_production) as avg_production FROM mines WHERE state = 'Queensland' GROUP BY state; |
What is the minimum claim amount for policies issued in '2021'? | CREATE TABLE claims (id INT,policy_number INT,claim_amount INT,issue_date DATE); INSERT INTO claims VALUES (1,1234,5000,'2021-01-01'); INSERT INTO claims VALUES (2,5678,7000,'2021-02-01'); INSERT INTO claims VALUES (3,9012,3000,'2020-01-01'); | SELECT MIN(claim_amount) FROM claims WHERE EXTRACT(YEAR FROM issue_date) = 2021; |
What is the total value of paintings sold by female artists in Germany? | CREATE TABLE Artists (id INT,name VARCHAR(255),gender VARCHAR(6)); CREATE TABLE ArtWork (id INT,title VARCHAR(255),artist_id INT,price DECIMAL(10,2),type VARCHAR(255)); INSERT INTO Artists (id,name,gender) VALUES (1,'ArtistX','Female'); INSERT INTO ArtWork (id,title,artist_id,price,type) VALUES (1,'Painting1',1,12000,'Painting'); | SELECT SUM(ArtWork.price) FROM ArtWork INNER JOIN Artists ON ArtWork.artist_id = Artists.id WHERE ArtWork.type = 'Painting' AND Artists.gender = 'Female' AND Artists.name LIKE '%Germany%'; |
Find the total installed capacity (in MW) for each technology type in the 'renewable_projects' table | CREATE TABLE renewable_projects (id INT,technology VARCHAR(50),location VARCHAR(50),capacity_mw FLOAT); | SELECT technology, SUM(capacity_mw) FROM renewable_projects GROUP BY technology; |
What is the average speed of electric buses in the City of Los Angeles? | CREATE TABLE electric_buses (bus_id int,city varchar(20),avg_speed decimal(5,2)); INSERT INTO electric_buses (bus_id,city,avg_speed) VALUES (1,'Los Angeles',25.6),(2,'Los Angeles',27.3),(3,'Los Angeles',28.1); | SELECT AVG(avg_speed) FROM electric_buses WHERE city = 'Los Angeles' AND bus_id <> 2; |
What is the total billing amount by legal precedent? | CREATE TABLE Precedents (PrecedentID INT,CaseID INT,BillingAmount DECIMAL(10,2)); INSERT INTO Precedents (PrecedentID,CaseID,BillingAmount) VALUES (1,1,500.00),(2,1,750.00),(3,2,800.00),(4,3,900.00),(5,4,1000.00),(6,5,400.00),(7,6,350.00),(8,7,1200.00),(9,8,1500.00),(10,9,1100.00); | SELECT PrecedentID, SUM(BillingAmount) AS Total_Billing_Amount FROM Precedents GROUP BY PrecedentID; |
What is the total number of electric bike rides in Berlin in the first half of 2022? | CREATE TABLE electric_bikes (bike_id INT,ride_id INT,start_time TIMESTAMP,end_time TIMESTAMP,city VARCHAR(255)); | SELECT COUNT(*) FROM electric_bikes WHERE city = 'Berlin' AND start_time >= '2022-01-01 00:00:00' AND start_time < '2022-07-01 00:00:00'; |
What was the total number of volunteers in 2020? | CREATE TABLE volunteers (id INT,name TEXT,year INT,sector TEXT); INSERT INTO volunteers (id,name,year,sector) VALUES (1,'John Doe',2019,'disaster response'); INSERT INTO volunteers (id,name,year,sector) VALUES (2,'Jane Doe',2020,'refugee support'); INSERT INTO volunteers (id,name,year,sector) VALUES (3,'Jim Smith',2020,'disaster response'); | SELECT COUNT(*) FROM volunteers WHERE year = 2020; |
What is the total labor cost for sustainable construction projects in Texas in the past month? | CREATE TABLE LaborCosts (CostID int,ProjectID int,LaborCost money,Date date,IsSustainable bit); CREATE TABLE Projects (ProjectID int,ProjectName varchar(255),State varchar(255),StartDate date,EndDate date); | SELECT SUM(LaborCost) as TotalLaborCost FROM LaborCosts JOIN Projects ON LaborCosts.ProjectID = Projects.ProjectID WHERE State = 'Texas' AND Date >= DATEADD(month, -1, GETDATE()) AND IsSustainable = 1; |
What is the number of users who clicked on an ad promoting renewable energy in Germany, in the past week, and have never clicked on an ad before? | CREATE TABLE clicks (click_id INT,user_id INT,ad_id INT,click_date DATE); | SELECT COUNT(DISTINCT c.user_id) FROM clicks c JOIN ads a ON c.ad_id = a.ad_id JOIN users u ON c.user_id = u.user_id WHERE a.content LIKE '%renewable energy%' AND c.click_date >= DATEADD(day, -7, GETDATE()) AND u.lifetime_clicks = 0; |
Find the average protein content for ingredients from specific suppliers | CREATE TABLE ingredients (id INT PRIMARY KEY,name VARCHAR(255),supplier_id INT); CREATE TABLE nutrition (ingredient_id INT,calories INT,protein INT,carbohydrates INT,fat INT); | SELECT AVG(nutrition.protein) FROM ingredients INNER JOIN nutrition ON ingredients.id = nutrition.ingredient_id WHERE ingredients.supplier_id IN (1, 2); |
What is the minimum distance traveled by an electric vehicle in Vancouver? | CREATE TABLE electric_vehicles (id INT,city VARCHAR(20),type VARCHAR(20),daily_distance INT); INSERT INTO electric_vehicles VALUES (1,'vancouver','sedan',40); INSERT INTO electric_vehicles VALUES (2,'vancouver','suv',50); INSERT INTO electric_vehicles VALUES (3,'toronto','truck',60); | SELECT MIN(daily_distance) FROM electric_vehicles WHERE city = 'vancouver'; |
What is the lowest risk investment strategy and its associated risk score? | CREATE TABLE investment_strategies (id INT,strategy TEXT,risk_score FLOAT); INSERT INTO investment_strategies (id,strategy,risk_score) VALUES (1,'Equity Investment',6.5),(2,'Real Estate Investment',4.8),(3,'Bond Investment',3.2); | SELECT strategy, MIN(risk_score) FROM investment_strategies; |
What is the total number of animals in 'animal_population' table? | CREATE TABLE animal_population (id INT,species VARCHAR(50),population INT);INSERT INTO animal_population (id,species,population) VALUES (1,'Tiger',250),(2,'Elephant',500); | SELECT SUM(population) FROM animal_population; |
What is the maximum number of units produced per day by each production line in the last month? | CREATE TABLE production_lines (id INT,name TEXT); INSERT INTO production_lines (id,name) VALUES (1,'Line 1'),(2,'Line 2'),(3,'Line 3'); CREATE TABLE production (line_id INT,production_date DATE,units INT); INSERT INTO production (line_id,production_date,units) VALUES (1,'2022-05-01',500),(1,'2022-05-02',550),(1,'2022-05-03',600),(2,'2022-05-01',400),(2,'2022-05-02',450),(2,'2022-05-03',500),(3,'2022-05-01',650),(3,'2022-05-02',700),(3,'2022-05-03',750); | SELECT line_id, MAX(units) as max_units_per_day FROM production WHERE production_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW() GROUP BY line_id; |
What is the total carbon offset of carbon offset programs in the 'carbon_offset_programs' table, grouped by project type? | CREATE TABLE carbon_offset_programs (project_type VARCHAR(255),carbon_offsets INT); | SELECT project_type, SUM(carbon_offsets) FROM carbon_offset_programs GROUP BY project_type; |
Insert a new excavation site into the ExcavationSites table | CREATE TABLE ExcavationSites (SiteID int,Name varchar(50),Country varchar(50),StartDate date); | INSERT INTO ExcavationSites (SiteID, Name, Country, StartDate) VALUES (4, 'Site D', 'Peru', '2008-08-08'); |
What is the 3-month rolling average of patient outcomes by condition? | CREATE TABLE patient_outcomes (patient_id INT,condition_id INT,improvement_score INT,follow_up_date DATE); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (13,1,12,'2022-04-01'); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (14,1,15,'2022-05-01'); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (15,2,8,'2022-06-01'); INSERT INTO patient_outcomes (patient_id,condition_id,improvement_score,follow_up_date) VALUES (16,2,10,'2022-07-01'); | SELECT condition_id, AVG(improvement_score) OVER (PARTITION BY condition_id ORDER BY follow_up_date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as rolling_avg FROM patient_outcomes; |
Calculate the sum of labor costs for 'Plumbing' workers in 'Dublin' for the year 2018. | CREATE TABLE labor_costs_ie (worker_id INT,city VARCHAR(20),sector VARCHAR(20),hourly_wage DECIMAL(5,2),hours_worked INT,record_date DATE); INSERT INTO labor_costs_ie (worker_id,city,sector,hourly_wage,hours_worked,record_date) VALUES (3,'Dublin','Plumbing',40.5,200,'2018-01-01'); INSERT INTO labor_costs_ie (worker_id,city,sector,hourly_wage,hours_worked,record_date) VALUES (4,'Dublin','Plumbing',41.8,196,'2018-02-15'); | SELECT SUM(hourly_wage * hours_worked) FROM labor_costs_ie WHERE city = 'Dublin' AND sector = 'Plumbing' AND EXTRACT(YEAR FROM record_date) = 2018; |
What are the names and origins of all drivers who have driven on route 123? | CREATE TABLE drivers (driver_id INT,name TEXT,origin TEXT);CREATE TABLE route_drivers (driver_id INT,route_id INT);CREATE TABLE routes (route_id INT,route_name TEXT); INSERT INTO drivers VALUES (1,'John Doe','New York'); INSERT INTO drivers VALUES (2,'Jane Smith','Los Angeles'); INSERT INTO route_drivers VALUES (1,123); INSERT INTO route_drivers VALUES (2,123); INSERT INTO routes VALUES (123,'Route 123'); | SELECT drivers.name, drivers.origin FROM drivers INNER JOIN route_drivers ON drivers.driver_id = route_drivers.driver_id INNER JOIN routes ON route_drivers.route_id = routes.route_id WHERE routes.route_name = 'Route 123'; |
What is the average score for food safety inspections in the US? | CREATE TABLE Inspections (id INT,restaurant_id INT,inspection_date DATE,score INT,country VARCHAR); INSERT INTO Inspections (id,restaurant_id,inspection_date,score,country) VALUES (1,1,'2021-01-01',95,'US'); INSERT INTO Inspections (id,restaurant_id,inspection_date,score,country) VALUES (2,2,'2021-01-02',85,'Italy'); | SELECT AVG(score) FROM Inspections WHERE country = 'US'; |
What is the maximum number of hospital visits for patients with mental health issues in Texas? | CREATE TABLE Patients (PatientID INT,MentalHealth TEXT,HospitalVisits INT,State TEXT); INSERT INTO Patients (PatientID,MentalHealth,HospitalVisits,State) VALUES (1,'Depression',5,'Texas'); | SELECT MAX(HospitalVisits) FROM Patients WHERE MentalHealth IS NOT NULL AND State = 'Texas'; |
How many units of vegan leather garments were sold by each brand in Q2 of 2021? | CREATE TABLE Brands (id INT,name VARCHAR(255)); INSERT INTO Brands (id,name) VALUES (1,'Brand A'),(2,'Brand B'),(3,'Brand C'),(4,'Brand D'); CREATE TABLE Vegan_Leather_Sales (id INT,brand_id INT,quarter INT,year INT,units INT); INSERT INTO Vegan_Leather_Sales (id,brand_id,quarter,year,units) VALUES (1,1,2,2021,150),(2,2,2,2021,200),(3,3,2,2021,250),(4,4,2,2021,300); | SELECT b.name, SUM(v.units) FROM Vegan_Leather_Sales v JOIN Brands b ON v.brand_id = b.id WHERE v.quarter = 2 AND v.year = 2021 GROUP BY b.name; |
What's the average rating of non-English movies released in 2010 or later? | CREATE TABLE Movies (id INT,title VARCHAR(100),release_year INT,rating FLOAT,language VARCHAR(20)); | SELECT AVG(rating) FROM Movies WHERE language <> 'English' AND release_year >= 2010; |
What is the minimum salary of employees working in technology for social good organizations in Africa? | CREATE TABLE employees (id INT,salary FLOAT,organization_type VARCHAR(255),location VARCHAR(255)); INSERT INTO employees (id,salary,organization_type,location) VALUES (1,70000.00,'social good','Africa'),(2,80000.00,'tech company','Europe'),(3,60000.00,'social good','Asia'),(4,90000.00,'tech company','North America'),(5,85000.00,'social good','Africa'); | SELECT MIN(salary) FROM employees WHERE organization_type = 'social good' AND location = 'Africa'; |
Select 'Name' from 'TopStudents' view | CREATE TABLE Students (StudentID INT,Name VARCHAR(100),Grade INT); CREATE VIEW TopStudents AS SELECT Name,Grade FROM Students WHERE Grade >= 12; | SELECT Name FROM TopStudents; |
What is the maximum CO2 emission level for each chemical category, for chemical manufacturing in Europe? | CREATE TABLE chemicals (id INT,name VARCHAR(255),category VARCHAR(255),co2_emissions FLOAT,region VARCHAR(255)); | SELECT category, MAX(co2_emissions) as max_emissions FROM chemicals WHERE region = 'Europe' GROUP BY category; |
Show the number of satellites in the satellite_database table, grouped by their country, and order by the count in ascending order, only showing the bottom 5 countries | CREATE TABLE satellite_database (id INT,name VARCHAR(50),type VARCHAR(50),orbit_type VARCHAR(50),country VARCHAR(50),launch_date DATE); | SELECT country, COUNT(*) as satellite_count FROM satellite_database GROUP BY country ORDER BY satellite_count ASC LIMIT 5; |
What is the average lifespan of satellites in Geostationary Orbit (GEO)? | CREATE TABLE satellite_lifetimes(id INT,name VARCHAR(255),launch_date DATE,launch_site VARCHAR(255),orbit VARCHAR(255),decommission_date DATE); INSERT INTO satellite_lifetimes VALUES (1,'Intelsat 507','1983-03-16','Cape Canaveral','GEO','1997-05-22'); INSERT INTO satellite_lifetimes VALUES (2,'Intelsat 603','1991-03-05','Cape Canaveral','GEO','2002-06-14'); INSERT INTO satellite_lifetimes VALUES (3,'Intelsat 708','1995-04-25','Baikonur Cosmodrome','GEO','2011-02-02'); | SELECT AVG(DATEDIFF(decommission_date, launch_date)) FROM satellite_lifetimes WHERE orbit = 'GEO'; |
What is the maximum sustainability score for hotels in each city? | CREATE TABLE hotel_ratings (hotel_id INT,sustainability_rating FLOAT); INSERT INTO hotel_ratings (hotel_id,sustainability_rating) VALUES (1,4.2),(2,4.5),(3,4.7),(4,4.3); | SELECT hi.city, MAX(st.sustainability_score) FROM sustainable_tourism st INNER JOIN hotel_info hi ON st.hotel_id = hi.hotel_id GROUP BY hi.city; |
What is the maximum energy efficiency rating for appliances in Japan? | CREATE TABLE appliances (id INT,country VARCHAR(255),name VARCHAR(255),energy_efficiency_rating FLOAT); INSERT INTO appliances (id,country,name,energy_efficiency_rating) VALUES (1,'Japan','Appliance A',3.5),(2,'Japan','Appliance B',4.2); | SELECT MAX(energy_efficiency_rating) FROM appliances WHERE country = 'Japan'; |
What is the number of microfinance loans disbursed for agricultural activities in each region? | CREATE TABLE microfinance_loans (region VARCHAR(50),loan_count INT); INSERT INTO microfinance_loans (region,loan_count) VALUES ('Region 1',300),('Region 2',350),('Region 3',400); | SELECT region, loan_count FROM microfinance_loans; |
What is the maximum installed capacity for a solar project in the 'renewable_energy' table? | CREATE TABLE renewable_energy (id INT,project_name TEXT,location TEXT,installed_capacity FLOAT); INSERT INTO renewable_energy (id,project_name,location,installed_capacity) VALUES (1,'Solar Farm 1','Spain',20.5),(2,'Wind Farm 2','Germany',60.3),(3,'Solar Farm 2','Australia',30.7); | SELECT MAX(installed_capacity) FROM renewable_energy WHERE project_name LIKE '%solar%'; |
What is the maximum number of fans for each team in the 'events' table? | CREATE TABLE events (event_id INT,team_id INT,num_fans INT); | SELECT team_id, MAX(num_fans) FROM events GROUP BY team_id; |
Identify the oldest hydroelectric power plant in each country. | CREATE TABLE hydro_plants (id INT,name TEXT,location TEXT,country TEXT,capacity INT,online_date DATE); INSERT INTO hydro_plants (id,name,location,country,capacity,online_date) VALUES (1,'Grand Coulee Dam','Washington,USA','USA',6809,'1942-01-01'),(2,'Itaipu Dam','Parana,Brazil','Brazil',14000,'1984-09-05'),(3,'Three Gorges Dam','Hubei,China','China',22500,'2003-07-04'); | SELECT location, name FROM hydro_plants WHERE online_date = (SELECT MIN(online_date) FROM hydro_plants AS h2 WHERE h2.country = hydro_plants.country) GROUP BY country; |
How many vegetarian options exist on the menu at 'Green Garden'? | CREATE TABLE menus (restaurant VARCHAR(255),item VARCHAR(255),veg BOOLEAN); INSERT INTO menus (restaurant,item,veg) VALUES ('Green Garden','salad',1),('Green Garden','beef burger',0); | SELECT COUNT(*) FROM menus WHERE restaurant = 'Green Garden' AND veg = 1; |
What is the total yield of crops for farmers in urban areas? | CREATE TABLE farmers (id INT,name VARCHAR(50),age INT,location VARCHAR(50)); INSERT INTO farmers (id,name,age,location) VALUES (1,'Jane Smith',40,'Chicago'); INSERT INTO farmers (id,name,age,location) VALUES (2,'Joe Johnson',50,'New York'); CREATE TABLE crops (id INT,name VARCHAR(50),yield INT,farmer_id INT,PRIMARY KEY (id),FOREIGN KEY (farmer_id) REFERENCES farmers(id)); INSERT INTO crops (id,name,yield,farmer_id) VALUES (1,'Corn',200,1); INSERT INTO crops (id,name,yield,farmer_id) VALUES (2,'Wheat',150,2); | SELECT SUM(crops.yield) as total_yield FROM crops INNER JOIN farmers ON crops.farmer_id = farmers.id WHERE farmers.location = 'New York' OR farmers.location = 'Chicago'; |
Delete all records in the 'community_development' table where the budget is greater than or equal to 100000. | CREATE TABLE community_development (id INT,initiative_name VARCHAR(255),budget INT); | DELETE FROM community_development WHERE budget >= 100000; |
What is the average age of patients who have received cognitive behavioral therapy (CBT) treatment in Canada? | CREATE TABLE patients (patient_id INT,age INT,country VARCHAR(50),treatment VARCHAR(50)); INSERT INTO patients (patient_id,age,country,treatment) VALUES (1,35,'Canada','CBT'),(2,42,'Canada','Pharmacotherapy'); | SELECT AVG(age) FROM patients WHERE country = 'Canada' AND treatment = 'CBT'; |
What is the maximum carbon tax per ton in African countries? | CREATE TABLE carbon_tax (id INT PRIMARY KEY,region VARCHAR(50),tax_per_ton FLOAT); INSERT INTO carbon_tax (id,region,tax_per_ton) VALUES (1,'South Africa',5.0),(2,'Morocco',4.5),(3,'Egypt',6.0); | SELECT region, MAX(tax_per_ton) FROM carbon_tax WHERE region IN ('South Africa', 'Morocco', 'Egypt'); |
What is the average mental health score of students per school in the last month? | CREATE TABLE student_mental_health (student_id INT,school_id INT,mental_health_score INT,date DATE); INSERT INTO student_mental_health (student_id,school_id,mental_health_score,date) VALUES (1,101,75,'2022-01-01'); | SELECT school_id, AVG(mental_health_score) as avg_mental_health_score FROM student_mental_health WHERE date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH) GROUP BY school_id; |
What is the minimum quantity of military equipment sold by Northrop Grumman to Middle Eastern countries in Q4 2019? | CREATE TABLE Military_Equipment_Sales(equipment_id INT,manufacturer VARCHAR(255),purchaser VARCHAR(255),sale_date DATE,quantity INT);INSERT INTO Military_Equipment_Sales(equipment_id,manufacturer,purchaser,sale_date,quantity) VALUES (1,'Northrop Grumman','Saudi Arabia','2019-11-01',15),(2,'Northrop Grumman','UAE','2019-12-15',20); | SELECT MIN(quantity) FROM Military_Equipment_Sales WHERE manufacturer = 'Northrop Grumman' AND purchaser LIKE 'Middle East%' AND sale_date BETWEEN '2019-10-01' AND '2019-12-31'; |
List the number of cybersecurity incidents reported by government agencies in the Asia-Pacific region in the last 12 months, in ascending order. | CREATE TABLE cybersecurity_incidents (incident_id INT,agency TEXT,region TEXT,incident_date DATE); INSERT INTO cybersecurity_incidents (incident_id,agency,region,incident_date) VALUES (1,'Ministry of Defense,Singapore','Asia-Pacific','2022-01-01'); | SELECT COUNT(*) FROM cybersecurity_incidents WHERE region = 'Asia-Pacific' AND incident_date >= DATEADD(year, -1, CURRENT_DATE) ORDER BY COUNT(*) ASC; |
What is the total calorie count for meals served in each region? | CREATE TABLE Meals (MealID INT,MealName VARCHAR(50),Region VARCHAR(50),Calories INT); INSERT INTO Meals (MealID,MealName,Region,Calories) VALUES (1,'Spaghetti Bolognese','Europe',650),(2,'Chicken Tikka Masala','Asia',850); | SELECT Region, SUM(Calories) as TotalCalories FROM Meals GROUP BY Region; |
What is the earliest arrival date for each warehouse and what is the latest departure date for each warehouse? | CREATE TABLE movement (movement_id INT,warehouse_id VARCHAR(5),arrival_date DATE,departure_date DATE); INSERT INTO movement (movement_id,warehouse_id,arrival_date,departure_date) VALUES (1,'W001','2021-01-01','2021-01-03'),(2,'W002','2021-02-10','2021-02-12'); | SELECT w.name, MIN(m.arrival_date) AS earliest_arrival, MAX(m.departure_date) AS latest_departure FROM movement m INNER JOIN warehouse w ON m.warehouse_id = w.warehouse_id GROUP BY w.name; |
What is the total number of fans who attended games in each city? | CREATE TABLE teams (team_id INT,team_name VARCHAR(255),city VARCHAR(100)); INSERT INTO teams (team_id,team_name,city) VALUES (1,'Golden State Warriors','San Francisco'),(2,'Los Angeles Lakers','Los Angeles'); CREATE TABLE game_attendance (game_id INT,team_id INT,num_fans INT); INSERT INTO game_attendance (game_id,team_id,num_fans) VALUES (1,1,15000),(2,1,20000),(3,2,10000); | SELECT t.city, SUM(ga.num_fans) as total_fans_attended FROM teams t INNER JOIN game_attendance ga ON t.team_id = ga.team_id GROUP BY t.city; |
Delete all military equipment sales records from the table that do not have a sale value greater than 50,000,000. | CREATE TABLE MilitaryEquipmentSales (seller VARCHAR(255),buyer VARCHAR(255),equipment VARCHAR(255),sale_value FLOAT,sale_date DATE); INSERT INTO MilitaryEquipmentSales (seller,buyer,equipment,sale_value,sale_date) VALUES ('BAE Systems','India','Hawk Jet Trainer',18000000,'2021-08-15'); | DELETE FROM MilitaryEquipmentSales WHERE sale_value < 50000000; |
What is the maximum carbon offsetting achieved by any utility company in 2020? | CREATE TABLE utilities (id INT,company_name VARCHAR(50),carbon_offset_tonnes INT,year INT); INSERT INTO utilities (id,company_name,carbon_offset_tonnes,year) VALUES (1,'Green Power Inc.',120000,2020),(2,'EcoEnergy Ltd.',150000,2019),(3,'Clean Energy Co.',180000,2020),(4,'Renewable Resources Inc.',90000,2020); | SELECT MAX(carbon_offset_tonnes) FROM utilities WHERE year = 2020; |
What is the most expensive artwork created by an artist from 'Asia'? | CREATE TABLE Artworks (artwork_id INTEGER,title TEXT,artist_name TEXT,artist_origin TEXT,price FLOAT); INSERT INTO Artworks (artwork_id,title,artist_name,artist_origin,price) VALUES (1,'Artwork 1','Hiroshi','Japan',10000.0),(2,'Artwork 2','Mei','China',12000.0),(3,'Artwork 3','Aamir','Pakistan',8000.0); | SELECT title, price FROM Artworks WHERE artist_origin = 'Asia' AND price = (SELECT MAX(price) FROM Artworks WHERE artist_origin = 'Asia') |
How many threat intelligence indicators are associated with the 'APT28' group? | CREATE TABLE threat_intelligence (id INT,group_name VARCHAR(255),indicator VARCHAR(255)); INSERT INTO threat_intelligence (id,group_name,indicator) VALUES (1,'APT28','192.168.0.1'),(2,'APT28','example.com'); | SELECT COUNT(*) FROM threat_intelligence WHERE group_name = 'APT28'; |
What is the total revenue of sustainable fashion sales in Berlin and Rome? | CREATE TABLE REVENUE(city VARCHAR(20),revenue DECIMAL(5,2)); INSERT INTO REVENUE(city,revenue) VALUES('Berlin',1500.00),('Berlin',1200.00),('Rome',1800.00),('Rome',2000.00); | SELECT SUM(revenue) FROM REVENUE WHERE city IN ('Berlin', 'Rome') AND revenue > 1000.00; |
List all cities with a population over 500,000 that have a recycling rate above the national average. | CREATE TABLE cities (name VARCHAR(255),state VARCHAR(255),population DECIMAL(10,2),recycling_rate DECIMAL(5,2)); INSERT INTO cities (name,state,population,recycling_rate) VALUES ('Los Angeles','California',3971883,76.9),('New York','New York',8550405,21.1),('Chicago','Illinois',2693976,9.5); | SELECT name FROM cities WHERE population > 500000 AND recycling_rate > (SELECT AVG(recycling_rate) FROM cities); |
List all the wells in the 'Utica' shale play that produced more than 1500 barrels in a day. | CREATE TABLE utica_production (well text,date text,production real); INSERT INTO utica_production VALUES ('Well1','2021-01-01',1000),('Well1','2021-01-02',1200),('Well2','2021-01-01',2100),('Well2','2021-01-02',1300); | SELECT well FROM utica_production WHERE production > 1500; |
What is the total fare collected from passengers for each route on January 1, 2022? | CREATE TABLE routes (route_id INT,route_name TEXT);CREATE TABLE fares (fare_id INT,route_id INT,fare_amount DECIMAL,fare_collection_date DATE); INSERT INTO routes (route_id,route_name) VALUES (1,'Route A'),(2,'Route B'); INSERT INTO fares (fare_id,route_id,fare_amount,fare_collection_date) VALUES (1,1,5.00,'2022-01-01'),(2,1,5.00,'2022-01-01'),(3,2,3.50,'2022-01-01'); | SELECT r.route_name, SUM(f.fare_amount) as total_fare FROM routes r JOIN fares f ON r.route_id = f.route_id WHERE f.fare_collection_date = '2022-01-01' GROUP BY r.route_name; |
What is the sum of all statement lengths in the database? | CREATE TABLE artist_statements (statement_length INTEGER); INSERT INTO artist_statements (statement_length) VALUES (50),(100),(150); | SELECT SUM(statement_length) FROM artist_statements; |
What is the minimum number of employees in a workplace with labor rights violations in Germany? | CREATE TABLE workplaces (id INT,country VARCHAR(50),num_employees INT,has_lrv BOOLEAN); INSERT INTO workplaces (id,country,num_employees,has_lrv) VALUES (1,'Germany',200,true),(2,'Germany',150,false),(3,'Germany',250,true); | SELECT MIN(num_employees) FROM workplaces WHERE country = 'Germany' AND has_lrv = true; |
Calculate the total ad spend for the advertising table for the last month. | CREATE TABLE advertising (campaign_id INT,spend DECIMAL(10,2),impressions INT,start_date DATE,end_date DATE); | SELECT SUM(spend) as total_spend FROM advertising WHERE start_date <= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND end_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH); |
Identify the drug with the highest sales amount in 'Europe' for 'Medichem' in 2021. | CREATE TABLE sales (drug_name TEXT,company TEXT,continent TEXT,sales_amount INT,sale_date DATE); INSERT INTO sales (drug_name,company,continent,sales_amount,sale_date) VALUES ('Paracetamol','Medichem','Europe',4000,'2021-01-01'); | SELECT drug_name, MAX(sales_amount) FROM sales WHERE company = 'Medichem' AND continent = 'Europe' AND sale_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY drug_name; |
What is the total number of cases heard by community courts in New York and the corresponding year? | CREATE TABLE community_courts (id INT,court_name VARCHAR(255),state VARCHAR(255),year INT,cases_heard INT); INSERT INTO community_courts (id,court_name,state,year,cases_heard) VALUES (1,'East Los Angeles Community Court','California',2018,850),(2,'Midtown Community Court','New York',2019,905),(3,'Red Hook Community Justice Center','New York',2017,760); | SELECT community_courts.year, SUM(community_courts.cases_heard) AS total_cases_heard FROM community_courts WHERE community_courts.state = 'New York'; |
What are the top 3 cosmetic brands in the Australian market with the most products certified as cruelty-free and vegan? | CREATE TABLE cosmetics_certifications (product_id INT,brand TEXT,is_cruelty_free BOOLEAN,is_vegan BOOLEAN,country TEXT); | SELECT brand, COUNT(*) as num_certified_products FROM cosmetics_certifications WHERE is_cruelty_free = TRUE AND is_vegan = TRUE AND country = 'Australia' GROUP BY brand ORDER BY num_certified_products DESC LIMIT 3; |
Which states in the United States have the highest voter turnout? | CREATE TABLE states (id INT,name VARCHAR(255),voter_turnout INT); INSERT INTO states (id,name,voter_turnout) VALUES (1,'California',70),(2,'Texas',60),(3,'Minnesota',80); | SELECT name FROM states WHERE voter_turnout = (SELECT MAX(voter_turnout) FROM states); |
What is the count of clients with a financial wellbeing score greater than 70, in the Southeast region? | CREATE TABLE clients (id INT,name VARCHAR,region VARCHAR,financial_wellbeing_score INT); INSERT INTO clients (id,name,region,financial_wellbeing_score) VALUES (1,'Ahmed','Southeast',75),(2,'Fatima','Northeast',65),(3,'Zainab','Southeast',85),(4,'Hassan','Midwest',55); | SELECT COUNT(*) FROM clients WHERE region = 'Southeast' AND financial_wellbeing_score > 70; |
Delete the farm with ID 502 | CREATE TABLE farms (farm_id INT,name VARCHAR(50),location VARCHAR(50)); | DELETE FROM farms WHERE farm_id = 502; |
What is the average size of vessels that entered the Indian Ocean in 2020? | CREATE TABLE vessel_traffic (id INTEGER,vessel_size INTEGER,year INTEGER,location TEXT); INSERT INTO vessel_traffic (id,vessel_size,year,location) VALUES (1,150,2020,'Indian Ocean'),(2,250,2021,'Indian Ocean'),(3,350,2020,'Pacific Ocean'); | SELECT AVG(vessel_size) FROM vessel_traffic WHERE year = 2020 AND location = 'Indian Ocean'; |
What was the total number of volunteers who participated in community development programs in Egypt in 2018? | CREATE TABLE volunteers (volunteer_id INT,program_id INT,volunteer_name VARCHAR(255),country VARCHAR(255),volunteer_start_date DATE,volunteer_end_date DATE); INSERT INTO volunteers (volunteer_id,program_id,volunteer_name,country,volunteer_start_date,volunteer_end_date) VALUES (1,1,'Volunteer1','Egypt','2018-01-01','2018-12-31'),(2,2,'Volunteer2','Egypt','2018-01-01','2018-06-30'),(3,3,'Volunteer3','Egypt','2018-07-01','2018-12-31'); | SELECT COUNT(*) FROM volunteers WHERE country = 'Egypt' AND YEAR(volunteer_start_date) = 2018 AND YEAR(volunteer_end_date) = 2018; |
Calculate total attendance at all events | CREATE TABLE Events (id INT,name TEXT,city TEXT,attendance INT); INSERT INTO Events (id,name,city,attendance) VALUES (1,'Art Exhibition','New York',500),(2,'Theater Performance','Los Angeles',300),(3,'Music Concert','Chicago',700); | SELECT SUM(attendance) FROM Events; |
update the ticket sales records for a specific game | CREATE TABLE ticket_sales (id INT PRIMARY KEY,game_id INT,number_of_tickets INT,date DATE); | UPDATE ticket_sales SET number_of_tickets = 600 WHERE game_id = 123 AND date = '2022-05-01'; |
List all the parks and their respective agencies in the state of California from the 'parks_database' | CREATE TABLE agencies (id INT PRIMARY KEY,name VARCHAR(255),state VARCHAR(255));CREATE TABLE parks (id INT PRIMARY KEY,name VARCHAR(255),agency_id INT,FOREIGN KEY (agency_id) REFERENCES agencies(id)); INSERT INTO agencies (id,name,state) VALUES (1,'California Department of Parks and Recreation','California'); INSERT INTO agencies (id,name,state) VALUES (2,'National Park Service','California'); | SELECT parks.name as park_name, agencies.name as agency_name FROM parks INNER JOIN agencies ON parks.agency_id = agencies.id WHERE agencies.state = 'California'; |
What are the total items shipped between Egypt and Nigeria, excluding items shipped in June 2021? | CREATE TABLE Shipment (id INT,source_country VARCHAR(255),destination_country VARCHAR(255),items_quantity INT,shipment_date DATE); INSERT INTO Shipment (id,source_country,destination_country,items_quantity,shipment_date) VALUES (1,'Egypt','Nigeria',100,'2021-06-01'),(2,'Egypt','Nigeria',200,'2021-05-01'); | SELECT SUM(items_quantity) FROM Shipment WHERE (source_country = 'Egypt' AND destination_country = 'Nigeria') OR (source_country = 'Nigeria' AND destination_country = 'Egypt') AND shipment_date NOT BETWEEN '2021-06-01' AND '2021-06-30'; |
What are the top 5 manufacturers with the highest sales amounts in 2020? | CREATE TABLE drug_sales (id INT PRIMARY KEY,drug_name VARCHAR(50),manufacturer VARCHAR(50),sales_qty INT,sales_amount DECIMAL(10,2),sale_year INT); | SELECT manufacturer, SUM(sales_amount) as total_sales FROM drug_sales WHERE sale_year = 2020 GROUP BY manufacturer ORDER BY total_sales DESC LIMIT 5; |
How many space missions has NASA conducted? | CREATE TABLE missions (mission_id INT,name VARCHAR(100),agency VARCHAR(100),launch_date DATE); INSERT INTO missions (mission_id,name,agency,launch_date) VALUES (1,'Apollo 11','NASA','1969-07-16'),(2,'STS-1','NASA','1981-04-12'); | SELECT COUNT(*) FROM missions WHERE agency = 'NASA'; |
What is the average biosensor technology development cost for companies in the UK? | CREATE SCHEMA if not exists biosensors;CREATE TABLE biosensors.development_costs (id INT,company_name VARCHAR(50),country VARCHAR(50),development_cost DECIMAL(10,2));INSERT INTO biosensors.development_costs (id,company_name,country,development_cost) VALUES (1,'CompanyA','UK',5000000.00),(2,'CompanyB','Canada',3500000.00),(3,'CompanyC','USA',8000000.00); | SELECT AVG(development_cost) FROM biosensors.development_costs WHERE country = 'UK'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.