instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Get the top 5 content creators with the most posts in the content_creators table who joined after 2020-06-01.
CREATE TABLE content_creators (creator_id INT,username VARCHAR(50),join_date DATE,posts INT);
SELECT username, posts FROM content_creators WHERE join_date > '2020-06-01' ORDER BY posts DESC LIMIT 5;
Remove all records from the 'facility_schedule' table where the facility_id is not in the 'facilities' table
CREATE TABLE facilities (id INT); CREATE TABLE facility_schedule (id INT,facility_id INT,start_time TIMESTAMP,end_time TIMESTAMP); INSERT INTO facilities (id) VALUES (1),(2);
DELETE FROM facility_schedule WHERE facility_id NOT IN (SELECT id FROM facilities);
What is the maximum crime severity score in the 'urban' schema?
CREATE SCHEMA if not exists urban; CREATE TABLE if not exists urban.crime_data (id INT,crime_severity_score INT); INSERT INTO urban.crime_data (id,crime_severity_score) VALUES (1,6),(2,8),(3,10),(4,12);
SELECT MAX(crime_severity_score) FROM urban.crime_data;
Identify the number of users who posted at least 5 tweets with the hashtag #climatechange in the month of January 2022, from the "social_media" schema.
CREATE TABLE tweets (id INT,user_id INT,content TEXT,timestamp DATETIME); INSERT INTO tweets (id,user_id,content,timestamp) VALUES (1,123,'This is a tweet about climate change','2022-01-01 10:00:00'),(2,456,'#climatechange is real','2022-01-15 14:30:00');
SELECT COUNT(DISTINCT user_id) FROM tweets WHERE MONTH(timestamp) = 1 AND content LIKE '%#climatechange%' GROUP BY user_id HAVING COUNT(*) >= 5;
Which salesperson has sold the least garments in the last 30 days, ordered by the number of garments sold?
CREATE TABLE salesperson (salesperson_id INT,name VARCHAR(50)); CREATE TABLE sales (sales_id INT,salesperson_id INT,sale_date DATE);
SELECT salesperson.name, COUNT(sales.sales_id) AS quantity_sold FROM salesperson INNER JOIN sales ON salesperson.salesperson_id = sales.salesperson_id WHERE sale_date >= CURRENT_DATE - INTERVAL '30 days' GROUP BY salesperson.name ORDER BY quantity_sold ASC;
What is the number of attendees for community training events in 'Rural Africa' and 'Urban Asia'?
CREATE TABLE CommunityTraining (id INT,training_name VARCHAR(50),location VARCHAR(50),attendees INT,training_date DATE); INSERT INTO CommunityTraining (id,training_name,location,attendees,training_date) VALUES (1,'AgriTech Tools','Rural India',50,'2021-10-01'); INSERT INTO CommunityTraining (id,training_name,location,a...
SELECT location, SUM(attendees) FROM CommunityTraining WHERE location IN ('Rural Africa', 'Urban Asia') GROUP BY location;
What is the total quantity of materials used in production that are not recycled, and what percentage does it represent of the total production quantity?
CREATE TABLE production (company_id INT,recycled_qty INT,total_qty INT);
SELECT SUM(total_qty - recycled_qty) AS total_non_recycled, (SUM(total_qty - recycled_qty) / SUM(total_qty)) * 100 AS pct_non_recycled FROM production;
What is the average number of tourists visiting Canada and Australia per year?
CREATE TABLE canada_tourists (year INT,tourists INT);CREATE TABLE australia_tourists (year INT,tourists INT);
SELECT AVG(tourists) FROM (SELECT year, AVG(tourists) AS tourists FROM canada_tourists GROUP BY year UNION ALL SELECT year, AVG(tourists) AS tourists FROM australia_tourists GROUP BY year) AS avg_tourists;
What is the average citizen feedback score for healthcare services in Mumbai in 2022?
CREATE TABLE MumbaiFeedback (service VARCHAR(30),score INT,year INT); INSERT INTO MumbaiFeedback (service,score,year) VALUES ('Healthcare Services',80,2022),('Healthcare Services',85,2022),('Healthcare Services',75,2022);
SELECT AVG(score) FROM MumbaiFeedback WHERE service = 'Healthcare Services' AND year = 2022;
What is the number of new HIV cases reported in each state of the US, by age group?
CREATE TABLE hiv_cases (id INT,patient_id INT,report_date DATE,state VARCHAR(255),age_group VARCHAR(255));
SELECT state, age_group, COUNT(*) AS num_new_hiv_cases FROM hiv_cases WHERE report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY state, age_group;
How many cases were handled by attorneys with 'Smith' as their last name?
CREATE TABLE Attorneys (AttorneyID INT,LastName VARCHAR(20)); INSERT INTO Attorneys (AttorneyID,LastName) VALUES (1,'Smith'),(2,'Johnson'),(3,'Williams'); CREATE TABLE Cases (CaseID INT,AttorneyID INT); INSERT INTO Cases (CaseID,AttorneyID) VALUES (1,1),(2,2),(3,3),(4,1);
SELECT COUNT(*) FROM Cases INNER JOIN Attorneys ON Cases.AttorneyID = Attorneys.AttorneyID WHERE Attorneys.LastName = 'Smith';
Identify the top 5 most sold vegan dishes by cuisine type.
CREATE TABLE orders(order_id INT,order_date DATE,menu_item_id INT,quantity INT); CREATE TABLE menu_items(menu_item_id INT,name TEXT,cuisine TEXT,type TEXT,is_vegan BOOLEAN,price DECIMAL);
SELECT cuisine, name, SUM(quantity) as total_sold FROM orders JOIN menu_items ON orders.menu_item_id = menu_items.menu_item_id WHERE is_vegan = TRUE GROUP BY cuisine, name ORDER BY total_sold DESC LIMIT 5;
Update the rating of all movies produced in France to 7.0.
CREATE TABLE movies (id INT,title VARCHAR(255),rating DECIMAL(3,2),production_country VARCHAR(64)); INSERT INTO movies (id,title,rating,production_country) VALUES (1,'MovieA',7.5,'Spain'),(2,'MovieB',8.2,'Italy'),(3,'MovieC',6.8,'France');
UPDATE movies SET rating = 7.0 WHERE production_country = 'France';
Show the number of threat intelligence reports generated in the last 30 days
CREATE SCHEMA intelligence_schema; CREATE TABLE report (report_id INT PRIMARY KEY,report_date DATE); INSERT INTO report (report_id,report_date) VALUES (1,'2022-01-01');
SELECT COUNT(*) FROM report WHERE report_date >= CURDATE() - INTERVAL 30 DAY;
What is the total number of clinics providing mental health services, by state?
CREATE TABLE clinics (state VARCHAR(2),num_clinics INT); INSERT INTO clinics (state,num_clinics) VALUES ('NY',250),('NJ',180),('CA',400),('FL',320),('TX',360);
SELECT state, SUM(num_clinics) as total_clinics FROM clinics WHERE service_type = 'mental health' GROUP BY state;
Delete the "rural_hospitals" table
CREATE TABLE rural_hospitals (hospital_id INT,name VARCHAR(50),beds INT);
DROP TABLE rural_hospitals;
Display the total amount of resources (coal, iron, gold, silver) mined by each mine.
CREATE TABLE mine (id INT,name VARCHAR(50),location VARCHAR(50));CREATE TABLE coal_mine (mine_id INT,amount INT);CREATE TABLE iron_mine (mine_id INT,amount INT);CREATE TABLE gold_mine (mine_id INT,amount INT);CREATE TABLE silver_mine (mine_id INT,amount INT);
SELECT m.name, m.location, SUM(COALESCE(c.amount, 0) + COALESCE(i.amount, 0) + COALESCE(g.amount, 0) + COALESCE(s.amount, 0)) AS total_amount FROM mine m LEFT JOIN coal_mine c ON m.id = c.mine_id LEFT JOIN iron_mine i ON m.id = i.mine_id LEFT JOIN gold_mine g ON m.id = g.mine_id LEFT JOIN silver_mine s ON m.id = s.mine...
What is the total quantity of recycled materials used in the company's manufacturing process in Q1 2022?
CREATE TABLE manufacturing_process (process_id INT,process_name VARCHAR(255),material_type VARCHAR(255),material_quantity INT); INSERT INTO manufacturing_process (process_id,process_name,material_type,material_quantity) VALUES (1,'Plastic Molding','Plastic Recyclate',500),(2,'Metal Stamping','Scrap Metal',300),(3,'Wood...
SELECT SUM(material_quantity) as total_quantity FROM manufacturing_process WHERE material_type LIKE '%Recycled%' AND process_date BETWEEN '2022-01-01' AND '2022-03-31';
What is the number of teachers who have participated in cross-cultural professional development programs in urban and rural areas?
CREATE TABLE teacher_pd (teacher_id INT,location VARCHAR(50),program VARCHAR(50)); INSERT INTO teacher_pd (teacher_id,location,program) VALUES (1,'Urban','Cross-Cultural Pedagogy 101'),(2,'Rural','Cross-Cultural Pedagogy 101'),(3,'Suburban','Cross-Cultural Pedagogy 101');
SELECT location, COUNT(DISTINCT teacher_id) as num_teachers FROM teacher_pd WHERE program = 'Cross-Cultural Pedagogy 101' GROUP BY location;
What is the total number of fire stations in Los Angeles?
CREATE TABLE la_fire_stations (id INT,station_name VARCHAR(20),location VARCHAR(20)); INSERT INTO la_fire_stations (id,station_name,location) VALUES (1,'Station 1','Los Angeles'),(2,'Station 2','Los Angeles');
SELECT COUNT(*) FROM la_fire_stations;
Show the total oil production in the Caspian Sea for each year from 2010 to 2020.
CREATE TABLE oil_production (id INT,location VARCHAR(20),production_date DATE,oil_production INT);
SELECT production_date, SUM(oil_production) FROM oil_production WHERE location LIKE 'Caspian Sea%' AND production_date BETWEEN '2010-01-01' AND '2020-12-31' GROUP BY production_date ORDER BY production_date;
Get the top 3 menu items with the highest sustainability rating
CREATE TABLE menu_sustainability (id INT PRIMARY KEY,menu_item VARCHAR(255),sustainability_rating DECIMAL(3,2));
SELECT menu_item, sustainability_rating FROM menu_sustainability ORDER BY sustainability_rating DESC LIMIT 3;
What is the earliest and latest date that each exhibition was open to the public?
CREATE TABLE Exhibitions (id INT,name VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO Exhibitions VALUES (1,'Exhibition A','2022-01-01','2022-03-31'),(2,'Exhibition B','2022-02-01','2022-04-30'),(3,'Exhibition C','2022-03-01','2022-05-31');
SELECT Exhibitions.name, MIN(Exhibitions.start_date) AS earliest_date, MAX(Exhibitions.end_date) AS latest_date FROM Exhibitions GROUP BY Exhibitions.name;
Determine the number of healthcare facilities in each state, offering telehealth services.
CREATE TABLE healthcare_facilities (facility_name VARCHAR(50),state VARCHAR(50),offers_telehealth BOOLEAN); INSERT INTO healthcare_facilities (facility_name,state,offers_telehealth) VALUES ('Clinic A','California',TRUE),('Clinic B','California',FALSE),('Hospital C','Texas',TRUE),('Hospital D','Texas',TRUE),('Clinic E',...
SELECT state, COUNT(*) as facility_count FROM healthcare_facilities WHERE offers_telehealth = TRUE GROUP BY state;
What is the total number of crime incidents, emergency calls, and fire incidents in each borough of NYC?
CREATE TABLE crime_incidents (id INT,borough VARCHAR(20),type VARCHAR(20)); INSERT INTO crime_incidents (id,borough,type) VALUES (1,'Brooklyn','theft'),(2,'Queens','burglary'); CREATE TABLE emergency_calls (id INT,borough VARCHAR(20),type VARCHAR(20)); INSERT INTO emergency_calls (id,borough,type) VALUES (1,'Bronx','em...
SELECT borough, 'crime incidents' AS type, COUNT(*) FROM crime_incidents GROUP BY borough UNION ALL SELECT borough, 'emergency calls' AS type, COUNT(*) FROM emergency_calls GROUP BY borough UNION ALL SELECT borough, 'fire incidents' AS type, COUNT(*) FROM fire_incidents GROUP BY borough;
List the total number of crimes and response time for each district in 2021.
CREATE TABLE district (did INT,name VARCHAR(255)); INSERT INTO district VALUES (1,'Downtown'),(2,'Uptown'); CREATE TABLE calls (call_id INT,district_id INT,response_time INT,year INT);
SELECT d.name, COUNT(c.call_id), AVG(c.response_time) FROM district d JOIN calls c ON d.did = c.district_id WHERE c.year = 2021 GROUP BY d.did;
What is the average citizen feedback score for all services in the North region in 2021?
CREATE TABLE Feedback (Year INT,Service VARCHAR(255),Region VARCHAR(255),Score DECIMAL(3,2)); INSERT INTO Feedback (Year,Service,Region,Score) VALUES (2021,'Healthcare','North',8.50),(2021,'Education','North',8.75),(2021,'Transportation','North',8.25),(2021,'Utilities','North',8.90);
SELECT AVG(Score) FROM Feedback WHERE Year = 2021 AND Region = 'North';
List all companies that have implemented 'workforce diversity training' programs and the start dates of these programs.
CREATE TABLE companies (company_id INT,diversity_training BOOLEAN,diversity_training_start_date DATE);
SELECT companies.company_id, companies.diversity_training_start_date FROM companies WHERE companies.diversity_training = TRUE;
Which departments have the most diverse workforces?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Ethnicity VARCHAR(20));CREATE VIEW DepartmentDiversity AS SELECT Department,COUNT(DISTINCT Ethnicity) as DiversityCount FROM Employees GROUP BY Department;
SELECT Department FROM DepartmentDiversity WHERE ROW_NUMBER() OVER(ORDER BY DiversityCount DESC) <= 3;
How many rural clinics offer telemedicine services in South America?
CREATE TABLE clinic_services (clinic_id INT,region VARCHAR(10),offers_telemedicine BOOLEAN); INSERT INTO clinic_services (clinic_id,region,offers_telemedicine) VALUES (1,'South America',TRUE),(2,'North America',FALSE),(3,'South America',TRUE),(4,'Oceania',FALSE);
SELECT COUNT(*) FROM clinic_services WHERE region = 'South America' AND offers_telemedicine = TRUE;
What is the maximum production of 'Potatoes' by any farmer in 'Colorado' or 'Arizona'?
CREATE TABLE Farmers (FarmerID int,FarmerName text,Location text); INSERT INTO Farmers (FarmerID,FarmerName,Location) VALUES (1,'Michael Jordan','Colorado'); CREATE TABLE Production (Product text,FarmerID int,Quantity int); INSERT INTO Production (Product,FarmerID,Quantity) VALUES ('Potatoes',1,1000); INSERT INTO Farme...
SELECT MAX(Quantity) FROM Production JOIN Farmers ON Production.FarmerID = Farmers.FarmerID WHERE Product = 'Potatoes' AND (Location = 'Colorado' OR Location = 'Arizona');
List the names and donation amounts of the top 5 donors in 2022.
CREATE TABLE Donors (DonorID int,Name varchar(50),TotalDonation decimal(10,2)); INSERT INTO Donors (DonorID,Name,TotalDonation) VALUES (1,'John Doe',500.00),(2,'Jane Smith',800.00),(3,'Alice Johnson',1500.00),(4,'Bob Brown',1000.00),(5,'Charlie Davis',2000.00);
SELECT Name, TotalDonation FROM Donors WHERE YEAR(DonationDate) = 2022 ORDER BY TotalDonation DESC LIMIT 5;
What are the unique program categories and their corresponding budgets, excluding categories with a budget of zero?
CREATE TABLE program_categories (program_category VARCHAR(20),budget INT);INSERT INTO program_categories VALUES ('Arts',0),('Education',5000),('Health',10000),('Science',2000);
SELECT program_category, budget FROM program_categories WHERE budget > 0;
Who are the top 3 contributors to explainable AI algorithms?
CREATE TABLE contributor (name VARCHAR(255),country VARCHAR(255),algorithms INTEGER); INSERT INTO contributor (name,country,algorithms) VALUES ('Google','USA',20),('IBM','USA',15),('Microsoft','USA',12),('OpenAI','USA',8),('DeepMind','UK',7);
SELECT name, algorithms FROM contributor ORDER BY algorithms DESC LIMIT 3;
List all companies and their diversity metrics
CREATE TABLE companies (id INT,name VARCHAR(50),diversity_score DECIMAL(3,2)); CREATE TABLE diversity_data (id INT,company_id INT,gender_diversity DECIMAL(3,2),racial_diversity DECIMAL(3,2));
SELECT companies.name, companies.diversity_score, diversity_data.gender_diversity, diversity_data.racial_diversity FROM companies INNER JOIN diversity_data ON companies.id = diversity_data.company_id;
What is the total production cost of garments made from sustainable materials?
CREATE TABLE ProductionCosts (productID INT,materialType VARCHAR(20),cost DECIMAL(5,2)); INSERT INTO ProductionCosts (productID,materialType,cost) VALUES (1,'Organic Cotton',15.50),(2,'Polyester',8.25),(3,'Hemp',20.00),(4,'Bamboo',18.00),(5,'Recycled Polyester',12.00);
SELECT SUM(cost) FROM ProductionCosts WHERE materialType IN ('Organic Cotton', 'Hemp', 'Bamboo', 'Recycled Polyester');
What is the total number of military personnel in the African region, excluding personnel from countries with less than 5000 personnel?
CREATE TABLE MilitaryPersonnel (region VARCHAR(255),country VARCHAR(255),personnel INT); INSERT INTO MilitaryPersonnel (region,country,personnel) VALUES ('Africa','CountryA',4000),('Africa','CountryB',6000),('Africa','CountryC',5000),('Asia','CountryD',3000),('Asia','CountryE',2000);
SELECT region, COUNT(*) FROM MilitaryPersonnel WHERE region = 'Africa' GROUP BY region HAVING SUM(personnel) > 5000;
Insert a new row with inclusive housing data into the properties view
CREATE VIEW properties AS SELECT * FROM property;
INSERT INTO properties (id, inclusive_housing, price) VALUES (789, TRUE, 450000.00);
Insert new environmental impact stats for the 'Amethyst Ascent' mine in Amazonas, Brazil
CREATE TABLE environmental_impact (mine_id INT,year INT,co2_emissions INT,water_consumption INT,waste_generation INT);
INSERT INTO environmental_impact (mine_id, year, co2_emissions, water_consumption, waste_generation) VALUES (8, 2021, 10000, 400000, 9000);
Find the number of defense contracts awarded to each company in table 'defense_contracts'
CREATE TABLE defense_contracts (contract_id INT,company_name VARCHAR(100),contract_value DECIMAL(10,2),contract_date DATE);
SELECT company_name, COUNT(*) as num_contracts FROM defense_contracts GROUP BY company_name;
Delete all records of players who have never reviewed a game.
CREATE TABLE Players (id INT,name VARCHAR(50),age INT,platform VARCHAR(50),favorite_game_id INT,num_reviews INT); INSERT INTO Players (id,name,age,platform,favorite_game_id,num_reviews) VALUES (1,'Player1',25,'PC',1,50),(2,'Player2',30,'Console',NULL,0),(3,'Player3',35,'Mobile',3,10);
DELETE FROM Players WHERE num_reviews = 0;
Calculate the average time to fulfill military equipment maintenance requests for the Army
CREATE TABLE military_equipment (equipment_id INT,branch VARCHAR(10),maintenance_requested BOOLEAN,maintenance_fulfilled BOOLEAN,maintenance_request_date DATE,maintenance_fulfillment_date DATE);
SELECT AVG(maintenance_fulfillment_date - maintenance_request_date) FROM military_equipment WHERE branch = 'Army' AND maintenance_requested = TRUE AND maintenance_fulfilled = TRUE;
Which disability services staff members have served the most students with disabilities?
CREATE TABLE Staff (staff_id INT,staff_name TEXT); CREATE TABLE Staff_Accommodations (staff_id INT,student_id INT); CREATE VIEW Staff_Accommodations_Count AS SELECT staff_id,COUNT(*) FROM Staff_Accommodations GROUP BY staff_id; CREATE VIEW Max_Staff_Accommodations AS SELECT staff_id,COUNT(*) FROM Staff_Accommodations G...
SELECT Staff.staff_name, Max_Staff_Accommodations.COUNT(*) FROM Staff INNER JOIN Max_Staff_Accommodations ON Staff.staff_id = Max_Staff_Accommodations.staff_id;
Find the number of unique students who received accommodations in 2021 and 2022
CREATE TABLE student_accommodations (student_id INT,accommodation_year INT,accommodation_type VARCHAR(255));
SELECT accommodation_year, COUNT(DISTINCT student_id) FROM student_accommodations WHERE accommodation_year IN (2021, 2022) GROUP BY accommodation_year;
Calculate the percentage of multi-modal trips using trains and buses.
CREATE TABLE trip_data (trip_id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,mode_1 VARCHAR(10),mode_2 VARCHAR(10));
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM trip_data)) AS percentage FROM trip_data WHERE mode_1 = 'Train' AND mode_2 = 'Bus';
How many cargos were transported by the vessel 'Sea Titan'?
CREATE TABLE cargos (cargo_id INT,cargo_name VARCHAR(50),vessel_name VARCHAR(50)); INSERT INTO cargos (cargo_id,cargo_name,vessel_name) VALUES (1,'Container 1','Sea Titan'),(2,'Coal','Marine Express'),(3,'Grain','Ocean Breeze');
SELECT COUNT(*) FROM cargos WHERE vessel_name = 'Sea Titan';
What was the average donation amount by donors from underrepresented communities in Q4 2020?
CREATE TABLE Donors (DonorID int,DonationDate date,DonationAmount numeric,DonorCommunity varchar(50));
SELECT AVG(DonationAmount) FROM (SELECT DonationAmount FROM Donors WHERE DonationDate BETWEEN '2020-10-01' AND '2020-12-31' AND DonorCommunity IN ('Historically Black Colleges and Universities', 'Indigenous Communities', 'LGBTQ+ Organizations')) AS UnderrepresentedDonors;
Who are the top 3 countries with the most satellites in orbit?
CREATE TABLE satellites_by_country (country VARCHAR(255),num_satellites INT); INSERT INTO satellites_by_country (country,num_satellites) VALUES ('USA',1796); INSERT INTO satellites_by_country (country,num_satellites) VALUES ('Russia',1447); INSERT INTO satellites_by_country (country,num_satellites) VALUES ('China',413)...
SELECT country, num_satellites FROM satellites_by_country ORDER BY num_satellites DESC LIMIT 3;
Display the total revenue generated from timber sales for each company, along with the number of employees for those companies, in a given year.
CREATE TABLE company (company_id INT,company_name TEXT,PRIMARY KEY (company_id)); CREATE TABLE employee (employee_id INT,company_id INT,employee_count INT,PRIMARY KEY (employee_id),FOREIGN KEY (company_id) REFERENCES company(company_id)); CREATE TABLE sale (sale_id INT,company_id INT,year INT,revenue INT,PRIMARY KEY (s...
SELECT c.company_name, s.year, SUM(s.revenue) AS total_revenue, COUNT(e.employee_count) AS total_employees FROM company c INNER JOIN sale s ON c.company_id = s.company_id INNER JOIN employee e ON c.company_id = e.company_id GROUP BY c.company_name, s.year ORDER BY s.year;
What is the minimum virtual tour rating for hotels in Japan?
CREATE TABLE hotel_ratings (hotel_id INT,country VARCHAR(50),rating FLOAT); INSERT INTO hotel_ratings (hotel_id,country,rating) VALUES (1,'Japan',4.2),(2,'Japan',4.6),(3,'Japan',4.5),(4,'Italy',4.7); CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,rating FLOAT); INSERT INTO virtual_tours (tour_id,hotel_id,rating) ...
SELECT MIN(vt.rating) FROM hotel_ratings hr JOIN virtual_tours vt ON hr.hotel_id = vt.hotel_id WHERE hr.country = 'Japan';
What is the average cargo handling time per port, including ports with no handling time?
CREATE TABLE cargo_handling (handling_id INT,port_id INT,handling_time INT);
SELECT p.port_name, AVG(ch.handling_time) as avg_handling_time FROM ports p LEFT JOIN cargo_handling ch ON p.port_id = ch.port_id GROUP BY p.port_name;
What is the average number of hours of professional development completed by teachers who are also coaches?
CREATE TABLE Teachers (TeacherID INT PRIMARY KEY,Coach BOOLEAN,Hours INT); INSERT INTO Teachers (TeacherID,Coach,Hours) VALUES (1,1,25);
SELECT AVG(Hours) FROM Teachers WHERE Coach = 1;
What is the average mental health parity complaint resolution time by state?
CREATE TABLE MentalHealthParity (ComplaintID INT,State VARCHAR(255),FilingDate DATE,ResolutionDate DATE); INSERT INTO MentalHealthParity (ComplaintID,State,FilingDate,ResolutionDate) VALUES (1,'California','2021-01-05','2021-02-10'),(2,'Texas','2021-03-12','2021-04-15'),(3,'New York','2021-06-20','2021-07-25'),(4,'Flor...
SELECT State, AVG(DATEDIFF(ResolutionDate, FilingDate)) as AvgResolutionTimeDays FROM MentalHealthParity GROUP BY State;
Delete a network investment from the 'network_investments' table
CREATE TABLE network_investments (investment_id INT,investment_name VARCHAR(255),investment_type VARCHAR(255),investment_amount DECIMAL(10,2),date DATE);
DELETE FROM network_investments WHERE investment_id = 4001;
Which wells in the North Sea have experienced the highest total exploration cost, ordered by the exploration date?
CREATE TABLE north_sea_data (data_id INT,well_id INT,date_explored DATE,type VARCHAR(50),cost FLOAT); INSERT INTO north_sea_data (data_id,well_id,date_explored,type,cost) VALUES (1,5,'2020-01-01','Seismic',150000.0),(2,5,'2020-02-01','Drilling',500000.0),(3,6,'2019-12-15','Seismic',200000.0),(4,6,'2020-01-10','Drilling...
SELECT well_id, SUM(cost) OVER (PARTITION BY well_id ORDER BY date_explored DESC) as total_cost FROM north_sea_data WHERE location = 'North Sea';
What was the total revenue for each menu category last week?
CREATE TABLE menu (category VARCHAR(255),revenue NUMERIC); INSERT INTO menu (category,revenue) VALUES ('Appetizers',500),('Entrees',2000),('Desserts',1000);
SELECT category, SUM(revenue) FROM menu WHERE revenue >= (SELECT AVG(revenue) FROM menu) AND date >= DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY) GROUP BY category;
What is the minimum rating of movies directed by female directors and released between 2015 and 2020?
CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,rating DECIMAL(2,1),director VARCHAR(50)); INSERT INTO movies (id,title,release_year,rating,director) VALUES (1,'Movie1',2016,7.6,'Director1'),(2,'Movie2',2018,8.1,'Director2'),(3,'Movie3',2019,6.3,'Director3');
SELECT MIN(rating) FROM movies WHERE release_year BETWEEN 2015 AND 2020 AND director LIKE '%female%';
What is the average waste generation for each mine involved in copper extraction, grouped by the geologists who conducted the surveys?
CREATE TABLE production_statistics (id INT,mine_id INT,year INT,total_production INT,waste_generation INT); INSERT INTO production_statistics (id,mine_id,year,total_production,waste_generation) VALUES (1,1,2019,12500,2500); INSERT INTO production_statistics (id,mine_id,year,total_production,waste_generation) VALUES (2,...
SELECT g.geologist, AVG(ps.waste_generation) as avg_waste_generation FROM geological_survey g JOIN mines m ON m.id = g.mine_id JOIN production_statistics ps ON m.id = ps.mine_id WHERE m.mineral = 'Copper' GROUP BY g.geologist;
How many pallets are stored in each warehouse and what is the total volume of each warehouse?
CREATE TABLE pallet (pallet_id INT,warehouse_id VARCHAR(5),volume INT); INSERT INTO pallet (pallet_id,warehouse_id,volume) VALUES (1001,'W001',5),(1002,'W001',5),(1003,'W002',7),(1004,'W002',7);
SELECT w.name, COUNT(p.pallet_id) AS pallet_count, SUM(p.volume) AS total_volume FROM pallet p INNER JOIN warehouse w ON p.warehouse_id = w.warehouse_id GROUP BY w.name;
What is the name of the developer and their corresponding digital asset that has the highest transaction count?
CREATE TABLE developers (developer_id INT PRIMARY KEY,name VARCHAR(100)); INSERT INTO developers (developer_id,name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'); CREATE TABLE smart_contracts (contract_id INT PRIMARY KEY,name VARCHAR(100),transaction_count INT,developer_id INT,FOREIGN KEY (developer_id) REFERENCES develo...
SELECT developers.name, MAX(smart_contracts.transaction_count) FROM developers INNER JOIN smart_contracts ON developers.developer_id = smart_contracts.developer_id INNER JOIN digital_assets ON smart_contracts.contract_id = digital_assets.contract_id GROUP BY developers.name;
What is the minimum caloric content of dishes in the 'Japanese' and 'Korean' cuisine types?
CREATE TABLE CuisineTypes (CuisineTypeID INT,CuisineType VARCHAR(50));CREATE TABLE Dishes (DishID INT,DishName VARCHAR(50),CuisineTypeID INT,CaloricContent INT); INSERT INTO CuisineTypes VALUES (1,'Italian'),(2,'Chinese'),(3,'Japanese'),(4,'Korean'); INSERT INTO Dishes VALUES (1,'Pizza Margherita',1,500),(2,'Spaghetti ...
SELECT MIN(CaloricContent) as MinCaloricContent FROM Dishes WHERE CuisineType IN ('Japanese', 'Korean');
How many female and male employees are there in total?
CREATE TABLE employees (id INT,name VARCHAR(255),department VARCHAR(255),gender VARCHAR(10)); INSERT INTO employees (id,name,department,gender) VALUES (1,'John Doe','Engineering','Male'),(2,'Jane Smith','Engineering','Female'),(3,'Bob Johnson','Operations','Male');
SELECT SUM(CASE WHEN gender = 'Female' THEN 1 ELSE 0 END) AS num_female, SUM(CASE WHEN gender = 'Male' THEN 1 ELSE 0 END) AS num_male FROM employees;
How many smart city projects in the 'SmartCityProjects' table have a budget greater than $10 million?
CREATE TABLE SmartCityProjects (id INT,projectName VARCHAR(50),budget DECIMAL(10,2),startDate DATE); INSERT INTO SmartCityProjects (id,projectName,budget,startDate) VALUES (1,'Intelligent Lighting System',8000000.50,'2021-01-01'),(2,'Smart Waste Management',5000000.00,'2021-05-15'),(3,'Advanced Traffic Management',1200...
SELECT COUNT(*) FROM SmartCityProjects WHERE budget > 10000000;
What is the total number of likes received by posts in the 'Cybersecurity' category?
CREATE TABLE content_categories (id INT,content_category VARCHAR(255)); CREATE TABLE posts_extended (id INT,content_category_id INT,likes INT,content TEXT); INSERT INTO content_categories (id,content_category) VALUES (1,'AI'),(2,'Data Science'),(3,'Cybersecurity'); INSERT INTO posts_extended (id,content_category_id,lik...
SELECT posts_extended.content_category_id, SUM(posts_extended.likes) FROM posts_extended WHERE posts_extended.content_category_id = 3 GROUP BY posts_extended.content_category_id;
What is the total number of hospital beds in rural hospitals that specialize in cardiology?
CREATE TABLE hospitals (hospital_id INT,name TEXT,location TEXT,hospital_type TEXT,num_beds INT); INSERT INTO hospitals (hospital_id,name,location,hospital_type,num_beds) VALUES (1,'Rural General Hospital','Bradley','Rural',100),(2,'Rural Cardiology Hospital','Bradley','Rural',150),(3,'Urban General Hospital','UrbanCen...
SELECT SUM(num_beds) FROM hospitals WHERE hospital_type = 'Rural' AND location IN (SELECT location FROM hospitals WHERE hospital_type = 'Rural' AND name LIKE '%Cardiology%');
What is the total cost of all infrastructure projects in the Rural Development schema, ordered by the project cost in descending order?
CREATE TABLE Infrastructure_Projects (Project_ID INT,Project_Name VARCHAR(50),Project_Cost FLOAT,Project_Location VARCHAR(50)); INSERT INTO Infrastructure_Projects (Project_ID,Project_Name,Project_Cost,Project_Location) VALUES (1,'Water Supply',50000,'Rural Area A'),(2,'Electricity Grid',75000,'Rural Area B'),(3,'Road ...
SELECT SUM(Project_Cost) AS Total_Cost FROM Infrastructure_Projects ORDER BY Total_Cost DESC;
What is the total quantity of carbon offset initiatives and the number of distinct cities for each state, ordered by the total offset quantity in descending order?
CREATE TABLE carbon_offset_initiatives (id INT,name VARCHAR(50),city VARCHAR(50),state VARCHAR(50),country VARCHAR(50),offset_quantity INT,PRIMARY KEY (id));
SELECT state, SUM(offset_quantity) as total_offset_quantity, COUNT(DISTINCT city) as city_count, ROW_NUMBER() OVER (ORDER BY SUM(offset_quantity) DESC) as ranking FROM carbon_offset_initiatives GROUP BY state;
What is the difference in average permit cost between commercial and residential buildings in California in 2021?
CREATE TABLE permit_cost_comparison (cost_id INT,state VARCHAR(50),building_type VARCHAR(50),permit_cost FLOAT,material_type VARCHAR(50),issue_date DATE); INSERT INTO permit_cost_comparison (cost_id,state,building_type,permit_cost,material_type,issue_date) VALUES (1,'California','Commercial',400000.00,'Sustainable','20...
SELECT AVG(permit_cost) - LAG(AVG(permit_cost)) OVER (PARTITION BY state ORDER BY EXTRACT(YEAR FROM issue_date)) FROM permit_cost_comparison WHERE state = 'California' AND building_type IN ('Commercial', 'Residential') AND issue_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the maximum number of attendees for a single cultural event?
CREATE TABLE Museums (museum_id INT,museum_name VARCHAR(255)); CREATE TABLE Events (event_id INT,museum_id INT,event_type VARCHAR(255),attendance INT); INSERT INTO Museums (museum_id,museum_name) VALUES (1,'Met'),(2,'Louvre'); INSERT INTO Events (event_id,museum_id,event_type,attendance) VALUES (1,1,'Art Exhibit',500),...
SELECT MAX(attendance) as Max_Attendance FROM Events;
Which sites have a higher than average CO2 emission level?
CREATE TABLE site (site_id INT,site_name VARCHAR(50),co2_emissions_tonnes INT);
SELECT site_name FROM site WHERE co2_emissions_tonnes > (SELECT AVG(co2_emissions_tonnes) FROM site);
What is the percentage of union members who are women, by union type?
CREATE TABLE unions (id INT,type TEXT); INSERT INTO unions (id,type) VALUES (1,'Manufacturing'),(2,'Service'),(3,'Construction'); CREATE TABLE members (id INT,union_id INT,gender TEXT); INSERT INTO members (id,union_id,gender) VALUES (1,1,'Female'),(2,1,'Male'),(3,2,'Female'),(4,2,'Female'),(5,3,'Male');
SELECT u.type, 100.0 * COUNT(m.id) FILTER (WHERE m.gender = 'Female') / COUNT(m.id) AS percentage FROM unions u JOIN members m ON u.id = m.union_id GROUP BY u.type;
How many albums were released by South Asian Indie musicians in the 2010s?
CREATE TABLE artists (id INT,name VARCHAR,region VARCHAR,genre VARCHAR); CREATE TABLE albums (id INT,artist_id INT,title VARCHAR,release_year INT); INSERT INTO artists VALUES (1,'Pentagram','South Asia','Indie'); INSERT INTO albums VALUES (1,1,'Bloodywood',2011); INSERT INTO albums VALUES (2,1,'It Will Come',2013);...
SELECT COUNT(albums.id) FROM albums JOIN artists ON albums.artist_id = artists.id WHERE artists.region = 'South Asia' AND artists.genre = 'Indie' AND albums.release_year BETWEEN 2010 AND 2019;
List all public transportation vehicles that have not been inspected in the last 60 days
CREATE TABLE vehicle (vehicle_id INT,last_inspection_date DATE);
SELECT vehicle_id FROM vehicle WHERE last_inspection_date < DATE(NOW()) - INTERVAL 60 DAY;
What is the most common mental health condition treated in Africa?
CREATE TABLE conditions (condition_id INT,condition_name TEXT,prevalence FLOAT); INSERT INTO conditions (condition_id,condition_name,prevalence) VALUES (1,'Depression',0.3); INSERT INTO conditions (condition_id,condition_name,prevalence) VALUES (2,'Anxiety',0.25); CREATE TABLE treatments (treatment_id INT,condition_id ...
SELECT conditions.condition_name FROM conditions INNER JOIN (SELECT condition_id, COUNT(*) as treatment_count FROM treatments GROUP BY condition_id ORDER BY treatment_count DESC LIMIT 1) as subquery ON conditions.condition_id = subquery.condition_id;
How many volunteers signed up for each program in Q1 of 2022?
CREATE TABLE volunteers (volunteer_id INT,volunteer_name TEXT,program TEXT,volunteer_date DATE); INSERT INTO volunteers (volunteer_id,volunteer_name,program,volunteer_date) VALUES (1,'Alice','Feeding the Homeless','2022-01-05'); INSERT INTO volunteers (volunteer_id,volunteer_name,program,volunteer_date) VALUES (2,'Bob'...
SELECT program, COUNT(volunteer_name) as num_volunteers FROM volunteers WHERE EXTRACT(MONTH FROM volunteer_date) BETWEEN 1 AND 3 GROUP BY program;
How many new broadband subscribers have signed up in the state of California in the last 30 days?
CREATE TABLE subscribers (id INT,subscriber_type VARCHAR(50),subscribe_date DATE);
SELECT COUNT(*) FROM subscribers WHERE subscriber_type = 'broadband' AND subscribe_date >= CURDATE() - INTERVAL 30 DAY AND subscribe_date < CURDATE() AND state = 'California';
Identify the climate mitigation projects in Africa that were started between 2015 and 2018 and list their names and funding amounts.
CREATE TABLE climate_mitigation_projects (id INT,project_name VARCHAR(100),location VARCHAR(100),start_year INT,funding FLOAT); INSERT INTO climate_mitigation_projects (id,project_name,location,start_year,funding) VALUES (1,'Solar Power Plant','Africa',2016,50000000),(2,'Wind Farm','Africa',2014,30000000);
SELECT project_name, funding FROM climate_mitigation_projects WHERE location = 'Africa' AND start_year BETWEEN 2015 AND 2018;
What is the total number of medical supplies distributed by 'Doctors Without Borders' in 'Middle East' in the year 2020?
CREATE TABLE medical_supplies (id INT,distributor VARCHAR(255),location VARCHAR(255),quantity INT,distribution_date DATE); INSERT INTO medical_supplies (id,distributor,location,quantity,distribution_date) VALUES (1,'Doctors Without Borders','Middle East',500,'2020-01-01');
SELECT SUM(quantity) FROM medical_supplies WHERE distributor = 'Doctors Without Borders' AND location = 'Middle East' AND YEAR(distribution_date) = 2020;
How many multimodal trips were taken in London in the last week?
CREATE TABLE MM_Trips (id INT,trip_type VARCHAR(20),city VARCHAR(50),trips INT,date DATE); INSERT INTO MM_Trips (id,trip_type,city,trips,date) VALUES (1,'Bike-Transit','London',10000,'2022-02-01'),(2,'Bus-Subway','London',15000,'2022-02-02'),(3,'Car-Transit','London',12000,'2022-02-03'); ALTER TABLE MM_Trips ADD COLUMN...
SELECT SUM(total_trips) as total_trips FROM MM_Trips WHERE city = 'London' AND date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
What is the maximum number of union members per union type for the year 2021, based on the 'union_members_2021' table?
CREATE TABLE union_members_2021 (id INT,union_type VARCHAR(255),state VARCHAR(255),member_count INT); INSERT INTO union_members_2021 (id,union_type,state,member_count) VALUES (1,'Labor Union','California',5000),(2,'Trade Union','New York',7000),(3,'Professional Union','Texas',3000);
SELECT union_type, MAX(member_count) as max_members FROM union_members_2021 GROUP BY union_type;
What is the minimum number of participants in community development initiatives in rural India?
CREATE TABLE Community_Development_Initiatives (id INT,initiative_name TEXT,participants INT,location TEXT); INSERT INTO Community_Development_Initiatives (id,initiative_name,participants,location) VALUES (1,'Clean Water Access',150,'Rural India'),(2,'Education Center',200,'Urban India');
SELECT MIN(participants) FROM Community_Development_Initiatives WHERE location = 'Rural India';
Which sustainable beauty brands have a customer return rate over 20%?
CREATE TABLE BrandSales (Brand VARCHAR(50),ProductID INT,ProductName VARCHAR(50),UnitsSold INT,ReturnRate DECIMAL(3,1)); INSERT INTO BrandSales (Brand,ProductID,ProductName,UnitsSold,ReturnRate) VALUES ('EcoBeauty',6,'Reusable Makeup Pads',500,25.3); INSERT INTO BrandSales (Brand,ProductID,ProductName,UnitsSold,ReturnR...
SELECT Brand, AVG(ReturnRate) AS AvgReturnRate FROM BrandSales WHERE UnitsSold > 500 GROUP BY Brand HAVING AvgReturnRate > 20;
What is the total budget for programs with a budget over $5000?
CREATE TABLE Programs (id INT,program TEXT,budget DECIMAL(10,2)); INSERT INTO Programs (id,program,budget) VALUES (1,'Feeding the Hungry',5000.00),(2,'Clothing Drive',3000.00),(3,'Education',7000.00);
SELECT SUM(budget) FROM Programs WHERE budget > 5000;
List inclusive housing policies that were implemented before 2010.
CREATE TABLE InclusiveHousingPolicies (PolicyID INT,PolicyName VARCHAR(50),ImplementationDate DATE); INSERT INTO InclusiveHousingPolicies (PolicyID,PolicyName,ImplementationDate) VALUES (1,'Policy A','2008-01-01'),(2,'Policy B','2011-01-01'),(3,'Policy C','2009-06-15');
SELECT PolicyName FROM InclusiveHousingPolicies WHERE ImplementationDate < '2010-01-01';
What is the maximum response time for emergency calls in 'Toronto'?
CREATE TABLE emergency_calls (id INT,city VARCHAR(20),response_time INT);
SELECT MAX(response_time) FROM emergency_calls WHERE city = 'Toronto';
What is the average points scored by the Warriors in the 2021-2022 season?
CREATE TABLE teams (team_name VARCHAR(255),season_start_year INT,season_end_year INT); INSERT INTO teams (team_name,season_start_year,season_end_year) VALUES ('Warriors',2021,2022); CREATE TABLE games (team_name VARCHAR(255),opponent VARCHAR(255),points_scored INT);
SELECT AVG(points_scored) FROM games WHERE team_name = 'Warriors' AND season_start_year = 2021 AND season_end_year = 2022;
What is the policy type and effective date of policies with a risk score less than 700 and that have a claim in 2021?
CREATE TABLE Policy (PolicyID int,PolicyType varchar(50),EffectiveDate date,RiskScore int); CREATE TABLE Claim (ClaimID int,PolicyID int,ClaimDate date,ClaimAmount int,State varchar(50)); INSERT INTO Policy (PolicyID,PolicyType,EffectiveDate,RiskScore) VALUES (1,'Auto','2020-01-01',700),(2,'Home','2019-05-05',900),(3,'...
SELECT Policy.PolicyType, Policy.EffectiveDate FROM Policy INNER JOIN Claim ON Policy.PolicyID = Claim.PolicyID WHERE Policy.RiskScore < 700 AND Claim.ClaimDate BETWEEN '2021-01-01' AND '2021-12-31';
What is the average loan amount for socially responsible lending in Africa, for each year?
CREATE TABLE socially_responsible_lending (id INT,year INT,country VARCHAR(255),loan_amount DECIMAL(10,2));
SELECT year, AVG(loan_amount) FROM socially_responsible_lending WHERE country = 'Africa' GROUP BY year;
List countries with most satellites launched
CREATE TABLE satellites (satellite_id INT,launch_date DATE,country VARCHAR(20)); INSERT INTO satellites (satellite_id,launch_date,country) VALUES (1,'1999-01-01','USA'),(2,'2000-01-01','China');
SELECT country, COUNT(*) AS launched_satellites FROM satellites GROUP BY country ORDER BY launched_satellites DESC;
Delete a professional development record from the 'ProfessionalDevelopment' table
CREATE TABLE ProfessionalDevelopment (TeacherID int,Date date,ProfessionalDevelopmentScore int);
DELETE FROM ProfessionalDevelopment WHERE TeacherID = 5678 AND Date = '2022-10-01';
What is the total number of community policing interactions for each user, ordered by the total?
CREATE TABLE community_policing (id INT,user_id INT,interaction_type VARCHAR(255),interaction_count INT); INSERT INTO community_policing (id,user_id,interaction_type,interaction_count) VALUES (1,4001,'Community Meeting',3),(2,4002,'Foot Patrol',5),(3,4003,'Bicycle Patrol',4);
SELECT user_id, SUM(interaction_count) as total_interactions FROM community_policing GROUP BY user_id ORDER BY total_interactions DESC;
Find the top 5 most expensive strains sold in Oregon in Q3 2021, ordered by their maximum retail price.
CREATE TABLE strains (id INT,name TEXT,type TEXT,origin TEXT); INSERT INTO strains (id,name,type,origin) VALUES (1,'White Widow','Hybrid','Oregon'),(2,'Girl Scout Cookies','Hybrid','Oregon'),(3,'Blue Dream','Sativa','California'); CREATE TABLE sales (id INT,strain_id INT,retail_price DECIMAL,sale_date DATE,state TEXT);...
SELECT name, MAX(retail_price) FROM (SELECT name, retail_price, ROW_NUMBER() OVER (PARTITION BY name ORDER BY retail_price DESC) rn FROM sales WHERE state = 'Oregon' AND sale_date >= '2021-07-01' AND sale_date < '2021-10-01') tmp WHERE rn <= 5 GROUP BY name ORDER BY MAX(retail_price) DESC;
What is the maximum age of all stone artifacts in the 'artifact_analysis' table, grouped by culture?
CREATE TABLE artifact_analysis (id INT,artifact_name VARCHAR(50),material VARCHAR(50),age INT,culture VARCHAR(50)); INSERT INTO artifact_analysis (id,artifact_name,material,age,culture) VALUES (1,'flint_tool','stone',3000,'Native American');
SELECT culture, MAX(age) FROM artifact_analysis WHERE material = 'stone' GROUP BY culture;
What is the percentage of the population without health insurance, by state?
CREATE TABLE uninsured (state VARCHAR(2),pct_uninsured FLOAT); INSERT INTO uninsured (state,pct_uninsured) VALUES ('NY',10.5),('NJ',9.3),('CA',12.2),('FL',15.6),('TX',18.9);
SELECT state, (SUM(pct_uninsured) / COUNT(state) * 100) as pct_uninsured FROM uninsured GROUP BY state;
What is the maximum temperature in chemical storage facilities in Egypt?
CREATE TABLE chemical_storages (id INT,facility_name VARCHAR(100),country VARCHAR(50),temperature FLOAT); INSERT INTO chemical_storages (id,facility_name,country,temperature) VALUES (1,'Egypt Storage 1','Egypt',35.5),(2,'Egypt Storage 2','Egypt',37.3);
SELECT MAX(temperature) FROM chemical_storages WHERE country = 'Egypt';
What is the total number of streams in the United States in 2021?
CREATE TABLE UserLocation (UserID INT,Country VARCHAR(100),State VARCHAR(100));
SELECT SUM(StreamCount) FROM UserStreams US INNER JOIN UserLocation UL ON US.UserID = UL.UserID WHERE UL.Country = 'United States' AND YEAR(US.StreamDate) = 2021;
Who are the top 3 investors in terms of total investment in the renewable energy sector?
CREATE TABLE investors (investor_id INT,investor_name TEXT,country TEXT); CREATE TABLE investments (investment_id INT,investor_id INT,sector TEXT,amount FLOAT); INSERT INTO investors (investor_id,investor_name,country) VALUES (1,'Investor A','USA'),(2,'Investor B','Canada'),(3,'Investor C','China'),(4,'Investor D','Ger...
SELECT i.investor_name, SUM(amount) as total_investment FROM investors i JOIN investments j ON i.investor_id = j.investor_id WHERE j.sector = 'Renewable Energy' GROUP BY i.investor_name ORDER BY total_investment DESC LIMIT 3;
Insert a new artifact 'Bead' with 30 quantities into the 'site_j_artifacts' table.
CREATE TABLE site_j_artifacts (id INT PRIMARY KEY,site_id INT,artifact_type VARCHAR(50),quantity INT); INSERT INTO site_j_artifacts (id,site_id,artifact_type,quantity) VALUES (1,7,'Stone tool',15),(2,7,'Pottery shard',20),(3,7,'Bone fragment',5);
INSERT INTO site_j_artifacts (id, artifact_type, quantity) VALUES (4, 'Bead', 30);
What is the total number of fans registered for the 2023 NBA All-Star Game by gender?
CREATE TABLE IF NOT EXISTS fans (id INT,name VARCHAR(50),gender VARCHAR(50),game VARCHAR(50));
SELECT gender, COUNT(*) FROM fans WHERE game = '2023 NBA All-Star Game' GROUP BY gender;
What is the total CO2 emission reduction achieved by carbon offset initiatives in the energy sector?
CREATE TABLE Carbon_Offset_Initiatives (id INT,sector VARCHAR(20),CO2_reduction FLOAT); INSERT INTO Carbon_Offset_Initiatives (id,sector,CO2_reduction) VALUES (1,'Transportation',12.6),(2,'Energy',23.7),(3,'Industry',34.8);
SELECT SUM(CO2_reduction) FROM Carbon_Offset_Initiatives WHERE sector = 'Energy';