instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Find the number of unique investors who have invested in both female and male-founded startups in the tech sector.
CREATE TABLE Investors (id INT,name VARCHAR(100)); CREATE TABLE Investments (investor_id INT,startup_id INT,sector VARCHAR(50),founder_gender VARCHAR(10)); INSERT INTO Investors (id,name) VALUES (1,'Accel'),(2,'Sequoia'),(3,'Kleiner Perkins'); INSERT INTO Investments (investor_id,startup_id,sector,founder_gender) VALUE...
SELECT COUNT(DISTINCT investor_id) FROM Investments i1 JOIN Investments i2 ON i1.investor_id = i2.investor_id WHERE i1.sector = 'Tech' AND i1.founder_gender = 'Female' AND i2.sector = 'Tech' AND i2.founder_gender = 'Male' AND i1.startup_id <> i2.startup_id;
What is the average crop yield for farmers in the 'rural_development' database, grouped by the region they are located in?
CREATE TABLE farmers (farmer_id INT,name VARCHAR(50),region VARCHAR(50),crop_yield INT); INSERT INTO farmers (farmer_id,name,region,crop_yield) VALUES (1,'John Doe','Midwest',120),(2,'Jane Smith','Southeast',150),(3,'Alice Johnson','Northeast',180);
SELECT region, AVG(crop_yield) FROM farmers GROUP BY region;
How many patients have been diagnosed with diabetes in each rural county?
CREATE TABLE patients (id INT,county VARCHAR(20),diagnosis VARCHAR(20)); INSERT INTO patients (id,county,diagnosis) VALUES (1,'Appalachia','diabetes'); INSERT INTO patients (id,county,diagnosis) VALUES (2,'Ozarks','diabetes'); INSERT INTO patients (id,county,diagnosis) VALUES (3,'Mississippi Delta','diabetes'); INSERT ...
SELECT county, COUNT(*) FROM patients WHERE diagnosis = 'diabetes' GROUP BY county;
List the top 3 cultural heritage sites in Barcelona by visitor count.
CREATE TABLE cultural_sites_spain (site_id INT,name TEXT,city TEXT,visitors INT); INSERT INTO cultural_sites_spain (site_id,name,city,visitors) VALUES (1,'Sagrada Familia','Barcelona',4500000),(2,'Park Guell','Barcelona',4000000),(3,'Picasso Museum','Barcelona',3500000);
SELECT name, visitors FROM cultural_sites_spain WHERE city = 'Barcelona' ORDER BY visitors DESC LIMIT 3;
What is the average speed of vessels that arrived in the USA ports?
CREATE TABLE VesselArrivals (ID INT,VesselName VARCHAR(50),ArrivalPort VARCHAR(50),ArrivalDate DATE,AverageSpeed DECIMAL(5,2)); INSERT INTO VesselArrivals (ID,VesselName,ArrivalPort,ArrivalDate,AverageSpeed) VALUES (1,'Test Vessel 1','New York','2022-01-01',15.5),(2,'Test Vessel 2','Los Angeles','2022-01-02',20.3);
SELECT AVG(AverageSpeed) FROM VesselArrivals WHERE ArrivalPort LIKE 'USA%';
What was the revenue for each store location in Australia for the month of November 2021?
CREATE TABLE sales (store_location VARCHAR(50),sale_date DATE,revenue DECIMAL(10,2));
SELECT store_location, SUM(revenue) as revenue FROM sales WHERE country = 'Australia' AND sale_date BETWEEN '2021-11-01' AND '2021-11-30' GROUP BY store_location;
What is the number of students enrolled in each open pedagogy course?
CREATE TABLE courses (course_id INT,course_name TEXT,course_type TEXT); CREATE TABLE enrollment (student_id INT,course_id INT); INSERT INTO courses (course_id,course_name,course_type) VALUES (1001,'Introduction to Open Pedagogy','open'),(1002,'Data Science for All','traditional'); INSERT INTO enrollment (student_id,cou...
SELECT c.course_name, COUNT(e.student_id) as num_students FROM courses c INNER JOIN enrollment e ON c.course_id = e.course_id WHERE c.course_type = 'open' GROUP BY c.course_name;
What is the total number of electric vehicles sold by manufacturer 'XYZ'?
CREATE TABLE sales_data (manufacturer VARCHAR(10),vehicle_type VARCHAR(10),quantity INT);
SELECT manufacturer, SUM(quantity) FROM sales_data WHERE vehicle_type = 'Electric' AND manufacturer = 'XYZ' GROUP BY manufacturer;
Which cities have the highest and lowest housing affordability scores?
CREATE TABLE housing_affordability (id INT,city VARCHAR(20),score FLOAT); INSERT INTO housing_affordability (id,city,score) VALUES (1,'SF',45.2),(2,'NYC',38.6),(3,'LA',51.1),(4,'Vancouver',60.0),(5,'Montreal',25.5),(6,'Toronto',32.3);
SELECT city, score FROM housing_affordability ORDER BY score DESC, city LIMIT 1;
What is the total revenue for natural nail polish products?
CREATE TABLE nail_polish_sales (product_type VARCHAR(20),is_natural BOOLEAN,revenue DECIMAL(10,2)); INSERT INTO nail_polish_sales (product_type,is_natural,revenue) VALUES ('Nail Polish',true,2000),('Nail Polish',false,3000),('Top Coat',true,1500),('Base Coat',false,1000);
SELECT SUM(revenue) FROM nail_polish_sales WHERE product_type = 'Nail Polish' AND is_natural = true;
Find the top 5 organizations with the most donations.
CREATE TABLE donation_summary (org_id INT,total_donations INT); INSERT INTO donation_summary (org_id,total_donations) SELECT donation.org_id,COUNT(*) FROM donation GROUP BY donation.org_id;
SELECT org_id, total_donations FROM donation_summary ORDER BY total_donations DESC LIMIT 5;
How many traditional arts and crafts workshops have been held in each region?
CREATE TABLE workshops(id INT,region TEXT,workshop_count INT); INSERT INTO workshops VALUES (1,'North',5),(2,'South',3),(3,'East',4),(4,'West',6);
SELECT region, workshop_count FROM workshops;
What is the average research grant amount awarded to female professors in the Computer Science department?
CREATE TABLE department (name VARCHAR(255),head VARCHAR(255));CREATE TABLE professor (name VARCHAR(255),gender VARCHAR(255),department_id INT,grant_amount DECIMAL(10,2));
SELECT AVG(grant_amount) FROM professor WHERE gender = 'Female' AND department_id IN (SELECT id FROM department WHERE name = 'Computer Science');
Count the number of platforms installed in the Gulf of Mexico each year since 2015.
CREATE TABLE gulf_of_mexico_platforms (platform_id INT,platform_name VARCHAR(50),install_date DATE); INSERT INTO gulf_of_mexico_platforms (platform_id,platform_name,install_date) VALUES (1,'Gulf of Mexico Platform A','2015-01-01'),(2,'Gulf of Mexico Platform B','2016-01-01'),(3,'Gulf of Mexico Platform C','2017-01-01')...
SELECT YEAR(install_date) AS Year, COUNT(*) AS Number_of_platforms FROM gulf_of_mexico_platforms GROUP BY YEAR(install_date);
What is the total quantity of each material used in dam projects?
CREATE TABLE dam_materials (id INT,project_id INT,dam_name VARCHAR(255),material VARCHAR(255),quantity INT);
SELECT dam_name, material, SUM(quantity) as total_quantity FROM dam_materials WHERE material IN ('Concrete', 'Steel', 'Earth') GROUP BY dam_name, material;
How many vehicles were in each maintenance category on a specific date in the 'vehicle_maintenance' table?
CREATE TABLE vehicle_maintenance (vehicle_id INT,category VARCHAR(255),maintenance_date DATE);
SELECT category, COUNT(*) as num_vehicles FROM vehicle_maintenance WHERE maintenance_date = '2022-01-01' GROUP BY category;
Insert new records of clients who have invested in socially responsible funds.
CREATE TABLE clients (id INT,name VARCHAR(255)); INSERT INTO clients (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); CREATE TABLE investments (id INT,client_id INT,fund_type VARCHAR(255),amount DECIMAL(10,2));
INSERT INTO clients (id, name) VALUES (3, 'Alice Johnson'), (4, 'Bob Brown'); INSERT INTO investments (id, client_id, fund_type, amount) VALUES (1, 3, 'Socially Responsible', 5000), (2, 4, 'Socially Responsible', 6000);
What is the maximum water usage in a single day for the state of New York?
CREATE TABLE daily_water_usage (id INT,state VARCHAR(20),water_usage FLOAT); INSERT INTO daily_water_usage (id,state,water_usage) VALUES (1,'New York',35000),(2,'Texas',40000),(3,'New York',37000);
SELECT MAX(water_usage) FROM daily_water_usage WHERE state = 'New York'
What is the average feed conversion ratio for each species in FeedLot1?
CREATE TABLE FeedLot1 (species VARCHAR(20),feed_conversion_ratio FLOAT); INSERT INTO FeedLot1 (species,feed_conversion_ratio) VALUES ('Cod',1.5),('Haddock',1.8),('Pollock',1.7);
SELECT species, AVG(feed_conversion_ratio) FROM FeedLot1 GROUP BY species;
What is the average monthly water consumption per location in 2021?
CREATE TABLE water_usage_2021 (id INT,location VARCHAR(50),year INT,monthly_consumption FLOAT); INSERT INTO water_usage_2021 (id,location,year,monthly_consumption) VALUES (1,'New York',2021,12000);
SELECT location, AVG(monthly_consumption) FROM water_usage_2021 WHERE year = 2021 GROUP BY location;
Drop the view 'soldier_details'
CREATE VIEW soldier_details AS SELECT id,name,branch FROM soldiers;
DROP VIEW soldier_details;
What is the total number of disability accommodations requested and approved by type and month?
CREATE TABLE Accommodation_Data (Request_ID INT,Request_Date DATE,Accommodation_Type VARCHAR(50),Request_Status VARCHAR(10));
SELECT DATE_PART('month', Request_Date) as Month, Accommodation_Type, COUNT(*) as Total_Requests FROM Accommodation_Data WHERE Request_Status = 'Approved' GROUP BY Month, Accommodation_Type;
Which state has the highest energy generation from hydro power?
CREATE TABLE state_energy (id INT,state TEXT,source TEXT,generation FLOAT); INSERT INTO state_energy (id,state,source,generation) VALUES (1,'Washington','hydro',98765.4),(2,'Oregon','hydro',34567.8);
SELECT state, MAX(generation) FROM state_energy WHERE source = 'hydro' GROUP BY state;
What is the market access strategy for the drug 'Curely' in South America?
CREATE TABLE market_access_2 (drug_name TEXT,strategy TEXT,region TEXT); INSERT INTO market_access_2 (drug_name,strategy,region) VALUES ('Drexo','Direct to consumer','Brazil'),('Curely','Limited distribution','Argentina');
SELECT strategy FROM market_access_2 WHERE drug_name = 'Curely' AND region = 'South America';
What is the total weight of vegetables in the inventory?
CREATE TABLE inventory (item TEXT,weight INT); INSERT INTO inventory (item,weight) VALUES ('Carrots',1200),('Potatoes',1500),('Lettuce',800);
SELECT SUM(weight) FROM inventory WHERE item LIKE 'Carrots%' OR item LIKE 'Potatoes%' OR item LIKE 'Lettuce%';
How many virtual tours were engaged in 'July 2021'?
CREATE TABLE virtual_tours (tour_date DATE); INSERT INTO virtual_tours (tour_date) VALUES ('2021-07-01'),('2021-07-03'),('2021-06-02');
SELECT COUNT(*) FROM virtual_tours WHERE EXTRACT(MONTH FROM tour_date) = 7 AND EXTRACT(YEAR FROM tour_date) = 2021;
Show the total production cost of ethical garments, grouped by garment type.
CREATE TABLE garment_type_production_cost (id INT,garment_type VARCHAR(255),production_cost DECIMAL(10,2));
SELECT garment_type, SUM(production_cost) AS total_cost FROM garment_type_production_cost GROUP BY garment_type;
What is the maximum satisfaction rating for VR games in the 'Education' category?
CREATE TABLE GameSatisfaction (game VARCHAR(100),category VARCHAR(50),satisfaction FLOAT);
SELECT MAX(satisfaction) FROM GameSatisfaction WHERE category = 'Education';
Show the number of climate finance projects per year in the Middle East.
CREATE TABLE finance_year (project_name TEXT,year INTEGER);INSERT INTO finance_year (project_name,year) VALUES ('Renewable Energy',2018),('Climate Resilience',2019);
SELECT year, COUNT(project_name) as num_projects FROM finance_year WHERE region = 'Middle East' GROUP BY year;
What is the total quantity of sustainable materials used by manufacturers located in the United States or Canada?
CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50),Location VARCHAR(50)); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName,Location) VALUES (1,'Manufacturer A','United States'),(2,'Manufacturer B','Canada'); CREATE TABLE Materials (MaterialID INT,MaterialName VARCHAR(50),Type VARCHAR(...
SELECT SUM(Quantity) FROM ManufacturerMaterials JOIN Materials ON ManufacturerMaterials.MaterialID = Materials.MaterialID WHERE Type = 'Sustainable' AND Manufacturers.Location IN ('United States', 'Canada');
what is the total number of animals in the 'animal_population' table that are not endangered?
CREATE TABLE animal_population (species VARCHAR(50),population INT,endangered BOOLEAN); INSERT INTO animal_population (species,population,endangered) VALUES ('Tiger',200,TRUE),('Lion',300,FALSE),('Elephant',400,FALSE);
SELECT SUM(population) FROM animal_population WHERE endangered = FALSE;
What is the total donation amount to climate change mitigation causes by donors from Europe in 2020?
CREATE TABLE donors (donor_id INT,donor_name TEXT,donation_amount FLOAT,cause TEXT,donation_date DATE,donor_country TEXT);
SELECT SUM(donation_amount) FROM donors WHERE cause = 'Climate Change Mitigation' AND donor_country LIKE 'Europe%' AND donation_date BETWEEN '2020-01-01' AND '2020-12-31';
What is the total number of containers handled by each port?
CREATE TABLE ports (port_id INT,port_name VARCHAR(50),total_containers INT); INSERT INTO ports VALUES (1,'PortA',5000),(2,'PortB',7000),(3,'PortC',8000);
SELECT port_name, SUM(total_containers) FROM ports GROUP BY port_name;
What is the total number of public hospitals and healthcare centers in each territory?
CREATE TABLE Territory (Id INT,Name VARCHAR(50),HospitalCount INT,HealthcareCenterCount INT); INSERT INTO Territory (Id,Name,HospitalCount,HealthcareCenterCount) VALUES (1,'TerritoryA',5,10); INSERT INTO Territory (Id,Name,HospitalCount,HealthcareCenterCount) VALUES (2,'TerritoryB',8,12);
SELECT Name, SUM(HospitalCount) AS TotalHospitals, SUM(HealthcareCenterCount) AS TotalHealthcareCenters FROM Territory GROUP BY Name;
What is the total revenue generated by cultural events, in the past three years, broken down by event category and country?
CREATE TABLE Events (id INT,date DATE,country VARCHAR(50),event_category VARCHAR(50),revenue DECIMAL(10,2)); INSERT INTO Events (id,date,country,event_category,revenue) VALUES (1,'2019-01-01','USA','Festival',5000),(2,'2020-01-01','Canada','Parade',7000);
SELECT e.event_category, e.country, SUM(e.revenue) AS revenue FROM Events e WHERE e.date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) AND e.event_category = 'Cultural' GROUP BY e.event_category, e.country;
Which states have the highest energy efficiency scores in 'StateEfficiency' table?
CREATE TABLE StateEfficiency (state TEXT,energy_efficiency_score INT);
SELECT state, energy_efficiency_score FROM StateEfficiency ORDER BY energy_efficiency_score DESC LIMIT 5;
What is the average property tax for properties in the table 'co_ownership' that are located in the city of Chicago?
CREATE TABLE co_ownership (id INT,property_tax FLOAT,city VARCHAR(20)); INSERT INTO co_ownership (id,property_tax,city) VALUES (1,5000,'Chicago'),(2,7000,'New York'),(3,3000,'Los Angeles');
SELECT AVG(property_tax) FROM co_ownership WHERE city = 'Chicago';
Who is the community member with the second-highest engagement in language preservation?
CREATE TABLE community_members (id INT,name TEXT,engagement INT,language TEXT); INSERT INTO community_members (id,name,engagement,language) VALUES (1,'Member A',5000,'Language1'),(2,'Member B',3000,'Language2'),(3,'Member C',7000,'Language3'),(4,'Member D',6000,'Language1'),(5,'Member E',4000,'Language3');
SELECT name FROM (SELECT name, engagement, DENSE_RANK() OVER (ORDER BY engagement DESC) AS rank FROM community_members) WHERE rank = 2
What was the minimum price per gram for Indica strains in Texas in 2021?
CREATE TABLE prices (id INT,state VARCHAR(50),year INT,strain_type VARCHAR(50),price FLOAT); INSERT INTO prices (id,state,year,strain_type,price) VALUES (1,'Texas',2021,'Indica',11.0),(2,'Texas',2021,'Sativa',13.0),(3,'California',2021,'Hybrid',12.0);
SELECT MIN(price) FROM prices WHERE state = 'Texas' AND year = 2021 AND strain_type = 'Indica';
Which defense projects have timelines that overlap with project X?
CREATE TABLE defense_projects (id INT,project_name VARCHAR,start_date DATE,end_date DATE);
SELECT project_name FROM defense_projects WHERE start_date < (SELECT end_date FROM defense_projects WHERE project_name = 'Project X') AND end_date > (SELECT start_date FROM defense_projects WHERE project_name = 'Project X');
What is the percentage of students who have not completed lifelong learning programs?
CREATE TABLE students (student_id INT,completed_llp BOOLEAN); INSERT INTO students VALUES (1,TRUE); INSERT INTO students VALUES (2,FALSE); INSERT INTO students VALUES (3,TRUE); INSERT INTO students VALUES (4,TRUE);
SELECT 100.0 * AVG(CASE WHEN NOT completed_llp THEN 1 ELSE 0 END) as percentage FROM students;
Determine the ratio of rental listings to sale listings for each neighborhood in Austin, Texas.
CREATE TABLE neighborhoods (name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),country VARCHAR(255),PRIMARY KEY (name)); INSERT INTO neighborhoods (name,city,state,country) VALUES ('East Austin','Austin','TX','USA');
SELECT name, COUNT(*) FILTER (WHERE listing_type = 'Rental') * 1.0 / COUNT(*) FILTER (WHERE listing_type = 'Sale') as rental_to_sale_ratio FROM real_estate_listings WHERE city = 'Austin' GROUP BY name;
What is the average speed of vessels that departed from the Port of Oakland in the past month?
CREATE TABLE VesselPerformance (Id INT,VesselName VARCHAR(50),DeparturePort VARCHAR(50),DepartureDate DATETIME,AverageSpeed DECIMAL(5,2));
SELECT AVG(AverageSpeed) FROM VesselPerformance WHERE DeparturePort = 'Port of Oakland' AND DepartureDate >= DATEADD(MONTH, -1, GETDATE());
What is the total fare collected on each route yesterday?
CREATE TABLE Routes (RouteID int,RouteName varchar(50)); INSERT INTO Routes VALUES (1,'Green Line'); INSERT INTO Routes VALUES (2,'Red Line'); CREATE TABLE Fares (FareID int,RouteID int,FareAmount decimal(5,2),PaymentDate date); INSERT INTO Fares VALUES (1,1,2.50,'2022-03-25'); INSERT INTO Fares VALUES (2,1,3.00,'2022-...
SELECT Routes.RouteName, SUM(Fares.FareAmount) as TotalFare FROM Routes INNER JOIN Fares ON Routes.RouteID = Fares.RouteID WHERE Fares.PaymentDate = DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY Routes.RouteName;
What is the maximum depth of the Pacific Ocean?
CREATE TABLE ocean_depths (ocean_name TEXT,max_depth REAL); INSERT INTO ocean_depths (ocean_name,max_depth) VALUES ('Pacific Ocean',10994.0),('Atlantic Ocean',8605.0);
SELECT max_depth FROM ocean_depths WHERE ocean_name = 'Pacific Ocean';
What is the total number of employees who have completed training programs in the IT and Marketing departments?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),completed_training BOOLEAN); INSERT INTO employees (id,name,department,completed_training) VALUES (1,'John Doe','IT',TRUE),(2,'Jane Smith','Marketing',FALSE),(3,'Mike Johnson','IT',TRUE),(4,'Sara Connor','Marketing',TRUE);
SELECT COUNT(*) FROM employees WHERE department IN ('IT', 'Marketing') AND completed_training = TRUE;
What is the maximum yield for each crop type in the 'Agroecology' schema?
CREATE SCHEMA Agroecology; CREATE TABLE crop_yields_max (crop_type TEXT,yield NUMERIC) IN Agroecology; INSERT INTO crop_yields_max (crop_type,yield) VALUES ('Wheat',14500),('Rice',18500),('Corn',26000),('Soybeans',17000);
SELECT crop_type, MAX(yield) as max_yield FROM Agroecology.crop_yields_max GROUP BY crop_type;
Delete records of artists who don't have any traditional art skills
CREATE TABLE artists (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO artists (id,name,country) VALUES (1,'John','USA'),(2,'Pablo','Mexico'); CREATE TABLE skills (id INT,artist_id INT,art_type VARCHAR(50)); INSERT INTO skills (id,artist_id,art_type) VALUES (1,1,'Painting'),(2,2,'Sculpting')
DELETE FROM artists WHERE id NOT IN (SELECT artist_id FROM skills)
What is the number of circular economy initiatives by city in Nigeria in 2020?
CREATE TABLE circular_economy (city VARCHAR(20),year INT,initiatives INT); INSERT INTO circular_economy (city,year,initiatives) VALUES ('Lagos',2020,10),('Abuja',2020,8),('Kano',2020,6),('Ibadan',2020,7),('Port Harcourt',2020,9);
SELECT city, SUM(initiatives) as total_initiatives FROM circular_economy WHERE year = 2020 GROUP BY city;
Show the total cost and total savings for each smart city initiative, for projects in Tokyo.
CREATE TABLE SmartCityInitiatives (InitiativeID INT,InitiativeName VARCHAR(50));CREATE TABLE SmartCityCosts (CostID INT,InitiativeID INT,Cost FLOAT,CityID INT);CREATE TABLE SmartCitySavings (SavingsID INT,InitiativeID INT,Savings FLOAT,CityID INT);
SELECT SmartCityInitiatives.InitiativeName, SUM(SmartCityCosts.Cost) AS TotalCost, SUM(SmartCitySavings.Savings) AS TotalSavings FROM SmartCityInitiatives INNER JOIN SmartCityCosts ON SmartCityInitiatives.InitiativeID = SmartCityCosts.InitiativeID INNER JOIN SmartCitySavings ON SmartCityInitiatives.InitiativeID = Smart...
How many unloading operations were performed in Nigeria?
CREATE TABLE ports (port_id INT,port_name VARCHAR(50),country VARCHAR(50)); INSERT INTO ports VALUES (1,'Lagos','Nigeria'); CREATE TABLE cargo_handling (handling_id INT,port_id INT,operation_type VARCHAR(50),operation_date DATE); INSERT INTO cargo_handling VALUES (1,1,'loading','2021-01-01'); INSERT INTO cargo_handling...
SELECT COUNT(*) FROM cargo_handling WHERE port_id IN (SELECT port_id FROM ports WHERE country = 'Nigeria') AND operation_type = 'unloading';
Calculate the total CO2 emissions savings (in metric tons) of renewable projects in California and New York
CREATE TABLE project (id INT,name TEXT,state TEXT,type TEXT,co2_savings INT); INSERT INTO project (id,name,state,type,co2_savings) VALUES (33,'California Wind','California','Wind',87654),(34,'New York Solar','New York','Solar',34567),(35,'California Solar','California','Solar',98765),(36,'New York Wind','New York','Win...
SELECT SUM(co2_savings) FROM project WHERE (state = 'California' OR state = 'New York') AND type IN ('Wind', 'Solar');
What is the total attendance by age group for a specific event in 2023?
CREATE SCHEMA events; CREATE TABLE events (event_id INT,event_name VARCHAR(255),event_date DATE,attendee_age INT,attendee_id INT); INSERT INTO events (event_id,event_name,event_date,attendee_age,attendee_id) VALUES (1,'Festival','2023-06-10',30,1001),(2,'Conference','2023-07-12',25,1002),(3,'Workshop','2023-08-15',45,1...
SELECT attendee_age, COUNT(DISTINCT attendee_id) as total_attendance FROM events WHERE event_date = '2023-06-10' GROUP BY attendee_age;
What is the maximum 'habitat_area' (in square kilometers) for the 'habitat_preservation' table?
CREATE TABLE habitat_preservation(id INT,habitat_name VARCHAR(50),habitat_area FLOAT); INSERT INTO habitat_preservation(id,habitat_name,habitat_area) VALUES (1,'Rainforest',10000),(2,'Mangrove Forest',1200),(3,'Coral Reef',300);
SELECT MAX(habitat_area) FROM habitat_preservation;
What is the maximum altitude (in km) of any satellite in a Low Earth Orbit (LEO)?
CREATE TABLE satellite_leo (id INT,satellite_id VARCHAR(50),altitude FLOAT,orbit_type VARCHAR(20));
SELECT MAX(altitude) FROM satellite_leo WHERE orbit_type = 'LEO';
Insert a new record into the 'artists' table for a new artist named 'Mx. Painter' with a 'gender' of 'Non-binary' and 'artist_id' of 4.
CREATE TABLE artists (artist_id INT,name VARCHAR(255),gender VARCHAR(64));
INSERT INTO artists (artist_id, name, gender) VALUES (4, 'Mx. Painter', 'Non-binary');
Get the average popularity for fashion trends.
CREATE TABLE FASHION_TRENDS (trend_id INT PRIMARY KEY,trend_name VARCHAR(50),popularity INT); INSERT INTO FASHION_TRENDS (trend_id,trend_name,popularity) VALUES (1,'TrendA',1000),(2,'TrendB',800),(3,'TrendC',1200),(4,'TrendD',1500);
SELECT AVG(popularity) FROM FASHION_TRENDS;
How many wells were drilled in the Orinoco Belt each year?
CREATE TABLE drilled_wells_orinoco (well_id INT,drilling_date DATE,location VARCHAR(20)); INSERT INTO drilled_wells_orinoco (well_id,drilling_date,location) VALUES (1,'2019-01-01','Orinoco Belt'); INSERT INTO drilled_wells_orinoco (well_id,drilling_date,location) VALUES (2,'2020-01-01','Orinoco Belt');
SELECT location, EXTRACT(YEAR FROM drilling_date) as year, COUNT(*) as wells_drilled FROM drilled_wells_orinoco WHERE location = 'Orinoco Belt' GROUP BY location, year ORDER BY year;
Who are the top 3 clients with the highest total assets value as of 2022-06-30?
CREATE TABLE clients (client_id INT,name VARCHAR(50),total_assets DECIMAL(10,2)); INSERT INTO clients (client_id,name,total_assets) VALUES (1,'Rajesh Patel',300000.00),(2,'Sarah Lee',450000.00),(3,'Carlos Alvarez',280000.00),(4,'Emily Wong',500000.00);
SELECT name, SUM(total_assets) as total_assets FROM clients WHERE DATE(client_timestamp) = '2022-06-30' GROUP BY name ORDER BY total_assets DESC LIMIT 3;
What is the average CO2 emissions for 'Shirt' production across factories in 'Bangladesh' and 'Vietnam'?
CREATE TABLE factories (factory_id INT,factory_name VARCHAR(20),country VARCHAR(20)); CREATE TABLE production (production_id INT,product_type VARCHAR(20),factory_id INT,co2_emissions FLOAT); INSERT INTO factories (factory_id,factory_name,country) VALUES (1,'Factory1','Bangladesh'),(2,'Factory2','Vietnam'),(3,'Factory3'...
SELECT AVG(co2_emissions) FROM production JOIN factories ON production.factory_id = factories.factory_id WHERE factories.country IN ('Bangladesh', 'Vietnam') AND product_type = 'Shirt';
List all unique algorithms used in AI safety research.
CREATE TABLE algorithms (id INT,name TEXT); INSERT INTO algorithms (id,name) VALUES (1,'Alg1'),(2,'Alg2'),(3,'Alg3'),(4,'Alg4'),(5,'Alg5'); CREATE TABLE safety_research (id INT,algorithm_id INT,name TEXT); INSERT INTO safety_research (id,algorithm_id,name) VALUES (1,1,'SafetyRes1'),(2,2,'SafetyRes2'),(3,3,'SafetyRes3')...
SELECT DISTINCT algorithms.name FROM algorithms INNER JOIN safety_research ON algorithms.id = safety_research.algorithm_id;
List the top 5 expensive military equipment maintenance costs worldwide.
CREATE TABLE military_equipment (id INT,country VARCHAR(50),cost FLOAT); INSERT INTO military_equipment (id,country,cost) VALUES (1,'USA',1500000); INSERT INTO military_equipment (id,country,cost) VALUES (2,'Germany',2000000); INSERT INTO military_equipment (id,country,cost) VALUES (3,'Canada',1200000); INSERT INTO mil...
SELECT country, cost FROM military_equipment ORDER BY cost DESC LIMIT 5;
What is the total volume of water used for irrigation in the state of Maharashtra, India in the year 2020?
CREATE TABLE maharashtra_irrigation (year INT,irrigation_volume INT); INSERT INTO maharashtra_irrigation (year,irrigation_volume) VALUES (2020,2000000);
SELECT SUM(maharashtra_irrigation.irrigation_volume) as total_irrigation_volume FROM maharashtra_irrigation WHERE maharashtra_irrigation.year = 2020;
List the mental health treatment approaches with the most associated patient outcomes in Europe.
CREATE TABLE european_outcomes (id INT,approach TEXT,outcome TEXT,region TEXT); INSERT INTO european_outcomes (id,approach,outcome,region) VALUES (1,'CBT','Improved','Europe'),(2,'DBT','Improved','Europe'),(3,'EMDR','Improved','Europe'),(4,'Medication','Improved','Europe'),(5,'Meditation','Improved','Europe');
SELECT approach, COUNT(*) as num_outcomes FROM european_outcomes WHERE region = 'Europe' GROUP BY approach ORDER BY num_outcomes DESC;
What was the total amount donated by new donors in Q3 2023?
CREATE TABLE donors (donor_id INT,first_donation_date DATE); INSERT INTO donors (donor_id,first_donation_date) VALUES (1,'2023-07-03'),(2,'2023-07-15'),(3,'2023-08-01'),(4,'2023-09-05'),(5,'2023-09-17'); CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount DECIMAL,donation_date DATE); INSERT INTO donati...
SELECT SUM(d.donation_amount) as total_donated FROM donations d JOIN donors don ON d.donor_id = don.donor_id WHERE d.donation_date BETWEEN '2023-07-01' AND '2023-09-30' AND don.first_donation_date BETWEEN '2023-07-01' AND '2023-09-30';
Calculate program budget by quartile
CREATE TABLE Programs (Id INT,ProgramName VARCHAR(50),Budget DECIMAL(10,2),StartDate DATE,EndDate DATE); INSERT INTO Programs (Id,ProgramName,Budget,StartDate,EndDate) VALUES (1,'Education',10000.00,'2021-01-01','2021-12-31'),(2,'Feeding',12000.00,'2021-01-01','2021-12-31'),(3,'Arts',7000.00,'2022-01-01','2022-12-31'),...
SELECT ProgramName, Budget, NTILE(4) OVER(ORDER BY Budget DESC) AS BudgetQuartile FROM Programs;
What is the average project timeline for sustainable building projects in the city of Portland, OR?
CREATE TABLE ProjectTimeline (ProjectID INT,City TEXT,Timeline INT); INSERT INTO ProjectTimeline (ProjectID,City,Timeline) VALUES (101,'Seattle',60),(102,'Portland',50),(103,'Seattle',70),(104,'Portland',55);
SELECT AVG(Timeline) FROM ProjectTimeline WHERE City = 'Portland' AND ProjectID IN (SELECT ProjectID FROM SustainableProjects);
What's the average rating of TV shows in the US that have more than 10 episodes?
CREATE TABLE tv_show (id INT PRIMARY KEY,title VARCHAR(255),country VARCHAR(255),num_episodes INT,rating DECIMAL(2,1)); INSERT INTO tv_show (id,title,country,num_episodes,rating) VALUES (1,'TVShowA','USA',12,8.2),(2,'TVShowB','USA',15,7.8),(3,'TVShowC','USA',8,9.1),(4,'TVShowD','USA',11,8.7),(5,'TVShowE','USA',16,7.5);
SELECT AVG(rating) FROM tv_show WHERE country = 'USA' AND num_episodes > 10;
Add a new record to the 'sensors' table for a 'temperature' sensor in the 'Mariana Trench' with 'status' 'active'.
CREATE TABLE sensors (sensor_id INT,sensor_type TEXT,location TEXT,status TEXT);
INSERT INTO sensors (sensor_id, sensor_type, location, status) VALUES (5, 'temperature', 'Mariana Trench', 'active');
How many menu items have a price above the average price of menu items in the 'Italian' category?
CREATE TABLE menu (menu_id INT,menu_name VARCHAR(50),category VARCHAR(50),quantity_sold INT,price DECIMAL(5,2),month_sold INT); INSERT INTO menu (menu_id,menu_name,category,quantity_sold,price,month_sold) VALUES (9,'Margherita Pizza','Italian',25,7.99,1),(10,'Spaghetti Bolognese','Italian',30,9.99,1),(11,'Tiramisu','It...
SELECT COUNT(*) FROM menu WHERE price > (SELECT AVG(price) FROM menu WHERE category = 'Italian');
What was the total number of songs released by artists from India in 2019?
CREATE TABLE artist_country_songs (artist VARCHAR(255),country VARCHAR(255),year INT,num_songs INT); INSERT INTO artist_country_songs (artist,country,year,num_songs) VALUES ('Arijit Singh','India',2019,10),('Shreya Ghoshal','India',2019,12),('AR Rahman','India',2019,8);
SELECT country, SUM(num_songs) FROM artist_country_songs WHERE country = 'India' AND year = 2019;
How many community policing programs were implemented in the city of Chicago between 2018 and 2020?
CREATE TABLE community_policing (id INT,city VARCHAR(50),start_year INT,end_year INT); INSERT INTO community_policing (id,city,start_year,end_year) VALUES (1,'Chicago',2018,2020); INSERT INTO community_policing (id,city,start_year,end_year) VALUES (2,'Chicago',2017,2019);
SELECT COUNT(*) FROM community_policing WHERE city = 'Chicago' AND start_year <= 2020 AND end_year >= 2018;
How many households in Michigan have a water consumption between 1000 and 2000 liters per day?
CREATE TABLE michigan_households (id INT,water_consumption FLOAT); INSERT INTO michigan_households (id,water_consumption) VALUES (1,1500),(2,2000),(3,1000),(4,1200);
SELECT COUNT(*) FROM michigan_households WHERE water_consumption BETWEEN 1000 AND 2000;
What is the maximum wage for 'warehouse' workers?
CREATE TABLE job_stats (employee_id INT,job_title VARCHAR(20),wage FLOAT); INSERT INTO job_stats (employee_id,job_title,wage) VALUES (1,'warehouse',18.00),(2,'warehouse',22.00),(3,'manager',40.00),(4,'warehouse',19.50);
SELECT MAX(wage) FROM job_stats WHERE job_title = 'warehouse';
What is the minimum age of policyholders who have a policy with a premium greater than $3000?
CREATE TABLE Policyholders (PolicyholderID INT,Age INT,Premium DECIMAL(10,2)); INSERT INTO Policyholders (PolicyholderID,Age,Premium) VALUES (1,35,5000),(2,45,1500),(3,50,3000);
SELECT MIN(Age) FROM Policyholders WHERE Premium > 3000;
What is the maximum price of each digital asset in the blockchain?
CREATE TABLE digital_assets (asset_id INT PRIMARY KEY,name VARCHAR(255),symbol VARCHAR(10),total_supply DECIMAL(20,2),price DECIMAL(20,2)); INSERT INTO digital_assets (asset_id,name,symbol,total_supply,price) VALUES (3,'ThirdCoin','TCR',700000.00,30.00);
SELECT symbol, MAX(price) as max_price FROM digital_assets GROUP BY symbol;
What is the average depth of the Atlantic Ocean?
CREATE TABLE oceans (id INT,name VARCHAR(255),avg_temperature DECIMAL(5,2),avg_salinity DECIMAL(5,2),avg_depth DECIMAL(5,2)); INSERT INTO oceans (id,name,avg_temperature,avg_salinity,avg_depth) VALUES (1,'Pacific',20.0,34.72,4282); INSERT INTO oceans (id,name,avg_temperature,avg_salinity,avg_depth) VALUES (2,'Atlantic'...
SELECT AVG(avg_depth) as avg_depth FROM oceans WHERE name = 'Atlantic';
What is the number of unique directors for movies and TV shows in France?
CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,views INT,country VARCHAR(50),director VARCHAR(50)); INSERT INTO movies (id,title,release_year,views,country,director) VALUES (1,'Movie1',2010,10000,'France','Director1'),(2,'Movie2',2015,15000,'France','Director2'); CREATE TABLE tv_shows (id INT,title VAR...
SELECT DISTINCT director FROM movies WHERE country = 'France' UNION SELECT DISTINCT director FROM tv_shows WHERE country = 'France';
How many accessible vehicles are available in each region?
CREATE TABLE Regions (RegionID int,RegionName varchar(50)); INSERT INTO Regions VALUES (1,'North'); INSERT INTO Regions VALUES (2,'South'); CREATE TABLE Vehicles (VehicleID int,VehicleType varchar(50),RegionID int,IsAccessible bool); INSERT INTO Vehicles VALUES (1,'Bus',1,true); INSERT INTO Vehicles VALUES (2,'Tram',1,...
SELECT Regions.RegionName, COUNT(Vehicles.VehicleID) as AccessibleVehicles FROM Regions INNER JOIN Vehicles ON Regions.RegionID = Vehicles.RegionID WHERE Vehicles.IsAccessible = true GROUP BY Regions.RegionName;
What is the average safety rating for vehicles made by 'Volvo' in the 'safety_ratings' table?
CREATE TABLE safety_ratings (vehicle_id INT,make VARCHAR(50),model VARCHAR(50),safety_rating INT);
SELECT AVG(safety_rating) FROM safety_ratings WHERE make = 'Volvo';
What is the total number of art programs, theater programs, and film programs combined, along with the total number of attendees for these programs?
CREATE TABLE ArtPrograms (program VARCHAR(50),attendees INT); INSERT INTO ArtPrograms (program,attendees) VALUES ('Art',120),('Theater',150),('Film',180);
SELECT SUM(attendees) FROM ArtPrograms WHERE program IN ('Art', 'Theater', 'Film');
Find the number of unique donors who have made donations in the gender equality sector, but not in the renewable energy sector.
CREATE TABLE gender_equality (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO gender_equality VALUES (1,25000,'2020-01-01'),(2,30000,'2020-02-01'),(3,15000,'2020-03-01'); CREATE TABLE renewable_energy (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,country VARCHAR(50)); INSERT...
SELECT COUNT(DISTINCT gender_equality.donor_id) FROM gender_equality LEFT JOIN renewable_energy ON gender_equality.donor_id = renewable_energy.donor_id WHERE renewable_energy.donor_id IS NULL;
What is the average production cost of clothing items manufactured in the United States and China?
CREATE TABLE clothing_production (id INT PRIMARY KEY,country VARCHAR(50),item_type VARCHAR(50),production_cost FLOAT); INSERT INTO clothing_production (id,country,item_type,production_cost) VALUES (1,'United States','T-Shirt',12.50),(2,'United States','Jeans',25.00),(3,'China','T-Shirt',5.00),(4,'China','Jeans',10.00);
SELECT AVG(production_cost) FROM clothing_production WHERE country IN ('United States', 'China');
Which countries have the highest total quantity of organic cotton used in textile production?
CREATE TABLE Countries (CountryID int,CountryName varchar(50),Region varchar(50)); INSERT INTO Countries (CountryID,CountryName,Region) VALUES (1,'Bangladesh','Asia'); INSERT INTO Countries (CountryID,CountryName,Region) VALUES (2,'India','Asia'); CREATE TABLE FabricUsage (CountryID int,FabricType varchar(50),Quantity ...
SELECT c.CountryName, SUM(fu.Quantity) as TotalQuantity FROM Countries c INNER JOIN FabricUsage fu ON c.CountryID = fu.CountryID WHERE fu.FabricType = 'Organic Cotton' GROUP BY c.CountryName ORDER BY TotalQuantity DESC;
List the satellite names, telemetry types, and values for telemetry data recorded on 2022-03-15.
CREATE TABLE Satellite_Telemetry (id INT,satellite_name VARCHAR(50),telemetry_type VARCHAR(50),telemetry_value DECIMAL(10,2),telemetry_date DATE); INSERT INTO Satellite_Telemetry (id,satellite_name,telemetry_type,telemetry_value,telemetry_date) VALUES (1,'ISS','Temperature',25.6,'2022-03-14'); INSERT INTO Satellite_Tel...
SELECT satellite_name, telemetry_type, telemetry_value FROM Satellite_Telemetry WHERE telemetry_date = '2022-03-15';
What is the total number of military aircraft in the 'NorthAmerica' schema?
CREATE SCHEMA NorthAmerica; CREATE TABLE MilitaryAircraft (id INT,name VARCHAR(255),type VARCHAR(255),quantity INT); INSERT INTO MilitaryAircraft (id,name,type,quantity) VALUES (1,'F-16','Fighter Jet',50); INSERT INTO MilitaryAircraft (id,name,type,quantity) VALUES (2,'B-52','Bomber',20);
SELECT SUM(quantity) FROM NorthAmerica.MilitaryAircraft;
What are the names and birth years of all artists who have created more than 100 artworks in our database?
CREATE TABLE Artists (artist_id INT,name TEXT,birth_year INT); INSERT INTO Artists (artist_id,name,birth_year) VALUES (1,'Pablo Picasso',1881),(2,'Vincent Van Gogh',1853); CREATE TABLE Artworks (artwork_id INT,title TEXT,artist_id INT); INSERT INTO Artworks (artwork_id,title,artist_id) VALUES (1,'Guernica',1),(2,'Starr...
SELECT Artists.name, Artists.birth_year FROM Artists INNER JOIN (SELECT artist_id FROM Artworks GROUP BY artist_id HAVING COUNT(*) > 100) AS ArtworksCount ON Artists.artist_id = ArtworksCount.artist_id;
What is the maximum and minimum temperature in Alaska for each month in 2018?
CREATE TABLE AlaskaTemperatures (id INT,month INT,temperature DECIMAL(5,2),reading_date DATE); INSERT INTO AlaskaTemperatures (id,month,temperature,reading_date) VALUES (1,1,-12.2,'2018-01-01'); INSERT INTO AlaskaTemperatures (id,month,temperature,reading_date) VALUES (2,12,1.1,'2018-12-31');
SELECT month, MAX(temperature) AS max_temp, MIN(temperature) AS min_temp FROM AlaskaTemperatures WHERE reading_date BETWEEN '2018-01-01' AND '2018-12-31' GROUP BY month;
How many shipments arrived in Mexico from various countries?
CREATE TABLE shipments (id INT,origin_country VARCHAR(255),destination_country VARCHAR(255)); INSERT INTO shipments (id,origin_country,destination_country) VALUES (1,'Canada','Mexico'),(2,'United States','Mexico'),(3,'Brazil','Mexico');
SELECT COUNT(*) FROM shipments WHERE destination_country = 'Mexico';
Get the number of employees in each department and the percentage of the total workforce
CREATE TABLE Departments (id INT,department_name VARCHAR(50),employee_id INT); CREATE TABLE Employees (id INT,salary DECIMAL(10,2));
SELECT Departments.department_name, COUNT(*) AS employees_count, (COUNT(*) / (SELECT COUNT(*) FROM Employees JOIN Departments ON Employees.id = Departments.employee_id) * 100) AS percentage FROM Departments JOIN Employees ON Departments.employee_id = Employees.id GROUP BY department_name;
What are the garments and their respective fabric compositions that are most popular in Spring?
CREATE TABLE fabrics (id INT PRIMARY KEY,name VARCHAR(100),composition VARCHAR(100),country_of_origin VARCHAR(100),popularity INT); CREATE TABLE garments (id INT PRIMARY KEY,fabric_id INT,style VARCHAR(100),price DECIMAL(10,2)); INSERT INTO fabrics (id,name,composition,country_of_origin,popularity) VALUES (1,'Cotton','...
SELECT g.style, f.composition FROM garments g INNER JOIN fabrics f ON g.fabric_id = f.id WHERE f.season = 'Spring' AND f.popularity = (SELECT MAX(popularity) FROM fabrics WHERE season = 'Spring');
List all farmers in 'Florida' who produce 'Lettuce' and the corresponding quantity, ordered by quantity in descending order.
CREATE TABLE Farmers (FarmerID int,FarmerName text,Location text); INSERT INTO Farmers (FarmerID,FarmerName,Location) VALUES (1,'Jim Brown','Florida'); CREATE TABLE Production (Product text,FarmerID int,Quantity int); INSERT INTO Production (Product,FarmerID,Quantity) VALUES ('Lettuce',1,600);
SELECT Farmers.FarmerName, Production.Quantity FROM Farmers JOIN Production ON Farmers.FarmerID = Production.FarmerID WHERE Product = 'Lettuce' AND Location = 'Florida' ORDER BY Quantity DESC;
What is the total number of military personnel who have received humanitarian aid training in the last 5 years, by country?
CREATE TABLE MilitaryPersonnel (ID INT,Name TEXT,TrainingHistory TEXT,Country TEXT); INSERT INTO MilitaryPersonnel VALUES (1,'John Doe','HumanitarianAid;PeacekeepingOperations','USA'); CREATE VIEW HumanitarianAidTraining AS SELECT TrainingHistory FROM MilitaryPersonnel WHERE TrainingHistory LIKE '%HumanitarianAid%';
SELECT h.Country, COUNT(*) as TotalTrained FROM MilitaryPersonnel m JOIN HumanitarianAidTraining h ON m.ID = h.ID AND m.TrainingHistory LIKE '%HumanitarianAid%' WHERE m.TrainingHistory BETWEEN DATEADD(year, -5, GETDATE()) AND GETDATE() GROUP BY h.Country;
What is the total number of climate finance projects in Southeast Asia, and how many of them were successful?
CREATE TABLE climate_finance (region VARCHAR(50),project VARCHAR(50),success BOOLEAN); INSERT INTO climate_finance (region,project,success) VALUES ('Southeast Asia','Solar Power Plant',TRUE),('Southeast Asia','Wind Farm',FALSE);
SELECT COUNT(*), SUM(success) FROM climate_finance WHERE region = 'Southeast Asia';
What is the distribution of employees by gender and job role, in alphabetical order?
CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50),Gender varchar(10),JobRole varchar(50)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Gender,JobRole) VALUES (1,'John','Doe','Male','Software Engineer'); INSERT INTO Employees (EmployeeID,FirstName,LastName,Gender,JobRole) VALUES ...
SELECT Gender, JobRole, COUNT(*) as Count FROM Employees GROUP BY Gender, JobRole ORDER BY JobRole, Gender;
What is the total number of products made by sustainable manufacturers?
CREATE TABLE manufacturers (id INT PRIMARY KEY,name TEXT,location TEXT,sustainability_score INT); CREATE TABLE products (id INT PRIMARY KEY,name TEXT,category TEXT,price DECIMAL,manufacturer_id INT,FOREIGN KEY (manufacturer_id) REFERENCES manufacturers(id));
SELECT COUNT(*) FROM products p JOIN manufacturers m ON p.manufacturer_id = m.id WHERE m.sustainability_score >= 80;
What is the healthcare provider cultural competency training completion rate by region?
CREATE TABLE provider_training (provider_id INT,provider_name VARCHAR(50),region_id INT,training_completion DATE);
SELECT region_id, (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM provider_training WHERE region_id = pt.region_id)) as completion_rate FROM provider_training pt WHERE training_completion IS NOT NULL GROUP BY region_id;
What is the average CO2 emissions reduction from renewable energy projects in Australia per year?
CREATE TABLE projects (id INT,country VARCHAR(255),name VARCHAR(255),co2_emissions_reduction INT,start_year INT,end_year INT); INSERT INTO projects (id,country,name,co2_emissions_reduction,start_year,end_year) VALUES (1,'Australia','Project1',1000,2018,2021),(2,'Australia','Project2',1500,2019,2022);
SELECT AVG(co2_emissions_reduction/(end_year - start_year + 1)) FROM projects WHERE country = 'Australia';
Find the total carbon offsets achieved by each carbon offset program in California, ordered by the highest total carbon offsets first.
CREATE TABLE Program (ProgramID INT,ProgramName VARCHAR(100),State VARCHAR(100),CarbonOffsets INT); INSERT INTO Program VALUES (1,'Carbon Offset Program 1','California',500),(2,'Carbon Offset Program 2','California',300),(3,'Carbon Offset Program 3','California',200),(4,'Carbon Offset Program 4','California',100);
SELECT ProgramName, State, SUM(CarbonOffsets) AS TotalCarbonOffsets FROM Program WHERE State = 'California' GROUP BY ProgramID ORDER BY TotalCarbonOffsets DESC;
How many graduate students are there in the Computer Science department?
CREATE TABLE students (id INT,name VARCHAR(50),gender VARCHAR(10),department VARCHAR(50),graduate_student VARCHAR(50)); INSERT INTO students (id,name,gender,department,graduate_student) VALUES (1,'Alice','Female','Computer Science','Yes'),(2,'Bob','Male','Computer Science','No'),(3,'Charlie','Non-binary','Computer Scie...
SELECT COUNT(*) FROM students WHERE department = 'Computer Science' AND graduate_student = 'Yes';