instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Identify submarines that descended below 4000 meters but haven't resurfaced since.
CREATE TABLE SUBMARINE_LOCATIONS (SUBMARINE_NAME VARCHAR(20),LOCATION_DATE DATE,DEPTH INT); INSERT INTO SUBMARINE_LOCATIONS (SUBMARINE_NAME,LOCATION_DATE,DEPTH) VALUES ('Alvin','2022-01-01',4000),('Nautile','2022-02-01',5000),('Alvin','2022-03-01',3000),('Nautile','2022-04-01',5500),('Alvin','2022-05-01',3500);
SELECT SUBMARINE_NAME FROM (SELECT SUBMARINE_NAME, LOCATION_DATE, DEPTH, LAG(DEPTH, 1) OVER (PARTITION BY SUBMARINE_NAME ORDER BY LOCATION_DATE) AS PREV_DEPTH FROM SUBMARINE_LOCATIONS) WHERE SUBMARINE_NAME IN ('Alvin', 'Nautile') AND DEPTH < PREV_DEPTH AND LOCATION_DATE > '2022-01-01';
What is the number of species in each category in the 'species' table, grouped by country?
CREATE TABLE species (species_id INT,species_name TEXT,category TEXT,country TEXT);
SELECT country, category, COUNT(*) FROM species GROUP BY country, category;
Determine the number of unique industries represented in the 'startups' table
CREATE TABLE startups (id INT,name VARCHAR(50),industry VARCHAR(50)); INSERT INTO startups VALUES (1,'Startup A','Technology'); INSERT INTO startups VALUES (2,'Startup B','Retail'); INSERT INTO startups VALUES (3,'Startup C','Technology');
SELECT COUNT(DISTINCT industry) FROM startups;
Find the total number of unique donors who made a donation in both the year 2019 and 2020?
CREATE TABLE Donors (id INT,donor_name VARCHAR(255),donation_year INT,donation_amount DECIMAL(10,2)); INSERT INTO Donors (id,donor_name,donation_year,donation_amount) VALUES (1,'John Doe',2019,500.00),(2,'Jane Smith',2020,300.00),(3,'Alice Johnson',2019,200.00),(4,'Bob Brown',2020,400.00),(5,'Charlie Davis',2019,100.00...
SELECT COUNT(DISTINCT donor_name) as total_unique_donors FROM Donors d1 INNER JOIN Donors d2 ON d1.donor_name = d2.donor_name WHERE d1.donation_year = 2019 AND d2.donation_year = 2020;
What is the total revenue generated by cannabis edibles sales in Washington in 2020?
CREATE TABLE revenue (product VARCHAR(20),revenue DECIMAL(10,2),state VARCHAR(20),year INT); INSERT INTO revenue (product,revenue,state,year) VALUES ('Edibles',45000,'Washington',2020),('Flower',60000,'Washington',2020),('Concentrate',55000,'Washington',2020);
SELECT SUM(revenue) as total_revenue FROM revenue WHERE product = 'Edibles' AND state = 'Washington' AND year = 2020;
What is the average number of volunteer hours contributed per volunteer from a specific community type?
CREATE TABLE volunteers (id INT,name TEXT,community_type TEXT,hours_contributed INT); INSERT INTO volunteers (id,name,community_type,hours_contributed) VALUES (1,'John Doe','Underrepresented',25); INSERT INTO volunteers (id,name,community_type,hours_contributed) VALUES (2,'Jane Smith','Represented',30);
SELECT community_type, AVG(hours_contributed) FROM volunteers GROUP BY community_type;
What is the average production quantity for all wells in the 'ocean' region?
CREATE TABLE wells (well_name TEXT,region TEXT,production_quantity INT); INSERT INTO wells (well_name,region,production_quantity) VALUES ('Well A','ocean',4000),('Well B','ocean',5000),('Well C','gulf',6000);
SELECT AVG(production_quantity) FROM wells WHERE region = 'ocean';
Insert new menu items and their prices for a specific restaurant.
CREATE TABLE Restaurants (RestaurantID INT,Name VARCHAR(50)); CREATE TABLE Menu (MenuID INT,RestaurantID INT,Item VARCHAR(50),Price DECIMAL(10,2));
INSERT INTO Menu (MenuID, RestaurantID, Item, Price) VALUES (1, 1, 'Vegan Burger', 12.99), (2, 1, 'Impossible Taco', 9.99);
What is the average rating for each product type?
CREATE TABLE products (product_id INT,product_name VARCHAR(50),product_type VARCHAR(50),rating DECIMAL(3,2));
SELECT product_type, AVG(rating) as avg_rating FROM products GROUP BY product_type;
Which Shariah-compliant financing products offered by banks in the Middle East and North Africa had the highest total financing in 2020, and what was the total financing amount for each product?
CREATE TABLE ShariahFinance (bank_name VARCHAR(50),product_type VARCHAR(50),amount DECIMAL(10,2),issue_date DATE,region VARCHAR(50));
SELECT product_type, SUM(amount) as total_financing FROM ShariahFinance WHERE region IN ('Middle East', 'North Africa') AND YEAR(issue_date) = 2020 GROUP BY product_type ORDER BY total_financing DESC;
Add a new smart city project 'Greenville' to the 'projects' table
CREATE TABLE projects (project_id INT,name VARCHAR(50),start_date DATE,end_date DATE);
INSERT INTO projects (project_id, name, start_date, end_date) VALUES (103, 'Greenville', '2023-01-01', '2024-12-31');
Delete all records from the volunteers table where the hours for the month of January 2022 were zero
CREATE TABLE volunteers (name VARCHAR(50),hours INT,volunteer_date DATE);
DELETE FROM volunteers WHERE EXTRACT(MONTH FROM volunteer_date) = 1 AND EXTRACT(YEAR FROM volunteer_date) = 2022 AND hours = 0;
Delete the record for paper recycling in the city of Chicago in the second quarter of 2021.
CREATE TABLE recycling_rates (city VARCHAR(255),quarter INT,material_type VARCHAR(255),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (city,quarter,material_type,recycling_rate) VALUES ('Chicago',2,'Plastic',40),('Chicago',2,'Paper',75),('Chicago',2,'Glass',50);
DELETE FROM recycling_rates WHERE city = 'Chicago' AND quarter = 2 AND material_type = 'Paper';
What is the total billing amount for cases with outcome 'lost'?
CREATE TABLE cases (case_id INT,case_outcome TEXT,total_billing FLOAT); INSERT INTO cases (case_id,case_outcome,total_billing) VALUES (1,'settled',2000.00),(2,'won',3000.00),(3,'lost',1500.00);
SELECT SUM(total_billing) FROM cases WHERE case_outcome = 'lost';
Which countries have the most brands with sustainable textile sourcing?
CREATE TABLE Brands (brand_id INT,brand_name TEXT,country TEXT,is_sustainable_sourcing BOOLEAN);
SELECT b.country, COUNT(DISTINCT b.brand_id) as sustainable_brand_count FROM Brands b WHERE b.is_sustainable_sourcing = TRUE GROUP BY b.country ORDER BY sustainable_brand_count DESC;
Show all records from 'Students' table
CREATE TABLE Students (StudentId INT,Name VARCHAR(50)); INSERT INTO Students (StudentId,Name) VALUES (1001,'John Doe');
SELECT * FROM Students;
What is the average response time for fire department incidents in Chicago, considering only incidents that occurred in the last 3 months?
CREATE TABLE fire_department_incidents (incident_id INT,incident_time TIMESTAMP,city TEXT,response_time INT); INSERT INTO fire_department_incidents (incident_id,incident_time,city,response_time) VALUES (1,'2022-01-01 12:34:56','Chicago',10); INSERT INTO fire_department_incidents (incident_id,incident_time,city,response...
SELECT AVG(response_time) FROM fire_department_incidents WHERE city = 'Chicago' AND incident_time >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 MONTH);
Calculate the total waste generated by the 'Plastics' department in 2020
CREATE TABLE waste (dept VARCHAR(20),year INT,amount INT); INSERT INTO waste (dept,year,amount) VALUES ('Electronics',2020,1500),('Plastics',2019,2000),('Plastics',2020,1800),('Metals',2020,1200);
SELECT SUM(amount) FROM waste WHERE dept = 'Plastics' AND year = 2020;
What is the total amount of food aid (in tons) provided to 'refugee_camps' table where the 'location' is 'middle_east'?
CREATE TABLE refugee_camps (id INT,camp_name TEXT,location TEXT,population INT,food_aid_tons FLOAT);
SELECT SUM(food_aid_tons) FROM refugee_camps WHERE location = 'middle_east';
What is the total budget allocated for education in rural areas?
CREATE TABLE BudgetAllocation (Department VARCHAR(25),Location VARCHAR(25),Budget INT); INSERT INTO BudgetAllocation (Department,Location,Budget) VALUES ('Education','Rural',8000000),('Education','Urban',10000000),('Health','Rural',7000000);
SELECT SUM(Budget) FROM BudgetAllocation WHERE Department = 'Education' AND Location = 'Rural';
What is the total budget for support programs by disability type?
CREATE TABLE support_programs (program_id INT,program_name VARCHAR(50),budget INT,disability_type VARCHAR(50)); INSERT INTO support_programs (program_id,program_name,budget,disability_type) VALUES (1,'Assistive Technology',50000,'Physical');
SELECT disability_type, SUM(budget) as total_budget FROM support_programs GROUP BY disability_type;
Summarize the total cargo weight transported by each vessel in a given month
VESSEL(vessel_id,vessel_name); TRIP(voyage_id,trip_date,vessel_id,cargo_weight)
SELECT v.vessel_id, v.vessel_name, DATEPART(year, t.trip_date) AS year, DATEPART(month, t.trip_date) AS month, SUM(t.cargo_weight) AS total_cargo_weight FROM VESSEL v JOIN TRIP t ON v.vessel_id = t.vessel_id WHERE t.trip_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY v.vessel_id, v.vessel_name, DATEPART(year, t.tr...
Update the recycling rate for the 'Urban' region in 2023 to 40%.
CREATE TABLE recycling_rates(region VARCHAR(20),year INT,recycling_rate FLOAT); INSERT INTO recycling_rates(region,year,recycling_rate) VALUES('Urban',2021,35.5),('Urban',2022,37.3),('Urban',2023,0),('Rural',2021,28.2),('Rural',2022,30.1);
UPDATE recycling_rates SET recycling_rate = 40 WHERE region = 'Urban' AND year = 2023;
Delete donation records with amounts less than $50 and dated before 2021.
CREATE TABLE Donations (DonationID int,DonationAmount decimal(10,2),DonationDate date); INSERT INTO Donations (DonationID,DonationAmount,DonationDate) VALUES (1,500,'2021-07-01'),(2,300,'2021-09-05'),(3,75,'2020-12-31'),(4,25,'2020-06-15');
DELETE FROM Donations WHERE DonationAmount < 50 AND DonationDate < '2021-01-01';
List the policies that have not been reviewed in the last 6 months, along with their reviewers and the date they were last reviewed.
CREATE TABLE cybersecurity_policies (id INT,policy_name TEXT,reviewer TEXT,last_review_date DATETIME); INSERT INTO cybersecurity_policies (id,policy_name,reviewer,last_review_date) VALUES (1,'Policy1','Alice','2022-03-01 12:00:00'),(2,'Policy2','Bob','2022-04-15 13:00:00');
SELECT policy_name, reviewer, last_review_date FROM cybersecurity_policies WHERE last_review_date < DATE_SUB(NOW(), INTERVAL 6 MONTH);
Update the revenue for the Jazz genre in the USA for the year 2020 to 6000.0
CREATE TABLE music_genres (genre VARCHAR(255),country VARCHAR(255),revenue FLOAT); INSERT INTO music_genres (genre,country,revenue) VALUES ('Pop','USA',10000.0),('Rock','USA',8000.0),('Jazz','USA',5000.0);
UPDATE music_genres SET revenue = 6000.0 WHERE genre = 'Jazz' AND country = 'USA' AND YEAR(event_date) = 2020;
What is the average age of visitors who attended exhibitions in Paris in the last 6 months?
CREATE TABLE exhibitions (id INT,city VARCHAR(20),visitor_age INT,visit_date DATE); INSERT INTO exhibitions (id,city,visitor_age,visit_date) VALUES (1,'Paris',35,'2022-01-01'); INSERT INTO exhibitions (id,city,visitor_age,visit_date) VALUES (2,'Paris',42,'2022-02-15');
SELECT AVG(visitor_age) FROM exhibitions WHERE city = 'Paris' AND visit_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
Update animal_population_summary view when birth_rate changes in animal_population table
CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),population INT,birth_rate DECIMAL(4,2),death_rate DECIMAL(4,2));
CREATE OR REPLACE VIEW animal_population_summary AS SELECT animal_name, population, (population * birth_rate) - (population * death_rate) AS net_change FROM animal_population;
What is the average duration of legal aid cases in 'justice_legal_aid' table, in months?
CREATE TABLE justice_legal_aid (id INT,case_id INT,case_type TEXT,duration INT); INSERT INTO justice_legal_aid (id,case_id,case_type,duration) VALUES (1,1,'Civil',6),(2,2,'Criminal',12),(3,3,'Civil',3);
SELECT AVG(duration/30.0) FROM justice_legal_aid WHERE case_type = 'Civil';
Find biosensor technology development projects in Sub-Saharan Africa.
CREATE TABLE biosensor_tech (id INT,project_name VARCHAR(100),location VARCHAR(50)); INSERT INTO biosensor_tech (id,project_name,location) VALUES (1,'BioSense X','Sub-Saharan Africa'); INSERT INTO biosensor_tech (id,project_name,location) VALUES (2,'Genomic Y','North America'); INSERT INTO biosensor_tech (id,project_na...
SELECT * FROM biosensor_tech WHERE location = 'Sub-Saharan Africa';
Update the water usage for New York in 2020 to 5000.
CREATE TABLE water_usage(state VARCHAR(20),year INT,usage FLOAT);
UPDATE water_usage SET usage=5000 WHERE state='New York' AND year=2020;
What is the distribution of digital divide index values for countries in the European Union?
CREATE TABLE digital_divide (id INT,country VARCHAR,region VARCHAR,index_value DECIMAL);
SELECT region, MIN(index_value) as min_index, MAX(index_value) as max_index, AVG(index_value) as avg_index FROM digital_divide WHERE region = 'European Union' GROUP BY region;
List the names and locations of all marine research facilities in the Arctic ocean.
CREATE TABLE marine_research_facilities (facility_name TEXT,location TEXT); INSERT INTO marine_research_facilities (facility_name,location) VALUES ('Facility 1','Arctic Ocean'),('Facility 2','Antarctic Ocean'),('Facility 3','Atlantic Ocean');
SELECT facility_name, location FROM marine_research_facilities WHERE location = 'Arctic Ocean';
What is the average age of patients who have been vaccinated against Measles, by gender?
CREATE TABLE vaccinations (id INT,patient_id INT,vaccine_date DATE,vaccine_type VARCHAR(255),gender VARCHAR(255),age INT);
SELECT gender, AVG(age) AS avg_age FROM vaccinations WHERE vaccine_type = 'Measles' GROUP BY gender;
What is the maximum carbon offset achieved by smart city projects in South Korea in 2018?
CREATE TABLE smart_city_projects (id INT,project_name VARCHAR(100),carbon_offset FLOAT,year INT,country VARCHAR(50)); INSERT INTO smart_city_projects (id,project_name,carbon_offset,year,country) VALUES (1,'Smart Grid',10000,2015,'Japan'),(2,'Smart Transportation',15000,2017,'South Korea'),(3,'Smart Waste Management',13...
SELECT MAX(carbon_offset) FROM smart_city_projects WHERE year = 2018 AND country = 'South Korea';
What is the weight of all cargo loaded in the port of Valparaíso, Chile?
CREATE TABLE ports (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE cargo (id INT PRIMARY KEY,name VARCHAR(255),description TEXT,weight FLOAT,volume FLOAT,port_id INT,vessel_id INT,FOREIGN KEY (port_id) REFERENCES ports(id),FOREIGN KEY (vessel_id) REFERENCES vessels(id));
SELECT SUM(weight) FROM cargo WHERE port_id = (SELECT id FROM ports WHERE name = 'Valparaíso');
What is the total budget spent on AI projects by organizations in the technology for social good sector?
CREATE TABLE social_good_projects (organization_name TEXT,sector TEXT,budget INTEGER); INSERT INTO social_good_projects (organization_name,sector,budget) VALUES ('AIforGood','technology for social good',1500000),('Tech4Good','technology for social good',2000000),('AIforChange','ethical AI',1000000);
SELECT SUM(budget) FROM social_good_projects WHERE sector = 'technology for social good';
What is the average processing time for creative AI applications in the US region?
CREATE TABLE Creative_AI_Apps (app_id INT,app_name VARCHAR(50),region VARCHAR(50),processing_time FLOAT); INSERT INTO Creative_AI_Apps (app_id,app_name,region,processing_time) VALUES (1,'TextGen','US',0.45),(2,'ImageGen','US',0.32),(3,'MusicGen','CA',0.51);
SELECT AVG(processing_time) FROM Creative_AI_Apps WHERE region = 'US';
What is the maximum carbon offset amount achieved in a single carbon offset program in South America?
CREATE TABLE CarbonOffsetPrograms (id INT,region VARCHAR(20),carbon_offset_amount INT); INSERT INTO CarbonOffsetPrograms (id,region,carbon_offset_amount) VALUES (1,'South America',5000),(2,'South America',7000),(3,'Africa',6000);
SELECT MAX(carbon_offset_amount) FROM CarbonOffsetPrograms WHERE region = 'South America';
Insert a new bike sharing station in the city of Seattle
CREATE TABLE bike_sharing_stations (id INT PRIMARY KEY,station_name VARCHAR(255),city VARCHAR(255),num_bikes_available INT,num_docks_available INT);
INSERT INTO bike_sharing_stations (id, station_name, city, num_bikes_available, num_docks_available) VALUES (501, 'Westlake Park', 'Seattle', 15, 20);
Display the production quantity, waste produced, and energy consumption for each chemical at the site with the highest total energy consumption
CREATE TABLE Chemical_Production (site_id INT,chemical_id INT,production_quantity INT,waste_amount DECIMAL(5,2),energy_consumption INT);
SELECT cp.chemical_id, cp.production_quantity, cp.waste_amount, cp.energy_consumption FROM Chemical_Production cp JOIN (SELECT site_id, MAX(SUM(energy_consumption)) as max_energy FROM Chemical_Production GROUP BY site_id) m ON cp.site_id = m.site_id GROUP BY cp.chemical_id, cp.production_quantity, cp.waste_amount, cp.e...
Delete policy records with coverage amounts less than $25000 and effective dates before 2020-01-01.
CREATE TABLE Policies (PolicyNumber VARCHAR(20),CoverageAmount INT,EffectiveDate DATE); INSERT INTO Policies (PolicyNumber,CoverageAmount,EffectiveDate) VALUES ('P001',50000,'2021-01-01');
DELETE FROM Policies WHERE CoverageAmount < 25000 AND EffectiveDate < '2020-01-01';
What are the contents of posts with more than 1000 impressions?
CREATE TABLE posts (id INT PRIMARY KEY,user_id INT,content TEXT,impressions INT); INSERT INTO posts (id,user_id,content,impressions) VALUES (1,1,'AI is cool!',1500); INSERT INTO posts (id,user_id,content,impressions) VALUES (2,2,'Machine learning rocks!',1200);
SELECT content FROM posts WHERE impressions > 1000;
How many traditional art pieces are there in total, and what is their average quantity?
CREATE TABLE Art (ArtID INT,Type VARCHAR(255),Region VARCHAR(255),Quantity INT); INSERT INTO Art (ArtID,Type,Region,Quantity) VALUES (1,'Painting','Asia',25),(2,'Sculpture','Africa',18),(3,'Textile','South America',30),(4,'Pottery','Europe',20),(5,'Jewelry','North America',12);
SELECT SUM(Quantity) as Total_Quantity, AVG(Quantity) as Average_Quantity FROM Art;
Get the names of attorneys with a 'civil' case
CREATE TABLE attorneys (id INT,name VARCHAR(50),department VARCHAR(20)); CREATE TABLE cases (id INT,attorney_id INT,case_number VARCHAR(20),case_type VARCHAR(10)); INSERT INTO attorneys (id,name,department) VALUES (1,'John Doe','criminal'); INSERT INTO attorneys (id,name,department) VALUES (2,'Jane Smith','civil'); INS...
SELECT attorneys.name FROM attorneys JOIN cases ON attorneys.id = cases.attorney_id WHERE cases.case_type = 'civil';
What was the total donation amount by each program in '2022'?
CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount DECIMAL,donation_date DATE,program_id INT); INSERT INTO donations (donation_id,donor_id,donation_amount,donation_date,program_id) VALUES (1,1,50.00,'2022-01-01',1); CREATE TABLE programs (program_id INT,program_name TEXT); INSERT INTO programs (progra...
SELECT p.program_name, SUM(d.donation_amount) FROM donations d JOIN programs p ON d.program_id = p.program_id WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY p.program_name;
What is the average media literacy score for countries with a population over 100 million?
CREATE TABLE country_population (id INT,user_id INT,country VARCHAR(50),population INT); INSERT INTO country_population (id,user_id,country,population) VALUES (1,1,'China',1439323776),(2,2,'India',1380004385),(3,3,'United States',331002651),(4,4,'Indonesia',273523615),(5,5,'Pakistan',220892340),(6,6,'Brazil',212559417)...
SELECT AVG(score) as avg_score FROM media_literacy m JOIN country_population c ON m.country = c.country WHERE population > 100000000;
What is the total revenue of makeup products with SPF higher than 30?
CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); CREATE VIEW makeup_products AS SELECT * FROM products WHERE category = 'Makeup' AND has_spf = TRUE;
SELECT SUM(sales.quantity * sales.price) FROM sales JOIN makeup_products ON sales.product_id = makeup_products.product_id WHERE makeup_products.spf > 30;
What is the total funding for conservation efforts in the Pacific Ocean?
CREATE TABLE ConservationEfforts (ID INT,Species VARCHAR(50),Year INT,Funding DECIMAL(10,2),Ocean VARCHAR(50)); INSERT INTO ConservationEfforts (ID,Species,Year,Funding,Ocean) VALUES (1,'Dugong',2015,500000.00,'Atlantic'); INSERT INTO ConservationEfforts (ID,Species,Year,Funding,Ocean) VALUES (2,'Turtle',2016,600000.00...
SELECT SUM(Funding) as TotalFunding FROM ConservationEfforts WHERE Ocean = 'Pacific';
What is the average fine amount for traffic violations in 'justice_traffic' table?
CREATE TABLE justice_traffic (id INT,violation_type TEXT,fine_amount INT); INSERT INTO justice_traffic (id,violation_type,fine_amount) VALUES (1,'Speeding',100),(2,'Running Red Light',200),(3,'Parking Violation',50);
SELECT AVG(fine_amount) FROM justice_traffic WHERE violation_type = 'traffic';
Which neighborhoods have experienced the most natural disasters in the last 5 years?
CREATE TABLE neighborhoods (neighborhood_id INT,neighborhood_name VARCHAR(255)); CREATE TABLE disasters (disaster_id INT,neighborhood_id INT,disaster_year INT);
SELECT n.neighborhood_name, COUNT(*) as disaster_count FROM neighborhoods n INNER JOIN disasters d ON n.neighborhood_id = d.neighborhood_id WHERE disaster_year >= YEAR(CURRENT_DATE) - 5 GROUP BY n.neighborhood_name ORDER BY disaster_count DESC;
What is the average number of likes for posts in Japanese?
CREATE TABLE posts (id INT,language VARCHAR(255),likes INT); INSERT INTO posts (id,language,likes) VALUES (1,'English',10),(2,'Japanese',25),(3,'French',30),(4,'Japanese',45);
SELECT AVG(likes) FROM posts WHERE language = 'Japanese';
Update the 'Grape Ape' sales record from July 20, 2021 to 7 units.
CREATE TABLE Sales (id INT,product VARCHAR(255),sold_date DATE,quantity INT); INSERT INTO Sales (id,product,sold_date,quantity) VALUES (1,'Grape Ape','2021-07-20',6);
UPDATE Sales SET quantity = 7 WHERE product = 'Grape Ape' AND sold_date = '2021-07-20';
Find the department with the highest average grant amount.
CREATE TABLE grant_applications (id INT,department VARCHAR(50),amount DECIMAL(10,2));
SELECT department, AVG(amount) AS avg_grant_amount FROM grant_applications GROUP BY department ORDER BY avg_grant_amount DESC LIMIT 1;
Report the number of policy changes in the 'Transportation' area from 2018 to 2020, and the policy change descriptions.
CREATE TABLE policy_changes (id INT,area VARCHAR(255),change_date DATE,description TEXT); INSERT INTO policy_changes (id,area,change_date,description) VALUES (1,'Transportation','2019-01-01','Change 1'),(2,'Transportation','2018-07-15','Change 2'),(3,'Transportation','2020-03-04','Change 3');
SELECT COUNT(*) as num_changes, description FROM policy_changes WHERE area = 'Transportation' AND change_date BETWEEN '2018-01-01' AND '2020-12-31' GROUP BY description
What was the minimum price for any Pop Art pieces sold in the year 1990?
CREATE TABLE art_pieces (id INT,artist VARCHAR(30),style VARCHAR(20),year_sold INT,price DECIMAL(10,2)); CREATE VIEW pop_art_sales AS SELECT * FROM art_pieces WHERE style = 'Pop Art';
SELECT style, MIN(price) FROM pop_art_sales WHERE year_sold = 1990 GROUP BY style;
How many volunteers signed up in Q1 2021, categorized by their location?
CREATE TABLE volunteers (id INT,name VARCHAR(50),location VARCHAR(30),signup_date DATE); INSERT INTO volunteers (id,name,location,signup_date) VALUES (1,'Michael','New York','2021-01-01'),(2,'Sarah','California','2021-02-15'),(3,'David','Texas','2021-03-03'),(4,'Emma','Florida','2021-04-20'),(5,'Oliver','Illinois','202...
SELECT location, COUNT(*) as new_volunteers FROM volunteers WHERE signup_date BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY location;
Delete all records of discrimination complaints that occurred more than 2 years ago.
CREATE TABLE discrimination_complaints (id INT PRIMARY KEY,complaint_type VARCHAR(255),date DATE);
DELETE FROM discrimination_complaints WHERE date <= DATE_SUB(CURDATE(), INTERVAL 2 YEAR);
Find the total revenue generated from exhibition sales in Paris.
CREATE TABLE ExhibitionSales (id INT,city VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO ExhibitionSales (id,city,revenue) VALUES (1,'Paris',5000),(2,'Paris',7000),(3,'Berlin',8000);
SELECT SUM(revenue) FROM ExhibitionSales WHERE city = 'Paris';
What is the total timber volume in temperate forests for each year?
CREATE TABLE forest_timber (id INT,region VARCHAR(20),year INT,volume FLOAT); INSERT INTO forest_timber (id,region,year,volume) VALUES (1,'Temperate',2018,5000),(2,'Temperate',2019,5500),(3,'Temperate',2020,6000),(4,'Temperate',2021,6500);
SELECT year, SUM(volume) as total_volume FROM forest_timber WHERE region = 'Temperate' GROUP BY year;
What is the minimum installed capacity (in MW) for hydro projects in the 'renewable_energy' table?
CREATE TABLE renewable_energy (project_id INT,location TEXT,installed_capacity FLOAT,technology TEXT); INSERT INTO renewable_energy (project_id,location,installed_capacity,technology) VALUES (1,'Niagara Falls',2000,'Hydro'),(2,'Amazon River',12000,'Hydro'),(3,'Mississippi River',3000,'Hydro');
SELECT MIN(installed_capacity) FROM renewable_energy WHERE technology = 'Hydro';
What is the total number of yellow cards given to each team in the UEFA Champions League?
CREATE TABLE ucl_yellow_cards (team VARCHAR(50),yellow_cards INT); INSERT INTO ucl_yellow_cards (team,yellow_cards) VALUES ('Barcelona',50),('Real Madrid',60),('Bayern Munich',45);
SELECT team, SUM(yellow_cards) AS total_yellow_cards FROM ucl_yellow_cards GROUP BY team ORDER BY total_yellow_cards DESC;
What is the average number of cybersecurity professionals in countries with a population greater than 50 million?
CREATE TABLE populations (id INT,country_id INT,population INT); CREATE TABLE cybersecurity_personnel (id INT,country_id INT,number INT);
SELECT AVG(cp.number) as avg_cybersecurity_personnel FROM populations p JOIN cybersecurity_personnel cp ON p.country_id = cp.country_id WHERE p.population > 50000000;
What is the total number of articles by each author?
CREATE TABLE authors (id INT,name TEXT); CREATE TABLE articles (id INT,author_id INT,title TEXT); INSERT INTO authors VALUES (1,'Alice'),(2,'Bob'); INSERT INTO articles VALUES (1,1,'Article 1'),(2,1,'Article 2'),(3,2,'Article 3');
SELECT a.name, COUNT(*) as article_count FROM authors a JOIN articles ar ON a.id = ar.author_id GROUP BY a.name;
Delete the 'vehicle_sales' table and its records
CREATE TABLE vehicle_sales (id INT PRIMARY KEY,vehicle_model VARCHAR(255),units_sold INT);
DROP TABLE vehicle_sales;
Insert records for 500 units of Ytterbium production in Vietnam for 2022.
CREATE TABLE production (year INT,element VARCHAR(10),country VARCHAR(10),quantity INT);
INSERT INTO production (year, element, country, quantity) VALUES (2022, 'Ytterbium', 'Vietnam', 500);
What are the unique engineering design standards for water supply systems?
CREATE TABLE EngineeringDesignStandards (id INT,system_type TEXT,standard_number TEXT,description TEXT); INSERT INTO EngineeringDesignStandards (id,system_type,standard_number,description) VALUES (1,'Water Supply','Standard123','Water quality criteria'); INSERT INTO EngineeringDesignStandards (id,system_type,standard_n...
SELECT DISTINCT standard_number, description FROM EngineeringDesignStandards WHERE system_type = 'Water Supply';
Delete all records related to the "Math" subject from the "Courses" table
CREATE TABLE Courses (ID INT,Subject VARCHAR(50),Teacher VARCHAR(50));
DELETE FROM Courses WHERE Subject = 'Math';
How many high-risk customers are there in California?
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),state VARCHAR(20),risk_level VARCHAR(10)); INSERT INTO customers (customer_id,customer_name,state,risk_level) VALUES (1,'John Doe','CA','high'),(2,'Jane Smith','NY','medium');
SELECT COUNT(*) FROM customers WHERE state = 'CA' AND risk_level = 'high';
How many habitats were preserved in 2021 and 2022?
CREATE TABLE habitat_preservation (id INT,year INT,location VARCHAR(50),acres FLOAT); INSERT INTO habitat_preservation (id,year,location,acres) VALUES (1,2021,'Location1',50.5),(2,2022,'Location2',75.3);
SELECT SUM(acres) FROM habitat_preservation WHERE year IN (2021, 2022);
Create a table for diversity metrics
CREATE TABLE diversity_metrics (metric_id INT,category VARCHAR(20),value FLOAT);
CREATE TABLE diversity_metrics (metric_id INT, category VARCHAR(20), value FLOAT);
What is the number of unique users who streamed each artist, for artists who have performed at music festivals in the last year?
CREATE TABLE user_streams (user_id INT,artist_id INT,stream_date DATE);
SELECT a.artist_id, COUNT(DISTINCT u.user_id) as num_users FROM user_streams u JOIN festival_performances f ON u.artist_id = f.artist_id WHERE f.performance_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY a.artist_id;
What is the total weight of all engines used in NASA's Orion spacecraft?
CREATE TABLE spacecraft_engines (id INT,engine_model VARCHAR(50),spacecraft VARCHAR(50),engine_weight FLOAT);
SELECT SUM(engine_weight) FROM spacecraft_engines WHERE spacecraft = 'Orion';
What is the average ESG score for companies in the 'Finance' sector for each year since 2017?
CREATE TABLE companies (id INT,name VARCHAR(255),esg_score DECIMAL(3,2),sector VARCHAR(255),company_start_date DATE);
SELECT YEAR(company_start_date) AS year, AVG(esg_score) FROM companies WHERE sector = 'Finance' GROUP BY year;
Calculate the average temperature in the Arctic Circle for the year 2020
CREATE TABLE WeatherData (location VARCHAR(255),temperature INT,time DATETIME); INSERT INTO WeatherData (location,temperature,time) VALUES ('Arctic Circle',10,'2020-01-01 00:00:00'); INSERT INTO WeatherData (location,temperature,time) VALUES ('Arctic Circle',12,'2020-01-02 00:00:00');
SELECT AVG(temperature) FROM WeatherData WHERE location = 'Arctic Circle' AND YEAR(time) = 2020;
What are the top 3 broadband services with the highest revenue in the state of Texas, considering both subscription fees and one-time fees?
CREATE TABLE broadband_services (service_id INT,subscription_fee FLOAT,one_time_fee FLOAT,state VARCHAR(20));
SELECT service_id, subscription_fee + one_time_fee as total_revenue FROM broadband_services WHERE state = 'Texas' GROUP BY service_id ORDER BY total_revenue DESC LIMIT 3;
What is the average trip duration for eco-tourists from Canada?
CREATE TABLE eco_tourists (id INT,name VARCHAR,country VARCHAR,trip_duration FLOAT); INSERT INTO eco_tourists (id,name,country,trip_duration) VALUES (1,'John Doe','Canada',14.5);
SELECT AVG(trip_duration) FROM eco_tourists WHERE country = 'Canada';
How many safety incidents were reported per week in the chemical manufacturing plant located in Berlin in 2019?
CREATE TABLE safety_berlin (plant_location VARCHAR(50),incident_date DATE); INSERT INTO safety_berlin (plant_location,incident_date) VALUES ('Berlin chemical plant','2019-01-01'); INSERT INTO safety_berlin (plant_location,incident_date) VALUES ('Berlin chemical plant','2019-01-07');
SELECT date_format(incident_date, '%Y-%V') as week, count(*) as total_incidents FROM safety_berlin WHERE plant_location = 'Berlin chemical plant' GROUP BY week;
What is the total revenue generated by eco-friendly hotels in Germany in 2021?
CREATE TABLE german_eco_hotels (hotel_id INT,name VARCHAR(255),country VARCHAR(255),revenue INT); INSERT INTO german_eco_hotels (hotel_id,name,country,revenue) VALUES (1,'Eco Hotel Berlin','Germany',300000),(2,'Green Hotel Munich','Germany',400000);
SELECT SUM(revenue) FROM german_eco_hotels WHERE country = 'Germany' AND YEAR(hotel_opening_date) = 2021;
What is the total number of hybrid buses in Beijing and their total distance covered?
CREATE TABLE hybrid_buses (bus_id INT,distance FLOAT,city VARCHAR(50));
SELECT COUNT(*), SUM(distance) FROM hybrid_buses WHERE city = 'Beijing';
What is the average life expectancy in rural areas of Nigeria?
CREATE TABLE rural_areas_nigeria (area_id INT,area_name VARCHAR(50),state VARCHAR(20),average_life_expectancy DECIMAL(3,1));
SELECT AVG(average_life_expectancy) AS avg_life_expectancy FROM rural_areas_nigeria WHERE is_rural = true;
List the top 3 countries with the highest number of impact investments?
CREATE TABLE impact_investments (id INT,investment_id INT,country TEXT); INSERT INTO impact_investments (id,investment_id,country) VALUES (1,1001,'United States'),(2,1002,'Canada'),(3,1003,'United States'),(4,1004,'Brazil'),(5,1005,'India');
SELECT country, COUNT(*) AS investment_count FROM impact_investments GROUP BY country ORDER BY investment_count DESC LIMIT 3;
What is the maximum budget allocated to any project related to housing in the state of Florida in the year 2021?
CREATE TABLE HousingProjects (ProjectID INT,Name VARCHAR(100),Budget DECIMAL(10,2),Year INT,State VARCHAR(50)); INSERT INTO HousingProjects (ProjectID,Name,Budget,Year,State) VALUES (1,'Public Housing Development',30000000,2021,'Florida'),(2,'Affordable Housing Construction',1000000,2021,'Florida'),(3,'Housing Assistan...
SELECT MAX(Budget) FROM HousingProjects WHERE Year = 2021 AND State = 'Florida' AND Name LIKE '%housing%';
Show the top 3 states with the highest number of rural hospitals
CREATE TABLE rural_hospitals (id INT,name VARCHAR(50),state VARCHAR(20)); INSERT INTO rural_hospitals (id,name,state) VALUES (1,'Rural General Hospital','Queensland'),(2,'Rural Hospital A','New South Wales'),(3,'Rural Hospital B','New South Wales'),(4,'Rural Hospital C','Victoria'),(5,'Rural Hospital D','Western Austra...
SELECT state, COUNT(*) as num_hospitals FROM rural_hospitals GROUP BY state ORDER BY num_hospitals DESC LIMIT 3;
What is the percentage of uninsured individuals by ethnic group?
CREATE TABLE health_insurance_ethnicity (ethnicity VARCHAR(20),uninsured INT); INSERT INTO health_insurance_ethnicity (ethnicity,uninsured) VALUES ('African American',50),('Hispanic',200),('Asian American',150),('Native American',100);
SELECT ethnicity, uninsured, ROUND(100.0 * uninsured / SUM(uninsured) OVER (), 2) AS pct_uninsured FROM health_insurance_ethnicity;
What is the total watch time by users segmented by content type?
CREATE TABLE users (user_id INT,user_name VARCHAR(50),age INT,gender VARCHAR(10)); CREATE TABLE content (content_id INT,content_type VARCHAR(20),views INT,watch_time INT);
SELECT content_type, SUM(watch_time) as total_watch_time FROM users JOIN content ON users.user_id = content.user_id GROUP BY content_type;
What is the difference in production quantity for each Rare Earth element between 2015 and 2020 for companies located in the Asia-Pacific region?
CREATE TABLE Producers (ProducerID INT PRIMARY KEY,Name TEXT,ProductionYear INT,RareEarth TEXT,Quantity INT,Location TEXT);
SELECT RareEarth, ProductionYear, SUM(Quantity) - (SELECT SUM(Quantity) FROM Producers p2 WHERE p2.RareEarth = p1.RareEarth AND p2.ProductionYear = 2015) AS Difference FROM Producers p1 WHERE ProductionYear = 2020 AND Location LIKE '%Asia-Pacific%' GROUP BY RareEarth, ProductionYear;
What is the total investment in 'gender_equality' initiatives?
CREATE TABLE initiatives (id INT,sector VARCHAR(20),investment_amount FLOAT)
SELECT SUM(investment_amount) FROM initiatives WHERE sector = 'gender_equality'
Insert a new artifact record into the artifacts table for a bronze spearhead.
artifacts(artifact_id,name,description,date_found,excavation_site_id); excavations(excavation_site_id,name,location,start_date,end_date)
INSERT INTO artifacts (artifact_id, name, description, date_found, excavation_site_id)
What is the average number of publications per graduate student?
CREATE TABLE graduate_students (id INT,program_id INT,gender VARCHAR(10),num_publications INT); INSERT INTO graduate_students (id,program_id,gender,num_publications) VALUES (1,1,'Female',1),(2,1,'Male',2),(3,2,'Female',0),(4,2,'Non-binary',1),(5,3,'Male',3),(6,3,'Female',2);
SELECT AVG(num_publications) FROM graduate_students;
Delete travel advisories for 'Japan' with a risk level of 3 or higher.
CREATE TABLE travel_advisories (id INT,title TEXT,country TEXT,risk_level INT,date DATE);
DELETE FROM travel_advisories WHERE country = 'Japan' AND risk_level >= 3;
What is the percentage of co-owned properties in each country?
CREATE TABLE properties (id INT,is_co_owned BOOLEAN,country VARCHAR(255)); INSERT INTO properties (id,is_co_owned,country) VALUES (1,true,'USA'),(2,false,'USA'),(3,true,'Canada'),(4,false,'Canada');
SELECT country, 100.0 * COUNT(*) FILTER (WHERE is_co_owned = true) / COUNT(*) as pct_co_owned FROM properties GROUP BY country;
Identify the number of students who require accommodations by accommodation type and their enrollment status.
CREATE TABLE student_enrollment (student_id INT,enrollment_status VARCHAR(50),requires_accommodation BOOLEAN); INSERT INTO student_enrollment (student_id,enrollment_status,requires_accommodation) VALUES (1,'Enrolled',TRUE),(2,'Dropped',FALSE);
SELECT accommodation_type, enrollment_status, COUNT(*) FROM student_enrollment JOIN accommodations ON student_enrollment.student_id = accommodations.student_id GROUP BY accommodation_type, enrollment_status;
Insert new records for a 'storage' table: Japan, 200, lithium_ion
CREATE TABLE storage (country VARCHAR(20),capacity INT,battery_type VARCHAR(20));
INSERT INTO storage (country, capacity, battery_type) VALUES ('Japan', 200, 'lithium_ion');
Find the top 5 smart contracts with the highest total gas usage in the last week on the Binance Smart Chain.
CREATE TABLE smart_contracts (contract_id INT,contract_address VARCHAR(42)); CREATE TABLE binance_transactions (transaction_id INT,contract_id INT,gas_used INT,transaction_time TIMESTAMP);
SELECT s.contract_address, SUM(bt.gas_used) as total_gas_used FROM smart_contracts s JOIN binance_transactions bt ON s.contract_id = bt.contract_id WHERE bt.transaction_time >= NOW() - INTERVAL '1 week' GROUP BY s.contract_address ORDER BY total_gas_used DESC LIMIT 5;
What is the total time spent on workouts for each member who has a loyalty membership?
CREATE TABLE Workouts (WorkoutID INT,Duration INT,MemberID INT); INSERT INTO Workouts (WorkoutID,Duration,MemberID) VALUES (1,60,1); INSERT INTO Workouts (WorkoutID,Duration,MemberID) VALUES (2,90,2); CREATE TABLE Members (MemberID INT,Name VARCHAR(50),MembershipType VARCHAR(50)); INSERT INTO Members (MemberID,Name,Mem...
SELECT Members.Name, SUM(Workouts.Duration) FROM Workouts INNER JOIN Members ON Workouts.MemberID = Members.MemberID WHERE Members.MembershipType = 'Loyalty' GROUP BY Members.Name;
Who are the volunteers with the most volunteer hours in the 'Education' department?
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,Department TEXT,Hours FLOAT); INSERT INTO Volunteers (VolunteerID,Name,Department,Hours) VALUES (1,'Alice','Education',30),(2,'Bob','Fundraising',25);
SELECT Name, SUM(Hours) as TotalHours FROM Volunteers WHERE Department = 'Education' GROUP BY Name ORDER BY TotalHours DESC;
How many specialists are available in each rural clinic in Washington state?
CREATE TABLE specialists (specialist_id INT,clinic_id INT,specialty VARCHAR(50)); INSERT INTO specialists (specialist_id,clinic_id,specialty) VALUES (1,1,'Cardiology'),(2,1,'Dermatology'),(3,2,'Cardiology'),(4,3,'Dermatology'); CREATE TABLE rural_clinics (clinic_id INT,state VARCHAR(2)); INSERT INTO rural_clinics (clin...
SELECT r.clinic_id, COUNT(s.specialist_id) AS specialists_count FROM specialists s JOIN rural_clinics r ON s.clinic_id = r.clinic_id WHERE r.state = 'Washington' GROUP BY r.clinic_id;
What is the maximum discovery of Uranium in Russia in 2019?
CREATE TABLE exploration_data (year INT,location VARCHAR(20),mineral VARCHAR(20),discovery FLOAT); INSERT INTO exploration_data (year,location,mineral,discovery) VALUES (2015,'Canada','Gold',1200.5),(2015,'Canada','Silver',1500.2),(2016,'Mexico','Gold',1700.0),(2016,'Mexico','Silver',2000.0),(2019,'Russia','Uranium',25...
SELECT mineral, MAX(discovery) as max_discovery FROM exploration_data WHERE location = 'Russia' AND mineral = 'Uranium' AND year = 2019;
What was the total revenue for lipsticks sold in the USA in Q1 2022?
CREATE TABLE cosmetics_sales(product_type VARCHAR(255),country VARCHAR(255),sales_quantity INT,sales_revenue DECIMAL(10,2));
SELECT SUM(sales_revenue) FROM cosmetics_sales WHERE product_type = 'lipstick' AND country = 'USA' AND sales_date BETWEEN '2022-01-01' AND '2022-03-31';