instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the percentage of transactions with a value greater than 100.00 in the 'creative_ai' application? | CREATE TABLE users (user_id INT,app VARCHAR(20)); INSERT INTO users (user_id,app) VALUES (1,'creative_ai'),(2,'algorithmic_fairness'),(3,'explainable_ai'); CREATE TABLE transactions (transaction_id INT,user_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,user_id,amount) VALUES (1,1,50.00),(2,1,75.00),(3,2,30.00),(4,3,100.00),(5,1,60.00); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM transactions)::DECIMAL) as percentage FROM transactions INNER JOIN users ON transactions.user_id = users.user_id WHERE users.app = 'creative_ai' AND amount > 100.00; |
How many songs are in the 'Jazz' genre that were released between 2000 and 2010? | CREATE TABLE genres (genre_id INT,genre VARCHAR(50)); INSERT INTO genres (genre_id,genre) VALUES (1,'Pop'),(2,'Rock'),(3,'Hip Hop'),(4,'Jazz'); CREATE TABLE songs (song_id INT,song_name VARCHAR(100),release_year INT,genre_id INT); INSERT INTO songs (song_id,song_name,release_year,genre_id) VALUES (1,'Shape of You',2017,1),(2,'Thinking Out Loud',2014,1),(3,'Bohemian Rhapsody',1975,2),(4,'Smells Like Teen Spirit',2001,2),(5,'No Woman No Cry',1974,4),(6,'Round Midnight',2005,4); | SELECT COUNT(*) FROM songs WHERE genre_id = (SELECT genre_id FROM genres WHERE genre = 'Jazz') AND release_year BETWEEN 2000 AND 2010; |
What is the maximum price of yttrium produced in India? | CREATE TABLE yttrium_production (country VARCHAR(255),price DECIMAL(10,2)); INSERT INTO yttrium_production (country,price) VALUES ('India',250.50); | SELECT MAX(price) FROM yttrium_production WHERE country = 'India'; |
What is the average energy consumption per square foot for green buildings in each city, partitioned by building type and ordered by the average consumption? | CREATE TABLE CityGreenBuildings (BuildingID INT,BuildingName VARCHAR(255),City VARCHAR(255),BuildingType VARCHAR(255),EnergyConsumption FLOAT,Area FLOAT); INSERT INTO CityGreenBuildings (BuildingID,BuildingName,City,BuildingType,EnergyConsumption,Area) VALUES (1,'EcoTower','New York','Residential',12000,2000),(2,'GreenHeights','Los Angeles','Commercial',20000,5000),(3,'SustainableHQ','Chicago','Residential',15000,3000); | SELECT City, BuildingType, AVG(EnergyConsumption/Area) OVER (PARTITION BY City, BuildingType) AS Avg_Consumption_Per_Sqft FROM CityGreenBuildings ORDER BY Avg_Consumption_Per_Sqft DESC; |
What is the average billing amount for clients by attorney in the South region? | CREATE TABLE AttorneyBilling (AttorneyID INT,AttorneyName VARCHAR(50),Region VARCHAR(50),BillingAmount DECIMAL(10,2)); INSERT INTO AttorneyBilling (AttorneyID,AttorneyName,Region,BillingAmount) VALUES (1,'Jane Doe','South',7000.00),(2,'John Smith','South',8000.00),(3,'Sara Connor','South',9000.00),(4,'David Kim','South',6000.00); | SELECT AttorneyName, AVG(BillingAmount) AS AvgBillingAmount FROM AttorneyBilling WHERE Region = 'South' GROUP BY AttorneyName; |
Create a table for storing mental health parity complaints by ethnicity and year, with a unique ID. | CREATE TABLE mental_health_parity_complaints (id INT PRIMARY KEY AUTO_INCREMENT,ethnicity VARCHAR(50),year INT,complaints INT); | INSERT INTO mental_health_parity_complaints (ethnicity, year, complaints) VALUES ('Hispanic', 2021, 220), ('African American', 2021, 180), ('Caucasian', 2021, 280); |
How many patients were diagnosed with depression in 2021? | CREATE TABLE diagnoses (patient_id INT,diagnosis_date DATE,condition VARCHAR(20)); INSERT INTO diagnoses (patient_id,diagnosis_date,condition) VALUES (1,'2021-04-15','depression'),(2,'2020-12-20','anxiety'),(3,'2021-06-05','depression'); | SELECT COUNT(*) FROM diagnoses WHERE condition = 'depression' AND YEAR(diagnosis_date) = 2021; |
Find the number of times each volunteer has donated, ordered by the number of donations in descending order? | CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),DonationDate DATE); INSERT INTO Donors (DonorID,DonorName,DonationDate) VALUES (1,'John Doe','2022-01-01'),(2,'Jane Smith','2022-01-15'),(3,'Alice Johnson','2022-02-01'),(1,'John Doe','2022-02-10'),(4,'Bob Brown','2022-03-01'),(2,'Jane Smith','2022-03-15'),(1,'John Doe','2022-04-01'),(5,'Charlie Davis','2022-04-10'); | SELECT DonorName, COUNT(*) as Donations FROM Donors GROUP BY DonorName ORDER BY Donations DESC; |
Delete records related to seal hunting from the arctic_resources table. | CREATE TABLE arctic_resources (id INT,resource VARCHAR(50),type VARCHAR(20)); INSERT INTO arctic_resources (id,resource,type) VALUES (1,'oil','drilling'),(2,'whale','hunting'),(3,'seal','hunting'); | DELETE FROM arctic_resources WHERE type = 'hunting' AND resource = 'seal'; |
What is the average labor productivity in the mining industry in Australia, by state, for the last 3 years? | CREATE TABLE AustralianLaborProductivity (state TEXT,year INT,industry TEXT,productivity FLOAT); INSERT INTO AustralianLaborProductivity (state,year,industry,productivity) VALUES ('Queensland',2019,'Mining',120000),('Queensland',2020,'Mining',125000),('Queensland',2021,'Mining',130000),('New South Wales',2019,'Mining',110000),('New South Wales',2020,'Mining',115000),('New South Wales',2021,'Mining',120000),('Western Australia',2019,'Mining',135000),('Western Australia',2020,'Mining',140000),('Western Australia',2021,'Mining',145000); | SELECT context.state, AVG(context.productivity) as avg_productivity FROM AustralianLaborProductivity context WHERE context.industry = 'Mining' AND context.year BETWEEN 2019 AND 2021 GROUP BY context.state; |
How many attendees were there at events with a 'Music' category in California? | CREATE TABLE Events (event_id INT,event_name VARCHAR(50),category VARCHAR(50),state VARCHAR(50),attendee_count INT); INSERT INTO Events (event_id,event_name,category,state,attendee_count) VALUES (1,'Music Festival','Music','California',2000),(2,'Art Exhibition','Art','California',1500); | SELECT SUM(attendee_count) FROM Events WHERE category = 'Music' AND state = 'California'; |
Identify countries in the Atlantic Ocean region with more than 5 marine research stations. | CREATE TABLE marine_research_stations (id INT,country TEXT,region TEXT,num_stations INT); INSERT INTO marine_research_stations (id,country,region,num_stations) VALUES (1,'Canada','Atlantic',7),(2,'USA','Atlantic',8),(3,'Mexico','Atlantic',3); | SELECT country FROM marine_research_stations WHERE region = 'Atlantic' GROUP BY country HAVING COUNT(*) > 5; |
How many content items were produced in each month of 2022, broken down by content type? | CREATE TABLE content (id INT,created_at TIMESTAMP); INSERT INTO content (id,created_at) VALUES (1,'2022-01-01 10:00:00'),(2,'2022-01-15 14:30:00'),(3,'2022-02-03 09:15:00'),(4,'2022-03-05 16:45:00'),(5,'2022-03-20 11:00:00'),(6,'2022-04-01 13:30:00'),(7,'2022-04-15 17:00:00'),(8,'2022-05-03 10:45:00'),(9,'2022-05-17 15:00:00'),(10,'2022-06-01 11:30:00'); | SELECT EXTRACT(MONTH FROM created_at) AS month, type, COUNT(*) AS num_content FROM content, (SELECT 'article' AS type UNION ALL SELECT 'video') types GROUP BY month, type ORDER BY month, type; |
What is the distribution of planting dates per crop in 'farm_activities' table? | CREATE TABLE farm_activities (region VARCHAR(50),crop VARCHAR(50),planting_date DATE); INSERT INTO farm_activities VALUES ('West Coast','Wheat','2022-04-01'); INSERT INTO farm_activities VALUES ('West Coast','Corn','2022-05-01'); INSERT INTO farm_activities VALUES ('East Coast','Rice','2022-06-01'); INSERT INTO farm_activities VALUES ('East Coast','Wheat','2022-04-01'); INSERT INTO farm_activities VALUES ('East Coast','Corn','2022-05-01'); | SELECT crop, planting_date, COUNT(*) OVER (PARTITION BY crop, planting_date) AS count FROM farm_activities; |
Calculate the total installed capacity (in MW) of wind projects for the year 2020 | CREATE TABLE wind_projects (project_id INT,project_name VARCHAR(255),location VARCHAR(255),installed_capacity INT,commissioning_date DATE); INSERT INTO wind_projects (project_id,project_name,location,installed_capacity,commissioning_date) VALUES (1,'Wind Farm A','California',150,'2018-05-01'); INSERT INTO wind_projects (project_id,project_name,location,installed_capacity,commissioning_date) VALUES (2,'Wind Farm B','Texas',200,'2019-11-15'); INSERT INTO wind_projects (project_id,project_name,location,installed_capacity,commissioning_date) VALUES (3,'Wind Farm C','Oklahoma',120,'2020-07-20'); | SELECT SUM(installed_capacity) FROM wind_projects WHERE YEAR(commissioning_date) = 2020 AND project_name LIKE '%Wind%'; |
What is the total area of forests in each country? | CREATE TABLE country_forest (country VARCHAR(255),forest_name VARCHAR(255),area_ha INT); INSERT INTO country_forest (country,forest_name,area_ha) VALUES ('Canada','Forest1',5000),('Canada','Forest2',7000),('USA','Forest3',8000),('USA','Forest4',6000); | SELECT country, SUM(area_ha) FROM country_forest GROUP BY country; |
What percentage of sustainable fabric sourcing is done from African countries? | CREATE TABLE FabricSourcing (Brand VARCHAR(255),Country VARCHAR(255),FabricType VARCHAR(255),Quantity INT); INSERT INTO FabricSourcing (Brand,Country,FabricType,Quantity) VALUES ('BrandD','EG','Organic Cotton',5000),('BrandE','NG','Recycled Polyester',7000),('BrandF','KE','Tencel',6000); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM FabricSourcing)) AS Percentage FROM FabricSourcing WHERE Country IN ('EG', 'NG', 'KE'); |
Display the number of employees who completed workforce development training, categorized by their job role. | CREATE TABLE employees (employee_id INT,employee_name VARCHAR(50),job_role VARCHAR(50)); INSERT INTO employees (employee_id,employee_name,job_role) VALUES (1,'John Doe','Engineer'),(2,'Jane Smith','Manager'),(3,'Mike Johnson','Technician'),(4,'Sara Williams','Operator'); CREATE TABLE trainings (training_id INT,employee_id INT,training_topic VARCHAR(50),completed INT); INSERT INTO trainings (training_id,employee_id,training_topic,completed) VALUES (1,1,'Safety Training',1),(2,1,'Automation Training',1),(3,2,'Quality Control Training',1),(4,2,'Sustainability Training',1),(5,3,'Robotics Training',1),(6,3,'Cybersecurity Training',1),(7,4,'Safety Training',0),(8,4,'Automation Training',0); | SELECT e.job_role, COUNT(t.employee_id) as completed_trainings FROM employees e JOIN trainings t ON e.employee_id = t.employee_id WHERE t.completed = 1 GROUP BY e.job_role; |
How many animals are there in total in each type of habitat? | CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),habitat_type VARCHAR(20),population INT); | SELECT habitat_type, SUM(population) FROM animal_population GROUP BY habitat_type; |
Find the number of AI researchers who have published papers, ordered by the number of papers in descending order, and include their country. | CREATE TABLE ai_researchers (id INT,name VARCHAR(100),gender VARCHAR(10),country VARCHAR(50),published_papers INT); INSERT INTO ai_researchers (id,name,gender,country,published_papers) VALUES (1,'Alice','Female','USA',3),(2,'Bob','Male','Canada',0),(3,'Charlotte','Female','UK',2),(4,'David','Male','USA',1),(5,'Eva','Female','Germany',0); | SELECT name, country, SUM(published_papers) AS total_papers FROM ai_researchers WHERE published_papers > 0 GROUP BY name, country ORDER BY total_papers DESC; |
What is the average funding per arts education program in the Pacific region? | CREATE TABLE arts_education_programs (id INT,program_name VARCHAR(255),region VARCHAR(255),funding FLOAT); | SELECT region, AVG(funding) as avg_funding FROM arts_education_programs WHERE region = 'Pacific' GROUP BY region; |
What is the total quantity of sustainable materials used by manufacturers located in Asia? | CREATE TABLE Manufacturers (manufacturer_id INT,name TEXT,location TEXT); INSERT INTO Manufacturers (manufacturer_id,name,location) VALUES (1,'Manufacturer A','Asia'),(2,'Manufacturer B','Europe'); CREATE TABLE SustainableMaterials (material_id INT,manufacturer_id INT,quantity INT); INSERT INTO SustainableMaterials (material_id,manufacturer_id,quantity) VALUES (1,1,500),(2,1,300),(3,2,700); | SELECT SUM(quantity) FROM SustainableMaterials INNER JOIN Manufacturers ON SustainableMaterials.manufacturer_id = Manufacturers.manufacturer_id WHERE location = 'Asia'; |
How many employees work in the 'food' sector? | CREATE TABLE if not exists employment (id INT,industry VARCHAR,number_of_employees INT); INSERT INTO employment (id,industry,number_of_employees) VALUES (1,'manufacturing',5000),(2,'technology',8000),(3,'healthcare',7000),(4,'retail',6000),(5,'education',9000),(6,'finance',10000),(7,'government',11000),(8,'food',12000); | SELECT SUM(number_of_employees) FROM employment WHERE industry = 'food'; |
What is the total property size in Philadelphia for properties built before 2000, excluding co-owned properties? | CREATE TABLE properties (property_id INT,size FLOAT,city VARCHAR(20),build_year INT,co_ownership BOOLEAN); INSERT INTO properties (property_id,size,city,build_year,co_ownership) VALUES (1,2000,'Philadelphia',1995,false); INSERT INTO properties (property_id,size,city,build_year,co_ownership) VALUES (2,1800,'Philadelphia',2005,true); | SELECT SUM(size) FROM properties WHERE city = 'Philadelphia' AND build_year < 2000 AND co_ownership = false; |
What is the maximum and minimum speed of vessels in the 'Cruise Ship' category in the last year? | CREATE TABLE vessels (id INT,name TEXT,type TEXT,speed FLOAT); INSERT INTO vessels (id,name,type,speed) VALUES (1,'Cruise Ship A','Cruise Ship',25),(2,'Cruise Ship B','Cruise Ship',30),(3,'Cruise Ship C','Cruise Ship',35); | SELECT vessels.type, MAX(vessels.speed) AS max_speed, MIN(vessels.speed) AS min_speed FROM vessels WHERE vessels.type = 'Cruise Ship' AND vessels.id >= DATEADD('year', -1, CURRENT_DATE) GROUP BY vessels.type; |
List the top 3 pollutants by total weight discharged in the Pacific ocean | CREATE TABLE pacific_pollution (pollutant_id INT,pollutant_name VARCHAR(255),weight DECIMAL(10,2),location VARCHAR(255)); CREATE VIEW pacific_pollution_pacific AS SELECT * FROM pacific_pollution WHERE location LIKE '%Pacific%'; | SELECT pollutant_name, SUM(weight) FROM pacific_pollution_pacific GROUP BY pollutant_name ORDER BY SUM(weight) DESC LIMIT 3; |
What is the average ticket price for concerts in the state of New York? | CREATE TABLE concert_sales (id INT,state VARCHAR,price DECIMAL); | SELECT AVG(price) FROM concert_sales WHERE state = 'New York'; |
What is the total revenue generated from broadband subscribers in the APAC region, for the year 2021? | CREATE TABLE subscribers (subscriber_id INT,subscriber_type VARCHAR(50),region VARCHAR(50)); CREATE TABLE sales (sale_id INT,subscriber_id INT,sale_date DATE,revenue DECIMAL(5,2)); | SELECT SUM(s.revenue) AS total_revenue FROM subscribers s JOIN sales ON s.subscriber_id = sales.subscriber_id WHERE s.subscriber_type = 'Broadband' AND s.region = 'APAC' AND YEAR(sale_date) = 2021; |
How many hours were spent by volunteers on each program in 2021? | CREATE TABLE volunteer_hours (volunteer_id INT,program_id INT,hours_spent INT,hours_date DATE); CREATE TABLE programs (program_id INT,program_name TEXT); INSERT INTO programs VALUES (1,'Food Bank'); INSERT INTO programs VALUES (2,'Education Support'); | SELECT program_id, program_name, SUM(hours_spent) as total_hours FROM volunteer_hours JOIN programs ON volunteer_hours.program_id = programs.program_id WHERE YEAR(hours_date) = 2021 GROUP BY program_id; |
Delete player records with a 'country' of 'Canada' from the 'players' table | CREATE TABLE players (player_id INT,player_name VARCHAR(50),country VARCHAR(20)); | DELETE FROM players WHERE country = 'Canada'; |
Show the funding allocated for climate mitigation and adaptation projects in Africa per year. | CREATE TABLE climate_projects (project_type TEXT,year INTEGER,funding INTEGER);INSERT INTO climate_projects (project_type,year,funding) VALUES ('Climate Mitigation',2018,3000000),('Climate Adaptation',2019,4000000); | SELECT project_type, year, SUM(funding) as total_funding FROM climate_projects GROUP BY project_type, year; |
Which regions have the most fair trade production? | CREATE TABLE production (product_id INT,region VARCHAR(20),is_fair_trade BOOLEAN); INSERT INTO production (product_id,region,is_fair_trade) VALUES (1,'North America',TRUE),(2,'South America',FALSE),(3,'Asia',TRUE),(4,'Europe',FALSE); | SELECT region, SUM(is_fair_trade) AS total_fair_trade FROM production GROUP BY region; |
What's the total number of traditional art performances by language preservation groups in France and Italy? | CREATE TABLE ArtPerformances (id INT,group_id INT,location VARCHAR(50),type VARCHAR(50));CREATE TABLE LanguagePreservationGroups (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO ArtPerformances (id,group_id,location,type) VALUES (1,101,'France','Traditional Dance'),(2,101,'Italy','Traditional Song'),(3,102,'France','Traditional Song'),(4,102,'Italy','Traditional Dance'); INSERT INTO LanguagePreservationGroups (id,name,location) VALUES (101,'Breton Language Group','France'),(102,'Sicilian Language Group','Italy'); | SELECT COUNT(*) FROM ArtPerformances ap INNER JOIN LanguagePreservationGroups lpg ON ap.group_id = lpg.id WHERE ap.type IN ('Traditional Dance', 'Traditional Song') AND lpg.location IN ('France', 'Italy'); |
Find the total number of protected species in each region. | CREATE TABLE Species(species_id INT,species_name TEXT,region TEXT); INSERT INTO Species (species_id,species_name,region) VALUES (1,'Eagle','Region A'),(2,'Wolf','Region A'),(3,'Bear','Region B'); | SELECT region, COUNT(*) FROM Species WHERE species_name IN ('Eagle', 'Wolf', 'Bear') GROUP BY region; |
List all the bridges in India with their inspection dates and maintenance records. | CREATE TABLE Bridges (BridgeID INT,Name VARCHAR(255),Location VARCHAR(255),ConstructionDate DATE); INSERT INTO Bridges VALUES (1,'Golden Gate Bridge','California'); INSERT INTO Bridges VALUES (2,'Bandra-Worli Sea Link','Mumbai,India'); CREATE TABLE Inspections (InspectionID INT,BridgeID INT,InspectionDate DATE); INSERT INTO Inspections VALUES (1,1,'2018-06-15'); INSERT INTO Inspections VALUES (2,2,'2020-12-28'); CREATE TABLE Maintenance (MaintenanceID INT,BridgeID INT,MaintenanceDate DATE,MaintenanceType VARCHAR(255)); INSERT INTO Maintenance VALUES (1,1,'2019-08-12','Concrete Repair'); INSERT INTO Maintenance VALUES (2,2,'2021-04-10','Drainage Upgrade'); | SELECT Bridges.Name, Inspections.InspectionDate, Maintenance.MaintenanceDate, Maintenance.MaintenanceType FROM Bridges LEFT JOIN Inspections ON Bridges.BridgeID = Inspections.BridgeID FULL OUTER JOIN Maintenance ON Bridges.BridgeID = Maintenance.BridgeID WHERE Bridges.Location = 'India'; |
How many players are there who are 25 years old or older? | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),VRGamePlayer BOOLEAN); INSERT INTO Players (PlayerID,Age,Gender,VRGamePlayer) VALUES (1,25,'Male',true),(2,30,'Female',false),(3,22,'Male',true); | SELECT COUNT(*) FROM Players WHERE Age >= 25; |
What is the maximum duration of a 'Spin' class? | CREATE TABLE Classes (ClassID INT,ClassType VARCHAR(20),Duration INT); INSERT INTO Classes (ClassID,ClassType,Duration) VALUES (1,'Spin',60),(2,'Pilates',45),(3,'Spin',45); | SELECT MAX(Duration) FROM Classes WHERE ClassType = 'Spin'; |
How many renewable energy projects are there in total in the 'renewable_energy_projects' table, and what is the average installed capacity of these projects? | CREATE TABLE renewable_energy_projects (id INT,project_type VARCHAR(255),country VARCHAR(255),name VARCHAR(255),capacity FLOAT); INSERT INTO renewable_energy_projects (id,project_type,country,name,capacity) VALUES (1,'Wind','Germany','Windfarm A',50.5),(2,'Solar','California','Solar Plant A',25.6); | SELECT COUNT(*) as project_count, AVG(capacity) as avg_capacity FROM renewable_energy_projects; |
How many food safety violations were recorded for each restaurant in the month of May 2022? | CREATE TABLE restaurant_inspections (restaurant_id INT,inspection_date DATE,violation_count INT); INSERT INTO restaurant_inspections (restaurant_id,inspection_date,violation_count) VALUES (1,'2022-05-01',3),(1,'2022-05-02',2),(2,'2022-05-01',1),(3,'2022-05-01',0),(3,'2022-05-02',1); | SELECT restaurant_id, SUM(violation_count) FROM restaurant_inspections WHERE EXTRACT(MONTH FROM inspection_date) = 5 AND EXTRACT(YEAR FROM inspection_date) = 2022 GROUP BY restaurant_id; |
What is the average light intensity in 'Greenhouse8' for the month of January? | CREATE TABLE Greenhouse8 (date DATE,light_intensity FLOAT); | SELECT AVG(light_intensity) FROM Greenhouse8 WHERE EXTRACT(MONTH FROM date) = 1; |
Find the top 5 defense contractors with the highest number of awarded contracts in the last 5 years. | CREATE TABLE contractors(id INT,company VARCHAR(50),num_contracts INT,contract_date DATE); | SELECT company, num_contracts FROM (SELECT company, COUNT(*) AS num_contracts FROM contractors WHERE contract_date >= DATE(NOW()) - INTERVAL 5 YEAR GROUP BY company ORDER BY num_contracts DESC) AS top_contractors LIMIT 5; |
List the names and genders of players who have played games on both PC and Mobile platforms. | CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Gender VARCHAR(10),Platform VARCHAR(10)); | SELECT p1.PlayerName, p1.Gender FROM Players p1 INNER JOIN Players p2 ON p1.PlayerName = p2.PlayerName WHERE p1.Platform = 'PC' AND p2.Platform = 'Mobile'; |
How many social impact investments were made in 'Asia' in 2021? | CREATE TABLE investments (id INT,location VARCHAR(50),investment_year INT,investment_type VARCHAR(20)); INSERT INTO investments (id,location,investment_year,investment_type) VALUES (1,'Asia',2021,'social impact'),(2,'Europe',2020,'social impact'),(3,'Asia',2021,'traditional'),(4,'North America',2022,'social impact'); | SELECT COUNT(*) FROM investments WHERE location = 'Asia' AND investment_year = 2021 AND investment_type = 'social impact'; |
What is the average time to complete military equipment maintenance for each type of equipment in the last year? | CREATE TABLE maintenance_duration (id INT,equipment_type VARCHAR(255),maintenance_time TIME,date DATE); | SELECT equipment_type, AVG(maintenance_time) FROM maintenance_duration WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) GROUP BY equipment_type; |
Find the total biomass of fish for each salmon farm in October. | CREATE TABLE farm (id INT,name VARCHAR(50)); CREATE TABLE farm_stock (farm_id INT,species VARCHAR(50),quantity INT,biomass FLOAT); INSERT INTO farm VALUES (1,'North Coast Farm'),(2,'South Channel Farm'); INSERT INTO farm_stock VALUES (1,'Atlantic Salmon',2000,8000),(1,'Coho Salmon',1000,4000),(2,'Atlantic Salmon',3000,12000),(2,'Pacific Salmon',500,2000); | SELECT f.name, SUM(fs.biomass) as total_biomass FROM farm f INNER JOIN farm_stock fs ON f.id = fs.farm_id WHERE MONTH(fs.date) = 10 GROUP BY f.id; |
What is the percentage of electric trains in the New York City subway system? | CREATE TABLE nyc_subway(id INT,train_number INT,line VARCHAR(20),electric BOOLEAN); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM nyc_subway) AS percentage FROM nyc_subway WHERE electric = TRUE; |
What is the total volume of recycled water in wastewater treatment plants in the city of Los Angeles for each month in the year 2022? | CREATE TABLE recycled_water_treatment (plant_id INT,city VARCHAR(20),recycled_volume FLOAT,day INT,month INT,year INT); INSERT INTO recycled_water_treatment (plant_id,city,recycled_volume,day,month,year) VALUES (1,'Los Angeles',800000,1,1,2022); INSERT INTO recycled_water_treatment (plant_id,city,recycled_volume,day,month,year) VALUES (2,'Los Angeles',900000,2,1,2022); | SELECT month, SUM(recycled_volume) FROM recycled_water_treatment WHERE city = 'Los Angeles' GROUP BY month; |
What are the names of provinces in South Africa with more than 5 million residents, and what are their populations? | CREATE TABLE south_africa_provinces (name TEXT,population INTEGER); INSERT INTO south_africa_provinces (name,population) VALUES ('Gauteng',15468000),('KwaZulu-Natal',11471000); | SELECT name, population FROM south_africa_provinces WHERE population > 5000000; |
What is the percentage of factories in each country that follow fair labor practices? | CREATE TABLE labor_practices (country VARCHAR(255),factory_id INT,ethical_practice BOOLEAN); INSERT INTO labor_practices (country,factory_id,ethical_practice) VALUES ('US',1,TRUE),('US',2,FALSE),('China',1,FALSE),('China',2,FALSE),('Bangladesh',1,TRUE),('Bangladesh',2,TRUE); | SELECT country, 100.0 * COUNT(*) FILTER (WHERE ethical_practice = TRUE) / COUNT(*) as fair_labor_percentage FROM labor_practices GROUP BY country; |
Insert a new well named 'NEW_WELL' with a production quantity of 1000 in the 'TEST_WELLS' table. | CREATE TABLE TEST_WELLS (WELL_NAME VARCHAR(255),PRODUCTION_QTY INT); | INSERT INTO TEST_WELLS (WELL_NAME, PRODUCTION_QTY) VALUES ('NEW_WELL', 1000); |
What is the average word count for news articles published in 2021? | CREATE TABLE news_articles_extended (title VARCHAR(100),publication DATE,word_count INT); INSERT INTO news_articles_extended (title,publication,word_count) VALUES ('Article 1','2021-01-01',1200),('Article 2','2021-02-03',800),('Article 3','2021-02-15',1500),('Article 4','2021-03-05',900),('Article 5','2021-04-10',700); | SELECT AVG(word_count) FROM news_articles_extended WHERE EXTRACT(YEAR FROM publication) = 2021; |
What is the average budget allocated for each animal species in the wildlife preservation program? | CREATE TABLE animal_species (species_id INT,species_name VARCHAR(50));CREATE TABLE budget_allocations (allocation_id INT,species_id INT,allocation_amount DECIMAL(10,2)); INSERT INTO animal_species (species_id,species_name) VALUES (1,'Tiger'),(2,'Elephant'),(3,'Rhinoceros'); INSERT INTO budget_allocations (allocation_id,species_id,allocation_amount) VALUES (101,1,5000.00),(102,2,7500.00),(103,3,10000.00); | SELECT s.species_name, AVG(ba.allocation_amount) AS avg_allocation FROM animal_species s JOIN budget_allocations ba ON s.species_id = ba.species_id GROUP BY s.species_name; |
Which lifelong learning programs have the highest and lowest enrollment? | CREATE TABLE lifelong_learning_enrollment (program_id INT,enrollment INT); INSERT INTO lifelong_learning_enrollment (program_id,enrollment) VALUES (1,50),(2,75),(3,100),(4,25); CREATE VIEW top_enrollment AS SELECT program_id,enrollment FROM lifelong_learning_enrollment WHERE enrollment IN (SELECT MAX(enrollment) FROM lifelong_learning_enrollment) UNION SELECT program_id,enrollment FROM lifelong_learning_enrollment WHERE enrollment IN (SELECT MIN(enrollment) FROM lifelong_learning_enrollment); | SELECT program_id FROM top_enrollment; |
What is the average investment in agricultural innovation for farmers in 'rural_development' database, grouped by country and year? | CREATE TABLE farmers (id INT,name TEXT,country TEXT,year INT,innovation_investment FLOAT); | SELECT country, year, AVG(innovation_investment) FROM farmers GROUP BY country, year; |
List all building permits in the city of New York that have been issued since 2020, along with the contractor company name and the total value of the permit. | CREATE TABLE building_permits (id INT,city VARCHAR(50),issue_date DATE,contractor_company VARCHAR(100),value DECIMAL(10,2)); | SELECT bp.city, bp.issue_date, bp.contractor_company, SUM(bp.value) as total_value FROM building_permits bp WHERE bp.city = 'New York' AND bp.issue_date >= '2020-01-01' GROUP BY bp.city, bp.issue_date, bp.contractor_company; |
What is the total number of volunteer hours contributed by each program? | CREATE TABLE volunteer_hours (program TEXT,volunteer_hours INT); INSERT INTO volunteer_hours VALUES ('Feeding Program',500),('Education Program',750),('Medical Program',1000); | SELECT program, SUM(volunteer_hours) as total_volunteer_hours FROM volunteer_hours GROUP BY program; |
What is the total duration of all mental health treatments provided in New York? | CREATE TABLE treatment_durations (patient_id INT,condition VARCHAR(50),duration INT); INSERT INTO treatment_durations (patient_id,condition,duration) VALUES (1,'Anxiety',12),(1,'Depression',10),(2,'Depression',15),(2,'Therapy',20),(3,'PTSD',25),(3,'Anxiety',18); CREATE TABLE patient_location (patient_id INT,location VARCHAR(50)); INSERT INTO patient_location (patient_id,location) VALUES (1,'New York'),(2,'New York'),(3,'California'); | SELECT SUM(duration) FROM treatment_durations JOIN patient_location ON patient_location.patient_id = treatment_durations.patient_id WHERE location = 'New York'; |
Insert records for a 50 kW system installed in 2021 by "SolarEase" in the "solar_panels" table | CREATE TABLE solar_panels (id INT PRIMARY KEY,system_size FLOAT,install_year INT,manufacturer VARCHAR(255)); | INSERT INTO solar_panels (system_size, install_year, manufacturer) VALUES (50, 2021, 'SolarEase'); |
What is the address of properties with a mortgage that starts in 2021 and ends in 2026?' | CREATE TABLE Mortgage (Id INT PRIMARY KEY,MortgageStartDate DATE,MortgageEndDate DATE,PropertyId INT,FOREIGN KEY (PropertyId) REFERENCES Property(Id)); | SELECT Property.Address FROM Property INNER JOIN Mortgage ON Property.Id = Mortgage.PropertyId WHERE Mortgage.MortgageStartDate BETWEEN '2021-01-01' AND '2021-12-31' AND Mortgage.MortgageEndDate BETWEEN '2026-01-01' AND '2026-12-31'; |
Who are the artists with the most art pieces in the TraditionalArt table? | CREATE TABLE TraditionalArt (ArtistID int,ArtPieceID int,ArtName varchar(50)); INSERT INTO TraditionalArt (ArtistID,ArtPieceID,ArtName) VALUES (1,101,'Pottery'),(1,102,'Woven Rug'),(2,103,'Calligraphy'),(3,104,'Dance Performance'),(1,105,'Painting'),(4,106,'Sculpture'); | SELECT ArtistID, COUNT(*) AS ArtCount FROM TraditionalArt GROUP BY ArtistID ORDER BY ArtCount DESC; |
List all clients who have paid more than $5000 in total billing amount? | CREATE TABLE clients (client_id INT,name VARCHAR(50)); CREATE TABLE cases (case_id INT,client_id INT,billing_amount DECIMAL(10,2)); INSERT INTO clients (client_id,name) VALUES (1,'Smith'),(2,'Johnson'),(3,'Williams'),(4,'Brown'); INSERT INTO cases (case_id,client_id,billing_amount) VALUES (1,1,3000.00),(2,2,6000.00),(3,3,7000.00),(4,4,1000.00); | SELECT clients.name FROM clients INNER JOIN cases ON clients.client_id = cases.client_id GROUP BY clients.name HAVING SUM(billing_amount) > 5000; |
What is the number of glaciers in the Arctic per country? | CREATE TABLE glaciers (id INT,glacier_name VARCHAR,country VARCHAR); INSERT INTO glaciers VALUES (1,'Glacier A','Norway'); | SELECT country, COUNT(*) FROM glaciers GROUP BY country; |
Display vessels with a length between 150 and 200 meters that had an inspection in 2022 and their corresponding details. | CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(255),length INT,year_built INT); CREATE TABLE vessel_inspections (vessel_id INT,inspection_date DATE,inspection_type VARCHAR(255),inspection_results VARCHAR(255)); | SELECT v.vessel_id, v.vessel_name, v.length, v.year_built FROM vessels v INNER JOIN vessel_inspections vi ON v.vessel_id = vi.vessel_id WHERE v.length BETWEEN 150 AND 200 AND YEAR(vi.inspection_date) = 2022; |
Show the number of threat intelligence reports generated per week | CREATE TABLE weekly_reports (report_week DATE); INSERT INTO weekly_reports (report_week) VALUES ('2021-01-03'),('2021-01-10'),('2021-01-17'),('2021-01-24'),('2021-01-31'),('2021-02-07'),('2021-02-14'),('2021-02-21'),('2021-02-28'),('2021-03-07'),('2021-03-14'),('2021-03-21'),('2021-03-28'),('2021-04-04'); | SELECT EXTRACT(WEEK FROM report_week) AS week, COUNT(*) AS reports FROM weekly_reports GROUP BY week; |
What is the average age of teachers who have completed a professional development course in the past year, grouped by their last professional development course? | CREATE TABLE teachers (id INT,name VARCHAR(50),age INT,last_pd_course DATE); | SELECT last_pd_course, AVG(age) FROM teachers WHERE last_pd_course >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY last_pd_course; |
Which African countries have more than 50 aquaculture farms? | CREATE TABLE Country_Farms (country VARCHAR(255),num_farms INT); INSERT INTO Country_Farms (country,num_farms) VALUES ('Egypt',75),('Nigeria',35),('Kenya',42),('South Africa',60),('Tanzania',53); | SELECT Country_Farms.country FROM Country_Farms WHERE Country_Farms.num_farms > 50; |
Display the total number of hospitals in each city in the state of New York. | CREATE TABLE Hospitals (City VARCHAR(255),State VARCHAR(255),Type VARCHAR(255)); INSERT INTO Hospitals (City,State,Type) VALUES ('New York','NY','Hospital'),('Buffalo','NY','Hospital'),('Rochester','NY','Hospital'); | SELECT City, COUNT(*) FROM Hospitals WHERE State = 'NY' GROUP BY City; |
Delete records with a budget over 100000 in the 'community_development' table | CREATE TABLE community_development (id INT,project_name VARCHAR(255),budget INT,country VARCHAR(255)); | DELETE FROM community_development WHERE budget > 100000; |
What is the maximum age of patients in rural_clinic from Canada? | CREATE TABLE rural_clinic (patient_id INT,age INT,gender VARCHAR(10),country VARCHAR(20)); | SELECT MAX(age) FROM rural_clinic WHERE country = 'Canada'; |
List all TV shows produced in South America or created by South American producers, along with their production budget and premiere date. | CREATE TABLE tv_shows (tv_show_id INT,title VARCHAR(50),production_country VARCHAR(50),premiere_date DATE,production_budget INT); INSERT INTO tv_shows (tv_show_id,title,production_country,premiere_date,production_budget) VALUES (1,'TV Show1','Brazil','2020-01-01',10000000),(2,'TV Show2','Argentina','2019-12-25',12000000),(3,'TV Show3','Colombia','2018-05-15',9000000); CREATE TABLE producers (producer_id INT,name VARCHAR(50),nationality VARCHAR(50)); INSERT INTO producers (producer_id,name,nationality) VALUES (1,'Producer1','Brazil'),(2,'Producer2','Argentina'),(3,'Producer3','Colombia'); | SELECT tv_shows.title, tv_shows.production_country, tv_shows.premiere_date, tv_shows.production_budget FROM tv_shows INNER JOIN producers ON (tv_shows.production_country = 'Brazil' OR producers.nationality = 'Brazil' OR tv_shows.production_country = 'Argentina' OR producers.nationality = 'Argentina' OR tv_shows.production_country = 'Colombia' OR producers.nationality = 'Colombia'); |
List the names of rural healthcare centers in India that serve more than 150 patients. | CREATE TABLE healthcare_centers_india_2 (name TEXT,location TEXT,patients_served INT); INSERT INTO healthcare_centers_india_2 (name,location,patients_served) VALUES ('HC A','Rural Tamil Nadu',200),('HC B','Rural Karnataka',100),('HC C','Rural Andhra Pradesh',150); | SELECT name FROM healthcare_centers_india_2 WHERE location LIKE 'Rural%' AND patients_served > 150; |
What are the most common themes in African art? | CREATE TABLE ArtThemes (ThemeID int,Name varchar(50)); CREATE TABLE ArtPieces (ArtPieceID int,Title varchar(50),YearCreated int,ThemeID int); CREATE TABLE Artists (ArtistID int,Name varchar(50),Nationality varchar(50)); | SELECT ArtThemes.Name, COUNT(ArtPieces.ArtPieceID) AS ArtPiecesCount FROM ArtThemes INNER JOIN ArtPieces ON ArtThemes.ThemeID = ArtPieces.ThemeID INNER JOIN Artists ON ArtPieces.ArtistID = Artists.ArtistID WHERE Artists.Nationality LIKE 'African%' GROUP BY ArtThemes.Name ORDER BY ArtPiecesCount DESC; |
Calculate the average carbon dioxide levels for each year in the Arctic. | CREATE TABLE co2_data (id INT,year INT,co2_level DECIMAL(5,2)); | SELECT year, AVG(co2_level) as avg_co2_level FROM co2_data WHERE region = 'Arctic' GROUP BY year; |
Which renewable energy projects have the highest installed capacity in each city? | CREATE TABLE renewable_energy_projects (project_id INT,project_name VARCHAR(50),city VARCHAR(50),installed_capacity FLOAT); INSERT INTO renewable_energy_projects (project_id,project_name,city,installed_capacity) VALUES (1,'Solar Farm 1','CityA',10000.0),(2,'Wind Farm 1','CityB',15000.0),(3,'Hydro Plant 1','CityA',20000.0); | SELECT city, MAX(installed_capacity) FROM renewable_energy_projects GROUP BY city; |
What is the average salary of employees in each department, by gender? | CREATE TABLE employee (id INT,department VARCHAR(255),gender VARCHAR(10),salary FLOAT); INSERT INTO employee (id,department,gender,salary) VALUES (1,'IT','M',80000),(2,'HR','F',70000),(3,'Finance','M',90000),(4,'Marketing','F',75000),(5,'IT','F',75000),(6,'HR','M',72000); | SELECT department, gender, AVG(salary) FROM employee GROUP BY department, gender; |
List all intelligence operations involving drones in the Middle East. | CREATE SCHEMA if not exists intelligence (Operation VARCHAR(255),Location VARCHAR(255),Drone BOOLEAN); INSERT INTO intelligence VALUES ('Op1','Middle East',true),('Op2','Europe',false); | SELECT * FROM intelligence WHERE Location LIKE '%Middle East%' AND Drone = true; |
What is the average billing rate for attorneys in the Los Angeles office? | CREATE TABLE attorneys (attorney_id INT,office_location VARCHAR(255),billing_rate DECIMAL(5,2)); INSERT INTO attorneys (attorney_id,office_location,billing_rate) VALUES (1,'Los Angeles',300),(2,'New York',400),(3,'Los Angeles',350); | SELECT AVG(billing_rate) FROM attorneys WHERE office_location = 'Los Angeles'; |
What is the minimum horsepower for vehicles in the 'green_vehicles' table with a production year greater than 2015? | CREATE TABLE green_vehicles (vehicle_id INT,make VARCHAR(50),model VARCHAR(50),horsepower INT,production_year INT); | SELECT MIN(horsepower) FROM green_vehicles WHERE production_year > 2015; |
How many creative AI applications were developed in the 'africa' region in 2021? | CREATE TABLE creative_ai (region TEXT,year INTEGER,applications INTEGER); INSERT INTO creative_ai (region,year,applications) VALUES ('americas',2021,20),('europe',2021,25),('africa',2021,30); | SELECT SUM(applications) FROM creative_ai WHERE region = 'africa' AND year = 2021; |
List the number of investments in Latinx-founded startups by year. | CREATE TABLE investment (id INT,company_id INT,investor TEXT,year INT,amount FLOAT); INSERT INTO investment (id,company_id,investor,year,amount) VALUES (1,1,'Sequoia',2018,10000000.0); CREATE TABLE company (id INT,name TEXT,industry TEXT,founder TEXT,PRIMARY KEY (id)); INSERT INTO company (id,name,industry,founder) VALUES (1,'Sol Inc','Renewable Energy','Latinx'); | SELECT year, COUNT(*) FROM investment i JOIN company c ON i.company_id = c.id WHERE c.founder = 'Latinx' GROUP BY year; |
What is the total revenue generated from freight forwarding for customers in Brazil in Q3 2022? | CREATE TABLE FreightForwarding (id INT,customer VARCHAR(255),revenue FLOAT,country VARCHAR(255),quarter INT,year INT); | SELECT SUM(revenue) FROM FreightForwarding WHERE country = 'Brazil' AND quarter = 3 AND year = 2022; |
Insert a new record into the 'programs' table for 'Environmental Sustainability' program in the 'Southwest' region | CREATE TABLE programs (id INT,program_name TEXT,region TEXT); | INSERT INTO programs (id, program_name, region) VALUES (1, 'Environmental Sustainability', 'Southwest'); |
Who are the recipients that received aid from both the Food Security and Health programs in Syria? | CREATE TABLE recipients (id INT,name TEXT,age INT,gender TEXT); CREATE TABLE aid (id INT,recipient_id INT,program_id INT); CREATE TABLE programs (id INT,name TEXT,location TEXT); INSERT INTO recipients VALUES (1,'Ali Al-Asad',30,'Male'),(2,'Fatima Al-Khateeb',25,'Female'); INSERT INTO aid VALUES (1,1,1),(2,1,2),(3,2,1),(4,2,2); INSERT INTO programs VALUES (1,'Food Security','Syria'),(2,'Health','Syria'); | SELECT r.name FROM recipients r INNER JOIN aid a1 ON r.id = a1.recipient_id INNER JOIN programs p1 ON a1.program_id = p1.id INNER JOIN aid a2 ON r.id = a2.recipient_id INNER JOIN programs p2 ON a2.program_id = p2.id WHERE p1.name = 'Food Security' AND p2.name = 'Health' AND p1.location = 'Syria' AND p2.location = 'Syria' GROUP BY r.name HAVING COUNT(DISTINCT p1.id) > 1; |
What is the average number of daily transactions for smart contracts associated with digital assets issued by companies in the EU? | CREATE TABLE Smart_Contracts (Contract_ID INT,Asset_ID INT,Daily_Transactions INT); INSERT INTO Smart_Contracts (Contract_ID,Asset_ID,Daily_Transactions) VALUES (1,1,500),(2,2,700),(3,1,600),(4,3,800),(5,4,900); CREATE TABLE Digital_Assets (Asset_ID INT,Asset_Name VARCHAR(255),Issuer_Country VARCHAR(50)); INSERT INTO Digital_Assets (Asset_ID,Asset_Name,Issuer_Country) VALUES (1,'Asset1','Germany'),(2,'Asset2','France'),(3,'Asset3','USA'),(4,'Asset4','Mexico'); | SELECT AVG(Daily_Transactions) AS Avg_Transactions FROM Smart_Contracts JOIN Digital_Assets ON Smart_Contracts.Asset_ID = Digital_Assets.Asset_ID WHERE Issuer_Country = 'Germany' OR Issuer_Country = 'France'; |
Show the total number of research grants awarded to the Biology department in the last 2 years. | CREATE TABLE Departments(DepartmentID INT,Department VARCHAR(255)); INSERT INTO Departments VALUES (1,'Biology'); CREATE TABLE ResearchGrants(GranteeID INT,DepartmentID INT,GrantAmount DECIMAL(10,2),GrantDate DATE); INSERT INTO ResearchGrants VALUES (1,1,50000.00,'2022-01-01'); | SELECT Departments.Department, COUNT(ResearchGrants.GranteeID) FROM Departments INNER JOIN ResearchGrants ON Departments.DepartmentID = ResearchGrants.DepartmentID WHERE Departments.Department = 'Biology' AND ResearchGrants.GrantDate >= DATEADD(year, -2, GETDATE()) GROUP BY Departments.Department; |
What is the average water usage of factories in the top 3 most water-intensive regions? | CREATE TABLE Factories (id INT,region VARCHAR,water_usage INT); CREATE VIEW TopWaterIntensiveRegions AS SELECT DISTINCT TOP 3 region FROM Factories ORDER BY water_usage DESC; | SELECT AVG(water_usage) FROM Factories WHERE region IN (SELECT region FROM TopWaterIntensiveRegions); |
What are the names and completion dates of rural infrastructure projects in the 'rural_infrastructure' schema that were completed using loan funding? | CREATE TABLE infrastructure_projects (id INT,name VARCHAR(50),completion_date DATE,funding_source VARCHAR(50)); INSERT INTO infrastructure_projects (id,name,completion_date,funding_source) VALUES (1,'Rural Bridge Project','2014-07-22','Loan'); | SELECT name, completion_date FROM rural_infrastructure.infrastructure_projects WHERE funding_source = 'Loan'; |
List all creative AI applications and their algorithm names used. | CREATE TABLE CreativeAIs (app_name VARCHAR(255),algorithm_name VARCHAR(255)); INSERT INTO CreativeAIs (app_name,algorithm_name) VALUES ('ArtGen','StyleGAN'),('MusicGen','WaveNet'); | SELECT app_name, algorithm_name FROM CreativeAIs; |
List all the policies implemented in the last 5 years and their corresponding impact ratings. | CREATE TABLE policies (policy_name VARCHAR(50),implementation_date DATE,impact_rating INT); INSERT INTO policies (policy_name,implementation_date,impact_rating) VALUES ('Policy A','2017-01-01',8),('Policy B','2018-05-15',6),('Policy C','2019-12-31',9),('Policy D','2020-07-04',7),('Policy E','2021-02-20',10); | SELECT policy_name, implementation_date, impact_rating FROM policies WHERE implementation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR); |
What were the total donation amounts by cause area for the year 2020? | CREATE TABLE donations (id INT,donor_name TEXT,cause_area TEXT,amount INT,donation_date DATE); INSERT INTO donations (id,donor_name,cause_area,amount,donation_date) VALUES (1,'John Doe','Education',500,'2020-01-01'); INSERT INTO donations (id,donor_name,cause_area,amount,donation_date) VALUES (2,'Jane Smith','Health',300,'2020-02-15'); | SELECT cause_area, SUM(amount) as total_donations FROM donations WHERE donation_date >= '2020-01-01' AND donation_date < '2021-01-01' GROUP BY cause_area; |
Find the total number of animals in each habitat type | CREATE TABLE habitats (id INT,type VARCHAR(20)); INSERT INTO habitats (id,type) VALUES (1,'Forest'),(2,'Savannah'),(3,'Wetlands'); CREATE TABLE animals (id INT,name VARCHAR(20),habitat_id INT); INSERT INTO animals (id,name,habitat_id) VALUES (1,'Lion',2),(2,'Elephant',1),(3,'Hippo',3),(4,'Tiger',2),(5,'Crane',3); | SELECT h.type, COUNT(a.id) as total_animals FROM animals a JOIN habitats h ON a.habitat_id = h.id GROUP BY h.type; |
What are the top 3 building permits by cost? | CREATE TABLE building_permits (permit_id SERIAL PRIMARY KEY,issue_date DATE,cost INTEGER); INSERT INTO building_permits (issue_date,cost) VALUES ('2021-01-01',1500),('2021-01-10',2000),('2022-02-01',5000); | SELECT permit_id, issue_date, cost FROM building_permits ORDER BY cost DESC LIMIT 3; |
Update the age of player with ID 1 to 27 | CREATE TABLE Players (PlayerID int,Name varchar(50),Age int,Gender varchar(10)); INSERT INTO Players (PlayerID,Name,Age,Gender) VALUES (1,'John Doe',25,'Male'),(2,'Jane Smith',30,'Female'),(3,'Alex Johnson',22,'Non-binary'); | UPDATE Players SET Age = 27 WHERE PlayerID = 1; |
What is the average time to resolve each type of case in the justice system? | CREATE TABLE Justice_System_Case_Resolution (ID INT,Case_Type VARCHAR(30),Avg_Time_To_Resolve INT); INSERT INTO Justice_System_Case_Resolution (ID,Case_Type,Avg_Time_To_Resolve) VALUES (1,'Criminal',60),(2,'Civil',90),(3,'Family',45); | SELECT Case_Type, AVG(Avg_Time_To_Resolve) FROM Justice_System_Case_Resolution GROUP BY Case_Type; |
What is the minimum budget for community development initiatives in Brazil's Paraná state? | CREATE TABLE community_development (id INT,initiative_name VARCHAR(255),budget FLOAT,country VARCHAR(50),state VARCHAR(50)); INSERT INTO community_development (id,initiative_name,budget,country,state) VALUES (1,'Cultural Festival',25000.00,'Brazil','Paraná'),(2,'Youth Training Center',150000.00,'Brazil','Paraná'),(3,'Public Space Renovation',75000.00,'Brazil','Paraná'); | SELECT MIN(budget) FROM community_development WHERE country = 'Brazil' AND state = 'Paraná' |
How many vessels are in the 'vessels' table that are registered in the 'Panama' registry? | CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50),registry VARCHAR(50)); INSERT INTO vessels (vessel_id,vessel_name,registry) VALUES (1,'CSCL Globe','China'),(2,'OOCL Hong Kong','Hong Kong'),(3,'MSC Maya','Panama'); | SELECT COUNT(*) FROM vessels WHERE registry = 'Panama'; |
What is the total production of 'cotton' in 'Asia' for the years 2018 and 2019? | CREATE TABLE crops (id INT,crop_name VARCHAR(20),country VARCHAR(20),production INT,year INT); INSERT INTO crops (id,crop_name,country,production,year) VALUES (1,'cotton','Asia',40000,2018),(2,'cotton','Asia',45000,2019); | SELECT SUM(production) as total_production FROM crops WHERE crop_name = 'cotton' AND country = 'Asia' AND year IN (2018, 2019); |
Delete the records with occupancy lower than 50% for the past month in 'hotel_bookings' table. | CREATE TABLE hotel_bookings (booking_id INT,hotel_id INT,occupancy INT,booked_date DATE); | DELETE FROM hotel_bookings WHERE occupancy < 50 AND booked_date >= DATE(NOW()) - INTERVAL 1 MONTH; |
What is the percentage of total donations made by donors from Asia in the year 2021? | CREATE TABLE donors (donor_id INT,donor_name VARCHAR(50),donor_country VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (donor_id,donor_name,donor_country,donation_amount,donation_date) VALUES (1,'John Doe','USA',50.00,'2020-01-01'); | SELECT (SUM(CASE WHEN donor_country = 'Asia' THEN donation_amount ELSE 0 END) / SUM(donation_amount)) * 100 AS donation_percentage FROM donors WHERE YEAR(donation_date) = 2021; |
What is the average fare for buses in the 'san_francisco' schema? | CREATE TABLE san_francisco.bus_fares (id INT,route_id INT,fare DECIMAL); INSERT INTO san_francisco.bus_fares (id,route_id,fare) VALUES (1,101,2.5),(2,102,2),(3,103,3); | SELECT AVG(fare) FROM san_francisco.bus_fares; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.