instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Update the seismic resistance score for a specific project | CREATE TABLE Resilience_Metrics (Metric_ID INT,Project_ID INT,Metric_Name VARCHAR(50),Score INT,Metric_Date DATE); INSERT INTO Resilience_Metrics (Metric_ID,Project_ID,Metric_Name,Score,Metric_Date) VALUES (1,1,'Seismic Resistance',8,'2021-03-01'); | UPDATE Resilience_Metrics SET Score = 9 WHERE Project_ID = 1 AND Metric_Name = 'Seismic Resistance'; |
What is the minimum labor productivity for each mine located in the USA? | CREATE TABLE mines (mine_id INT,name TEXT,location TEXT,productivity FLOAT); INSERT INTO mines (mine_id,name,location,productivity) VALUES (1,'ABC Mine','USA',1200),(2,'DEF Mine','USA',800); | SELECT location, MIN(productivity) FROM mines GROUP BY location; |
How many graduate students have published more than 5 papers in the Computer Science department? | CREATE TABLE graduate_students (id INT,name VARCHAR(50),department VARCHAR(50),num_papers INT); INSERT INTO graduate_students (id,name,department,num_papers) VALUES (1,'Charlie','Computer Science',4); INSERT INTO graduate_students (id,name,department,num_papers) VALUES (2,'David','Physics',6); | SELECT COUNT(*) FROM graduate_students WHERE department = 'Computer Science' AND num_papers > 5; |
Who is the top volunteer by total hours in H1 2021? | CREATE TABLE volunteers (id INT,name TEXT,hours INT); INSERT INTO volunteers (id,name,hours) VALUES (4,'David',125),(5,'Eva',150),(6,'Frank',200); | SELECT name FROM volunteers ORDER BY hours DESC LIMIT 1; |
Find the earliest age of a patient treated for a mental health condition | CREATE TABLE patients_treatments (patient_id INT,age INT,condition VARCHAR(20)); INSERT INTO patients_treatments (patient_id,age,condition) VALUES (1,20,'depression'); | SELECT MIN(age) FROM patients_treatments; |
Which country has the highest number of organic farms? | CREATE TABLE organic_farms (id INT,country TEXT,number_of_farms INT); INSERT INTO organic_farms (id,country,number_of_farms) VALUES (1,'United States',15000),(2,'Germany',12000),(3,'Australia',8000); | SELECT country, MAX(number_of_farms) FROM organic_farms; |
What is the total number of research grants awarded to each department in the past year? | CREATE TABLE graduate_students (student_id INT,name TEXT,gpa DECIMAL(3,2),department TEXT); CREATE TABLE research_grants (grant_id INT,student_id INT,amount DECIMAL(10,2),date DATE,department TEXT); | SELECT rg.department, SUM(rg.amount) FROM research_grants rg WHERE rg.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY rg.department; |
Which artists have conducted the most workshops by region? | CREATE TABLE ArtistWorkshops (id INT,artist_name VARCHAR(255),region VARCHAR(255),workshops INT); INSERT INTO ArtistWorkshops (id,artist_name,region,workshops) VALUES (1,'Artist A','North',5),(2,'Artist B','South',3),(3,'Artist C','North',7),(4,'Artist D','East',2); | SELECT region, artist_name, SUM(workshops) FROM ArtistWorkshops GROUP BY region, artist_name; |
What is the maximum number of mental health parity cases reported in the Northwest region in a single month? | CREATE TABLE MentalHealthParity (Id INT,Region VARCHAR(20),ReportDate DATE); INSERT INTO MentalHealthParity (Id,Region,ReportDate) VALUES (1,'Southwest','2020-01-01'),(2,'Northeast','2019-12-31'),(3,'Southwest','2020-06-15'),(4,'Northeast','2020-01-10'),(5,'Southwest','2020-06-15'),(6,'Northeast','2019-03-02'),(7,'Southwest','2020-02-20'),(8,'Northwest','2020-12-25'),(9,'Northwest','2020-02-28'),(10,'Northwest','2020-02-21'); | SELECT DATE_FORMAT(ReportDate, '%Y-%m') as Month, COUNT(*) as CountOfCases FROM MentalHealthParity WHERE Region = 'Northwest' GROUP BY Month ORDER BY CountOfCases DESC LIMIT 1; |
List the top 3 countries by fish stock in the past year, partitioned by species? | CREATE TABLE fish_stocks (id INT,species TEXT,country TEXT,year INT,stock_weight INT); INSERT INTO fish_stocks (id,species,country,year,stock_weight) VALUES (1,'Salmon','Norway',2021,150000),(2,'Salmon','Chile',2021,120000),(3,'Salmon','Norway',2020,140000),(4,'Tuna','Japan',2021,180000),(5,'Tuna','Philippines',2021,160000),(6,'Tuna','Japan',2020,170000); | SELECT species, country, SUM(stock_weight) stock_weight FROM fish_stocks WHERE year = 2021 GROUP BY species, country ORDER BY stock_weight DESC FETCH FIRST 3 ROWS ONLY; |
What is the total number of art pieces and artifacts in the 'ArtCollection' and 'AncientArtifacts' tables, excluding those that are on loan? | CREATE TABLE ArtCollection (id INT,name VARCHAR(50),on_loan BOOLEAN); CREATE TABLE AncientArtifacts (id INT,name VARCHAR(50),on_loan BOOLEAN); | SELECT COUNT(*) FROM ArtCollection WHERE on_loan = FALSE UNION SELECT COUNT(*) FROM AncientArtifacts WHERE on_loan = FALSE; |
Update the donation amount for donor_id 2 to $400.00 | CREATE TABLE Donations (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,country VARCHAR(50)); INSERT INTO Donations (donor_id,donation_amount,donation_date,country) VALUES (1,500.00,'2021-09-01','USA'),(2,300.00,'2021-07-15','Canada'),(3,700.00,'2021-10-20','Mexico'),(4,250.00,'2021-06-05','USA'),(5,600.00,'2021-08-30','Canada'); | UPDATE Donations SET donation_amount = 400.00 WHERE donor_id = 2; |
Show the total cost of all space missions in the SpaceMissions table. | CREATE TABLE SpaceMissions (id INT,name VARCHAR(50),cost INT,launch_date DATE); INSERT INTO SpaceMissions (id,name,cost,launch_date) VALUES (1,'Artemis I',24000000000,'2022-08-29'); INSERT INTO SpaceMissions (id,name,cost,launch_date) VALUES (2,'Artemis II',35000000000,'2024-11-01'); | SELECT SUM(cost) FROM SpaceMissions; |
What is the maximum impact measurement score for companies in the healthcare sector? | CREATE TABLE company_impact (id INT,name VARCHAR(255),sector VARCHAR(255),impact_measurement_score FLOAT); INSERT INTO company_impact (id,name,sector,impact_measurement_score) VALUES (1,'Johnson & Johnson','Healthcare',82.5),(2,'Pfizer','Healthcare',85.0),(3,'Medtronic','Healthcare',87.5); | SELECT MAX(impact_measurement_score) FROM company_impact WHERE sector = 'Healthcare'; |
Create a view named "grant_totals_by_department" that shows the total amount of research grants awarded to each department | CREATE TABLE departments (department_id INT,department_name VARCHAR(20)); INSERT INTO departments (department_id,department_name) VALUES (1,'Computer Science'),(2,'Mathematics'),(3,'Physics'); CREATE TABLE research_grants (grant_id INT,title VARCHAR(50),amount DECIMAL(10,2),principal_investigator VARCHAR(50),department_id INT,start_date DATE,end_date DATE); | CREATE VIEW grant_totals_by_department AS SELECT d.department_name, SUM(r.amount) AS total_amount FROM departments d LEFT JOIN research_grants r ON d.department_id = r.department_id GROUP BY d.department_name; |
List all unique biosensor technology patents filed by startups from India or China. | CREATE TABLE biosensor_patents (patent_name VARCHAR(255),filing_country VARCHAR(255),startup BOOLEAN); INSERT INTO biosensor_patents (patent_name,filing_country,startup) VALUES ('BioPatent1','India',TRUE); | SELECT DISTINCT patent_name FROM biosensor_patents WHERE filing_country IN ('India', 'China') AND startup = TRUE; |
Which countries have the most AI safety research institutions? | CREATE TABLE Institutions (institution TEXT,country TEXT); INSERT INTO Institutions VALUES ('Institution-A','USA'),('Institution-B','Canada'),('Institution-C','USA'),('Institution-D','Germany'); | SELECT country, COUNT(*) FROM Institutions GROUP BY country ORDER BY COUNT(*) DESC; |
Identify the previous port of call for each vessel. | CREATE TABLE PortCall (CallID INT,VesselID INT,PortID INT,CallDateTime DATETIME); INSERT INTO PortCall (CallID,VesselID,PortID,CallDateTime) VALUES (1,1,1,'2022-01-01 10:00:00'); INSERT INTO PortCall (CallID,VesselID,PortID,CallDateTime) VALUES (2,1,2,'2022-01-03 14:00:00'); | SELECT VesselID, PortID, LAG(PortID) OVER (PARTITION BY VesselID ORDER BY CallDateTime) as PreviousPort FROM PortCall; |
What is the total number of posts related to sports? | CREATE TABLE posts (id INT,user_id INT,content TEXT,category VARCHAR(50)); INSERT INTO posts (id,user_id,content,category) VALUES (1,1,'I love football','sports'),(2,1,'Basketball game tonight','sports'),(3,2,'Reading a book','literature'); | SELECT COUNT(*) FROM posts WHERE category = 'sports'; |
Which species has the highest population? | 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 species, MAX(population) FROM animal_population; |
How many parks were established in the last 3 years, and what are their names? | CREATE TABLE parks (id INT,name VARCHAR(255),establish_date DATE); INSERT INTO parks (id,name,establish_date) VALUES (1,'Park1','2020-01-01'),(2,'Park2','2019-07-15'),(3,'Park3','2017-03-04'); | SELECT name FROM parks WHERE establish_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) |
What is the total production of quinoa in agroecological farming in Latin America between 2017 and 2020? | CREATE TABLE Agroecological_Farming (Farm_ID INT,Crop VARCHAR(20),Production INT,Year INT,Continent VARCHAR(20)); INSERT INTO Agroecological_Farming (Farm_ID,Crop,Production,Year,Continent) VALUES (401,'Quinoa',1200,2017,'Latin America'),(402,'Quinoa',1500,2018,'Latin America'),(403,'Quinoa',1800,2019,'Latin America'),(404,'Quinoa',1000,2020,'Latin America'); | SELECT SUM(Production) FROM Agroecological_Farming WHERE Crop = 'Quinoa' AND Continent = 'Latin America' AND Year BETWEEN 2017 AND 2020; |
What is the average fare for each mode of transportation? | CREATE TABLE modes (mode_id INT,mode_name VARCHAR(255)); CREATE TABLE fares (fare_id INT,mode_id INT,fare_amount DECIMAL(5,2)); INSERT INTO modes VALUES (1,'Bus'); INSERT INTO modes VALUES (2,'Train'); INSERT INTO fares VALUES (1,1,2.50); INSERT INTO fares VALUES (2,1,3.00); INSERT INTO fares VALUES (3,2,1.75); | SELECT mode_name, AVG(fare_amount) as avg_fare FROM modes m JOIN fares f ON m.mode_id = f.mode_id GROUP BY m.mode_name; |
What is the average ticket price for each tier in the 'concert_ticket_prices' table? | CREATE TABLE concert_ticket_prices (tier_num INT,concert_name VARCHAR(255),tier_price INT); | SELECT tier_num, AVG(tier_price) as avg_price FROM concert_ticket_prices GROUP BY tier_num; |
What is the minimum quantity of vegetarian dishes sold in the Chicago region? | CREATE TABLE orders (item_id INT,quantity INT,order_date DATE); INSERT INTO orders (item_id,quantity,order_date) VALUES (1,20,'2021-01-01'),(2,30,'2021-01-02'); | SELECT MIN(quantity) FROM orders JOIN menu ON orders.item_id = menu.item_id WHERE menu.dish_type = 'vegetarian' AND menu.region = 'Chicago'; |
What is the total quantity of all items in warehouse 'CDG'? | CREATE TABLE inventory (item_code varchar(5),warehouse_id varchar(5),quantity int); INSERT INTO inventory (item_code,warehouse_id,quantity) VALUES ('B01','CDG',400),('B02','CDG',500),('B03','CDG',600); | SELECT SUM(quantity) FROM inventory WHERE warehouse_id = 'CDG'; |
What is the maximum donation amount in the year 2021? | CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL,DonationDate DATE); INSERT INTO Donors (DonorID,DonorName,DonationAmount,DonationDate) VALUES (1,'John Doe',50.00,'2021-01-01'); INSERT INTO Donors (DonorID,DonorName,DonationAmount,DonationDate) VALUES (2,'Jane Smith',200.00,'2021-05-15'); | SELECT MAX(DonationAmount) FROM Donors WHERE YEAR(DonationDate) = 2021; |
Find the average ESG score for each sector, only showing sectors with more than 2 investments. | CREATE TABLE investments(id INT,sector VARCHAR(20),esg_score INT); INSERT INTO investments VALUES(1,'Tech',85),(2,'Healthcare',75),(3,'Tech',82); | SELECT sector, AVG(esg_score) as avg_esg_score FROM investments GROUP BY sector HAVING COUNT(*) > 2; |
Update the number of followers for a user from Brazil | CREATE TABLE users (id INT,username VARCHAR(255),followers INT,country VARCHAR(255)); | UPDATE users SET followers = followers + 100 WHERE username = 'user_brazil' AND country = 'Brazil'; |
What is the total CO2 emissions for the landfill waste treatment method in the state of Texas? | CREATE TABLE waste_treatment_methods (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO waste_treatment_methods (id,name,state) VALUES (1,'Landfill','Texas'),(2,'Incineration','Texas'),(3,'Recycling','Texas'),(4,'Composting','Texas'); CREATE TABLE co2_emissions (treatment_method_id INT,emissions INT,state VARCHAR(255)); INSERT INTO co2_emissions (treatment_method_id,emissions,state) VALUES (1,100,'Texas'),(1,120,'Texas'),(2,80,'Texas'),(2,100,'Texas'),(3,60,'Texas'),(3,70,'Texas'); | SELECT wtm.name as treatment_method, SUM(ce.emissions) as total_emissions FROM waste_treatment_methods wtm JOIN co2_emissions ce ON wtm.id = ce.treatment_method_id WHERE wtm.name = 'Landfill' AND wtm.state = 'Texas' GROUP BY wtm.name; |
What is the average financial capability score for each occupation? | CREATE TABLE financial_capability_2 (occupation VARCHAR(255),score INT); INSERT INTO financial_capability_2 (occupation,score) VALUES ('Doctor',1400),('Engineer',1300),('Teacher',1200),('Lawyer',1500); | SELECT occupation, AVG(score) FROM financial_capability_2 GROUP BY occupation; |
What is the average salary of teachers in urban and rural areas? | CREATE TABLE schools (name VARCHAR(255),location VARCHAR(255),salary FLOAT); INSERT INTO schools (name,location,salary) VALUES ('School A','Urban',50000),('School B','Urban',55000),('School C','Rural',45000),('School D','Rural',40000); | SELECT s1.location, AVG(s1.salary) as avg_salary FROM schools s1 GROUP BY s1.location; |
Calculate the total revenue for each category from the sales table | CREATE TABLE sales (id INT,product_id INT,quantity INT,price DECIMAL(5,2),country VARCHAR(50)); | SELECT category, SUM(quantity * price) as total_revenue FROM sales JOIN garments ON sales.product_id = garments.id GROUP BY category; |
What is the average response time for police departments in each city in the state of New York? | CREATE TABLE police_department (id INT,city VARCHAR(255),response_time INT); | SELECT city, AVG(response_time) as avg_response_time FROM police_department GROUP BY city; |
What is the average daily step count for all members with a Platinum membership? | CREATE TABLE Members (MemberID INT,Name VARCHAR(50),Age INT,Membership VARCHAR(20)); CREATE TABLE Steps (StepID INT,MemberID INT,Steps INT,Date DATE); INSERT INTO Members (MemberID,Name,Age,Membership) VALUES (1,'John Doe',35,'Platinum'),(2,'Jane Smith',28,'Gold'); INSERT INTO Steps (StepID,MemberID,Steps,Date) VALUES (1,1,8000,'2022-01-01'),(2,1,7000,'2022-01-02'),(3,1,9000,'2022-01-03'),(4,2,6000,'2022-01-01'),(5,2,6500,'2022-01-02'),(6,2,7000,'2022-01-03'); | SELECT AVG(Steps) FROM Members JOIN Steps ON Members.MemberID = Steps.MemberID WHERE Membership = 'Platinum'; |
What is the sum of labor productivity for each mine located in Canada? | CREATE TABLE mines (mine_id INT,name TEXT,location TEXT,productivity FLOAT); INSERT INTO mines (mine_id,name,location,productivity) VALUES (1,'ABC Mine','USA',1200),(2,'DEF Mine','Canada',1500); | SELECT location, SUM(productivity) FROM mines GROUP BY location; |
What is the total amount donated by organizations with more than 100 employees in South Africa, in the year 2019? | CREATE TABLE organizations (org_id int,num_employees int,country varchar(50),donation_date date); INSERT INTO organizations (org_id,num_employees,country,donation_date) VALUES (1,200,'South Africa','2019-01-01'),(2,50,'South Africa','2019-02-01'),(3,150,'South Africa','2019-03-01'); | SELECT SUM(donation_amount) FROM donations INNER JOIN organizations ON donations.org_id = organizations.org_id WHERE organizations.country = 'South Africa' AND YEAR(donation_date) = 2019 GROUP BY organizations.org_id HAVING num_employees > 100; |
What is the total weight of vessels for each type, and the average length of vessels for each type? | CREATE TABLE VesselTypes (id INT PRIMARY KEY,type VARCHAR(255),max_weight INT,max_length FLOAT); CREATE TABLE Vessels (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),length FLOAT,weight INT); | SELECT vt.type, SUM(v.weight) as total_weight, AVG(v.length) as avg_length FROM Vessels v INNER JOIN VesselTypes vt ON v.type = vt.type GROUP BY vt.type; |
Delete all records from the equipment table that have a name starting with 'Obsolete' | CREATE TABLE equipment (id INT,name VARCHAR(50)); | DELETE FROM equipment WHERE name LIKE 'Obsolete%'; |
What are the top 3 clinical trials by expenditure in the cardiovascular therapeutic area? | CREATE TABLE clinical_trial (id INT,trial_name VARCHAR(255),therapeutic_area VARCHAR(255),expenditure DECIMAL(10,2)); INSERT INTO clinical_trial (id,trial_name,therapeutic_area,expenditure) VALUES (1,'Trial1','Cardiovascular',1000000.00),(2,'Trial2','Oncology',1200000.00),(3,'Trial3','Cardiovascular',1500000.00),(4,'Trial4','Neurology',800000.00),(5,'Trial5','Cardiovascular',2000000.00); | SELECT * FROM clinical_trial WHERE therapeutic_area = 'Cardiovascular' ORDER BY expenditure DESC LIMIT 3; |
What is the total number of streams for hip hop artists in the United States? | CREATE TABLE Artists (ArtistID int,ArtistName varchar(100),Genre varchar(50),Country varchar(50)); INSERT INTO Artists (ArtistID,ArtistName,Genre,Country) VALUES (1,'Eminem','Hip Hop','United States'),(2,'B.B. King','Blues','United States'),(3,'Taylor Swift','Pop','United States'); CREATE TABLE StreamingData (StreamDate date,ArtistID int,Streams int); INSERT INTO StreamingData (StreamDate,ArtistID,Streams) VALUES ('2022-01-01',1,10000),('2022-01-02',2,8000),('2022-01-03',3,9000),('2022-01-04',1,11000); | SELECT SUM(Streams) as TotalStreams FROM Artists JOIN StreamingData ON Artists.ArtistID = StreamingData.ArtistID WHERE Artists.Genre = 'Hip Hop' AND Artists.Country = 'United States'; |
What is the total number of hospitals by state? | CREATE TABLE hospitals (id INT,name TEXT,city TEXT,state TEXT,beds INT); INSERT INTO hospitals (id,name,city,state,beds) VALUES (1,'General Hospital','Miami','Florida',500); INSERT INTO hospitals (id,name,city,state,beds) VALUES (2,'Memorial Hospital','Boston','Massachusetts',600); | SELECT state, COUNT(*) as total_hospitals FROM hospitals GROUP BY state; |
Update the ticket prices for all salespeople in New York by 10%. | CREATE TABLE salesperson (id INT,name VARCHAR(50),city VARCHAR(50)); CREATE TABLE tickets (id INT,salesperson_id INT,quantity INT,city VARCHAR(50),price DECIMAL(5,2)); INSERT INTO salesperson (id,name,city) VALUES (1,'John Doe','New York'),(2,'Jane Smith','Los Angeles'); INSERT INTO tickets (id,salesperson_id,quantity,city,price) VALUES (1,1,50,'New York',100.00),(2,1,75,'New York',100.00),(3,2,30,'Los Angeles',75.00),(4,2,40,'Los Angeles',75.00); | UPDATE tickets t SET price = t.price * 1.10 WHERE t.city = 'New York'; |
Update the "contract_address" field to "0x2234567890123456789012345678901234567890" for the record with "contract_type" as "ERC721" in the "smart_contracts" table | CREATE TABLE smart_contracts (contract_address VARCHAR(42),contract_type VARCHAR(10),country VARCHAR(2)); INSERT INTO smart_contracts (contract_address,contract_type,country) VALUES ('0x1234567890123456789012345678901234567890','ERC721','US'); | UPDATE smart_contracts SET contract_address = '0x2234567890123456789012345678901234567890' WHERE contract_type = 'ERC721'; |
What's the total number of employees for each mining site? | CREATE TABLE mining_sites (id INT,site_name VARCHAR(255)); INSERT INTO mining_sites (id,site_name) VALUES (1,'Site A'),(2,'Site B'),(3,'Site C'); CREATE TABLE employees (id INT,site_id INT,first_name VARCHAR(255),last_name VARCHAR(255)); INSERT INTO employees (id,site_id,first_name,last_name) VALUES (1,1,'John','Doe'),(2,1,'Jane','Smith'),(3,2,'Mike','Johnson'),(4,3,'Sara','Lee'); | SELECT s.site_name, COUNT(e.id) as total_employees FROM mining_sites s INNER JOIN employees e ON s.id = e.site_id GROUP BY s.site_name; |
What is the count of vessels for each fuel type? | CREATE TABLE vessels (id INT,name VARCHAR(20),fuel_type VARCHAR(20)); INSERT INTO vessels (id,name,fuel_type) VALUES (1,'VesselA','Diesel'),(2,'VesselB','LNG'),(3,'VesselC','Diesel'),(4,'VesselD','Hybrid'); | SELECT fuel_type, COUNT(*) FROM vessels GROUP BY fuel_type; |
What is the total water consumption by each city in the state of California? | CREATE TABLE cities (city_id INT,city_name VARCHAR(255),state VARCHAR(255)); INSERT INTO cities (city_id,city_name,state) VALUES (1,'Sacramento','California'),(2,'San Diego','California'); CREATE TABLE water_usage (usage_id INT,city_id INT,water_consumption INT); INSERT INTO water_usage (usage_id,city_id,water_consumption) VALUES (1,1,50000),(2,2,70000); | SELECT c.city_name, SUM(w.water_consumption) FROM cities c INNER JOIN water_usage w ON c.city_id = w.city_id WHERE c.state = 'California' GROUP BY c.city_name; |
What is the minimum fare of ride-sharing services in Rome? | CREATE TABLE ride_sharing (service_id INT,fare FLOAT,city VARCHAR(50)); | SELECT MIN(fare) FROM ride_sharing WHERE city = 'Rome'; |
What is the minimum number of flight hours per pilot per year? | CREATE TABLE Flight_Hours (ID INT,Year INT,Pilot VARCHAR(50),Flight_Hours INT); INSERT INTO Flight_Hours (ID,Year,Pilot,Flight_Hours) VALUES (1,2015,'John Doe',1000),(2,2015,'Jane Smith',1200),(3,2016,'John Doe',1100),(4,2016,'Jane Smith',1300),(5,2017,'John Doe',1200),(6,2017,'Jane Smith',1400); | SELECT Pilot, MIN(Flight_Hours) FROM Flight_Hours GROUP BY Pilot; |
Which destinations have the least hotel awards in Spain? | CREATE TABLE Destinations (destination_id INT,destination_name TEXT,country TEXT,awards INT); INSERT INTO Destinations (destination_id,destination_name,country,awards) VALUES (1,'City A','Germany',3),(2,'City B','Switzerland',5),(3,'City C','France',2); | SELECT destination_name, country, awards, RANK() OVER (PARTITION BY country ORDER BY awards ASC) AS rank FROM Destinations WHERE country = 'Spain'; |
What is the total number of military personnel in 'North America' and 'South America'? | CREATE TABLE MilitaryPersonnel (ID INT,BaseName VARCHAR(50),Country VARCHAR(50),Personnel INT); INSERT INTO MilitaryPersonnel (ID,BaseName,Country,Personnel) VALUES (1,'Base1','North America',500); INSERT INTO MilitaryPersonnel (ID,BaseName,Country,Personnel) VALUES (2,'Base2','South America',700); | SELECT SUM(Personnel) FROM MilitaryPersonnel WHERE Country IN ('North America', 'South America'); |
Which vessels have transported the most cargo in the past 6 months? | CREATE TABLE vessel (id INT,name VARCHAR(50));CREATE TABLE cargo (id INT,vessel_id INT,weight INT,cargo_date DATE); | SELECT v.name, SUM(c.weight) as total_weight FROM vessel v JOIN cargo c ON v.id = c.vessel_id WHERE c.cargo_date >= DATE(NOW(), INTERVAL -6 MONTH) GROUP BY v.name ORDER BY total_weight DESC; |
What is the maximum ticket price for an event at the Louvre Museum? | CREATE TABLE Events (id INT,museum VARCHAR(30),price DECIMAL(5,2)); INSERT INTO Events (id,museum,price) VALUES (1,'Louvre Museum',50.00),(2,'British Museum',40.00),(3,'Louvre Museum',60.00); | SELECT MAX(price) FROM Events WHERE museum = 'Louvre Museum'; |
Show the total number of citations for all publications by graduate students in the Physics department. | CREATE TABLE GraduateStudents(StudentID INT,Department VARCHAR(255)); INSERT INTO GraduateStudents VALUES (1,'Physics'); CREATE TABLE Publications(PublicationID INT,StudentID INT,Citations INT); INSERT INTO Publications VALUES (1,1,50); | SELECT SUM(Publications.Citations) FROM GraduateStudents INNER JOIN Publications ON GraduateStudents.StudentID = Publications.StudentID WHERE GraduateStudents.Department = 'Physics'; |
What is the policy type and coverage amount for policies with the lowest coverage amount? | CREATE TABLE policies (policy_number INT,policy_type VARCHAR(50),coverage_amount INT,state VARCHAR(2)); INSERT INTO policies (policy_number,policy_type,coverage_amount,state) VALUES (12345,'Auto',50000,'TX'); INSERT INTO policies (policy_number,policy_type,coverage_amount,state) VALUES (67890,'Home',300000,'CA'); INSERT INTO policies (policy_number,policy_type,coverage_amount,state) VALUES (111213,'Umbrella',1000000,'CA'); | SELECT policy_type, coverage_amount FROM policies WHERE coverage_amount = (SELECT MIN(coverage_amount) FROM policies); |
What is the total number of employees in the renewable energy sector by region? | CREATE TABLE RenewableEnergy (EmployeeID INT,Company VARCHAR(50),Region VARCHAR(50),Sector VARCHAR(50)); INSERT INTO RenewableEnergy (EmployeeID,Company,Region,Sector) VALUES (1,'Company A','North America','Renewable Energy'),(2,'Company B','South America','Renewable Energy'),(3,'Company C','Europe','Renewable Energy'); | SELECT Region, COUNT(*) as TotalEmployees FROM RenewableEnergy WHERE Sector = 'Renewable Energy' GROUP BY Region; |
List the number of tours offered in each country from the 'tours' table | CREATE TABLE tours (tour_id INT,tour_name VARCHAR(50),country VARCHAR(50),tour_count INT); | SELECT country, SUM(tour_count) as total_tours FROM tours GROUP BY country; |
Which organizations received donations from donors located in a specific city, based on the 'donations', 'donors', and 'organizations' tables? | CREATE TABLE organizations (id INT,organization_name TEXT,organization_city TEXT);CREATE TABLE donors (id INT,name TEXT,email TEXT,donor_city TEXT);CREATE TABLE donations (id INT,donor_id INT,organization_id INT,amount DECIMAL(10,2),donation_date DATE); | SELECT organizations.organization_name FROM organizations INNER JOIN donations ON organizations.id = donations.organization_id INNER JOIN donors ON donations.donor_id = donors.id WHERE donors.donor_city = 'San Francisco'; |
Insert new sales records for NY dispensaries in August 2022 with random quantities between 10 and 50? | CREATE TABLE sales (id INT,dispensary_id INT,quantity INT,month TEXT,year INT); INSERT INTO sales (id,dispensary_id,quantity,month,year) VALUES (1,1,25,'August',2022),(2,2,30,'August',2022); CREATE TABLE dispensaries (id INT,name TEXT,state TEXT); INSERT INTO dispensaries (id,name,state) VALUES (1,'Dispensary A','New York'),(2,'Dispensary B','New York'); | INSERT INTO sales (dispensary_id, quantity, month, year) SELECT d.id, FLOOR(RAND() * 41 + 10), 'August', 2022 FROM dispensaries d WHERE d.state = 'New York' AND NOT EXISTS (SELECT 1 FROM sales s WHERE s.dispensary_id = d.id AND s.month = 'August' AND s.year = 2022); |
Identify the top three states with the highest percentage of mental health parity coverage. | CREATE TABLE MentalHealthParity (State VARCHAR(20),Coverage DECIMAL(5,2)); INSERT INTO MentalHealthParity (State,Coverage) VALUES ('California',0.75),('Texas',0.82),('New York',0.91),('Florida',0.68),('Illinois',0.77); | SELECT State, Coverage, RANK() OVER(ORDER BY Coverage DESC) as rnk FROM MentalHealthParity WHERE rnk <= 3; |
How many stations are on each train route in London? | CREATE TABLE train_routes (route_id INT,city VARCHAR(50),num_stations INT); INSERT INTO train_routes (route_id,city,num_stations) VALUES (101,'London',10),(102,'London',8),(103,'London',12),(104,'London',14); | SELECT route_id, city, num_stations FROM train_routes WHERE city = 'London'; |
List all the unique satellite names from the Satellite_Table. | CREATE TABLE Satellite_Table (id INT,satellite_name VARCHAR(100),country_launched VARCHAR(50)); | SELECT DISTINCT SATELLITE_NAME FROM Satellite_Table; |
Identify the job titles with the lowest average salaries | CREATE TABLE Employees (id INT,job_title VARCHAR(50),salary DECIMAL(10,2)); CREATE TABLE Departments (id INT,employee_id INT,department_name VARCHAR(50)); | SELECT job_title, AVG(salary) AS avg_salary FROM Employees JOIN Departments ON Employees.id = Departments.employee_id GROUP BY job_title ORDER BY avg_salary ASC LIMIT 5; |
How many exhibitions featured more than 50 artworks by artists from Egypt? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name VARCHAR(255),Nationality VARCHAR(255)); CREATE TABLE Artworks (ArtworkID INT PRIMARY KEY,Title VARCHAR(255),ArtistID INT,Year INT); CREATE TABLE Exhibitions (ExhibitionID INT PRIMARY KEY,Name VARCHAR(255),StartDate DATE,EndDate DATE,ArtworkCount INT); CREATE TABLE ExhibitionArtworks (ExhibitionID INT,ArtworkID INT); | SELECT COUNT(Exhibitions.ExhibitionID) AS ExhibitionCount FROM Exhibitions INNER JOIN (SELECT ExhibitionID FROM ExhibitionArtworks GROUP BY ExhibitionID HAVING COUNT(*) > 50) AS Subquery ON Exhibitions.ExhibitionID = Subquery.ExhibitionID INNER JOIN Artists ON Exhibitions.ArtistID = Artists.ArtistID WHERE Artists.Nationality = 'Egyptian'; |
What is the average response time for emergency calls by district? | CREATE TABLE districts (did INT,district_name VARCHAR(255)); CREATE TABLE emergencies (eid INT,did INT,response_time INT); | SELECT d.district_name, AVG(e.response_time) FROM districts d INNER JOIN emergencies e ON d.did = e.did GROUP BY d.district_name; |
List all the articles published by 'Al Jazeera' that are not related to sports. | CREATE TABLE al_jazeera (article_id INT,title TEXT,content TEXT,publisher TEXT); INSERT INTO al_jazeera (article_id,title,content,publisher) VALUES (1,'Article 1','Sports content','Al Jazeera'),(2,'Article 2','Politics content','Al Jazeera'); | SELECT * FROM al_jazeera WHERE content NOT LIKE '%sports%'; |
Determine the number of customers who have an account balance greater than the median balance for all accounts. | CREATE TABLE accounts (customer_id INT,account_type VARCHAR(20),balance DECIMAL(10,2)); | SELECT COUNT(DISTINCT customer_id) FROM accounts WHERE balance > PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY balance) OVER (); |
What is the minimum production quantity of Sativa strains in Nevada in 2021? | CREATE TABLE strains (id INT,name VARCHAR(255),type VARCHAR(255)); CREATE TABLE production (id INT,strain_id INT,year INT,quantity INT); INSERT INTO strains (id,name,type) VALUES (1,'Strawberry Cough','Sativa'); INSERT INTO production (id,strain_id,year,quantity) VALUES (1,1,2021,1000); | SELECT MIN(production.quantity) FROM production JOIN strains ON production.strain_id = strains.id WHERE strains.type = 'Sativa' AND production.year = 2021; |
Add a record for the 'Houston Toad' to the Amphibians table. | CREATE TABLE Amphibians (id INT,name VARCHAR(255),population INT,status VARCHAR(255)); | INSERT INTO Amphibians (id, name, population, status) VALUES (4, 'Houston Toad', 150, 'Vulnerable'); |
What is the total distance traveled by electric trains in Seoul during the morning commute? | CREATE TABLE electric_trains (train_id INT,route_id INT,departure_time TIMESTAMP,arrival_time TIMESTAMP,distance FLOAT); INSERT INTO electric_trains (train_id,route_id,departure_time,arrival_time,distance) VALUES (1,301,'2022-01-01 06:00:00','2022-01-01 07:00:00',40.0),(2,302,'2022-01-01 06:15:00','2022-01-01 07:15:00',45.0); | SELECT SUM(distance) AS total_distance FROM electric_trains WHERE EXTRACT(HOUR FROM departure_time) BETWEEN 6 AND 8 AND route_id IN (301, 302, 303, 304) |
What is the average daily plastic waste generation in kilograms by each city? | CREATE TABLE Cities (id INT,city_name VARCHAR(255)); INSERT INTO Cities (id,city_name) VALUES (1,'CityA'),(2,'CityB'); CREATE TABLE WasteData (city_id INT,waste_type VARCHAR(50),waste_generation INT,date DATE); INSERT INTO WasteData (city_id,waste_type,waste_generation,date) VALUES (1,'plastic',120,'2021-01-01'),(1,'plastic',150,'2021-01-02'),(2,'plastic',80,'2021-01-01'),(2,'plastic',100,'2021-01-02'); | SELECT Cities.city_name, AVG(WasteData.waste_generation / 1000.0) FROM Cities INNER JOIN WasteData ON Cities.id = WasteData.city_id AND WasteData.waste_type = 'plastic' GROUP BY Cities.city_name; |
List the number of athletes enrolled in each program and the average age of athletes in the 'wellbeing' program, grouped by gender. | CREATE TABLE athletes (athlete_id INT,name VARCHAR(255),age INT,program VARCHAR(255),gender VARCHAR(255)); INSERT INTO athletes (athlete_id,name,age,program,gender) VALUES (1,'John Doe',25,'Wellbeing','Male'),(2,'Jane Smith',30,'Fitness','Female'),(3,'Alice Johnson',35,'Wellbeing','Female'),(4,'Bob Brown',40,'Fitness','Male'),(5,'Charlie Davis',45,'Fitness','Male'),(6,'Diana White',50,'Fitness','Female'),(7,'Eva Green',55,'Wellbeing','Female'); | SELECT program, gender, COUNT(*), AVG(age) FROM athletes WHERE program = 'Wellbeing' GROUP BY program, gender; |
What is the average playtime for each genre in the 'gaming' database? | CREATE TABLE playtimes_genres (user_id INT,game_id INT,playtime FLOAT,genre VARCHAR(50)); INSERT INTO playtimes_genres (user_id,game_id,playtime,genre) VALUES (1,3,60,'Strategy'),(2,3,90,'Strategy'),(3,3,75,'Strategy'),(4,3,80,'Strategy'),(5,3,70,'Strategy'),(1,1,30,'Action'),(2,1,45,'Action'),(3,2,60,'Adventure'),(4,2,75,'Adventure'),(5,2,90,'Adventure'); | SELECT genre, AVG(playtime) as avg_playtime FROM playtimes_genres GROUP BY genre; |
What is the maximum temperature recorded in 'field4' for each day in the last month? | CREATE TABLE field4 (date DATE,temperature FLOAT); INSERT INTO field4 (date,temperature) VALUES ('2021-10-01',18.2),('2021-10-02',20.1),('2021-10-03',19.3); | SELECT date, MAX(temperature) FROM field4 WHERE date >= (CURRENT_DATE - INTERVAL '30 days') GROUP BY date; |
Identify customers with both 'Homeowners' and 'Car' policies in the United States. | CREATE TABLE Policy (PolicyID INT,PolicyType VARCHAR(20),CustomerID INT,Country VARCHAR(20)); INSERT INTO Policy (PolicyID,PolicyType,CustomerID,Country) VALUES (1,'Homeowners',101,'USA'),(2,'Auto',101,'USA'),(3,'Renters',102,'USA'),(4,'Car',103,'USA'),(5,'Homeowners',104,'USA'); | SELECT Policy.CustomerID FROM Policy INNER JOIN Policy AS P2 ON Policy.CustomerID = P2.CustomerID WHERE Policy.PolicyType = 'Homeowners' AND P2.PolicyType = 'Car' AND Policy.Country = 'USA'; |
List the top 3 most energy efficient states in terms of solar power (kWh/m2/day)? | CREATE TABLE solar_projects (project_id INT,project_name TEXT,state TEXT,efficiency_kwh FLOAT); INSERT INTO solar_projects (project_id,project_name,state,efficiency_kwh) VALUES (1,'Solar Farm 1','California',0.18),(2,'Solar Farm 2','Nevada',0.20),(3,'Solar Farm 3','Arizona',0.19); | SELECT state, AVG(efficiency_kwh) as avg_efficiency FROM solar_projects GROUP BY state ORDER BY avg_efficiency DESC LIMIT 3; |
What is the total number of security incidents resolved by each member of the security team in the past year? | CREATE TABLE security_team (id INT,member VARCHAR(255),incidents_resolved INT,incident_at DATETIME); CREATE VIEW incident_view AS SELECT member,SUM(incidents_resolved) as incidents_resolved FROM security_team GROUP BY member; | SELECT member, incidents_resolved FROM incident_view WHERE incident_at >= DATE_SUB(NOW(), INTERVAL 1 YEAR); |
What is the average funding for biotech startups in New York? | CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT,name TEXT,location TEXT,funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','New York',6000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (2,'StartupB','California',7000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (3,'StartupC','New York',5000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (4,'StartupD','California',8000000.00); | SELECT AVG(funding) FROM biotech.startups WHERE location = 'New York'; |
List the top 3 most vulnerable software products by the number of high severity vulnerabilities. | CREATE TABLE software (id INT,name VARCHAR(255)); INSERT INTO software (id,name) VALUES (1,'Product A'),(2,'Product B'),(3,'Product C'); CREATE TABLE vulnerabilities (id INT,software_id INT,severity VARCHAR(255)); INSERT INTO vulnerabilities (id,software_id,severity) VALUES (1,1,'High'),(2,1,'Medium'),(3,2,'High'),(4,2,'Low'),(5,3,'Medium'); | SELECT software.name, COUNT(vulnerabilities.id) as high_severity_vulnerabilities FROM software LEFT JOIN vulnerabilities ON software.id = vulnerabilities.software_id WHERE vulnerabilities.severity = 'High' GROUP BY software.name ORDER BY high_severity_vulnerabilities DESC LIMIT 3; |
What is the total budget spent on climate mitigation projects in '2019' from the 'mitigation_projects' table? | CREATE TABLE mitigation_projects (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),description TEXT,start_date DATE,end_date DATE,budget FLOAT); INSERT INTO mitigation_projects (id,name,location,description,start_date,end_date,budget) VALUES (1,'Solar Farm Installation','California','Installation of solar panels','2018-01-01','2019-12-31',10000000); | SELECT SUM(budget) FROM mitigation_projects WHERE start_date <= '2019-12-31' AND end_date >= '2019-01-01'; |
What is the total revenue generated from organic hair care products in Canada in H1 of 2022? | CREATE TABLE products (id INT,product_name VARCHAR(50),category VARCHAR(50),is_organic BOOLEAN,price DECIMAL(5,2)); INSERT INTO products (id,product_name,category,is_organic,price) VALUES (1,'Shampoo','Hair Care',true,12.99),(2,'Conditioner','Hair Care',false,14.50),(3,'Styling Gel','Hair Care',false,8.99); CREATE TABLE sales (id INT,product_id INT,quantity INT,sale_date DATE,country VARCHAR(50)); INSERT INTO sales (id,product_id,quantity,sale_date,country) VALUES (1,1,200,'2022-03-15','Canada'),(2,2,150,'2022-06-10','Canada'),(3,3,300,'2022-02-22','USA'); | SELECT SUM(price * quantity) FROM products JOIN sales ON products.id = sales.product_id WHERE products.category = 'Hair Care' AND products.is_organic = true AND sales.country = 'Canada' AND sales.sale_date BETWEEN '2022-01-01' AND '2022-06-30'; |
What is the average bioprocess engineering project duration for projects led by Dr. Patel? | CREATE TABLE bioprocess_engineering (id INT,project_name VARCHAR(100),lead_engineer VARCHAR(100),duration INT); | SELECT AVG(duration) FROM bioprocess_engineering WHERE lead_engineer = 'Dr. Patel'; |
What is the maximum transaction amount for 'BTC'? | CREATE TABLE digital_assets (asset_id varchar(10),asset_name varchar(10)); INSERT INTO digital_assets (asset_id,asset_name) VALUES ('ETH','Ethereum'),('BTC','Bitcoin'); CREATE TABLE transactions (transaction_id serial,asset_id varchar(10),transaction_amount numeric); INSERT INTO transactions (asset_id,transaction_amount) VALUES ('ETH',120),('ETH',230),('BTC',500),('ETH',100); | SELECT MAX(transaction_amount) FROM transactions WHERE asset_id = 'BTC'; |
Present the number of heritage sites and community engagement events in each city. | CREATE TABLE CityData (City VARCHAR(20),HeritageSites INT,CommunityEvents INT); INSERT INTO CityData VALUES ('Seattle',1,2),('Portland',0,1); CREATE VIEW HeritageSiteCount AS SELECT City,COUNT(*) AS HeritageSites FROM HeritageSites GROUP BY City; CREATE VIEW CommunityEventCount AS SELECT City,COUNT(*) AS CommunityEvents FROM CityEngagement GROUP BY City; | SELECT d.City, h.HeritageSites, e.CommunityEvents FROM CityData d JOIN HeritageSiteCount h ON d.City = h.City JOIN CommunityEventCount e ON d.City = e.City; |
What is the average quantity of products sold in the European market per month? | CREATE TABLE sales (sale_id INT,product_id INT,quantity INT,price DECIMAL(5,2),sale_date DATE); CREATE TABLE products (product_id INT,material VARCHAR(20),market VARCHAR(20)); INSERT INTO sales (sale_id,product_id,quantity,price,sale_date) VALUES (1,1,10,25.00,'2022-01-01'),(2,2,5,10.00,'2022-01-05'),(3,3,8,30.00,'2022-01-10'),(4,1,15,25.00,'2022-02-01'),(5,2,8,10.00,'2022-02-05'),(6,3,12,30.00,'2022-02-10'); INSERT INTO products (product_id,material,market) VALUES (1,'organic cotton','Europe'),(2,'polyester','Asia'),(3,'recycled cotton','Europe'); | SELECT AVG(quantity) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.market = 'Europe' GROUP BY EXTRACT(MONTH FROM sale_date); |
What is the average age of patients with bipolar disorder who have not received any therapy in mental health clinics located in Florida? | CREATE TABLE clinics (clinic_id INT,clinic_name VARCHAR(50),city VARCHAR(50),state VARCHAR(50)); INSERT INTO clinics (clinic_id,clinic_name,city,state) VALUES (1,'ClinicE','Miami','FL'),(2,'ClinicF','Tampa','FL'); CREATE TABLE patients (patient_id INT,patient_name VARCHAR(50),age INT,clinic_id INT,condition_id INT); INSERT INTO patients (patient_id,patient_name,age,clinic_id,condition_id) VALUES (1,'James Doe',35,1,3),(2,'Jasmine Smith',28,1,1),(3,'Alice Johnson',42,2,2); CREATE TABLE conditions (condition_id INT,condition_name VARCHAR(50)); INSERT INTO conditions (condition_id,condition_name) VALUES (1,'Depression'),(2,'Anxiety Disorder'),(3,'Bipolar Disorder'); CREATE TABLE therapies (therapy_id INT,therapy_name VARCHAR(50),patient_id INT); INSERT INTO therapies (therapy_id,therapy_name,patient_id) VALUES (1,'CBT',1),(2,'DBT',2); | SELECT AVG(age) FROM patients p JOIN clinics c ON p.clinic_id = c.clinic_id LEFT JOIN therapies t ON p.patient_id = t.patient_id JOIN conditions cond ON p.condition_id = cond.condition_id WHERE c.state = 'FL' AND cond.condition_name = 'Bipolar Disorder' AND t.therapy_id IS NULL; |
Display ingredient sourcing information for all organic ingredients. | CREATE TABLE ingredient_sourcing (ingredient_id INT,ingredient_name VARCHAR(100),sourcing_country VARCHAR(50),is_organic BOOLEAN); INSERT INTO ingredient_sourcing (ingredient_id,ingredient_name,sourcing_country,is_organic) VALUES (1,'Rosehip Oil','Chile',TRUE),(2,'Shea Butter','Ghana',TRUE),(3,'Jojoba Oil','Argentina',TRUE),(4,'Coconut Oil','Philippines',FALSE),(5,'Aloe Vera','Mexico',TRUE); | SELECT * FROM ingredient_sourcing WHERE is_organic = TRUE; |
List all unique shipping methods used in the reverse logistics process, along with the number of times each method was used. | CREATE TABLE reverse_logistics (id INT,shipping_method VARCHAR(20),quantity INT); INSERT INTO reverse_logistics (id,shipping_method,quantity) VALUES (1,'Return Shipping',50),(2,'Exchange Shipping',30),(3,'Repair Shipping',40),(4,'Return Shipping',60),(5,'Exchange Shipping',20); | SELECT shipping_method, COUNT(*) FROM reverse_logistics GROUP BY shipping_method; |
Delete a mental health record from the 'MentalHealth' table | CREATE TABLE MentalHealth (StudentID int,Date date,MentalHealthScore int); | DELETE FROM MentalHealth WHERE StudentID = 1234 AND Date = '2022-09-01'; |
What is the rank of each state in terms of wastewater treatment efficiency? | CREATE TABLE wastewater_treatment (state_name TEXT,efficiency FLOAT); INSERT INTO wastewater_treatment (state_name,efficiency) VALUES ('California',0.85),('Texas',0.83),('Florida',0.88),('New York',0.82),('Pennsylvania',0.87); | SELECT state_name, RANK() OVER (ORDER BY efficiency DESC) AS rank FROM wastewater_treatment; |
What is the number of articles published per day in the 'Entertainment' category? | CREATE TABLE articles_by_day (day DATE,category TEXT,article_count INT); INSERT INTO articles_by_day (day,category,article_count) VALUES ('2022-01-01','Entertainment',3),('2022-01-02','Sports',2),('2022-01-01','Entertainment',1); | SELECT day, category, SUM(article_count) as total FROM articles_by_day WHERE category = 'Entertainment' GROUP BY day; |
What is the average severity of vulnerabilities for each software product in the last month? | CREATE TABLE vulnerabilities (id INT,product VARCHAR(50),severity INT,last_patch DATE); | SELECT product, AVG(severity) as avg_severity FROM vulnerabilities WHERE last_patch < DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY product; |
What is the average time to detect and respond to security incidents? | CREATE TABLE incidents (incident_id INT,detected_at TIMESTAMP,responded_at TIMESTAMP); | AVG(TIMESTAMPDIFF(MINUTE, detected_at, responded_at)) as avg_time_to_respond |
What is the total amount of resources produced by each region? | CREATE TABLE regions (id INT,mine VARCHAR(50),region VARCHAR(50),resource VARCHAR(50),quantity INT); INSERT INTO regions (id,mine,region,resource,quantity) VALUES (1,'Mine A','West','Coal',1000),(2,'Mine B','East','Iron Ore',2000),(3,'Mine A','West','Iron Ore',1500); | SELECT region, resource, SUM(quantity) AS total_quantity FROM regions GROUP BY region, resource; |
Find the total production volume for each year, for the 'Oil' production type, for wells located in 'Canada'. | CREATE TABLE production (production_id INT,well_id INT,production_date DATE,production_type TEXT,country TEXT); INSERT INTO production (production_id,well_id,production_date,production_type,country) VALUES (1,1,'2018-01-01','Oil','USA'),(2,1,'2018-01-02','Gas','Norway'),(3,2,'2019-05-03','Oil','Canada'),(4,3,'2020-02-04','Gas','Norway'),(5,4,'2021-03-09','Oil','Brazil'),(6,5,'2021-04-15','Gas','India'),(7,6,'2018-06-20','Oil','Canada'),(8,6,'2019-06-20','Oil','Canada'),(9,7,'2020-06-20','Oil','Canada'),(10,7,'2021-06-20','Oil','Canada'); | SELECT EXTRACT(YEAR FROM production_date) as year, SUM(production_volume) as total_oil_production FROM production WHERE production_type = 'Oil' AND country = 'Canada' GROUP BY year; |
What is the average speed of electric vehicles in the city of New York in the month of August? | CREATE TABLE EV_Data (Id INT,City VARCHAR(50),Type VARCHAR(50),Speed INT,Month VARCHAR(10)); INSERT INTO EV_Data (Id,City,Type,Speed,Month) VALUES (1,'NewYork','Electric',60,'August'); INSERT INTO EV_Data (Id,City,Type,Speed,Month) VALUES (2,'SanFrancisco','Hybrid',55,'August'); | SELECT AVG(Speed) FROM EV_Data WHERE City = 'NewYork' AND Month = 'August' AND Type = 'Electric'; |
Create a view named 'equipment_summary' with columns 'equipment_name', 'region', 'total_sales' | CREATE VIEW equipment_summary AS SELECT equipment.name AS equipment_name,sales.region,SUM(sales.quantity * equipment.price) AS total_sales FROM equipment INNER JOIN sales ON equipment.id = sales.equipment_id GROUP BY equipment.name,sales.region; | CREATE VIEW equipment_summary AS SELECT equipment.name AS equipment_name, sales.region, SUM(sales.quantity * equipment.price) AS total_sales FROM equipment INNER JOIN sales ON equipment.id = sales.equipment_id GROUP BY equipment.name, sales.region; |
Find the number of unique programs funded by 'Corporate' and 'Foundation' funding sources. | CREATE TABLE Programs (id INT,name TEXT,funding_source TEXT); INSERT INTO Programs (id,name,funding_source) VALUES (1,'Dance Performance','Corporate'),(2,'Film Festival','Foundation'),(3,'Photography Exhibition','Government'); | SELECT COUNT(DISTINCT name) FROM Programs WHERE funding_source IN ('Corporate', 'Foundation'); |
What is the average savings of customers living in 'California'? | CREATE TABLE savings (customer_id INT,name TEXT,state TEXT,savings DECIMAL(10,2)); INSERT INTO savings (customer_id,name,state,savings) VALUES (789,'Bob Smith','California',8000.00),(111,'Alice Johnson','California',6000.00); | SELECT AVG(savings) FROM savings WHERE state = 'California'; |
List all sustainable tourism practices and the number of countries implementing each. | CREATE TABLE sustainability (practice VARCHAR(50),country VARCHAR(50)); INSERT INTO sustainability (practice,country) VALUES ('Renewable Energy','France'),('Local Sourcing','Italy'),('Educational Programs','Spain'),('Waste Management','Germany'),('Renewable Energy','Japan'),('Local Sourcing','Canada'); | SELECT practice, COUNT(DISTINCT country) as num_countries FROM sustainability GROUP BY practice; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.