instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Find the number of cases and total billing amount for cases with a favorable outcome in California.
CREATE TABLE cases (case_id INT,state VARCHAR(2),outcome VARCHAR(10)); INSERT INTO cases (case_id,state,outcome) VALUES (1,'CA','Favorable'),(2,'CA','Unfavorable'),(3,'NY','Favorable'); CREATE TABLE case_outcomes (outcome_id INT,description VARCHAR(20)); INSERT INTO case_outcomes (outcome_id,description) VALUES (1,'Favorable'),(2,'Unfavorable');
SELECT COUNT(*), SUM(billing_amount) FROM cases INNER JOIN case_outcomes ON cases.outcome = case_outcomes.description WHERE state = 'CA' AND description = 'Favorable';
Identify the chemical product with the lowest sales in South Korea and its manufacturing site safety score.
CREATE TABLE korean_products (product_id INT,product_name TEXT,country TEXT,total_sales FLOAT,site_safety_score FLOAT); INSERT INTO korean_products (product_id,product_name,country,total_sales,site_safety_score) VALUES (1,'Product U','South Korea',45000,85.6),(2,'Product V','South Korea',35000,90.2),(3,'Product W','South Korea',50000,87.8),(4,'Product X','South Korea',40000,82.9);
SELECT product_name, total_sales, site_safety_score FROM korean_products WHERE country = 'South Korea' AND total_sales = (SELECT MIN(total_sales) FROM korean_products WHERE country = 'South Korea');
Show the innovation progress for chemical 103 over time, including its innovation score and ranking among other chemicals?
CREATE TABLE innovation_scores (chemical_id INT,innovation_score INT,measurement_date DATE); INSERT INTO innovation_scores (chemical_id,innovation_score,measurement_date) VALUES (103,65,'2019-01-01'),(103,68,'2019-04-01'),(103,72,'2019-07-01'),(103,75,'2019-10-01'),(101,60,'2019-01-01'),(101,63,'2019-04-01'),(101,66,'2019-07-01'),(101,69,'2019-10-01');
SELECT innovation_score, RANK() OVER (PARTITION BY measurement_date ORDER BY innovation_score DESC) as innovation_rank FROM innovation_scores WHERE chemical_id = 103
Update the 'safety_rating' in the 'chemicals' table to 85 for any chemical with an ID present in the 'hazardous_chemicals' table and a safety rating below 85.
CREATE TABLE hazardous_chemicals (chemical_id INT); CREATE TABLE chemicals (id INT,chemical_name VARCHAR(255),safety_rating INT); INSERT INTO hazardous_chemicals (chemical_id) VALUES (1),(3),(5); INSERT INTO chemicals (id,chemical_name,safety_rating) VALUES (1,'H2O',80),(2,'CO2',70),(3,'N2',60),(4,'O2',95),(5,'F2',75);
UPDATE chemicals SET safety_rating = 85 WHERE id IN (SELECT chemical_id FROM hazardous_chemicals) AND safety_rating < 85;
What is the total climate finance provided to Indigenous communities for climate communication initiatives between 2015 and 2020?
CREATE TABLE climate_finance (year INT,community VARCHAR(50),initiative VARCHAR(50),amount FLOAT); INSERT INTO climate_finance (year,community,initiative,amount) VALUES (2015,'Indigenous Community 1','climate communication',75000);
SELECT SUM(amount) FROM climate_finance WHERE initiative = 'climate communication' AND community LIKE '%Indigenous%' AND year BETWEEN 2015 AND 2020;
What is the total number of vaccinations administered in each province?
CREATE TABLE Vaccinations (Province VARCHAR(50),Vaccinations INT); INSERT INTO Vaccinations (Province,Vaccinations) VALUES ('Alberta',1000000),('British Columbia',1200000),('Ontario',2000000);
SELECT Province, SUM(Vaccinations) FROM Vaccinations GROUP BY Province;
What is the average number of funding rounds for companies in the fintech sector, founded by entrepreneurs over the age of 40?
CREATE TABLE companies (company_id INT,company_name TEXT,industry TEXT,founding_year INT,founder_age INT); INSERT INTO companies (company_id,company_name,industry,founding_year,founder_age) VALUES (1,'Fintech40','Fintech',2017,45); CREATE TABLE funding_records (funding_id INT,company_id INT,amount INT,round_number INT); INSERT INTO funding_records (funding_id,company_id,amount,round_number) VALUES (1,1,400000,1);
SELECT AVG(fr.round_number) FROM companies c JOIN funding_records fr ON c.company_id = fr.company_id WHERE c.industry = 'Fintech' AND c.founder_age > 40;
Determine the top 3 crops with the highest total quantity harvested by farmers in each country in 2021.
CREATE TABLE Farmers (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO Farmers (id,name,location) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE Crops (id INT,farmer_id INT,crop VARCHAR(50),quantity INT,harvest_date DATE,country VARCHAR(50)); INSERT INTO Crops (id,farmer_id,crop,quantity,harvest_date,country) VALUES (1,1,'Corn',100,'2021-01-01','USA'),(2,1,'Soybeans',150,'2021-05-10','USA'),(3,2,'Wheat',200,'2021-07-15','Canada');
SELECT crop, country, SUM(quantity) as total_quantity, RANK() OVER(PARTITION BY country ORDER BY SUM(quantity) DESC) as crop_rank FROM Crops WHERE harvest_date >= '2021-01-01' AND harvest_date < '2022-01-01' GROUP BY crop, country HAVING crop_rank <= 3;
What is the average size of all marine turtles?
CREATE TABLE marine_turtles (id INT,name TEXT,average_size FLOAT); INSERT INTO marine_turtles (id,name,average_size) VALUES (1,'Leatherback',200),(2,'Loggerhead',90),(3,'Green',120),(4,'Hawksbill',80),(5,'Olive Ridley',70);
SELECT AVG(average_size) FROM marine_turtles;
What's the name and market capitalization of digital assets in the 'Cosmos' network with a market capitalization above 300?
CREATE TABLE cosmos_digital_assets (id INT,name VARCHAR(255),network VARCHAR(255),market_cap DECIMAL(10,2)); INSERT INTO cosmos_digital_assets (id,name,network,market_cap) VALUES (1,'Asset1','cosmos',400),(2,'Asset2','cosmos',350);
SELECT name, market_cap FROM cosmos_digital_assets WHERE network = 'cosmos' AND market_cap > 300;
Which smart contract creator has the most contracts in the Gaming category?
CREATE TABLE smart_contracts (contract_id INT,name VARCHAR(255),creator_address VARCHAR(42),category VARCHAR(255)); INSERT INTO smart_contracts (contract_id,name,creator_address,category) VALUES (1,'CryptoKitties','0x1234567890123456789012345678901234567890','Gaming'),(2,'Axie Infinity','0x1234567890123456789012345678901234567890','Gaming'),(3,'Decentraland','0x987654321098765432109876543210987654321','Virtual Worlds');
SELECT creator_address, COUNT(*) AS contracts_created FROM smart_contracts WHERE category = 'Gaming' GROUP BY creator_address ORDER BY contracts_created DESC FETCH FIRST 1 ROW ONLY;
Which smart contracts have the highest gas consumption?
CREATE TABLE smart_contracts (id INT,name VARCHAR(50),gas_consumption INT);
SELECT name, gas_consumption FROM smart_contracts ORDER BY gas_consumption DESC LIMIT 10;
How many forest management practices are recorded in the 'tropical_forests'?
CREATE TABLE forest_management (id INT,forest_type VARCHAR(50),practice_count INT); INSERT INTO forest_management (id,forest_type,practice_count) VALUES (1,'Tropical Forests',45); INSERT INTO forest_management (id,forest_type,practice_count) VALUES (2,'Temperate Forests',34);
SELECT practice_count FROM forest_management WHERE forest_type = 'Tropical Forests';
What is the average height of trees in the 'BorealForest' table?
CREATE TABLE BorealForest (id INT,species VARCHAR(255),diameter FLOAT,height FLOAT,volume FLOAT); INSERT INTO BorealForest (id,species,diameter,height,volume) VALUES (1,'Pine',2.1,30,8.1); INSERT INTO BorealForest (id,species,diameter,height,volume) VALUES (2,'Spruce',2.5,35,10.5);
SELECT AVG(height) FROM BorealForest;
Find the average price of organic face creams sold in the United States
CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255),organic BOOLEAN,price DECIMAL(10,2)); CREATE TABLE sales (sale_id INT,product_id INT,quantity INT,country VARCHAR(255)); INSERT INTO products (product_id,product_name,category,organic,price) VALUES (1,'Organic Face Cream','Face Care',true,35.00),(2,'Regular Face Cream','Face Care',false,25.00); INSERT INTO sales (sale_id,product_id,quantity,country) VALUES (1,1,50,'USA'),(2,2,75,'USA');
SELECT AVG(products.price) FROM products JOIN sales ON products.product_id = sales.product_id WHERE products.organic = true AND sales.country = 'USA' AND category = 'Face Care';
List all products with a rating lower than the average rating for all products, ordered by rating in ascending order.
CREATE TABLE products (product_id INT,name VARCHAR(255),category VARCHAR(255),rating FLOAT);
SELECT * FROM products WHERE rating < (SELECT AVG(rating) FROM products) ORDER BY rating ASC;
What is the minimum price of cruelty-free skincare products sold in Italy?
CREATE TABLE skincare_sales(product_name TEXT,price DECIMAL(5,2),is_cruelty_free BOOLEAN,country TEXT); INSERT INTO skincare_sales VALUES ('Cleanser',10.99,true,'Italy'); INSERT INTO skincare_sales VALUES ('Toner',8.99,true,'Italy'); INSERT INTO skincare_sales VALUES ('Serum',15.99,false,'Italy');
SELECT MIN(price) FROM skincare_sales WHERE is_cruelty_free = true AND country = 'Italy';
Find the number of contracts awarded to company 'ABC Corp' in the year 2020
CREATE TABLE contracts (contract_id INT,contract_award_date DATE,company_name VARCHAR(255)); INSERT INTO contracts (contract_id,contract_award_date,company_name) VALUES (1,'2020-01-01','ABC Corp'); INSERT INTO contracts (contract_id,contract_award_date,company_name) VALUES (2,'2019-01-01','XYZ Inc');
SELECT COUNT(*) FROM contracts WHERE company_name = 'ABC Corp' AND YEAR(contract_award_date) = 2020;
What is the average transaction value in the last week, split by product category and customer demographics?
CREATE TABLE transactions (transaction_id INT,customer_id INT,product_id INT,category_id INT,transaction_date DATE,amount DECIMAL(10,2)); CREATE TABLE customers (customer_id INT,age INT,gender VARCHAR(10),location VARCHAR(255)); CREATE TABLE products (product_id INT,name VARCHAR(255),category_id INT);
SELECT c.age, c.gender, p.category_id, AVG(t.amount) as avg_transaction_value FROM transactions t INNER JOIN customers c ON t.customer_id = c.customer_id INNER JOIN products p ON t.product_id = p.product_id WHERE t.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY c.age, c.gender, p.category_id;
What is the total number of ports by region?
CREATE TABLE if not exists ports (id INT,name VARCHAR(255),country VARCHAR(255),region VARCHAR(255)); INSERT INTO ports (id,name,country,region) VALUES (1,'Port of Los Angeles','USA','North America'); INSERT INTO ports (id,name,country,region) VALUES (2,'Port of Rotterdam','Netherlands','Europe'); CREATE VIEW ports_by_region AS SELECT region,COUNT(*) as total FROM ports GROUP BY region;
SELECT * FROM ports_by_region;
What is the total number of songs released by each artist?
CREATE TABLE Songs (song_id INT,release_date DATE,artist_name VARCHAR(255),song_title VARCHAR(255)); INSERT INTO Songs (song_id,release_date,artist_name,song_title) VALUES (1,'2020-01-01','Arijit Singh','Tum Hi Ho'),(2,'2019-12-31','Billie Eilish','Bad Guy'),(3,'2020-02-14','Taylor Swift','Love Story');
SELECT artist_name, COUNT(song_id) as total_songs FROM Songs GROUP BY artist_name;
Create a table named 'Donations'
CREATE TABLE Donations(id INT PRIMARY KEY AUTO_INCREMENT,donor_name VARCHAR(255),donation_amount DECIMAL(10,2),donation_date DATE)
CREATE TABLE Donations( id INT PRIMARY KEY AUTO_INCREMENT, donor_name VARCHAR(255), donation_amount DECIMAL(10, 2), donation_date DATE)
What is the maximum donation amount for donors from India?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Country TEXT); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Doe','India'),(2,'Jane Smith','Canada'); CREATE TABLE Donations (DonationID INT,DonorID INT,Amount DECIMAL); INSERT INTO Donations (DonationID,DonorID,Amount) VALUES (1,1,500),(2,1,250),(3,2,300);
SELECT MAX(Donations.Amount) FROM Donors JOIN Donations ON Donors.DonorID = Donations.DonorID WHERE Donors.Country = 'India';
What is the maximum donation amount received from a single donor in a month, and how many times did they donate that month?
CREATE TABLE donations (donor_id INT,donation_date DATE,donation_amount FLOAT); INSERT INTO donations (donor_id,donation_date,donation_amount) VALUES (1,'2021-03-05',500.00),(1,'2021-03-15',250.00),(2,'2021-03-25',1000.00),(3,'2021-03-30',150.00);
SELECT MAX(donation_amount) AS max_donation, COUNT(*) AS donation_count FROM donations WHERE MONTH(donation_date) = 3 GROUP BY donor_id HAVING max_donation = (SELECT MAX(donation_amount) FROM donations WHERE MONTH(donation_date) = 3);
What is the total budget allocated to programs with a high community impact score?
CREATE TABLE programs (id INT,name TEXT,community_impact_score INT,budget REAL); INSERT INTO programs (id,name,community_impact_score,budget) VALUES (100,'Education',8,50000),(200,'Healthcare',5,75000),(300,'Environment',10,60000);
SELECT SUM(budget) FROM programs WHERE community_impact_score >= 8;
What is the total number of points scored by the LA Lakers in the 2020 NBA season?
CREATE TABLE team_points (id INT,team VARCHAR(50),sport VARCHAR(20),season VARCHAR(10),points INT);
SELECT SUM(points) FROM team_points WHERE team = 'LA Lakers' AND sport = 'NBA' AND season = '2020';
List the top 3 donor names and their total donation amounts for the 'Education' sector in the 'Americas' region for the year 2019, ordered by the donation amount in descending order.
CREATE TABLE Donors (donor_id INT,donor_name VARCHAR(255),donation_amount INT,sector VARCHAR(255),region VARCHAR(255),donation_date DATE); INSERT INTO Donors (donor_id,donor_name,donation_amount,sector,region,donation_date) VALUES (1,'DonorB',125000,'Education','Americas','2019-01-01');
SELECT donor_name, SUM(donation_amount) AS total_donation FROM Donors WHERE sector = 'Education' AND region = 'Americas' AND donation_date >= '2019-01-01' AND donation_date < '2020-01-01' GROUP BY donor_name ORDER BY total_donation DESC LIMIT 3;
Update the salaries of developers who work on accessibility projects to be 10% higher
CREATE TABLE developers (id INT,name VARCHAR(50),salary FLOAT,project VARCHAR(50)); INSERT INTO developers (id,name,salary,project) VALUES (1,'Alice',80000.0,'Accessibility'); INSERT INTO developers (id,name,salary,project) VALUES (2,'Bob',85000.0,'Machine Learning');
UPDATE developers SET salary = salary * 1.1 WHERE project = 'Accessibility';
How many accessible metro stations are there in Paris?
CREATE TABLE MetroStations (StationID int,Accessible bit); INSERT INTO MetroStations (StationID,Accessible) VALUES (1,1),(2,1),(3,0);
SELECT COUNT(*) FROM MetroStations WHERE Accessible = 1;
What is the earliest and latest trip_start_time for route 106?
CREATE TABLE trips (id INT,route_id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,passengers INT); INSERT INTO trips (id,route_id,trip_start_time,trip_end_time,passengers) VALUES (3,106,'2022-02-01 06:00:00','2022-02-01 07:00:00',50),(4,106,'2022-02-01 08:00:00','2022-02-01 09:00:00',55);
SELECT route_id, MIN(trip_start_time) as earliest_trip_start_time, MAX(trip_start_time) as latest_trip_start_time FROM trips WHERE route_id = 106;
Insert new records of fair labor practices for a specific factory.
CREATE TABLE fair_labor_practices (factory_id INT PRIMARY KEY,practice_date DATE,hours_worked INT,overtime_hours INT);
INSERT INTO fair_labor_practices (factory_id, practice_date, hours_worked, overtime_hours) VALUES (123, '2022-06-01', 8, 0), (123, '2022-06-02', 8, 0), (123, '2022-06-03', 8, 0);
What is the maximum wage in factories, by country, for the current year?
CREATE SCHEMA ethical_fashion; CREATE TABLE factories (factory_id INT,country VARCHAR(255),wage FLOAT,year INT); INSERT INTO factories VALUES (1,'USA',9.0,2022),(2,'USA',9.5,2021),(3,'USA',8.5,2020),(4,'Canada',12.0,2022),(5,'Canada',11.5,2021),(6,'Canada',10.5,2020);
SELECT country, MAX(wage) FROM ethical_fashion.factories WHERE year = 2022 GROUP BY country;
What is the minimum CO2 emissions per unit of sustainable material for brands operating in Spain?
CREATE TABLE brands (brand_id INT,brand_name TEXT,country TEXT); INSERT INTO brands (brand_id,brand_name,country) VALUES (1,'EcoBrand','Spain'),(2,'GreenFashion','France'),(5,'SpanishEthicalFashion','Spain'); CREATE TABLE material_usage (brand_id INT,material_type TEXT,quantity INT,co2_emissions INT); INSERT INTO material_usage (brand_id,material_type,quantity,co2_emissions) VALUES (1,'recycled_polyester',1200,2000),(1,'organic_cotton',800,1000),(5,'recycled_polyester',1800,3000);
SELECT MIN(mu.co2_emissions / mu.quantity) AS min_co2_emissions FROM brands b JOIN material_usage mu ON b.brand_id = mu.brand_id WHERE b.country = 'Spain';
Who are the top 5 suppliers of sustainable materials?
CREATE TABLE Suppliers (supplierID INT,name VARCHAR(50),material VARCHAR(20),sustainabilityScore INT); INSERT INTO Suppliers (supplierID,name,material,sustainabilityScore) VALUES (1,'GreenFibers','Organic Cotton',90),(2,'EcoFabrics','Recycled Polyester',85),(3,'SustainableTextiles','Hemp',95),(4,'FairTradeFibers','Organic Cotton',88),(5,'RecycledMaterialsInc','Recycled Denim',92);
SELECT name, sustainabilityScore FROM Suppliers ORDER BY sustainabilityScore DESC LIMIT 5;
How many customers have a credit card in the Kiva Community Credit Union?
CREATE TABLE credit_cards (customer_id INT,card_type VARCHAR(50)); INSERT INTO credit_cards (customer_id,card_type) VALUES (1,'Platinum'),(2,'Gold'),(3,'Platinum'),(4,'Silver');
SELECT COUNT(*) FROM credit_cards WHERE card_type IN ('Platinum', 'Gold');
What is the average financial wellbeing score for customers in Europe?
CREATE TABLE financial_wellbeing_eu (id INT,customer_id INT,country VARCHAR(255),score INT); INSERT INTO financial_wellbeing_eu (id,customer_id,country,score) VALUES (1,3001,'Germany',85),(2,3002,'France',80),(3,3003,'UK',90);
SELECT AVG(score) FROM financial_wellbeing_eu WHERE country IN ('Germany', 'France', 'UK');
Find the total number of volunteers and the number of volunteers who have completed at least one activity.
CREATE TABLE volunteers (volunteer_id INT,volunteer_name TEXT); INSERT INTO volunteers (volunteer_id,volunteer_name) VALUES (1,'Alice'); INSERT INTO volunteers (volunteer_id,volunteer_name) VALUES (2,'Bob'); INSERT INTO volunteers (volunteer_id,volunteer_name) VALUES (3,'Charlie'); CREATE TABLE volunteer_activities (volunteer_id INT,activity_id INT); INSERT INTO volunteer_activities (volunteer_id,activity_id) VALUES (1,1); INSERT INTO volunteer_activities (volunteer_id,activity_id) VALUES (1,2); INSERT INTO volunteer_activities (volunteer_id,activity_id) VALUES (2,3);
SELECT COUNT(DISTINCT volunteer_id) as total_volunteers, COUNT(DISTINCT volunteer_id) - COUNT(DISTINCT CASE WHEN activity_id IS NOT NULL THEN volunteer_id END) as completed_activities FROM volunteers LEFT JOIN volunteer_activities ON volunteers.volunteer_id = volunteer_activities.volunteer_id;
What is the average donation per donor in India?
CREATE TABLE donations (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,country TEXT); INSERT INTO donations VALUES (1,50.00,'2021-05-15','India'),(2,100.00,'2021-06-10','India'),(3,25.00,'2021-04-01','India');
SELECT AVG(donation_amount) FROM donations WHERE country = 'India';
Identify the number of genetic research projects in each country.
CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.projects (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO genetics.projects (id,name,country) VALUES (1,'ProjectX','UK'),(2,'ProjectY','Germany'),(3,'ProjectZ','UK'),(4,'ProjectA','USA'),(5,'ProjectB','France');
SELECT country, COUNT(*) FROM genetics.projects GROUP BY country;
What is the average budget allocated per department for the years 2021 and 2022?
CREATE TABLE Department (id INT,name VARCHAR(255),budget FLOAT,year INT); INSERT INTO Department (id,name,budget,year) VALUES (1,'Education',5000000,2021),(2,'Healthcare',7000000,2021),(3,'Transportation',8000000,2021),(4,'Education',6000000,2022),(5,'Healthcare',8000000,2022),(6,'Transportation',9000000,2022);
SELECT AVG(budget) FROM Department WHERE year IN (2021, 2022);
Which representatives have not sponsored any bills, displayed in ascending order of their IDs?
CREATE TABLE government_representatives (rep_id INT,rep_name TEXT,sponsored_bills INT); INSERT INTO government_representatives (rep_id,rep_name,sponsored_bills) VALUES (1,'Representative A',0),(2,'Representative B',3),(3,'Representative C',0),(4,'Representative D',2),(5,'Representative E',1);
SELECT rep_name FROM government_representatives WHERE sponsored_bills = 0 ORDER BY rep_id ASC;
Delete all grant records with a budget over $100,000.
CREATE TABLE grants (grant_id INT,title VARCHAR(50),budget INT); INSERT INTO grants VALUES (1,'Research Grant 1',50000); INSERT INTO grants VALUES (2,'Research Grant 2',120000); INSERT INTO grants VALUES (3,'Research Grant 3',75000);
DELETE FROM grants WHERE budget > 100000;
Show the number of unique students who have enrolled in the Data Science program in the last 3 years, by year.
CREATE TABLE students (id INT,name VARCHAR(100),enrollment_date DATE);
SELECT YEAR(enrollment_date) AS enrollment_year, COUNT(DISTINCT id) AS unique_students FROM students WHERE enrollment_date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR) AND program = 'Data Science' GROUP BY YEAR(enrollment_date);
What is the average number of research grants received by faculty members in the Engineering department in the last 3 years?
CREATE TABLE faculty_grants (id INT,name VARCHAR(50),department VARCHAR(50),grants_received INT,grant_year INT);
SELECT AVG(grants_received) FROM faculty_grants WHERE department = 'Engineering' AND grant_year BETWEEN YEAR(CURRENT_DATE) - 3 AND YEAR(CURRENT_DATE);
What is the average research grant amount awarded to professors in the Music department who have published at least one paper?
CREATE TABLE department (name VARCHAR(255),id INT);CREATE TABLE professor (name VARCHAR(255),department_id INT,grant_amount DECIMAL(10,2),publication_year INT);
SELECT AVG(grant_amount) FROM professor WHERE department_id IN (SELECT id FROM department WHERE name = 'Music') AND publication_year IS NOT NULL;
What is the total amount of research grants awarded to graduate students from underrepresented communities in the last 5 years, partitioned by their home departments?
CREATE TABLE grad_students (student_id INT,name VARCHAR(50),home_dept VARCHAR(50),underrepresented_community BOOLEAN); CREATE TABLE research_grants (grant_id INT,student_id INT,grant_amount DECIMAL(10,2),grant_date DATE);
SELECT home_dept, SUM(grant_amount) FROM research_grants rg JOIN grad_students gs ON rg.student_id = gs.student_id WHERE gs.underrepresented_community = TRUE AND rg.grant_date >= DATEADD(year, -5, GETDATE()) GROUP BY home_dept;
How many smart city projects were completed in the US and Canada?
CREATE TABLE smart_city_projects (id INT,name TEXT,country TEXT);
SELECT COUNT(*) FROM smart_city_projects WHERE country IN ('USA', 'Canada');
What is the total number of Green buildings in the United States certified by BREEAM?
CREATE TABLE green_buildings (id INT,project_name VARCHAR(100),certifier VARCHAR(50),country VARCHAR(50)); INSERT INTO green_buildings (id,project_name,certifier,country) VALUES (1,'Eco Tower','LEED','US'),(2,'Green Heights','BREEAM','UK'),(3,'Sustainable Plaza','GRIHA','India'),(4,'Green Skyscraper','BREEAM','US');
SELECT COUNT(*) FROM green_buildings WHERE certifier = 'BREEAM' AND country = 'US';
What is the average rating of hotels in the US that have a virtual tour?
CREATE TABLE hotels (id INT,name TEXT,country TEXT,rating FLOAT,virtual_tour BOOLEAN); INSERT INTO hotels (id,name,country,rating,virtual_tour) VALUES (1,'Hotel A','USA',4.5,true),(2,'Hotel B','USA',3.2,false),(3,'Hotel C','USA',4.7,true);
SELECT AVG(rating) FROM hotels WHERE country = 'USA' AND virtual_tour = true;
Delete all art pieces created before 1950 and after 2000
CREATE TABLE ArtPieces (id INT,title VARCHAR(50),galleryId INT,year INT,value INT,style VARCHAR(20)); INSERT INTO ArtPieces (id,title,galleryId,year,value,style) VALUES (1,'Piece 1',1,2000,10000,'Impressionism'),(2,'Piece 2',1,2010,15000,'Surrealism'),(3,'Piece 3',2,2020,20000,'Cubism'),(4,'Piece 4',3,1990,5000,'Surrealism'),(5,'Piece 5',NULL,1984,25000,'Impressionism'),(6,'Piece 6',NULL,2014,30000,'Abstract'),(7,'Piece 7',NULL,1964,15000,'Pop Art');
DELETE FROM ArtPieces WHERE year < 1950 OR year > 2000;
Delete all paintings created by the artist with ArtistID 2.
CREATE TABLE Artists (ArtistID INT,Name VARCHAR(50),Nationality VARCHAR(50)); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (1,'Vincent van Gogh','Dutch'); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (2,'Pablo Picasso','Spanish'); CREATE TABLE Paintings (PaintingID INT,Title VARCHAR(50),ArtistID INT,YearCreated INT); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated) VALUES (1,'The Starry Night',1,1889); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated) VALUES (2,'Guernica',2,1937);
DELETE FROM Paintings WHERE ArtistID = 2;
What is the total quantity of organic ingredients used in vegan dishes?
CREATE TABLE ingredient (ingredient_id INT,ingredient_name TEXT,organic_flag BOOLEAN); INSERT INTO ingredient (ingredient_id,ingredient_name,organic_flag) VALUES (1,'Spinach',true),(2,'Chicken',false); CREATE TABLE recipe (recipe_id INT,dish_id INT,ingredient_id INT,quantity INT); INSERT INTO recipe (recipe_id,dish_id,ingredient_id,quantity) VALUES (1,1,1,2),(2,2,2,1); CREATE TABLE dish (dish_id INT,dish_name TEXT,vegan_flag BOOLEAN,vendor_id INT); INSERT INTO dish (dish_id,dish_name,vegan_flag,vendor_id) VALUES (1,'Vegan Salad',true,1),(2,'Grilled Chicken',false,2);
SELECT i.ingredient_name, SUM(r.quantity) as total_quantity FROM ingredient i JOIN recipe r ON i.ingredient_id = r.ingredient_id JOIN dish d ON r.dish_id = d.dish_id WHERE d.vegan_flag = true AND i.organic_flag = true GROUP BY i.ingredient_name;
Find the total production of copper in Chile for the current year.
CREATE TABLE mineral_production (id INT,mine_id INT,location TEXT,year INT,production INT); INSERT INTO mineral_production (id,mine_id,location,year,production) VALUES (1,1,'Chile',2022,5000); INSERT INTO mineral_production (id,mine_id,location,year,production) VALUES (2,2,'Chile',2021,6000);
SELECT SUM(production) FROM mineral_production WHERE location = 'Chile' AND year = YEAR(CURRENT_DATE);
What is the maximum number of safety violations by a single worker in the past year?
CREATE TABLE worker (id INT,name TEXT,department TEXT,hire_date DATE); CREATE TABLE violation (id INT,worker_id INT,date DATE,description TEXT);
SELECT MAX(violation_count) as max_violations FROM (SELECT worker.name, COUNT(violation.id) as violation_count FROM worker INNER JOIN violation ON worker.id = violation.worker_id WHERE violation.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE GROUP BY worker.name) as subquery;
What is the total donation amount for each city?
CREATE TABLE Donors (DonorID INT,Name VARCHAR(50),City VARCHAR(50),State VARCHAR(2),Zip VARCHAR(10),DonationAmount DECIMAL(10,2)); CREATE TABLE Grants (GrantID INT,DonorID INT,NonprofitID INT,GrantAmount DECIMAL(10,2),Date DATE);
SELECT City, SUM(DonationAmount) FROM Donors D INNER JOIN Grants G ON D.DonorID = G.DonorID GROUP BY City;
Find the top 5 games by rating
CREATE TABLE games (game_id INT PRIMARY KEY,name VARCHAR(50),genre VARCHAR(50),rating DECIMAL(3,2));
SELECT * FROM (SELECT name, rating, ROW_NUMBER() OVER (ORDER BY rating DESC) as rn FROM games) t WHERE rn <= 5;
Decrease agricultural automation trends data for sensor_id 14 by 10% recorded before '2022-03-15'
CREATE TABLE automation_trends (sensor_id INT,trend_date DATE,automation_level INT); INSERT INTO automation_trends (sensor_id,trend_date,automation_level) VALUES (14,'2022-03-10',75),(14,'2022-03-12',80);
WITH updated_data AS (UPDATE automation_trends SET automation_level = automation_level - (automation_level * 0.1) WHERE sensor_id = 14 AND trend_date < '2022-03-15' RETURNING *) SELECT * FROM updated_data;
How many citizen feedback submissions were made for infrastructure services in New York City in the month of March in the year 2022?
CREATE TABLE feedback (submission_id INT,submission_date DATE,service VARCHAR(50),city VARCHAR(50)); INSERT INTO feedback (submission_id,submission_date,service,city) VALUES (1,'2022-03-01','Infrastructure','New York City'),(2,'2022-03-10','Infrastructure','New York City'),(3,'2022-03-20','Transportation','New York City');
SELECT COUNT(*) FROM feedback WHERE service = 'Infrastructure' AND city = 'New York City' AND EXTRACT(MONTH FROM submission_date) = 3 AND EXTRACT(YEAR FROM submission_date) = 2022;
What is the maximum rent for sustainable buildings in San Francisco?
CREATE TABLE Rents (RentID int,BuildingID int,Rent int,City varchar(20),Sustainable varchar(5)); CREATE TABLE Buildings (BuildingID int,Certification varchar(20)); INSERT INTO Rents (RentID,BuildingID,Rent,City,Sustainable) VALUES (1,1,2000,'San Francisco','Yes'); INSERT INTO Buildings (BuildingID,Certification) VALUES (1,'Green');
SELECT MAX(Rent) FROM Rents INNER JOIN Buildings ON Rents.BuildingID = Buildings.BuildingID WHERE Rents.City = 'San Francisco' AND Buildings.Certification IS NOT NULL;
How many sustainable sourcing audits were conducted in 'Florida'?
CREATE TABLE sourcing_audits (restaurant_name TEXT,location TEXT,audit_date DATE); INSERT INTO sourcing_audits (restaurant_name,location,audit_date) VALUES ('Restaurant A','Florida','2021-05-01'),('Restaurant B','California','2021-07-15'),('Restaurant C','Florida','2021-08-05');
SELECT COUNT(*) FROM sourcing_audits WHERE location = 'Florida';
What is the percentage of revenue by menu category for the past month?
CREATE TABLE restaurant_revenue (date DATE,menu_category VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO restaurant_revenue (date,menu_category,revenue) VALUES ('2022-01-01','Appetizers',500.00),('2022-01-01','Entrees',1000.00),('2022-01-01','Desserts',600.00),('2022-01-02','Appetizers',550.00),('2022-01-02','Entrees',1100.00),('2022-01-02','Desserts',650.00);
SELECT menu_category, SUM(revenue) as total_revenue, (SUM(revenue) / (SELECT SUM(revenue) FROM restaurant_revenue WHERE date BETWEEN '2022-01-01' AND '2022-01-31') * 100.00) as percentage_revenue FROM restaurant_revenue WHERE date BETWEEN '2022-01-01' AND '2022-01-31' GROUP BY menu_category;
List all satellites launched by year and country in the satellite_launches_by_year_country table?
CREATE TABLE satellite_launches_by_year_country (id INT,year INT,country VARCHAR(30),num_satellites INT); INSERT INTO satellite_launches_by_year_country (id,year,country,num_satellites) VALUES (1,1958,'USA',1),(2,1960,'USA',2),(3,1962,'USA',6),(4,1977,'USSR',3),(5,2000,'Russia',12),(6,2020,'USA',93),(7,2021,'China',48);
SELECT year, country, SUM(num_satellites) FROM satellite_launches_by_year_country GROUP BY year, country;
What is the minimum and maximum speed of spacecraft launched by SpaceX?
CREATE TABLE spacecraft (id INT,name VARCHAR(255),launch_company VARCHAR(255),launch_date DATE,max_speed FLOAT);
SELECT MIN(max_speed) as min_speed, MAX(max_speed) as max_speed FROM spacecraft WHERE launch_company = 'SpaceX';
Which spacecraft models have been used for missions to Jupiter?
CREATE TABLE Spacecraft (SpacecraftID INT,Name VARCHAR(50),Manufacturer VARCHAR(50)); CREATE TABLE SpacecraftMissions (MissionID INT,SpacecraftID INT,Destination VARCHAR(50));
SELECT Spacecraft.Name FROM Spacecraft INNER JOIN SpacecraftMissions ON Spacecraft.SpacecraftID = SpacecraftMissions.SpacecraftID WHERE SpacecraftMissions.Destination = 'Jupiter';
What is the average time to resolution for high severity incidents in the energy sector?
CREATE TABLE incidents (incident_id INT,incident_severity VARCHAR(255),incident_sector VARCHAR(255),incident_resolution_time INT);
SELECT AVG(incident_resolution_time) FROM incidents WHERE incident_severity = 'High' AND incident_sector = 'Energy';
Which countries have the most vulnerabilities reported in the last month?
CREATE TABLE vulnerabilities (id INT,country VARCHAR(50),reported_date DATE,severity INT); INSERT INTO vulnerabilities (id,country,reported_date,severity) VALUES (1,'USA','2022-01-01',5),(2,'Canada','2022-01-05',3),(3,'Mexico','2022-01-10',7); CREATE TABLE countries (id INT,name VARCHAR(50)); INSERT INTO countries (id,name) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'Brazil');
SELECT c.name, COUNT(v.id) as num_vulnerabilities FROM countries c LEFT JOIN vulnerabilities v ON c.name = v.country AND v.reported_date >= DATEADD(month, -1, GETDATE()) GROUP BY c.name ORDER BY num_vulnerabilities DESC;
Delete all records from the inventory table where the quantity is less than 10
CREATE TABLE inventory (id INT,garment_id INT,quantity INT);
DELETE FROM inventory WHERE quantity < 10;
List all underwriting departments in 'Ontario' and 'Quebec' with their count?
CREATE TABLE underwriting (id INT,department TEXT,city TEXT,province TEXT); INSERT INTO underwriting (id,department,city,province) VALUES (1,'Department A','Toronto','ON'); INSERT INTO underwriting (id,department,city,province) VALUES (2,'Department B','Montreal','QC'); INSERT INTO underwriting (id,department,city,province) VALUES (3,'Department C','Ottawa','ON');
SELECT department, COUNT(*) FROM underwriting WHERE province IN ('ON', 'QC') GROUP BY department;
What is the minimum and maximum age of policyholders who have a policy with a premium between $1500 and $5000?
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),(4,25,2000);
SELECT MIN(Age), MAX(Age) FROM Policyholders WHERE Premium BETWEEN 1500 AND 5000;
Which autonomous driving research studies were conducted in Japan?
CREATE TABLE Research (StudyID int,StudyName varchar(50),Location varchar(50)); INSERT INTO Research (StudyID,StudyName,Location) VALUES (1,'Autonomous Driving in Cities','Japan'),(2,'Impact of Autonomous Driving on Traffic','USA'),(3,'Safety of Autonomous Vehicles','Germany');
SELECT StudyName FROM Research WHERE Location = 'Japan';
Find the vessel with the highest average speed in the Vessel table.
CREATE TABLE Vessel (ID INT,Name TEXT,AverageSpeed DECIMAL); INSERT INTO Vessel (ID,Name,AverageSpeed) VALUES (1,'VesselA',20.5),(2,'VesselB',22.3),(3,'VesselC',18.9);
SELECT Name FROM (SELECT Name, AverageSpeed, ROW_NUMBER() OVER (ORDER BY AverageSpeed DESC) AS Rank FROM Vessel) AS RankedVessels WHERE Rank = 1;
Insert a new record in the "vessels" table for a vessel named "Mary Ann" with id 101, built in 2015, and a gross tonnage of 1500
CREATE TABLE vessels (id INT,name TEXT,build_year INT,gross_tonnage INT);
INSERT INTO vessels (id, name, build_year, gross_tonnage) VALUES (101, 'Mary Ann', 2015, 1500);
What is the average weight of a cargo in the 'cargo_tracking' table?
CREATE TABLE cargo_tracking (cargo_id INT,cargo_type VARCHAR(50),weight FLOAT); INSERT INTO cargo_tracking (cargo_id,cargo_type,weight) VALUES (1,'CargoType1',5000),(2,'CargoType2',7000),(3,'CargoType3',6000);
SELECT AVG(weight) FROM cargo_tracking;
What is the total cargo weight transported by each vessel in the last quarter?
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(255)); INSERT INTO Vessels (VesselID,VesselName) VALUES (1,'VesselA'),(2,'VesselB'),(3,'VesselC'); CREATE TABLE Cargo (CargoID INT,VesselID INT,CargoWeight INT,TransportTime TIMESTAMP); INSERT INTO Cargo (CargoID,VesselID,CargoWeight,TransportTime) VALUES (1,1,5000,'2022-01-01 10:00:00'),(2,2,7000,'2022-03-15 14:30:00'),(3,3,6000,'2022-04-08 08:00:00');
SELECT V.VesselName, SUM(C.CargoWeight) FROM Vessels V INNER JOIN Cargo C ON V.VesselID = C.VesselID WHERE C.TransportTime BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 MONTH) AND CURRENT_TIMESTAMP GROUP BY V.VesselName;
What is the total number of cargo and tanker vessels in the 'fleet_inventory' table?
CREATE TABLE fleet_inventory (id INT,vessel_name TEXT,type TEXT,quantity INT); INSERT INTO fleet_inventory (id,vessel_name,type,quantity) VALUES (1,'Cargo Ship 1','Cargo',20),(2,'Tanker Vessel 1','Tanker',30);
SELECT SUM(quantity) FROM fleet_inventory WHERE type IN ('Cargo', 'Tanker');
What is the earliest artwork year?
CREATE TABLE artworks (id INT PRIMARY KEY,title VARCHAR(255),artist VARCHAR(255),year INT);
SELECT MIN(year) FROM artworks;
What is the average recycling rate in the state of California for the year 2020?
CREATE TABLE recycling_rates (state VARCHAR(20),year INT,recycling_rate FLOAT); INSERT INTO recycling_rates (state,year,recycling_rate) VALUES ('California',2020,55.5);
SELECT recycling_rate FROM recycling_rates WHERE state = 'California' AND year = 2020;
What is the progress of circular economy initiatives in Southeast Asia?
CREATE TABLE circular_economy (country VARCHAR(255),initiative VARCHAR(255),progress FLOAT); INSERT INTO circular_economy (country,initiative,progress) VALUES ('Indonesia','Waste-to-Energy',0.60),('Singapore','Recycling Program',0.85),('Thailand','Circular Economy Policy',0.55);
SELECT AVG(progress) FROM circular_economy WHERE country IN ('Indonesia', 'Singapore', 'Thailand');
List the top 5 most prolific explainable AI researchers and their publications.
CREATE TABLE researcher_publications (id INT,researcher_id INT,title VARCHAR(255));
SELECT r.researcher_name, COUNT(p.title) as num_publications FROM researchers r JOIN researcher_publications rp ON r.id = rp.researcher_id JOIN publications p ON rp.id = p.id GROUP BY r.researcher_name ORDER BY num_publications DESC;
Which AI research topics have more than 5 papers published in 2021, but do not have any papers published in the top 10 AI journals?
CREATE TABLE ai_topics (id INT,topic VARCHAR(100),papers INT,journal_rank INT);
SELECT topic FROM ai_topics WHERE papers > 5 AND year = 2021 AND journal_rank IS NULL;
Show the total cost of agricultural innovation projects by implementing organization from the 'rural_development' database
CREATE TABLE agricultural_projects (id INT,name VARCHAR(50),cost DECIMAL(10,2),type VARCHAR(20),implementing_organization VARCHAR(50)); INSERT INTO agricultural_projects (id,name,cost,type,implementing_organization) VALUES (1,'Precision Farming',15000.00,'Innovation','Agritech Inc.'); INSERT INTO agricultural_projects (id,name,cost,type,implementing_organization) VALUES (2,'Vertical Farming',22000.00,'Innovation','Farming Future'); INSERT INTO agricultural_projects (id,name,cost,type,implementing_organization) VALUES (3,'Organic Farming',18000.00,'Traditional','Cooperative Farm');
SELECT implementing_organization, SUM(cost) FROM agricultural_projects GROUP BY implementing_organization;
Which community development initiatives were implemented in India's rural areas between 2015 and 2017, and what was their combined budget?
CREATE TABLE community_initiatives (initiative VARCHAR(50),country VARCHAR(50),start_year INT,end_year INT,budget FLOAT); INSERT INTO community_initiatives (initiative,country,start_year,end_year,budget) VALUES ('Rural Employment Scheme','India',2015,2017,50000000),('Rural Housing Scheme','India',2015,2017,75000000);
SELECT initiative, SUM(budget) FROM community_initiatives WHERE country = 'India' AND start_year BETWEEN 2015 AND 2017 AND end_year BETWEEN 2015 AND 2017 GROUP BY initiative;
Add a new coldwater fish species 'Trout' to fish_species table.
CREATE TABLE fish_species (id INT,name VARCHAR(255),species_type VARCHAR(255)); INSERT INTO fish_species (id,name,species_type) VALUES (1,'Salmon','Coldwater'),(2,'Tilapia','Tropical');
INSERT INTO fish_species (name, species_type) VALUES ('Trout', 'Coldwater');
What is the maximum price per gram of hybrid strains sold in Oregon dispensaries?
CREATE TABLE strains (id INT,name VARCHAR(255),type VARCHAR(255)); CREATE TABLE dispensaries (id INT,name VARCHAR(255),state VARCHAR(255)); CREATE TABLE sales (id INT,strain_id INT,dispensary_id INT,price DECIMAL(10,2),quantity INT); INSERT INTO strains (id,name,type) VALUES (1,'Girl Scout Cookies','Hybrid'); INSERT INTO dispensaries (id,name,state) VALUES (1,'Green Mart','Oregon'); INSERT INTO sales (id,strain_id,dispensary_id,price,quantity) VALUES (1,1,1,12.00,100);
SELECT MAX(sales.price) FROM sales JOIN strains ON sales.strain_id = strains.id JOIN dispensaries ON sales.dispensary_id = dispensaries.id WHERE strains.type = 'Hybrid' AND dispensaries.state = 'Oregon';
What are the names and funding of mitigation projects in India that have funding greater than $500,000?
CREATE TABLE mitigation_projects (id INT,project_name VARCHAR(50),funding INT,country VARCHAR(50),sector VARCHAR(50)); INSERT INTO mitigation_projects (id,project_name,funding,country,sector) VALUES (1,'Wind Farm',1200000,'Germany','Renewable Energy'); INSERT INTO mitigation_projects (id,project_name,funding,country,sector) VALUES (2,'Solar Panel Installation',800000,'Spain','Renewable Energy'); INSERT INTO mitigation_projects (id,project_name,funding,country,sector) VALUES (3,'Smart Grid',600000,'India','Energy Efficiency'); INSERT INTO mitigation_projects (id,project_name,funding,country,sector) VALUES (4,'Carbon Capture',700000,'Canada','Carbon Capture');
SELECT project_name, funding FROM mitigation_projects WHERE country = 'India' AND funding > 500000;
What is the total number of COVID-19 cases in Oceania in 2021?
CREATE TABLE covid (country VARCHAR(255),region VARCHAR(255),year INT,cases INT); INSERT INTO covid (country,region,year,cases) VALUES ('Country A','Oceania',2021,100),('Country B','Oceania',2021,150);
SELECT SUM(cases) FROM covid WHERE region = 'Oceania' AND year = 2021;
What is the maximum funding amount received by a startup founded by a person of color in the renewable energy sector?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_year INT,founder_race TEXT); INSERT INTO companies (id,name,industry,founding_year,founder_race) VALUES (1,'SolarPioneer','Renewable Energy',2018,'African American'); INSERT INTO companies (id,name,industry,founding_year,founder_race) VALUES (2,'WindForce','Renewable Energy',2019,'Asian'); CREATE TABLE funding (company_id INT,amount INT,funding_round TEXT); INSERT INTO funding (company_id,amount,funding_round) VALUES (1,10000000,'Series B'); INSERT INTO funding (company_id,amount,funding_round) VALUES (2,7000000,'Series A');
SELECT MAX(funding.amount) FROM companies JOIN funding ON companies.id = funding.company_id WHERE companies.industry = 'Renewable Energy' AND companies.founder_race IS NOT NULL;
What is the total funding received by startups in the innovation sector?
CREATE TABLE startups(id INT,name TEXT,sector TEXT,funding FLOAT); INSERT INTO startups VALUES (1,'Acme Inc','Technology',2000000); INSERT INTO startups VALUES (2,'Beta Corp','Retail',3000000); INSERT INTO startups VALUES (3,'Gamma Start','Innovation',5000000);
SELECT SUM(funding) FROM startups WHERE sector = 'Innovation';
What is the total production of maize in East African indigenous food systems?
CREATE TABLE MaizeProduction (Location VARCHAR(20),System VARCHAR(20),Quantity FLOAT); INSERT INTO MaizeProduction (Location,System,Quantity) VALUES ('Kenya','Indigenous Food Systems',12000),('Tanzania','Indigenous Food Systems',18000),('Uganda','Indigenous Food Systems',15000);
SELECT SUM(Quantity) FROM MaizeProduction WHERE Location = 'Kenya' OR Location = 'Tanzania' OR Location = 'Uganda' AND System = 'Indigenous Food Systems';
What is the total budget allocated for accommodations and support programs in the West?
CREATE TABLE Accommodations (ID INT,Type VARCHAR(50),Cost FLOAT,Region VARCHAR(50)); INSERT INTO Accommodations (ID,Type,Cost,Region) VALUES (1,'Note-taking Services',20000.0,'West'),(2,'Accessible Furniture',25000.0,'West'); CREATE TABLE SupportPrograms (ID INT,Type VARCHAR(50),Cost FLOAT,Region VARCHAR(50)); INSERT INTO SupportPrograms (ID,Type,Cost,Region) VALUES (1,'Assistive Technology Grant',30000.0,'West'),(2,'Disability Awareness Training',35000.0,'West');
SELECT SUM(A.Cost) + SUM(S.Cost) FROM Accommodations A, SupportPrograms S WHERE A.Region = 'West' AND S.Region = 'West';
List the dapps that have deployed the most smart contracts in the 'Solana' network.
CREATE TABLE solana_dapps (dapp_name VARCHAR(20),network VARCHAR(20),smart_contracts INT); INSERT INTO solana_dapps (dapp_name,network,smart_contracts) VALUES ('Serum','Solana',50),('Raydium','Solana',60),('Orca','Solana',70);
SELECT dapp_name, network, smart_contracts, RANK() OVER (ORDER BY smart_contracts DESC) as rank FROM solana_dapps WHERE network = 'Solana';
What is the total value of all transactions in the 'stablecoin' category?
CREATE TABLE transactions (id INT,tx_type VARCHAR(10),tx_category VARCHAR(30),tx_amount FLOAT,tx_time TIMESTAMP); INSERT INTO transactions (id,tx_type,tx_category,tx_amount,tx_time) VALUES (9,'transfer','stablecoin',100.0,'2022-01-05 10:00:00'); INSERT INTO transactions (id,tx_type,tx_category,tx_amount,tx_time) VALUES (10,'exchange','crypto',200.0,'2022-01-06 11:00:00');
SELECT SUM(tx_amount) as total_stablecoin_value FROM transactions WHERE tx_category = 'stablecoin';
What is the CO2 sequestration potential for mangrove forests in 2025?
CREATE TABLE mangroves (id INT,year INT,sequestration FLOAT);
SELECT sequestration FROM mangroves WHERE year = 2025 AND id = (SELECT MAX(id) FROM mangroves WHERE year < 2025);
What is the total population of all wildlife species in 2020?
CREATE TABLE wildlife (id INT,species VARCHAR(255),year INT,population INT); INSERT INTO wildlife (id,species,year,population) VALUES (1,'Deer',2018,75),(2,'Bear',2019,60),(3,'Elk',2020,45),(4,'Wolf',2020,40),(5,'Moose',2020,55);
SELECT SUM(population) as total_population FROM wildlife WHERE year = 2020;
List all unique artifact materials and their average analysis costs
CREATE TABLE artifact_materials (id INT,name VARCHAR(255)); CREATE TABLE artifact_analysis (id INT,artifact_material_id INT,cost FLOAT);
SELECT artifact_materials.name, AVG(artifact_analysis.cost) FROM artifact_materials
List the number of rural hospitals in each state, excluding hospitals with less than 50 beds.
CREATE TABLE hospitals (hospital_id INT,hospital_name TEXT,beds INT,rural BOOLEAN,state_id INT); INSERT INTO hospitals (hospital_id,hospital_name,beds,rural,state_id) VALUES (1,'Hospital A',100,true,1); CREATE TABLE states (state_id INT,state TEXT); INSERT INTO states (state_id,state) VALUES (1,'Alabama'),(2,'Alaska');
SELECT states.state, COUNT(hospitals.hospital_id) hospital_count FROM hospitals JOIN states ON hospitals.state_id = states.state_id WHERE hospitals.rural = true AND hospitals.beds >= 50 GROUP BY states.state;
List the top 3 states with highest prevalence of diabetes in rural areas?
USE rural_healthcare; CREATE TABLE DiabetesPrevalence (id INT,state VARCHAR(100),rural BOOLEAN,prevalence DECIMAL(5,2)); INSERT INTO DiabetesPrevalence VALUES (1,'California',true,9.5),(2,'Texas',true,11.2),(3,'Florida',true,8.8),(4,'California',false,7.8),(5,'Texas',false,9.1),(6,'Florida',false,7.3); CREATE VIEW DiabetesPrevalence_rural AS SELECT * FROM DiabetesPrevalence WHERE rural = true;
SELECT state, AVG(prevalence) as avg_prevalence FROM DiabetesPrevalence_rural GROUP BY state ORDER BY avg_prevalence DESC LIMIT 3;
Update the ESG score for an investment in the table.
CREATE TABLE investments_scores (id INT,investment_id INT,ESG_score FLOAT); INSERT INTO investments_scores (id,investment_id,ESG_score) VALUES (1,1,70),(2,2,45),(3,3,80),(4,4,60),(5,5,40);
UPDATE investments_scores SET ESG_score = 75 WHERE investment_id = 2;
What are the cybersecurity policies of countries in the European Union?
CREATE TABLE cybersecurity_policies (id INT,country VARCHAR(50),policy TEXT);
SELECT * FROM cybersecurity_policies WHERE country LIKE 'EU%';
List the unique artists who have released songs in the rock genre.
CREATE TABLE song_releases (song_id INT,artist_name VARCHAR(50),genre VARCHAR(20));
SELECT DISTINCT artist_name FROM song_releases WHERE genre = 'rock';