instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Update the names of players who use PlayStation VR to 'PSVR Users'.
CREATE TABLE Players (PlayerID INT,Name VARCHAR(20),VRPlatform VARCHAR(10)); INSERT INTO Players (PlayerID,Name,VRPlatform) VALUES (1,'John','PlayStation VR');
UPDATE Players SET Name = 'PSVR Users' WHERE VRPlatform = 'PlayStation VR';
What's the gender ratio of players who play esports games in Canada?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Location VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (1,25,'Male','Canada'); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (2,30,'Female','Canada'); CREATE TABLE Games (GameID INT,GameName VARCHAR(20),Esports BOOLEAN); INSERT INTO Games (GameID,GameName,Esports) VALUES (1,'Starship Battle',true);
SELECT (COUNT(CASE WHEN Gender = 'Male' THEN 1 END) * 1.0 / COUNT(*)) AS Male_ratio, (COUNT(CASE WHEN Gender = 'Female' THEN 1 END) * 1.0 / COUNT(*)) AS Female_ratio FROM Players INNER JOIN Games ON Players.Location = Games.GameName WHERE Games.Esports = true AND Players.Location = 'Canada';
Update the temperature data for field ID 11111 where the temperature is over 30 degrees.
CREATE TABLE field_temperature (field_id INT,date DATE,temperature DECIMAL(5,2)); INSERT INTO field_temperature (field_id,date,temperature) VALUES (11111,'2022-03-01',32.0),(11111,'2022-03-02',29.0),(11111,'2022-03-03',35.0);
UPDATE field_temperature SET temperature = 30.0 WHERE field_id = 11111 AND temperature > 30.0;
How many citizen feedback records were created by each citizen in 2023?
CREATE TABLE feedback (id INT,citizen_id INT,created_at DATETIME); INSERT INTO feedback (id,citizen_id,created_at) VALUES (1,1,'2023-01-01 12:34:56'),(2,1,'2023-01-15 10:20:34'),(3,2,'2023-02-20 16:45:01');
SELECT citizen_id, COUNT(*) as num_records FROM feedback WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY citizen_id;
What is the average response time for citizen feedback in rural areas?
CREATE TABLE Feedback (Location VARCHAR(255),ResponseTime INT); INSERT INTO Feedback (Location,ResponseTime) VALUES ('Rural',120),('Rural',150),('Urban',90),('Urban',80),('Rural',130),('Rural',140);
SELECT AVG(ResponseTime) FROM Feedback WHERE Location = 'Rural';
What is the total quantity of Europium produced in Oceania?
CREATE TABLE europium_production (year INT,region VARCHAR(20),quantity INT); INSERT INTO europium_production (year,region,quantity) VALUES (2015,'Australia',1000),(2016,'Australia',1200),(2015,'New Zealand',800),(2016,'New Zealand',900);
SELECT SUM(quantity) FROM europium_production WHERE region IN ('Australia', 'New Zealand');
Update the description of a sustainable urbanism initiative in the sustainable_urbanism_initiatives table
CREATE TABLE public.sustainable_urbanism_initiatives (id SERIAL PRIMARY KEY,initiative_name VARCHAR(255),initiative_description TEXT,city_name VARCHAR(255),state_name VARCHAR(255)); INSERT INTO public.sustainable_urbanism_initiatives (initiative_name,initiative_description,city_name,state_name) VALUES ('Green City Program','Promotes green spaces and sustainable transportation options in urban areas','Portland','Oregon'),('EcoDistricts Initiative','Encourages sustainable community development in city neighborhoods','Vancouver','British Columbia');
WITH updated_initiative AS (UPDATE public.sustainable_urbanism_initiatives SET initiative_description = 'Promotes green spaces, sustainable transportation, and energy-efficient buildings in urban areas' WHERE initiative_name = 'Green City Program' RETURNING *) INSERT INTO public.sustainable_urbanism_initiatives (initiative_name, initiative_description, city_name, state_name) SELECT initiative_name, initiative_description, city_name, state_name FROM updated_initiative;
What is the minimum installed capacity (MW) of renewable energy projects?
CREATE TABLE renewable_projects_4 (id INT,name VARCHAR(255),location VARCHAR(255),capacity FLOAT,technology VARCHAR(255));
SELECT MIN(capacity) FROM renewable_projects_4 WHERE technology IN ('Solar', 'Wind', 'Hydro', 'Geothermal', 'Biomass');
How many satellites were launched by each country in 2019?
CREATE TABLE satellites (satellite_id INT,satellite_name VARCHAR(100),country VARCHAR(50),launch_date DATE); INSERT INTO satellites (satellite_id,satellite_name,country,launch_date) VALUES (1,'Sentinel-1A','France','2012-04-03'); INSERT INTO satellites (satellite_id,satellite_name,country,launch_date) VALUES (2,'Chandrayaan-1','India','2008-10-22');
SELECT country, COUNT(*) as total_launched FROM satellites WHERE YEAR(launch_date) = 2019 GROUP BY country;
What is the source distribution of space debris in orbit and how long has it been there on average?
CREATE TABLE space_debris (id INT,name VARCHAR(255),type VARCHAR(255),source VARCHAR(255),launch_date DATE); INSERT INTO space_debris VALUES (3,'Defunct Probe','Probe','ESA','2000-07-02');
SELECT source, COUNT(id) as count, AVG(DATEDIFF(CURDATE(), launch_date)) as avg_years_in_orbit FROM space_debris GROUP BY source;
What is the total cost of space missions led by each country?
CREATE TABLE missions (mission_name VARCHAR(50),country VARCHAR(50),cost INT); INSERT INTO missions (mission_name,country,cost) VALUES ('Apollo','USA',25000000000),('Artemis','USA',30000000000),('Luna','Russia',5000000000);
SELECT country, SUM(cost) as total_cost FROM missions GROUP BY country ORDER BY total_cost DESC;
What is the average manufacturing cost of spacecrafts for each country?
CREATE TABLE SpacecraftManufacturing (id INT,country VARCHAR,cost FLOAT);
SELECT country, AVG(cost) AS avg_cost FROM SpacecraftManufacturing GROUP BY country;
How many security incidents have been reported in each region per month?
CREATE TABLE security_incidents (id INT,timestamp TIMESTAMP,region VARCHAR(255),incident_type VARCHAR(255)); INSERT INTO security_incidents (id,timestamp,region,incident_type) VALUES (1,'2020-01-01 12:00:00','North America','Phishing'),(2,'2020-02-05 10:30:00','Europe','Malware');
SELECT region, DATE_FORMAT(timestamp, '%Y-%m') as month, COUNT(*) as num_incidents FROM security_incidents GROUP BY region, month;
Update user information with the following details: [(1, '[email protected]', 'Jane Doe', '2022-01-01 10:30:00'), (2, '[email protected]', 'John Doe', '2022-02-12 15:45:00')] in the "users" table
CREATE TABLE users (id INT PRIMARY KEY,email VARCHAR(50),name VARCHAR(50),last_login DATETIME);
UPDATE users SET email = CASE id WHEN 1 THEN '[email protected]' WHEN 2 THEN '[email protected]' END, name = CASE id WHEN 1 THEN 'Jane Doe' WHEN 2 THEN 'John Doe' END, last_login = CASE id WHEN 1 THEN '2022-01-01 10:30:00' WHEN 2 THEN '2022-02-12 15:45:00' END WHERE id IN (1, 2);
What are the most common types of policy violations in the last year, and how many incidents of each type occurred?
CREATE TABLE policy_violations (id INT,violation_type VARCHAR(20),timestamp TIMESTAMP);
SELECT violation_type, COUNT(*) FROM policy_violations WHERE timestamp >= NOW() - INTERVAL 1 YEAR GROUP BY violation_type ORDER BY COUNT(*) DESC;
Update the sustainability_metrics table to reflect the correct CO2 emissions for garment production in the South American region.
CREATE TABLE sustainability_metrics (id INT,region VARCHAR(255),co2_emissions INT); INSERT INTO sustainability_metrics (id,region,co2_emissions) VALUES (1,'South America',120),(2,'South America',150),(3,'South America',180);
UPDATE sustainability_metrics SET co2_emissions = 130 WHERE region = 'South America';
Show the total tonnage of each cargo type in the inventory
CREATE TABLE Cargo (CargoID INT,CargoType VARCHAR(50),Tonnage INT); INSERT INTO Cargo (CargoID,CargoType,Tonnage) VALUES (1,'Coal',1000),(2,'IronOre',2000),(3,'Grain',1500),(4,'Coal',500);
SELECT CargoType, SUM(Tonnage) FROM Cargo GROUP BY CargoType;
What is the maximum daily water usage in the Tokyo region in the past year?
CREATE TABLE daily_usage (region VARCHAR(20),daily_usage FLOAT,timestamp TIMESTAMP); INSERT INTO daily_usage (region,daily_usage,timestamp) VALUES ('Tokyo',1200000,'2022-01-01 10:00:00'),('Tokyo',1300000,'2022-02-01 10:00:00');
SELECT MAX(daily_usage) FROM daily_usage WHERE region = 'Tokyo' AND timestamp BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) AND CURRENT_TIMESTAMP;
What is the average safety score for each creative AI application, grouped by region?
CREATE TABLE CreativeAIs (id INT,name VARCHAR(50),safety_score INT,region VARCHAR(50)); INSERT INTO CreativeAIs (id,name,safety_score,region) VALUES (1,'AI Painter',85,'North America'); INSERT INTO CreativeAIs (id,name,safety_score,region) VALUES (2,'AI Music Composer',90,'Europe'); INSERT INTO CreativeAIs (id,name,safety_score,region) VALUES (3,'AI Poet',80,'Asia');
SELECT region, AVG(safety_score) as avg_safety_score FROM CreativeAIs GROUP BY region;
What is the average budget for agricultural innovation projects in the 'rural_development' database, grouped by project type?
CREATE TABLE agri_innovation_project (project_id INT,project_name VARCHAR(50),project_type VARCHAR(50),budget INT); INSERT INTO agri_innovation_project (project_id,project_name,project_type,budget) VALUES (1,'Precision Agriculture','Technology',500000);
SELECT project_type, AVG(budget) FROM agri_innovation_project GROUP BY project_type;
Insert a new aircraft model 'B747-8' into the 'aircraft_models' table with corresponding details.
CREATE TABLE aircraft_models (model VARCHAR(50),manufacturer VARCHAR(50),first_flight YEAR,production_status VARCHAR(50));
INSERT INTO aircraft_models (model, manufacturer, first_flight, production_status) VALUES ('B747-8', 'Boeing', 2010, 'In Production');
What was the total cost of aircraft manufactured by Boeing in 2020?
CREATE TABLE Aircraft (aircraft_id INT,manufacturer VARCHAR(50),model VARCHAR(50),year INT,cost FLOAT); INSERT INTO Aircraft (aircraft_id,manufacturer,model,year,cost) VALUES (1,'Boeing','B737',2020,100000000.0),(2,'Airbus','A320',2019,85000000.0),(3,'Boeing','B787',2021,250000000.0);
SELECT SUM(cost) FROM Aircraft WHERE manufacturer = 'Boeing' AND year = 2020;
Find the total number of attendees at events in Paris and Rome from 2018 to 2020, excluding repeating attendees.
CREATE TABLE EventAttendance (attendee_id INT,event_city VARCHAR(50),event_year INT,attended INT); INSERT INTO EventAttendance (attendee_id,event_city,event_year,attended) VALUES (1,'Paris',2018,1),(2,'Rome',2019,1),(3,'Paris',2018,1),(4,'Rome',2020,1),(5,'Paris',2019,1),(6,'Rome',2018,1),(7,'Paris',2020,1);
SELECT event_city, COUNT(DISTINCT attendee_id) FROM EventAttendance WHERE event_city IN ('Paris', 'Rome') AND event_year BETWEEN 2018 AND 2020 GROUP BY event_city;
What is the total funding received by performing arts events from government sources in the last 5 years?
CREATE TABLE funding_table (id INT,event_name TEXT,funding_source TEXT,amount_funded INT,event_date DATE); INSERT INTO funding_table (id,event_name,funding_source,amount_funded,event_date) VALUES (1,'Theatre Performance','Government',8000,'2018-01-01'),(2,'Dance Recital','Government',9000,'2017-01-01');
SELECT SUM(amount_funded) FROM funding_table WHERE funding_source = 'Government' AND event_date BETWEEN DATEADD(year, -5, GETDATE()) AND GETDATE() AND event_type = 'Performing Arts';
Which 'Literary Arts' events in Boston had more than 50 attendees?
CREATE TABLE event_attendance (event_name VARCHAR(50),city VARCHAR(50),attendees INT); INSERT INTO event_attendance (event_name,city,attendees) VALUES ('Literary Arts','Boston',60);
SELECT event_name, city FROM event_attendance WHERE event_name = 'Literary Arts' AND city = 'Boston' AND attendees > 50;
How many TV shows were produced by each studio in 2021?
CREATE TABLE Studios (studio_id INT,studio_name VARCHAR(255),country VARCHAR(255)); INSERT INTO Studios (studio_id,studio_name,country) VALUES (1,'Studio A','USA'),(2,'Studio B','USA'),(3,'Studio C','Canada'); CREATE TABLE TV_Shows (show_id INT,show_name VARCHAR(255),studio_id INT,year INT); INSERT INTO TV_Shows (show_id,show_name,studio_id,year) VALUES (1,'Show X',1,2021),(2,'Show Y',1,2022),(3,'Show Z',2,2021),(4,'Show W',3,2020);
SELECT s.studio_name, COUNT(*) as shows_in_2021 FROM Studios s JOIN TV_Shows t ON s.studio_id = t.studio_id WHERE t.year = 2021 GROUP BY s.studio_id, s.studio_name;
Get the number of construction labor hours worked in the month of January 2022
CREATE TABLE construction_labor (worker_id INT,hours_worked INT,work_date DATE);
SELECT SUM(hours_worked) FROM construction_labor WHERE EXTRACT(MONTH FROM work_date) = 1 AND EXTRACT(YEAR FROM work_date) = 2022;
List the number of unique strains available in each dispensary in Washington in Q3 of 2022.
CREATE TABLE available_strains (id INT,strain_name VARCHAR(255),dispensary_name VARCHAR(255),state VARCHAR(255),availability_date DATE);
SELECT dispensary_name, COUNT(DISTINCT strain_name) FROM available_strains WHERE state = 'Washington' AND availability_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY dispensary_name;
What is the minimum billing amount for cases in the region 'South'?
CREATE TABLE cases (case_id INT,region TEXT,billing_amount INT);
SELECT MIN(billing_amount) FROM cases WHERE region = 'South';
List the total waste generated per month by chemical manufacturers in Brazil for the past 12 months.
CREATE TABLE waste (id INT,manufacturer_country VARCHAR(255),amount FLOAT,waste_type VARCHAR(255),date DATE);
SELECT manufacturer_country, DATE_FORMAT(date, '%Y-%m') as month, SUM(amount) as total_waste FROM waste WHERE manufacturer_country = 'Brazil' AND date > DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY manufacturer_country, month;
Update a record with infectious disease tracking data
CREATE TABLE infectious_disease_tracking_v2 (id INT,location VARCHAR(20),infection_rate INT);
UPDATE infectious_disease_tracking_v2 SET infection_rate = 14 WHERE id = 1;
What is the maximum amount of funding received by a social enterprise founded by a person from the LGBTQ+ community?
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,founders TEXT,funding FLOAT,lgbtq_founder BOOLEAN); INSERT INTO Companies (id,name,industry,founders,funding,lgbtq_founder) VALUES (1,'CompassionateCare','Social Enterprise','LGBTQ+ Founder',8000000.00,TRUE); INSERT INTO Companies (id,name,industry,founders,funding,lgbtq_founder) VALUES (2,'NeighborhoodAid','Social Enterprise','Straight Founder',12000000.00,FALSE);
SELECT MAX(funding) FROM Companies WHERE industry = 'Social Enterprise' AND lgbtq_founder = TRUE;
List all startups that have not had an investment round yet and were founded after 2015?
CREATE TABLE company (id INT,name TEXT,founding_date DATE); CREATE TABLE investment_rounds (id INT,company_id INT,funding_amount INT); INSERT INTO company (id,name,founding_date) VALUES (1,'Acme Inc','2016-01-01'); INSERT INTO investment_rounds (id,company_id,funding_amount) VALUES (1,1,500000);
SELECT company.name FROM company LEFT JOIN investment_rounds ON company.id = investment_rounds.company_id WHERE investment_rounds.id IS NULL AND founding_date > '2015-12-31';
What was the maximum number of training hours for farmers in each country in 2020?
CREATE TABLE training (id INT,country_id INT,farmer_id INT,hours INT,date DATE);
SELECT country_id, MAX(hours) FROM training WHERE YEAR(date) = 2020 GROUP BY country_id;
What is the minimum number of disability accommodations provided in a month for 'Mental Health Support'?
CREATE TABLE Accommodations (ID INT,Category TEXT,Month INT,NumberProvided INT); INSERT INTO Accommodations (ID,Category,Month,NumberProvided) VALUES (1,'Mental Health Support',1,5),(2,'Mental Health Support',2,7),(3,'Physical Assistance',1,20);
SELECT MIN(NumberProvided) FROM Accommodations WHERE Category = 'Mental Health Support';
How many shark species are found in the Indian Ocean?
CREATE TABLE shark_species (name VARCHAR(255),ocean VARCHAR(255)); INSERT INTO shark_species (name,ocean) VALUES ('Whale Shark','Indian Ocean'),('Tiger Shark','Atlantic Ocean');
SELECT COUNT(*) FROM shark_species WHERE ocean = 'Indian Ocean';
How many smart contracts have been deployed by developer 'Hayden Adams'?
CREATE TABLE smart_contract_deployments (deployment_id INT PRIMARY KEY,developer_name TEXT,contract_name TEXT,deployment_date DATE); INSERT INTO smart_contract_deployments (deployment_id,developer_name,contract_name,deployment_date) VALUES (1,'Hayden Adams','Uniswap','2021-01-01');
SELECT COUNT(*) FROM smart_contract_deployments WHERE developer_name = 'Hayden Adams';
What is the maximum height of a tree species in the boreal region?
CREATE TABLE tree_species (id INT,species TEXT,avg_height FLOAT,region TEXT);
SELECT MAX(avg_height) FROM tree_species WHERE region = 'boreal';
What are the top 3 preferred cosmetic products by consumers from the USA?
CREATE TABLE cosmetics (id INT,product_name TEXT,consumer_preference FLOAT,country TEXT); INSERT INTO cosmetics (id,product_name,consumer_preference,country) VALUES (1,'Lipstick',4.2,'USA'),(2,'Foundation',4.5,'Canada'),(3,'Mascara',4.7,'USA');
SELECT product_name, consumer_preference FROM cosmetics WHERE country = 'USA' ORDER BY consumer_preference DESC LIMIT 3;
Which region sources the most natural ingredients for cosmetic products?
CREATE TABLE Ingredient_Sourcing (SupplierID INT,ProductID INT,Natural BOOLEAN,Region VARCHAR(50)); INSERT INTO Ingredient_Sourcing (SupplierID,ProductID,Natural,Region) VALUES (2001,101,TRUE,'Asia'),(2002,102,FALSE,'Asia'),(2003,101,TRUE,'Europe'),(2004,103,FALSE,'Europe'),(2005,102,TRUE,'Africa');
SELECT Region, SUM(Natural) as TotalNatural FROM Ingredient_Sourcing GROUP BY Region ORDER BY TotalNatural DESC;
Count the number of vegan lipsticks sold in the US.
CREATE TABLE lipsticks(product_name TEXT,product_type TEXT,vegan BOOLEAN,sale_country TEXT); INSERT INTO lipsticks(product_name,product_type,vegan,sale_country) VALUES ('Matte Lipstick','lipsticks',true,'US');
SELECT COUNT(*) FROM lipsticks WHERE product_type = 'lipsticks' AND vegan = true AND sale_country = 'US';
What is the total quantity of lip and cheek products sold in France in the past quarter?
CREATE TABLE QuantitySales (product VARCHAR(255),country VARCHAR(255),date DATE,quantity INT);
SELECT SUM(quantity) FROM QuantitySales WHERE (product = 'Lipstick' OR product = 'Cheek Stain') AND country = 'France' AND date >= DATEADD(quarter, -1, GETDATE());
What is the total number of crime incidents reported in each city in the state of Texas in the last month?
CREATE TABLE crime_incidents_tx (id INT,city VARCHAR(255),crime_type VARCHAR(255),reported_date DATE);
SELECT city, COUNT(*) as total_incidents FROM crime_incidents_tx WHERE reported_date BETWEEN '2021-11-01' AND '2021-11-30' GROUP BY city;
What is the total transaction amount by transaction type?
CREATE TABLE Transactions (TransactionID INT,TransactionType VARCHAR(20),Amount DECIMAL(10,2)); INSERT INTO Transactions (TransactionID,TransactionType,Amount) VALUES (1,'Deposit',5000.00),(2,'Withdrawal',2000.00),(3,'Transfer',3000.00);
SELECT TransactionType, SUM(Amount) AS TotalAmount FROM Transactions GROUP BY TransactionType;
What is the total value of transactions for each customer in the last 30 days?
CREATE TABLE transactions (id INT,customer_id INT,value DECIMAL(10,2),transaction_date DATE); INSERT INTO transactions (id,customer_id,value,transaction_date) VALUES (1,1,100,'2022-01-01'),(2,1,200,'2022-01-15'),(3,2,50,'2022-01-05'),(4,2,150,'2022-01-30'),(5,3,300,'2022-01-20');
SELECT c.id, SUM(t.value) FROM customers c INNER JOIN transactions t ON c.id = t.customer_id WHERE t.transaction_date >= CURDATE() - INTERVAL 30 DAY GROUP BY c.id;
Count the number of artifacts found in each 'material' in the 'artifacts' table.
CREATE TABLE artifacts (id INT,site_id INT,artifact_type VARCHAR(50),material VARCHAR(50),date_found DATE); INSERT INTO artifacts (id,site_id,artifact_type,material,date_found) VALUES (1,1,'Pottery','Clay','2020-01-01'),(2,1,'Coin','Metal','2020-01-02'),(3,2,'Bead','Glass','2020-01-03'),(4,1,'Pottery','Ceramic','2020-01-04');
SELECT material, COUNT(*) FROM artifacts GROUP BY material;
Calculate total resource allocation for each clinic
CREATE TABLE if not exists 'clinic_resources' (id INT,clinic_name TEXT,resource TEXT,allocation INT,PRIMARY KEY(id));
SELECT clinic_name, SUM(allocation) FROM 'clinic_resources' GROUP BY clinic_name;
What is the average number of beds in rural hospitals in each province of Canada?
CREATE TABLE rural_canada_hospitals (name TEXT,province TEXT,num_beds INTEGER); INSERT INTO rural_canada_hospitals (name,province,num_beds) VALUES ('Hospital A','Ontario',50),('Hospital B','Quebec',75),('Hospital C','Alberta',40),('Hospital D','British Columbia',60);
SELECT province, AVG(num_beds) FROM rural_canada_hospitals GROUP BY province;
How many unique donors contributed to each program category in H2 2021?
CREATE TABLE DonorPrograms (donor_id INT,program_category VARCHAR(255),donation_date DATE); INSERT INTO DonorPrograms (donor_id,program_category,donation_date) VALUES (1,'Education','2021-07-02'),(2,'Health','2021-07-03'),(3,'Environment','2021-07-04'),(4,'Education','2021-08-05'),(5,'Health','2021-08-06'),(6,'Arts','2021-07-07'),(7,'Arts','2021-08-08');
SELECT program_category, COUNT(DISTINCT donor_id) as total_donors FROM DonorPrograms WHERE donation_date BETWEEN '2021-07-01' AND '2021-12-31' GROUP BY program_category;
Who are the top 3 donors based on the total amount donated in the 'Donations' table?
CREATE TABLE Donations (DonorID INT,DonationDate DATE,Amount DECIMAL(10,2)); INSERT INTO Donations (DonorID,DonationDate,Amount) VALUES (1,'2020-01-01',50.00),(2,'2019-12-31',100.00),(3,'2019-11-01',200.00),(4,'2019-10-01',150.00);
SELECT DonorID, SUM(Amount) as TotalDonated FROM Donations GROUP BY DonorID ORDER BY TotalDonated DESC LIMIT 3;
How many employees who identify as Latinx were hired in each department in 2020?
CREATE TABLE Employees (EmployeeID INT,Race VARCHAR(20),HireYear INT,Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Race,HireYear,Department) VALUES (1,'White',2020,'IT'),(2,'Black',2019,'HR'),(3,'Asian',2018,'IT'),(4,'Latinx',2020,'IT'),(5,'Latinx',2020,'HR');
SELECT Department, COUNT(*) FROM Employees WHERE HireYear = 2020 AND Race = 'Latinx' GROUP BY Department;
List the job titles of employees who have a salary higher than the average salary in the IT department.
CREATE TABLE Employees (EmployeeID INT,JobTitle VARCHAR(50),Salary DECIMAL(10,2),Department VARCHAR(50)); INSERT INTO Employees (EmployeeID,JobTitle,Salary,Department) VALUES (1,'Software Engineer',90000.00,'IT'),(2,'Data Analyst',80000.00,'IT'),(3,'Software Engineer',75000.00,'IT');
SELECT JobTitle FROM Employees WHERE Salary > (SELECT AVG(Salary) FROM Employees WHERE Department = 'IT') AND Department = 'IT';
List the top 3 donors from the 'asia_donors' table who have donated the highest amounts.
CREATE TABLE asia_donors (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2)); INSERT INTO asia_donors (id,donor_name,donation_amount) VALUES (1,'DonorA',25000),(2,'DonorB',18000),(3,'DonorC',12000),(4,'DonorD',22000),(5,'DonorE',15000);
SELECT donor_name, donation_amount FROM asia_donors ORDER BY donation_amount DESC LIMIT 3;
How many ethical AI projects does each organization have in Canada?
CREATE TABLE ai_ethics (id INT,project VARCHAR(50),organization VARCHAR(50),country VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO ai_ethics (id,project,organization,country,start_date,end_date) VALUES (3,'AI Ethics Compliance','AI Guardians','Canada','2020-01-01','2020-12-31');
SELECT organization, COUNT(*) as total_projects FROM ai_ethics WHERE country = 'Canada' GROUP BY organization;
What is the maximum fare for 'Train' mode of transport in 'June'?
CREATE TABLE Fares(fare INT,journey_date DATE,mode_of_transport VARCHAR(20)); INSERT INTO Fares(fare,journey_date,mode_of_transport) VALUES (7,'2022-06-01','Train'),(8,'2022-06-02','Train'),(9,'2022-07-01','Train');
SELECT MAX(fare) FROM Fares WHERE mode_of_transport = 'Train' AND EXTRACT(MONTH FROM journey_date) = 6;
Find the number of brands that adhere to fair labor practices in each country.
CREATE TABLE brands (brand_id INT,country VARCHAR(20),adheres_to_fair_labor_practices BOOLEAN);
SELECT country, COUNT(*) FROM brands WHERE adheres_to_fair_labor_practices = TRUE GROUP BY country;
What is the total quantity of sustainable material used by each brand, ordered by the most used material?
CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50),Material VARCHAR(50),Quantity INT);INSERT INTO Brands (BrandID,BrandName,Material,Quantity) VALUES (1,'BrandA','Organic Cotton',3000),(2,'BrandB','Recycled Polyester',2500),(1,'BrandA','Hemp',1500),(3,'BrandC','Organic Cotton',2000),(2,'BrandB','Tencel',1800);
SELECT Material, SUM(Quantity) as TotalQuantity FROM Brands GROUP BY Material ORDER BY TotalQuantity DESC;
What is the average textile waste generation (in metric tons) per sustainable fashion brand in the EU?
CREATE TABLE TextileWaste (Brand VARCHAR(255),Location VARCHAR(255),WasteQuantity FLOAT); INSERT INTO TextileWaste (Brand,Location,WasteQuantity) VALUES ('BrandA','EU',12.5),('BrandB','EU',15.8),('BrandC','EU',10.4);
SELECT AVG(WasteQuantity) FROM TextileWaste WHERE Location = 'EU';
How many unique donors are there in the state of Washington?
CREATE TABLE donors (id INT,state TEXT); INSERT INTO donors (id,state) VALUES (1,'Washington'),(2,'Washington'),(3,'Oregon'),(4,'Washington');
SELECT COUNT(DISTINCT id) FROM donors WHERE state = 'Washington';
What is the average donation amount per month for the last two years?
CREATE TABLE Donations (DonationID INT,DonationAmount DECIMAL(10,2),DonationDate DATE);
SELECT DATEPART(month, DonationDate) AS Month, AVG(DonationAmount) FROM Donations WHERE YEAR(DonationDate) >= YEAR(DATEADD(year, -2, GETDATE())) GROUP BY DATEPART(month, DonationDate);
Delete the cultural competency training record for the employee with id 1006
CREATE TABLE employee_trainings (employee_id INT,training_type VARCHAR(255),completed_date DATE); INSERT INTO employee_trainings (employee_id,training_type,completed_date) VALUES (1001,'Cultural Competency','2022-01-15'),(1002,'Cultural Competency','2021-12-12'),(1003,'Cultural Competency','2022-02-20'),(1006,'Cultural Competency','2022-03-15');
DELETE FROM employee_trainings WHERE employee_id = 1006;
List all virtual tours in Canada with a price over 20 CAD.
CREATE TABLE VirtualTours (id INT,name TEXT,country TEXT,price FLOAT); INSERT INTO VirtualTours (id,name,country,price) VALUES (1,'Virtual Niagara Falls Tour','Canada',25.0),(2,'Canada Virtual Wildlife Tour','Canada',18.5);
SELECT * FROM VirtualTours WHERE country = 'Canada' AND price > 20;
What is the engagement rate for virtual tours in 'Rome'?
CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,city TEXT,engagement INT); INSERT INTO virtual_tours (tour_id,hotel_id,city,engagement) VALUES (1,3,'Rome',100),(2,3,'Rome',150),(3,4,'Rome',200);
SELECT AVG(engagement) FROM virtual_tours WHERE city = 'Rome';
Insert records of new traditional art forms
CREATE TABLE art_forms (id INT,name VARCHAR(50),description VARCHAR(100),origin_country VARCHAR(50));
INSERT INTO art_forms (id, name, description, origin_country) VALUES (3, 'Taiga', 'Traditional Siberian embroidery', 'Russia'), (4, 'Tebedu', 'Sarawakian traditional weaving', 'Malaysia')
Delete the 'therapists' table
DROP TABLE therapists;
DROP TABLE therapists;
Find the minimum depth of the ocean floor in the Indian Ocean.
CREATE TABLE ocean_floor_depth (location TEXT,depth INTEGER); INSERT INTO ocean_floor_depth (location,depth) VALUES ('Indian Ocean',8000); INSERT INTO ocean_floor_depth (location,depth) VALUES ('Pacific Ocean',10000);
SELECT MIN(depth) FROM ocean_floor_depth WHERE location = 'Indian Ocean';
How many hours of content are available for children in the Middle East?
CREATE TABLE content (content_id INT,content_type VARCHAR(20),audience_type VARCHAR(20),hours_available FLOAT); INSERT INTO content VALUES (1,'cartoons','children',15.5);
SELECT SUM(hours_available) FROM content WHERE audience_type = 'children' AND country IN ('Saudi Arabia', 'United Arab Emirates', 'Israel');
What is the average number of social media followers of news anchors in a specific news channel, categorized by gender?
CREATE TABLE news_anchors (id INT,name VARCHAR(255),news_channel VARCHAR(255),followers INT,gender VARCHAR(255)); INSERT INTO news_anchors (id,name,news_channel,followers,gender) VALUES (1,'Anchor1','Channel1',50000,'Female'),(2,'Anchor2','Channel1',60000,'Male');
SELECT gender, AVG(followers) FROM news_anchors WHERE news_channel = 'Channel1' GROUP BY gender;
Display the mining sites and their respective water consumption in the 'water_consumption' table.
CREATE TABLE water_consumption (site VARCHAR(50),water_consumption DECIMAL(10,2));
SELECT site, water_consumption FROM water_consumption;
How many complaints were received for mobile and broadband services in the last month?
CREATE TABLE customer_complaints (complaint_id INT,complaint_type VARCHAR(50),complaint_date DATE); INSERT INTO customer_complaints (complaint_id,complaint_type,complaint_date) VALUES (1,'Mobile','2022-03-01'),(2,'Broadband','2022-03-15'),(3,'Mobile','2022-04-01');
SELECT COUNT(*) FROM customer_complaints WHERE complaint_date >= DATE_TRUNC('month', NOW()) - INTERVAL '1 month' AND complaint_type IN ('Mobile', 'Broadband');
What is the peak usage time for each day of the week?
CREATE TABLE usage_timestamps (usage_time TIMESTAMP,data_usage FLOAT); INSERT INTO usage_timestamps (usage_time,data_usage) VALUES ('2022-01-01 09:00:00',5000),('2022-01-01 10:00:00',6000),('2022-01-02 11:00:00',7000);
SELECT DATE_FORMAT(usage_time, '%W') AS day_of_week, HOUR(usage_time) AS hour_of_day, MAX(data_usage) AS peak_usage FROM usage_timestamps GROUP BY day_of_week, hour_of_day;
Calculate the total number of volunteer hours contributed by volunteers from 'California' in 'Health' projects in 2021.
CREATE TABLE volunteers (volunteer_id INT,name VARCHAR(255),state VARCHAR(255));
SELECT SUM(vh.hours) as total_hours FROM volunteer_projects vp JOIN volunteer_hours vh ON vp.project_id = vh.project_id JOIN volunteers vol ON vh.volunteer_id = vol.volunteer_id WHERE vp.cause = 'Health' AND vol.state = 'California' AND vh.volunteer_date BETWEEN '2021-01-01' AND '2021-12-31';
Update records in the 'Donors' table where the donation amount is greater than $1000 and change the last donation date to '2022-01-01'
CREATE TABLE Donors (id INT PRIMARY KEY,donor_name VARCHAR(255),last_donation DATE,donation_amount FLOAT);
UPDATE Donors SET last_donation = '2022-01-01' WHERE donation_amount > 1000;
What is the average donation amount for the 'Health' program?
CREATE TABLE program (id INT,name VARCHAR(50)); INSERT INTO program (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donation (id INT,amount DECIMAL(10,2),program_id INT);
SELECT AVG(d.amount) as avg_donation_amount FROM donation d WHERE d.program_id = 2;
Find the number of unique organizations in each country in the Philanthropy Trends table?
CREATE TABLE PhilanthropyTrends (OrgID INT,Name TEXT,Country TEXT);
SELECT Country, COUNT(DISTINCT OrgID) as UniqueOrganizations FROM PhilanthropyTrends GROUP BY Country;
What is the total number of games designed by non-binary game designers?
CREATE TABLE GameDesigners (DesignerID INT,DesignerName VARCHAR(50),Gender VARCHAR(10),NumberOfGames INT); INSERT INTO GameDesigners (DesignerID,DesignerName,Gender,NumberOfGames) VALUES (1,'Alice','Female',3),(2,'Bob','Male',2),(3,'Charlie','Non-binary',1);
SELECT SUM(NumberOfGames) FROM GameDesigners WHERE Gender = 'Non-binary';
Identify the number of IoT devices in each country and the total number of devices.
CREATE TABLE device_country (device_id INT,country TEXT); INSERT INTO device_country (device_id,country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'Brazil'); CREATE TABLE device_info (device_id INT,device_type TEXT); INSERT INTO device_info (device_id,device_type) VALUES (1,'Soil Sensor'),(2,'Temperature Sensor'),(3,'Humidity Sensor'),(4,'Precision Sprayer');
SELECT country, COUNT(*) AS device_count FROM device_country GROUP BY country UNION SELECT 'Total' AS country, COUNT(*) FROM device_country;
Show the total budget allocation for healthcare services in the top 5 states with the highest budget allocation
CREATE TABLE healthcare_services (service_id INT,state_id INT,budget FLOAT);CREATE TABLE states (state_id INT,state_name TEXT);
SELECT s.state_name, SUM(hs.budget) FROM healthcare_services hs INNER JOIN states s ON hs.state_id = s.state_id GROUP BY s.state_name ORDER BY SUM(hs.budget) DESC LIMIT 5;
What is the total budget allocated for all services in 'Arizona' and 'New Mexico'?
CREATE TABLE budget (state VARCHAR(20),service VARCHAR(20),amount INT); INSERT INTO budget (state,service,amount) VALUES ('Arizona','Education',40000),('Arizona','Healthcare',60000),('Arizona','Transportation',30000),('New Mexico','Education',50000),('New Mexico','Healthcare',70000),('New Mexico','Transportation',20000);
SELECT SUM(amount) FROM budget WHERE state IN ('Arizona', 'New Mexico');
How many Terbium mines are there in China, and what is their production capacity?
CREATE TABLE terbium_mines (mine VARCHAR(50),country VARCHAR(50),capacity INT);
SELECT COUNT(*), SUM(capacity) FROM terbium_mines WHERE country = 'China';
What is the average production of Neodymium in South Africa in 2020?
CREATE TABLE Neodymium_Production (year INT,country TEXT,production FLOAT); INSERT INTO Neodymium_Production (year,country,production) VALUES (2015,'China',33000),(2015,'Australia',200),(2016,'China',35000),(2016,'Australia',250),(2017,'China',34000),(2017,'Australia',300),(2018,'China',36000),(2018,'Australia',320),(2019,'China',37000),(2019,'Australia',400),(2020,'China',38000),(2020,'South Africa',150);
SELECT AVG(production) FROM Neodymium_Production WHERE country = 'South Africa' AND year = 2020;
What is the average property tax for 2-bedroom units in each neighborhood?
CREATE TABLE neighborhood (id INT,name VARCHAR(255)); INSERT INTO neighborhood (id,name) VALUES (1,'Central Park'),(2,'Downtown'); CREATE TABLE property (id INT,bedrooms INT,neighborhood_id INT,property_tax DECIMAL(5,2)); INSERT INTO property (id,bedrooms,neighborhood_id,property_tax) VALUES (1,2,1,3000),(2,2,2,4000);
SELECT n.name AS neighborhood, AVG(p.property_tax) AS avg_property_tax FROM property p JOIN neighborhood n ON p.neighborhood_id = n.id GROUP BY n.name;
What is the total square footage of all properties in the city of Vancouver, BC that are affordable and wheelchair accessible?
CREATE TABLE vancouver_real_estate(id INT,city VARCHAR(50),size INT,affordable BOOLEAN,wheelchair_accessible BOOLEAN); INSERT INTO vancouver_real_estate VALUES (1,'Vancouver',1000,true,true);
SELECT SUM(size) FROM vancouver_real_estate WHERE city = 'Vancouver' AND affordable = true AND wheelchair_accessible = true;
How many countries in the Middle East have implemented energy efficiency policies since 2010?
CREATE TABLE EnergyEfficiencyPolicies (id INT,country VARCHAR(20),policy_start_date DATE); INSERT INTO EnergyEfficiencyPolicies (id,country,policy_start_date) VALUES (1,'UAE','2012-01-01'),(2,'Saudi Arabia','2011-06-01'),(3,'Egypt','2015-03-15');
SELECT COUNT(DISTINCT country) FROM EnergyEfficiencyPolicies WHERE policy_start_date >= '2010-01-01' AND country IN ('UAE', 'Saudi Arabia', 'Iran', 'Iraq', 'Israel', 'Jordan', 'Kuwait', 'Lebanon', 'Oman', 'Palestine', 'Qatar', 'Syria', 'Yemen', 'Bahrain');
Show the wind energy projects in Europe, sorted by the capacity in descending order.
CREATE TABLE Europe_Wind_Energy (project VARCHAR(255),capacity INT); INSERT INTO Europe_Wind_Energy (project,capacity) VALUES ('Windfarm A',10000),('Windfarm B',12000),('Windfarm C',8000);
SELECT project, capacity FROM Europe_Wind_Energy ORDER BY capacity DESC;
List the names and launch dates of all space missions that have been lost or failed, ordered by the launch date in ascending order.
CREATE TABLE space_missions_status(id INT,mission_name VARCHAR(255),launch_date DATE,status VARCHAR(255));
SELECT mission_name, launch_date FROM space_missions_status WHERE status IN ('lost', 'failed') ORDER BY launch_date ASC;
Who was the first South Korean astronaut?
CREATE TABLE astronauts (id INT,name VARCHAR(255),country VARCHAR(255),first_flight DATE); INSERT INTO astronauts (id,name,country,first_flight) VALUES (1,'Yi So-yeon','South Korea','2008-04-08');
SELECT name FROM astronauts WHERE country = 'South Korea' AND id = (SELECT MIN(id) FROM astronauts WHERE country = 'South Korea');
Which top 3 threat actors have been most active in the last week in the APAC region?
CREATE TABLE threat_actors (id INT,name VARCHAR(255),region VARCHAR(255),activity_count INT,last_seen TIMESTAMP); INSERT INTO threat_actors (id,name,region,activity_count,last_seen) VALUES (1,'APT28','APAC',15,'2022-03-10 12:00:00'),(2,'APT33','NA',12,'2022-03-12 08:00:00'),(3,'MuddyWater','APAC',18,'2022-03-14 10:00:00');
SELECT name, activity_count FROM threat_actors WHERE region = 'APAC' AND last_seen >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 WEEK) ORDER BY activity_count DESC LIMIT 3;
Find the total number of policies for each policy state.
CREATE TABLE Policies (PolicyNumber INT,PolicyholderID INT,PolicyState VARCHAR(20)); INSERT INTO Policies (PolicyNumber,PolicyholderID,PolicyState) VALUES (1001,3,'California'),(1002,4,'California'),(1003,5,'Texas');
SELECT PolicyState, COUNT(*) FROM Policies GROUP BY PolicyState;
Delete records from the "union_members" table where the "state" column is "NY"
CREATE TABLE union_members (id INT,name VARCHAR(50),state VARCHAR(2),city VARCHAR(20),occupation VARCHAR(20)); INSERT INTO union_members (id,name,state,city,occupation) VALUES (1,'John Doe','NY','New York','Engineer'); INSERT INTO union_members (id,name,state,city,occupation) VALUES (2,'Jane Smith','CA','Los Angeles','Teacher');
DELETE FROM union_members WHERE state = 'NY';
List the make and model of electric vehicles sold in Japan since 2019.
CREATE TABLE japan_ev_sales (year INT,make VARCHAR(50),model VARCHAR(50),sales INT); INSERT INTO japan_ev_sales (year,make,model,sales) VALUES (2019,'Nissan','Leaf',15000),(2020,'Toyota','Prius Prime',12000),(2021,'Mitsubishi','Outlander PHEV',10000),(2021,'Honda','Clarity',8000);
SELECT DISTINCT make, model FROM japan_ev_sales WHERE year >= 2019;
What is the average speed of electric vehicles in the 'test_drives' table?
CREATE TABLE test_drives (id INT,vehicle_type VARCHAR(10),avg_speed FLOAT); INSERT INTO test_drives (id,vehicle_type,avg_speed) VALUES (1,'EV',55.0),(2,'Hybrid',50.0),(3,'EV',60.0);
SELECT AVG(avg_speed) FROM test_drives WHERE vehicle_type = 'EV';
Add new records to the Vessel table for the following vessels: 'Solar Eagle' (Type: Solar, MaxCapacity: 200 tons), 'Wind Spirit' (Type: Wind, MaxCapacity: 300 tons)
CREATE TABLE Vessel (Id INT IDENTITY(1,1) PRIMARY KEY,Name VARCHAR(50),Type VARCHAR(50),MaxCapacity INT);
INSERT INTO Vessel (Name, Type, MaxCapacity) VALUES ('Solar Eagle', 'Solar', 200), ('Wind Spirit', 'Wind', 300);
What is the minimum speed in knots for vessels that docked at the port of Hong Kong between the dates of June 15th and June 30th, 2021?
CREATE TABLE Vessels(Id INT,Name VARCHAR(255),AverageSpeed DECIMAL(5,2)); CREATE TABLE DockingHistory(Id INT,VesselId INT,Port VARCHAR(255),DockingDateTime DATETIME); INSERT INTO Vessels VALUES (1,'VesselA',15.5),(2,'VesselB',18.3),(3,'VesselC',20.2); INSERT INTO DockingHistory VALUES (1,1,'Hong Kong','2021-06-16 12:00:00'),(2,1,'Hong Kong','2021-06-25 15:00:00'),(3,2,'Hong Kong','2021-06-20 09:00:00'),(4,3,'Hong Kong','2021-06-22 18:00:00');
SELECT MIN(v.AverageSpeed) FROM Vessels v INNER JOIN DockingHistory dh ON v.Id = dh.VesselId WHERE dh.Port = 'Hong Kong' AND dh.DockingDateTime BETWEEN '2021-06-15' AND '2021-06-30';
How many visitors from the USA have an annual pass for our museums?
CREATE TABLE Visitors (id INT,country VARCHAR(255),has_annual_pass BOOLEAN);
SELECT COUNT(*) FROM Visitors WHERE country = 'USA' AND has_annual_pass = TRUE;
Delete records with year 2018 from table 'waste_generation'
CREATE TABLE waste_generation (id INT PRIMARY KEY,region VARCHAR(50),year INT,metric DECIMAL(5,2)); INSERT INTO waste_generation (id,region,year,metric) VALUES (1,'Mumbai',2018,5678.90),(2,'Mumbai',2019,6001.12),(3,'Tokyo',2018,3456.78),(4,'Tokyo',2019,3501.09);
DELETE FROM waste_generation WHERE year = 2018;
List all circular economy initiatives in the 'Manufacturing' sector.
CREATE TABLE Sectors (id INT,sector VARCHAR(255)); INSERT INTO Sectors (id,sector) VALUES (1,'Energy'),(2,'Manufacturing'),(3,'Agriculture'); CREATE TABLE Initiatives (id INT,name VARCHAR(255),sector_id INT); INSERT INTO Initiatives (id,name,sector_id) VALUES (1,'ProjectA',1),(2,'ProjectB',2),(3,'ProjectC',2),(4,'ProjectD',3);
SELECT Initiatives.name FROM Initiatives JOIN Sectors ON Initiatives.sector_id = Sectors.id WHERE Sectors.sector = 'Manufacturing';
List the top 3 cities with the highest number of workout sessions.
CREATE TABLE Workouts (WorkoutID INT,MemberID INT,City VARCHAR(50)); INSERT INTO Workouts (WorkoutID,MemberID,City) VALUES (1,1,'New York'),(2,2,'Los Angeles'),(3,3,'Chicago');
SELECT City, COUNT(*) FROM Workouts GROUP BY City ORDER BY COUNT(*) DESC LIMIT 3;
What are the names of the community development initiatives in the 'community_development' table that have different initiation years than any agricultural innovation projects in the 'rural_innovations' table?
CREATE TABLE rural_innovations (id INT,project_name VARCHAR(50),initiation_year INT); INSERT INTO rural_innovations (id,project_name,initiation_year) VALUES (1,'Precision Agriculture',2010),(2,'Smart Greenhouses',2012); CREATE TABLE community_development (id INT,initiative_name VARCHAR(50),initiation_year INT); INSERT INTO community_development (id,initiative_name,initiation_year) VALUES (1,'Youth Empowerment Program',2008),(2,'Renewable Energy Workshops',2022);
SELECT initiative_name FROM community_development WHERE initiation_year NOT IN (SELECT initiation_year FROM rural_innovations);
What is the total area of habitat preservation efforts in the 'Amazon Rainforest' region?
CREATE TABLE habitat_preservation (preservation_id INT,location VARCHAR(50),area FLOAT); INSERT INTO habitat_preservation (preservation_id,location,area) VALUES (1,'Amazon Rainforest',1500000); INSERT INTO habitat_preservation (preservation_id,location,area) VALUES (2,'Arctic Tundra',2500000);
SELECT SUM(area) FROM habitat_preservation WHERE location = 'Amazon Rainforest';