instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What cybersecurity strategies were implemented in 2010?
CREATE TABLE Cybersecurity_Strategies (Year INT,Strategy VARCHAR(255)); INSERT INTO Cybersecurity_Strategies (Year,Strategy) VALUES (2005,'Cybersecurity Initiative'),(2010,'Comprehensive National Cybersecurity Initiative'),(2015,'Cybersecurity National Action Plan');
SELECT Strategy FROM Cybersecurity_Strategies WHERE Year = 2010;
Update the genre of the song 'Vande Mataram' to 'Indian Classical Fusion'
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,ArtistName VARCHAR(100)); CREATE TABLE Songs (SongID INT PRIMARY KEY,SongName VARCHAR(100),ArtistID INT,Genre VARCHAR(50),ReleasedDate DATE); INSERT INTO Artists (ArtistID,ArtistName) VALUES (101,'Selena Gomez'),(102,'Taylor Swift'),(103,'Kala Bhairava'),(104,'Billie Eilish'),(105,'Maria Fernandes'); INSERT INTO Songs (SongID,SongName,ArtistID,Genre,ReleasedDate) VALUES (1,'Bad Liar',101,'Pop','2017-05-19'),(2,'Shake it Off',102,'Pop','2014-08-18'),(3,'Vande Mataram',103,'Indian Classical','2018-12-15'),(4,'Bad Guy',104,'Pop','2019-03-29'),(5,'Tuyo',105,'Latin Pop','2021-05-21');
UPDATE Songs SET Genre = 'Indian Classical Fusion' WHERE SongName = 'Vande Mataram';
What is the name and release year of the most recent album in the rock genre?
CREATE TABLE albums (album_id INT,title VARCHAR(255),release_year INT,genre VARCHAR(10));
SELECT title, release_year FROM albums WHERE genre = 'rock' ORDER BY release_year DESC LIMIT 1;
Which programs have received donations from donors residing in multiple countries?
CREATE TABLE donations (id INT,amount REAL,donor_id INT,country TEXT); INSERT INTO donations (id,amount,donor_id,country) VALUES (1,50.0,1001,'Canada'),(2,100.0,1002,'USA'),(3,75.0,1003,'Mexico'),(4,25.0,1002,'Canada');
SELECT program_id, COUNT(DISTINCT country) AS num_countries FROM donations GROUP BY program_id HAVING num_countries > 1;
What is the number of students in the mental health program who have had exactly 2 absences in the past month?
CREATE TABLE students (id INT,name VARCHAR(50),program VARCHAR(50),absences INT,last_visit DATE);
SELECT COUNT(*) FROM students WHERE program = 'mental health' AND absences = 2 AND last_visit >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
What is the minimum salary in the HR department?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Salary FLOAT); INSERT INTO Employees (EmployeeID,Department,Salary) VALUES (1,'IT',70000),(2,'HR',65000),(3,'IT',75000),(4,'Finance',72000);
SELECT MIN(Salary) FROM Employees WHERE Department = 'HR';
Show total production for each company in the North Sea, including companies that have no production
CREATE TABLE Company (CompanyID int,CompanyName varchar(50),Location varchar(50)); CREATE TABLE Production (ProductionID int,CompanyID int,ProductionQuantity int);
SELECT Company.CompanyName, SUM(Production.ProductionQuantity) as Total_Production FROM Company LEFT JOIN Production ON Company.CompanyID = Production.CompanyID WHERE Company.Location = 'North Sea' GROUP BY Company.CompanyName;
What is the minimum capacity for schools in each location ('community_development')?
CREATE TABLE community_development.schools (id INT,name VARCHAR(50),capacity INT,location VARCHAR(50));
SELECT location, MIN(capacity) FROM community_development.schools GROUP BY location;
List all unique ethical AI principles.
CREATE TABLE ethical_ai_principles (id INT,principle VARCHAR(100)); INSERT INTO ethical_ai_principles (id,principle) VALUES (1,'Fairness'),(2,'Transparency'),(3,'Accountability'),(4,'Privacy'),(5,'Non-Discrimination');
SELECT DISTINCT principle FROM ethical_ai_principles;
What is the average budget allocated for AI projects in Latin America?
CREATE TABLE ai_projects (project_id INT,region VARCHAR(20),budget DECIMAL(10,2)); INSERT INTO ai_projects (project_id,region,budget) VALUES (1,'Latin America',50000.00),(2,'Europe',100000.00),(3,'North America',200000.00);
SELECT AVG(budget) FROM ai_projects WHERE region = 'Latin America';
Which country had the most ad impressions on our social media platform in July 2022?
CREATE TABLE ads (id INT,country VARCHAR(50),impressions INT); INSERT INTO ads (id,country,impressions) VALUES (1,'USA',5000),(2,'Canada',3000),(3,'Mexico',4000);
SELECT country, SUM(impressions) as total_impressions FROM ads WHERE ads.date BETWEEN '2022-07-01' AND '2022-07-31' GROUP BY country ORDER BY total_impressions DESC LIMIT 1;
Find the top 5 countries with the lowest financial capability scores in Europe.
CREATE TABLE financial_capability (id INT,country VARCHAR(255),score INT);
SELECT country, score FROM (SELECT country, score, ROW_NUMBER() OVER (ORDER BY score ASC) rn FROM financial_capability WHERE region = 'Europe') t WHERE rn <= 5;
List all Shariah-compliant financial products offered by the bank.
CREATE TABLE financial_products (id INT,name TEXT,type TEXT); CREATE VIEW shariah_compliant_products AS SELECT * FROM financial_products WHERE type = 'Shariah-compliant';
SELECT name FROM shariah_compliant_products;
What is the maximum financial wellbeing score for customers who have a socially responsible loan?
CREATE TABLE socially_responsible_loans (loan_id INT,customer_id INT,financial_wellbeing_score INT); CREATE TABLE socially_responsible_lending (lending_id INT,loan_id INT);
SELECT MAX(srl.financial_wellbeing_score) FROM socially_responsible_loans srl JOIN socially_responsible_lending srlg ON srl.loan_id = srlg.loan_id;
What are the names and capacities of all warehouses located in Canada?
CREATE TABLE Warehouses (warehouse_id INT,name TEXT,capacity INT,country TEXT); INSERT INTO Warehouses (warehouse_id,name,capacity,country) VALUES (1,'Warehouse A',5000,'Canada'),(2,'Warehouse B',7000,'USA');
SELECT name, capacity FROM Warehouses WHERE country = 'Canada';
Virtual tourism revenue by quarter in 2022, for the Americas.
CREATE TABLE tourism_revenue (country VARCHAR(50),revenue FLOAT,quarter INT,year INT); INSERT INTO tourism_revenue (country,revenue,quarter,year) VALUES ('USA',1200000,1,2022),('Canada',800000,1,2022),('Mexico',500000,1,2022),('USA',1500000,2,2022),('Canada',900000,2,2022),('Mexico',600000,2,2022);
SELECT quarter, SUM(revenue) as total_revenue FROM tourism_revenue WHERE country LIKE '%Americas%' AND year = 2022 GROUP BY quarter;
List the number of virtual tours conducted per salesperson in the 'Sales' table.
CREATE TABLE Sales (salesperson_id INT,salesperson_name TEXT,virtual_tours INT); INSERT INTO Sales (salesperson_id,salesperson_name,virtual_tours) VALUES (1,'John Doe',15),(2,'Jane Smith',18);
SELECT salesperson_name, COUNT(virtual_tours) FROM Sales GROUP BY salesperson_name;
What is the difference in the number of bridges between 'California' and 'Texas'?
CREATE TABLE Bridges (name TEXT,state TEXT); INSERT INTO Bridges (name,state) VALUES ('Golden Gate Bridge','California'); INSERT INTO Bridges (name,state) VALUES ('Houston Ship Channel Bridge','Texas');
SELECT COUNT(*) - (SELECT COUNT(*) FROM Bridges WHERE state = 'Texas') FROM Bridges WHERE state = 'California';
Determine the percentage of sales from each ingredient category
CREATE TABLE Sales_Details (sale_id INT,ingredient_id INT,quantity INT); INSERT INTO Sales_Details (sale_id,ingredient_id,quantity) VALUES (1,1,2),(1,2,8),(2,1,3),(2,2,7); CREATE TABLE Ingredient_Categories (ingredient_id INT,ingredient_category VARCHAR(255)); INSERT INTO Ingredient_Categories (ingredient_id,ingredient_category) VALUES (1,'Legumes'),(2,'Poultry');
SELECT ingredient_category, SUM(quantity) AS total_quantity, SUM(quantity) * 100.0 / (SELECT SUM(quantity) FROM Sales_Details) AS percentage_of_sales FROM Sales_Details, Ingredient_Categories WHERE Sales_Details.ingredient_id = Ingredient_Categories.ingredient_id GROUP BY ingredient_category;
List all geopolitical risk assessments with a rating greater than 7.0 from North America since 2020.
CREATE TABLE GeopoliticalRiskAssessments (id INT,assessment_name VARCHAR(100),region VARCHAR(50),rating FLOAT,assessment_date DATE); INSERT INTO GeopoliticalRiskAssessments (id,assessment_name,region,rating,assessment_date) VALUES (1,'Assessment A','North America',7.2,'2020-05-12'); INSERT INTO GeopoliticalRiskAssessments (id,assessment_name,region,rating,assessment_date) VALUES (2,'Assessment B','North America',8.1,'2021-03-03'); INSERT INTO GeopoliticalRiskAssessments (id,assessment_name,region,rating,assessment_date) VALUES (3,'Assessment C','North America',6.9,'2022-08-25');
SELECT * FROM GeopoliticalRiskAssessments WHERE region = 'North America' AND rating > 7.0 AND assessment_date >= '2020-01-01';
How many workers are there in the mining industry in California?
CREATE TABLE Mines (MineID INT,Name TEXT,Location TEXT,TotalWorkers INT); INSERT INTO Mines (MineID,Name,Location,TotalWorkers) VALUES (1,'Golden Mine','California',250),(2,'Silver Ridge','Nevada',300);
SELECT SUM(TotalWorkers) FROM Mines WHERE Location = 'California';
Find and delete duplicate records in the resource_depletion table
CREATE TABLE resource_depletion (id INT,resource VARCHAR(255),depletion_rate DECIMAL(10,2));
DELETE t1 FROM resource_depletion t1 INNER JOIN (SELECT id, resource, depletion_rate, COUNT(*) FROM resource_depletion GROUP BY resource, depletion_rate HAVING COUNT(*) > 1) t2 ON t1.resource = t2.resource AND t1.depletion_rate = t2.depletion_rate AND t1.id < t2.id;
List all mines and their number of employees, grouped by country
CREATE TABLE mine (id INT,name TEXT,country TEXT); CREATE TABLE employee (id INT,mine_id INT,name TEXT); INSERT INTO mine VALUES (1,'Mine A','Country A'); INSERT INTO mine VALUES (2,'Mine B','Country B'); INSERT INTO employee VALUES (1,1,'John'); INSERT INTO employee VALUES (2,1,'Maria'); INSERT INTO employee VALUES (3,2,'David');
SELECT mine.country, COUNT(employee.id) AS employee_count FROM mine INNER JOIN employee ON mine.id = employee.mine_id GROUP BY mine.country;
What was the total revenue from broadband services in Q3 2021?
CREATE TABLE broadband_revenue (revenue_id INT,revenue DECIMAL(10,2),revenue_date DATE); INSERT INTO broadband_revenue (revenue_id,revenue,revenue_date) VALUES (1,50000.00,'2021-07-01'),(2,60000.00,'2021-08-01'),(3,75000.00,'2021-09-01');
SELECT SUM(revenue) AS total_revenue FROM broadband_revenue WHERE revenue_date BETWEEN '2021-07-01' AND '2021-09-30';
What was the total revenue for concerts in states that start with the letter 'C'?
CREATE TABLE concerts (id INT,state VARCHAR(255),revenue FLOAT); INSERT INTO concerts (id,state,revenue) VALUES (1,'California',100000.0),(2,'Colorado',30000.0);
SELECT SUM(revenue) FROM concerts WHERE state LIKE 'C%';
What's the total number of news articles published in January 2021 and February 2021?
CREATE TABLE ny_times (article_id INT,article_date DATE); INSERT INTO ny_times (article_id,article_date) VALUES (1,'2021-01-01'),(2,'2021-01-02'),(3,'2021-02-01'),(4,'2021-02-02');
SELECT COUNT(*) FROM ny_times WHERE article_date BETWEEN '2021-01-01' AND '2021-01-31' UNION ALL SELECT COUNT(*) FROM ny_times WHERE article_date BETWEEN '2021-02-01' AND '2021-02-28';
Insert a new record for 'donor_information' table with 'donor_name' as 'Sophia Choi', 'donor_type' as 'local_donors', and 'total_donated' as 1200.
CREATE TABLE donor_information (donor_name VARCHAR(50),donor_type VARCHAR(20),total_donated DECIMAL(10,2));
INSERT INTO donor_information (donor_name, donor_type, total_donated) VALUES ('Sophia Choi', 'local_donors', 1200);
Display the name and location of all marine research labs.
CREATE TABLE marine_research_labs (lab_name TEXT,lab_location TEXT); INSERT INTO marine_research_labs (lab_name,lab_location) VALUES ('Oceanus Institute','Portugal'),('Aquatica Lab','Canada'),('Blue Horizon Research','Brazil');
SELECT lab_name, lab_location FROM marine_research_labs;
What are the names and types of vessels used in research expeditions in the regions with the lowest ocean acidification levels?
CREATE TABLE ocean_acidification (id INT PRIMARY KEY,region VARCHAR(255),year INT,acidification_level INT); INSERT INTO ocean_acidification (id,region,year,acidification_level) VALUES (1,'Arctic Ocean',2018,20),(2,'Southern Ocean',2019,22); CREATE TABLE expedition_vessels (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),region VARCHAR(255)); INSERT INTO expedition_vessels (id,name,type,region) VALUES (1,'Sea Researcher','Research Vessel','Arctic Ocean');
SELECT v.name, v.type FROM expedition_vessels v INNER JOIN ocean_acidification oa ON v.region = oa.region WHERE oa.acidification_level = (SELECT MIN(acidification_level) FROM ocean_acidification);
What is the minimum donation amount from donors in South Africa?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL(10,2),Country TEXT);
SELECT MIN(DonationAmount) FROM Donors WHERE Country = 'South Africa';
How many times has each soil moisture sensor been recalibrated in the past year?
CREATE TABLE soil_moisture_sensors (sensor_id INTEGER,last_calibration TIMESTAMP);
SELECT sensor_id, COUNT(*) as calibrations_count FROM soil_moisture_sensors WHERE last_calibration >= NOW() - INTERVAL '1 year' GROUP BY sensor_id ORDER BY calibrations_count DESC;
Delete records in the "park_violations" table where the "fine_amount" is greater than $100
CREATE TABLE park_violations (violation_id INT,vehicle_plate VARCHAR(20),fine_amount DECIMAL(5,2));
DELETE FROM park_violations WHERE fine_amount > 100.00;
How many traffic violations were issued in 2019, broken down by violation type and city?
CREATE TABLE TrafficViolations (Year INT,ViolationType VARCHAR(255),City VARCHAR(255),Count INT); INSERT INTO TrafficViolations (Year,ViolationType,City,Count) VALUES (2019,'Speeding','New York',2500),(2019,'Parking','New York',3000),(2019,'Speeding','Los Angeles',2000),(2019,'Parking','Los Angeles',3500);
SELECT ViolationType, City, COUNT(*) AS ViolationCount FROM TrafficViolations WHERE Year = 2019 GROUP BY ViolationType, City;
What is the average budget allocated for all categories in the Central region in the year 2020?
CREATE TABLE Budget (Year INT,Region VARCHAR(50),Category VARCHAR(50),Amount INT); INSERT INTO Budget (Year,Region,Category,Amount) VALUES (2020,'Central','Education',5000000),(2020,'Central','Public Transportation',6000000);
SELECT AVG(Amount) FROM Budget WHERE Year = 2020 AND Region = 'Central';
How many clean energy policy proposals have been submitted in Europe in the last 5 years?
CREATE TABLE policies (id INT,region VARCHAR(255),name VARCHAR(255),submission_year INT); INSERT INTO policies (id,region,name,submission_year) VALUES (1,'Europe','Policy1',2017),(2,'Europe','Policy2',2019),(3,'Europe','Policy3',2018),(4,'Europe','Policy4',2016);
SELECT COUNT(*) FROM policies WHERE region = 'Europe' AND submission_year >= 2016;
Identify the number of ethical labor violations for suppliers located in Spain and Portugal.
CREATE TABLE suppliers (supplier_id INT,supplier_location VARCHAR(255),num_violations INT);
SELECT COUNT(*) FROM suppliers WHERE supplier_location IN ('Spain', 'Portugal') AND num_violations > 0;
What is the total quantity of products sold by each customer?
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(255)); CREATE TABLE sales (sale_id INT,customer_id INT,product_quantity INT);
SELECT customers.customer_name, SUM(sales.product_quantity) as total_quantity FROM sales JOIN customers ON sales.customer_id = customers.customer_id GROUP BY customers.customer_name;
How many days has each spacecraft been in space, ordered by manufacturer?
CREATE TABLE Spacecraft (id INT,name VARCHAR(50),type VARCHAR(50),manufacturer VARCHAR(50),launch_date DATE);
SELECT name, type, DATEDIFF(day, launch_date, GETDATE()) as days_in_space, manufacturer FROM Spacecraft ORDER BY manufacturer, days_in_space DESC;
How many spacecraft components have been manufactured by AstroCorp in Russia with a weight less than 100 tons?
CREATE TABLE spacecraft_components (id INT,company VARCHAR(255),country VARCHAR(255),component_type VARCHAR(255),weight FLOAT); INSERT INTO spacecraft_components (id,company,country,component_type,weight) VALUES (1,'AstroCorp','Russia','Propulsion System',50.0),(2,'AstroCorp','Russia','Structure',200.0);
SELECT COUNT(*) FROM spacecraft_components WHERE company = 'AstroCorp' AND country = 'Russia' AND weight < 100.0;
What is the average orbital velocity of all satellites in low Earth orbit?
CREATE TABLE satellites (id INT,name VARCHAR(50),orbit VARCHAR(50),velocity FLOAT); INSERT INTO satellites (id,name,orbit,velocity) VALUES (1,'ISS','Low Earth Orbit',7662);
SELECT AVG(velocity) FROM satellites WHERE orbit = 'Low Earth Orbit';
Count the number of fans from the 'fan_demographics' table who are over 30 years old and reside in 'NY' or 'CA'.
CREATE TABLE fan_demographics (fan_id INT,age INT,state VARCHAR(2));
SELECT COUNT(*) FROM fan_demographics WHERE age > 30 AND state IN ('NY', 'CA');
What is the average fan attendance per game for each team?
CREATE TABLE FanAttendance (GameID INT,TeamID INT,FanAttendance INT); INSERT INTO FanAttendance VALUES (1,1,5000),(2,1,5200),(3,2,6000),(4,2,6200);
SELECT TeamID, AVG(FanAttendance) as AvgFanAttendance FROM FanAttendance GROUP BY TeamID;
What is the total revenue for each sport in the 'team_performances' table?
CREATE TABLE team_performances (team VARCHAR(20),sport VARCHAR(20),games_played INT,wins INT,losses INT,revenue DECIMAL(10,2));
SELECT sport, SUM(revenue) FROM team_performances GROUP BY sport;
Identify the top 2 vulnerabilities with the most occurrences in the past 3 months, along with the number of affected systems for each.
CREATE TABLE vulnerabilities (id INT PRIMARY KEY,vulnerability_name VARCHAR(50),occurrence_time TIMESTAMP,affected_system VARCHAR(50)); INSERT INTO vulnerabilities (id,vulnerability_name,occurrence_time,affected_system) VALUES (1,'CVE-2022-21555','2022-05-01 10:00:00','Web Server'),(2,'CVE-2022-22954','2022-06-01 12:30:00','Database Server');
SELECT vulnerability_name, COUNT(DISTINCT affected_system) as affected_systems FROM vulnerabilities WHERE occurrence_time >= NOW() - INTERVAL '3 months' GROUP BY vulnerability_name ORDER BY affected_systems DESC LIMIT 2;
What is the number of unique names of vulnerabilities in the 'vulnerabilities' table?
CREATE TABLE schema1.vulnerabilities (id INT,name VARCHAR(255),severity VARCHAR(50),description TEXT,date_discovered DATE,last_observed DATE); INSERT INTO schema1.vulnerabilities (id,name,severity,description,date_discovered,last_observed) VALUES (1,'SQL Injection','Critical','Allows unauthorized access','2021-01-01','2021-02-01');
SELECT COUNT(DISTINCT name) FROM schema1.vulnerabilities;
What is the percentage of security incidents resolved within 24 hours for each department in the last month?
CREATE TABLE SecurityIncidents(id INT,department VARCHAR(50),resolved BOOLEAN,resolution_time FLOAT,incident_date DATE);
SELECT department, AVG(IF(resolution_time <= 24, 1, 0)) as resolved_within_24_hours FROM SecurityIncidents WHERE incident_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH) GROUP BY department;
Identify policyholders who have submitted more than two claims in the last 30 days?
CREATE TABLE Policy (PolicyNumber INT,PolicyholderName VARCHAR(50)); CREATE TABLE Claim (ClaimID INT,PolicyNumber INT,ClaimDate DATE); INSERT INTO Policy VALUES (1,'Amina Ali'),(2,'Raul Rodriguez'); INSERT INTO Claim VALUES (1,1,'2021-07-01'),(2,1,'2021-07-15'),(3,2,'2021-08-01'),(4,2,'2021-09-01'),(5,1,'2021-10-01'),(6,1,'2021-11-01'),(7,2,'2021-12-01');
SELECT PolicyNumber, PolicyholderName FROM Policy WHERE PolicyNumber IN (SELECT PolicyNumber FROM Claim WHERE ClaimDate >= DATEADD(DAY, -30, GETDATE()) GROUP BY PolicyNumber HAVING COUNT(DISTINCT ClaimDate) > 2);
Show the names and negotiation dates for all unions in New York that had at least 3 machinery malfunctions in the last 6 months.
CREATE TABLE UnionMembers (id INT PRIMARY KEY,name VARCHAR(50),state VARCHAR(2),union_id INT,FOREIGN KEY (union_id) REFERENCES UnionNegotiations(union_id)); CREATE TABLE UnionNegotiations (id INT PRIMARY KEY,union_id INT,negotiation_date DATE); CREATE TABLE WorkplaceSafety (id INT PRIMARY KEY,union_id INT,incident_date DATE,incident_type VARCHAR(20),severity INT);
SELECT m.name, n.negotiation_date FROM UnionMembers m JOIN UnionNegotiations n ON m.union_id = n.union_id JOIN (SELECT w.union_id FROM WorkplaceSafety w WHERE w.incident_date >= DATE(NOW()) - INTERVAL 6 MONTH AND w.incident_type = 'Machinery Malfunction' GROUP BY w.union_id HAVING COUNT(*) >= 3) malfunctions ON m.union_id = malfunctions.union_id ORDER BY n.negotiation_date DESC;
Count the number of electric vehicles sold by year, for vehicles with a range greater than 300 miles
CREATE TABLE electric_vehicles (id INT,vehicle_name VARCHAR(50),year INT,range INT,sales INT); INSERT INTO electric_vehicles (id,vehicle_name,year,range,sales) VALUES (1,'Tesla Model S',2020,373,50000),(2,'Tesla Model 3',2021,263,75000),(3,'Chevy Bolt',2022,259,40000),(4,'Nissan Leaf',2020,226,35000),(5,'Ford Mustang Mach-E',2021,303,60000);
SELECT year, COUNT(*) as high_range_evs FROM electric_vehicles WHERE range > 300 GROUP BY year;
What is the maximum fuel consumption by vessels in the Caribbean in January 2022?
CREATE TABLE FuelConsumption (Id INT,VesselName VARCHAR(50),Area VARCHAR(50),Consumption DATE,FuelConsumption DECIMAL(5,2));
SELECT MAX(FuelConsumption) FROM FuelConsumption WHERE Area = 'Caribbean' AND Consumption = '2022-01-01';
Identify the top 3 cities with the highest total water consumption in the year 2020.
CREATE TABLE water_consumption (city VARCHAR(50),consumption FLOAT,year INT); INSERT INTO water_consumption (city,consumption,year) VALUES ('Seattle',3500.5,2020),('Portland',4000.2,2020),('San-Francisco',2500.8,2020);
SELECT city, SUM(consumption) AS total_consumption FROM water_consumption WHERE year = 2020 GROUP BY city ORDER BY total_consumption DESC LIMIT 3;
What is the average water usage by all users in the state of New York?
CREATE TABLE all_users (id INT,state VARCHAR(20),water_usage FLOAT); INSERT INTO all_users (id,state,water_usage) VALUES (1,'New York',12.5),(2,'New York',15.6),(3,'California',10.2);
SELECT AVG(water_usage) FROM all_users WHERE state = 'New York';
What is the average age of members who have a gold membership and have used a treadmill in the past month?
CREATE TABLE Members (MemberID INT,Age INT,MembershipType VARCHAR(20)); INSERT INTO Members (MemberID,Age,MembershipType) VALUES (1,25,'Gold'),(2,30,'Silver'),(3,35,'Gold'); CREATE TABLE Workout (MemberID INT,Equipment VARCHAR(20),Duration INT); INSERT INTO Workout (MemberID,Equipment,Duration) VALUES (1,'Treadmill',60),(2,'Bike',45),(3,'Treadmill',30);
SELECT AVG(Members.Age) FROM Members INNER JOIN Workout ON Members.MemberID = Workout.MemberID WHERE Members.MembershipType = 'Gold' AND Workout.Equipment = 'Treadmill' AND Workout.Duration > 0;
What is the total number of workouts logged by users who identify as female?
CREATE TABLE user_info (user_id INT,gender VARCHAR(10),workouts_logged INT);
SELECT SUM(workouts_logged) FROM user_info WHERE gender = 'female';
What is the percentage of models trained on dataset A with a satisfaction score greater than 4.0, for each region, excluding North America?
CREATE TABLE models (id INT,dataset VARCHAR(20),satisfaction FLOAT,region VARCHAR(20)); INSERT INTO models VALUES (1,'datasetA',4.3,'Europe'),(2,'datasetA',4.5,'Asia'),(3,'datasetB',3.9,'Africa'),(4,'datasetB',4.1,'Africa'),(5,'datasetA',4.2,'North America');
SELECT region, 100.0 * AVG(satisfaction > 4.0) FROM models WHERE dataset = 'datasetA' AND region != 'North America' GROUP BY region;
Find the top 5 agricultural innovation projects with the highest budget in the Americas.
CREATE TABLE AgriculturalInnovation (ProjectID INT,ProjectName VARCHAR(100),ProjectType VARCHAR(100),Budget DECIMAL(10,2),Region VARCHAR(100)); INSERT INTO AgriculturalInnovation VALUES (1,'Precision Farming Project','Precision Farming',500000,'Americas'),(2,'Vertical Farming Project','Vertical Farming',400000,'Africa'),(3,'Drip Irrigation Project','Drip Irrigation',300000,'Asia'),(4,'Genetic Engineering Project','Genetic Engineering',200000,'Europe'),(5,'Drone Pollination Project','Drone Pollination',100000,'Oceania');
SELECT ProjectName, ProjectType, Budget FROM AgriculturalInnovation WHERE Region = 'Americas' ORDER BY Budget DESC FETCH NEXT 5 ROWS ONLY;
List the unique sectors and the number of economic diversification projects in the 'economic_diversification' table for each.
CREATE TABLE economic_diversification (id INT,project_name TEXT,sector TEXT); INSERT INTO economic_diversification (id,project_name,sector) VALUES (1,'Renewable Energy','Energy'),(2,'Smart Farming','Agriculture'),(3,'Artisanal Workshops','Crafts');
SELECT sector, COUNT(*) FROM economic_diversification GROUP BY sector;
What is the minimum cost of agricultural innovation projects in Mexico?
CREATE TABLE agriculture_innovation (id INT,country VARCHAR(50),sector VARCHAR(50),cost FLOAT); INSERT INTO agriculture_innovation (id,country,sector,cost) VALUES (1,'Mexico','Agriculture',100000);
SELECT MIN(cost) FROM agriculture_innovation WHERE country = 'Mexico' AND sector = 'Agriculture';
Calculate the average number of employees at each aircraft manufacturing plant by country.
CREATE TABLE country_plants (plant_id INT,country TEXT); INSERT INTO country_plants (plant_id,country) VALUES (1,'USA'),(2,'France'),(3,'Canada'),(4,'Brazil'),(5,'India'),(6,'Ukraine');
SELECT country, AVG(num_employees) as avg_employees FROM aircraft_plants JOIN country_plants ON aircraft_plants.plant_id = country_plants.plant_id GROUP BY country;
What is the maximum water temperature in Salmon Farms in the Pacific Ocean?
CREATE TABLE Salmon_Farms (Farm_ID INT,Farm_Name TEXT,Ocean TEXT,Water_Temperature FLOAT); INSERT INTO Salmon_Farms (Farm_ID,Farm_Name,Ocean,Water_Temperature) VALUES (1,'Farm P','Pacific',14.0); INSERT INTO Salmon_Farms (Farm_ID,Farm_Name,Ocean,Water_Temperature) VALUES (2,'Farm Q','Atlantic',16.0); INSERT INTO Salmon_Farms (Farm_ID,Farm_Name,Ocean,Water_Temperature) VALUES (3,'Farm R','Pacific',15.0);
SELECT MAX(Water_Temperature) FROM Salmon_Farms WHERE Ocean = 'Pacific';
What is the maximum number of hours worked per week by construction laborers in Germany?
CREATE TABLE Labor_Statistics (Employee_ID INT,Country VARCHAR(50),Job_Title VARCHAR(50),Hours_Per_Week INT);
SELECT MAX(Hours_Per_Week) FROM Labor_Statistics WHERE Country = 'Germany' AND Job_Title LIKE '%Construction%Laborer%';
What is the total number of construction laborers in Georgia?
CREATE TABLE LaborStatistics (id INT,job_title VARCHAR(50),hourly_wage DECIMAL(5,2),state VARCHAR(20)); INSERT INTO LaborStatistics (id,job_title,hourly_wage,state) VALUES (1,'Construction Laborer',20.50,'Georgia'),(2,'Carpenter',25.00,'California');
SELECT COUNT(*) FROM LaborStatistics WHERE job_title = 'Construction Laborer' AND state = 'Georgia';
Determine the percentage of cases handled by female attorneys that were won.
CREATE TABLE Performance (ID INT PRIMARY KEY,AttorneyID INT,Wins INT,Losses INT,TotalCases INT); CREATE TABLE Cases (ID INT PRIMARY KEY,CaseNumber VARCHAR(20),ClientID INT,AttorneyID INT,Outcome VARCHAR(20)); INSERT INTO Performance (ID,AttorneyID,Wins,Losses,TotalCases) VALUES (1,1,7,3,10),(2,2,6,2,8),(3,3,9,1,10); INSERT INTO Cases (ID,CaseNumber,ClientID,AttorneyID,Outcome) VALUES (1,'12345',1,1,'Won'),(2,'54321',2,2,'Won'),(3,'98765',3,3,'Won'),(4,'34567',1,1,'Lost'),(5,'76543',1,1,'Lost'),(6,'23456',2,2,'Lost'),(7,'65432',3,3,'Lost');
SELECT (SUM(CASE WHEN Gender = 'Female' AND Outcome = 'Won' THEN 1 ELSE 0 END) * 100.0 / NULLIF(SUM(CASE WHEN Gender = 'Female' THEN 1 ELSE 0 END), 0)) AS WinningPercentage FROM Cases INNER JOIN Attorneys ON Cases.AttorneyID = Attorneys.ID
Find the total billing amount for attorneys in the 'Criminal Law' practice area, for the year 2020, partitioned by attorney's last name and ordered by the total billing amount in descending order.
CREATE TABLE Attorneys (AttorneyID INT,FirstName VARCHAR(50),LastName VARCHAR(50),PracticeArea VARCHAR(50),TotalBilling FLOAT,BillingYear INT); INSERT INTO Attorneys (AttorneyID,FirstName,LastName,PracticeArea,TotalBilling,BillingYear) VALUES (1,'Clara','Rivera','Personal Injury',8000.00,2020),(2,'Jamal','Lee','Personal Injury',6000.00,2019),(3,'Sophia','Gomez','Criminal Law',9000.00,2020);
SELECT LastName, SUM(TotalBilling) OVER (PARTITION BY PracticeArea, LastName, BillingYear) AS TotalBilling FROM Attorneys WHERE PracticeArea = 'Criminal Law' AND BillingYear = 2020 ORDER BY TotalBilling DESC;
What is the total amount of climate finance invested in renewable energy projects by public and private sectors in Africa?
CREATE TABLE renewable_energy_projects (project_id INT,sector TEXT,investor_type TEXT,region TEXT,amount FLOAT); INSERT INTO renewable_energy_projects (project_id,sector,investor_type,region,amount) VALUES (1,'Renewable Energy','Public','Africa',5000000); INSERT INTO renewable_energy_projects (project_id,sector,investor_type,region,amount) VALUES (2,'Renewable Energy','Private','Africa',7000000);
SELECT SUM(amount) FROM renewable_energy_projects WHERE sector = 'Renewable Energy' AND region = 'Africa';
What is the total funding allocated for climate change adaptation initiatives in Africa in 2020?
CREATE TABLE climate_funds (fund_id INT,initiative_name VARCHAR(50),region VARCHAR(50),allocation DECIMAL(10,2),funding_year INT); INSERT INTO climate_funds (fund_id,initiative_name,region,allocation,funding_year) VALUES (1,'Green Climate Fund','Africa',5000000.00,2020),(2,'Adaptation Fund','Africa',2500000.00,2020);
SELECT SUM(allocation) FROM climate_funds WHERE region = 'Africa' AND funding_year = 2020 AND initiative_name IN ('Green Climate Fund', 'Adaptation Fund');
What is the average funding round size for startups founded by women in the healthcare sector?
CREATE TABLE company (id INT,name TEXT,industry TEXT,founder_gender TEXT); INSERT INTO company (id,name,industry,founder_gender) VALUES (1,'MedHealth','Healthcare','Female'); INSERT INTO company (id,name,industry,founder_gender) VALUES (2,'TechBoost','Technology','Male'); CREATE TABLE funding_round (company_id INT,round_size INT); INSERT INTO funding_round (company_id,round_size) VALUES (1,5000000); INSERT INTO funding_round (company_id,round_size) VALUES (2,7000000);
SELECT AVG(funding_round.round_size) FROM company INNER JOIN funding_round ON company.id = funding_round.company_id WHERE company.founder_gender = 'Female' AND company.industry = 'Healthcare';
What is the average temperature and precipitation in April for farms located in urban areas?
CREATE TABLE farms (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO farms (id,name,location,type) VALUES (1,'Smith Farm','Rio de Janeiro','Urban'); INSERT INTO farms (id,name,location,type) VALUES (2,'Jones Farm','Toronto','Urban'); CREATE TABLE weather (id INT,farm_id INT,month INT,temperature INT,precipitation INT); INSERT INTO weather (id,farm_id,month,temperature,precipitation) VALUES (1,1,4,22,50); INSERT INTO weather (id,farm_id,month,temperature,precipitation) VALUES (2,2,4,15,75);
SELECT AVG(w.temperature), AVG(w.precipitation) FROM weather w JOIN farms f ON w.farm_id = f.id WHERE w.month = 4 AND f.type = 'Urban';
How many marine species in the Indian Ocean are not threatened by climate change?
CREATE TABLE marine_species (name VARCHAR(255),region VARCHAR(255),threatened_by_climate_change BOOLEAN); INSERT INTO marine_species (name,region,threatened_by_climate_change) VALUES ('Species 1','Indian Ocean',TRUE); INSERT INTO marine_species (name,region,threatened_by_climate_change) VALUES ('Species 2','Atlantic',FALSE);
SELECT COUNT(*) FROM marine_species WHERE region = 'Indian Ocean' AND threatened_by_climate_change = FALSE;
Update the marine_species table to reflect an increase in population by 10% for species with id 1, 4, and 6
CREATE TABLE marine_species (id INT,name VARCHAR(50),population INT);
UPDATE marine_species SET population = population * 1.1 WHERE id IN (1, 4, 6);
What are the top 3 cruelty-free certified cosmetic products by sales in Canada?
CREATE TABLE products (product_id INT,product_name VARCHAR(100),sales INT,certification VARCHAR(20)); INSERT INTO products VALUES (1,'Mascara',5000,'cruelty-free'),(2,'Lipstick',7000,'not_certified'),(3,'Foundation',6000,'cruelty-free'); CREATE TABLE regions (region_id INT,region_name VARCHAR(50)); INSERT INTO regions VALUES (1,'Canada'),(2,'USA');
SELECT product_name, sales FROM products WHERE certification = 'cruelty-free' ORDER BY sales DESC LIMIT 3;
What are the top 5 cruelty-free certified cosmetic products by consumer preference score, ordered from highest to lowest?
CREATE TABLE cosmetics (product_name TEXT,cruelty_free BOOLEAN,consumer_preference_score INTEGER); INSERT INTO cosmetics (product_name,cruelty_free,consumer_preference_score) VALUES ('ProductA',true,85),('ProductB',false,90),('ProductC',true,70),('ProductD',true,95),('ProductE',false,80),('ProductF',true,75);
SELECT product_name, consumer_preference_score FROM cosmetics WHERE cruelty_free = true ORDER BY consumer_preference_score DESC LIMIT 5;
How many artworks were sold by each gallery in the last year?
CREATE TABLE Galleries (GalleryID INT,GalleryName VARCHAR(50),City VARCHAR(50)); CREATE TABLE Sales (SaleID INT,GalleryID INT,ArtworkID INT,Year INT); INSERT INTO Galleries VALUES (1,'Gallery 1','New York'),(2,'Gallery 2','Los Angeles'),(3,'Gallery 3','London'); INSERT INTO Sales VALUES (1,1,1,2021),(2,1,2,2021),(3,2,3,2021),(4,2,4,2021),(5,3,5,2021),(6,3,6,2021);
SELECT G.GalleryName, COUNT(S.ArtworkID) AS ArtworksSold FROM Galleries G INNER JOIN Sales S ON G.GalleryID = S.GalleryID WHERE S.Year = 2021 GROUP BY G.GalleryName;
List all countries and their corresponding peacekeeping operation budgets from the 'Budget' and 'Countries' tables
CREATE TABLE Budget (country TEXT,budget INT); CREATE TABLE Countries (country TEXT,peacekeeping_operation TEXT); INSERT INTO Budget (country,budget) VALUES ('United States',2000000),('China',1500000),('Russia',1000000); INSERT INTO Countries (country,peacekeeping_operation) VALUES ('United States','MINUSMA'),('China','MONUSCO'),('Russia','UNMISS');
SELECT Countries.country, Budget.budget FROM Countries INNER JOIN Budget ON Countries.country = Budget.country;
Get average returns of stocks with market cap > $10B in the past year
CREATE TABLE stocks (stock_id INT PRIMARY KEY,symbol VARCHAR(10),market_cap DECIMAL(15,2)); CREATE TABLE returns (return_id INT PRIMARY KEY,stock_id INT,year INT,avg_return DECIMAL(5,2));
SELECT s.symbol, AVG(r.avg_return) FROM stocks s JOIN returns r ON s.stock_id = r.stock_id WHERE s.market_cap > 10000000000 GROUP BY s.symbol;
Show the total assets under management (AUM) for each risk category.
CREATE TABLE risk_categories (risk_category VARCHAR(20)); INSERT INTO risk_categories (risk_category) VALUES ('Low'),('Medium'),('High'); CREATE TABLE client_risk (client_id INT,risk_category VARCHAR(20)); INSERT INTO client_risk (client_id,risk_category) VALUES (1,'Medium'),(2,'High'),(3,'Low');
SELECT cr.risk_category, SUM(value) AS total_aum FROM client_risk cr JOIN clients c ON cr.client_id = c.client_id JOIN assets a ON c.client_id = a.client_id GROUP BY cr.risk_category;
What is the maximum balance for high-risk accounts in the Africa region?
CREATE TABLE balances (id INT,risk_level VARCHAR(10),region VARCHAR(20),balance DECIMAL(15,2)); INSERT INTO balances (id,risk_level,region,balance) VALUES (1,'high','Africa',200000.00),(2,'medium','Europe',150000.00),(3,'low','North America',100000.00),(4,'high','Asia-Pacific',300000.00);
SELECT MAX(balance) FROM balances WHERE risk_level = 'high' AND region = 'Africa';
Find the names of healthcare professionals who work in rural areas of Australia and New Zealand, and the facilities they work for.
CREATE TABLE professionals (name TEXT,title TEXT,location TEXT); INSERT INTO professionals (name,title,location) VALUES ('Dr. Smith','Doctor','Rural Australia'),('Nurse Johnson','Nurse','Rural New Zealand'),('Dr. Brown','Doctor','Rural New Zealand'); CREATE TABLE facilities (name TEXT,location TEXT,type TEXT); INSERT INTO facilities (name,location,type) VALUES ('Facility X','Rural Australia','Hospital'),('Facility Y','Rural New Zealand','Clinic');
SELECT professionals.name, facilities.name FROM professionals INNER JOIN facilities ON professionals.location = facilities.location;
Find the total number of healthcare professionals in 'rural_healthcare' schema?
CREATE SCHEMA if not exists rural_healthcare; use rural_healthcare; CREATE TABLE hospitals (id int,name varchar(255),num_doctors int); CREATE TABLE clinics (id int,name varchar(255),num_nurses int);
SELECT COALESCE(SUM(h.num_doctors), 0) + COALESCE(SUM(c.num_nurses), 0) FROM hospitals h RIGHT JOIN clinics c ON 1=1;
How many female doctors are in 'healthcare_staff' table?
CREATE TABLE healthcare_staff (name VARCHAR(255),gender VARCHAR(255),position VARCHAR(255),hospital_id INT); INSERT INTO healthcare_staff (name,gender,position,hospital_id) VALUES ('Dr. Jane Smith','Female','Doctor',1),('Dr. Maria Garcia','Female','Doctor',2);
SELECT COUNT(*) FROM healthcare_staff WHERE gender = 'Female' AND position = 'Doctor';
What is the total number of medical professionals working in rural areas of California?
CREATE TABLE professional (professional_id INT,name VARCHAR(50),specialty VARCHAR(50),location VARCHAR(20)); INSERT INTO professional (professional_id,name,specialty,location) VALUES (1,'Dr. Smith','Cardiologist','Rural California'); INSERT INTO professional (professional_id,name,specialty,location) VALUES (2,'Dr. Johnson','Pediatrician','Urban California');
SELECT COUNT(*) FROM professional WHERE location = 'Rural California';
What is the total budget and the number of programs in each department for the next fiscal year?
CREATE TABLE department_budget (id INT,department VARCHAR(255),fiscal_year VARCHAR(255),program_budget DECIMAL(10,2)); INSERT INTO department_budget (id,department,fiscal_year,program_budget) VALUES (1,'Education','2023',5000),(2,'Health','2023',7000),(3,'Education','2023',3000),(4,'Environment','2023',8000),(5,'Health','2023',9000),(6,'Education','2023',4000);
SELECT department, SUM(program_budget) AS total_budget, COUNT(*) AS num_programs FROM department_budget WHERE fiscal_year = '2024' GROUP BY department;
What is the total number of donations and the total donation amount for donations made in the month of June?
CREATE TABLE Donations (id INT,donor_name TEXT,donation_amount FLOAT,donation_date DATE,state TEXT); INSERT INTO Donations (id,donor_name,donation_amount,donation_date,state) VALUES (1,'John Doe',250,'2022-06-01','NY'),(2,'Jane Smith',125,'2022-07-02','CA');
SELECT COUNT(*), SUM(donation_amount) FROM Donations WHERE EXTRACT(MONTH FROM donation_date) = 6;
How many employees from each country have completed the 'SQL' course in the 'training' table?
CREATE TABLE employees (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE training (id INT,employee_id INT,course VARCHAR(255)); INSERT INTO employees (id,name,country) VALUES (1,'John Doe','USA'); INSERT INTO employees (id,name,country) VALUES (2,'Jane Smith','Canada'); INSERT INTO employees (id,name,country) VALUES (3,'Alice Johnson','USA'); INSERT INTO training (id,employee_id,course) VALUES (1,1,'SQL'); INSERT INTO training (id,employee_id,course) VALUES (2,1,'Python'); INSERT INTO training (id,employee_id,course) VALUES (3,3,'SQL'); INSERT INTO training (id,employee_id,course) VALUES (4,4,'SQL');
SELECT e.country, COUNT(t.id) FROM employees e JOIN training t ON e.id = t.employee_id WHERE t.course = 'SQL' GROUP BY e.country;
What is the distribution of renewable energy subsidies by technology in the US?
CREATE TABLE renewable_energy_subsidies (id INT,technology VARCHAR(255),year INT,amount INT);
SELECT technology, AVG(amount) as avg_subsidy, COUNT(*) as num_subsidies FROM renewable_energy_subsidies s JOIN energy_storage e ON s.technology = e.technology WHERE e.country = 'United States' GROUP BY technology;
How many offshore platforms have been decommissioned since 2016?
CREATE TABLE Platforms (PlatformName TEXT,DecommissionDate DATE); INSERT INTO Platforms (PlatformName,DecommissionDate) VALUES ('Platform1','2016-12-31'),('Platform2','2017-08-15'),('Platform3','2018-02-28');
SELECT COUNT(*) AS DecommissionedPlatforms FROM Platforms WHERE DecommissionDate BETWEEN '2016-01-01' AND '2022-12-31';
Which operators have the highest average production quantity per well?
CREATE TABLE wells (well_id INT,well_name TEXT,production_qty FLOAT,operator_id INT); INSERT INTO wells (well_id,well_name,production_qty,operator_id) VALUES (1,'Well A',1000,1),(2,'Well B',1500,1),(3,'Well C',800,2); CREATE TABLE operators (operator_id INT,operator_name TEXT); INSERT INTO operators (operator_id,operator_name) VALUES (1,'ABC Inc.'),(2,'DEF'),(3,'GHI Inc.');
SELECT o.operator_name, AVG(w.production_qty) as avg_production FROM wells w JOIN operators o ON w.operator_id = o.operator_id GROUP BY o.operator_name ORDER BY avg_production DESC;
Get the total number of points scored by each team in the 2021 NBA season
CREATE TABLE teams (team_id INT,team_name VARCHAR(255)); INSERT INTO teams VALUES (1,'Brooklyn Nets'); INSERT INTO teams VALUES (2,'Los Angeles Lakers'); CREATE TABLE points (team_id INT,points INT,season VARCHAR(10)); INSERT INTO points VALUES (1,120,'2021'); INSERT INTO points VALUES (2,110,'2021');
SELECT a.team_name, SUM(b.points) as total_points FROM teams a JOIN points b ON a.team_id = b.team_id WHERE b.season = '2021' GROUP BY a.team_name;
Calculate the sum of all donations made on or after January 1, 2021 in the 'refugee_support' schema.
CREATE TABLE refugee_support.donations_2021 (donation_id INT,donor_id INT,donation_amount DECIMAL,donation_date DATE); INSERT INTO refugee_support.donations_2021 (donation_id,donor_id,donation_amount,donation_date) VALUES (1,1,50.00,'2021-01-02'),(2,2,100.00,'2021-03-15'),(3,3,25.00,'2021-06-20');
SELECT SUM(donation_amount) FROM refugee_support.donations_2021 WHERE donation_date >= '2021-01-01';
Update the status of incomplete projects from 2018 to 'In Progress'
CREATE TABLE Projects (ProjectID int,Status varchar(50),Year int); INSERT INTO Projects (ProjectID,Status,Year) VALUES (1,'Completed',2018),(2,'In Progress',2019),(3,'Completed',2017),(4,'Not Started',2018);
UPDATE Projects SET Status = 'In Progress' WHERE Year = 2018 AND Status = 'Not Started';
What is the total number of schools and hospitals in 'relief_operations' table?
CREATE TABLE relief_operations (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO relief_operations (id,name,type,location) VALUES (1,'School A','school','Country1'),(2,'Hospital B','hospital','Country2');
SELECT SUM(CASE WHEN type = 'school' THEN 1 ELSE 0 END) as total_schools, SUM(CASE WHEN type = 'hospital' THEN 1 ELSE 0 END) as total_hospitals FROM relief_operations;
Who are the top three contributors to accessible technology initiatives in India?
CREATE TABLE accessibility_contributors (contributor VARCHAR(50),contributions INT); INSERT INTO accessibility_contributors (contributor,contributions) VALUES ('ABC Corp',35000),('XYZ Foundation',40000),('TechAid India',30000),('Lara Solutions',25000);
SELECT contributor FROM accessibility_contributors ORDER BY contributions DESC LIMIT 3;
What is the total number of trips taken on accessible vehicles in the 'East' region for the current year?
CREATE TABLE Vehicles (VehicleID int,VehicleType varchar(255),Region varchar(255)); INSERT INTO Vehicles (VehicleID,VehicleType,Region) VALUES (1,'Bus','East'),(2,'Tram','West'),(3,'Wheelchair Bus','South'),(4,'Accessible Tram','East'); CREATE TABLE Trips (TripID int,VehicleID int,TripDateTime datetime);
SELECT COUNT(*) FROM Vehicles JOIN Trips ON Vehicles.VehicleID = Trips.VehicleID WHERE Vehicles.Region = 'East' AND Vehicles.VehicleType IN ('Wheelchair Bus', 'Accessible Tram') AND YEAR(Trips.TripDateTime) = YEAR(GETDATE());
What is the distribution of clothing sizes sold to customers in France?
CREATE TABLE sizes (country VARCHAR(10),product VARCHAR(20),size DECIMAL(3,2)); INSERT INTO sizes (country,product,size) VALUES ('France','shirt',40.0),('France','shirt',42.0),('France','shirt',44.0),('France','pants',32.0),('France','pants',34.0),('France','pants',36.0);
SELECT size, COUNT(*) FROM sizes WHERE country = 'France' GROUP BY size;
Which countries source the most of each sustainable fabric type?
CREATE TABLE sourcing (id INT,country TEXT,fabric TEXT,quantity INT); INSERT INTO sourcing (id,country,fabric,quantity) VALUES (1,'Italy','Organic Cotton',400),(2,'France','Organic Cotton',300),(3,'Germany','Recycled Polyester',500),(4,'Spain','Recycled Polyester',400),(5,'Italy','Hemp',600),(6,'France','Hemp',200);
SELECT country, fabric, SUM(quantity) as total_quantity FROM sourcing GROUP BY country, fabric ORDER BY total_quantity DESC;
How many packages arrived in Texas from China since 2021-01-01?
CREATE TABLE Packages (id INT,arrived DATE,destination VARCHAR(20)); INSERT INTO Packages (id,arrived,destination) VALUES (1,'2021-01-05','Texas'),(2,'2021-02-10','Texas'),(3,'2021-03-20','China');
SELECT COUNT(*) FROM Packages WHERE destination = 'Texas' AND arrived >= '2021-01-01' AND arrived < '2022-01-01' AND destination = 'China'
Identify the freight forwarders and their respective total shipment weight for the region 'Asia' in the month of July 2021.
CREATE TABLE FreightForwarders (FFID INT,FFName VARCHAR(100),Region VARCHAR(50));CREATE TABLE ShipmentDetails (ShipmentID INT,FFID INT,ShipmentWeight DECIMAL(10,2),ShipmentDate DATE); INSERT INTO FreightForwarders VALUES (1,'ABC Logistics','Asia'); INSERT INTO ShipmentDetails VALUES (1,1,500,'2021-07-01');
SELECT FreightForwarders.FFName, SUM(ShipmentDetails.ShipmentWeight) as TotalShipmentWeight FROM FreightForwarders INNER JOIN ShipmentDetails ON FreightForwarders.FFID = ShipmentDetails.FFID WHERE FreightForwarders.Region = 'Asia' AND MONTH(ShipmentDate) = 7 AND YEAR(ShipmentDate) = 2021 GROUP BY FreightForwarders.FFName;
What is the average quantity of inventory in country 'France'?
CREATE TABLE warehouses (id VARCHAR(10),name VARCHAR(20),city VARCHAR(10),country VARCHAR(10)); CREATE TABLE inventory (item VARCHAR(10),warehouse_id VARCHAR(10),quantity INT); INSERT INTO warehouses (id,name,city,country) VALUES ('EWR-WH-01','Newark Warehouse','Newark','USA'),('CDG-WH-01','Paris Warehouse','Paris','France'),('DXB-WH-01','Dubai Warehouse','Dubai','UAE'); INSERT INTO inventory (item,warehouse_id,quantity) VALUES ('Laptop','EWR-WH-01',500),('Monitor','EWR-WH-01',300),('Keyboard','EWR-WH-01',250),('Laptop','CDG-WH-01',600),('Monitor','CDG-WH-01',400),('Keyboard','CDG-WH-01',350),('Laptop','DXB-WH-01',700),('Monitor','DXB-WH-01',500),('Keyboard','DXB-WH-01',450);
SELECT AVG(quantity) as avg_quantity FROM inventory i JOIN warehouses w ON i.warehouse_id = w.id WHERE w.country = 'France';
How many genetic research projects in Japan use CRISPR technology?
CREATE TABLE projects (id INT,name VARCHAR(50),country VARCHAR(50),techniques VARCHAR(50)); INSERT INTO projects (id,name,country,techniques) VALUES (1,'ProjectA','Japan','CRISPR,PCR'); INSERT INTO projects (id,name,country,techniques) VALUES (2,'ProjectB','Japan','PCR,bioinformatics'); INSERT INTO projects (id,name,country,techniques) VALUES (3,'ProjectC','Japan','CRISPR,bioinformatics');
SELECT COUNT(*) FROM projects WHERE country = 'Japan' AND techniques LIKE '%CRISPR%';
What is the total investment in biosensor technology development in Germany and France?
CREATE SCHEMA if not exists biosensors; CREATE TABLE if not exists biosensors.investments (id INT,country VARCHAR(50),investment_type VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO biosensors.investments (id,country,investment_type,amount) VALUES (1,'Germany','Equity',2000000.00),(2,'France','Grants',1500000.00),(3,'Germany','Grants',1000000.00),(4,'France','Equity',2500000.00);
SELECT SUM(amount) FROM biosensors.investments WHERE country IN ('Germany', 'France') AND investment_type IN ('Equity', 'Grants');