instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many suppliers comply with labor rights in Africa?
CREATE TABLE LaborRightsSuppliers (id INT,supplier_location VARCHAR(50)); INSERT INTO LaborRightsSuppliers (id,supplier_location) VALUES (1,'Nigeria'),(2,'South Africa'),(3,'Egypt'),(4,'Morocco'),(5,'Kenya'),(6,'Ethiopia'),(7,'Tanzania');
SELECT COUNT(*) FROM LaborRightsSuppliers WHERE supplier_location LIKE '%%Africa%%';
Insert a new record for a company named 'Social Startups Ltd.' with an ESG rating of 'B+' in the companies table.
CREATE TABLE companies (id INT,name VARCHAR(50),esg_rating VARCHAR(3)); INSERT INTO companies (id,name,esg_rating) VALUES (1,'ABC Inc.','A'); INSERT INTO companies (id,name,esg_rating) VALUES (2,'DEF Inc.','B'); INSERT INTO companies (id,name,esg_rating) VALUES (3,'XYZ Inc.','C');
INSERT INTO companies (name, esg_rating) VALUES ('Social Startups Ltd.', 'B+');
Find the REE production amounts for each country in 2018 and 2020, including the difference.
CREATE TABLE production (country VARCHAR(255),year INT,ree_production INT); INSERT INTO production (country,year,ree_production) VALUES ('China',2018,120000),('China',2020,140000),('USA',2018,12000),('USA',2020,15000),('Australia',2018,20000),('Australia',2020,22000);
SELECT a.country, SUM(a.ree_production) AS production_2018, SUM(b.ree_production) AS production_2020, SUM(b.ree_production) - SUM(a.ree_production) AS difference FROM production AS a JOIN production AS b ON a.country = b.country WHERE a.year = 2018 AND b.year = 2020 GROUP BY a.country;
What is the total quantity of garments sold per store for the 'cotton' fabric type?
CREATE TABLE garment_sales (id INT PRIMARY KEY,garment_id INT,store_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); INSERT INTO garment_sales (id,garment_id,store_id,sale_date,quantity,price) VALUES (1,1001,101,'2022-01-01',5,150.00); CREATE TABLE fabric_garment (id INT PRIMARY KEY,fabric_type VARCHAR(50),garment_id INT); INSERT INTO fabric_garment (id,fabric_type,garment_id) VALUES (1,'cotton',1001);
SELECT s.store_id, SUM(gs.quantity) AS total_quantity FROM garment_sales gs JOIN fabric_garment fg ON gs.garment_id = fg.garment_id JOIN garment g ON gs.garment_id = g.id JOIN store s ON gs.store_id = s.id WHERE fg.fabric_type = 'cotton' GROUP BY s.store_id;
What is the percentage of patients in mental health treatment centers in South America who have Anxiety Disorder?
CREATE TABLE south_american_health_centers (id INT,name VARCHAR(255),patients INT,condition VARCHAR(255)); INSERT INTO south_american_health_centers (id,name,patients,condition) VALUES (1,'Amazon Healing',100,'Anxiety Disorder'); INSERT INTO south_american_health_centers (id,name,patients,condition) VALUES (2,'Andes Care',150,'Depression'); INSERT INTO south_american_health_centers (id,name,patients,condition) VALUES (3,'Patagonia Peace',120,'Anxiety Disorder');
SELECT 100.0 * SUM(CASE WHEN condition = 'Anxiety Disorder' THEN patients ELSE 0 END) / SUM(patients) FROM south_american_health_centers;
List all artists who have performed in Africa but not in Egypt.
CREATE TABLE Artists (ArtistID int,ArtistName varchar(100),Country varchar(50)); INSERT INTO Artists (ArtistID,ArtistName,Country) VALUES (1,'Taylor Swift','United States'),(2,'Drake','Canada'),(3,'Wizkid','Nigeria'); CREATE TABLE Concerts (ConcertID int,ArtistID int,City varchar(50),Country varchar(50)); INSERT INTO Concerts (ConcertID,ArtistID,City,Country) VALUES (1,1,'New York','United States'),(2,2,'Toronto','Canada'),(3,3,'Lagos','Nigeria');
SELECT DISTINCT Artists.ArtistName FROM Artists JOIN Concerts ON Artists.ArtistID = Concerts.ArtistID WHERE Artists.Country = 'Africa' AND Concerts.Country != 'Egypt';
Who works in the bioprocess engineering department and their associated startups?
CREATE TABLE Employee (Employee_ID INT PRIMARY KEY,Employee_Name VARCHAR(50),Department VARCHAR(50)); INSERT INTO Employee (Employee_ID,Employee_Name,Department) VALUES (1,'John Doe','Genetic Research'); INSERT INTO Employee (Employee_ID,Employee_Name,Department) VALUES (2,'Jane Smith','BioProcess Engineering'); CREATE TABLE Startup (Startup_Name VARCHAR(50) PRIMARY KEY,Industry VARCHAR(50),Funding DECIMAL(10,2)); INSERT INTO Startup (Startup_Name,Industry,Funding) VALUES ('GenTech','Genetic Research',3000000.00); INSERT INTO Startup (Startup_Name,Industry,Funding) VALUES ('BioPro','BioProcess Engineering',4000000.00);
SELECT E.Employee_Name, S.Startup_Name FROM Employee E RIGHT JOIN Startup S ON E.Department = S.Industry WHERE E.Department = 'BioProcess Engineering';
Which countries have the highest timber production in 2020?
CREATE TABLE countries (id INT,name VARCHAR(255)); INSERT INTO countries (id,name) VALUES (1,'USA'),(2,'Canada'); CREATE TABLE timber_production (country_id INT,year INT,volume FLOAT); INSERT INTO timber_production (country_id,year,volume) VALUES (1,2020,35.6),(2,2020,23.4);
SELECT c.name, tp.volume FROM countries c JOIN timber_production tp ON c.id = tp.country_id WHERE tp.year = 2020 ORDER BY tp.volume DESC;
What is the minimum consumer preference score for cosmetic products that source ingredients from country Y?
CREATE TABLE cosmetics (product_name TEXT,consumer_preference_score INTEGER,ingredient_source TEXT); INSERT INTO cosmetics (product_name,consumer_preference_score,ingredient_source) VALUES ('ProductA',85,'CountryX'),('ProductB',90,'CountryY'),('ProductC',70,'CountryX'),('ProductD',95,'CountryZ'),('ProductE',80,'CountryY'),('ProductF',75,'CountryX');
SELECT MIN(consumer_preference_score) FROM cosmetics WHERE ingredient_source = 'CountryY';
What is the maximum ocean acidification level recorded in the Atlantic Ocean, and which marine protected area had this level?
CREATE TABLE ocean_acidification (measurement_date DATE,location TEXT,level FLOAT); INSERT INTO ocean_acidification (measurement_date,location,level) VALUES ('2021-01-01','Galapagos Islands',7.5); INSERT INTO ocean_acidification (measurement_date,location,level) VALUES ('2021-01-02','Great Barrier Reef',7.6);
SELECT mpa.area_name, oa.level AS max_level FROM marine_protected_areas mpa JOIN (SELECT location, MAX(level) AS max_level FROM ocean_acidification WHERE region = 'Atlantic Ocean' GROUP BY location) oa ON mpa.area_name = oa.location;
What is the number of ethical AI research papers published per year in the United States?
CREATE TABLE ethical_ai_research (id INT,publication_year INT,country VARCHAR,is_ethical BOOLEAN);
SELECT publication_year, COUNT(*) as num_publications FROM ethical_ai_research WHERE is_ethical = TRUE AND country = 'United States' GROUP BY publication_year;
Display the average depth of the ocean floor for the 'Atlantic' ocean.
CREATE SCHEMA OceanFloor(ocean_id INT,ocean_name TEXT,depth INT);INSERT INTO OceanFloor(ocean_id,ocean_name,depth) VALUES (1,'Atlantic',5000),(2,'Pacific',4000),(3,'Indian',3000);
SELECT AVG(depth) FROM OceanFloor WHERE ocean_name = 'Atlantic';
Insert new customer 'Peter Lee' with 10 GB data usage in 'Seattle' for 'GHI Internet'.
CREATE TABLE customers (id INT,name TEXT,isp TEXT,city TEXT,data_usage FLOAT); CREATE TABLE regions (id INT,name TEXT,isp TEXT); INSERT INTO regions (id,name,isp) VALUES (1,'NYC','DEF Internet'),(2,'LA','DEF Internet'),(3,'Chicago','ABC Internet'),(4,'Seattle','GHI Internet');
INSERT INTO customers (id, name, isp, city, data_usage) VALUES (5, 'Peter Lee', 'GHI Internet', 'Seattle', 10.0);
What is the total number of military personnel in the 'Air Force' and 'Navy' branches?
CREATE TABLE MilitaryPersonnel (ID INT,Branch VARCHAR(10),Personnel INT); INSERT INTO MilitaryPersonnel (ID,Branch,Personnel) VALUES (1,'Army',500000),(2,'Navy',350000),(3,'Air Force',400000);
SELECT SUM(Personnel) FROM MilitaryPersonnel WHERE Branch IN ('Air Force', 'Navy');
What is the maximum depth of any marine protected area in the Atlantic region?
CREATE TABLE marine_protected_areas (name VARCHAR(255),location VARCHAR(255),depth FLOAT); INSERT INTO marine_protected_areas (name,location,depth) VALUES ('MPA 1','Pacific',120.5); INSERT INTO marine_protected_areas (name,location,depth) VALUES ('MPA 2','Atlantic',200.3);
SELECT MAX(depth) FROM marine_protected_areas WHERE location = 'Atlantic';
Insert a new record for waste generation in the city of Boston for the third quarter of 2021, with 1200 grams of plastic waste, 1500 grams of glass waste, and 1800 grams of paper waste.
CREATE TABLE waste_generation (city VARCHAR(255),quarter INT,material_type VARCHAR(255),generation_grams INT);
INSERT INTO waste_generation (city, quarter, material_type, generation_grams) VALUES ('Boston', 3, 'Plastic', 1200), ('Boston', 3, 'Glass', 1500), ('Boston', 3, 'Paper', 1800);
Delete records from the 'dispensary_sales' table where the sale date is '2022-01-02'
CREATE TABLE dispensary_sales (dispensary_id INT,product_id INT,sale_date DATE,quantity INT);
DELETE FROM dispensary_sales WHERE sale_date = '2022-01-02';
What is the average age of patients who have completed the Mindfulness-Based Stress Reduction program?
CREATE TABLE patient (patient_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),condition VARCHAR(50)); INSERT INTO patient (patient_id,name,age,gender,condition) VALUES (1,'Sophia Garcia',35,'Female','Anxiety'),(2,'Daniel Park',42,'Male','Depression'),(3,'Hana Kim',28,'Female',NULL); CREATE TABLE treatment (treatment_id INT,patient_id INT,treatment_name VARCHAR(50),start_date DATE,end_date DATE,completed BOOLEAN); INSERT INTO treatment (treatment_id,patient_id,treatment_name,start_date,end_date,completed) VALUES (1,1,'Mindfulness-Based Stress Reduction','2021-01-01','2021-03-31',TRUE),(2,2,'Mindfulness-Based Stress Reduction','2021-04-01','2021-06-30',FALSE),(3,3,'Mindfulness-Based Stress Reduction','2021-07-01','2021-09-30',TRUE);
SELECT AVG(age) FROM patient JOIN treatment ON patient.patient_id = treatment.patient_id WHERE treatment_name = 'Mindfulness-Based Stress Reduction' AND completed = TRUE;
Update the battery_capacity of tesla_model_3 cars to 55 kWh in the ev_battery_stats table.
CREATE TABLE ev_battery_stats (id INT PRIMARY KEY,make VARCHAR(50),model VARCHAR(50),battery_capacity FLOAT);
UPDATE ev_battery_stats SET battery_capacity = 55 WHERE make = 'tesla' AND model = 'model 3';
Show the total amount of grants awarded by type
CREATE TABLE grants (id INT PRIMARY KEY,type VARCHAR(255),amount DECIMAL(10,2));
SELECT type, SUM(amount) FROM grants GROUP BY type;
What is the number of patients diagnosed with asthma in the rural county of "Seabrook" who are also under the age of 18?
CREATE TABLE patients (id INT,name VARCHAR(50),age INT,diagnosis VARCHAR(50)); INSERT INTO patients (id,name,age,diagnosis) VALUES (1,'John Doe',15,'Asthma'); INSERT INTO patients (id,name,age,diagnosis) VALUES (2,'Jane Smith',20,'Hypertension'); INSERT INTO patients (id,name,age,diagnosis) VALUES (3,'Bob Johnson',17,'Asthma'); INSERT INTO patients (id,name,age,diagnosis) VALUES (4,'Alice Williams',12,'Asthma'); CREATE TABLE county (name VARCHAR(50),population INT); INSERT INTO county (name,population) VALUES ('Seabrook',7000);
SELECT COUNT(*) FROM patients WHERE diagnosis = 'Asthma' AND age < 18 AND (SELECT name FROM county WHERE population = (SELECT population FROM county WHERE name = 'Seabrook')) = 'Seabrook';
Update the genre of movie 'Movie A' to 'Comedy'.
CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO movies (id,title,genre,budget) VALUES (1,'Movie A','Action',8000000.00);
UPDATE movies SET genre = 'Comedy' WHERE title = 'Movie A';
Find the total number of autonomous vehicle tests conducted in each month in the 'testing_data' table.
CREATE TABLE testing_data (id INT,test_date DATE,make VARCHAR(50),model VARCHAR(50),autonomy_level INT);
SELECT MONTH(test_date), SUM(autonomy_level) FROM testing_data GROUP BY MONTH(test_date);
Find the number of pollution control initiatives in the Atlantic and Indian oceans.
CREATE TABLE Ocean (ocean_name VARCHAR(50),pollution_initiatives NUMERIC(8,2)); INSERT INTO Ocean (ocean_name,pollution_initiatives) VALUES ('Atlantic',150),('Indian',120);
SELECT SUM(pollution_initiatives) FROM Ocean WHERE ocean_name IN ('Atlantic', 'Indian');
What are the top 3 education-focused NPOs in Southeast Asia in terms of total donations in 2021?
CREATE TABLE npos (id INT,name VARCHAR(50),sector VARCHAR(50),country VARCHAR(50),total_donations FLOAT,donation_date DATE); INSERT INTO npos (id,name,sector,country,total_donations,donation_date) VALUES (1,'UNESCO','Education','Indonesia',150000,'2021-06-01'),(2,'Save the Children','Education','Thailand',200000,'2021-07-01'),(3,'Plan International','Education','Philippines',120000,'2021-08-01');
SELECT name, total_donations FROM npos WHERE sector = 'Education' AND country IN ('Indonesia', 'Thailand', 'Philippines', 'Malaysia', 'Vietnam') AND donation_date BETWEEN '2021-01-01' AND '2021-12-31' ORDER BY total_donations DESC LIMIT 3;
Insert new cargo records into the cargo_tracking table with cargo_name 'Fertilizer', destination 'Sydney', and eta '2023-04-15'
CREATE TABLE cargo_tracking (cargo_id INT,cargo_name VARCHAR(50),destination VARCHAR(50),eta DATE);
INSERT INTO cargo_tracking (cargo_name, destination, eta) VALUES ('Fertilizer', 'Sydney', '2023-04-15');
List all humanitarian assistance operations in the last 5 years, excluding those with a budget lower than $100,000.
CREATE TABLE humanitarian_assistance (id INT,operation VARCHAR(50),date DATE,budget INT); INSERT INTO humanitarian_assistance (id,operation,date,budget) VALUES (1,'Operation Provide Comfort','1991-04-07',1500000),(2,'Operation Restore Hope','1992-12-03',8000000),(3,'Operation Unified Assistance','2004-12-26',300000000),(4,'Operation Continuing Promise','2009-01-01',2500000),(5,'Operation United Assistance','2014-10-01',30000000);
SELECT * FROM humanitarian_assistance WHERE date >= DATE_SUB(CURDATE(), INTERVAL 5 YEAR) AND budget >= 100000;
What is the average number of employees for startups founded by women in the renewable energy industry?
CREATE TABLE company (id INT,name TEXT,founder_gender TEXT,industry TEXT,num_employees INT); INSERT INTO company (id,name,founder_gender,industry,num_employees) VALUES (1,'GreenEnergy','Female','Renewable Energy',15); INSERT INTO company (id,name,founder_gender,industry,num_employees) VALUES (2,'SolarTech','Male','Renewable Energy',25);
SELECT AVG(num_employees) FROM company WHERE founder_gender = 'Female' AND industry = 'Renewable Energy';
What is the percentage of tourists visiting Thailand in 2018 from Western countries compared to the total number of tourists who visited Thailand that year?
CREATE TABLE tourism_data (visitor_country VARCHAR(50),destination_country VARCHAR(50),visit_year INT); INSERT INTO tourism_data (visitor_country,destination_country,visit_year) VALUES ('USA','Thailand',2018),('Canada','Thailand',2018),('UK','Thailand',2018),('France','Thailand',2018),('Germany','Thailand',2018);
SELECT (COUNT(*) * 100.0 / (SELECT SUM(*) FROM tourism_data WHERE visit_year = 2018 AND destination_country = 'Thailand')) FROM tourism_data WHERE visit_year = 2018 AND destination_country = 'Thailand' AND visitor_country LIKE 'Western%';
Delete the record of Europium production in Q1 2020 from the German mine.
CREATE TABLE production (id INT,mine_id INT,element TEXT,production FLOAT,datetime DATE); INSERT INTO production (id,mine_id,element,production,datetime) VALUES (1,1,'Europium',120.5,'2020-01-01'),(2,2,'Samarium',180.2,'2020-01-15');
DELETE FROM production WHERE mine_id = 1 AND element = 'Europium' AND QUARTER(datetime) = 1 AND YEAR(datetime) = 2020;
What is the number of players who have played each game in the "Strategy" category?
CREATE TABLE GamePlayers (GameID int,GameName varchar(50),Category varchar(50),PlayerID int);
SELECT Category, COUNT(DISTINCT PlayerID) OVER(PARTITION BY Category) as PlayersCount FROM GamePlayers;
How many cases were handled by attorneys who graduated from a top 10 law school?
CREATE TABLE attorneys (id INT,law_school_rank INT); INSERT INTO attorneys (id,law_school_rank) VALUES (1,5); CREATE TABLE cases (id INT,attorney_id INT); INSERT INTO cases (id,attorney_id) VALUES (1,1);
SELECT COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE attorneys.law_school_rank <= 10;
Insert new records for volunteers who participated in a program.
CREATE TABLE volunteers (id INT,name VARCHAR(50),program_id INT); INSERT INTO volunteers (id,name,program_id) VALUES (1,'Mary Johnson',1),(2,'David Lee',NULL),(3,'Susan Chen',3); CREATE TABLE programs (id INT,name VARCHAR(50),budget INT); INSERT INTO programs (id,name,budget) VALUES (1,'Youth Mentoring',50000),(2,'Food Bank',75000),(3,'Environmental Cleanup',60000);
INSERT INTO volunteers (id, name, program_id) VALUES (4, 'James Brown', 2), (5, 'Grace Kim', 3);
What was the total budget for program A?
CREATE TABLE Budget (id INT,program VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO Budget (id,program,amount) VALUES (1,'Program A',5000.00),(2,'Program B',3000.00);
SELECT SUM(amount) FROM Budget WHERE program = 'Program A';
Which excavation sites have no public outreach records?
CREATE TABLE site_l (site_id INT); CREATE TABLE public_outreach (site_id INT,outreach_type VARCHAR(255)); INSERT INTO site_l (site_id) VALUES (1),(2),(3); INSERT INTO public_outreach (site_id,outreach_type) VALUES (1,'Exhibition'),(2,'Lecture'),(3,'Workshop'),(4,'Tour');
SELECT context FROM (SELECT 'site_l' AS context EXCEPT SELECT site_id FROM public_outreach) AS subquery;
What is the average AI ethics score for each country, ordered by the highest average score?
CREATE TABLE ai_ethics_scores (country VARCHAR(50),score INT); INSERT INTO ai_ethics_scores (country,score) VALUES ('USA',85),('India',78),('Brazil',72),('Germany',90),('China',80);
SELECT country, AVG(score) as avg_score FROM ai_ethics_scores GROUP BY country ORDER BY avg_score DESC;
List all policies that are related to mobility impairments and the corresponding policy advocates.
CREATE TABLE Policies (PolicyID INT,PolicyName VARCHAR(50),PolicyType VARCHAR(50)); INSERT INTO Policies VALUES (1,'Ramp Accessibility','Infrastructure'); CREATE TABLE PolicyAdvocates (AdvocateID INT,AdvocateName VARCHAR(50),PolicyID INT); INSERT INTO PolicyAdvocates VALUES (1,'Jane Doe',1); CREATE TABLE PolicyDetails (PolicyID INT,DisabilityType VARCHAR(50)); INSERT INTO PolicyDetails VALUES (1,'Mobility Impairment');
SELECT p.PolicyName, pa.AdvocateName FROM Policies p INNER JOIN PolicyDetails pd ON p.PolicyID = pd.PolicyID INNER JOIN PolicyAdvocates pa ON p.PolicyID = pa.PolicyID WHERE pd.DisabilityType = 'Mobility Impairment';
List all unique artifact types found 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');
SELECT DISTINCT artifact_type FROM artifacts;
Identify marine species that do not have any associated pollution control initiatives.
CREATE TABLE marine_species (id INT,species VARCHAR(255)); INSERT INTO marine_species (id,species) VALUES (1,'Dolphin'),(2,'Shark'),(3,'Turtle'); CREATE TABLE pollution_control (id INT,species_id INT,initiative VARCHAR(255)); INSERT INTO pollution_control (id,species_id,initiative) VALUES (1,1,'Beach Cleanup'),(2,1,'Ocean Floor Mapping'),(3,2,'Beach Cleanup');
SELECT marine_species.species FROM marine_species LEFT JOIN pollution_control ON marine_species.id = pollution_control.species_id WHERE pollution_control.id IS NULL;
What is the total virtual tour engagement time per user for luxury hotels in Q1 2023?
CREATE TABLE hotel_virtual_tours (hotel_category VARCHAR(20),user_id INT,engagement_time INT,tour_date DATE); INSERT INTO hotel_virtual_tours (hotel_category,user_id,engagement_time,tour_date) VALUES ('Luxury',1,300,'2023-01-01'),('Luxury',2,350,'2023-01-01'),('Boutique',3,250,'2023-01-02');
SELECT hotel_category, AVG(engagement_time) as avg_engagement_time FROM hotel_virtual_tours WHERE hotel_category = 'Luxury' AND tour_date BETWEEN '2023-01-01' AND '2023-03-31' GROUP BY hotel_category;
What are the common technology accessibility concerns for people with visual impairments and hearing impairments in the accessibility table?
CREATE TABLE accessibility (id INT,disability VARCHAR(255),concern VARCHAR(255));
SELECT concern FROM accessibility WHERE disability = 'people with visual impairments' INTERSECT SELECT concern FROM accessibility WHERE disability = 'people with hearing impairments';
How many visitors attended events in Tokyo, Japan in the last month?
CREATE TABLE Events (id INT,city VARCHAR(20),country VARCHAR(20),date DATE); INSERT INTO Events (id,city,country,date) VALUES (1,'Tokyo','Japan','2022-03-01'),(2,'Tokyo','Japan','2022-03-15');
SELECT COUNT(*) FROM Events WHERE city = 'Tokyo' AND country = 'Japan' AND date >= DATEADD(month, -1, GETDATE());
What is the average monthly water consumption per worker at the 'North' region mines in 2021?
CREATE TABLE water_consumption (site_id INT,site_name TEXT,region TEXT,month INT,year INT,worker_id INT,water_consumption INT); INSERT INTO water_consumption (site_id,site_name,region,month,year,worker_id,water_consumption) VALUES (7,'RST Mine','North',1,2021,7001,150),(8,'STU Mine','North',2,2021,8001,160),(9,'VWX Mine','North',3,2021,9001,170);
SELECT region, AVG(water_consumption) as avg_water_consumption_per_worker FROM water_consumption WHERE region = 'North' AND year = 2021 GROUP BY region, year;
What is the infection rate of Tuberculosis in 2019?
CREATE TABLE infections (id INT,patient_id INT,infection_type VARCHAR(20),infection_date DATE);
SELECT COUNT(*) * 100000 / (SELECT COUNT(*) FROM infections WHERE YEAR(infection_date) = 2019) AS infection_rate FROM infections WHERE infection_type = 'Tuberculosis' AND YEAR(infection_date) = 2019;
Who are the top 3 artists with the most artworks in the 'Painting' category?
CREATE TABLE artworks (id INT,artist TEXT,category TEXT); INSERT INTO artworks (id,artist,category) VALUES (1,'Van Gogh','Painting'),(2,'Van Gogh','Drawing'),(3,'Monet','Painting'),(4,'Monet','Painting'),(5,'Degas','Painting'),(6,'Degas','Painting'),(7,'Degas','Sculpture');
SELECT artist, COUNT(*) AS num_of_artworks FROM artworks WHERE category = 'Painting' GROUP BY artist ORDER BY num_of_artworks DESC LIMIT 3;
How many COVID-19 vaccines have been administered in each region of Texas, by healthcare provider type?
CREATE TABLE vaccinations (id INT,patient_name VARCHAR(50),healthcare_provider VARCHAR(50),provider_type VARCHAR(30),region VARCHAR(20),vaccine_type VARCHAR(50),date DATE); INSERT INTO vaccinations (id,patient_name,healthcare_provider,provider_type,region,vaccine_type,date) VALUES (1,'Alex','Houston General Hospital','Public','Houston','Pfizer','2021-03-15'); INSERT INTO vaccinations (id,patient_name,healthcare_provider,provider_type,region,vaccine_type,date) VALUES (2,'Bella','Austin Medical Center','Public','Austin','Moderna','2021-03-27'); INSERT INTO vaccinations (id,patient_name,healthcare_provider,provider_type,region,vaccine_type,date) VALUES (3,'Charlie','Dallas Primary Care','Private','Dallas','Johnson & Johnson','2021-04-09');
SELECT region, provider_type, COUNT(*) as num_vaccines FROM vaccinations WHERE vaccine_type = 'COVID-19' GROUP BY region, provider_type;
What is the total CO2 emission for the dyeing process in the Europe region in H1 2022?
CREATE TABLE emissions_europe (emission_id INT,manufacturing_process VARCHAR(50),co2_emission DECIMAL(10,2),region VARCHAR(50),emission_date DATE);
SELECT manufacturing_process, SUM(co2_emission) FROM emissions_europe WHERE manufacturing_process = 'dyeing' AND region = 'Europe' AND emission_date BETWEEN '2022-01-01' AND '2022-06-30' GROUP BY manufacturing_process;
What is the change in infectious disease cases between consecutive months?
CREATE TABLE infectious_disease_monthly (month INT,district VARCHAR(20),cases INT); INSERT INTO infectious_disease_monthly (month,district,cases) VALUES (1,'East Delhi',100),(2,'East Delhi',120),(1,'South Delhi',150),(2,'South Delhi',180);
SELECT month, district, cases, LAG(cases, 1) OVER (PARTITION BY district ORDER BY month) AS prev_cases, cases - LAG(cases, 1) OVER (PARTITION BY district ORDER BY month) AS change FROM infectious_disease_monthly;
What is the total water consumption in the residential sector in Victoria?
CREATE TABLE residential_sector (id INT,state VARCHAR(20),water_consumption FLOAT); INSERT INTO residential_sector (id,state,water_consumption) VALUES (1,'Victoria',1200000000),(2,'Victoria',1300000000),(3,'Victoria',1400000000);
SELECT SUM(water_consumption) FROM residential_sector WHERE state = 'Victoria';
Delete users with no posts in the past month
CREATE TABLE users (id INT,name TEXT,last_post_at TIMESTAMP); INSERT INTO users (id,name,last_post_at) VALUES (1,'Alice','2022-02-15 10:00:00'); INSERT INTO users (id,name,last_post_at) VALUES (2,'Bob','2022-03-01 15:00:00');
DELETE FROM users WHERE last_post_at < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND last_post_at IS NOT NULL;
Insert a new record into the education table with an id of 101, topic of 'Biodiversity', and attendees of 25
CREATE TABLE education (id INT,topic VARCHAR(50),attendees INT);
INSERT INTO education (id, topic, attendees) VALUES (101, 'Biodiversity', 25);
What is the total number of mobile customers and the total data usage in GB for each region?
CREATE TABLE customers (id INT,type VARCHAR(10),region VARCHAR(10)); INSERT INTO customers (id,type,region) VALUES (1,'postpaid','Northeast'),(2,'prepaid','Northeast'),(3,'postpaid','Southeast'),(4,'prepaid','Southeast'); CREATE TABLE usage (customer_id INT,data_usage FLOAT); INSERT INTO usage (customer_id,data_usage) VALUES (1,3.5),(2,2.2),(3,4.7),(4,1.8);
SELECT customers.region, COUNT(customers.id) AS total_customers, SUM(usage.data_usage) AS total_data_usage FROM customers JOIN usage ON customers.id = usage.customer_id GROUP BY customers.region;
Which renewable energy projects have the highest installed capacity?
CREATE TABLE renewable_energy (country VARCHAR(50),project_type VARCHAR(50),installed_capacity INT); INSERT INTO renewable_energy (country,project_type,installed_capacity) VALUES ('USA','Wind',3000),('USA','Solar',5000),('Mexico','Wind',2000),('Mexico','Solar',4000);
SELECT project_type, MAX(installed_capacity) FROM renewable_energy;
What is the percentage of consumers aware of ethical fashion?
CREATE TABLE consumer_awareness (id INT,aware BOOLEAN); INSERT INTO consumer_awareness (id,aware) VALUES (1,TRUE),(2,FALSE),(3,TRUE),(4,TRUE),(5,FALSE);
SELECT (COUNT(*) FILTER (WHERE aware = TRUE)) * 100.0 / COUNT(*) FROM consumer_awareness;
Insert a new event into the 'events' table
CREATE TABLE events (id INT PRIMARY KEY,name VARCHAR(255),date DATE,location VARCHAR(255));
INSERT INTO events (id, name, date, location) VALUES (1, 'Community Meeting', '2023-03-22', 'City Hall');
What is the daily trading volume for the USDC stablecoin on the Stellar network?
CREATE TABLE stellar_usdc (transaction_id INT,volume DECIMAL,timestamp TIMESTAMP);
SELECT SUM(volume) FROM stellar_usdc WHERE timestamp >= NOW() - INTERVAL '1 day' GROUP BY DATE(timestamp);
What is the average mental health score of students per gender?
CREATE TABLE student_demographics (student_id INT,gender VARCHAR(10),mental_health_score INT);
SELECT gender, AVG(mental_health_score) FROM student_demographics GROUP BY gender;
Identify the event type with the highest average attendance and its average attendance
CREATE TABLE events (event_id INT,event_name VARCHAR(50),event_type VARCHAR(30),attendance INT); INSERT INTO events (event_id,event_name,event_type,attendance) VALUES (1,'Theater Play','Play',200),(2,'Art Exhibit','Exhibit',300),(3,'Music Festival','Play',400);
SELECT event_type, AVG(attendance) as avg_attendance FROM events GROUP BY event_type ORDER BY avg_attendance DESC LIMIT 1;
What is the minimum capacity of wind farms in Australia?
CREATE TABLE wind_farms (id INT PRIMARY KEY,country VARCHAR(50),name VARCHAR(50),capacity FLOAT); INSERT INTO wind_farms (id,country,name,capacity) VALUES (1,'Australia','Windfarm A',15.5),(2,'Australia','Windfarm B',25.2);
SELECT MIN(capacity) FROM wind_farms WHERE country = 'Australia';
How many patients participated in clinical trial 'CT001'?
CREATE TABLE clinical_trials (trial_id varchar(10),num_patients int); INSERT INTO clinical_trials (trial_id,num_patients) VALUES ('CT001',350);
SELECT num_patients FROM clinical_trials WHERE trial_id = 'CT001';
What is the number of companies founded by underrepresented minority groups in the renewable energy industry?
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,founders TEXT); INSERT INTO Companies (id,name,industry,founders) VALUES (1,'SolEnergia','Renewable Energy','Hispanic,Female'); INSERT INTO Companies (id,name,industry,founders) VALUES (2,'GreenTech','Renewable Energy','Asian,Female'); CREATE TABLE Underrepresented_Minorities (minority TEXT); INSERT INTO Underrepresented_Minorities (minority) VALUES ('Hispanic'); INSERT INTO Underrepresented_Minorities (minority) VALUES ('Black'); INSERT INTO Underrepresented_Minorities (minority) VALUES ('Native American');
SELECT COUNT(c.id) FROM Companies c JOIN Underrepresented_Minorities m ON c.founders LIKE CONCAT('%', m.minority, '%') WHERE c.industry = 'Renewable Energy';
What is the average age of patients diagnosed with eating disorders?
CREATE TABLE patient (patient_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),condition VARCHAR(50)); INSERT INTO patient (patient_id,name,age,gender,condition) VALUES (1,'Sophia Garcia',28,'Female','Anorexia Nervosa'),(2,'David Kim',40,'Male','Bipolar Disorder'),(3,'Emily Chen',33,'Female','Bulimia Nervosa');
SELECT AVG(age) FROM patient WHERE condition IN ('Anorexia Nervosa', 'Bulimia Nervosa');
What is the average speed of vessels in the Arctic Circle, grouped by their registration year?
CREATE TABLE vessels (id INT,name VARCHAR(255),type VARCHAR(255),speed DECIMAL(5,2),registration_year INT,latitude DECIMAL(9,6),longitude DECIMAL(9,6)); INSERT INTO vessels (id,name,type,speed,registration_year,latitude,longitude) VALUES (1,'VesselA','Cargo',15.2,2018,76.234544,168.879444);
SELECT registration_year, AVG(speed) as avg_speed FROM vessels WHERE latitude BETWEEN 66.5 AND 90.0 AND longitude BETWEEN -180.0 AND 180.0 GROUP BY registration_year;
Update the 'status' column to 'completed' for all projects with 'project_id' between 100 and 200 in the 'ai_projects' table
CREATE TABLE ai_projects (id INT PRIMARY KEY,project_name VARCHAR(50),project_id INT,status VARCHAR(20));
UPDATE ai_projects SET status = 'completed' WHERE project_id BETWEEN 100 AND 200;
For the 'project_materials' table, add a new row with the following information: project_id 1, material 'Concrete', quantity 100 and unit 'ton'.
CREATE TABLE project_materials (project_id INT,material VARCHAR(20),quantity INT,unit VARCHAR(10));
INSERT INTO project_materials (project_id, material, quantity, unit) VALUES (1, 'Concrete', 100, 'ton');
What is the difference in water usage between industrial and agricultural users in the state of Texas?
CREATE TABLE industrial_users (id INT,state VARCHAR(20),water_usage FLOAT); INSERT INTO industrial_users (id,state,water_usage) VALUES (1,'Texas',1000.5),(2,'Texas',1200.3),(3,'California',800.2); CREATE TABLE agricultural_users (id INT,state VARCHAR(20),water_usage FLOAT); INSERT INTO agricultural_users (id,state,water_usage) VALUES (1,'Texas',2000.1),(2,'Texas',2500.0),(3,'California',1500.2);
SELECT SUM(industrial_users.water_usage) - SUM(agricultural_users.water_usage) FROM industrial_users, agricultural_users WHERE industrial_users.state = agricultural_users.state AND industrial_users.state = 'Texas';
Delete all spacecrafts from the 'mars_rovers' table that were active prior to 2000
CREATE TABLE mars_rovers (id INT PRIMARY KEY,name VARCHAR(50),active_year INT,type VARCHAR(50)); INSERT INTO mars_rovers (id,name,active_year,type) VALUES (1,'Sojourner',1997,'rover'),(2,'Spirit',2004,'rover'),(3,'Opportunity',2004,'rover'),(4,'Curiosity',2012,'rover'),(5,'Perseverance',2021,'rover');
DELETE FROM mars_rovers WHERE active_year < 2000;
What is the percentage of total attendance at art exhibitions by age group?
CREATE TABLE art_exhibitions (id INT,exhibition_type VARCHAR(20),attendance INT,attendee_age INT); INSERT INTO art_exhibitions (id,exhibition_type,attendance,attendee_age) VALUES (1,'modern',500,25),(2,'classical',700,35),(3,'contemporary',800,45);
SELECT attendee_age, 100.0 * attendance / SUM(attendance) OVER () AS percentage FROM art_exhibitions GROUP BY attendee_age ORDER BY percentage DESC;
What are the total greenhouse gas emissions in the US and China?
CREATE TABLE emissions (id INT PRIMARY KEY,country VARCHAR(50),year INT,emissions FLOAT); INSERT INTO emissions (id,country,year,emissions) VALUES (1,'US',2015,5500000.0); INSERT INTO emissions (id,country,year,emissions) VALUES (2,'China',2016,10000000.0);
SELECT country, SUM(emissions) FROM emissions GROUP BY country HAVING country IN ('US', 'China');
What is the total length of all highways in Texas?
CREATE TABLE Highways (id INT,name VARCHAR(100),state VARCHAR(50),length FLOAT); INSERT INTO Highways (id,name,state,length) VALUES (1,'I-10','Texas',879),(2,'I-20','Texas',669),(3,'I-35','Texas',892);
SELECT SUM(length) FROM Highways WHERE state = 'Texas';
What is the average cost of military vehicles by type?
CREATE TABLE MilitaryVehicles (type TEXT,cost INTEGER); INSERT INTO MilitaryVehicles (type,cost) VALUES ('Tank',7000000),('Humvee',150000),('FighterJet',120000000);
SELECT type, AVG(cost) FROM MilitaryVehicles GROUP BY type;
What is the maximum exit valuation for startups founded by women over 40 in the EU?
CREATE TABLE founders(id INT,name VARCHAR(50),age INT,gender VARCHAR(10)); CREATE TABLE exits(startup_id INT,exit_valuation FLOAT); INSERT INTO founders VALUES (1,'FounderA',45,'Female'); INSERT INTO founders VALUES (2,'FounderB',35,'Female'); INSERT INTO founders VALUES (3,'FounderC',50,'Male'); INSERT INTO exits VALUES (1,25000000); INSERT INTO exits VALUES (2,30000000); INSERT INTO exits VALUES (3,15000000);
SELECT MAX(exit_valuation) FROM founders INNER JOIN exits ON founders.id = exits.startup_id WHERE age > 40 AND gender = 'Female' AND country LIKE 'EU%';
What is the maximum heart rate for users in each country, and which user achieved it?
CREATE TABLE Users (UserID INT,Name VARCHAR(50),Age INT,Gender VARCHAR(10),Country VARCHAR(50),HeartRate INT); INSERT INTO Users (UserID,Name,Age,Gender,Country,HeartRate) VALUES (1,'John Doe',30,'Male','USA',80),(2,'Jane Smith',25,'Female','Canada',75),(3,'Jean Dupont',35,'Male','France',90);
SELECT Country, MAX(HeartRate) as MaxHeartRate, Name FROM Users GROUP BY Country HAVING MAX(HeartRate) = HeartRate;
Add a new record to the 'water_conservation' table with an 'id' of 8, 'location' of 'Los Angeles', and 'savings' of 25
CREATE TABLE water_conservation (id INT PRIMARY KEY,location VARCHAR(20),savings INT);
INSERT INTO water_conservation (id, location, savings) VALUES (8, 'Los Angeles', 25);
What is the total quantity of item 'A01' in all warehouses?
CREATE TABLE inventory (item_code varchar(5),warehouse_id varchar(5),quantity int); INSERT INTO inventory (item_code,warehouse_id,quantity) VALUES ('A01','BRU',300),('A01','CDG',400),('A02','BRU',500);
SELECT SUM(quantity) FROM inventory WHERE item_code = 'A01';
What is the average income in urban areas of Canada in 2020?
CREATE TABLE urban_areas (id INT,name VARCHAR(50),is_urban BOOLEAN,country VARCHAR(50),income FLOAT,year INT); INSERT INTO urban_areas (id,name,is_urban,country,income,year) VALUES (1,'Vancouver',true,'Canada',60000,2020),(2,'Toronto',true,'Canada',65000,2020),(3,'Calgary',true,'Canada',70000,2020);
SELECT AVG(income) FROM urban_areas WHERE is_urban = true AND country = 'Canada' AND year = 2020;
What is the average production rate for each product, partitioned by month and ordered by the average production rate?
CREATE TABLE production (product_id INT,supplier_id INT,production_date DATE,production_rate INT); INSERT INTO production (product_id,supplier_id,production_date,production_rate) VALUES (1,1,'2022-02-01',500),(2,1,'2022-02-05',600);
SELECT product_id, DATE_TRUNC('month', production_date) AS month, AVG(production_rate) AS avg_production_rate, RANK() OVER (ORDER BY AVG(production_rate) DESC) AS ranking FROM production GROUP BY product_id, month ORDER BY avg_production_rate DESC;
Insert records for new members who joined in April 2022 with no workouts yet into the 'Workouts' table
CREATE TABLE Members (MemberID INT,MemberName VARCHAR(50),JoinDate DATETIME);
INSERT INTO Workouts (WorkoutID, MemberID, Duration, MembershipType) SELECT NULL, m.MemberID, 0, 'Premium' FROM (SELECT MemberID FROM Members WHERE MONTH(JoinDate) = 4 AND YEAR(JoinDate) = 2022 LIMIT 4) m WHERE NOT EXISTS (SELECT 1 FROM Workouts w WHERE w.MemberID = m.MemberID);
What is the minimum depth of all silver mines?
CREATE TABLE MineDepths (MineID INT,MineType VARCHAR(10),Depth INT); INSERT INTO MineDepths (MineID,MineType,Depth) VALUES (1,'Gold',1200),(2,'Silver',800),(3,'Gold',1500);
SELECT MineType, MIN(Depth) FROM MineDepths WHERE MineType = 'Silver' GROUP BY MineType;
List the membership status and join date for members who joined after 2020-01-01 and live in Texas or California.
CREATE TABLE members (id INT,name VARCHAR(50),membership_status VARCHAR(20),join_date DATE,state VARCHAR(20));
SELECT membership_status, join_date FROM members WHERE state IN ('Texas', 'California') AND join_date > '2020-01-01' ORDER BY join_date;
Find the bioprocess engineering projects led by 'Dr. Maria Rodriguez' that started in 2020.
CREATE TABLE bioprocess_engineering (id INT PRIMARY KEY,project_name VARCHAR(255),lead_scientist VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO bioprocess_engineering (id,project_name,lead_scientist,start_date,end_date) VALUES (1,'Protein Purification','John Doe','2020-01-01','2020-12-31'),(2,'Cell Culturing','Jane Smith','2019-01-01','2019-12-31'),(3,'Enzyme Production','Alice Johnson','2020-07-01',NULL),(4,'Gene Cloning','Dr. Maria Rodriguez','2020-04-01','2020-11-30');
SELECT project_name, lead_scientist FROM bioprocess_engineering WHERE lead_scientist = 'Dr. Maria Rodriguez' AND start_date >= '2020-01-01' AND start_date <= '2020-12-31';
Update the price of all shampoo products with the word 'natural' in their name to 12.99.
CREATE TABLE cosmetics (product VARCHAR(255),price DECIMAL(10,2)); CREATE VIEW shampoo_products AS SELECT * FROM cosmetics WHERE product_category = 'Shampoos' AND product_name LIKE '%natural%';
UPDATE cosmetics SET price = 12.99 WHERE product IN (SELECT product FROM shampoo_products);
What is the total carbon sequestration for each forest type in 2021?
CREATE TABLE forests (forest_type VARCHAR(255),year INT,carbon_sequestration INT); INSERT INTO forests (forest_type,year,carbon_sequestration) VALUES ('Temperate',2018,500),('Temperate',2019,550),('Temperate',2020,600),('Temperate',2021,650),('Boreal',2018,700),('Boreal',2019,750),('Boreal',2020,800),('Boreal',2021,825),('Tropical',2018,900),('Tropical',2019,950),('Tropical',2020,1000),('Tropical',2021,1075);
SELECT forest_type, SUM(carbon_sequestration) as total_carbon_sequestration FROM forests WHERE year = 2021 GROUP BY forest_type;
What is the number of electric vehicles sold in India by quarter?
CREATE TABLE electric_vehicle_sales (sale_id INT,sale_date DATE,vehicle_type VARCHAR(50)); INSERT INTO electric_vehicle_sales (sale_id,sale_date,vehicle_type) VALUES (1,'2021-01-01','car'),(2,'2021-02-01','motorcycle'),(3,'2021-03-01','car');
SELECT EXTRACT(QUARTER FROM sale_date) AS quarter, COUNT(DISTINCT sale_id) AS electric_vehicles_sold FROM electric_vehicle_sales WHERE vehicle_type LIKE '%electric%' GROUP BY quarter
What is the total labor cost for sustainable building projects in Austin, Texas in 2020?
CREATE TABLE labor_costs (project_id INT,project_type VARCHAR(20),city VARCHAR(20),year INT,cost FLOAT); INSERT INTO labor_costs (project_id,project_type,city,year,cost) VALUES (7,'Sustainable','Austin',2020,150000),(8,'Conventional','Austin',2019,120000),(9,'Sustainable','Dallas',2020,200000);
SELECT SUM(cost) FROM labor_costs WHERE project_type = 'Sustainable' AND city = 'Austin' AND year = 2020;
Get the number of peacekeeping operations per country per year.
CREATE TABLE peacekeeping_operations (id INT,country VARCHAR(255),year INT);
SELECT country, year, COUNT(*) as num_ops FROM peacekeeping_operations GROUP BY country, year ORDER BY year;
What was the total revenue for a specific genre's concert ticket sales in 2017?
CREATE TABLE Genre_Concerts_3 (year INT,genre VARCHAR(50),revenue FLOAT); INSERT INTO Genre_Concerts_3 (year,genre,revenue) VALUES (2016,'Pop',1000000),(2017,'Rock',1500000),(2018,'Hip Hop',800000),(2019,'Jazz',1200000),(2017,'Rock',1600000);
SELECT genre, SUM(revenue) FROM Genre_Concerts_3 WHERE year = 2017 GROUP BY genre;
How many vessels were involved in maritime accidents by country?
CREATE TABLE maritime_accidents (accident_id INT,vessel_id INT,country VARCHAR(100)); INSERT INTO maritime_accidents (accident_id,vessel_id,country) VALUES (1,1,'Canada'); INSERT INTO maritime_accidents (accident_id,vessel_id,country) VALUES (2,2,'Mexico');
SELECT country, COUNT(vessel_id) FROM maritime_accidents GROUP BY country;
What is the total number of emergency calls made in the "east" region in 2019, with a response time of less than 5 minutes?
CREATE TABLE emergency_calls (id INT,call_time TIMESTAMP,location VARCHAR(20));
SELECT COUNT(*) FROM emergency_calls WHERE location = 'east' AND EXTRACT(EPOCH FROM call_time - LAG(call_time) OVER (PARTITION BY location ORDER BY call_time)) / 60 < 5 AND EXTRACT(YEAR FROM call_time) = 2019;
What are the names of vessels that have visited ports in the Americas?
CREATE TABLE vessels (vessel_id INT,vessel_name TEXT); INSERT INTO vessels VALUES (1,'Vessel X'),(2,'Vessel Y'); CREATE TABLE port_visits (vessel_id INT,port_id INT); INSERT INTO port_visits VALUES (1,1),(1,2),(2,2);
SELECT DISTINCT vessels.vessel_name FROM vessels INNER JOIN port_visits ON vessels.vessel_id = port_visits.vessel_id INNER JOIN ports ON port_visits.port_id = ports.port_id WHERE ports.region = 'Americas';
How many unique users have streamed songs from artists who identify as female, in the last 30 days?
CREATE TABLE users (id INT,last_stream_date DATE); CREATE TABLE streams (user_id INT,song_id INT,artist_gender VARCHAR(10));
SELECT COUNT(DISTINCT users.id) FROM users INNER JOIN streams ON users.id = streams.user_id WHERE streams.artist_gender = 'female' AND users.last_stream_date >= NOW() - INTERVAL 30 DAY;
Find the Solar Power Plants with the highest energy generation (in MWh) installed in 2015 and 2016
CREATE TABLE solar_power_plants (id INT,year INT,owner VARCHAR(100),name VARCHAR(100),energy_generation_mwh FLOAT);
SELECT year, owner, name, energy_generation_mwh FROM solar_power_plants WHERE year IN (2015, 2016) ORDER BY energy_generation_mwh DESC LIMIT 2;
Find the number of co-ownership properties in California and Texas.
CREATE TABLE co_ownership_states (id INT,location VARCHAR(20)); INSERT INTO co_ownership_states (id,location) VALUES (1,'California'),(2,'California'),(3,'Texas');
SELECT location, COUNT(*) FROM co_ownership_states WHERE location IN ('California', 'Texas') GROUP BY location;
What is the maximum and minimum total transaction volume for digital assets in the Tron network?
CREATE TABLE if not exists tron_assets (asset_id INT,asset_name VARCHAR(255),total_txn_volume DECIMAL(18,2)); INSERT INTO tron_assets (asset_id,asset_name,total_txn_volume) VALUES (1,'TRX',1000000000),(2,'USDT',700000000),(3,'BTT',500000000),(4,'WIN',400000000),(5,'SUN',300000000),(6,'JST',200000000),(7,'BTC',150000000),(8,'ETH',120000000),(9,'LTC',100000000),(10,'DOT',80000000);
SELECT MAX(total_txn_volume) as max_volume, MIN(total_txn_volume) as min_volume FROM tron_assets;
Add a new sustainable sourcing practice for a menu item
CREATE TABLE sustainable_sourcing (item_id INT,sourcing_date DATE,sustainability_practice VARCHAR(255));
INSERT INTO sustainable_sourcing (item_id, sourcing_date, sustainability_practice) VALUES (345, '2022-04-01', 'Local Sourcing');
List the top 5 donors who have donated the most this year, along with their total donation amounts.
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationDate DATE,Amount DECIMAL(10,2));
SELECT DonorName, SUM(Amount) AS TotalDonated FROM Donors WHERE DonationDate >= DATEADD(year, -1, GETDATE()) GROUP BY DonorName ORDER BY TotalDonated DESC LIMIT 5;
How many autonomous vehicles are registered in California by year?
CREATE TABLE autonomous_vehicles (vehicle_id INT,registration_date TIMESTAMP,vehicle_type VARCHAR(50),state VARCHAR(50));
SELECT YEAR(registration_date) as year, COUNT(*) as num_vehicles FROM autonomous_vehicles WHERE state = 'California' GROUP BY year;
What is the total amount of funding for peacekeeping operations in the 'Funding' table, for the 'Americas' and 'Oceania' regions combined?
CREATE TABLE Funding (id INT,operation VARCHAR(255),amount DECIMAL(10,2));
SELECT SUM(amount) FROM Funding WHERE operation IN ('Americas', 'Oceania') AND type = 'Peacekeeping';
What is the total amount of food aid distributed in each region in 2020?
CREATE TABLE food_aid (id INT,name TEXT,region TEXT,distribution_date DATE,quantity INT); INSERT INTO food_aid (id,name,region,distribution_date,quantity) VALUES (1,'Food Aid 1','Asia','2020-01-01',100),(2,'Food Aid 2','Asia','2020-02-01',200),(3,'Food Aid 3','Africa','2020-03-01',300),(4,'Food Aid 4','Africa','2020-04-01',400);
SELECT region, SUM(quantity) as total_quantity FROM food_aid WHERE distribution_date >= '2020-01-01' AND distribution_date < '2021-01-01' GROUP BY region;
Delete all fairness audit records for models with a safety score below 85.00.
CREATE TABLE fairness_audits (audit_id INT,model_id INT,fairness_score DECIMAL(5,2)); CREATE TABLE models (model_id INT,model_name VARCHAR(50),model_type VARCHAR(50),country VARCHAR(50),safety_score DECIMAL(5,2)); INSERT INTO models (model_id,model_name,model_type,country,safety_score) VALUES (1,'ModelA','Recommender','USA',85.00),(2,'ModelB','Classifier','Japan',92.50),(3,'ModelC','Generative','USA',87.50),(4,'ModelD','Recommender','Japan',90.00),(5,'ModelE','Classifier','USA',88.50); INSERT INTO fairness_audits (audit_id,model_id,fairness_score) VALUES (1,1,0.90),(2,2,0.95),(3,3,0.88),(4,4,0.92),(5,5,0.91);
DELETE FROM fairness_audits WHERE model_id IN (SELECT model_id FROM models WHERE safety_score < 85.00);