instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the percentage of union members involved in collective bargaining in each sector? | CREATE TABLE union_members (id INT,union_name VARCHAR(30),sector VARCHAR(20)); INSERT INTO union_members (id,union_name,sector) VALUES (1,'Union A','manufacturing'),(2,'Union B','education'),(3,'Union C','manufacturing'),(4,'Union D','technology'),(5,'Union E','technology'); CREATE TABLE collective_bargaining (id INT,union_id INT,member_id INT); INSERT INTO collective_bargaining (id,union_id,member_id) VALUES (1,1,101),(2,3,102),(3,4,103),(4,5,104); | SELECT sector, (COUNT(*) * 100.0 / (SELECT SUM(num_members) FROM (SELECT COUNT(*) AS num_members FROM union_members WHERE sector = u.sector) t)) AS percentage FROM union_members u LEFT JOIN collective_bargaining cb ON u.id = cb.union_id GROUP BY sector; |
Find all collaborations between 'Pablo Picasso' and 'Georges Braque'. | CREATE TABLE Art_Collaboration (artist_1 VARCHAR(255),artist_2 VARCHAR(255)); | SELECT artist_1, artist_2 FROM Art_Collaboration WHERE (artist_1 = 'Pablo Picasso' AND artist_2 = 'Georges Braque') OR (artist_1 = 'Georges Braque' AND artist_2 = 'Pablo Picasso'); |
How many sustainable tourism initiatives are there in total in Denmark and Norway? | CREATE TABLE sustainable_tourism (initiative_id INT,name TEXT,country TEXT); INSERT INTO sustainable_tourism VALUES (1,'Sustainable Copenhagen Tour','Denmark'),(2,'Eco-friendly Norwegian Fjords','Norway'); | SELECT COUNT(*) FROM sustainable_tourism WHERE country IN ('Denmark', 'Norway'); |
What is the total number of crimes reported in 'crime_data' and 'community_policing' tables? | CREATE TABLE crime_data (id INT,type VARCHAR(255),location VARCHAR(255),reported_date DATE); INSERT INTO crime_data (id,type,location,reported_date) VALUES (1,'Theft','Park','2021-01-01'); CREATE TABLE community_policing (id INT,type VARCHAR(255),location VARCHAR(255),reported_date DATE); INSERT INTO community_policing (id,type,location,reported_date) VALUES (1,'Meeting','Community Center','2021-01-02'); | SELECT COUNT(*) FROM crime_data UNION SELECT COUNT(*) FROM community_policing; |
What is the minimum age of users who have used technology for social good? | CREATE TABLE Users (UserID INT,Age INT,UsedTech4Good BOOLEAN); INSERT INTO Users (UserID,Age,UsedTech4Good) VALUES (1,34,true),(2,45,false),(3,29,true); | SELECT MIN(Age) FROM Users WHERE UsedTech4Good = true; |
What is the minimum environmental impact score for mining operations in Year 2005? | CREATE TABLE impact (id INT,mining_operation TEXT,year INT,score FLOAT); INSERT INTO impact (id,mining_operation,year,score) VALUES (1,'Operation A',2004,85.6); INSERT INTO impact (id,mining_operation,year,score) VALUES (2,'Operation B',2005,34.8); | SELECT MIN(score) FROM impact WHERE year = 2005 AND mining_operation LIKE '%Mining%'; |
List all sustainable tourism certifications and the number of associated tour operators in each country. | CREATE TABLE tour_operators (id INT,country VARCHAR(255),certification VARCHAR(255)); INSERT INTO tour_operators (id,country,certification) VALUES (1,'Australia','EcoCert'),(2,'Australia','Green Globe'),(3,'Australia',NULL),(4,'Canada','Green Tourism'),(5,'Canada',NULL),(6,'New Zealand','Qualmark'),(7,'New Zealand','EcoTourism'),(8,'South Africa','Fair Trade'),(9,'South Africa','Green Key'),(10,'South Africa',NULL); | SELECT country, certification, COUNT(*) AS num_tour_operators FROM tour_operators WHERE certification IS NOT NULL GROUP BY country, certification; |
What is the maximum number of passengers carried by a single spacecraft of ROSCOSMOS? | CREATE TABLE Spacecraft(id INT,organization VARCHAR(255),name VARCHAR(255),capacity INT); INSERT INTO Spacecraft(id,organization,name,capacity) VALUES (1,'ROSCOSMOS','Spacecraft 1',7),(2,'NASA','Spacecraft 2',4),(3,'ROSCOSMOS','Spacecraft 3',8); | SELECT MAX(capacity) FROM Spacecraft WHERE organization = 'ROSCOSMOS'; |
What is the average fare for passengers using the 'North' bus route during peak hours? | CREATE TABLE Routes (RouteID int,RouteName varchar(255)); INSERT INTO Routes (RouteID,RouteName) VALUES (1,'North'); CREATE TABLE Trips (TripID int,RouteID int,Fare double,TripDateTime datetime); CREATE TABLE PeakHours (PeakHourID int,StartTime time,EndTime time); INSERT INTO PeakHours (PeakHourID,StartTime,EndTime) VALUES (1,'06:00','09:00'),(2,'16:00','19:00'); | SELECT AVG(Fare) FROM Routes JOIN Trips ON Routes.RouteID = Trips.RouteID JOIN PeakHours ON Trips.TripDateTime BETWEEN PeakHours.StartTime AND PeakHours.EndTime WHERE Routes.RouteName = 'North'; |
Which basketball players have the highest scoring average in the Eastern Conference? | CREATE TABLE players (player_id INT,name TEXT,team TEXT,position TEXT,points_per_game FLOAT); INSERT INTO players (player_id,name,team,position,points_per_game) VALUES (1,'John Doe','Boston Celtics','Guard',23.4),(2,'Jane Smith','Philadelphia 76ers','Forward',21.2); | SELECT p.name, p.points_per_game FROM players p WHERE p.team IN (SELECT t.team FROM teams t WHERE t.conference = 'Eastern') ORDER BY p.points_per_game DESC; |
Insert a new sustainable fabric type 'Organic Linen' into the 'fabrics' table | CREATE TABLE fabrics (id INT PRIMARY KEY,fabric_name VARCHAR(50),is_sustainable BOOLEAN); | INSERT INTO fabrics (id, fabric_name, is_sustainable) VALUES (1, 'Organic Linen', true); |
What is the average annual rainfall in the coffee-growing regions of Colombia? | CREATE TABLE weather_data (region VARCHAR(255),year INT,rainfall FLOAT); INSERT INTO weather_data (region,year,rainfall) VALUES ('Caldas',2010,2200),('Caldas',2011,2500),('Quindio',2010,1800),('Quindio',2011,2000),('Huila',2010,1500),('Huila',2011,1700); | SELECT AVG(rainfall) FROM weather_data WHERE region IN ('Caldas', 'Quindio', 'Huila'); |
insert a new artifact record into the artifacts table | CREATE TABLE artifacts (id INT PRIMARY KEY,site_id INT,artifact_id INT,description TEXT); | INSERT INTO artifacts (id, site_id, artifact_id, description) VALUES (1, 123, 456, 'Small pottery shard with intricate geometric patterns'); |
Find the total cargo weight handled at the port of 'Los Angeles', partitioned by year and month. | CREATE TABLE ports (port_id INT,port_name VARCHAR(50),city VARCHAR(50),country VARCHAR(50)); CREATE TABLE cargo (cargo_id INT,port_id INT,weight FLOAT,handling_date DATE); | SELECT YEAR(handling_date) AS handling_year, MONTH(handling_date) AS handling_month, SUM(weight) AS total_weight FROM cargo WHERE port_id = (SELECT port_id FROM ports WHERE port_name = 'Los Angeles') GROUP BY YEAR(handling_date), MONTH(handling_date); |
List all the agroecological projects in Mexico with their respective websites. | CREATE TABLE agroecological_projects (project_id INT,name TEXT,location TEXT,website TEXT,city TEXT,state TEXT,country TEXT); INSERT INTO agroecological_projects (project_id,name,location,website,city,state,country) VALUES (1,'Sustainable Fields','rural area','sustainablefields.org','Puebla','','Mexico'); | SELECT name, website FROM agroecological_projects WHERE country = 'Mexico'; |
What is the number of graduate students in the Computer Science department who have published at least one paper? | CREATE TABLE publications (id INT,student_type VARCHAR(10),department VARCHAR(10),year INT); INSERT INTO publications (id,student_type,department,year) VALUES (1,'graduate','Chemistry',2019),(2,'undergraduate','Biology',2020),(3,'graduate','Computer Science',2020); | SELECT COUNT(DISTINCT id) FROM publications WHERE student_type = 'graduate' AND department = 'Computer Science'; |
What is the average price of vegan dishes on the menu? | CREATE TABLE Menu (item_id INT,name VARCHAR(50),is_vegan BOOLEAN,price DECIMAL(5,2)); INSERT INTO Menu (item_id,name,is_vegan,price) VALUES (1,'Vegan Burger',true,12.99),(2,'Fries',false,3.99),(3,'Vegan Pizza',true,14.99); | SELECT AVG(price) FROM Menu WHERE is_vegan = true; |
Insert the following records into the 'autonomous_driving_research' table: 'Zoox' with 'USA', 'Aptiv' with 'USA' | CREATE TABLE autonomous_driving_research (id INT PRIMARY KEY,company VARCHAR(255),country VARCHAR(255)); | INSERT INTO autonomous_driving_research (company, country) VALUES ('Zoox', 'USA'), ('Aptiv', 'USA'); |
How many electric and autonomous vehicle models are available in cities with a population less than 3 million? | CREATE TABLE City (id INT,name VARCHAR,population INT,PRIMARY KEY(id)); INSERT INTO City (id,name,population) VALUES (1,'NYC',8500000); INSERT INTO City (id,name,population) VALUES (2,'LA',4000000); INSERT INTO City (id,name,population) VALUES (3,'Sydney',2500000); CREATE TABLE ElectricVehicle (id INT,city_id INT,model VARCHAR,PRIMARY KEY(id)); INSERT INTO ElectricVehicle (id,city_id,model) VALUES (1,1,'Tesla Model S'); INSERT INTO ElectricVehicle (id,city_id,model) VALUES (2,2,'Tesla Model 3'); INSERT INTO ElectricVehicle (id,city_id,model) VALUES (3,3,'Rivian R1T'); CREATE TABLE AutonomousVehicle (id INT,city_id INT,model VARCHAR,PRIMARY KEY(id)); INSERT INTO AutonomousVehicle (id,city_id,model) VALUES (1,1,'Wayve'); INSERT INTO AutonomousVehicle (id,city_id,model) VALUES (2,2,'NVIDIA'); INSERT INTO AutonomousVehicle (id,city_id,model) VALUES (3,3,'Zoox'); | SELECT COUNT(DISTINCT E.model) + COUNT(DISTINCT A.model) as total_models FROM City C LEFT JOIN ElectricVehicle E ON C.id = E.city_id LEFT JOIN AutonomousVehicle A ON C.id = A.city_id WHERE C.population < 3000000; |
Identify the highest-paid employee for each department in the Engineering division. | CREATE TABLE Employee (Employee_ID INT,First_Name VARCHAR(50),Last_Name VARCHAR(50),Position VARCHAR(50),Department VARCHAR(50),Division VARCHAR(50),Annual_Salary DECIMAL(10,2),Date_Hired DATE); CREATE TABLE Department_Organization (Department_ID INT,Department VARCHAR(50),Division VARCHAR(50)); | SELECT E.Employee_ID, E.First_Name, E.Last_Name, E.Department, E.Division, E.Annual_Salary FROM Employee E JOIN (SELECT Department, MAX(Annual_Salary) AS Max_Salary FROM Employee WHERE Division = 'Engineering' GROUP BY Department) M ON E.Department = M.Department AND E.Annual_Salary = M.Max_Salary; |
Get the chemical code and production_date for the records with the highest production quantity | CREATE TABLE chemical_production (production_date DATE,chemical_code VARCHAR(10),quantity INT); INSERT INTO chemical_production (production_date,chemical_code,quantity) VALUES ('2021-01-03','A123',450),('2021-01-07','A123',620),('2021-01-12','A123',390); | SELECT chemical_code, production_date, quantity FROM chemical_production WHERE (chemical_code, quantity) IN (SELECT chemical_code, MAX(quantity) FROM chemical_production GROUP BY chemical_code); |
What is the average funding amount for companies in EMEA and APAC regions? | CREATE TABLE companies (id INT,name TEXT,region TEXT,funding INT); INSERT INTO companies (id,name,region,funding) VALUES (1,'Rho Corp','EMEA',4000000),(2,'Sigma Ltd','APAC',5000000); | SELECT region, AVG(funding) FROM companies WHERE region IN ('EMEA', 'APAC') GROUP BY region; |
What is the total investment value for all clients with a last name starting with 'B'? | CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(50));CREATE TABLE investments (investment_id INT,client_id INT,market VARCHAR(50),value INT);INSERT INTO clients (client_id,name,region) VALUES (1,'John Doe','North America'),(2,'Barbara Black','Asia');INSERT INTO investments (investment_id,client_id,market,value) VALUES (1,1,'US',50000),(2,2,'Europe',120000),(3,2,'Asia',80000); | SELECT SUM(i.value) FROM clients c INNER JOIN investments i ON c.client_id = i.client_id WHERE SUBSTRING(c.name, 1, 1) = 'B'; |
What was the total cost of space missions led by countries other than the USA? | CREATE TABLE space_missions (id INT,mission_name VARCHAR(255),country VARCHAR(255),cost FLOAT); INSERT INTO space_missions (id,mission_name,country,cost) VALUES (1,'Apollo 11','USA',25500000),(2,'Mars Orbiter Mission','India',73000000),(3,'Chandrayaan-1','India',79000000),(4,'Grail','USA',496000000); | SELECT SUM(cost) FROM space_missions WHERE country != 'USA'; |
Find the total value of all artworks in the Surrealism movement. | CREATE TABLE art_movements (id INT,movement_name VARCHAR(50)); CREATE TABLE artwork_value (id INT,artwork_name VARCHAR(50),movement_id INT,value DECIMAL(10,2)); | SELECT SUM(value) as total_value FROM artwork_value WHERE movement_id = (SELECT id FROM art_movements WHERE movement_name = 'Surrealism'); |
Update the 'teacher_certification' column in the 'teachers' table to 'yes' if the 'state' is 'California' | CREATE TABLE teachers (teacher_id INT,name VARCHAR(50),state VARCHAR(20),teacher_certification VARCHAR(5)); | UPDATE teachers SET teacher_certification = 'yes' WHERE state = 'California'; |
Which marine mammals are found in the Arctic and have a population size greater than 5000? | CREATE TABLE marine_mammals (mammal_id INT,name VARCHAR(50),population INT,habitat VARCHAR(50)); INSERT INTO marine_mammals (mammal_id,name,population,habitat) VALUES (1,'Polar Bear',25000,'Arctic'),(2,'Walrus',19000,'Arctic'); | SELECT name FROM marine_mammals WHERE habitat = 'Arctic' AND population > 5000; |
What is the total number of tickets sold and the total revenue for teams that have 'Arena' in their name? | CREATE TABLE ticket_sales (team_name VARCHAR(50),tickets_sold INT,revenue DECIMAL(10,2)); INSERT INTO ticket_sales (team_name,tickets_sold,revenue) VALUES ('Team A Stadium',1000,25000.00),('Team B Arena',800,20000.00),('Stadium City FC',1200,32000.00),('Team D Field',900,21000.00),('Arena City FC',700,18000.00); | SELECT SUM(tickets_sold) AS total_tickets_sold, SUM(revenue) AS total_revenue FROM ticket_sales WHERE team_name LIKE '%Arena%'; |
What is the average budget allocated for AI ethics initiatives in Asia and Africa? | CREATE TABLE AIEthicsBudget(initiative VARCHAR(255),region VARCHAR(255),budget DECIMAL(10,2));INSERT INTO AIEthicsBudget(initiative,region,budget) VALUES('Bias Mitigation','Asia',50000.00),('Transparency','Africa',45000.00),('Fairness','Asia',60000.00),('Accountability','Africa',55000.00); | SELECT AVG(budget) FROM AIEthicsBudget WHERE region IN ('Asia', 'Africa'); |
What is the minimum number of visitors required to break even for each exhibition in San Francisco? | CREATE TABLE Exhibitions_Break_Even (exhibition_id INT,city VARCHAR(50),min_visitors INT); | SELECT exhibition_id, min_visitors FROM Exhibitions_Break_Even WHERE city = 'San Francisco'; |
What is the total number of public transportation vehicles in use in the transportation system? | CREATE TABLE transportation_system (id INT,vehicle_name TEXT,type TEXT);INSERT INTO transportation_system (id,vehicle_name,type) VALUES (1,'BusA','Public'),(2,'CarB','Private'),(3,'BusC','Public'); | SELECT COUNT(*) FROM transportation_system WHERE type = 'Public'; |
List the top 3 news categories with the highest number of articles in the "articles" table. | CREATE TABLE articles (article_id INT,title VARCHAR(100),category VARCHAR(50),publication_date DATE,views INT); INSERT INTO articles (article_id,title,category,publication_date,views) VALUES (1,'News from the Capital','Politics','2022-01-01',1500),(2,'Tech Innovations in 2022','Technology','2022-01-02',1200),(3,'The Art of Persuasion','Psychology','2022-01-03',1800),(4,'Education Reforms in Europe','Education','2022-01-04',1000); | SELECT category, COUNT(*) as article_count FROM articles GROUP BY category ORDER BY article_count DESC LIMIT 3; |
What is the average water consumption per capita in New York City for the year 2020? | CREATE TABLE new_york_water_use (year INT,population INT,water_consumption INT); INSERT INTO new_york_water_use (year,population,water_consumption) VALUES (2020,8500000,850000000),(2021,8600000,860000000); | SELECT AVG(new_york_water_use.water_consumption / new_york_water_use.population) as avg_water_consumption FROM new_york_water_use WHERE new_york_water_use.year = 2020; |
List all archaeologists who specialize in a specific field | CREATE TABLE Archaeologists (id INT PRIMARY KEY,name VARCHAR(255),specialty TEXT,years_experience INT); INSERT INTO Archaeologists (id,name,specialty,years_experience) VALUES (1,'Dr. Jane Doe','Egyptology',20),(2,'Dr. John Smith','Mayan Civilization',15),(3,'Dr. Maria Lopez','Inca Civilization',18); | SELECT * FROM Archaeologists WHERE specialty = 'Egyptology'; |
List the companies that have received funding in both the USA and Canada. | CREATE TABLE companies (id INT,name TEXT,country TEXT); CREATE TABLE fundings (id INT,company_id INT,round TEXT,country TEXT); INSERT INTO companies (id,name,country) VALUES (1,'Acme Inc','USA'),(2,'Zebra Corp','Canada'),(3,'Dino Tech','USA'),(4,'Elephant Inc','Canada'),(5,'Fox Enterprises','USA'); INSERT INTO fundings (id,company_id,round,country) VALUES (1,1,'Seed','USA'),(2,1,'Series A','Canada'),(3,2,'Seed','Canada'),(4,2,'Series A','USA'),(5,3,'Seed','USA'),(6,4,'Seed','Canada'),(7,4,'Series A','Canada'),(8,5,'Seed','USA'); | SELECT companies.name FROM companies INNER JOIN fundings AS us_fundings ON companies.id = us_fundings.company_id AND us_fundings.country = 'USA' INNER JOIN fundings AS canada_fundings ON companies.id = canada_fundings.company_id AND canada_fundings.country = 'Canada' GROUP BY companies.name HAVING COUNT(DISTINCT companies.id) > 1; |
How many players from 'Germany' have played a game in the 'Simulation' genre in the last month? | CREATE TABLE PlayerGameGenres (PlayerID INT,GameGenre VARCHAR(20)); INSERT INTO PlayerGameGenres (PlayerID,GameGenre) VALUES (1,'Action'),(1,'Adventure'),(2,'Strategy'),(2,'Simulation'),(3,'Simulation'),(3,'Virtual Reality'); | SELECT COUNT(DISTINCT PlayerID) FROM PlayerGameGenres INNER JOIN Players ON PlayerGameGenres.PlayerID = Players.PlayerID WHERE Country = 'Germany' AND GameGenre = 'Simulation' AND LastPurchaseDate >= DATEADD(month, -1, GETDATE()); |
Which organizations have not received any donations? | CREATE TABLE organizations (id INT,name VARCHAR(100)); CREATE TABLE us_donations (id INT,organization_id INT,amount DECIMAL(10,2)); CREATE TABLE canada_donations (id INT,organization_id INT,amount DECIMAL(10,2)); INSERT INTO organizations (id,name) VALUES (1,'Organization A'),(2,'Organization B'),(3,'Organization C'); INSERT INTO us_donations (id,organization_id,amount) VALUES (1,1,100.00),(2,1,200.00),(3,2,50.00); INSERT INTO canada_donations (id,organization_id,amount) VALUES (1,1,75.00),(2,2,25.00); | SELECT o.name FROM organizations o LEFT JOIN (SELECT * FROM us_donations UNION ALL SELECT * FROM canada_donations) d ON o.id = d.organization_id WHERE d.organization_id IS NULL; |
What is the maximum billing amount for cases in the legal precedents table? | CREATE TABLE legal_precedents (precedent_id INT,case_id INT,billing_amount FLOAT); INSERT INTO legal_precedents (precedent_id,case_id,billing_amount) VALUES (1,1,300.0),(2,2,400.0),(3,3,500.0); | SELECT MAX(billing_amount) FROM legal_precedents; |
What is the maximum revenue generated by sustainable tours in Germany? | CREATE TABLE sustainable_tours (tour_id INT,tour_name TEXT,country TEXT,revenue FLOAT); INSERT INTO sustainable_tours (tour_id,tour_name,country,revenue) VALUES (1,'Wind Farm Visit','Germany',3000),(2,'Solar Panel Farm','Germany',4000); | SELECT MAX(revenue) FROM sustainable_tours WHERE country = 'Germany'; |
Delete records of clients from the 'clients' table who have not invested in any funds. | CREATE TABLE clients (client_id INT,name TEXT,region TEXT); INSERT INTO clients (client_id,name,region) VALUES (1,'John Doe','US'),(2,'Jane Smith','APAC'),(3,'Mike Johnson','EU'); CREATE TABLE investments (client_id INT,fund_id INT,amount DECIMAL(10,2)); INSERT INTO investments (client_id,fund_id,amount) VALUES (1,1,15000.00),(1,2,20000.00),(2,1,30000.00); CREATE TABLE funds (fund_id INT,fund_name TEXT,category TEXT); INSERT INTO funds (fund_id,fund_name,category) VALUES (1,'Global Fund','Fixed Income'),(2,'Regional Fund','Equity'); | DELETE FROM clients WHERE client_id NOT IN (SELECT c.client_id FROM clients c JOIN investments i ON c.client_id = i.client_id); |
How many unique attendees were there at concerts in Germany? | CREATE TABLE Events (EventID INT,EventType TEXT,Country TEXT); INSERT INTO Events (EventID,EventType,Country) VALUES (1,'Concert','Germany'),(2,'Exhibition','France'),(3,'Concert','Germany'); CREATE TABLE Attendees (AttendeeID INT,EventID INT); INSERT INTO Attendees (AttendeeID,EventID) VALUES (1,1),(2,1),(3,2),(4,3),(5,1); | SELECT COUNT(DISTINCT AttendeeID) FROM Attendees A JOIN Events E ON A.EventID = E.EventID WHERE E.EventType = 'Concert' AND E.Country = 'Germany'; |
What are the names, hazard types, and inspection dates of all chemicals from the 'chemical_inspections' and 'chemicals' tables where the manufacturer is based in India? | CREATE TABLE manufacturers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE chemical_inspections (id INT PRIMARY KEY,chemical_id INT,hazard_type VARCHAR(255),inspection_date DATE); | SELECT c.name, ci.hazard_type, ci.inspection_date FROM chemical_inspections ci INNER JOIN chemicals c ON ci.chemical_id = c.id INNER JOIN manufacturers m ON c.manufacturer_id = m.id WHERE m.country = 'India'; |
How many donations were made in each month of 2022? | CREATE TABLE donations_date (donation_id INT,donation_date DATE); INSERT INTO donations_date (donation_id,donation_date) VALUES (1,'2022-01-01'),(2,'2022-02-15'),(3,'2022-01-20'),(4,'2022-03-05'); | SELECT EXTRACT(MONTH FROM donation_date) as month, COUNT(*) as num_donations FROM donations_date GROUP BY month; |
Drop the 'mitigation_projects' table | CREATE TABLE mitigation_projects (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(50),start_date DATE,end_date DATE,budget DECIMAL(10,2)); DROP TABLE mitigation_projects; | DROP TABLE mitigation_projects; |
Update contract status for 'Middle East' defense projects with timelines > 2023 | CREATE TABLE defense_projects (proj_id INT,proj_name VARCHAR(50),region VARCHAR(50),start_date DATE,end_date DATE); | UPDATE defense_projects SET contract_status = 'Active' WHERE region = 'Middle East' AND start_date < '2023-01-01' AND end_date > '2023-12-31'; |
What is the maximum budget for projects addressing technology accessibility? | CREATE TABLE projects_2 (id INT,name VARCHAR,type VARCHAR,budget FLOAT); INSERT INTO projects_2 (id,name,type,budget) VALUES (1,'Accessible Software Development','Accessibility',150000),(2,'Adaptive Hardware Research','Accessibility',200000),(3,'AI for Good','AI',100000),(4,'Digital Divide Initiative','Digital Divide',120000); | SELECT MAX(budget) FROM projects_2 WHERE type = 'Accessibility'; |
What is the total revenue for organic hair care products in the European market? | CREATE TABLE Haircare_Europe(Product VARCHAR(30),Brand VARCHAR(30),Revenue DECIMAL(10,2)); INSERT INTO Haircare_Europe(Product,Brand,Revenue) VALUES('Shampoo A','Brand X',2000),('Conditioner B','Brand Y',1500),('Styling C','Brand Z',1200),('Shampoo D','Brand X',2500),('Conditioner E','Brand Y',1800),('Styling F','Brand Z',1700),('Shampoo G','Brand W',1000),('Conditioner H','Brand V',1400),('Styling I','Brand W',1300),('Styling J','Brand V',1600); | SELECT SUM(Revenue) FROM Haircare_Europe WHERE Product LIKE '%Organic%' AND Country = 'Europe'; |
What is the average age of patients by condition? | CREATE TABLE PatientConditions (PatientID int,ConditionID int,Age int); INSERT INTO PatientConditions (PatientID,ConditionID,Age) VALUES (1,1,30),(2,2,35); | SELECT Conditions.Condition, AVG(PatientConditions.Age) FROM PatientConditions JOIN Conditions ON PatientConditions.ConditionID = Conditions.ConditionID GROUP BY Conditions.Condition; |
Find the number of countries with a threat level of 'high' in Q2 2022 | CREATE TABLE threat_intelligence (country VARCHAR(100),threat_level VARCHAR(20),quarter VARCHAR(10)); | SELECT COUNT(DISTINCT country) FROM threat_intelligence WHERE threat_level = 'high' AND quarter = 'Q2 2022'; |
What is the average preference rating for makeup products that are not cruelty-free and have a revenue above 200? | CREATE TABLE products (product_id INT,category VARCHAR(50),cruelty_free BOOLEAN,preference_rating INT,revenue INT); INSERT INTO products (product_id,category,cruelty_free,preference_rating,revenue) VALUES (1,'Eyeliner',true,8,150),(2,'Lipstick',false,9,300),(3,'Eyeshadow',true,7,250); | SELECT AVG(products.preference_rating) FROM products WHERE products.cruelty_free = false AND products.revenue > 200; |
What is the average number of tourists visiting countries in the African continent? | CREATE TABLE africa_tourists (id INT,country VARCHAR(20),tourists INT); INSERT INTO africa_tourists (id,country,tourists) VALUES (1,'Egypt',10000000),(2,'South Africa',15000000),(3,'Morocco',8000000); | SELECT AVG(tourists) FROM africa_tourists; |
Find the number of male and female students in the 'Student' table | CREATE TABLE Student (StudentID INT,Gender VARCHAR(10)); INSERT INTO Student (StudentID,Gender) VALUES (1,'Male'),(2,'Female'),(3,'Male'); | SELECT Gender, COUNT(*) FROM Student GROUP BY Gender; |
What is the difference between the maximum and minimum transaction amounts for Mexico? | CREATE TABLE transactions (user_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE,country VARCHAR(255)); INSERT INTO transactions (user_id,transaction_amount,transaction_date,country) VALUES (1,50.00,'2022-01-01','Mexico'),(2,150.50,'2022-01-02','Mexico'),(3,100.00,'2022-01-03','Mexico'); | SELECT country, MAX(transaction_amount) - MIN(transaction_amount) as transaction_amount_difference FROM transactions WHERE country = 'Mexico' GROUP BY country; |
Calculate the total population of all animals in Australian conservation programs | CREATE TABLE conservation_programs (id INT,program_name VARCHAR(255),location VARCHAR(255)); CREATE TABLE animal_populations (id INT,program_id INT,animal_type VARCHAR(255),population INT); INSERT INTO conservation_programs (id,program_name,location) VALUES (1,'Australian Wildlife Conservancy','Australia'),(2,'Taronga Conservation Society','Australia'); INSERT INTO animal_populations (id,program_id,animal_type,population) VALUES (1,1,'Kangaroo',10000),(2,1,'Wallaby',5000),(3,2,'Koala',8000),(4,2,'Wombat',2000); | SELECT SUM(animal_populations.population) FROM conservation_programs INNER JOIN animal_populations ON conservation_programs.id = animal_populations.program_id WHERE conservation_programs.location = 'Australia'; |
What is the maximum dissolved oxygen level for each zone in the 'ocean_health' table? | CREATE TABLE ocean_health (zone VARCHAR(255),dissolved_oxygen DECIMAL(4,2)); INSERT INTO ocean_health (zone,dissolved_oxygen) VALUES ('Zone A',7.6),('Zone B',6.8),('Zone C',8.3),('Zone A',7.9),('Zone B',7.1); | SELECT zone, MAX(dissolved_oxygen) as max_dissolved_oxygen FROM ocean_health GROUP BY zone; |
How many units of the "Eco-friendly" fabric were produced in July 2021? | CREATE TABLE production_data (fabric_type VARCHAR(20),month VARCHAR(10),units_produced INT); INSERT INTO production_data (fabric_type,month,units_produced) VALUES ('Eco-friendly','July',5000),('Regular','July',7000),('Eco-friendly','August',5500); | SELECT SUM(units_produced) FROM production_data WHERE fabric_type = 'Eco-friendly' AND month = 'July'; |
Calculate the total value of transactions for each client in the African region. | CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(20)); CREATE TABLE transactions (transaction_id INT,client_id INT,amount DECIMAL(10,2)); INSERT INTO clients (client_id,name,region) VALUES (1,'John Doe','African'),(2,'Jane Smith','African'),(3,'Mike Johnson','European'); INSERT INTO transactions (transaction_id,client_id,amount) VALUES (1,1,1000.00),(2,1,2000.00),(3,2,500.00),(4,2,3000.00),(5,3,10000.00); | SELECT c.client_id, c.name, SUM(t.amount) FROM clients c INNER JOIN transactions t ON c.client_id = t.client_id WHERE c.region = 'African' GROUP BY c.client_id, c.name; |
Which forests in Germany have more than 5 distinct years of timber production data? | CREATE TABLE Forests (id INT,name VARCHAR(50),hectares FLOAT,country VARCHAR(50)); INSERT INTO Forests (id,name,hectares,country) VALUES (1,'Black Forest',150000.0,'Germany'); CREATE TABLE Timber_Production (id INT,forest_id INT,year INT,production_cubic_meters INT); INSERT INTO Timber_Production (id,forest_id,year,production_cubic_meters) VALUES (1,1,2000,12000); | SELECT forest_id FROM Timber_Production WHERE forest_id IN (SELECT id FROM Forests WHERE country = 'Germany') GROUP BY forest_id HAVING COUNT(DISTINCT year) > 5; |
Add a new marine conservation law in the Caribbean Sea | CREATE TABLE marine_conservation_laws (id INT PRIMARY KEY,law_name VARCHAR(255),region VARCHAR(255)); | INSERT INTO marine_conservation_laws (id, law_name, region) VALUES (1, 'Caribbean Marine Protected Areas Act', 'Caribbean Sea'); |
How many patients with disabilities in Illinois have not visited a hospital in the last year? | CREATE TABLE Patients (PatientID INT,Disabilities TEXT,LastHospitalVisit DATE,State TEXT); INSERT INTO Patients (PatientID,Disabilities,LastHospitalVisit,State) VALUES (1,'Mobility Impairment','2020-01-01','Illinois'); | SELECT COUNT(*) FROM Patients WHERE Disabilities IS NOT NULL AND LastHospitalVisit < DATEADD(year, -1, GETDATE()) AND State = 'Illinois'; |
What is the average grant amount awarded to graduate students in the Physics department? | CREATE TABLE grant_data (id INT,student_id INT,amount FLOAT,department VARCHAR(50),year INT); INSERT INTO grant_data (id,student_id,amount,department,year) VALUES (1,1,10000,'Physics',2019),(2,2,15000,'Physics',2020); | SELECT AVG(amount) FROM grant_data WHERE department = 'Physics' AND year IN (2019, 2020) GROUP BY department; |
What is the total revenue and player count for each game in the 'Adventure' genre? | CREATE TABLE Games (Id INT,Name VARCHAR(100),Genre VARCHAR(50),Sales INT,Players INT); INSERT INTO Games VALUES (1,'GameX','Adventure',3000,10000),(2,'GameY','Simulation',4000,15000),(3,'GameZ','Adventure',5000,12000),(4,'GameW','Strategy',6000,18000); | SELECT Genre, SUM(Sales) AS Total_Revenue, COUNT(*) AS Player_Count FROM Games WHERE Genre = 'Adventure' GROUP BY Genre; |
What is the maximum transaction amount for customers from Latin America in the last week? | CREATE TABLE Customers (CustomerID INT,Name VARCHAR(255),Country VARCHAR(255)); INSERT INTO Customers (CustomerID,Name,Country) VALUES (1,'Juan Perez','Mexico'); INSERT INTO Customers (CustomerID,Name,Country) VALUES (2,'Maria Rodriguez','Brazil'); CREATE TABLE Transactions (TransactionID INT,CustomerID INT,Amount DECIMAL(10,2),TransactionDate DATE); INSERT INTO Transactions (TransactionID,CustomerID,Amount,TransactionDate) VALUES (1,1,500.00,'2022-05-01'); INSERT INTO Transactions (TransactionID,CustomerID,Amount,TransactionDate) VALUES (2,1,200.00,'2022-05-05'); INSERT INTO Transactions (TransactionID,CustomerID,Amount,TransactionDate) VALUES (3,2,150.00,'2022-05-03'); | SELECT MAX(Amount) FROM Transactions JOIN Customers ON Transactions.CustomerID = Customers.CustomerID WHERE Customers.Country IN ('Mexico', 'Brazil') AND Transactions.TransactionDate >= DATEADD(day, -7, GETDATE()); |
What is the average daily ridership for each subway line in Seoul? | CREATE TABLE subway (line_id INT,city VARCHAR(50),daily_ridership INT); INSERT INTO subway (line_id,city,daily_ridership) VALUES (1,'Tokyo',300000),(2,'Tokyo',450000),(3,'Tokyo',400000),(4,'Tokyo',500000),(5,'Seoul',250000),(6,'Seoul',300000); | SELECT line_id, city, AVG(daily_ridership) FROM subway WHERE city = 'Seoul' GROUP BY line_id, city; |
What is the trend in mental health hospitalizations for each age group? | CREATE TABLE mental_health (patient_id INT,patient_age INT,hospitalized TEXT,date DATE); INSERT INTO mental_health (patient_id,patient_age,hospitalized,date) VALUES (1,18,'Yes','2021-01-01'),(2,25,'No','2021-01-02'),(3,30,'Yes','2021-01-03'); | SELECT patient_age, hospitalized, COUNT(*) AS count, LAG(count, 1) OVER (ORDER BY patient_age) AS previous_age_count FROM mental_health GROUP BY patient_age, hospitalized ORDER BY patient_age; |
Update the cybersecurity strategy for Canada to include training on social engineering. | CREATE TABLE strategies (id INT,country VARCHAR(255),description VARCHAR(255));INSERT INTO strategies (id,country,description) VALUES (1,'Canada','Training on malware and phishing'); | UPDATE strategies SET description = 'Training on malware, phishing, and social engineering' WHERE country = 'Canada'; |
What is the average distance from the sun for objects studied in astrophysics research? | CREATE TABLE AstrophysicsResearch (object_name VARCHAR(255),distance_from_sun FLOAT); INSERT INTO AstrophysicsResearch (object_name,distance_from_sun) VALUES ('Sun',0),('Mercury',57.9),('Venus',108.2),('Earth',149.6),('Mars',227.9); | SELECT AVG(distance_from_sun) FROM AstrophysicsResearch WHERE object_name != 'Sun'; |
Update the title of the music track 'Bohemian Rhapsody' to 'Queen's Bohemian Rhapsody'. | CREATE TABLE music_track (track_id INT,title VARCHAR(100),artist VARCHAR(100)); INSERT INTO music_track (track_id,title,artist) VALUES (1,'Bohemian Rhapsody','Queen'); | UPDATE music_track SET title = 'Queen''s Bohemian Rhapsody' WHERE title = 'Bohemian Rhapsody'; |
List spacecraft manufacturers who have never manufactured a spacecraft priced over 10 million. | CREATE TABLE spacecraft_manufacturing(id INT,cost FLOAT,year INT,manufacturer VARCHAR(20)); INSERT INTO spacecraft_manufacturing(id,cost,year,manufacturer) VALUES (1,5000000,2025,'SpaceCorp'); INSERT INTO spacecraft_manufacturing(id,cost,year,manufacturer) VALUES (2,7000000,2025,'Galactic Inc'); | SELECT DISTINCT manufacturer FROM spacecraft_manufacturing WHERE id NOT IN (SELECT id FROM spacecraft_manufacturing WHERE cost > 10000000); |
Delete the 'state_facts' table | CREATE TABLE state_facts (state VARCHAR(2),capital VARCHAR(50),population INT,area_sq_miles INT); | DROP TABLE state_facts; |
Identify crime rates and response times for each district in London. | CREATE TABLE crimes (id INT,crime_type VARCHAR(255),district VARCHAR(255),response_time INT); INSERT INTO crimes (id,crime_type,district,response_time) VALUES (1,'Theft','Camden',10); INSERT INTO crimes (id,crime_type,district,response_time) VALUES (2,'Vandalism','Kensington',15); CREATE TABLE districts (district VARCHAR(255),city VARCHAR(255)); INSERT INTO districts (district,city) VALUES ('Camden','London'); INSERT INTO districts (district,city) VALUES ('Kensington','London'); | SELECT c.crime_type, d.district, COUNT(c.id) AS crime_count, AVG(c.response_time) AS response_time_avg FROM crimes c INNER JOIN districts d ON c.district = d.district WHERE d.city = 'London' GROUP BY c.crime_type, d.district; |
Find the number of distinct players who have played games on each platform, excluding mobile and PC gamers. | CREATE TABLE PlayerPlatform (PlayerID INT,Platform VARCHAR(10)); INSERT INTO PlayerPlatform (PlayerID,Platform) VALUES (1,'PC'),(2,'Console'),(3,'Mobile'),(4,'Console'),(5,'VR'); | SELECT Platform, COUNT(DISTINCT PlayerID) as NumPlayers FROM PlayerPlatform WHERE Platform NOT IN ('PC', 'Mobile') GROUP BY Platform; |
Insert a new marine species record into the marine_species table. | CREATE TABLE marine_species (id INT PRIMARY KEY,name VARCHAR(255),conservation_status VARCHAR(255)); | INSERT INTO marine_species (id, name, conservation_status) VALUES (4, 'Giant Pacific Octopus', 'vulnerable'); |
Delete the view "top_articles_this_week" from the database | CREATE VIEW top_articles_this_week AS SELECT * FROM articles WHERE publication_date >= CURDATE() - INTERVAL 7 DAY ORDER BY pageviews DESC; | DROP VIEW top_articles_this_week; |
What is the average budget for transportation projects in the 'transportation_projects' table? | CREATE TABLE transportation_projects (project VARCHAR(50),budget INT); INSERT INTO transportation_projects (project,budget) VALUES ('Road Construction',1000000); INSERT INTO transportation_projects (project,budget) VALUES ('Bridge Building',5000000); INSERT INTO transportation_projects (project,budget) VALUES ('Bus Purchase',800000); | SELECT AVG(budget) FROM transportation_projects; |
What is the total area of protected forests in the United States? | CREATE TABLE ProtectedForests (id INT,country VARCHAR(255),region VARCHAR(255),name VARCHAR(255),area FLOAT); INSERT INTO ProtectedForests (id,country,region,name,area) VALUES (1,'United States','Pacific Northwest','Olympic National Park',922600); | SELECT SUM(area) FROM ProtectedForests WHERE country = 'United States'; |
What is the total number of cybersecurity incidents in 'Asia' and 'Africa' in 2020 and 2021? | CREATE TABLE CybersecurityIncidents (ID INT,Country VARCHAR(50),Year INT,Incidents INT); INSERT INTO CybersecurityIncidents (ID,Country,Year,Incidents) VALUES (1,'Country1',2020,100); INSERT INTO CybersecurityIncidents (ID,Country,Year,Incidents) VALUES (2,'Country2',2021,150); INSERT INTO CybersecurityIncidents (ID,Country,Year,Incidents) VALUES (3,'Country3',2020,120); | SELECT Country, SUM(Incidents) as TotalIncidents FROM CybersecurityIncidents WHERE Country IN ('Asia', 'Africa') AND Year IN (2020, 2021) GROUP BY Country; |
Who were the top 3 customers by total revenue in the state of Colorado in 2021? | CREATE TABLE Customers (id INT,name VARCHAR(255),state VARCHAR(255));CREATE TABLE Purchases (id INT,customer_id INT,revenue DECIMAL(10,2),year INT);INSERT INTO Customers (id,name,state) VALUES (1,'John Doe','CO');INSERT INTO Purchases (id,customer_id,revenue,year) VALUES (1,1,1500,2021); | SELECT c.name, SUM(p.revenue) as total_revenue FROM Customers c JOIN Purchases p ON c.id = p.customer_id WHERE c.state = 'CO' GROUP BY c.name ORDER BY total_revenue DESC LIMIT 3; |
What is the maximum number of games played in a single day by any player? | CREATE TABLE player_activity (player_id INT,play_date DATE,num_games INT); INSERT INTO player_activity (player_id,play_date,num_games) VALUES (1,'2021-01-01',3),(1,'2021-01-02',2),(2,'2021-01-01',1),(2,'2021-01-03',5),(3,'2021-01-02',4),(3,'2021-01-03',3); | SELECT MAX(num_games) FROM player_activity; |
What is the number of unique donors and total donation amount for each program in H1 2021? | CREATE TABLE program_donations (donation_id INT,program_id INT,donor_id INT,donation_amount FLOAT,donation_date DATE); INSERT INTO program_donations (donation_id,program_id,donor_id,donation_amount,donation_date) VALUES (1,1,1,80,'2021-01-01'); INSERT INTO program_donations (donation_id,program_id,donor_id,donation_amount,donation_date) VALUES (2,2,2,100,'2021-03-01'); | SELECT p.program_name, COUNT(DISTINCT d.donor_id) AS num_donors, SUM(d.donation_amount) AS total_donation FROM program_donations d INNER JOIN programs p ON d.program_id = p.program_id WHERE EXTRACT(YEAR FROM d.donation_date) = 2021 AND EXTRACT(MONTH FROM d.donation_date) BETWEEN 1 AND 6 GROUP BY p.program_name; |
What is the distribution of job titles by department? | CREATE TABLE job_titles (id INT,department_id INT,title VARCHAR(255)); INSERT INTO job_titles (id,department_id,title) VALUES (1,1,'Manager'),(2,1,'Associate'),(3,2,'Engineer'),(4,2,'Analyst'),(5,3,'Designer'); | SELECT department_id, title, COUNT(*) as count FROM job_titles GROUP BY department_id, title; |
What is the minimum number of electric scooter rentals in Paris in a day? | CREATE TABLE if not exists Scooters (id INT,city VARCHAR(20),rentals INT,date DATE); INSERT INTO Scooters (id,city,rentals,date) VALUES (1,'Paris',3000,'2022-03-15'),(2,'Paris',2800,'2022-03-16'),(3,'Berlin',2000,'2022-03-15'); | SELECT MIN(rentals) FROM Scooters WHERE city = 'Paris'; |
Find the percentage change in water consumption in rural areas from 2019 to 2020. | CREATE TABLE rural_water_consumption (id INT,city VARCHAR(50),year INT,monthly_consumption FLOAT); INSERT INTO rural_water_consumption (id,city,year,monthly_consumption) VALUES (1,'Smalltown',2019,120000),(2,'Smalltown',2020,130000); | SELECT (SUM(t2.monthly_consumption) - SUM(t1.monthly_consumption)) * 100.0 / SUM(t1.monthly_consumption) FROM rural_water_consumption t1, rural_water_consumption t2 WHERE t1.city = t2.city AND t1.year = 2019 AND t2.year = 2020; |
Insert a new row into the 'charging_stations' table with the following values: 'Rivian', 'Los Angeles', 'Level 3', 25 | CREATE TABLE charging_stations (company VARCHAR(255),city VARCHAR(255),charging_level VARCHAR(255),count INT); | INSERT INTO charging_stations (company, city, charging_level, count) VALUES ('Rivian', 'Los Angeles', 'Level 3', 25); |
Which fans have not attended any events? | CREATE TABLE fans (fan_id INT,state VARCHAR(255)); CREATE TABLE events (fan_id INT,event_id INT); INSERT INTO fans (fan_id,state) VALUES (1,'Texas'),(2,'California'),(3,'Texas'),(4,'New York'),(5,'California'),(6,'California'),(7,'Texas'),(8,'Texas'),(9,'New York'),(10,'New York'); INSERT INTO events (fan_id,event_id) VALUES (1,101),(1,102),(1,103),(2,101),(3,102),(3,103),(3,104),(4,101),(5,101),(5,102),(5,103),(5,104),(5,105); | SELECT f.fan_id, f.state FROM fans f LEFT JOIN events e ON f.fan_id = e.fan_id WHERE e.fan_id IS NULL; |
Remove the 'Data Breach' record from the 'incident_types' table | CREATE TABLE incident_types (id INT,name VARCHAR,description TEXT); INSERT INTO incident_types (id,name,description) VALUES (1,'Data Breach','Unauthorized access to data'); | DELETE FROM incident_types WHERE name='Data Breach'; |
Find the teams with the greatest difference in ticket sales between home and away matches. | CREATE TABLE teams (team_id INT,team_name VARCHAR(100)); INSERT INTO teams (team_id,team_name) VALUES (1,'Barcelona'),(2,'Bayern Munich'); CREATE TABLE matches (match_id INT,team_home_id INT,team_away_id INT,tickets_sold INT); INSERT INTO matches (match_id,team_home_id,team_away_id,tickets_sold) VALUES (1,1,2,5000),(2,2,1,6000); | SELECT team_name, home_sales - away_sales as diff FROM (SELECT team_home_id, SUM(tickets_sold) as home_sales FROM matches GROUP BY team_home_id) home_sales JOIN (SELECT team_away_id, SUM(tickets_sold) as away_sales FROM matches GROUP BY team_away_id) away_sales JOIN teams t ON home_sales.team_home_id = t.team_id OR away_sales.team_away_id = t.team_id ORDER BY diff DESC; |
What is the total salary cost for each department, sorted alphabetically by department name? | CREATE TABLE employee (id INT,name VARCHAR(50),department VARCHAR(50),salary INT); INSERT INTO employee (id,name,department,salary) VALUES (1,'John Doe','Engineering',50000),(2,'Jane Smith','Engineering',55000),(3,'Mike Johnson','Manufacturing',60000),(4,'Alice Williams','Manufacturing',65000),(5,'Bob Brown','Quality',45000),(6,'Charlie Green','Quality',40000); | SELECT department, SUM(salary) as total_salary FROM employee GROUP BY department ORDER BY department; |
How many policyholders have never filed a claim? | CREATE TABLE claims (claim_id INT,policyholder_id INT); INSERT INTO claims (claim_id,policyholder_id) VALUES (1,1),(2,3),(3,2),(4,1); CREATE TABLE policyholders (policyholder_id INT); INSERT INTO policyholders (policyholder_id) VALUES (1),(2),(3),(4),(5); | SELECT COUNT(DISTINCT ph.policyholder_id) as num_policyholders_no_claims FROM policyholders ph LEFT JOIN claims c ON ph.policyholder_id = c.policyholder_id WHERE c.claim_id IS NULL; |
What is the average donation amount per donor in the United States, for donations made in 2021? | CREATE TABLE donors (id INT,name TEXT,country TEXT,donation_amount DECIMAL,donation_date DATE); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (1,'John Doe','USA',50.00,'2021-05-12'); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (2,'Jane Smith','USA',100.00,'2021-08-16'); | SELECT AVG(donation_amount) FROM donors WHERE country = 'USA' AND YEAR(donation_date) = 2021; |
What is the maximum budget for a single public works project in the state of Texas? | CREATE TABLE project (id INT PRIMARY KEY,name TEXT,budget INT,status TEXT,city_id INT,FOREIGN KEY (city_id) REFERENCES city(id)); | SELECT MAX(budget) FROM project WHERE city_id IN (SELECT id FROM city WHERE state = 'TX') AND status = 'Open'; |
What is the average trip length for bus rides in London during peak hours? | CREATE TABLE bus_trips (trip_id INT,start_date DATETIME,end_date DATETIME,route_id INT,total_amount FLOAT); INSERT INTO bus_trips VALUES (1,'2022-03-01 07:30:00','2022-03-01 08:00:00',45,2.50); | SELECT AVG(EXTRACT(MINUTE FROM end_date - start_date)) FROM bus_trips WHERE EXTRACT(HOUR FROM start_date) BETWEEN 7 AND 9 OR EXTRACT(HOUR FROM start_date) BETWEEN 16 AND 19; |
List all suppliers and their products that have potential allergens. | CREATE TABLE Allergens (ProductID INT,Allergen VARCHAR(100)); INSERT INTO Allergens (ProductID,Allergen) VALUES (1,'Nuts'); INSERT INTO Allergens (ProductID,Allergen) VALUES (2,'Gluten'); | SELECT S.SupplierID, S.SupplierName, P.ProductName FROM Suppliers S INNER JOIN Products P ON S.SupplierID = P.SupplierID INNER JOIN Allergens A ON P.ProductID = A.ProductID; |
Get the average program budget for programs in the 'Health' category | CREATE TABLE programs (id INT,name VARCHAR(50),category VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO programs (id,name,category,budget) VALUES (1,'Primary Healthcare','Health',25000.00); INSERT INTO programs (id,name,category,budget) VALUES (2,'Secondary Healthcare','Health',30000.00); INSERT INTO programs (id,name,category,budget) VALUES (3,'Education','Education',75000.00); | SELECT category, AVG(budget) as avg_budget FROM programs WHERE category = 'Health' GROUP BY category; |
What is the average landfill capacity in the 'Industrial' area? | CREATE TABLE IndustrialLandfills (id INT,area VARCHAR(20),capacity INT); INSERT INTO IndustrialLandfills (id,area,capacity) VALUES (1,'Industrial',4000),(2,'Industrial',5000); | SELECT AVG(capacity) FROM IndustrialLandfills WHERE area = 'Industrial'; |
What is the 5-year trend of sea surface temperature in the Atlantic Ocean? | CREATE TABLE sea_surface_temperature (ocean VARCHAR(255),date DATE,temperature FLOAT); INSERT INTO sea_surface_temperature (ocean,date,temperature) VALUES ('Atlantic','2017-01-01',20.5),('Atlantic','2017-07-01',21.2),('Atlantic','2018-01-01',20.8),('Atlantic','2018-07-01',21.1),('Atlantic','2019-01-01',20.7),('Atlantic','2019-07-01',21.0),('Atlantic','2020-01-01',20.6),('Atlantic','2020-07-01',20.9),('Atlantic','2021-01-01',20.5),('Atlantic','2021-07-01',20.8); | SELECT date, temperature, ROW_NUMBER() OVER (ORDER BY date) as rn, AVG(temperature) OVER (ORDER BY date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW) as moving_avg FROM sea_surface_temperature WHERE ocean = 'Atlantic'; |
What is the current population of the 'Oak' species? | CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(255),population INT); INSERT INTO species (id,name,population) VALUES (1,'Spruce',5000000); INSERT INTO species (id,name,population) VALUES (2,'Pine',6000000); INSERT INTO species (id,name,population) VALUES (3,'Oak',4000000); | SELECT population FROM species WHERE name = 'Oak'; |
List types of disasters and their frequency in 'disaster_data' table. | CREATE TABLE disaster_data (id INT,year INT,type VARCHAR(50),location VARCHAR(50)); | SELECT type, COUNT(*) as frequency FROM disaster_data GROUP BY type; |
What is the maximum length of a railroad in India? | CREATE TABLE railroads (id INT,name VARCHAR(255),location VARCHAR(255),length FLOAT); INSERT INTO railroads (id,name,location,length) VALUES (1,'Western Railway','India',1435),(2,'Eastern Railway','India',2202); | SELECT MAX(length) FROM railroads WHERE location = 'India'; |
What are the names of eco-friendly hotels in Barcelona with a rating above 4? | CREATE TABLE hotels (id INT,name TEXT,city TEXT,rating FLOAT); INSERT INTO hotels (id,name,city,rating) VALUES (1,'Eco Hotel Barcelona','Barcelona',4.3),(2,'Green Hotel Barcelona','Barcelona',4.1); | SELECT name FROM hotels WHERE city = 'Barcelona' AND rating > 4 AND (name = 'Eco Hotel Barcelona' OR name = 'Green Hotel Barcelona'); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.