instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many 'Red' line rides were there in 'Evening'?
CREATE TABLE red_line_rides (ride_id int,time_of_day varchar(20)); INSERT INTO red_line_rides (ride_id,time_of_day) VALUES (1,'Morning'),(2,'Evening'),(3,'Morning');
SELECT COUNT(*) FROM red_line_rides WHERE time_of_day = 'Evening';
What is the total number of hospital beds by hospital type?
CREATE TABLE hospital_beds (id INT,hospital_name VARCHAR(50),hospital_type VARCHAR(50),num_beds INT); INSERT INTO hospital_beds (id,hospital_name,hospital_type,num_beds) VALUES (1,'Hospital A','Public',500);
SELECT hospital_type, SUM(num_beds) as total_beds FROM hospital_beds GROUP BY hospital_type;
How many users in Asia have updated their profile pictures in the past month and what is the average number of posts they have made?
CREATE TABLE users (user_id INT,region VARCHAR(50),profile_picture_update_date DATE,gender VARCHAR(50));CREATE TABLE posts (post_id INT,user_id INT,post_date DATE); INSERT INTO users (user_id,region,profile_picture_update_date,gender) VALUES (1,'Asia','2023-03-25','female'),(2,'Asia','2023-03-23','male'); INSERT INTO posts (post_id,user_id,post_date) VALUES (1,1,'2023-03-28'),(2,1,'2023-03-30'),(3,2,'2023-03-27'),(4,2,'2023-03-28'),(5,2,'2023-03-29');
SELECT AVG(post_count) as avg_posts, COUNT(DISTINCT user_id) as num_users FROM (SELECT user_id, COUNT(*) as post_count FROM posts WHERE post_date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY user_id) as post_counts JOIN users ON post_counts.user_id = users.user_id WHERE region = 'Asia' AND profile_picture_update_date >= DATEADD(month, -1, CURRENT_DATE);
What is the number of patients and their respective primary care physicians in the Midwest?
CREATE TABLE patients(id INT,name TEXT,location TEXT,primary_care_physician TEXT); INSERT INTO patients(id,name,location,primary_care_physician) VALUES (1,'Patient A','Midwest','Dr. Smith'),(2,'Patient B','Midwest','Dr. Johnson'),(3,'Patient C','California','Dr. Brown'),(4,'Patient D','Florida','Dr. Davis');
SELECT COUNT(*) as patient_count, primary_care_physician FROM patients WHERE location = 'Midwest' GROUP BY primary_care_physician;
Get the average calories for organic products.
CREATE TABLE nutrition (product_id VARCHAR(10),calories INTEGER); INSERT INTO nutrition (product_id,calories) VALUES ('P001',150),('P002',200),('P003',250),('P004',120),('P005',180);CREATE TABLE products (product_id VARCHAR(10),name VARCHAR(50),is_organic BOOLEAN); INSERT INTO products (product_id,name,is_organic) VALUES ('P001','Apples',true),('P002','Bananas',false),('P003','Organic Carrots',true),('P004','Dates',false),('P005','Eggs',false);
SELECT AVG(nutrition.calories) FROM nutrition JOIN products ON nutrition.product_id = products.product_id WHERE products.is_organic = true;
List all permits and the number of labor violations for each permit
CREATE TABLE building_permits (permit_id INT); CREATE TABLE labor_stats (permit_id INT,violation VARCHAR(100));
SELECT bp.permit_id, COUNT(ls.permit_id) AS num_violations FROM building_permits bp LEFT JOIN labor_stats ls ON bp.permit_id = ls.permit_id GROUP BY bp.permit_id;
List the names and accuracy scores of all models that belong to the 'explainable_ai' category.
CREATE TABLE model_scores (model_name TEXT,accuracy FLOAT,category TEXT); INSERT INTO model_scores (model_name,accuracy,category) VALUES ('modelA',0.91,'explainable_ai'),('modelB',0.85,'algorithmic_fairness'),('modelC',0.95,'explainable_ai'),('modelD',0.78,'creative_ai');
SELECT model_name, accuracy FROM model_scores WHERE category = 'explainable_ai';
What is the total budget for film programs, and what percentage of the budget is allocated to each program category?
CREATE TABLE FilmPrograms (Id INT,ProgramName VARCHAR(50),Category VARCHAR(50),Budget DECIMAL(10,2));
SELECT Category, SUM(Budget) as TotalBudget, 100.0 * SUM(Budget) / (SELECT SUM(Budget) FROM FilmPrograms) as Percentage FROM FilmPrograms GROUP BY Category;
What is the average monthly data usage for mobile customers in each age group?
CREATE TABLE age_groups (subscriber_id INT,data_usage_gb FLOAT,age_group VARCHAR(25));
SELECT age_group, AVG(data_usage_gb) FROM age_groups GROUP BY age_group;
How many security incidents were recorded in 'region_3' in the 'incidents' table?
CREATE TABLE incidents (incident_id INT,region VARCHAR(50),severity VARCHAR(10)); INSERT INTO incidents (incident_id,region,severity) VALUES (1,'region_1','medium'),(2,'region_2','high'),(3,'region_3','high'),(4,'region_1','low'),(5,'region_3','medium');
SELECT COUNT(*) FROM incidents WHERE region = 'region_3';
What are the average donations received per volunteer for organizations located in the Midwest region?
CREATE TABLE organizations (id INT,name TEXT,city TEXT,state TEXT,donations_received DECIMAL(10,2),volunteers INT); INSERT INTO organizations (id,name,city,state,donations_received,volunteers) VALUES (1,'Organization A','San Francisco','CA',50000.00,100),(2,'Organization B','Los Angeles','CA',75000.00,150),(3,'Organization C','Sacramento','CA',35000.00,75),(4,'Organization D','Chicago','IL',90000.00,200),(5,'Organization E','Houston','TX',60000.00,120); CREATE TABLE states (id INT,state TEXT,region TEXT); INSERT INTO states (id,state,region) VALUES (1,'CA','West'),(2,'NY','Northeast'),(3,'FL','South'),(4,'IL','Midwest'),(5,'TX','South'),(6,'WA','West');
SELECT AVG(o.donations_received / o.volunteers) AS avg_donations_per_volunteer FROM organizations o JOIN states s ON o.state = s.state WHERE s.region = 'Midwest';
What is the total amount of funds raised by year in 'community_development' schema?
CREATE TABLE funds (fund_id INT,community_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO funds (fund_id,community_id,amount,donation_date) VALUES (1,1,5000.00,'2021-01-01');
SELECT YEAR(donation_date) as year, SUM(amount) as total_funds_raised FROM funds GROUP BY YEAR(donation_date);
List all unique genders in the Employees table.
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Gender,Department) VALUES (1,'Female','IT'),(2,'Male','IT'),(3,'Non-binary','HR'),(4,'Male','Finance'),(5,'Non-binary','IT'),(6,'Genderqueer','IT');
SELECT DISTINCT Gender FROM Employees;
Insert new waste generation records for the 'Mountain' region in 2024 with a waste_gram of 55000.
CREATE TABLE waste_generation(region VARCHAR(20),year INT,waste_gram INT); INSERT INTO waste_generation(region,year,waste_gram) VALUES('North',2021,50000),('North',2022,60000),('South',2021,40000),('South',2022,70000);
INSERT INTO waste_generation(region, year, waste_gram) VALUES('Mountain', 2024, 55000);
How many agricultural innovation projects were completed in the province of Quebec between 2017 and 2019?
CREATE TABLE agricultural_projects (id INT,province VARCHAR(50),cost FLOAT,project_type VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO agricultural_projects (id,province,cost,project_type,start_date,end_date) VALUES (1,'Quebec',45000.00,'Smart Farming','2017-01-01','2017-12-31');
SELECT COUNT(*) FROM agricultural_projects WHERE province = 'Quebec' AND start_date <= '2019-12-31' AND end_date >= '2017-01-01' AND project_type = 'Smart Farming';
What is the total revenue for each bus route in the past month?
CREATE TABLE bus_routes (route_id INT,route_name TEXT,starting_point TEXT,ending_point TEXT); INSERT INTO bus_routes (route_id,route_name,starting_point,ending_point) VALUES (1,'Green Line','Downtown','Suburbia'); CREATE TABLE fares (fare_id INT,route_id INT,fare_amount DECIMAL,fare_date DATE);
SELECT br.route_name, SUM(f.fare_amount) as total_revenue FROM bus_routes br INNER JOIN fares f ON br.route_id = f.route_id WHERE f.fare_date >= DATEADD(month, -1, GETDATE()) GROUP BY br.route_name;
What is the average food safety score for each restaurant over time, with the most recent score first?
CREATE TABLE Inspections (restaurant TEXT,score INT,date TEXT); INSERT INTO Inspections (restaurant,score,date) VALUES ('Asian Fusion',95,'2022-01-01'),('Bistro Bella Vita',90,'2022-01-02'),('Taqueria Tsunami',98,'2022-01-03'),('Asian Fusion',96,'2022-01-04'),('Bistro Bella Vita',92,'2022-01-05');
SELECT restaurant, AVG(score) as avg_score, MAX(date) as max_date FROM Inspections GROUP BY restaurant ORDER BY max_date DESC;
What is the maximum smart city technology adoption rate per region?
CREATE TABLE SmartCityAdoption (region VARCHAR(20),adoption_rate FLOAT); INSERT INTO SmartCityAdoption (region,adoption_rate) VALUES ('RegionA',70.5),('RegionB',80.0),('RegionC',65.0),('RegionD',85.0);
SELECT region, MAX(adoption_rate) FROM SmartCityAdoption;
What is the maximum and minimum billing amount for each legal precedent?
CREATE TABLE Precedents (PrecedentID INT,CaseID INT,BillingAmount DECIMAL(10,2)); INSERT INTO Precedents (PrecedentID,CaseID,BillingAmount) VALUES (1,1,500.00),(2,1,750.00),(3,2,800.00),(4,3,900.00),(5,4,1000.00),(6,5,400.00),(7,6,350.00),(8,7,1200.00),(9,8,1500.00),(10,9,1100.00),(11,10,1300.00),(12,10,1400.00);
SELECT PrecedentID, MAX(BillingAmount) AS Max_Billing_Amount, MIN(BillingAmount) AS Min_Billing_Amount FROM Precedents GROUP BY PrecedentID;
How many restaurants are there in each area?
CREATE TABLE restaurants (id INT,name TEXT,area TEXT); INSERT INTO restaurants (id,name,area) VALUES (1,'Restaurant A','downtown'),(2,'Restaurant B','uptown'),(3,'Restaurant C','downtown'),(4,'Restaurant D','downtown'),(5,'Restaurant E','uptown'),(6,'Restaurant F','downtown');
SELECT area, COUNT(area) FROM restaurants GROUP BY area;
How many educational resources were provided in total by each organization in 2020?
CREATE TABLE organizations (id INT,name VARCHAR(255)); INSERT INTO organizations (id,name) VALUES (1,'UNESCO'),(2,'UNICEF'),(3,'Save the Children'); CREATE TABLE resources (id INT,organization_id INT,resource_type VARCHAR(255),quantity INT,distribution_date DATE); INSERT INTO resources (id,organization_id,resource_type,quantity,distribution_date) VALUES (1,1,'Textbooks',500,'2020-01-01'),(2,1,'Educational Software',300,'2020-02-01'),(3,2,'Textbooks',700,'2020-03-01'),(4,2,'Educational Software',400,'2020-04-01'),(5,3,'Textbooks',600,'2020-05-01'),(6,3,'Educational Software',800,'2020-06-01');
SELECT organization_id, SUM(quantity) as total_resources FROM resources WHERE YEAR(distribution_date) = 2020 GROUP BY organization_id;
What is the maximum and minimum hectares of wildlife habitat in each forest?
CREATE TABLE Forests (id INT,name VARCHAR(255),hectares FLOAT,country VARCHAR(255)); INSERT INTO Forests (id,name,hectares,country) VALUES (1,'Amazon Rainforest',55000000.0,'Brazil'); CREATE TABLE WildlifeHabitat (id INT,forest_id INT,hectares FLOAT); INSERT INTO WildlifeHabitat (id,forest_id,hectares) VALUES (1,1,15000000),(2,1,20000000);
SELECT Forests.name, MAX(WildlifeHabitat.hectares) as max_wildlife_habitat, MIN(WildlifeHabitat.hectares) as min_wildlife_habitat FROM Forests INNER JOIN WildlifeHabitat ON Forests.id = WildlifeHabitat.forest_id GROUP BY Forests.name;
Determine the number of unique vessel names for vessels with a loading capacity greater than 40000 tons
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(100),LoadingCapacity FLOAT); INSERT INTO Vessels (VesselID,VesselName,LoadingCapacity) VALUES (1,'Ocean Titan',65000),(2,'Sea Giant',35000),(3,'Marine Unicorn',42000),(4,'Sky Wanderer',28000);
SELECT COUNT(DISTINCT VesselName) FROM Vessels WHERE LoadingCapacity > 40000;
How many female and male visitors attended performing arts events?
CREATE TABLE events (event_id INT,event_name VARCHAR(50),event_type VARCHAR(50),visitor_count INT,gender VARCHAR(10));
SELECT event_type, SUM(CASE WHEN gender = 'Female' THEN visitor_count ELSE 0 END) AS female_visitors, SUM(CASE WHEN gender = 'Male' THEN visitor_count ELSE 0 END) AS male_visitors FROM events WHERE event_type = 'Performing Arts' GROUP BY event_type;
What is the maximum amount donated to "climate_change" by a unique donor?
CREATE TABLE donations_climate_change (id INT,donor_id INT,category VARCHAR(255),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations_climate_change (id,donor_id,category,donation_amount,donation_date) VALUES (1,9001,'climate_change',50.00,'2022-01-01'); INSERT INTO donations_climate_change (id,donor_id,category,donation_amount,donation_date) VALUES (2,9002,'climate_change',75.00,'2022-02-01');
SELECT MAX(donation_amount) FROM donations_climate_change WHERE category = 'climate_change' GROUP BY donor_id HAVING COUNT(donor_id) = 1;
Update all records in the "company_founding" table, setting the founding date to 2017-01-01 for the company 'Kilo Ltd.'
CREATE TABLE company_founding (id INT,company_name VARCHAR(100),founding_date DATE); INSERT INTO company_founding (id,company_name,founding_date) VALUES (1,'Acme Inc.','2015-06-20'),(2,'Bravo Corp.','2016-08-10'),(9,'Kilo Ltd.','2016-03-05');
UPDATE company_founding SET founding_date = '2017-01-01' WHERE company_name = 'Kilo Ltd.';
How many factories are located in 'Oceania' and have a labor rating of 80 or higher?
CREATE TABLE regions (region_id INT,name VARCHAR(255)); INSERT INTO regions VALUES (1,'Oceania'); INSERT INTO regions VALUES (2,'Asia'); CREATE TABLE factories (factory_id INT,name VARCHAR(255),location VARCHAR(255),country_id INT,labor_rating INT,region_id INT); INSERT INTO factories VALUES (1,'Ethical Factory X','Sydney,Australia',1,95,1); INSERT INTO factories VALUES (2,'Fast Fashion Factory Y','Tokyo,Japan',2,70,2);
SELECT COUNT(factories.factory_id) FROM factories WHERE factories.region_id IN (SELECT region_id FROM regions WHERE regions.name = 'Oceania') AND factories.labor_rating >= 80;
List all security incidents that occurred in the last month, including their status and the number of assets impacted?
CREATE TABLE SecurityIncidents (incident_id INT,status VARCHAR(10),assets_impacted INT,timestamp TIMESTAMP); INSERT INTO SecurityIncidents (incident_id,status,assets_impacted,timestamp) VALUES (1,'Open',2,'2022-01-01 10:00:00');
SELECT incident_id, status, assets_impacted, timestamp FROM SecurityIncidents WHERE timestamp BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH) AND CURRENT_TIMESTAMP;
What are the top 3 favorite dishes of customers from the USA?
CREATE TABLE restaurants (id INT,name TEXT,location TEXT);CREATE TABLE dishes (id INT,name TEXT,restaurant_id INT);CREATE TABLE orders (id INT,dish_id INT,customer_name TEXT,order_date DATE);INSERT INTO restaurants (id,name,location) VALUES (1,'Diner A','USA');INSERT INTO dishes (id,name,restaurant_id) VALUES (1,'Burger',1),(2,'Fries',1),(3,'Salad',1);INSERT INTO orders (id,dish_id,customer_name,order_date) VALUES (1,1,'John','2022-01-01'),(2,2,'John','2022-01-01'),(3,3,'Sarah','2022-01-02');
SELECT d.name, COUNT(o.id) AS orders_count FROM dishes d JOIN orders o ON d.id = o.dish_id JOIN restaurants r ON d.restaurant_id = r.id WHERE r.location = 'USA' GROUP BY d.name ORDER BY orders_count DESC LIMIT 3;
How many landfills are there in the province of Ontario?
CREATE TABLE landfills (province VARCHAR(255),num_landfills INT); INSERT INTO landfills (province,num_landfills) VALUES ('Ontario',100);
SELECT num_landfills FROM landfills WHERE province = 'Ontario';
Get the average number of sustainable building practices per month for 'Green Builders Inc.' in the 'sustainable_practices' table
CREATE TABLE sustainable_practices (contractor_name VARCHAR(50),practice_date DATE,practice_description VARCHAR(100)); INSERT INTO sustainable_practices (contractor_name,practice_date,practice_description) VALUES ('Green Builders Inc.','2023-02-01','Installed solar panels on a residential project.'),('Green Builders Inc.','2023-02-15','Used recycled materials for flooring.'),('Green Builders Inc.','2023-03-05','Implemented energy-efficient lighting.');
SELECT AVG(DATEDIFF(MONTH, practice_date, LAG(practice_date) OVER (PARTITION BY contractor_name ORDER BY practice_date))) FROM sustainable_practices WHERE contractor_name = 'Green Builders Inc.';
What is the average heart rate of users during their morning workouts?
CREATE TABLE workouts (id INT,user_id INT,duration INT,heart_rate INT,workout_time TIME); INSERT INTO workouts (id,user_id,duration,heart_rate,workout_time) VALUES (1,1,60,120,'07:00:00');
SELECT AVG(heart_rate) FROM workouts WHERE workout_time BETWEEN '06:00:00' AND '11:59:59';
Update the 'target' column in the 'climate_mitigation_targets' table where the 'country' is 'Germany' and 'sector' is 'Energy'
CREATE TABLE climate_mitigation_targets (id INT,country VARCHAR(255),sector VARCHAR(255),year INT,target FLOAT);
UPDATE climate_mitigation_targets SET target = target * 1.05 WHERE country = 'Germany' AND sector = 'Energy';
What is the maximum quantity of 'Neodymium' produced in a year by 'Australia'?
CREATE TABLE production (element VARCHAR(10),country VARCHAR(20),quantity INT,year INT); INSERT INTO production (element,country,quantity,year) VALUES ('Neodymium','Australia',9000,2016),('Neodymium','Australia',10000,2017),('Neodymium','Australia',11000,2018),('Neodymium','Australia',12000,2019),('Neodymium','Australia',13000,2020),('Neodymium','Australia',14000,2021);
SELECT MAX(quantity) FROM production WHERE element = 'Neodymium' AND country = 'Australia';
How many items are produced in the top 2 countries with the most productions?
CREATE TABLE CountryProduction (item_id INT,country VARCHAR(255)); INSERT INTO CountryProduction (item_id,country) VALUES (1,'Spain'),(2,'Italy'),(3,'Spain'),(4,'France'),(5,'Spain'),(6,'Germany'),(7,'Spain');
SELECT COUNT(*) FROM (SELECT country, ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) rn FROM CountryProduction GROUP BY country) t WHERE rn <= 2;
Insert a new record into the 'Donations' table for a $500 donation to the 'Habitat for Humanity' organization by a 'John Smith' on '2022-03-15'
CREATE TABLE Donations (donation_id INT,donor_name TEXT,donation_amount DECIMAL(10,2),donation_date DATE,org_id INT);
INSERT INTO Donations (donor_name, donation_amount, donation_date, org_id) VALUES ('John Smith', 500, '2022-03-15', (SELECT org_id FROM Organizations WHERE org_name = 'Habitat for Humanity'));
Find the total CO2 emissions for garments made of cotton.
CREATE TABLE inventory (id INT,garment_id INT,material VARCHAR(50),CO2_emissions INT); INSERT INTO inventory (id,garment_id,material,CO2_emissions) VALUES (1,1003,'cotton',5);
SELECT SUM(CO2_emissions) FROM inventory WHERE material = 'cotton';
What is the average carbon footprint of the top 3 materials used in production?
CREATE TABLE carbon_footprint(material VARCHAR(20),carbon_footprint DECIMAL(5,2)); INSERT INTO carbon_footprint(material,carbon_footprint) VALUES('organic cotton',2.50),('recycled polyester',3.20),('tencel',1.80);
SELECT AVG(carbon_footprint) FROM carbon_footprint WHERE material IN (SELECT material FROM carbon_footprint ORDER BY carbon_footprint LIMIT 3);
Who is the largest construction company in 'Vancouver'?
CREATE TABLE companies (id INT,company_name TEXT,city TEXT,employees INT); INSERT INTO companies (id,company_name,city,employees) VALUES (1,'Eco-Construction Ltd.','Vancouver',500),(2,'GreenTech Inc.','Toronto',300);
SELECT company_name FROM companies WHERE city = 'Vancouver' ORDER BY employees DESC LIMIT 1;
List the total sales of 'Fair Trade' products from 'Small Retailers'?
CREATE TABLE Products (ProductID INT,Product TEXT,Price DECIMAL,Trade TEXT); INSERT INTO Products (ProductID,Product,Price,Trade) VALUES (1,'Coffee',15,'Fair Trade'); CREATE TABLE Retailers (RetailerID INT,Retailer TEXT,Size TEXT); INSERT INTO Retailers (RetailerID,Retailer,Size) VALUES (1,'Mom and Pop Groceries','Small'); CREATE TABLE Sales (SaleID INT,ProductID INT,RetailerID INT,Quantity INT); INSERT INTO Sales (SaleID,ProductID,RetailerID) VALUES (1,1,1);
SELECT Products.Product, SUM(Sales.Quantity * Products.Price) as TotalSales FROM Sales INNER JOIN Products ON Sales.ProductID = Products.ProductID INNER JOIN Retailers ON Sales.RetailerID = Retailers.RetailerID WHERE Products.Trade = 'Fair Trade' AND Retailers.Size = 'Small' GROUP BY Products.Product;
Which disaster types have no donations?
CREATE TABLE DisasterDonations (DisasterID INT,DonationID INT,Amount DECIMAL(10,2)); INSERT INTO DisasterDonations (DisasterID,DonationID,Amount) VALUES (1,1,100.00),(2,2,150.00);
SELECT d.DisasterType FROM Disasters d LEFT JOIN DisasterDonations dd ON d.DisasterID = dd.DisasterID WHERE dd.DonationID IS NULL;
What is the total number of marine protected areas in the Arctic and Southern Oceans?
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),ocean VARCHAR(255),size FLOAT); INSERT INTO marine_protected_areas (id,name,ocean,size) VALUES (1,'Area A','Arctic',100000); INSERT INTO marine_protected_areas (id,name,ocean,size) VALUES (2,'Area B','Southern Ocean',200000); INSERT INTO marine_protected_areas (id,name,ocean,size) VALUES (3,'Area C','Arctic',300000);
SELECT SUM(size) FROM marine_protected_areas WHERE ocean IN ('Arctic', 'Southern Ocean');
List all cybersecurity strategies and their respective budgets from the 'CyberSecurity' table for the year 2024
CREATE TABLE CyberSecurity (Strategy_Name VARCHAR(255),Budget INT,Fiscal_Year INT); INSERT INTO CyberSecurity (Strategy_Name,Budget,Fiscal_Year) VALUES ('Endpoint Protection',15000000,2024); INSERT INTO CyberSecurity (Strategy_Name,Budget,Fiscal_Year) VALUES ('Cloud Security',25000000,2024);
SELECT * FROM CyberSecurity WHERE Fiscal_Year = 2024;
How many patients with anxiety disorders in South Korea have been treated with medication?
CREATE TABLE patients_anxiety (patient_id INT,country VARCHAR(50),condition VARCHAR(50),medication BOOLEAN); INSERT INTO patients_anxiety (patient_id,country,condition,medication) VALUES (1,'South Korea','Anxiety Disorder',TRUE),(2,'South Korea','Depression',FALSE),(3,'South Korea','Anxiety Disorder',TRUE);
SELECT COUNT(*) FROM patients_anxiety WHERE country = 'South Korea' AND condition = 'Anxiety Disorder' AND medication = TRUE;
What is the average number of likes per post for influencers in the music genre?
CREATE TABLE influencer_posts (post_id INT,post_date DATE,influencer_name VARCHAR(50),genre VARCHAR(50),likes INT); INSERT INTO influencer_posts VALUES (505,'2022-01-01','Influencer U','Music',100),(506,'2022-01-03','Influencer V','Music',150),(507,'2022-01-05','Influencer W','Music',50),(508,'2022-01-07','Influencer U','Music',120);
SELECT genre, AVG(likes) as avg_likes_per_post FROM (SELECT genre, influencer_name, AVG(likes) as likes FROM influencer_posts GROUP BY genre, influencer_name) AS subquery WHERE genre = 'Music';
Show the total number of eco-friendly tours in Paris.
CREATE TABLE tours (id INT,city VARCHAR(20),eco_friendly BOOLEAN); INSERT INTO tours (id,city,eco_friendly) VALUES (1,'Paris',true),(2,'Paris',false),(3,'Berlin',true);
SELECT COUNT(*) FROM tours WHERE city = 'Paris' AND eco_friendly = true;
What is the maximum ESG score for all impact investments in the healthcare sector?
CREATE TABLE impact_investments (investment_id INT,investment_name TEXT,sector TEXT,esg_score INT); INSERT INTO impact_investments (investment_id,investment_name,sector,esg_score) VALUES (1,'Investment X','Healthcare',85),(2,'Investment Y','Healthcare',90),(3,'Investment Z','Education',80);
SELECT MAX(esg_score) FROM impact_investments WHERE sector = 'Healthcare';
What is the average claim amount for policyholders in the Southwest region?
CREATE TABLE Policyholders (PolicyholderID INT,Region VARCHAR(20)); CREATE TABLE Claims (ClaimID INT,PolicyholderID INT,Amount DECIMAL(10,2)); INSERT INTO Policyholders (PolicyholderID,Region) VALUES (1,'Southwest'),(2,'Northeast'); INSERT INTO Claims (ClaimID,PolicyholderID,Amount) VALUES (1,1,500),(2,1,300),(3,2,700);
SELECT AVG(Claims.Amount) FROM Claims INNER JOIN Policyholders ON Claims.PolicyholderID = Policyholders.PolicyholderID WHERE Policyholders.Region = 'Southwest';
What are the circular economy initiatives in the city of Los Angeles?
CREATE TABLE circular_economy_initiatives (city varchar(255),initiative varchar(255)); INSERT INTO circular_economy_initiatives (city,initiative) VALUES ('Los Angeles','Waste-to-Energy Program'); INSERT INTO circular_economy_initiatives (city,initiative) VALUES ('Los Angeles','Recycling Expansion Project');
SELECT initiative FROM circular_economy_initiatives WHERE city = 'Los Angeles'
What is the total amount of socially responsible loans issued by financial institutions in the Asia region for the year 2020?
CREATE TABLE financial_institutions (institution_id INT,institution_name TEXT,region TEXT);CREATE TABLE loans (loan_id INT,institution_id INT,loan_amount INT,issue_date DATE); INSERT INTO financial_institutions (institution_id,institution_name,region) VALUES (1,'Institution A','Asia'),(2,'Institution B','Asia'),(3,'Institution C','Europe'); INSERT INTO loans (loan_id,institution_id,loan_amount,issue_date) VALUES (1,1,5000,'2020-01-01'),(2,1,7000,'2020-06-15'),(3,2,6000,'2020-03-20');
SELECT SUM(loan_amount) FROM loans JOIN financial_institutions ON loans.institution_id = financial_institutions.institution_id WHERE region = 'Asia' AND EXTRACT(YEAR FROM issue_date) = 2020 AND loans.loan_amount IN (SELECT loan_amount FROM loans WHERE loan_amount >= 0);
List the total number of job applications in the 'Research' department for each month in the year 2022, including the months without any applications.
CREATE TABLE job_applications (application_id INT,name VARCHAR(50),department VARCHAR(50),application_date DATE);
SELECT EXTRACT(MONTH FROM application_date) AS month, COUNT(*) AS total_applications FROM job_applications WHERE department = 'Research' AND EXTRACT(YEAR FROM application_date) = 2022 GROUP BY month ORDER BY month;
What was the average donation amount for each program in 2023?
CREATE TABLE ProgramDonations (DonationID int,ProgramID int,DonationAmount decimal(10,2)); INSERT INTO ProgramDonations VALUES (1,1,250),(2,2,500),(3,3,150),(4,4,400),(5,5,750),(6,1,300),(7,2,550),(8,3,175),(9,4,425),(10,5,800);
SELECT ProgramName, AVG(DonationAmount) as AvgDonation FROM ProgramDonations GROUP BY ProgramName;
List all seafood products with a weight greater than 10.
CREATE TABLE inventory (id INT,product_name TEXT,category TEXT,weight FLOAT); INSERT INTO inventory (id,product_name,category,weight) VALUES (1,'Wild Alaskan Salmon','Seafood',15.2),(2,'Farm-Raised Shrimp','Seafood',2.1),(3,'Pacific Cod','Seafood',12.5),(4,'Squid','Seafood',7.3);
SELECT * FROM inventory WHERE category = 'Seafood' AND weight > 10;
What is the total quantity of textiles sourced from each country?
CREATE TABLE Textiles (id INT,country VARCHAR(20),quantity INT); CREATE VIEW TextilesByCountry AS SELECT country,SUM(quantity) as total_quantity FROM Textiles GROUP BY country;
SELECT country, total_quantity FROM TextilesByCountry;
How many professional development courses did 'Teacher B' complete in '2019' and '2020'?
CREATE TABLE teacher_professional_development (teacher_name VARCHAR(20),course_name VARCHAR(30),completion_date DATE); INSERT INTO teacher_professional_development (teacher_name,course_name,completion_date) VALUES ('Teacher B','Course 4','2019-02-03'),('Teacher B','Course 5','2019-11-17'),('Teacher B','Course 6','2020-07-29');
SELECT teacher_name, COUNT(course_name) as total_courses FROM teacher_professional_development WHERE teacher_name = 'Teacher B' AND EXTRACT(YEAR FROM completion_date) IN (2019, 2020) GROUP BY teacher_name;
What is the total biomass for marine life in each type of habitat, partitioned by region?
CREATE TABLE life_habitat (region VARCHAR(50),habitat VARCHAR(50),biomass FLOAT); INSERT INTO life_habitat VALUES ('Region A','Habitat 1',123.4),('Region A','Habitat 2',234.5),('Region B','Habitat 1',345.6);
SELECT region, habitat, SUM(biomass) OVER (PARTITION BY region, habitat) as total_biomass FROM life_habitat;
What is the total number of travel advisories issued by the US and Canada for all countries in 2020?
CREATE TABLE travel_advisories (country VARCHAR(50),year INT,advisories INT);CREATE TABLE canada_travel_advisories (country VARCHAR(50),year INT,advisory_level INT);
SELECT SUM(advisories) FROM (SELECT country, SUM(advisories) AS advisories FROM travel_advisories WHERE year = 2020 GROUP BY country UNION ALL SELECT country, SUM(advisory_level) AS advisories FROM canada_travel_advisories WHERE year = 2020 GROUP BY country) AS total;
How many unique donors have donated in the North since 2019?
CREATE TABLE donors (donor_id INT,donor_name TEXT,donor_region TEXT,donation_date DATE); INSERT INTO donors (donor_id,donor_name,donor_region,donation_date) VALUES (1,'Jane Doe','North','2019-01-01'),(2,'Rajesh Smith','North','2020-01-01'),(3,'Sophia Johnson','North','2019-05-05');
SELECT COUNT(DISTINCT donor_name) as unique_donors FROM donors WHERE donation_date >= '2019-01-01' AND donor_region = 'North';
List all juvenile court cases that involved a status offense?
CREATE TABLE status_offenses (id INT,case_number INT,offense VARCHAR(20)); INSERT INTO status_offenses (id,case_number,offense) VALUES (1,33333,'Truancy'); INSERT INTO status_offenses (id,case_number,offense) VALUES (2,44444,'Curfew Violation');
SELECT * FROM status_offenses WHERE offense IN ('Truancy', 'Curfew Violation');
Compare the carbon pricing schemes in Canada and the United States
CREATE TABLE carbon_pricing (country VARCHAR(50),scheme VARCHAR(50),price FLOAT); INSERT INTO carbon_pricing (country,scheme,price) VALUES ('Canada','Carbon Tax',30.0),('Canada','Cap-and-Trade',20.5),('United States','Regulation',0.0);
SELECT * FROM carbon_pricing WHERE country IN ('Canada', 'United States');
What percentage of cosmetic products are certified cruelty-free?
CREATE TABLE cosmetics (product_name TEXT,cruelty_free BOOLEAN); INSERT INTO cosmetics (product_name,cruelty_free) VALUES ('ProductA',true),('ProductB',false),('ProductC',true),('ProductD',true),('ProductE',false),('ProductF',true);
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM cosmetics) AS percentage FROM cosmetics WHERE cruelty_free = true;
How many wildlife habitat records were inserted?
CREATE TABLE wildlife_habitat (id INT,name VARCHAR(50),area FLOAT); INSERT INTO wildlife_habitat (id,name,area) VALUES (1,'Habitat1',150.3),(2,'Habitat2',250.8),(3,'Habitat3',175.5);
SELECT COUNT(*) FROM wildlife_habitat;
What is the average monthly transaction value per customer for the last 6 months?
CREATE TABLE customers (customer_id INT,name VARCHAR(50),registration_date DATE); INSERT INTO customers (customer_id,name,registration_date) VALUES (1,'John Doe','2020-01-01'); INSERT INTO customers (customer_id,name,registration_date) VALUES (2,'Jane Smith','2020-02-15'); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_date DATE,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,transaction_date,amount) VALUES (1,1,'2021-04-01',500); INSERT INTO transactions (transaction_id,customer_id,transaction_date,amount) VALUES (2,1,'2021-04-15',300); INSERT INTO transactions (transaction_id,customer_id,transaction_date,amount) VALUES (3,2,'2021-04-20',700);
SELECT c.customer_id, AVG(t.amount) as avg_monthly_transaction FROM customers c JOIN transactions t ON c.customer_id = t.customer_id WHERE t.transaction_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) GROUP BY c.customer_id;
What is the total number of donations and total amount donated by each cause category in the 'Causes' table?
CREATE TABLE Causes (CauseID int,CauseName varchar(50),CauseCategory varchar(50),DonationCount int,TotalDonations numeric(18,2));
SELECT CauseCategory, SUM(DonationCount) as TotalDonationsCount, SUM(TotalDonations) as TotalDonationsAmount FROM Causes GROUP BY CauseCategory;
Find the total number of aircraft manufactured by Boeing and Airbus.
CREATE TABLE AircraftManufacturers (ID INT,Manufacturer VARCHAR(50),Quantity INT); INSERT INTO AircraftManufacturers (ID,Manufacturer,Quantity) VALUES (1,'Boeing',15000),(2,'Airbus',16000);
SELECT Manufacturer, SUM(Quantity) FROM AircraftManufacturers GROUP BY Manufacturer;
Show total sales revenue for recycled products in the last month.
CREATE TABLE products (product_id INT,name VARCHAR(255),recycled_materials BOOLEAN); INSERT INTO products (product_id,name,recycled_materials) VALUES (1,'Recycled Notebook',TRUE),(2,'Plastic Phone Case',FALSE); CREATE TABLE sales (sale_id INT,product_id INT,sale_price DECIMAL(10,2),sale_date DATE); INSERT INTO sales (sale_id,product_id,sale_price,sale_date) VALUES (1,1,12.99,'2022-12-05'),(2,2,5.99,'2022-11-10'),(3,1,12.99,'2022-12-20');
SELECT SUM(sale_price) FROM products JOIN sales ON products.product_id = sales.product_id WHERE recycled_materials = TRUE AND sale_date BETWEEN '2022-12-01' AND '2022-12-31';
What is the percentage of organic waste recycled in the waste management company's own operations in 2021?
CREATE TABLE company_waste(waste_type VARCHAR(255),year INT,recycled_waste FLOAT,total_waste FLOAT); INSERT INTO company_waste(waste_type,year,recycled_waste,total_waste) VALUES('Organic Waste',2021,123.45,234.56);
SELECT (recycled_waste / total_waste) * 100 FROM company_waste WHERE waste_type = 'Organic Waste' AND year = 2021;
What is the total budget for policy advocacy initiatives in the past 2 years?
CREATE TABLE policy_advocacy (initiative_id INT,initiative_name VARCHAR(30),budget DECIMAL(10,2),initiation_date DATE); INSERT INTO policy_advocacy (initiative_id,initiative_name,budget,initiation_date) VALUES (1,'Accessibility Laws',50000,'2021-01-01'),(2,'Inclusive Education',75000,'2020-06-15'),(3,'Employment Policies',60000,'2019-12-01');
SELECT SUM(budget) FROM policy_advocacy WHERE initiation_date >= '2020-01-01';
What was the total amount donated by individuals from the United States in Q1 2022?
CREATE TABLE donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,donor_name,donation_amount,donation_date) VALUES (1,'John Doe',50.00,'2022-01-05'),(2,'Jane Smith',100.00,'2022-03-15');
SELECT SUM(donation_amount) FROM donations WHERE donor_country = 'United States' AND donation_date BETWEEN '2022-01-01' AND '2022-03-31';
How many total visitors attended events in each month of the year?
CREATE TABLE events (id INT PRIMARY KEY,event_name VARCHAR(100),event_date DATE,num_attendees INT);
SELECT EXTRACT(MONTH FROM event_date) AS month, SUM(num_attendees) AS total_visitors FROM events GROUP BY month;
Delete marine species records from the Indian Ocean with a population less than 1000.
CREATE TABLE marine_species_research (id INT,species TEXT,location TEXT,year INT,population INT); INSERT INTO marine_species_research (id,species,location,year,population) VALUES (1,'Whale Shark','Indian Ocean',2010,1200),(2,'Dolphin','Indian Ocean',2005,500),(3,'Turtle','Indian Ocean',2018,2000);
DELETE FROM marine_species_research WHERE location = 'Indian Ocean' AND population < 1000;
Find the total financial assets of Shariah-compliant institutions in Malaysia and Indonesia?
CREATE TABLE if not exists financial_assets (id INT,institution_name VARCHAR(100),country VARCHAR(50),is_shariah_compliant BOOLEAN,assets DECIMAL(15,2));
SELECT SUM(assets) FROM financial_assets WHERE country IN ('Malaysia', 'Indonesia') AND is_shariah_compliant = TRUE;
How many marine species have been discovered in the Southern Ocean since 2000?
CREATE TABLE southern_ocean_species (species_name TEXT,year INTEGER,discovered BOOLEAN); INSERT INTO southern_ocean_species (species_name,year,discovered) VALUES ('Antarctic Krill',2005,TRUE),('Southern Ocean Squid',2010,TRUE);
SELECT COUNT(*) FROM southern_ocean_species WHERE year >= 2000 AND discovered = TRUE;
Delete all records in the community_engagement table related to the 'Cultural Awareness Program'?
CREATE TABLE community_engagement (id INT,program VARCHAR(50),country VARCHAR(50)); INSERT INTO community_engagement (id,program,country) VALUES (1,'Cultural Awareness Program','USA'),(2,'Language Preservation Project','Canada'),(3,'Artistic Heritage Revitalization','Mexico'),(4,'Traditional Craftsmanship Initiative','Spain'),(5,'Cultural Awareness Program','Brazil');
DELETE FROM community_engagement WHERE program = 'Cultural Awareness Program';
Identify marine species with a conservation status score below 50 that inhabit the Pacific Ocean.
CREATE TABLE species (id INT,name VARCHAR(50),habitat_ocean VARCHAR(50)); CREATE TABLE conservation_status (id INT,species_id INT,status VARCHAR(50),score FLOAT);
SELECT species.name FROM species INNER JOIN conservation_status ON species.id = conservation_status.species_id WHERE habitat_ocean = 'Pacific Ocean' AND score < 50;
List all defense projects with a start date after 2021-01-01 and end date before 2023-12-31
CREATE TABLE DefenseProjects (ProjectID INT,ProjectName VARCHAR(255),StartDate DATE,EndDate DATE); INSERT INTO DefenseProjects (ProjectID,ProjectName,StartDate,EndDate) VALUES (1,'Project A','2022-01-01','2022-12-31'),(2,'Project B','2021-12-01','2023-06-30'),(3,'Project C','2021-06-01','2022-11-30');
SELECT * FROM DefenseProjects WHERE StartDate > '2021-01-01' AND EndDate < '2023-12-31';
Identify the departments with zero employees
CREATE TABLE Departments (department_id INT,department_name VARCHAR(50),manufacturer_id INT); INSERT INTO Departments (department_id,department_name,manufacturer_id) VALUES (1,'Department1',4),(2,'Department2',4),(3,'Department3',5); CREATE TABLE Employees (employee_id INT,employee_name VARCHAR(50),department_id INT); INSERT INTO Employees (employee_id,employee_name,department_id) VALUES (1,'Employee1',1),(2,'Employee2',1),(3,'Employee3',2); CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),region VARCHAR(50)); INSERT INTO Manufacturers (manufacturer_id,manufacturer_name,region) VALUES (4,'ManufacturerD','North America'),(5,'ManufacturerE','Asia-Pacific');
SELECT d.department_name FROM Departments d LEFT JOIN Employees e ON d.department_id = e.department_id WHERE e.employee_id IS NULL;
What is the distribution of policy types by region?
CREATE TABLE Policy (PolicyID INT,PolicyType VARCHAR(20),Region VARCHAR(20)); INSERT INTO Policy (PolicyID,PolicyType,Region) VALUES (1,'Auto','Northeast'),(2,'Home','Northeast'),(3,'Life','Midwest');
SELECT PolicyType, Region, COUNT(*) OVER (PARTITION BY PolicyType, Region) AS CountByTypeRegion, ROW_NUMBER() OVER (PARTITION BY PolicyType ORDER BY Region) AS RankByPolicyType FROM Policy;
What percentage of total donations was allocated to each project category in 2021?
CREATE TABLE donations (donation_id INT,donation_amount DECIMAL,donation_date DATE,project_category VARCHAR(255)); INSERT INTO donations (donation_id,donation_amount,donation_date,project_category) VALUES (1,500,'2021-06-15','Arts & Culture'),(2,300,'2021-03-01','Arts & Culture'),(3,700,'2021-12-28','Education');
SELECT project_category, (SUM(donation_amount) / (SELECT SUM(donation_amount) FROM donations WHERE donation_date BETWEEN '2021-01-01' AND '2021-12-31')) * 100 as percentage_of_total FROM donations WHERE donation_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY project_category;
What is the total number of reported crimes in the state of New York in 2018?
CREATE TABLE ReportedCrimes (ID INT,State VARCHAR(20),Year INT,Crimes INT); INSERT INTO ReportedCrimes (ID,State,Year,Crimes) VALUES (1,'New York',2018,1200);
SELECT SUM(Crimes) FROM ReportedCrimes WHERE State = 'New York' AND Year = 2018;
Find all excavation sites in 'Country X' and 'Country Y'
CREATE TABLE ExcavationSites (SiteID INT,SiteName TEXT,Country TEXT,StartDate DATE,EndDate DATE);
SELECT SiteName FROM ExcavationSites WHERE Country IN ('Country X', 'Country Y');
What are the total costs of satellite components supplied by each supplier in 2019?
CREATE TABLE Supplier_Components (component_id INT,component_name VARCHAR(50),supplier VARCHAR(50),component_cost DECIMAL(10,2),year INT); INSERT INTO Supplier_Components (component_id,component_name,supplier,component_cost,year) VALUES (1,'Solar Panel','SpaceX',10000,2019),(2,'Communications System','Blue Origin',50000,2019),(3,'Battery','Northrop Grumman',30000,2019),(4,'Antenna','Airbus',25000,2019);
SELECT supplier, SUM(component_cost) as total_component_cost FROM Supplier_Components WHERE year = 2019 GROUP BY supplier;
How many autonomous driving research papers have been published in Europe?
CREATE TABLE ResearchPapers (Id INT,Title VARCHAR(50),PublicationDate DATE,Country VARCHAR(20)); INSERT INTO ResearchPapers (Id,Title,PublicationDate,Country) VALUES (1,'Autonomous Driving Revolution','2022-01-01','USA'),(2,'AI and Self-Driving Cars','2021-12-15','Germany'),(3,'The Future of Autonomous Vehicles','2022-02-20','Japan'),(4,'Autonomous Driving in Asia','2022-03-05','China'),(5,'Self-Driving Cars in Europe','2022-06-10','Germany');
SELECT COUNT(*) FROM ResearchPapers WHERE Country = 'Germany';
Find the total quantity of Lanthanum imported to Oceania before 2017 and the number of unique importers.
CREATE TABLE imports (id INT,country VARCHAR(50),Lanthanum_imported FLOAT,importer_id INT,datetime DATETIME); INSERT INTO imports (id,country,Lanthanum_imported,importer_id,datetime) VALUES (1,'Australia',120.0,500,'2016-01-01 10:00:00'),(2,'New Zealand',90.0,350,'2016-02-15 14:30:00');
SELECT country, SUM(Lanthanum_imported) AS total_Lanthanum, COUNT(DISTINCT importer_id) AS unique_importers FROM imports WHERE YEAR(datetime) < 2017 AND Lanthanum_imported IS NOT NULL AND country LIKE 'Oceania%' GROUP BY country;
Show the total number of contract negotiations for 'Global Defence Inc.'
CREATE TABLE company (name VARCHAR(50),type VARCHAR(50)); INSERT INTO company (name,type) VALUES ('Global Defence Inc.','Defense Contractor'),('Techno Solutions','Defense Contractor'),('Alpha Corp.','Defense Contractor'),('Beta Industries','Defense Contractor'); CREATE TABLE contract_negotiations (contract_id INT,company_name VARCHAR(50),negotiation_date DATE); INSERT INTO contract_negotiations (contract_id,company_name,negotiation_date) VALUES (1,'Global Defence Inc.','2022-01-15'),(2,'Global Defence Inc.','2022-02-10'),(3,'Alpha Corp.','2022-03-17'),(4,'Techno Solutions','2022-04-05'),(5,'Beta Industries','2022-05-22');
SELECT COUNT(*) FROM contract_negotiations WHERE company_name = 'Global Defence Inc.';
What is the total distance traveled by trains in the Paris metropolitan area in the last year?
CREATE TABLE train_routes (route_id INT,route_distance INT,city VARCHAR(255)); CREATE TABLE train_trips (trip_id INT,route_id INT,trip_date DATE);
SELECT SUM(route_distance) FROM train_routes JOIN train_trips ON train_routes.route_id = train_trips.route_id WHERE train_routes.city = 'Paris' AND train_trips.trip_date >= DATEADD(YEAR, -1, GETDATE());
List the digital assets that have had the most transactions on a single day.
CREATE TABLE transactions (asset TEXT,tx_date DATE); INSERT INTO transactions (asset,tx_date) VALUES ('Securitize','2021-01-01'),('Securitize','2021-01-02'),('Polymath','2021-01-01'),('Polymath','2021-01-02'),('Polymath','2021-01-03');
SELECT asset, MAX(tx_count) FROM (SELECT asset, COUNT(*) AS tx_count FROM transactions GROUP BY asset, tx_date) AS subquery GROUP BY asset;
What is the total amount of climate finance committed to climate adaptation projects in Europe between 2010 and 2015?
CREATE TABLE climate_finance (project_id INT,project_name TEXT,location TEXT,funded_year INT,funding_amount FLOAT); INSERT INTO climate_finance (project_id,project_name,location,funded_year,funding_amount) VALUES (1,'Adaptation 1','France',2010,6000000.0),(2,'Mitigation 1','Germany',2013,8000000.0),(3,'Adaptation 2','Spain',2015,4000000.0);
SELECT SUM(funding_amount) FROM climate_finance WHERE funded_year BETWEEN 2010 AND 2015 AND project_type = 'climate adaptation' AND location LIKE 'Europe%';
Which sites have 'Stone Age' artifacts?
CREATE TABLE SiteArtifacts (SiteID varchar(5),ArtifactPeriod varchar(15)); INSERT INTO SiteArtifacts (SiteID,ArtifactPeriod) VALUES ('S001','Stone Age'),('S002','Bronze Age');
SELECT SiteID FROM SiteArtifacts WHERE ArtifactPeriod = 'Stone Age';
What is the minimum salary of members in the 'Construction Union' who work in Texas?
CREATE TABLE ConstructionUnion (member_id INT,member_name TEXT,salary FLOAT,state TEXT); INSERT INTO ConstructionUnion (member_id,member_name,salary,state) VALUES (1,'John Doe',45000,'Texas'); INSERT INTO ConstructionUnion (member_id,member_name,salary,state) VALUES (2,'Jane Smith',50000,'Texas');
SELECT MIN(salary) FROM ConstructionUnion WHERE state = 'Texas';
What are the total scores for the 'Apex Predators' team?
CREATE TABLE PlayerTeam (PlayerID INT,TeamID INT); INSERT INTO PlayerTeam (PlayerID,TeamID) VALUES (101,1),(102,1),(103,2),(104,3); CREATE TABLE PlayerScore (PlayerID INT,GameID INT,TeamID INT,Score INT); INSERT INTO PlayerScore (PlayerID,GameID,TeamID,Score) VALUES (101,1001,1,70),(102,1001,1,80),(103,1002,2,85),(104,1002,2,90);
SELECT SUM(Score) FROM PlayerScore WHERE TeamID = 1;
What is the average delivery time for satellites?
CREATE TABLE SatelliteDeployments (satellite_id INT,launch_date DATE,delivery_time INT);
SELECT AVG(delivery_time) FROM SatelliteDeployments;
Add a new entry to the "crops" table with the name "sorghum", a yield of 80, and region "Africa"
CREATE TABLE crops (id SERIAL PRIMARY KEY,name TEXT,yield INT,region TEXT);
INSERT INTO crops (name, yield, region) VALUES ('sorghum', 80, 'Africa');
Which art movements had the most artworks created in Asia during the 20th century?
CREATE TABLE Artworks (ArtworkID INT,ArtworkName TEXT,Movement TEXT,Year INT); INSERT INTO Artworks (ArtworkID,ArtworkName,Movement,Year) VALUES (1,'Moonlight','Impressionism',1920); INSERT INTO Artworks (ArtworkID,ArtworkName,Movement,Year) VALUES (2,'Silent Song','Cubism',1930);
SELECT Movement, COUNT(*) as NumArtworks FROM Artworks WHERE Year BETWEEN 1900 AND 1999 AND Region = 'Asia' GROUP BY Movement ORDER BY NumArtworks DESC;
What is the total number of alternative sentencing programs implemented in California between 2017 and 2020?
CREATE TABLE alternative_sentencing_ca (id INT,program_name VARCHAR(50),start_date DATE,end_date DATE,state VARCHAR(50)); INSERT INTO alternative_sentencing_ca (id,program_name,start_date,end_date,state) VALUES (1,'Rehabilitation Works','2017-01-01','2020-12-31','California'),(2,'Justice Alternatives','2016-01-01','2019-12-31','New York');
SELECT SUM(id) FROM alternative_sentencing_ca WHERE state = 'California' AND start_date >= '2017-01-01' AND end_date <= '2020-12-31';
Insert a new fare for 'Ferry' rides
CREATE TABLE fares (ride_type TEXT,fare DECIMAL(5,2));
INSERT INTO fares (ride_type, fare) VALUES ('Ferry', 3.00);
What is the total number of public transportation trips taken in each city in 2020?
CREATE TABLE public_transportation (city TEXT,trip_count INT,year INT); INSERT INTO public_transportation (city,trip_count,year) VALUES ('New York',5000,2020),('Los Angeles',4000,2020);
SELECT city, SUM(trip_count) as total_trips FROM public_transportation WHERE year = 2020 GROUP BY city;
What is the average weight of packages shipped to Texas from the 'west' region?
CREATE TABLE warehouses (id INT,name TEXT,region TEXT); INSERT INTO warehouses (id,name,region) VALUES (1,'Seattle Warehouse','west'),(2,'Dallas Warehouse','south'); CREATE TABLE packages (id INT,warehouse_id INT,weight FLOAT,state TEXT); INSERT INTO packages (id,warehouse_id,weight,state) VALUES (1,1,15.5,'Texas'),(2,1,20.3,'California'),(3,2,12.8,'Texas');
SELECT AVG(weight) FROM packages p JOIN warehouses w ON p.warehouse_id = w.id WHERE w.region = 'west' AND p.state = 'Texas';
What is the average donation amount per donor in the United States, for the year 2020, rounded to the nearest dollar?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),Country VARCHAR(50),Amount DECIMAL(10,2),DonationYear INT); INSERT INTO Donors (DonorID,DonorName,Country,Amount,DonationYear) VALUES (1,'John Doe','USA',500.00,2020),(2,'Jane Smith','USA',350.00,2020),(3,'Alice Johnson','USA',700.00,2020);
SELECT ROUND(AVG(Amount), 0) AS AvgDonationPerDonor FROM Donors WHERE Country = 'USA' AND DonationYear = 2020;
Update the 'players' table to set the name to 'Anonymous' for the player with ID 1
CREATE TABLE players (player_id INT,name VARCHAR(255));
UPDATE players SET name = 'Anonymous' WHERE player_id = 1;