instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Insert a new record for a sustainable sourcing practice
|
CREATE TABLE sustainable_sourcing (item_id INT,sourcing_date DATE,sustainability_practice VARCHAR(255));
|
INSERT INTO sustainable_sourcing (item_id, sourcing_date, sustainability_practice) VALUES (456, '2022-05-01', 'Organic Ingredients');
|
Identify the decentralized application with the most code updates in the 'Storage' industry sector during Q2 2022.
|
CREATE TABLE code_updates (dapp_name VARCHAR(20),industry_sector VARCHAR(10),quarter INT,update_count INT); INSERT INTO code_updates (dapp_name,industry_sector,quarter,update_count) VALUES ('AppA','Storage',1,500),('AppB','Storage',2,750),('AppC','Storage',3,1000),('AppD','Storage',4,1250),('AppE','Storage',2,1500);
|
SELECT dapp_name, update_count FROM code_updates WHERE industry_sector = 'Storage' AND quarter = 2 ORDER BY update_count DESC LIMIT 1;
|
What is the total number of security incidents for each severity level in Q1 2022?
|
CREATE TABLE security_incidents (id INT,incident_type TEXT,date_reported DATE,severity TEXT); INSERT INTO security_incidents (id,incident_type,date_reported,severity) VALUES (1,'Phishing','2022-01-01','High');
|
SELECT severity, SUM(CASE WHEN date_reported >= '2022-01-01' AND date_reported < '2022-02-01' THEN 1 ELSE 0 END) as count_january, SUM(CASE WHEN date_reported >= '2022-02-01' AND date_reported < '2022-03-01' THEN 1 ELSE 0 END) as count_february, SUM(CASE WHEN date_reported >= '2022-03-01' AND date_reported < '2022-04-01' THEN 1 ELSE 0 END) as count_march FROM security_incidents WHERE severity IN ('Critical', 'High', 'Medium', 'Low') GROUP BY severity;
|
List all financial capability programs offered by providers in the US?
|
CREATE TABLE financial_capability_programs (provider VARCHAR(50),program VARCHAR(50),country VARCHAR(50)); INSERT INTO financial_capability_programs (provider,program,country) VALUES ('Bank C','Financial Literacy 101','USA'),('Credit Union D','Youth Financial Education','Canada');
|
SELECT DISTINCT provider, program FROM financial_capability_programs WHERE country = 'USA';
|
What is the total amount donated by individuals in the United States?
|
CREATE TABLE donors (donor_id INT,donor_name TEXT,country TEXT,amount DECIMAL(10,2)); INSERT INTO donors (donor_id,donor_name,country,amount) VALUES (1,'John Doe','USA',100.00); INSERT INTO donors (donor_id,donor_name,country,amount) VALUES (2,'Jane Smith','Canada',200.00);
|
SELECT SUM(amount) FROM donors WHERE country = 'USA';
|
Decrease the number of workers benefitting from fair labor practices in 'Africa' by 20% in the 'fair_labor_practices' table.
|
CREATE TABLE fair_labor_practices (practice_id INT,brand_id INT,region TEXT,workers_benefitted INT);
|
UPDATE fair_labor_practices SET workers_benefitted = workers_benefitted * 0.8 WHERE region = 'Africa';
|
What is the maximum number of cases handled by a public defender in a year?
|
CREATE TABLE public_defenders (defender_id INT,cases_handled INT,year INT);
|
SELECT MAX(cases_handled) FROM public_defenders WHERE year = (SELECT MAX(year) FROM public_defenders);
|
Identify the number of cultural heritage sites and virtual tours offered in Spain and Portugal, and find the difference between the two numbers.
|
CREATE TABLE cultural_sites (site_id INT,country VARCHAR(20),type VARCHAR(20)); INSERT INTO cultural_sites (site_id,country,type) VALUES (1,'Spain','heritage'),(2,'Portugal','heritage'),(3,'Spain','heritage'),(4,'Spain','virtual'),(5,'Portugal','virtual');
|
SELECT COUNT(*) FROM cultural_sites WHERE country = 'Spain' AND type = 'heritage' UNION ALL SELECT COUNT(*) FROM cultural_sites WHERE country = 'Portugal' AND type = 'heritage' UNION ALL SELECT COUNT(*) FROM cultural_sites WHERE country = 'Spain' AND type = 'virtual' UNION ALL SELECT COUNT(*) FROM cultural_sites WHERE country = 'Portugal' AND type = 'virtual' EXCEPT (SELECT * FROM (SELECT COUNT(*) FROM cultural_sites WHERE country = 'Spain' AND type = 'heritage' UNION ALL SELECT COUNT(*) FROM cultural_sites WHERE country = 'Portugal' AND type = 'heritage' UNION ALL SELECT COUNT(*) FROM cultural_sites WHERE country = 'Spain' AND type = 'virtual' UNION ALL SELECT COUNT(*) FROM cultural_sites WHERE country = 'Portugal' AND type = 'virtual') AS subquery);
|
What is the average age of readers in 'readers' table?
|
CREATE TABLE readers (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),country VARCHAR(50));
|
SELECT AVG(age) FROM readers;
|
What is the total number of containers handled at ports in Europe, grouped by the quarter in which they were handled?
|
CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT); INSERT INTO ports VALUES (1,'Port A','Germany'),(2,'Port B','France'),(3,'Port C','Spain'); CREATE TABLE cargo (cargo_id INT,port_id INT,quantity INT,handling_date DATE); INSERT INTO cargo VALUES (1,1,500,'2022-01-01'),(2,1,600,'2022-01-02'),(3,2,700,'2022-01-01'),(4,1,800,'2022-04-03');
|
SELECT COUNT(cargo.quantity) FROM cargo JOIN ports ON cargo.port_id = ports.port_id WHERE ports.country = 'Europe' GROUP BY EXTRACT(QUARTER FROM cargo.handling_date);
|
Delete all records from the Waste table that have a WasteType of 'Radioactive Waste'.
|
CREATE TABLE Waste (WasteID INT,WasteType VARCHAR(50),Amount INT,Date DATE); INSERT INTO Waste (WasteID,WasteType,Amount,Date) VALUES (1,'Toxic Chemicals',120,'2022-01-01'); INSERT INTO Waste (WasteID,WasteType,Amount,Date) VALUES (2,'Radioactive Waste',50,'2022-02-01'); INSERT INTO Waste (WasteID,WasteType,Amount,Date) VALUES (3,'Plastic Waste',80,'2022-03-01');
|
DELETE FROM Waste WHERE WasteType = 'Radioactive Waste';
|
Which organizations have received donations from donors residing in the same city as the organization's headquarters?
|
CREATE TABLE organizations (org_id INT,org_name VARCHAR(50),org_city_id INT);CREATE TABLE donations (donation_id INT,donor_city_id INT,org_id INT); INSERT INTO organizations (org_id,org_name,org_city_id) VALUES (1,'Habitat for Humanity',1),(2,'Greenpeace',2),(3,'American Cancer Society',3); INSERT INTO donations (donation_id,donor_city_id,org_id) VALUES (1,1,1),(2,2,2),(3,3,3),(4,1,2),(5,2,3);
|
SELECT o.org_name, d.donor_city_id FROM organizations o INNER JOIN donations d ON o.org_city_id = d.donor_city_id AND o.org_id = d.org_id;
|
What is the average budget for excavations led by archaeologist 'Alex Nguyen'?
|
CREATE TABLE Archaeologists (ArchaeologistID INT,Name VARCHAR(50),Age INT); INSERT INTO Archaeologists (ArchaeologistID,Name,Age) VALUES (1,'Alex Nguyen',35); CREATE TABLE Excavations (ExcavationID INT,Site VARCHAR(50),ArchaeologistID INT,Budget DECIMAL(10,2)); INSERT INTO Excavations (ExcavationID,Site,ArchaeologistID,Budget) VALUES (1,'Vietnam Dig',1,25000.00); INSERT INTO Excavations (ExcavationID,Site,ArchaeologistID,Budget) VALUES (2,'Cambodia Exploration',1,30000.00);
|
SELECT AVG(E.Budget) FROM Archaeologists A INNER JOIN Excavations E ON A.ArchaeologistID = E.ArchaeologistID WHERE A.Name = 'Alex Nguyen';
|
What are the veteran employment statistics by state and gender?
|
CREATE TABLE veteran_employment (state VARCHAR(255),gender VARCHAR(255),employed_veterans INT,total_veterans INT); INSERT INTO veteran_employment (state,gender,employed_veterans,total_veterans) VALUES ('California','Male',400000,600000),('California','Female',100000,200000),('Texas','Male',350000,550000),('Texas','Female',50000,150000),('Florida','Male',300000,500000),('Florida','Female',50000,100000),('New York','Male',250000,450000),('New York','Female',50000,100000),('Pennsylvania','Male',200000,400000),('Pennsylvania','Female',50000,100000);
|
SELECT state, gender, SUM(employed_veterans) FROM veteran_employment GROUP BY state, gender;
|
Which speakers have given talks on ethical AI at the AI for Social Good Summit?
|
CREATE TABLE speakers (id INT PRIMARY KEY,name VARCHAR(255),affiliation VARCHAR(255),country VARCHAR(255)); INSERT INTO speakers (id,name,affiliation,country) VALUES (1,'Dr. Joy Buolamwini','MIT Media Lab','USA'); INSERT INTO speakers (id,name,affiliation,country) VALUES (2,'Prof. Virginia Dignum','Umeå University','Sweden'); INSERT INTO speakers (id,name,affiliation,country) VALUES (3,'Dr. Rumman Chowdhury','Twitter','USA'); CREATE TABLE talks (id INT PRIMARY KEY,title VARCHAR(255),speaker_id INT,conference_id INT,date DATE); INSERT INTO talks (id,title,speaker_id,conference_id,date) VALUES (1,'Algorithms of Oppression',1,6,'2022-10-02'); INSERT INTO talks (id,title,speaker_id,conference_id,date) VALUES (2,'Ethics for AI in Healthcare',1,5,'2022-10-02'); INSERT INTO talks (id,title,speaker_id,conference_id,date) VALUES (3,'Accountable AI Systems',2,4,'2022-09-02'); INSERT INTO talks (id,title,speaker_id,conference_id,date) VALUES (4,'Responsible AI in Social Media',3,6,'2022-11-02'); CREATE TABLE conference_speakers (talk_id INT,speaker_id INT); INSERT INTO conference_speakers (talk_id,speaker_id) VALUES (1,1); INSERT INTO conference_speakers (talk_id,speaker_id) VALUES (2,1); INSERT INTO conference_speakers (talk_id,speaker_id) VALUES (3,2); INSERT INTO conference_speakers (talk_id,speaker_id) VALUES (4,3);
|
SELECT speakers.name FROM speakers JOIN conference_speakers ON speakers.id = conference_speakers.speaker_id JOIN talks ON conference_speakers.talk_id = talks.id WHERE talks.title LIKE '%ethical AI%' AND talks.conference_id = 5;
|
What is the minimum ticket price for Pop concerts in the UK?
|
CREATE TABLE Concerts (country VARCHAR(50),genre VARCHAR(50),price DECIMAL(5,2)); INSERT INTO Concerts (country,genre,price) VALUES ('UK','Pop',35.99); INSERT INTO Concerts (country,genre,price) VALUES ('UK','Pop',39.49);
|
SELECT MIN(price) FROM Concerts WHERE country = 'UK' AND genre = 'Pop';
|
Find the number of IoT sensors in 'farm2' that recorded a minimum temperature below -5 degrees Celsius.
|
CREATE TABLE farm2 (id INT,sensor_id INT,temperature FLOAT); INSERT INTO farm2 (id,sensor_id,temperature) VALUES (1,101,-2.3),(2,102,-6.1),(3,103,0.5);
|
SELECT COUNT(*) FROM farm2 WHERE temperature < -5;
|
What is the total number of health equity metric evaluations conducted in each region?
|
CREATE TABLE evaluations (evaluation_id INT,evaluation_date DATE,region_id INT);
|
SELECT region_id, COUNT(*) as evaluation_count FROM evaluations GROUP BY region_id;
|
What is the average rating of tours in New Zealand with more than 100 reviews?
|
CREATE TABLE tours (id INT,name TEXT,country TEXT,rating FLOAT,reviews INT); INSERT INTO tours (id,name,country,rating,reviews) VALUES (1,'Milford Sound Day Tour','New Zealand',4.6,120),(2,'Doubtful Sound Day Tour','New Zealand',4.7,80),(3,'Hobbiton Movie Set Tour','New Zealand',4.8,250);
|
SELECT AVG(rating) FROM tours WHERE country = 'New Zealand' AND reviews > 100;
|
What is the maximum number of fire incidents in 'brooklyn' that occurred in a single day?
|
CREATE TABLE fire_incidents (id INT,incident_time TIMESTAMP,district VARCHAR(20)); INSERT INTO fire_incidents (id,incident_time,district) VALUES (1,'2022-02-01 12:30:00','brooklyn'),(2,'2022-02-02 15:10:00','bronx'),(3,'2022-02-02 09:45:00','brooklyn');
|
SELECT district, MAX(COUNT(*)) OVER (PARTITION BY district) AS max_incidents_per_day FROM fire_incidents GROUP BY district, DATE_TRUNC('day', incident_time);
|
Show me the total revenue for each location in the past month.
|
CREATE TABLE orders (order_id INT,location_id INT,item_id INT,quantity INT,date DATE); CREATE TABLE menu (item_id INT,item_name VARCHAR(50),category VARCHAR(50),cuisine VARCHAR(50),price DECIMAL(5,2));
|
SELECT o.location_id, SUM(m.price * o.quantity) as total_revenue FROM orders o JOIN menu m ON o.item_id = m.item_id WHERE o.date >= CURDATE() - INTERVAL 1 MONTH GROUP BY o.location_id;
|
What is the total online travel agency revenue for each country?
|
CREATE TABLE ota_revenue (country VARCHAR(255),revenue DECIMAL(10,2));
|
SELECT country, SUM(revenue) FROM ota_revenue GROUP BY country;
|
List all biotech startups founded in the last 3 years, along with their funding amounts.
|
CREATE TABLE startups(id INT,name VARCHAR(50),sector VARCHAR(50),total_funding FLOAT,founded_date DATE);INSERT INTO startups (id,name,sector,total_funding,founded_date) VALUES (1,'StartupA','Genetics',20000000,'2018-05-15');INSERT INTO startups (id,name,sector,total_funding,founded_date) VALUES (2,'StartupB','Bioprocess',15000000,'2019-12-20');
|
SELECT name, total_funding FROM startups WHERE founded_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR);
|
List the safety issues for products launched in 2021.
|
CREATE TABLE products(id INT,name TEXT,launch_year INT,safety_issue TEXT); INSERT INTO products(id,name,launch_year,safety_issue) VALUES (1,'Cleanser X',2021,'microplastic use'),(2,'Lotion Y',2020,'paraben content'),(3,'Shampoo Z',2021,'none'),(4,'Conditioner W',2019,'formaldehyde content');
|
SELECT name, safety_issue FROM products WHERE launch_year = 2021 AND safety_issue IS NOT NULL;
|
Create a table for storing veteran hiring statistics
|
CREATE TABLE veteran_hiring_stats (state VARCHAR(2),year INT,total_veterans INT,hired_veterans INT);
|
INSERT INTO veteran_hiring_stats (state, year, total_veterans, hired_veterans) VALUES ('NY', 2020, 5000, 3500);
|
What is the average watch time per user for each content category, segmented by gender?
|
CREATE TABLE user_content_views (view_id INT,user_id INT,content_id INT,view_date DATE,user_gender VARCHAR(10),watch_time INT); CREATE TABLE content (content_id INT,content_category VARCHAR(20));
|
SELECT content.content_category, user_gender, AVG(watch_time) as avg_watch_time FROM user_content_views JOIN content ON user_content_views.content_id = content.content_id GROUP BY content.content_category, user_gender;
|
How many energy storage projects were initiated in Europe in Q3 2022?
|
CREATE TABLE energy_storage_projects (quarter VARCHAR(6),region VARCHAR(255),num_projects INT); INSERT INTO energy_storage_projects (quarter,region,num_projects) VALUES ('Q3 2022','Europe',20),('Q3 2022','Asia',18),('Q4 2022','Europe',22);
|
SELECT num_projects FROM energy_storage_projects WHERE quarter = 'Q3 2022' AND region = 'Europe'
|
Create a new table for storing disaster donation records
|
CREATE TABLE donations (id SERIAL PRIMARY KEY,donor_name VARCHAR(255),donation_amount INTEGER,donation_date DATE);
|
CREATE TABLE donations (id SERIAL PRIMARY KEY, donor_name VARCHAR(255), donation_amount INTEGER, donation_date DATE);
|
Delete all healthcare facilities in 'City X' that do not offer mental health services.
|
CREATE TABLE HealthcareFacilities (Name VARCHAR(255),City VARCHAR(255),Specialized BOOLEAN); INSERT INTO HealthcareFacilities (Name,City,Specialized) VALUES ('Facility A','City X',TRUE),('Facility B','City X',FALSE),('Facility C','City Y',TRUE);
|
DELETE FROM HealthcareFacilities WHERE City = 'City X' AND Specialized = FALSE;
|
What is the average dissolved oxygen level per week for each aquafarm in the Atlantic region?
|
CREATE TABLE aquafarms (id INT,name TEXT,location TEXT); INSERT INTO aquafarms (id,name,location) VALUES (1,'Farm A','Atlantic'),(2,'Farm B','Pacific'); CREATE TABLE oxygen_data (aquafarm_id INT,timestamp TIMESTAMP,oxygen_level FLOAT);
|
SELECT aquafarm_id, AVG(oxygen_level) AS avg_oxygen_level, EXTRACT(WEEK FROM timestamp) AS week FROM oxygen_data JOIN aquafarms ON oxygen_data.aquafarm_id = aquafarms.id WHERE location LIKE 'Atlantic%' GROUP BY aquafarm_id, week;
|
How many workers are employed in the textile industry in each country, and what is their average salary?
|
CREATE TABLE textile_industry (id INT PRIMARY KEY,country VARCHAR(50),workers INT,avg_salary FLOAT); INSERT INTO textile_industry (id,country,workers,avg_salary) VALUES (1,'China',3000000,5000.00),(2,'India',2500000,4000.00),(3,'United States',1000000,6000.00),(4,'Indonesia',800000,3500.00),(5,'Bangladesh',600000,2500.00);
|
SELECT country, workers, AVG(avg_salary) FROM textile_industry GROUP BY country;
|
What is the maximum construction cost for a building in the West?
|
CREATE TABLE Building (building_id INT,region VARCHAR(20),construction_cost DECIMAL(10,2)); INSERT INTO Building (building_id,region,construction_cost) VALUES (1,'West',3000000.00),(2,'Midwest',2500000.00);
|
SELECT MAX(construction_cost) FROM Building WHERE region = 'West';
|
Add a new organic ingredient 'Jojoba Oil' to the product with ID 2 in the ProductIngredients table.
|
CREATE TABLE ProductIngredients (productID INT,ingredient VARCHAR(50),organic BOOLEAN); INSERT INTO ProductIngredients (productID,ingredient,organic) VALUES (1,'Aloe Vera',true),(2,'Chamomile',true),(3,'Retinol',false),(4,'Hyaluronic Acid',false);
|
INSERT INTO ProductIngredients (productID, ingredient, organic) VALUES (2, 'Jojoba Oil', true);
|
How many patients have been treated with exposure therapy in the past 6 months?
|
CREATE TABLE patients (patient_id INT,age INT,gender VARCHAR(20),condition VARCHAR(50),registration_date DATE); INSERT INTO patients (patient_id,age,gender,condition,registration_date) VALUES (1,35,'Female','Depression','2021-05-18'); CREATE TABLE treatments (treatment_id INT,patient_id INT,therapy_type VARCHAR(50),duration INT,treatment_date DATE); INSERT INTO treatments (treatment_id,patient_id,therapy_type,duration,treatment_date) VALUES (1,1,'CBT',12,'2021-08-23');
|
SELECT COUNT(DISTINCT patients.patient_id) FROM patients JOIN treatments ON patients.patient_id = treatments.patient_id WHERE treatments.therapy_type = 'Exposure Therapy' AND treatments.treatment_date >= '2021-07-01';
|
What is the total balance of Shariah-compliant savings accounts for customers in California, grouped by city?
|
CREATE TABLE savings_accounts (id INT,customer_id INT,account_type VARCHAR(20),balance DECIMAL(10,2),state VARCHAR(2)); INSERT INTO savings_accounts (id,customer_id,account_type,balance,state) VALUES (1,101,'Shariah',5000,'California'); CREATE TABLE customers (id INT,first_name VARCHAR(20),last_name VARCHAR(20),city VARCHAR(20)); INSERT INTO customers (id,first_name,last_name,city) VALUES (101,'Ahmad','Ali','San Francisco');
|
SELECT savings_accounts.state, customers.city, SUM(savings_accounts.balance) FROM savings_accounts INNER JOIN customers ON savings_accounts.customer_id = customers.id WHERE savings_accounts.account_type = 'Shariah' AND savings_accounts.state = 'California' GROUP BY customers.city;
|
Delete all records from the 'MarineSpecies' table where the 'SpeciesName' is 'Coral'
|
CREATE TABLE MarineSpecies (SpeciesID INT,SpeciesName VARCHAR(255),Habitat VARCHAR(255),ConservationStatus VARCHAR(255));
|
DELETE FROM MarineSpecies WHERE SpeciesName = 'Coral';
|
Determine the minimum and maximum labor hours per project by region.
|
CREATE TABLE project (project_id INT,region VARCHAR(20),labor_hours INT); INSERT INTO project VALUES (1,'Northeast',500); INSERT INTO project VALUES (2,'Southwest',700);
|
SELECT region, MIN(labor_hours) as min_labor_hours, MAX(labor_hours) as max_labor_hours FROM project GROUP BY region;
|
What is the total value of sustainable properties in each neighborhood, ordered from highest to lowest?
|
CREATE TABLE Neighborhoods (NeighborhoodID INT,NeighborhoodName VARCHAR(255)); CREATE TABLE Properties (PropertyID INT,NeighborhoodID INT,Size INT,Sustainable BOOLEAN,PropertyPrice INT);
|
SELECT NeighborhoodName, SUM(CASE WHEN Sustainable = 1 THEN PropertyPrice * Size ELSE 0 END) AS TotalValue FROM Properties JOIN Neighborhoods ON Properties.NeighborhoodID = Neighborhoods.NeighborhoodID GROUP BY NeighborhoodName ORDER BY TotalValue DESC;
|
Determine the market share of each sales region for a given drug.
|
CREATE TABLE sales_data (drug_name TEXT,region TEXT,sales INTEGER);
|
SELECT region, SUM(sales) OVER (PARTITION BY region) / SUM(sales) OVER () AS market_share FROM sales_data WHERE drug_name = 'DrugX' GROUP BY 1 ORDER BY 1;
|
Which players are part of the 'Apex Predators' team?
|
CREATE TABLE PlayerTeam (PlayerID INT,TeamID INT); INSERT INTO PlayerTeam (PlayerID,TeamID) VALUES (101,1),(102,1),(103,2),(104,3);
|
SELECT PlayerID FROM PlayerTeam WHERE TeamID = 1;
|
Delete all records with a conservation status of 'Least Concern' from the 'conservation_status' table.
|
CREATE TABLE conservation_status (id INT,species_name VARCHAR(50),status VARCHAR(20)); INSERT INTO conservation_status (id,species_name,status) VALUES (1,'Green Sea Turtle','Least Concern'),(2,'Clownfish','Least Concern'),(3,'Bottlenose Dolphin','Data Deficient'),(4,'Blue Whale','Critically Endangered');
|
DELETE FROM conservation_status WHERE status = 'Least Concern';
|
What is the total revenue generated by art auctions in the American region?
|
CREATE TABLE Auctions (AuctionID INT,AuctionName TEXT,Year INT,Region TEXT,Revenue DECIMAL(10,2)); INSERT INTO Auctions (AuctionID,AuctionName,Year,Region,Revenue) VALUES (1,'Christie''s New York',2017,'America',5000000); INSERT INTO Auctions (AuctionID,AuctionName,Year,Region,Revenue) VALUES (2,'Sotheby''s London',2018,'Europe',6000000);
|
SELECT Region, SUM(Revenue) as TotalRevenue FROM Auctions WHERE Region = 'America' GROUP BY Region;
|
Identify the artist with the most significant increase in the number of sculptures in their portfolio from 2020 to 2021.
|
CREATE TABLE ArtistSculptures (ArtistID INT,Year INT,TotalSculptures INT); INSERT INTO ArtistSculptures (ArtistID,Year,TotalSculptures) VALUES (1,2020,450),(1,2021,550),(2,2020,220),(2,2021,180),(3,2020,290),(3,2021,310);
|
SELECT ArtistID, (LAG(TotalSculptures, 1) OVER (PARTITION BY ArtistID ORDER BY Year) - TotalSculptures) AS Increase FROM ArtistSculptures WHERE Year = 2021 ORDER BY Increase DESC LIMIT 1;
|
What is the average price of organic products sold by retailers located in California?
|
CREATE TABLE retailers (retailer_id INT,retailer_name VARCHAR(255),state VARCHAR(255)); INSERT INTO retailers (retailer_id,retailer_name,state) VALUES (1,'Eco-Friendly Goods','California'); INSERT INTO retailers (retailer_id,retailer_name,state) VALUES (2,'Green Retailer','California'); CREATE TABLE products (product_id INT,product_name VARCHAR(255),price DECIMAL(5,2),organic BOOLEAN); INSERT INTO products (product_id,product_name,price,organic) VALUES (1,'Bio-Degradable Bags',9.99,true); INSERT INTO products (product_id,product_name,price,organic) VALUES (2,'Natural Soap',5.49,true);
|
SELECT AVG(price) FROM products JOIN retailers ON retailers.retailer_id = products.retailer_id WHERE organic = true AND state = 'California';
|
Delete players with a score below the average score in the 'Simulation' game category.
|
CREATE TABLE SimulationScores (PlayerID int,PlayerName varchar(50),Game varchar(50),Score int); INSERT INTO SimulationScores (PlayerID,PlayerName,Game,Score) VALUES (1,'Player1','Game4',1000),(2,'Player2','Game4',1200),(3,'Player3','Game4',800),(4,'Player4','Game4',1400);
|
DELETE FROM SimulationScores WHERE Game = 'Game4' AND Score < (SELECT AVG(Score) FROM SimulationScores WHERE Game = 'Game4');
|
Find the average investment amount in biotech startups for the year 2020.
|
CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.investments (id INT,startup_id INT,amount DECIMAL(10,2),investment_year INT); INSERT INTO biotech.investments (id,startup_id,amount,investment_year) VALUES (1,1,500000,2020),(2,2,300000,2019),(3,1,750000,2020);
|
SELECT AVG(amount) FROM biotech.investments WHERE investment_year = 2020 AND startup_id IN (SELECT id FROM biotech.startups);
|
What is the total duration of workouts for members aged 30-40, grouped by gender?
|
CREATE TABLE Workout (WorkoutID INT PRIMARY KEY,MemberID INT,Duration INT,Date DATE); CREATE TABLE Member (MemberID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),MembershipStart DATE);
|
SELECT Member.Gender, SUM(Workout.Duration) FROM Workout INNER JOIN Member ON Workout.MemberID = Member.MemberID WHERE Member.Age BETWEEN 30 AND 40 GROUP BY Member.Gender;
|
What is the average capacity of hydroelectric dams in Brazil?
|
CREATE TABLE hydro_dams (id INT PRIMARY KEY,country VARCHAR(50),name VARCHAR(50),capacity FLOAT); INSERT INTO hydro_dams (id,country,name,capacity) VALUES (1,'Brazil','Hydro Dam A',300.5),(2,'Brazil','Hydro Dam B',320.2);
|
SELECT AVG(capacity) FROM hydro_dams WHERE country = 'Brazil';
|
List all digital assets with their respective smart contract names and the number of transactions, sorted by the total transaction count in descending order. If there is no associated smart contract, display 'N/A'.
|
CREATE TABLE smart_contracts (contract_id INT,contract_name VARCHAR(255),total_transactions INT); CREATE TABLE assets_contracts (asset_id INT,contract_id INT); CREATE TABLE assets (asset_id INT,asset_name VARCHAR(255));
|
SELECT a.asset_name, sc.contract_name, SUM(sc.total_transactions) as total_transactions FROM assets a LEFT JOIN assets_contracts ac ON a.asset_id = ac.asset_id LEFT JOIN smart_contracts sc ON ac.contract_id = sc.contract_id GROUP BY a.asset_id, sc.contract_name ORDER BY total_transactions DESC;
|
What is the maximum price of any product that is transparent about its labor practices?
|
CREATE TABLE products (product_id INT,product_name TEXT,is_labor_practices_transparent BOOLEAN,price DECIMAL); INSERT INTO products (product_id,product_name,is_labor_practices_transparent,price) VALUES (1,'Eco-Friendly Notebook',TRUE,5.99),(2,'Sustainable Sneakers',FALSE,129.99),(3,'Handmade Jewelry',TRUE,89.99);
|
SELECT MAX(price) FROM products WHERE is_labor_practices_transparent = TRUE;
|
Find the total number of smart city projects in the smart_cities schema that have project_status 'completed'.
|
CREATE SCHEMA IF NOT EXISTS smart_cities; CREATE TABLE IF NOT EXISTS smart_cities.smart_city_projects (project_id INT NOT NULL,location VARCHAR(255) NOT NULL,project_status VARCHAR(255) NOT NULL,PRIMARY KEY (project_id));
|
SELECT COUNT(*) FROM smart_cities.smart_city_projects WHERE project_status = 'completed';
|
What is the maximum number of mental health conditions treated at a single facility?
|
CREATE TABLE facilities (facility_id INT,conditions_treated INT); INSERT INTO facilities (facility_id,conditions_treated) VALUES (1,5),(2,3),(3,7),(4,2);
|
SELECT MAX(conditions_treated) FROM facilities;
|
Determine the total amount of research grants awarded to each department in the last five years, excluding grants awarded to faculty members who have not published in the last three years.
|
CREATE TABLE departments (department VARCHAR(50),total_grant_amount FLOAT); INSERT INTO departments VALUES ('Computer Science',500000),('Mathematics',400000),('Physics',600000); CREATE TABLE grants (grant_id INT,department VARCHAR(50),year INT,amount FLOAT,faculty_published BOOLEAN); INSERT INTO grants VALUES (1,'Computer Science',2018,100000,true),(2,'Physics',2017,150000,false),(3,'Mathematics',2019,120000,true),(4,'Computer Science',2020,125000,true),(5,'Physics',2016,130000,false),(6,'Mathematics',2021,110000,true);
|
SELECT d.department, SUM(g.amount) FROM departments d JOIN grants g ON d.department = g.department WHERE g.faculty_published = true AND g.year BETWEEN YEAR(CURRENT_DATE) - 5 AND YEAR(CURRENT_DATE) GROUP BY d.department;
|
What is the average annual CO2 emissions reduction for each climate adaptation project in Asia?
|
CREATE TABLE climate_adaptation (project_name VARCHAR(255),region VARCHAR(255),co2_reduction_tonnes INT,start_date DATE); INSERT INTO climate_adaptation (project_name,region,co2_reduction_tonnes,start_date) VALUES ('Flood Prevention','Asia',1000,'2018-01-01'); INSERT INTO climate_adaptation (project_name,region,co2_reduction_tonnes,start_date) VALUES ('Drought Resistance','Asia',1500,'2019-05-15');
|
SELECT region, AVG(co2_reduction_tonnes / DATEDIFF(year, start_date, CURDATE())) as avg_annual_reduction FROM climate_adaptation WHERE region = 'Asia' GROUP BY region;
|
What's the total donation amount given to the Education program in Nigeria and the Clean Water project in Somalia?
|
CREATE TABLE donations (id INT,donor_id INT,project_id INT,amount INT); CREATE TABLE donors (id INT,name TEXT,age INT); CREATE TABLE projects (id INT,name TEXT,location TEXT); INSERT INTO donations VALUES (1,1,1,500),(2,2,2,300),(3,3,1,700); INSERT INTO donors VALUES (1,'Adebola Johnson',35),(2,'Abdirahman Osman',40),(3,'Chiamaka Nwankwo',45); INSERT INTO projects VALUES (1,'Education','Nigeria'),(2,'Clean Water','Somalia');
|
SELECT SUM(d.amount) FROM donations d INNER JOIN projects p ON d.project_id = p.id WHERE p.name IN ('Education', 'Clean Water') AND p.location IN ('Nigeria', 'Somalia');
|
Delete all artworks by artist 'Artist 1'.
|
CREATE TABLE artists (id INT,name TEXT); INSERT INTO artists (id,name) VALUES (1,'Artist 1'),(2,'Artist 2'),(3,'Artist 3'); CREATE TABLE artworks (id INT,title TEXT,year_created INT,artist_id INT); INSERT INTO artworks (id,title,year_created,artist_id) VALUES (1,'Artwork 1',2000,1),(2,'Artwork 2',1990,1),(3,'Artwork 3',2010,2),(4,'Artwork 4',2022,3),(5,'Artwork 5',2015,1);
|
DELETE FROM artworks WHERE artist_id = 1;
|
What was the average food safety inspection score for 'Fast Food' restaurants in 'California' in 2021?
|
CREATE TABLE food_safety_inspections(restaurant_id INT,restaurant_name VARCHAR(255),category VARCHAR(255),state VARCHAR(255),score INT,date DATE); INSERT INTO food_safety_inspections(restaurant_id,restaurant_name,category,state,score,date) VALUES (1,'Burger Joint','Fast Food','California',85,'2021-01-01'); INSERT INTO food_safety_inspections(restaurant_id,restaurant_name,category,state,score,date) VALUES (2,'Pizza Place','Fast Food','California',90,'2021-01-02');
|
SELECT AVG(score) FROM food_safety_inspections WHERE category = 'Fast Food' AND state = 'California' AND date BETWEEN '2021-01-01' AND '2021-12-31';
|
Number of infectious disease cases in each region, ordered by the highest number of cases.
|
CREATE TABLE infectious_disease (region VARCHAR(10),cases INT); INSERT INTO infectious_disease (region,cases) VALUES ('North',100),('South',150),('East',200),('West',50);
|
SELECT region, cases, RANK() OVER (ORDER BY cases DESC) AS rank FROM infectious_disease;
|
How many Petite customers have purchased Eco-friendly Denim items in Paris during 2021?
|
CREATE TABLE Customers (customer_id INT,country VARCHAR(255),size VARCHAR(50),preferred_trend_id INT);CREATE TABLE Sales (sale_id INT,garment_id INT,location_id INT,sale_date DATE);CREATE TABLE Garments (garment_id INT,trend_id INT,fabric_source_id INT,size VARCHAR(50),style VARCHAR(255));CREATE TABLE FabricSources (source_id INT,fabric_type VARCHAR(255),country_of_origin VARCHAR(255),ethical_rating DECIMAL(3,2));CREATE TABLE StoreLocations (location_id INT,city VARCHAR(255),country VARCHAR(255),sales_volume INT);CREATE VIEW PetiteCustomers AS SELECT * FROM Customers WHERE size = 'Petite';CREATE VIEW EcoFriendlyDenim AS SELECT * FROM Garments WHERE fabric_source_id IN (SELECT source_id FROM FabricSources WHERE fabric_type = 'Denim' AND ethical_rating >= 7.0) AND style = 'Eco-friendly';CREATE VIEW ParisSales AS SELECT * FROM Sales WHERE location_id IN (SELECT location_id FROM StoreLocations WHERE city = 'Paris');CREATE VIEW ParisPetiteEcoDenim AS SELECT * FROM ParisSales WHERE garment_id IN (SELECT garment_id FROM EcoFriendlyDenim WHERE size = 'Petite');
|
SELECT COUNT(DISTINCT customer_id) FROM ParisPetiteEcoDenim WHERE sale_date BETWEEN '2021-01-01' AND '2021-12-31';
|
How many ethical AI projects were completed in the "responsible_ai" schema in 2021, 2022, and Q1 2023?
|
CREATE TABLE ethical_ai_projects (id INT,project_name VARCHAR(50),completion_date DATE,schema VARCHAR(50)); INSERT INTO ethical_ai_projects (id,project_name,completion_date,schema) VALUES (1,'Project A','2021-01-01','responsible_ai'),(2,'Project B','2022-01-01','responsible_ai'),(3,'Project C','2023-02-01','responsible_ai'),(4,'Project D','2023-03-15','responsible_ai');
|
SELECT COUNT(*) FROM ethical_ai_projects WHERE schema = 'responsible_ai' AND (YEAR(completion_date) BETWEEN 2021 AND 2023 OR QUARTER(completion_date) = 1 AND YEAR(completion_date) = 2023);
|
How many trains in Berlin pass through a station between 7 AM and 9 AM?
|
CREATE TABLE train_schedules (id INT,station_id INT,route_id INT,timestamp TIMESTAMP); CREATE VIEW trains_between_7_9 AS SELECT station_id FROM train_schedules WHERE TIME(timestamp) BETWEEN '07:00:00' AND '09:00:00';
|
SELECT COUNT(*) FROM trains_between_7_9;
|
Find the names and locations of all the museums that have a website.
|
CREATE TABLE museums (name VARCHAR(255),location VARCHAR(255),website VARCHAR(255));
|
SELECT name, location FROM museums WHERE website IS NOT NULL;
|
Determine the total hectares of forest land for each country
|
CREATE TABLE forests (id INT,name VARCHAR(50),hectares DECIMAL(5,2),year_planted INT,country VARCHAR(50),PRIMARY KEY (id)); INSERT INTO forests (id,name,hectares,year_planted,country) VALUES (1,'Forest A',123.45,1990,'USA'),(2,'Forest B',654.32,1985,'Canada'),(3,'Forest C',456.78,2010,'USA'),(4,'Forest D',903.45,1980,'Mexico');
|
SELECT f.country, SUM(f.hectares) FROM forests f GROUP BY f.country;
|
Display the total value of assets for each portfolio manager who manages at least one portfolio with a value greater than $10 million.
|
CREATE TABLE portfolio_managers (manager_id INT,portfolio_id INT,manager_name VARCHAR(30),portfolio_value DECIMAL(12,2)); INSERT INTO portfolio_managers (manager_id,portfolio_id,manager_name,portfolio_value) VALUES (1,1001,'Manager A',12000000.00),(2,1002,'Manager B',8000000.00),(3,1003,'Manager C',5000000.00),(1,1004,'Manager A',15000000.00);
|
SELECT manager_name, SUM(portfolio_value) FROM portfolio_managers WHERE portfolio_value > 10000000 GROUP BY manager_name;
|
What was the average amount spent per person on shelter in 2019?
|
CREATE TABLE people (id INT,name TEXT); CREATE TABLE expenses (id INT,person_id INT,category TEXT,year INT,amount FLOAT); INSERT INTO people (id,name) VALUES (1,'John Doe'); INSERT INTO people (id,name) VALUES (2,'Jane Doe'); INSERT INTO expenses (id,person_id,category,year,amount) VALUES (1,1,'Shelter',2019,1000.00); INSERT INTO expenses (id,person_id,category,year,amount) VALUES (2,1,'Shelter',2018,1500.00); INSERT INTO expenses (id,person_id,category,year,amount) VALUES (3,2,'Shelter',2019,2000.00);
|
SELECT AVG(amount) FROM expenses e JOIN people p ON e.person_id = p.id WHERE e.category = 'Shelter' AND e.year = 2019;
|
What is the average revenue per user (ARPU) for the rock genre across all streaming platforms in Q3 2021?
|
CREATE TABLE RevenueData (StreamingPlatform TEXT,Genre TEXT,Quarter TEXT(2),Year INTEGER,ARPU FLOAT); INSERT INTO RevenueData (StreamingPlatform,Genre,Quarter,Year,ARPU) VALUES ('Spotify','Rock','Q3',2021,4.5),('AppleMusic','Rock','Q3',2021,5.3),('YoutubeMusic','Rock','Q3',2021,3.9),('Pandora','Rock','Q3',2021,4.1),('Tidal','Rock','Q3',2021,5.7);
|
SELECT AVG(ARPU) as AvgARPU FROM RevenueData WHERE Genre = 'Rock' AND Quarter = 'Q3' AND Year = 2021;
|
What is the average water usage quantity for mines that use recycled water, updated to reflect a 10% decrease?
|
CREATE TABLE water_usage (id INT PRIMARY KEY,mine_id INT,water_type VARCHAR(255),usage_quantity FLOAT,FOREIGN KEY (mine_id) REFERENCES mines(id));
|
SELECT AVG(usage_quantity) FROM water_usage WHERE water_type = 'recycled';
|
Insert a new record for a production site located in India with a safety score of 88 and a last inspection date of 2022-01-10.
|
CREATE TABLE production_sites(id INT,site_name TEXT,safety_score INT,last_inspection_date DATE);
|
INSERT INTO production_sites (site_name, safety_score, last_inspection_date) VALUES ('Site C', 88, '2022-01-10');
|
What is the maximum donation amount received from a donor in each country?
|
CREATE TABLE Donors (DonorID int,DonorName varchar(50),Country varchar(50)); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE Donations (DonationID int,DonorID int,DonationAmount decimal(10,2)); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (1,2,100),(2,2,200),(3,1,50);
|
SELECT Country, MAX(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID GROUP BY Country;
|
What are the total number of songs and the average length in minutes for the jazz genre in 2020?
|
CREATE TABLE Songs (SongName TEXT,Genre TEXT,LengthMinutes INTEGER,Year INTEGER); INSERT INTO Songs (SongName,Genre,LengthMinutes,Year) VALUES ('Song1','Jazz',4,2020),('Song2','Jazz',5,2020),('Song3','Jazz',3,2020);
|
SELECT Genre, COUNT(*) as NumOfSongs, AVG(LengthMinutes) as AvgLength FROM Songs WHERE Genre = 'Jazz' AND Year = 2020;
|
How many climate finance records are there for each country in Africa?
|
CREATE TABLE climate_finance (country VARCHAR(50),year INT,amount INT); INSERT INTO climate_finance (country,year,amount) VALUES ('Nigeria',2020,5000000),('Kenya',2020,6000000),('Egypt',2020,7000000);
|
SELECT country, COUNT(*) FROM climate_finance WHERE country IN ('Nigeria', 'Kenya', 'Egypt') GROUP BY country;
|
Update the warehouse location for item XYZ
|
CREATE TABLE inventory(item VARCHAR(255),warehouse VARCHAR(255)); INSERT INTO inventory VALUES('XYZ','A01');
|
UPDATE inventory SET warehouse = 'B02' WHERE item = 'XYZ';
|
What is the total quantity of organic cotton garments sold by retailers located in Los Angeles, grouped by product category and date?
|
CREATE TABLE organic_sales (id INT PRIMARY KEY,retailer_id INT,product_id INT,quantity INT,date DATE,organic BOOLEAN); INSERT INTO organic_sales (id,retailer_id,product_id,quantity,date,organic) VALUES (1,1,1,50,'2022-01-01',true),(2,2,2,75,'2022-01-02',true);
|
SELECT o.category, o.date, SUM(o.quantity) FROM organic_sales o JOIN products p ON o.product_id = p.id JOIN retailers r ON o.retailer_id = r.id WHERE o.organic = true AND r.location = 'Los Angeles' GROUP BY o.category, o.date;
|
Which programs received the most donations?
|
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,Donations DECIMAL(10,2)); INSERT INTO Programs (ProgramID,ProgramName,Donations) VALUES (1,'Education',5000.00),(2,'Healthcare',7000.00);
|
SELECT ProgramName, SUM(Donations) AS TotalDonations FROM Programs GROUP BY ProgramName ORDER BY TotalDonations DESC;
|
What's the total amount of donations made for each cause in the last 3 years?
|
CREATE TABLE donors (id INT,name VARCHAR(255),country VARCHAR(255));CREATE TABLE donations (id INT,donor_id INT,cause_id INT,amount DECIMAL(10,2),donation_date DATE);CREATE TABLE causes (id INT,name VARCHAR(255));
|
SELECT c.name, YEAR(d.donation_date), SUM(d.amount) FROM donations d INNER JOIN causes c ON d.cause_id = c.id WHERE d.donation_date >= DATE_SUB(NOW(), INTERVAL 3 YEAR) GROUP BY YEAR(d.donation_date), c.name;
|
Show the number of cases and their respective outcomes for a given attorney
|
CREATE TABLE case_outcomes (case_id INT PRIMARY KEY,attorney_id INT,outcome VARCHAR(20));
|
SELECT attorney_id, COUNT(*) FROM case_outcomes GROUP BY attorney_id;
|
What are the top cybersecurity vulnerabilities?
|
CREATE TABLE CybersecurityVulnerabilities (Vulnerability VARCHAR(50),Severity DECIMAL(3,2)); INSERT INTO CybersecurityVulnerabilities (Vulnerability,Severity) VALUES ('SQL Injection',9.0),('Cross-Site Scripting',8.5),('Remote Code Execution',8.0),('Buffer Overflow',7.5),('Path Traversal',7.0);
|
SELECT Vulnerability, Severity, RANK() OVER (ORDER BY Severity DESC) as Rank FROM CybersecurityVulnerabilities WHERE Rank <= 3;
|
How many broadband subscribers does the company have in 'Suburban' areas?
|
CREATE TABLE subscribers (id INT,subscriber_type VARCHAR(20),location VARCHAR(20)); INSERT INTO subscribers (id,subscriber_type,location) VALUES (1,'Broadband','Suburban');
|
SELECT COUNT(*) FROM subscribers WHERE subscriber_type = 'Broadband' AND location = 'Suburban';
|
Delete all diversity and inclusion training records for employees who were hired before 2020 or have a salary less than 50000.
|
CREATE TABLE employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),hire_date DATE,salary INT); CREATE TABLE diversity_training (id INT,employee_id INT,training_name VARCHAR(50),completed_date DATE);
|
DELETE dt FROM diversity_training dt WHERE dt.employee_id IN (SELECT e.id FROM employees e WHERE e.hire_date < '2020-01-01' OR e.salary < 50000);
|
List all the forests in descending order of their total carbon sequestration in 2019 and 2020.
|
CREATE TABLE forests (id INT,forest VARCHAR(50),year INT,carbon_sequestration FLOAT); INSERT INTO forests (id,forest,year,carbon_sequestration) VALUES (1,'Forest A',2019,12.5),(2,'Forest A',2020,15.2),(3,'Forest B',2019,10.0),(4,'Forest B',2020,11.8);
|
SELECT forest, SUM(carbon_sequestration) AS total_carbon_sequestration FROM forests WHERE year IN (2019, 2020) GROUP BY forest ORDER BY total_carbon_sequestration DESC;
|
Update policy records for 'Mary Johnson' to decrease coverage amount by 10%
|
CREATE TABLE policy (policy_id INT,policy_holder VARCHAR(50),coverage_amount INT); INSERT INTO policy (policy_id,policy_holder,coverage_amount) VALUES (1,'John Doe',400000),(2,'Jane Smith',600000),(3,'Mary Johnson',350000);
|
UPDATE policy SET coverage_amount = coverage_amount * 0.9 WHERE policy_holder = 'Mary Johnson';
|
Identify the station on the Green Line with the highest fare collected in a single day
|
CREATE TABLE stations (station_id INT,station_name VARCHAR(255),line VARCHAR(255));CREATE TABLE trips (trip_id INT,station_id INT,entry_time TIMESTAMP,fare FLOAT); INSERT INTO stations (station_id,station_name,line) VALUES (1,'Ruggles','Green Line'),(2,'Boylston','Green Line'),(3,'Lechmere','Green Line'); INSERT INTO trips (trip_id,station_id,entry_time,fare) VALUES (1,1,'2022-01-01 06:00:00',2.5),(2,1,'2022-01-01 18:00:00',3.0),(3,2,'2022-01-01 12:00:00',1.5);
|
SELECT s.station_name, SUM(t.fare) as total_fare FROM trips t JOIN stations s ON t.station_id = s.station_id WHERE s.line = 'Green Line' GROUP BY s.station_name ORDER BY total_fare DESC LIMIT 1;
|
What is the number of distinct animals in 'rehabilitated_animals' table?
|
CREATE TABLE rehabilitated_animals (id INT,animal_name VARCHAR(50),rehabilitated_date DATE); INSERT INTO rehabilitated_animals VALUES (1,'Tiger','2021-01-01'),(2,'Lion','2021-02-01');
|
SELECT COUNT(DISTINCT animal_name) FROM rehabilitated_animals;
|
Find the average energy consumption of machines in the 'textiles' department.
|
CREATE TABLE departments (id INT,name VARCHAR(255),machine_id INT);CREATE TABLE machines (id INT,name VARCHAR(255),energy_consumption DECIMAL(10,2));
|
SELECT AVG(machines.energy_consumption) FROM machines INNER JOIN departments ON machines.id = departments.machine_id WHERE departments.name = 'textiles';
|
What is the average number of years since the establishment of heritage sites by continent?
|
CREATE TABLE HeritageSites (SiteID INT,SiteName VARCHAR(255),Type VARCHAR(255),Continent VARCHAR(255),YearEstablished INT); INSERT INTO HeritageSites (SiteID,SiteName,Type,Continent,YearEstablished) VALUES (1,'Machu Picchu','Historic','South America',1983),(2,'Great Barrier Reef','Natural','Australia',1981),(3,'Galapagos Islands','Natural','South America',1978),(4,'Chichen Itza','Historic','North America',1988),(5,'African Rain Forests','Natural','Africa',2007);
|
SELECT Continent, AVG(YEAR(CURRENT_DATE) - YearEstablished) as Avg_Years_Since_Estab FROM HeritageSites GROUP BY Continent;
|
Show the number of policies and total claim amount for each policy type in the month of August
|
CREATE TABLE claims (claim_id INT,policy_id INT,claim_amount DECIMAL(10,2),claim_date DATE,policy_type VARCHAR(20));
|
SELECT policy_type, COUNT(*), SUM(claim_amount) FROM claims WHERE MONTH(claim_date) = 8 GROUP BY policy_type;
|
What is the total funding received by startups founded in 2015?
|
CREATE TABLE startups (id INT,name VARCHAR(255),founding_year INT); INSERT INTO startups (id,name,founding_year) VALUES (1,'Acme Inc',2015),(2,'Bravo Corp',2017); CREATE TABLE funding (startup_id INT,amount INT); INSERT INTO funding (startup_id,amount) VALUES (1,500000),(1,1000000),(2,750000);
|
SELECT SUM(funding.amount) FROM funding INNER JOIN startups ON funding.startup_id = startups.id WHERE startups.founding_year = 2015;
|
What is the total cargo weight transported by vessels flying the flag of India to Australia in Q3 2021?
|
CREATE TABLE Cargo (CargoID INT,VesselFlag VARCHAR(50),Destination VARCHAR(50),CargoWeight INT,TransportDate DATE); INSERT INTO Cargo VALUES (1,'India','Australia',10000,'2021-07-10'),(2,'India','Australia',12000,'2021-09-25'),(3,'Norway','Europe',11000,'2021-08-18');
|
SELECT SUM(CargoWeight) FROM Cargo WHERE VesselFlag = 'India' AND Destination = 'Australia' AND TransportDate >= '2021-07-01' AND TransportDate <= '2021-09-30';
|
How many climate adaptation projects were initiated in Asia in Q1 2021?
|
CREATE TABLE climate_projects (region VARCHAR(50),quarter INT,year INT,project_count INT); INSERT INTO climate_projects VALUES ('Asia',1,2021,120);
|
SELECT SUM(project_count) FROM climate_projects WHERE region = 'Asia' AND quarter = 1 AND year = 2021;
|
What is the name and type of the most expensive military aircraft in the AIRCRAFT_INFO table?
|
CREATE TABLE AIRCRAFT_INFO (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),cost INT);
|
SELECT name, type FROM AIRCRAFT_INFO WHERE cost = (SELECT MAX(cost) FROM AIRCRAFT_INFO);
|
Display union names with no collective bargaining agreements, but active labor rights advocacy campaigns.
|
CREATE TABLE campaigns (id INT PRIMARY KEY,union_id INT,campaign_status VARCHAR(255)); CREATE TABLE cb_agreements (id INT PRIMARY KEY,union_id INT); CREATE TABLE unions (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO campaigns (id,union_id,campaign_status) VALUES (1,1,'Active'),(2,2,'Inactive'),(3,4,'Active'); INSERT INTO cb_agreements (id,union_id) VALUES (1,1),(2,3); INSERT INTO unions (id,name) VALUES (1,'Union A'),(2,'Union B'),(3,'Union C'),(4,'Union D');
|
SELECT name FROM unions u WHERE u.id IN (SELECT union_id FROM campaigns WHERE campaign_status = 'Active') AND u.id NOT IN (SELECT union_id FROM cb_agreements);
|
Which programs received donations over $500 and their respective city?
|
CREATE TABLE Programs (id INT,program_name VARCHAR(255),budget DECIMAL(10,2),start_date DATE,end_date DATE,city VARCHAR(255)); CREATE TABLE Donations (id INT,donation_amount DECIMAL(10,2),donation_date DATE,program_id INT);
|
SELECT p.program_name, p.city, SUM(d.donation_amount) as total_donations FROM Programs p INNER JOIN Donations d ON p.id = d.program_id WHERE d.donation_amount > 500 GROUP BY p.program_name, p.city;
|
What is the total number of employees working in companies with ethical manufacturing certifications?
|
CREATE TABLE companies (id INT,name TEXT,certified_ethical BOOLEAN); INSERT INTO companies (id,name,certified_ethical) VALUES (1,'Eco-Friendly Manufacturing',TRUE); INSERT INTO companies (id,name,certified_ethical) VALUES (2,'Green Innovations',FALSE); INSERT INTO companies (id,name,certified_ethical) VALUES (3,'Sustainable Solutions',TRUE); INSERT INTO companies (id,name,certified_ethical) VALUES (4,'Traditional Production',FALSE); CREATE TABLE employees (id INT,company_id INT,role TEXT); INSERT INTO employees (id,company_id,role) VALUES (1,1,'Engineer'); INSERT INTO employees (id,company_id,role) VALUES (2,1,'Manager'); INSERT INTO employees (id,company_id,role) VALUES (3,3,'Designer'); INSERT INTO employees (id,company_id,role) VALUES (4,3,'Operator');
|
SELECT COUNT(*) AS total_employees FROM employees INNER JOIN companies ON employees.company_id = companies.id WHERE companies.certified_ethical = TRUE;
|
What is the earliest departure date for each vessel?
|
CREATE TABLE Vessel (VesselID INT,VesselName VARCHAR(50)); INSERT INTO Vessel (VesselID,VesselName) VALUES (1,'MSC Fantasia'); INSERT INTO Vessel (VesselID,VesselName) VALUES (2,'CMA CGM Georg Forster'); CREATE TABLE Voyage (VoyageID INT,VesselID INT,PortID INT,DepartureDate DATE); INSERT INTO Voyage (VoyageID,VesselID,PortID,DepartureDate) VALUES (1,1,1,'2022-01-01'); INSERT INTO Voyage (VoyageID,VesselID,PortID,DepartureDate) VALUES (2,2,2,'2022-02-01');
|
SELECT v.VesselName, MIN(DepartureDate) as EarliestDepartureDate FROM Vessel v JOIN Voyage vo ON v.VesselID = vo.VesselID GROUP BY v.VesselName;
|
What is the total quantity of rare earth elements mined in India over time, with a running total?
|
CREATE TABLE mines (id INT,country VARCHAR(255),mineral VARCHAR(255),quantity INT,year INT); INSERT INTO mines (id,country,mineral,quantity,year) VALUES (1,'India','Rare Earth Elements',100,2000),(2,'India','Rare Earth Elements',120,2001),(3,'India','Rare Earth Elements',140,2002);
|
SELECT year, SUM(quantity) OVER (ORDER BY year) FROM mines WHERE country = 'India' AND mineral = 'Rare Earth Elements';
|
What was the average rare earth element production in 2020?
|
CREATE TABLE production (country VARCHAR(255),year INT,amount INT); INSERT INTO production (country,year,amount) VALUES ('China',2020,140000),('USA',2020,38000),('Australia',2020,20000),('India',2020,5000);
|
SELECT AVG(amount) AS avg_production FROM production WHERE year = 2020;
|
Show the names, types, and locations of all transportation projects in California
|
CREATE TABLE CA_Transportation (id INT,name VARCHAR(50),type VARCHAR(50),location VARCHAR(50)); INSERT INTO CA_Transportation (id,name,type,location) VALUES (1,'BART','Train','California'),(2,'CA-1','Highway','California');
|
SELECT name, type, location FROM CA_Transportation WHERE state = 'California' AND type = 'Transportation';
|
What is the total quantity of items with type 'G' or type 'H' in warehouse Q and warehouse R?
|
CREATE TABLE warehouse_q(item_id INT,item_type VARCHAR(10),quantity INT);CREATE TABLE warehouse_r(item_id INT,item_type VARCHAR(10),quantity INT);INSERT INTO warehouse_q(item_id,item_type,quantity) VALUES (1,'G',200),(2,'H',300),(3,'G',50),(4,'H',400);INSERT INTO warehouse_r(item_id,item_type,quantity) VALUES (1,'G',150),(2,'H',250),(3,'G',40),(4,'H',350);
|
SELECT quantity FROM warehouse_q WHERE item_type IN ('G', 'H') UNION ALL SELECT quantity FROM warehouse_r WHERE item_type IN ('G', 'H');
|
How many mobile and broadband subscribers are there in each region?
|
CREATE TABLE mobile_subscribers (subscriber_id INT,name VARCHAR(255),region_id INT); CREATE TABLE broadband_subscribers (subscriber_id INT,name VARCHAR(255),region_id INT); INSERT INTO mobile_subscribers (subscriber_id,name,region_id) VALUES (1,'John Doe',1),(2,'Jane Smith',2),(3,'Mike Johnson',3),(4,'Sara Jones',4); INSERT INTO broadband_subscribers (subscriber_id,name,region_id) VALUES (5,'Alice Davis',1),(6,'Bob Evans',2),(7,'Claire Wilson',3),(8,'David Brown',4);
|
SELECT r.region_name, COUNT(m.subscriber_id) as mobile_subscribers, COUNT(b.subscriber_id) as broadband_subscribers FROM regions AS r LEFT JOIN mobile_subscribers AS m ON r.region_id = m.region_id LEFT JOIN broadband_subscribers AS b ON r.region_id = b.region_id GROUP BY r.region_name;
|
What is the total number of safety incidents in the Persian Gulf in the last 6 months?
|
CREATE TABLE SafetyIncidents (Id INT,IncidentId INT,VesselName VARCHAR(50),Area VARCHAR(50),IncidentDate DATETIME);
|
SELECT COUNT(DISTINCT IncidentId) FROM SafetyIncidents WHERE Area = 'Persian Gulf' AND IncidentDate >= DATEADD(MONTH, -6, GETDATE());
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.