instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the adoption rate of autonomous vehicles in urban areas?
CREATE TABLE areas (id INT,name VARCHAR(50)); CREATE TABLE autonomous_vehicles (id INT,area_id INT,vehicle_count INT); INSERT INTO areas (id,name) VALUES (1,'Urban'),(2,'Suburban'),(3,'Rural'); INSERT INTO autonomous_vehicles (id,area_id,vehicle_count) VALUES (1,1,2000),(2,2,1000),(3,3,500);
SELECT 'Urban', (SUM(av.vehicle_count) / (SELECT SUM(vehicle_count) FROM autonomous_vehicles)) * 100.0 AS adoption_rate FROM autonomous_vehicles av WHERE av.area_id = 1;
What is the average number of natural disasters per year in the 'pacific' and 'atlantic' zones?
CREATE TABLE natural_disasters (id INT,zone VARCHAR(10),year INT,num_disasters INT); INSERT INTO natural_disasters (id,zone,year,num_disasters) VALUES (1,'pacific',2020,3),(2,'atlantic',2020,5),(3,'pacific',2019,4),(4,'atlantic',2019,6);
SELECT AVG(num_disasters) FROM natural_disasters WHERE zone IN ('pacific', 'atlantic') GROUP BY year;
Identify the average capacity building expenditure per nonprofit in 'region_EU' over the last year.
CREATE TABLE nonprofit (nonprofit_id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO nonprofit (nonprofit_id,name,region) VALUES (1,'Greenpeace EU','region_EU'); INSERT INTO nonprofit (nonprofit_id,name,region) VALUES (2,'Amnesty International EU','region_EU'); CREATE TABLE expenditure (expenditure_id INT,nonprof...
SELECT AVG(e.amount) as avg_capacity_expenditure FROM expenditure e INNER JOIN nonprofit n ON e.nonprofit_id = n.nonprofit_id WHERE n.region = 'region_EU' AND e.category = 'capacity building' AND e.expenditure_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
Insert data into the 'military_equipment' table
CREATE TABLE military_equipment (equipment_id INT,name VARCHAR(255),type VARCHAR(255),country_of_origin VARCHAR(255),year INT); INSERT INTO military_equipment (equipment_id,name,type,country_of_origin,year) VALUES (1,'M1 Abrams','Tank','USA',1980);
INSERT INTO military_equipment (equipment_id, name, type, country_of_origin, year) VALUES (2, 'Leopard 2', 'Tank', 'Germany', 1979);
What is the total fare collected on weekdays for route 5?
CREATE TABLE Routes (id INT,name VARCHAR(255),type VARCHAR(255),length_miles DECIMAL(5,2),weekday_frequency INT); INSERT INTO Routes (id,name,type,length_miles,weekday_frequency) VALUES (5,'Green Line','Light Rail',12.3,150); CREATE TABLE Fares (id INT,trip_id INT,fare_amount DECIMAL(5,2),collected BOOLEAN,collected_on...
SELECT SUM(Fares.fare_amount) FROM Fares JOIN Trips ON Fares.trip_id = Trips.id JOIN Routes ON Trips.route_id = Routes.id WHERE Routes.id = 5 AND DAYOFWEEK(collected_on) < 6;
Insert new records into the "team_achievements" table with the following data: (1, 'Speedrun Record', '2022-02-01'), (2, 'First Blood', '2022-02-02')
CREATE TABLE team_achievements (team_id INT,achievement_name VARCHAR(50),achievement_date DATE);
WITH cte AS (VALUES (1, 'Speedrun Record', '2022-02-01'), (2, 'First Blood', '2022-02-02')) INSERT INTO team_achievements (team_id, achievement_name, achievement_date) SELECT * FROM cte;
How many more tourists visited Africa than Australia in 2019?
CREATE TABLE tourists (id INT,continent VARCHAR(50),country VARCHAR(50),visitors INT,year INT); INSERT INTO tourists (id,continent,country,visitors,year) VALUES (1,'Africa','Egypt',3000,2019),(2,'Australia','Sydney',2500,2019);
SELECT t1.visitors - t2.visitors FROM tourists t1 INNER JOIN tourists t2 ON t1.year = t2.year WHERE t1.continent = 'Africa' AND t2.continent = 'Australia';
How many coal mines are there in the Appalachian region with more than 500 employees?
CREATE TABLE Mines (MineID INT,Region VARCHAR(20),NumberOfEmployees INT);
SELECT COUNT(*) FROM Mines WHERE Region = 'Appalachian' AND NumberOfEmployees > 500;
What is the average cargo capacity of vessels from Greece?
CREATE TABLE Vessels (ID VARCHAR(10),Name VARCHAR(20),Type VARCHAR(20),Cargo_Capacity FLOAT,Registered_Country VARCHAR(20)); INSERT INTO Vessels (ID,Name,Type,Cargo_Capacity,Registered_Country) VALUES ('1','Vessel A','Cargo',12000.0,'Greece'),('2','Vessel B','Tanker',15000.0,'Canada'),('3','Vessel C','Bulk Carrier',180...
SELECT AVG(Cargo_Capacity) FROM Vessels WHERE Registered_Country = 'Greece';
How many graduate students in each department have published papers?
CREATE SCHEMA publications;CREATE TABLE student_publications(student_name TEXT,department TEXT,num_publications INTEGER);INSERT INTO student_publications(student_name,department,num_publications)VALUES('Nancy','Physics',5),('Oliver','Physics',2),('Penny','Computer Science',1);
SELECT department,COUNT(DISTINCT student_name) FROM publications.student_publications GROUP BY department;
What is the average certification level for properties in the table 'sustainable_urbanism' that have a certification?
CREATE TABLE sustainable_urbanism (id INT,certification VARCHAR(10)); INSERT INTO sustainable_urbanism (id,certification) VALUES (1,'gold'),(2,'platinum'),(3,'bronze'),(4,'silver'),(5,NULL);
SELECT AVG(CASE WHEN certification IS NOT NULL THEN 1 ELSE 0 END) FROM sustainable_urbanism;
Find the top 5 cities with the longest average emergency response time in the state of New York.
CREATE TABLE emergency_calls (id INT,city VARCHAR(20),state VARCHAR(20),response_time INT); INSERT INTO emergency_calls (id,city,state,response_time) VALUES (1,'New York City','New York',120),(2,'Buffalo','New York',90),(3,'Rochester','New York',100),(4,'Yonkers','New York',110),(5,'Syracuse','New York',130);
SELECT city, AVG(response_time) as avg_response_time FROM emergency_calls WHERE state = 'New York' GROUP BY city ORDER BY avg_response_time DESC LIMIT 5;
What is the total revenue from ticket sales for each region?
CREATE TABLE ticket_sales (ticket_sale_id INT,region_id INT,revenue INT); INSERT INTO ticket_sales VALUES (1,1,15000),(2,2,12000),(3,1,16000),(4,3,20000),(5,2,13000);
SELECT region_id, SUM(revenue) FROM ticket_sales GROUP BY region_id;
What is the total budget allocation for healthcare for each territory, in descending order?
CREATE TABLE territories (territory_name VARCHAR(50),budget_allocation INT); INSERT INTO territories VALUES ('Territory A',12000000); INSERT INTO territories VALUES ('Territory B',10000000); INSERT INTO territories VALUES ('Territory C',9000000);
SELECT territory_name, SUM(budget_allocation) OVER (PARTITION BY territory_name) as total_budget_allocation FROM territories ORDER BY total_budget_allocation DESC;
What is the total number of space missions for each country?
CREATE TABLE space_missions (id INT,mission_name VARCHAR(255),launch_date DATE,country VARCHAR(255)); INSERT INTO space_missions (id,mission_name,launch_date,country) VALUES (1,'Apollo 11','1969-07-16','USA'),(2,'Mars Rover','2004-01-04','USA'),(3,'Soyuz T-15','1986-03-13','Russia');
SELECT country, COUNT(*) OVER (PARTITION BY country) as TotalMissions FROM space_missions;
Which eSports players have the most wins in "League of Legends" tournaments?
CREATE TABLE Players (PlayerName VARCHAR(255),TournamentWins INT); INSERT INTO Players (PlayerName,TournamentWins) VALUES ('PlayerA',12),('PlayerB',15),('PlayerC',18),('PlayerD',9),('PlayerE',11);
SELECT PlayerName FROM Players ORDER BY TournamentWins DESC LIMIT 2;
Insert a new record for a basketball player, 'Giannis Antetokounmpo', age 28, in the 'Bucks' team.
CREATE TABLE players (id INT PRIMARY KEY,name VARCHAR(50),age INT,sport VARCHAR(20),team VARCHAR(30));
INSERT INTO players (name, age, sport, team) VALUES ('Giannis Antetokounmpo', 28, 'Basketball', 'Bucks');
What is the number of patients in each rural health center in Micronesia?
CREATE TABLE health_centers (id INT,name TEXT,location TEXT); CREATE TABLE patients (id INT,name TEXT,health_center_id INT); INSERT INTO health_centers (id,name,location) VALUES (1,'Health Center A','Rural Micronesia'); INSERT INTO health_centers (id,name,location) VALUES (6,'Health Center F','Rural Micronesia'); INSER...
SELECT health_centers.name, COUNT(patients.id) FROM health_centers INNER JOIN patients ON health_centers.id = patients.health_center_id WHERE health_centers.location = 'Rural Micronesia' GROUP BY health_centers.name;
What is the total waste generation for factories located in the African continent?
CREATE TABLE factories (name TEXT,id INTEGER,region TEXT); INSERT INTO factories (name,id,region) VALUES ('Factory I',9,'Africa'),('Factory J',10,'Africa'),('Factory K',11,'Europe'); CREATE TABLE waste_generation (factory_id INTEGER,generation INTEGER); INSERT INTO waste_generation (factory_id,generation) VALUES (9,120...
SELECT SUM(generation) FROM waste_generation wg JOIN factories f ON wg.factory_id = f.id WHERE f.region = 'Africa';
What is the count of male players who have not adopted VR technology?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (2,30,'Female','Brazil'); CREATE TABLE VRAdoption (PlayerID INT,VRPurchaseDate DATE);
SELECT COUNT(Players.PlayerID) FROM Players LEFT JOIN VRAdoption ON Players.PlayerID = VRAdoption.PlayerID WHERE Players.Gender = 'Male' AND VRAdoption.PlayerID IS NULL;
What is the average salary for workers in unions that have collective bargaining agreements and are in the 'Finance' industry?
CREATE TABLE unions (id INT,industry VARCHAR(255),has_cba BOOLEAN); CREATE TABLE workers (id INT,union_id INT,salary DECIMAL(10,2));
SELECT AVG(workers.salary) FROM workers JOIN unions ON workers.union_id = unions.id WHERE unions.industry = 'Finance' AND unions.has_cba = TRUE;
What is the percentage of completed economic diversification projects in each region?
CREATE TABLE EconomicDiversification (ProjectID INT,Region VARCHAR(100),CompletionStatus VARCHAR(20)); INSERT INTO EconomicDiversification VALUES (1,'Asia','Completed'),(2,'Africa','In Progress'),(3,'Europe','Completed'),(4,'Americas','In Progress'),(5,'Oceania','Completed');
SELECT Region, COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (PARTITION BY NULL) AS Percentage FROM EconomicDiversification WHERE CompletionStatus = 'Completed' GROUP BY Region;
Identify menu items not ordered by any customer.
CREATE TABLE orders_summary (order_id INT,menu_id INT,quantity INT); INSERT INTO orders_summary (order_id,menu_id,quantity) VALUES (1,1,2),(2,2,1),(3,3,3),(4,5,1);
SELECT m.menu_name FROM menus m LEFT JOIN orders_summary os ON m.menu_id = os.menu_id WHERE os.menu_id IS NULL;
Delete records of animals with a population of 0.
CREATE TABLE Animal_Population (id INT,name VARCHAR(255),population INT); INSERT INTO Animal_Population (id,name,population) VALUES (1,'Sumatran Rhino',0),(2,'Vaquita',10),(3,'Kakapo',200);
DELETE FROM Animal_Population WHERE population = 0;
What is the number of drought-impacted regions in California with a population greater than 500,000?
CREATE TABLE DroughtImpact (id INT,state VARCHAR(20),region VARCHAR(20),population INT); INSERT INTO DroughtImpact (id,state,region,population) VALUES (1,'California','Northern',600000),(2,'California','Southern',800000),(3,'Texas','Central',400000);
SELECT COUNT(*) FROM DroughtImpact WHERE state = 'California' AND population > 500000;
Insert a new record for a patient from Illinois who received interpersonal therapy.
CREATE TABLE patients (id INT,name TEXT,state TEXT);CREATE TABLE treatments (id INT,patient_id INT,therapy TEXT);
INSERT INTO patients (id, name, state) VALUES (1, 'James Brown', 'Illinois');INSERT INTO treatments (id, patient_id, therapy) VALUES (1, 1, 'Interpersonal Therapy');
Update the genre of a TV show?
CREATE TABLE tv_series (id INT,title VARCHAR(100),genre VARCHAR(50),viewership INT); INSERT INTO tv_series (id,title,genre,viewership) VALUES (1,'Series1','Comedy',8000000),(2,'Series2','Drama',6000000),(3,'Series3','Action',9000000);
UPDATE tv_series SET genre = 'Adventure' WHERE title = 'Series1';
Calculate the daily gas production for each well, for the month of January
CREATE TABLE wells (well_id INT,daily_gas_production FLOAT); INSERT INTO wells (well_id,daily_gas_production) VALUES (1,1000000),(2,2000000),(3,1500000),(4,2500000),(5,3000000);
SELECT well_id, daily_gas_production FROM wells WHERE daily_gas_production IS NOT NULL AND daily_gas_production <> 0;
Delete the agricultural automation trends data for sensor_id 8 from table automation_trends that was recorded before '2021-02-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 (7,'2021-01-01',60),(8,'2021-02-05',70),(9,'2021-02-07',80);
WITH data_to_delete AS (DELETE FROM automation_trends WHERE sensor_id = 8 AND trend_date < '2021-02-15' RETURNING *) SELECT * FROM data_to_delete;
Find the smart contracts with the highest transaction volume in the 'SmartContractsTransactions' view.
CREATE VIEW SmartContractsTransactions AS SELECT SmartContracts.name,Transactions.volume FROM SmartContracts JOIN Transactions ON SmartContracts.hash = Transactions.smart_contract_hash;
SELECT name, MAX(volume) FROM SmartContractsTransactions GROUP BY name;
What is the total number of hours of professional development per instructor per district?
CREATE TABLE development_hours (teacher_id INT,district_id INT,hours_developed INT);
SELECT d.district_id, t.instructor_id, SUM(d.hours_developed) as total_hours FROM development_hours d INNER JOIN teachers t ON d.teacher_id = t.teacher_id GROUP BY d.district_id, t.instructor_id;
Identify the policyholder with the second highest claim amount across all underwriting groups.
CREATE TABLE underwriting (id INT,group VARCHAR(10),name VARCHAR(20),claim_amount DECIMAL(10,2)); INSERT INTO underwriting (id,group,name,claim_amount) VALUES (1,'High Risk','John Doe',5000.00),(2,'Low Risk','Jane Smith',2500.00),(3,'High Risk','Mike Johnson',7000.00),(4,'Low Risk','Emma White',3000.00);
SELECT name, claim_amount FROM (SELECT name, claim_amount, ROW_NUMBER() OVER (ORDER BY claim_amount DESC) rn FROM underwriting) sub WHERE rn = 2;
What is the number of products with natural ingredients by subcategory in Q2 of 2022?
CREATE TABLE products (product_id INT,product_name VARCHAR(100),category VARCHAR(50),subcategory VARCHAR(50),natural_ingredients BOOLEAN,sale_date DATE); INSERT INTO products (product_id,product_name,category,subcategory,natural_ingredients,sale_date) VALUES (1,'Cleanser','Skincare','Natural',true,'2022-04-02'),(2,'Con...
SELECT subcategory, COUNT(*) FILTER (WHERE natural_ingredients = true) AS number_of_products_with_natural_ingredients FROM products WHERE category = 'Cosmetics' AND EXTRACT(QUARTER FROM sale_date) = 2 GROUP BY subcategory;
Count the number of policies by policy type and region in New York and New Jersey.
CREATE TABLE policy_types (id INT,policy_type TEXT); INSERT INTO policy_types (id,policy_type) VALUES (1,'Auto'); INSERT INTO policy_types (id,policy_type) VALUES (2,'Home'); CREATE TABLE regions (id INT,region TEXT); INSERT INTO regions (id,region) VALUES (1,'NYC'); INSERT INTO regions (id,region) VALUES (2,'New Jerse...
SELECT policy_types.policy_type, regions.region, COUNT(*) AS num_policies FROM policies JOIN policy_types ON policies.policy_type_id = policy_types.id JOIN regions ON policies.region_id = regions.id WHERE regions.region IN ('NYC', 'New Jersey') GROUP BY policy_types.policy_type, regions.region;
What are the top three mental health conditions with the highest number of effective treatment approaches in Asia?
CREATE TABLE mental_health_conditions (id INT PRIMARY KEY,name VARCHAR(255),region VARCHAR(255));CREATE TABLE treatment_approaches (id INT PRIMARY KEY,name VARCHAR(255),condition_id INT,effectiveness FLOAT,region VARCHAR(255));
SELECT mental_health_conditions.name, COUNT(treatment_approaches.id) AS num_effective_treatments FROM mental_health_conditions JOIN treatment_approaches ON mental_health_conditions.id = treatment_approaches.condition_id WHERE mental_health_conditions.region = 'Asia' AND treatment_approaches.effectiveness > 0.8 GROUP BY...
How many accessible technology initiatives have been launched in each continent?
CREATE TABLE initiative (initiative_id INT,initiative_name VARCHAR(255),launch_date DATE,region VARCHAR(50)); INSERT INTO initiative (initiative_id,initiative_name,launch_date,region) VALUES (1,'Accessible Software Development','2018-04-01','North America'),(2,'Adaptive Hardware Prototyping','2019-12-15','Europe'),(3,'...
SELECT region, COUNT(*) as num_initiatives FROM initiative GROUP BY region;
Find the total number of packages shipped from the 'EMEA' region
CREATE TABLE warehouses (id INT,name TEXT,region TEXT); INSERT INTO warehouses (id,name,region) VALUES (1,'Warehouse A','EMEA'),(2,'Warehouse B','APAC'); CREATE TABLE shipments (id INT,warehouse_id INT,packages INT); INSERT INTO shipments (id,warehouse_id,packages) VALUES (1,1,500),(2,1,700),(3,2,350);
SELECT SUM(shipments.packages) AS total_packages FROM shipments JOIN warehouses ON shipments.warehouse_id = warehouses.id WHERE warehouses.region = 'EMEA';
Identify the investors who have invested in both seed and series A rounds.
CREATE TABLE investments (investor_id INT,startup_id INT,round_type TEXT); INSERT INTO investments (investor_id,startup_id,round_type) VALUES (1,10,'Seed'),(2,10,'Series A'),(3,11,'Seed'),(4,12,'Series B'),(5,13,'Seed'),(6,14,'Series C'),(7,15,'Seed'),(8,15,'Series A'),(9,16,'Seed'),(10,16,'Series A');
SELECT investor_id FROM investments WHERE round_type = 'Seed' INTERSECT SELECT investor_id FROM investments WHERE round_type = 'Series A';
List all the water conservation initiatives in Canada in 2020.
CREATE TABLE water_conservation (initiative_name VARCHAR(50),country VARCHAR(30),year INT,initiative_type VARCHAR(30));
SELECT initiative_name FROM water_conservation WHERE country='Canada' AND year=2020;
How many AI algorithms were evaluated for fairness in each country in the North American region?
CREATE TABLE ai_algorithms (algorithm_id INT,algorithm_name VARCHAR(50),country VARCHAR(50),region VARCHAR(50)); INSERT INTO ai_algorithms (algorithm_id,algorithm_name,country,region) VALUES (1,'AlgoA','USA','North America'),(2,'AlgoB','Canada','North America'),(3,'AlgoC','Mexico','North America'),(4,'AlgoD','USA','Nor...
SELECT country, region, COUNT(*) AS fairness_evaluations_count FROM ai_algorithms WHERE region = 'North America' GROUP BY country, region;
Find the names of artists who had more than 10 million streams in 2020.
CREATE TABLE Streams (artist_name VARCHAR(50),year INT,streams INT); INSERT INTO Streams (artist_name,year,streams) VALUES ('Taylor Swift',2020,12000000),('Drake',2020,15000000),('BTS',2020,20000000),('Billie Eilish',2020,11000000);
SELECT artist_name FROM Streams WHERE year = 2020 AND streams > 10000000;
Which artists have their artwork exhibited in 'Guggenheim Museum'?
CREATE TABLE Exhibitions (id INT,museum_name VARCHAR(255),artist_name VARCHAR(255)); INSERT INTO Exhibitions (id,museum_name,artist_name) VALUES (1,'Guggenheim Museum','Pablo Picasso'); INSERT INTO Exhibitions (id,museum_name,artist_name) VALUES (2,'Guggenheim Museum','Francisco Goya');
SELECT artist_name FROM Exhibitions WHERE museum_name = 'Guggenheim Museum';
Who are the disability services advocates that have participated in more than 3 policy advocacy events in the last year?
CREATE TABLE advocates (advocate_id INT,advocate_name VARCHAR(255),advocate_role VARCHAR(255));
SELECT advocate_name FROM advocates A JOIN policy_events PE ON A.advocate_name = PE.advocate_name WHERE PE.event_date >= DATEADD(year, -1, GETDATE()) GROUP BY advocate_name HAVING COUNT(*) > 3;
Compare sales quantities between 'EcoStitch' and 'FairFashion' across all materials.
CREATE TABLE SupplierSales (SaleID INT,SupplierName TEXT,Material TEXT,Quantity INT); INSERT INTO SupplierSales (SaleID,SupplierName,Material,Quantity) VALUES (4,'EcoStitch','Silk',10),(5,'EcoStitch','Cotton',20),(6,'FairFashion','Silk',15),(7,'FairFashion','Cotton',25);
SELECT s1.SupplierName, SUM(s1.Quantity) - SUM(s2.Quantity) FROM SupplierSales s1 INNER JOIN SupplierSales s2 ON s1.Material = s2.Material AND (s1.SupplierName = 'EcoStitch' AND s2.SupplierName = 'FairFashion') GROUP BY s1.SupplierName;
How many international visitors arrived per month in '2022'?
CREATE TABLE Arrivals (ArrivalID INT,VisitorID INT,ArrivalDate DATE); INSERT INTO Arrivals (ArrivalID,VisitorID,ArrivalDate) VALUES (1,1,'2022-01-01'),(2,2,'2022-02-01');
SELECT EXTRACT(MONTH FROM ArrivalDate), COUNT(VisitorID) FROM Arrivals WHERE YEAR(ArrivalDate) = 2022 GROUP BY EXTRACT(MONTH FROM ArrivalDate);
Determine the number of artists who have released music in more than one genre.
CREATE TABLE artist_genre (artist_id INT,genre VARCHAR(10));
SELECT COUNT(DISTINCT artist_id) FROM artist_genre GROUP BY artist_id HAVING COUNT(DISTINCT genre) > 1;
Find the exhibitions that have been visited by visitors from underrepresented communities in the last year and have the highest community engagement score.
CREATE TABLE Exhibition (id INT,name VARCHAR(100),Visitor_id INT,community_score INT,country VARCHAR(50)); INSERT INTO Exhibition (id,name,Visitor_id,community_score,country) VALUES (1,'Ancient Civilizations',1,80,'South Africa'),(2,'Modern Art',2,75,'Brazil'),(3,'Nature Photography',3,85,'Mexico'),(4,'Wildlife',4,90,'...
SELECT Exhibition.name FROM Exhibition WHERE Exhibition.country IN ('South Africa', 'Brazil', 'Mexico', 'India') AND Exhibition.interaction_date >= CURDATE() - INTERVAL 1 YEAR GROUP BY Exhibition.name ORDER BY community_score DESC;
What is the average GRE score for students in the Computer Science department?
CREATE TABLE students (id INT,name VARCHAR(50),department VARCHAR(50),gre_score INT); INSERT INTO students (id,name,department,gre_score) VALUES (1,'John Doe','Computer Science',160),(2,'Jane Smith','Computer Science',155);
SELECT AVG(gre_score) FROM students WHERE department = 'Computer Science';
Which urban farms in Oakland, CA have the highest yield per acre?
CREATE TABLE urban_farms (name TEXT,city TEXT,state TEXT,acres NUMERIC,yield NUMERIC); INSERT INTO urban_farms (name,city,state,acres,yield) VALUES ('Groundwork','Oakland','CA',2.5,15000),('City Slicker Farms','Oakland','CA',3.2,12000),('Kinderfarms','Oakland','CA',1.9,8000);
SELECT name, acres, yield, ROW_NUMBER() OVER (ORDER BY yield/acres DESC) as rank FROM urban_farms WHERE city = 'Oakland' AND state = 'CA';
What is the distribution of digital divide issues across the globe?
CREATE TABLE digital_divide (id INT,country TEXT,issue_type TEXT,severity INT); INSERT INTO digital_divide (id,country,issue_type,severity) VALUES (1,'India','Internet Access',70),(2,'Brazil','Digital Literacy',60),(3,'South Africa','Infrastructure',80),(4,'Germany','Affordability',40),(5,'Canada','Internet Access',50)...
SELECT issue_type, AVG(severity) FROM digital_divide GROUP BY issue_type;
What is the average number of accommodations provided per student in each school?
CREATE TABLE Accommodations (SchoolName VARCHAR(255),Student VARCHAR(255),Accommodation VARCHAR(255)); INSERT INTO Accommodations (SchoolName,Student,Accommodation) VALUES ('SchoolA','Student1','Extra Time'),('SchoolA','Student2','Reader'),('SchoolB','Student3','Extra Time');
SELECT SchoolName, AVG(CountOfAccommodations) as AverageAccommodationsPerStudent FROM (SELECT SchoolName, Student, COUNT(*) as CountOfAccommodations FROM Accommodations GROUP BY SchoolName, Student) as Subquery GROUP BY SchoolName;
List the number of unique players who have played 'Among Us' and 'Valorant' on PC
CREATE TABLE player_platforms (player_id INT,game_id INT,platform VARCHAR(50),PRIMARY KEY (player_id,game_id)); INSERT INTO player_platforms VALUES (1,1,'PC'),(1,2,'PC'),(2,1,'PC'),(2,2,'Console'),(3,1,'Mobile'),(3,2,'PC'); CREATE TABLE game_titles (game_id INT,title VARCHAR(50),PRIMARY KEY (game_id)); INSERT INTO game...
SELECT COUNT(DISTINCT player_id) as unique_players FROM player_platforms pp INNER JOIN game_titles gt ON pp.game_id = gt.game_id WHERE gt.title IN ('Among Us', 'Valorant') AND pp.platform = 'PC';
List the names of healthcare providers who have served more than 1000 patients?
CREATE TABLE providers (id INT,name TEXT,specialty TEXT); CREATE TABLE patient_encounters (id INT,provider_id INT,patient_id INT); INSERT INTO providers (id,name,specialty) VALUES (1,'Dr. Smith','Cardiology'),(2,'Dr. Johnson','Pediatrics'); INSERT INTO patient_encounters (id,provider_id,patient_id) VALUES (1,1,1),(2,1,...
SELECT providers.name FROM providers INNER JOIN patient_encounters ON providers.id = patient_encounters.provider_id GROUP BY providers.name HAVING COUNT(patient_encounters.id) > 1000;
What is the revenue trend for each menu category over the past 30 days?
CREATE TABLE menu_engineering (menu_category VARCHAR(255),date DATE,revenue DECIMAL(10,2)); INSERT INTO menu_engineering (menu_category,date,revenue) VALUES ('Appetizers','2022-01-01',500.00),('Entrees','2022-01-01',1000.00),('Desserts','2022-01-01',600.00),('Appetizers','2022-01-02',550.00),('Entrees','2022-01-02',110...
SELECT menu_category, date, revenue, LAG(revenue) OVER (PARTITION BY menu_category ORDER BY date) as previous_day_revenue FROM menu_engineering;
What is the average price and total sales for each product?
CREATE TABLE products (id INT,name VARCHAR(50),category VARCHAR(50),price DECIMAL(10,2),sales INT); INSERT INTO products (id,name,category,price,sales) VALUES (1,'Product A','Category 1',100.00,50),(2,'Product B','Category 2',200.00,30),(3,'Product C','Category 1',150.00,70),(4,'Product D','Category 3',75.00,80),(5,'Pr...
SELECT name, AVG(price) AS avg_price, SUM(sales) AS total_sales FROM products GROUP BY name;
Update labor_statistics table and set hourly_wage = 30.50 for all records where job_category is 'Carpentry'
CREATE TABLE labor_statistics (id INT,job_category VARCHAR(20),hourly_wage DECIMAL(5,2));
UPDATE labor_statistics SET hourly_wage = 30.50 WHERE job_category = 'Carpentry';
What is the minimum ESG score for companies in the 'healthcare' sector?
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_score FLOAT); INSERT INTO companies (id,sector,ESG_score) VALUES (1,'healthcare',82.0),(2,'technology',75.5),(3,'healthcare',78.7),(4,'finance',90.2);
SELECT MIN(ESG_score) FROM companies WHERE sector = 'healthcare';
List all the marine species that belong to the Chordata phylum and reside at a depth greater than 4000 meters.
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(100),max_depth FLOAT,phylum VARCHAR(50));
SELECT species_name FROM marine_species WHERE phylum = 'Chordata' AND max_depth > 4000;
What is the total quantity of size 8 garments sold in India?
CREATE TABLE Sales (id INT,garmentID INT,quantity INT,saleDate DATE); INSERT INTO Sales (id,garmentID,quantity,saleDate) VALUES (1,201,5,'2021-01-10'),(2,202,3,'2021-02-15'),(3,203,4,'2021-03-20'),(4,204,6,'2021-04-12'); CREATE TABLE Garments (id INT,garmentID INT,size INT,country VARCHAR(50)); INSERT INTO Garments (id...
SELECT SUM(quantity) FROM Sales INNER JOIN Garments ON Sales.garmentID = Garments.garmentID WHERE Garments.size = 8 AND Garments.country = 'India';
What is the sum of transaction fees for all decentralized applications in the EU?
CREATE TABLE DecentralizedApps (app_id INT,app_name TEXT,transaction_fee DECIMAL(10,2)); INSERT INTO DecentralizedApps (app_id,app_name,transaction_fee) VALUES (1,'App1',10.50),(2,'App2',15.25),(3,'App3',20.00); CREATE TABLE AppLocation (app_id INT,location TEXT); INSERT INTO AppLocation (app_id,location) VALUES (1,'EU...
SELECT SUM(DecentralizedApps.transaction_fee) FROM DecentralizedApps INNER JOIN AppLocation ON DecentralizedApps.app_id = AppLocation.app_id WHERE AppLocation.location = 'EU';
Delete records in the wastewater_facilities table where the facility_type is 'Sewage Treatment Plant' and the region is 'Northeast'
CREATE TABLE wastewater_facilities (id INT PRIMARY KEY,name VARCHAR(50),facility_type VARCHAR(50),region VARCHAR(20),capacity_bod INT,operational_status VARCHAR(20)); INSERT INTO wastewater_facilities (id,name,facility_type,region,capacity_bod,operational_status) VALUES (1,'Facility A','Sewage Treatment Plant','Northea...
DELETE FROM wastewater_facilities WHERE facility_type = 'Sewage Treatment Plant' AND region = 'Northeast';
What is the average water waste per household in Florida?
CREATE TABLE wastewater_data (state VARCHAR(20),waste_per_household FLOAT); INSERT INTO wastewater_data (state,waste_per_household) VALUES ('Florida',150),('California',120),('Texas',180);
SELECT AVG(waste_per_household) FROM wastewater_data WHERE state = 'Florida';
Which artists have exhibited at more than one museum?
CREATE TABLE exhibitions (artist VARCHAR(255),museum VARCHAR(255)); INSERT INTO exhibitions (artist,museum) VALUES ('Vincent van Gogh','Louvre Museum,Paris'),('Vincent van Gogh','Metropolitan Museum of Art,NY'),('Pablo Picasso','Tate Modern,London'),('Pablo Picasso','Metropolitan Museum of Art,NY');
SELECT artist FROM exhibitions GROUP BY artist HAVING COUNT(DISTINCT museum) > 1;
Find the maximum number of visitors at exhibitions in each city?
CREATE TABLE Exhibition_Attendance (id INT,exhibition_id INT,city VARCHAR(255),num_visitors INT); INSERT INTO Exhibition_Attendance (id,exhibition_id,city,num_visitors) VALUES (1,101,'Chicago',500),(2,102,'Chicago',700),(3,103,'New York',600),(4,104,'New York',800);
SELECT city, MAX(num_visitors) FROM Exhibition_Attendance GROUP BY city;
Find the top 3 locations with the highest average energy consumption in the 'GreenBuildings' table.
CREATE TABLE GreenBuildings (id INT,name VARCHAR(50),location VARCHAR(50),energyConsumption DECIMAL(5,2));
SELECT location, AVG(energyConsumption) as avg_consumption FROM GreenBuildings GROUP BY location ORDER BY avg_consumption DESC LIMIT 3;
What is the percentage of total energy consumption that came from solar power in Oregon in 2019?
CREATE TABLE energy_consumption_by_source (state VARCHAR(20),year INT,energy_source VARCHAR(20),energy_consumption FLOAT);
SELECT (SUM(CASE WHEN energy_source = 'Solar' THEN energy_consumption END) / SUM(energy_consumption)) * 100 as solar_percentage FROM energy_consumption_by_source WHERE state = 'Oregon' AND year = 2019;
What is the maximum fare for a wheelchair accessible bus in Mumbai?
CREATE TABLE bus_fares (fare_id INT,vehicle_type VARCHAR(20),fare DECIMAL(10,2),city VARCHAR(50)); INSERT INTO bus_fares (fare_id,vehicle_type,fare,city) VALUES (1,'Bus',1.50,'Mumbai'),(2,'Wheelchair Accessible Bus',2.00,'Mumbai'),(3,'Minibus',1.20,'Mumbai');
SELECT MAX(fare) FROM bus_fares WHERE vehicle_type = 'Wheelchair Accessible Bus' AND city = 'Mumbai';
How many aircraft have been manufactured in the United States between 2010 and 2020, excluding aircraft with a production year of 2015?
CREATE TABLE aircraft_manufacturing (aircraft_id INT,manufacturer VARCHAR(50),production_year INT); INSERT INTO aircraft_manufacturing (aircraft_id,manufacturer,production_year) VALUES (1,'Boeing',2010),(2,'Boeing',2011),(3,'Airbus',2012),(4,'Boeing',2013),(5,'Airbus',2014),(6,'Gulfstream',2016);
SELECT COUNT(*) FROM aircraft_manufacturing WHERE manufacturer = 'United States' AND production_year BETWEEN 2010 AND 2020 AND production_year != 2015;
What is the average fuel consumption per day for container vessels in the Atlantic Ocean?
CREATE TABLE vessel_fuel_consumption (id INT,vessel_id INT,vessel_type VARCHAR(255),fuel_consumption_l_per_day INT,ocean VARCHAR(255)); INSERT INTO vessel_fuel_consumption (id,vessel_id,vessel_type,fuel_consumption_l_per_day,ocean) VALUES (5,20,'Container',120,'Atlantic'); INSERT INTO vessel_fuel_consumption (id,vessel...
SELECT vessel_type, AVG(fuel_consumption_l_per_day) as avg_fuel_consumption FROM vessel_fuel_consumption WHERE ocean = 'Atlantic' AND vessel_type = 'Container' GROUP BY vessel_type;
What is the average military innovation budget (in USD) for each organization in the 'military_innovation' table, excluding those with less than 2 projects, ordered by the average budget in descending order?
CREATE TABLE military_innovation (id INT,organization VARCHAR(50),budget INT);
SELECT organization, AVG(budget) as avg_budget FROM military_innovation GROUP BY organization HAVING COUNT(*) >= 2 ORDER BY avg_budget DESC;
List all artists from the Oceanian continent along with their art forms.
CREATE TABLE artists (id INT PRIMARY KEY,name VARCHAR(50),ethnicity VARCHAR(20),age INT,genre VARCHAR(30)); CREATE TABLE art_forms (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(30)); INSERT INTO artists (id,name,ethnicity,age,genre) VALUES (1,'Saraa','Mongolian',35,'Throat Singing'); INSERT INTO art_forms (id,name,...
SELECT artists.name, art_forms.name FROM artists INNER JOIN art_forms ON artists.genre = art_forms.name WHERE artists.ethnicity LIKE 'Oceanian%';
How many different species are present in the 'arctic_biodiversity' table?
CREATE TABLE arctic_biodiversity (id INTEGER,species VARCHAR(255),population INTEGER);
SELECT COUNT(DISTINCT species) AS species_count FROM arctic_biodiversity;
What is the total CO2 emissions for 'Site Alpha' in the 'environmental_impact' table?
CREATE TABLE environmental_impact (site_name VARCHAR(50),co2_emissions INT,waste_generation INT); INSERT INTO environmental_impact (site_name,co2_emissions,waste_generation) VALUES ('Site Alpha',1200,500),('Site Bravo',1800,800);
SELECT co2_emissions FROM environmental_impact WHERE site_name = 'Site Alpha';
What are the police budgets for urban and rural areas in 2023?
CREATE TABLE budget_2023 (service TEXT,location TEXT,budget INTEGER); INSERT INTO budget_2023 (service,location,budget) VALUES ('Police','Urban',1100000),('Police','Rural',900000);
SELECT SUM(budget) FROM budget_2023 WHERE service = 'Police' AND location IN ('Urban', 'Rural');
What is the total revenue generated by hotels with sustainability ratings in London?
CREATE TABLE hotels (id INT,city TEXT,sustainability_rating INT,revenue DECIMAL(10,2)); INSERT INTO hotels (id,city,sustainability_rating,revenue) VALUES (1,'London',4,5000),(2,'London',5,7000);
SELECT SUM(revenue) FROM hotels WHERE city = 'London' AND sustainability_rating IS NOT NULL;
What is the average number of experiments per Mars mission?
CREATE TABLE MarsMissions (Mission VARCHAR(50),Agency VARCHAR(50),LaunchYear INT,NumberOfExperiments INT); INSERT INTO MarsMissions (Mission,Agency,LaunchYear,NumberOfExperiments) VALUES ('Mars Pathfinder','NASA',1996,3),('Mars Global Surveyor','NASA',1996,12),('Mars Climate Orbiter','NASA',1998,7),('Mars Polar Lander'...
SELECT AVG(NumberOfExperiments) FROM MarsMissions;
What is the total number of public events organized by community groups in the last 3 months, grouped by location?
CREATE TABLE public_events (id INT,location VARCHAR(255),event_date DATE); INSERT INTO public_events (id,location,event_date) VALUES (1,'Urban','2022-02-01'),(2,'Rural','2022-03-15'),(3,'Urban','2022-04-20');
SELECT location, COUNT(*) FROM public_events WHERE event_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) GROUP BY location;
Which stations on the red line have bikes available for rental?
CREATE TABLE stations (id INT,name TEXT,line TEXT); INSERT INTO stations (id,name,line) VALUES (1,'StationA','Red'),(2,'StationB','Red'),(3,'StationC','Red'); CREATE TABLE bikes (id INT,station_id INT,available BOOLEAN); INSERT INTO bikes (id,station_id,available) VALUES (1,1,TRUE),(2,1,FALSE),(3,2,TRUE),(4,2,TRU...
SELECT s.name FROM stations s JOIN bikes b ON s.id = b.station_id WHERE s.line = 'Red' AND b.available = TRUE;
What is the average donation amount per month?
CREATE TABLE Donations (DonationID INT,DonationDate DATE,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonationDate,DonationAmount) VALUES (1,'2022-01-01',100.00),(2,'2022-01-15',200.00),(3,'2022-02-01',300.00),(4,'2022-02-15',400.00);
SELECT AVG(DonationAmount) OVER (PARTITION BY EXTRACT(MONTH FROM DonationDate) ORDER BY EXTRACT(MONTH FROM DonationDate)) AS AvgDonationPerMonth FROM Donations;
What is the local economic impact of tourism in Costa Rica's coastal towns?
CREATE TABLE tourism(town_id INT,town_name TEXT,country TEXT,tourism_impact INT); INSERT INTO tourism (town_id,town_name,country,tourism_impact) VALUES (1,'Manuel Antonio','Costa Rica',200),(2,'Jacó','Costa Rica',150),(3,'Cancún','Mexico',300);
SELECT town_name, tourism_impact FROM tourism WHERE country = 'Costa Rica';
What is the number of hospitals and long-term care facilities in each province, ordered by the number of hospitals, descending?
CREATE TABLE hospitals (id INT,name TEXT,province TEXT,location TEXT,type TEXT,num_beds INT); INSERT INTO hospitals (id,name,province,location,type,num_beds) VALUES (1,'Hospital A','Province A','Urban','Teaching',200),(2,'Hospital B','Province B','Rural','Community',150),(3,'Hospital C','Province A','Urban','Specialty'...
SELECT h.province, COUNT(h.id) as num_hospitals, COUNT(ltcf.id) as num_ltcf FROM hospitals h FULL OUTER JOIN long_term_care ltcf ON h.province = ltcf.province GROUP BY h.province ORDER BY num_hospitals DESC;
Display the names and capacities of all water treatment plants in 'water_treatment_plants' table
CREATE TABLE water_treatment_plants (plant_id INT PRIMARY KEY,plant_name VARCHAR(100),capacity FLOAT,country VARCHAR(50));
SELECT plant_name, capacity FROM water_treatment_plants;
How many drought-impacted counties are there in Texas?
CREATE TABLE texas_drought_impact (county VARCHAR(20),drought_impacted INT); INSERT INTO texas_drought_impact (county,drought_impacted) VALUES ('Harris',1),('Dallas',1),('Tarrant',1),('Bexar',1),('Travis',1),('Collin',1);
SELECT COUNT(*) FROM texas_drought_impact WHERE drought_impacted = 1
How many employees work in each state?
CREATE TABLE staff (id INT,state VARCHAR(20),employee_count INT); INSERT INTO staff (id,state,employee_count) VALUES (1,'Queensland',500),(2,'NewSouthWales',700),(3,'Victoria',800);
SELECT state, SUM(employee_count) as total_employees FROM staff GROUP BY state;
What is the total number of hours streamed for Rocket League on Twitch?
CREATE TABLE streams (stream_id INT,game VARCHAR(50),streamer VARCHAR(50),start_time TIMESTAMP,end_time TIMESTAMP,viewer_count INT,hours_streamed DECIMAL(5,2));
SELECT SUM(hours_streamed) FROM streams WHERE game = 'Rocket League';
How many donations were made in each quarter of 2019?
CREATE TABLE donations (donation_id INT,donation_amount DECIMAL,donation_date DATE); INSERT INTO donations VALUES (1,1000,'2019-01-15'); INSERT INTO donations VALUES (2,2000,'2019-04-20'); INSERT INTO donations VALUES (3,3000,'2019-07-01'); INSERT INTO donations VALUES (4,4000,'2019-10-05');
SELECT DATE_PART('quarter', donation_date) as quarter, COUNT(*) as num_donations FROM donations WHERE donation_date >= '2019-01-01' AND donation_date < '2020-01-01' GROUP BY quarter;
Show the number of workers in each factory, sorted by the factory with the most workers.
CREATE TABLE factories (id INT,name VARCHAR(255),worker_count INT);CREATE TABLE factory_workers (factory_id INT,worker_id INT);
SELECT factories.name, COUNT(factory_workers.worker_id) AS worker_count FROM factories INNER JOIN factory_workers ON factories.id = factory_workers.factory_id GROUP BY factories.id ORDER BY worker_count DESC;
What is the most popular color for size 8 garments?
CREATE TABLE garment_colors (id INT,garment_id INT,color VARCHAR(20)); INSERT INTO garment_colors (id,garment_id,color) VALUES (1,301,'red'),(2,302,'blue'),(3,303,'black'),(4,304,'red'),(5,305,'green'),(6,306,'yellow'),(7,307,'purple');
SELECT color, COUNT(*) as count FROM garment_colors gc JOIN sales s ON gc.garment_id = s.garment_id WHERE size = 8 GROUP BY color ORDER BY count DESC LIMIT 1;
What is the average sustainability rating for makeup products in the EU?
CREATE TABLE ProductRatings (product_id INT,product_name VARCHAR(20),category VARCHAR(20),sustainability_rating INT); INSERT INTO ProductRatings (product_id,product_name,category,sustainability_rating) VALUES (1,'lipstick','makeup',80),(2,'mascara','makeup',75),(3,'foundation','makeup',90),(4,'blush','makeup',85);
SELECT AVG(sustainability_rating) as avg_rating FROM ProductRatings WHERE category = 'makeup' AND country = 'EU';
How many members have a platinum membership and have never used the swimming pool?
CREATE TABLE Members (MemberID INT,Age INT,MembershipType VARCHAR(20)); INSERT INTO Members (MemberID,Age,MembershipType) VALUES (1,25,'Gold'),(2,30,'Silver'),(3,35,'Platinum'); CREATE TABLE Workout (MemberID INT,Equipment VARCHAR(20),Duration INT); INSERT INTO Workout (MemberID,Equipment,Duration) VALUES (1,'Treadmill...
SELECT COUNT(*) FROM Members LEFT JOIN Workout ON Members.MemberID = Workout.MemberID WHERE Members.MembershipType = 'Platinum' AND Workout.Equipment IS NULL;
Delete waste data for the 'Other' sector.
CREATE TABLE waste_data (id INT,sector VARCHAR(50),waste_kg INT); INSERT INTO waste_data (id,sector,waste_kg) VALUES (1,'Industrial',1500),(2,'Commercial',1000),(3,'Residential',800),(4,'Other',300);
DELETE FROM waste_data WHERE sector = 'Other';
List the top 2 suppliers with the highest total quantity of organic vegetables in their inventory.
CREATE TABLE inventory(id INT PRIMARY KEY,supplier_id INT,product VARCHAR(50),quantity INT,organic BOOLEAN); INSERT INTO inventory(id,supplier_id,product,quantity,organic) VALUES (1,1,'organic carrots',300,TRUE),(2,1,'organic tomatoes',500,TRUE),(3,2,'conventional potatoes',400,FALSE),(4,2,'organic onions',250,TRUE),(5...
SELECT s.name, SUM(i.quantity) AS total_quantity FROM inventory i JOIN suppliers s ON i.supplier_id = s.id WHERE i.organic = TRUE GROUP BY s.id ORDER BY total_quantity DESC LIMIT 2;
What is the distribution of decentralized applications by platform?
CREATE TABLE dapps (id INT,dapp_name VARCHAR(50),dapp_category VARCHAR(30),dapp_platform VARCHAR(20),developer_address VARCHAR(100)); INSERT INTO dapps (id,dapp_name,dapp_category,dapp_platform,developer_address) VALUES (11,'Dapp 4','Category 4','Platform 4','0xADDRESS1'); INSERT INTO dapps (id,dapp_name,dapp_category,...
SELECT dapp_platform, COUNT(*) as dapp_count FROM dapps GROUP BY dapp_platform;
What is the minimum waste generation rate in 'CountyD' in the first half of the year?
CREATE TABLE CountyD (Month INT,WasteQuantity INT); INSERT INTO CountyD (Month,WasteQuantity) VALUES (1,500),(2,600),(3,700),(4,800),(5,900),(6,1000);
SELECT MIN(WasteQuantity) FROM CountyD WHERE Month BETWEEN 1 AND 6 AND Month % 2 = 0;
What is the total number of collective bargaining agreements in the 'Manufacturing' sector that were successfully negotiated in 2021?
CREATE TABLE CollectiveBargaining (AgreementID INT,Sector VARCHAR(20),Year INT,NegotiationStatus VARCHAR(20)); INSERT INTO CollectiveBargaining (AgreementID,Sector,Year,NegotiationStatus) VALUES (1,'Manufacturing',2021,'Successful'),(2,'Manufacturing',2022,'Pending'),(3,'Retail',2021,'Unsuccessful');
SELECT SUM(*) FROM CollectiveBargaining WHERE Sector = 'Manufacturing' AND Year = 2021 AND NegotiationStatus = 'Successful';
Update the 'product_name' to 'Sustainable Product 2.0' for the record with id 2 in the 'circular_economy' table
CREATE TABLE circular_economy (id INT PRIMARY KEY,product_name VARCHAR(100),reuse_percentage INT);
UPDATE circular_economy SET product_name = 'Sustainable Product 2.0' WHERE id = 2;
What is the name and material of the bridges built before 1980 in California that have a length greater than 500 meters?
CREATE TABLE Bridges (BridgeID INT,Name VARCHAR(255),Material VARCHAR(255),Length FLOAT,BuildDate DATE); INSERT INTO Bridges VALUES (1,'Bridge A','Steel',650,'1975-05-12'); INSERT INTO Bridges VALUES (2,'Bridge B','Concrete',450,'1978-08-24'); INSERT INTO Bridges VALUES (3,'Bridge C','Steel',700,'1979-12-31');
SELECT Name, Material FROM Bridges WHERE BuildDate < '1980-01-01' AND Length > 500;
What is the total claim amount for policies with a coverage level greater than 50000?
CREATE TABLE Claims (id INT,policy_id INT,claim_amount FLOAT,coverage_level INT); INSERT INTO Claims (id,policy_id,claim_amount,coverage_level) VALUES (1,1001,6000,55000),(2,1002,8000,60000),(3,1003,4000,45000),(4,1004,9000,70000);
SELECT SUM(claim_amount) as total_claim_amount FROM Claims WHERE coverage_level > 50000;
Which programs had the most donations in Q3 2021?
CREATE TABLE program_donations (id INT,program TEXT,amount DECIMAL,donation_date DATE);
SELECT program, SUM(amount) as total_donations FROM program_donations WHERE donation_date >= '2021-07-01' AND donation_date < '2021-10-01' GROUP BY program ORDER BY total_donations DESC;
What are the unique art forms in each region and the number of associated artifacts?
CREATE TABLE ArtForm (ArtFormID INT,ArtFormName VARCHAR(50),RegionID INT); INSERT INTO ArtForm (ArtFormID,ArtFormName,RegionID) VALUES (1,'Batik',1),(2,'Ikat Weaving',1),(3,'Tambourine',2),(4,'Calligraphy',2); CREATE TABLE Artifact (ArtifactID INT,ArtifactName VARCHAR(50),ArtFormID INT); INSERT INTO Artifact (ArtifactI...
SELECT r.RegionName, a.ArtFormName, COUNT(a.ArtifactID) as ArtifactCount FROM ArtForm a JOIN (SELECT DISTINCT RegionID, RegionName FROM ArtForm) r ON a.RegionID = r.RegionID JOIN Artifact art ON a.ArtFormID = art.ArtFormID GROUP BY r.RegionName, a.ArtFormName;