instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average ethical rating of Handwoven fabric sources for Plus Size garments?
CREATE TABLE FabricSources (source_id INT,fabric_type VARCHAR(255),country_of_origin VARCHAR(255),ethical_rating DECIMAL(3,2));CREATE TABLE Garments (garment_id INT,trend_id INT,fabric_source_id INT,size VARCHAR(50),style VARCHAR(255));CREATE VIEW HandwovenFabric AS SELECT * FROM FabricSources WHERE fabric_type = 'Handwoven';CREATE VIEW PlusSizeGarments AS SELECT * FROM Garments WHERE size LIKE '%Plus%';
SELECT AVG(ethical_rating) FROM HandwovenFabric HF JOIN PlusSizeGarments PSG ON HF.source_id = PSG.fabric_source_id;
Find the number of unique customers who purchased items from brands with sustainable textile sourcing.
CREATE TABLE Customers (customer_id INT,customer_name TEXT); CREATE TABLE Brands (brand_id INT,brand_name TEXT,is_sustainable_sourcing BOOLEAN); CREATE TABLE Brand_Customers (brand_id INT,customer_id INT);
SELECT COUNT(DISTINCT c.customer_id) FROM Customers c JOIN Brand_Customers bc ON c.customer_id = bc.customer_id JOIN Brands b ON bc.brand_id = b.brand_id WHERE b.is_sustainable_sourcing = TRUE;
What is the total energy efficiency improvement (in percentage) in France for 2019, grouped by sector?
CREATE TABLE france_energy_efficiency (id INT PRIMARY KEY,year INT,sector VARCHAR(30),improvement_percent FLOAT); INSERT INTO france_energy_efficiency (id,year,sector,improvement_percent) VALUES (1,2019,'Industry',2.0),(2,2019,'Residential',2.5),(3,2019,'Commercial',2.2),(4,2019,'Transportation',1.8);
SELECT year, sector, SUM(improvement_percent) as total_improvement_percent FROM france_energy_efficiency WHERE year = 2019 GROUP BY year, sector;
Which states had the most volunteer signups in 2021?
CREATE TABLE volunteer_signups (id INT,state VARCHAR(50),signup_date DATE); INSERT INTO volunteer_signups (id,state,signup_date) VALUES (1,'NY','2021-03-01'); INSERT INTO volunteer_signups (id,state,signup_date) VALUES (2,'CA','2021-02-15');
SELECT state, COUNT(*) as num_signups FROM volunteer_signups WHERE signup_date >= '2021-01-01' AND signup_date < '2022-01-01' GROUP BY state ORDER BY num_signups DESC LIMIT 5;
Add records of new galleries into the 'Galleries' table.
CREATE TABLE Galleries (gallery_id INT,gallery_name VARCHAR(255)); INSERT INTO Galleries (gallery_id,gallery_name) VALUES (1,'Guggenheim Museum'),(2,'Louvre Museum');
INSERT INTO Galleries (gallery_id, gallery_name) VALUES (3, 'Museum of Modern Art, Paris'), (4, 'Museum of Contemporary Art, Tokyo');
List the names of restaurants in the 'food_trucks' schema that do not have a sustainable sourcing certification.
CREATE TABLE food_trucks.restaurants (restaurant_id INT,name TEXT,sustainable_certification BOOLEAN); INSERT INTO food_trucks.restaurants (restaurant_id,name,sustainable_certification) VALUES (1,'Tasty Bites',false),(2,'Lunch Rush',true);
SELECT name FROM food_trucks.restaurants WHERE sustainable_certification = false;
What is the number of explainable AI research papers published per year, segmented by region?
CREATE TABLE explainable_ai (id INT,paper_name VARCHAR(50),publication_year INT,region VARCHAR(50)); INSERT INTO explainable_ai (id,paper_name,publication_year,region) VALUES (1,'Interpretable Machine Learning Methods',2020,'North America'),(2,'Visualizing Decision Trees for Explainability',2019,'Europe'),(3,'Explainable AI for Healthcare Applications',2021,'Asia');
SELECT publication_year, region, COUNT(*) FROM explainable_ai GROUP BY publication_year, region;
What is the total billing amount for cases handled by attorneys in the 'New York' region who specialize in 'Personal Injury'?
CREATE TABLE attorneys (id INT,name TEXT,region TEXT,specialty TEXT); INSERT INTO attorneys (id,name,region,specialty) VALUES (1,'Jane Smith','New York','Personal Injury'),(2,'John Doe','Boston','Criminal Law'),(3,'Sarah Lee','New York','Bankruptcy'); CREATE TABLE cases (id INT,attorney_id INT,billing_amount INT); INSERT INTO cases (id,attorney_id,billing_amount) VALUES (1,1,1000),(2,1,2000),(3,2,3000),(4,3,4000),(5,3,5000);
SELECT SUM(billing_amount) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE attorneys.region = 'New York' AND attorneys.specialty = 'Personal Injury';
What is the total funding received by startups founded by women in the US?
CREATE TABLE startups(id INT,name TEXT,founder TEXT,total_funding FLOAT,country TEXT); INSERT INTO startups(id,name,founder,total_funding,country) VALUES (1,'Acme Inc','John Doe',20000000.00,'US'),(2,'Beta Corp','Jane Smith',30000000.00,'UK');
SELECT SUM(total_funding) FROM startups WHERE founder = 'Jane Smith' AND country = 'US';
What is the total number of marine life species observed in the Atlantic Ocean that are not sharks?
CREATE TABLE Oceans (id INT,name VARCHAR(20)); INSERT INTO Oceans (id,name) VALUES (1,'Pacific'),(2,'Atlantic'); CREATE TABLE SpeciesObservations (id INT,ocean_id INT,species VARCHAR(50),count INT); INSERT INTO SpeciesObservations (id,ocean_id,species,count) VALUES (1,1,'Shark',500),(2,1,'Whale',300),(3,2,'Shark',700),(4,2,'Dolphin',600);
SELECT SUM(SpeciesObservations.count) FROM SpeciesObservations JOIN Oceans ON SpeciesObservations.ocean_id = Oceans.id WHERE Oceans.name = 'Atlantic' AND SpeciesObservations.species != 'Shark';
What is the average temperature in 'Tokyo' for the month of 'August' in the 'weather' table?
CREATE TABLE weather (location VARCHAR(255),temperature INT,date DATE);
SELECT AVG(temperature) FROM weather WHERE location = 'Tokyo' AND EXTRACT(MONTH FROM date) = 8;
What was the total amount donated by new donors in Q1 2022, compared to Q1 2021?
CREATE TABLE Donations (DonationID INT,DonorID INT,Amount FLOAT,DonationDate DATE); INSERT INTO Donations (DonationID,DonorID,Amount,DonationDate) VALUES (1,1,500.00,'2021-01-01'),(2,1,250.00,'2021-02-14'),(3,2,750.00,'2022-01-05'),(4,3,1000.00,'2022-02-20');
SELECT YEAR(DonationDate) as Year, SUM(Amount) as TotalDonated FROM Donations WHERE DonationDate BETWEEN '2021-01-01' AND '2021-03-31' AND DonorID NOT IN (SELECT DonorID FROM Donations WHERE DonationDate BETWEEN '2020-01-01' AND '2020-03-31') GROUP BY Year;
What is the total revenue generated by brands that have a sustainable supply chain, in the year 2020?
CREATE TABLE BrandRevenue (brand VARCHAR(255),revenue DECIMAL(10,2),year INT,sustainable_supply_chain BOOLEAN);
SELECT SUM(revenue) FROM BrandRevenue WHERE sustainable_supply_chain = TRUE AND year = 2020;
Insert new mineral extraction data
CREATE TABLE extraction (id INT PRIMARY KEY,site_id INT,mineral VARCHAR(50),quantity INT,year INT);
INSERT INTO extraction (site_id, mineral, quantity, year) VALUES (1, 'Iron', 500, 2021);
What are the articles and videos with the word 'climate' in the title in the 'media_library'?
CREATE TABLE media_library (id INT,type VARCHAR(10),title VARCHAR(50),length FLOAT,source VARCHAR(50)); INSERT INTO media_library (id,type,title,length,source) VALUES (1,'article','Sample Article on Climate Change',5.5,'BBC'); INSERT INTO media_library (id,type,title,length,source) VALUES (2,'video','Sample Video on Climate',12.3,'CNN');
SELECT * FROM media_library WHERE (type = 'article' OR type = 'video') AND title LIKE '%climate%';
How many virtual tours are available for each cultural heritage site in Italy?
CREATE TABLE cultural_sites (site_id INT,name TEXT,country TEXT,num_virtual_tours INT); INSERT INTO cultural_sites (site_id,name,country,num_virtual_tours) VALUES (1,'Colosseum','Italy',3),(2,'Canal Grande','Italy',2),(3,'Leaning Tower','Italy',4);
SELECT name, num_virtual_tours FROM cultural_sites WHERE country = 'Italy';
What is the daily revenue for each menu category?
CREATE TABLE daily_sales (sale_date DATE,menu_category VARCHAR(255),revenue INT);
SELECT sale_date, menu_category, SUM(revenue) as daily_revenue FROM daily_sales GROUP BY sale_date, menu_category;
What is the total sales of the drugs that were approved in 2020?
CREATE TABLE drug_sales (drug_name VARCHAR(255),sales INT); INSERT INTO drug_sales (drug_name,sales) VALUES ('DrugA',5000000),('DrugB',7000000),('DrugC',8000000); CREATE TABLE drug_approval (drug_name VARCHAR(255),approval_year INT); INSERT INTO drug_approval (drug_name,approval_year) VALUES ('DrugA',2019),('DrugB',2020),('DrugC',2018);
SELECT ds.sales FROM drug_sales ds JOIN drug_approval da ON ds.drug_name = da.drug_name WHERE da.approval_year = 2020;
Display the number of unique users who have created playlists.
CREATE TABLE playlist_users (playlist_id INT,user_id INT); INSERT INTO playlist_users (playlist_id,user_id) VALUES (1,1),(2,2),(3,1),(4,3),(5,4);
SELECT COUNT(DISTINCT user_id) AS num_users FROM playlist_users;
Calculate attendance by age group for the 'Women in Art' event.
CREATE TABLE attendance (id INT,age INT,event VARCHAR(50),visitors INT); INSERT INTO attendance (id,age,event,visitors) VALUES (1,18,'Art of the Americas',500),(2,25,'Art of the Americas',700),(3,35,'Art of the Americas',800),(4,19,'Women in Art',400),(5,27,'Women in Art',600);
SELECT event, AVG(age) as avg_age, COUNT(*) as total FROM attendance WHERE event = 'Women in Art' GROUP BY event;
List the top 3 continents with the highest average funding amount for female-led startups in the past 3 years.
CREATE TABLE FemaleStartups(id INT,name TEXT,continent TEXT,founding_year INT,funding_amount INT); INSERT INTO FemaleStartups VALUES (1,'FemTech','North America',2018,8000000),(2,'GreenCity','North America',2019,9000000),(3,'AI-Health','Europe',2020,7000000),(4,'SolarEnergy','Australia',2017,6000000),(5,'DataAnalytics','Europe',2016,5000000),(6,'SmartGrid','North America',2021,10000000),(7,'CloudServices','Asia',2018,4000000),(8,'RenewableEnergy','South America',2019,11000000),(9,'WasteManagement','Africa',2020,3000000);
SELECT continent, AVG(funding_amount) AS avg_funding FROM FemaleStartups WHERE founding_year >= YEAR(CURRENT_DATE) - 3 GROUP BY continent ORDER BY avg_funding DESC LIMIT 3;
What is the average temperature (in Kelvin) per spacecraft, ranked in descending order?
CREATE TABLE spacecraft_temperatures (spacecraft_name TEXT,temperature FLOAT,mission_date DATE);
SELECT spacecraft_name, AVG(temperature) as avg_temperature, RANK() OVER (ORDER BY AVG(temperature) DESC) as temp_rank FROM spacecraft_temperatures GROUP BY spacecraft_name ORDER BY temp_rank;
Show startups with no funding records.
CREATE TABLE funding_records (funding_id INT,company_id INT,funding_amount DECIMAL(10,2)); INSERT INTO funding_records (funding_id,company_id,funding_amount) VALUES (1,1,5000000.00),(2,2,7000000.00),(3,3,1000000.00);
SELECT company_id FROM company_founding WHERE company_id NOT IN (SELECT company_id FROM funding_records);
What is the percentage of gluten-free items in each menu category?
CREATE TABLE menu_categories (menu_category VARCHAR(50),num_gluten_free INT); INSERT INTO menu_categories (menu_category,num_gluten_free) VALUES ('Appetizers',1),('Entrees',2),('Desserts',1);
SELECT menu_category, (num_gluten_free::DECIMAL / (SELECT SUM(num_gluten_free) FROM menu_categories)) * 100 FROM menu_categories;
What is the total amount of research grants awarded to faculty members in the Computer Science department?
CREATE TABLE department (id INT,name TEXT);CREATE TABLE faculty (id INT,department_id INT);CREATE TABLE research_grant (id INT,faculty_id INT,amount INT);
SELECT SUM(rg.amount) FROM research_grant rg JOIN faculty f ON rg.faculty_id = f.id JOIN department d ON f.department_id = d.id WHERE d.name = 'Computer Science';
What is the average property size for co-ownership properties in Paris?
CREATE TABLE co_ownership (property_id INT,city VARCHAR(20),size INT); INSERT INTO co_ownership (property_id,city,size) VALUES (1,'Vancouver',1200),(2,'Paris',1000),(3,'Toronto',1800);
SELECT AVG(size) FROM co_ownership WHERE city = 'Paris' AND property_id IN (SELECT DISTINCT property_id FROM co_ownership WHERE co_ownership.city = 'Paris' AND co_ownership.property_id IS NOT NULL);
Which countries have intelligence operations in 'Asia' and 'Africa'?
CREATE TABLE IntelligenceOperations (ID INT,Country VARCHAR(50),Region VARCHAR(10)); INSERT INTO IntelligenceOperations (ID,Country,Region) VALUES (1,'USA','Asia'),(2,'UK','Africa'),(3,'France','Asia'),(4,'Germany','Africa');
SELECT Country FROM IntelligenceOperations WHERE Region IN ('Asia', 'Africa') GROUP BY Country HAVING COUNT(DISTINCT Region) = 2;
List all military equipment sales by all defense contractors to the Brazilian government in the last 3 years, ordered by sale_date in descending order.
CREATE TABLE military_sales (id INT,company VARCHAR(255),country VARCHAR(255),sale_value DECIMAL(10,2),sale_date DATE); INSERT INTO military_sales (id,company,country,sale_value,sale_date) VALUES (1,'Lockheed Martin','Brazil',300000,'2020-01-01'); INSERT INTO military_sales (id,company,country,sale_value,sale_date) VALUES (2,'Boeing','Brazil',400000,'2019-01-01');
SELECT * FROM military_sales WHERE country = 'Brazil' AND sale_date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR) ORDER BY sale_date DESC;
Which country in Asia has the highest number of eco-friendly hotels?
CREATE TABLE hotels (hotel_id INT,region VARCHAR(50),rating VARCHAR(10),is_eco_friendly BOOLEAN); INSERT INTO hotels (hotel_id,region,rating,is_eco_friendly) VALUES (1,'Europe','Luxury',false),(2,'Asia','Standard',true),(3,'America','Eco-Friendly',true),(4,'Asia','Standard',true);
SELECT region, COUNT(*) as num_hotels FROM hotels WHERE is_eco_friendly = true GROUP BY region ORDER BY num_hotels DESC LIMIT 1;
What is the total volume of timber harvested from mangrove forests in Southeast Asia?
CREATE TABLE mangrove_forests (id INT,name VARCHAR(255),country VARCHAR(255),volume DECIMAL(10,2)); INSERT INTO mangrove_forests (id,name,country,volume) VALUES (1,'Mangrove Forest 1','Indonesia',2000),(2,'Mangrove Forest 2','Indonesia',3000),(3,'Mangrove Forest 3','Thailand',1000);
SELECT SUM(volume) FROM mangrove_forests WHERE country = 'Indonesia';
What is the maximum water temperature recorded in the Mediterranean Sea for the last 5 years?
CREATE TABLE mediterranean_temp (year INT,temperature FLOAT); INSERT INTO mediterranean_temp (year,temperature) VALUES (2018,25.2),(2019,25.5),(2020,26.0),(2021,26.5),(2022,27.0);
SELECT MAX(temperature) FROM mediterranean_temp WHERE year BETWEEN (SELECT EXTRACT(YEAR FROM NOW()) - 5) AND EXTRACT(YEAR FROM NOW());
How many flu shots were administered to patients under 18 in New York?
CREATE TABLE flu_shots (patient_id INT,state VARCHAR(255)); CREATE TABLE patients (patient_id INT,age INT); INSERT INTO flu_shots (patient_id,state) VALUES (1,'New York'),(2,'New York'); INSERT INTO patients (patient_id,age) VALUES (1,15),(2,25);
SELECT COUNT(*) FROM flu_shots f INNER JOIN patients p ON f.patient_id = p.patient_id WHERE p.age < 18 AND f.state = 'New York';
Delete all records from the 'weapons' table where the 'country' is 'Russia'
CREATE TABLE weapons (id INT PRIMARY KEY,weapon_name VARCHAR(50),country VARCHAR(50)); INSERT INTO weapons (id,weapon_name,country) VALUES (1,'AK-47','Russia'); INSERT INTO weapons (id,weapon_name,country) VALUES (2,'RPG-7','Russia');
DELETE FROM weapons WHERE country = 'Russia';
Find fields with crop types that have not been planted in the last 30 days.
CREATE TABLE crop_planting_history (id INT,location VARCHAR(50),crop VARCHAR(50),planting_date DATE,planting_time TIME); INSERT INTO crop_planting_history (id,location,crop,planting_date,planting_time) VALUES (1,'Field4','Cotton','2022-02-15','11:30:00');
SELECT location FROM crop_planting_history WHERE planting_date < NOW() - INTERVAL 30 DAY EXCEPT SELECT location FROM crop_planting;
How many participants from each country attended the theater events last year?
CREATE TABLE theater_events (id INT,event_id INT,participant_id INT,country VARCHAR(50)); INSERT INTO theater_events (id,event_id,participant_id,country) VALUES (1,101,201,'USA'),(2,102,202,'Canada'),(3,103,203,'Mexico'); INSERT INTO theater_events (id,event_id,participant_id,country) VALUES (4,104,301,'UK'),(5,105,302,'France'),(6,106,303,'Germany');
SELECT country, COUNT(DISTINCT participant_id) FROM theater_events WHERE event_date >= '2021-01-01' GROUP BY country;
Which suppliers provide more than 10 items?
CREATE TABLE inventory(item_id INT,supplier_id INT,quantity INT); CREATE TABLE suppliers(supplier_id INT,name TEXT,location TEXT);
SELECT suppliers.name FROM suppliers INNER JOIN (SELECT supplier_id, COUNT(*) as item_count FROM inventory GROUP BY supplier_id) as inventory_counts ON suppliers.supplier_id = inventory_counts.supplier_id WHERE item_count > 10;
What is the total number of medical supply distributions in Haiti?
CREATE TABLE medical_supplies (id INT,location VARCHAR(255),distribution_date DATE); INSERT INTO medical_supplies (id,location,distribution_date) VALUES (1,'Haiti','2022-01-01'),(2,'Syria','2022-01-02'),(3,'Haiti','2022-01-03');
SELECT COUNT(*) FROM medical_supplies WHERE location = 'Haiti';
What is the average calorie intake per meal for vegetarian customers?
CREATE TABLE meals (id INT,name VARCHAR(255),customer_id INT,calories INT); INSERT INTO meals (id,name,customer_id,calories) VALUES (1,'Vegetarian Pizza',1001,350),(2,'Quinoa Salad',1002,400),(3,'Chickpea Curry',1001,500); CREATE TABLE customers (id INT,is_vegetarian BOOLEAN); INSERT INTO customers (id,is_vegetarian) VALUES (1001,true),(1002,false);
SELECT AVG(meals.calories) FROM meals INNER JOIN customers ON meals.customer_id = customers.id WHERE customers.is_vegetarian = true;
What is the number of Shariah-compliant banks in each country?
CREATE TABLE ShariahBanks (id INT,bank_name VARCHAR(50),country VARCHAR(50)); INSERT INTO ShariahBanks (id,bank_name,country) VALUES (1,'ABC Islamic Bank','Malaysia'),(2,'XYZ Islamic Bank','Malaysia'),(3,'Islamic Bank of Saudi Arabia','Saudi Arabia'),(4,'Al Rajhi Bank','Saudi Arabia'),(5,'Bank Islam Brunei Darussalam','Brunei');
SELECT country, COUNT(*) as num_banks FROM ShariahBanks GROUP BY country;
What is the total number of volunteers and total donation amount for each organization?
CREATE TABLE organization (id INT,name VARCHAR(255)); CREATE TABLE volunteer (id INT,name VARCHAR(255),organization_id INT); CREATE TABLE donation (id INT,donor_id INT,organization_id INT,amount DECIMAL(10,2));
SELECT o.name, COUNT(v.id) as total_volunteers, SUM(d.amount) as total_donations FROM volunteer v JOIN organization o ON v.organization_id = o.id JOIN donation d ON o.id = d.organization_id GROUP BY o.id;
How many tickets were sold for the 2022 World Series game in Boston, MA?
CREATE TABLE tickets (ticket_id INT,game_name VARCHAR(50),location VARCHAR(50),tickets_sold INT); INSERT INTO tickets (ticket_id,game_name,location,tickets_sold) VALUES (1,'World Series 2022','Boston,MA',50000),(2,'World Series 2022','New York,NY',45000);
SELECT SUM(tickets_sold) FROM tickets WHERE game_name = 'World Series 2022' AND location = 'Boston, MA';
List the number of rural infrastructure projects per district that were completed in the last 3 years, sorted by completion date in descending order?
CREATE TABLE infrastructure_projects (id INT,district VARCHAR(50),project_name VARCHAR(100),start_date DATE,end_date DATE);
SELECT district, COUNT(*) FROM infrastructure_projects WHERE end_date BETWEEN DATE_SUB(NOW(), INTERVAL 3 YEAR) AND NOW() GROUP BY district ORDER BY end_date DESC;
Find the number of tourists from Canada in each destination in 2021?
CREATE TABLE tourism_stats (visitor_country VARCHAR(20),destination VARCHAR(20),year INT,tourists INT); INSERT INTO tourism_stats (visitor_country,destination,year,tourists) VALUES ('Canada','Toronto',2021,600),('Canada','Vancouver',2021,700),('Canada','Montreal',2021,800);
SELECT destination, tourists FROM tourism_stats WHERE visitor_country = 'Canada' AND year = 2021;
Determine virtual reality games that have more than 800 players and released in 2019
CREATE TABLE vr_games (game VARCHAR(20),players INT,release_year INT); INSERT INTO vr_games (game,players,release_year) VALUES ('Game1',1000,2019); INSERT INTO vr_games (game,players,release_year) VALUES ('Game2',500,2018);
SELECT game FROM vr_games WHERE players > 800 AND release_year = 2019;
How many community development initiatives were initiated in Mexico between 2018 and 2020?
CREATE TABLE community_development_initiatives (id INT,name TEXT,start_date DATE,country TEXT); INSERT INTO community_development_initiatives (id,name,start_date,country) VALUES (1,'Initiative G','2018-05-01','Mexico'); INSERT INTO community_development_initiatives (id,name,start_date,country) VALUES (2,'Initiative H','2019-07-15','Mexico');
SELECT COUNT(*) FROM community_development_initiatives WHERE country = 'Mexico' AND start_date BETWEEN '2018-01-01' AND '2020-12-31';
Show the number of research vessels in each ocean, partitioned by ocean conservation organization.
CREATE TABLE RESEARCH_VESSELS (VESSEL_NAME VARCHAR(20),ORGANIZATION VARCHAR(20),LOCATION VARCHAR(20)); INSERT INTO RESEARCH_VESSELS (VESSEL_NAME,ORGANIZATION,LOCATION) VALUES ('Victor','National Oceanic and Atmospheric Administration','Pacific Ocean'),('Atlantis','Woods Hole Oceanographic Institution','Atlantic Ocean'),('Sonne','Helmholtz Centre for Ocean Research Kiel','Indian Ocean'),('Araon','Korea Polar Research Institute','Southern Ocean'),('Healy','United States Coast Guard','Arctic Ocean');
SELECT LOCATION, ORGANIZATION, COUNT(*) FROM RESEARCH_VESSELS GROUP BY LOCATION, ORGANIZATION;
What is the distribution of audience demographics by age group for articles in the "Metropolis Herald" in the past year?
CREATE TABLE audience (id INT,age INT,gender VARCHAR(50),article_id INT); INSERT INTO audience (id,age,gender,article_id) VALUES (1,30,'male',1),(2,45,'female',2); CREATE TABLE articles (id INT,title VARCHAR(50),source VARCHAR(50),date DATE); INSERT INTO articles (id,title,source,date) VALUES (1,'Article 1','Metropolis Herald','2022-01-01'),(2,'Article 2','Metropolis Herald','2022-02-01');
SELECT age_groups.age_group, COUNT(audience.id) FROM (SELECT CASE WHEN age < 25 THEN '18-24' WHEN age < 35 THEN '25-34' WHEN age < 45 THEN '35-44' WHEN age < 55 THEN '45-54' ELSE '55+' END AS age_group FROM audience) AS age_groups INNER JOIN audience ON age_groups.age = audience.age INNER JOIN articles ON audience.article_id = articles.id WHERE articles.source = 'Metropolis Herald' AND articles.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY age_groups.age_group;
What is the total number of tourists who visited Canada in 2021 and 2022?
CREATE TABLE visitor_stats (country VARCHAR(20),visit_year INT); INSERT INTO visitor_stats (country,visit_year) VALUES ('Canada',2021),('Canada',2021),('Canada',2022),('Canada',2022),('Canada',2022);
SELECT SUM(visits) FROM (SELECT COUNT(*) AS visits FROM visitor_stats WHERE country = 'Canada' AND visit_year = 2021 UNION ALL SELECT COUNT(*) FROM visitor_stats WHERE country = 'Canada' AND visit_year = 2022) AS subquery;
List all peacekeeping operations and their respective operation leads in 2021.
CREATE TABLE Peacekeeping_Operations (Operation_ID INT PRIMARY KEY,Year INT,Leader VARCHAR(100));
SELECT * FROM Peacekeeping_Operations WHERE Year = 2021;
How many marine species are there in the Arctic?
CREATE TABLE marine_species (id INT,species_name VARCHAR(255),location VARCHAR(255)); INSERT INTO marine_species (id,species_name,location) VALUES (1,'Narwhal','Arctic'),(2,'Beluga','Arctic');
SELECT COUNT(*) FROM marine_species WHERE marine_species.location = 'Arctic';
How many unique roles are there in the company with the name 'TechBoost'?
CREATE TABLE Company (id INT,name TEXT,industry TEXT,location TEXT); INSERT INTO Company (id,name,industry,location) VALUES (1,'EcoInnovations','GreenTech','Nigeria'),(2,'BioSolutions','Biotech','Brazil'),(3,'TechBoost','Tech','India'); CREATE TABLE Employee (id INT,company_id INT,name TEXT,role TEXT,gender TEXT,ethnicity TEXT,date_hired DATE); INSERT INTO Employee (id,company_id,name,role,gender,ethnicity,date_hired) VALUES (1,1,'Amina','Software Engineer','Female','Black','2021-01-10'),(2,1,'Bruno','Data Scientist','Male','Latino','2020-06-01'),(3,2,'Chen','Hardware Engineer','Non-binary','Asian','2019-12-20'),(4,3,'Dana','Product Manager','Female','White','2022-03-01');
SELECT COUNT(DISTINCT Employee.role) FROM Company INNER JOIN Employee ON Company.id = Employee.company_id WHERE Company.name = 'TechBoost';
What is the average donation amount and total number of donors for each program in the year 2020?
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); CREATE TABLE Donors (DonorID INT,DonorName TEXT,ProgramID INT,DonationAmount DECIMAL,DonationDate DATE); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Feeding the Hungry'); INSERT INTO Programs (ProgramID,ProgramName) VALUES (2,'Tutoring Kids'); INSERT INTO Donors (DonorID,DonorName,ProgramID,DonationAmount,DonationDate) VALUES (1,'John Doe',1,500.00,'2020-01-01'); INSERT INTO Donors (DonorID,DonorName,ProgramID,DonationAmount,DonationDate) VALUES (2,'Jane Smith',2,300.00,'2020-02-15');
SELECT Programs.ProgramName, AVG(Donors.DonationAmount) as AvgDonation, COUNT(DISTINCT Donors.DonorID) as NumDonors FROM Programs INNER JOIN Donors ON Programs.ProgramID = Donors.ProgramID WHERE YEAR(DonationDate) = 2020 GROUP BY Programs.ProgramName;
What is the maximum number of trades performed by a single customer in a day?
CREATE TABLE trades (trade_id INT,customer_id INT,trade_date DATE); INSERT INTO trades (trade_id,customer_id,trade_date) VALUES (1,1,'2022-02-01'),(2,1,'2022-02-01'),(3,2,'2022-02-02'),(4,3,'2022-02-03'),(5,3,'2022-02-03'),(6,3,'2022-02-03');
SELECT customer_id, MAX(count_per_day) FROM (SELECT customer_id, trade_date, COUNT(*) AS count_per_day FROM trades GROUP BY customer_id, trade_date) AS daily_trades GROUP BY customer_id;
What was the total revenue for the 'Vegetarian' menu category in January 2021?
CREATE TABLE restaurant_revenue(menu_category VARCHAR(20),revenue DECIMAL(10,2),order_date DATE); INSERT INTO restaurant_revenue(menu_category,revenue,order_date) VALUES ('Vegetarian',2000,'2021-01-01'),('Vegetarian',2200,'2021-01-03'),('Vegetarian',1800,'2021-01-12');
SELECT SUM(revenue) FROM restaurant_revenue WHERE menu_category = 'Vegetarian' AND order_date >= '2021-01-01' AND order_date <= '2021-01-31';
List all athletes who participated in the wellbeing program but did not have any illnesses in the last season.
CREATE TABLE AthleteWellbeing (AthleteID INT,ProgramName VARCHAR(50)); CREATE TABLE AthleteIllnesses (AthleteID INT,IllnessDate DATE);
SELECT AthleteID FROM AthleteWellbeing WHERE AthleteID NOT IN (SELECT AthleteID FROM AthleteIllnesses WHERE IllnessDate >= DATEADD(YEAR, -1, GETDATE()));
What is the minimum time between subway train arrivals in Toronto during off-peak hours?
CREATE TABLE subway_stations (station_id INT,station_name VARCHAR(50),city VARCHAR(50),time_between_arrivals TIME,rush_hour BOOLEAN); INSERT INTO subway_stations (station_id,station_name,city,time_between_arrivals,rush_hour) VALUES (1,'Union Station','Toronto','5:00',false),(2,'Yonge-Bloor Station','Toronto','4:00',false),(3,'Finch Station','Toronto','3:00',false);
SELECT MIN(TIME_TO_SEC(time_between_arrivals))/60.0 FROM subway_stations WHERE city = 'Toronto' AND rush_hour = false;
What is the average age of patients diagnosed with PTSD in the Eastern region?
CREATE TABLE ptsd_age (patient_id INT,region TEXT,age INT); INSERT INTO ptsd_age (patient_id,region,age) VALUES (12,'Eastern',33); INSERT INTO ptsd_age (patient_id,region,age) VALUES (13,'Western',41);
SELECT AVG(age) FROM ptsd_age WHERE region = 'Eastern';
What is the total number of marine species in the Indian Ocean, grouped by their feeding habits and conservation status?
CREATE TABLE marine_species (id INT,species VARCHAR(50),ocean VARCHAR(50),feeding_habits VARCHAR(50),conservation_status VARCHAR(50));
SELECT ocean, feeding_habits, conservation_status, COUNT(*) FROM marine_species WHERE ocean = 'Indian Ocean' GROUP BY ocean, feeding_habits, conservation_status;
Economic diversification progress, by industry and country, for the year 2016?
CREATE TABLE economic_diversification (id INT,industry VARCHAR(255),country VARCHAR(255),progress_percent FLOAT,year INT); INSERT INTO economic_diversification (id,industry,country,progress_percent,year) VALUES (1,'Textiles','India',22.6,2016),(2,'IT Services','India',30.9,2016),(3,'Automobiles','India',26.4,2016);
SELECT country, industry, AVG(progress_percent) as average_progress_percent FROM economic_diversification WHERE year = 2016 GROUP BY country, industry;
What is the maximum budget for a single space mission launched by any space agency between 2010 and 2020, inclusive?
CREATE TABLE space_mission_budgets(id INT,agency VARCHAR(255),mission_name VARCHAR(255),launch_date DATE,budget DECIMAL(10,2));
SELECT MAX(budget) FROM space_mission_budgets WHERE launch_date BETWEEN '2010-01-01' AND '2020-12-31';
What is the minimum area (in hectares) required for an indigenous food system to operate sustainably?
CREATE TABLE indigenous_food_systems (system_id INT,system_name TEXT,area FLOAT); INSERT INTO indigenous_food_systems (system_id,system_name,area) VALUES (1,'Acorn Farming',12.5),(2,'Maple Syrup Production',18.7),(3,'Bison Ranching',25.0);
SELECT MIN(area) FROM indigenous_food_systems WHERE system_name = 'Bison Ranching';
What are the top 5 preferred lipstick shades among consumers in the US?
CREATE TABLE Consumer_Preferences (Consumer_ID INT,Product_ID INT,Preference_Score INT); INSERT INTO Consumer_Preferences (Consumer_ID,Product_ID,Preference_Score) VALUES (1,101,9),(2,101,8),(3,102,7),(4,103,6),(5,102,5),(6,104,4),(7,105,3),(8,103,2),(9,106,1),(10,101,10);
SELECT Product_ID, SUM(Preference_Score) as Total_Preference FROM Consumer_Preferences WHERE Consumer_ID IN (SELECT Consumer_ID FROM Consumers WHERE Country = 'USA') GROUP BY Product_ID ORDER BY Total_Preference DESC LIMIT 5;
Insert data into the 'aircraft_manufacturing' table
CREATE TABLE aircraft_manufacturing (id INT PRIMARY KEY,manufacturer VARCHAR(255),model VARCHAR(255),production_year INT,quantity INT);
INSERT INTO aircraft_manufacturing (id, manufacturer, model, production_year, quantity) VALUES (1, 'Boeing', '737 MAX', 2017, 1000);
What is the total budget allocated for policy advocacy efforts in the last 5 years?
CREATE TABLE Advocacy_Budget (budget_year INT,amount DECIMAL(5,2));
SELECT SUM(amount) FROM Advocacy_Budget WHERE budget_year BETWEEN YEAR(CURRENT_DATE)-5 AND YEAR(CURRENT_DATE);
Identify the unique game genres for games with over 20000 players
CREATE TABLE GameDesignData (Game VARCHAR(20),Genre VARCHAR(20),Players INT); INSERT INTO GameDesignData (Game,Genre,Players) VALUES ('Fortnite','Battle Royale',50000),('Call of Duty','FPS',30000),('Minecraft','Sandbox',12000),('Among Us','Social Deduction',70000),('Valorant','FPS',35000),('Rainbow Six Siege','FPS',22000);
SELECT DISTINCT Genre FROM GameDesignData WHERE Players > 20000
What are the top 5 destinations for sustainable tourism in 2021?
CREATE TABLE SustainableTourism (Destination VARCHAR(255),Year INT,SustainabilityScore INT);
SELECT Destination, SustainabilityScore, ROW_NUMBER() OVER (ORDER BY SustainabilityScore DESC) AS Rank FROM SustainableTourism WHERE Year = 2021 AND SustainabilityScore > 0 GROUP BY Destination HAVING Rank <= 5;
How many volunteers signed up in Q1 2022 for the education program?
CREATE TABLE volunteers (id INT,name TEXT,signup_date DATE,program TEXT); INSERT INTO volunteers (id,name,signup_date,program) VALUES (1,'Bob Brown','2022-01-15','Education'),(2,'Charlie Davis','2022-03-30','Arts'),(3,'Eva Thompson','2021-12-31','Education');
SELECT COUNT(*) FROM volunteers WHERE program = 'Education' AND signup_date >= '2022-01-01' AND signup_date < '2022-04-01';
List all artworks and their respective mediums from the 'impressionist' artist?
CREATE TABLE artists (id INT,name TEXT); INSERT INTO artists (id,name) VALUES (1,'Monet'),(2,'Renoir'); CREATE TABLE artworks (id INT,artist_id INT,title TEXT,medium TEXT); INSERT INTO artworks (id,artist_id,title,medium) VALUES (1,1,'Water Lilies','Oil on canvas'),(2,1,'Bridge over a Pond','Oil on canvas'),(3,2,'Dance at Bougival','Oil on canvas'); CREATE TABLE artist_specialties (id INT,artist_id INT,specialty TEXT); INSERT INTO artist_specialties (id,artist_id,specialty) VALUES (1,1,'Impressionism');
SELECT artworks.title, artworks.medium FROM artworks INNER JOIN artist_specialties ON artworks.artist_id = artist_specialties.artist_id WHERE artist_specialties.specialty = 'Impressionism';
Identify countries with the highest number of marine species, by continent?
CREATE TABLE marine_species (id INT,name VARCHAR(255),country VARCHAR(255),continent VARCHAR(255)); INSERT INTO marine_species (id,name,country,continent) VALUES (1,'Species1','Country1','Continent1'),(2,'Species2','Country2','Continent2');
SELECT continent, country, COUNT(*) as species_count FROM marine_species GROUP BY continent, country ORDER BY continent, species_count DESC;
What is the maximum fare for a trip on the subway?
CREATE TABLE subway_fares (id INT,route VARCHAR(10),fare FLOAT); INSERT INTO subway_fares (id,route,fare) VALUES (1,'1',2.50),(2,'2',3.25),(3,'3',4.00);
SELECT MAX(fare) FROM subway_fares;
Who are the top 2 authors with the most articles in the 'audience_demographics' table, and what is the age range of their audience?
CREATE TABLE audience_demographics (article_id INT,category VARCHAR(30),word_count INT,age INT,gender VARCHAR(10),author VARCHAR(50)); INSERT INTO audience_demographics (article_id,category,word_count,age,gender,author) VALUES (1,'Politics',500,20,'Male','Sophia Lee'),(2,'Sports',700,25,'Female','Maria Rodriguez');
SELECT author, COUNT(article_id) AS total_articles, MIN(age) AS min_age, MAX(age) AS max_age FROM audience_demographics GROUP BY author ORDER BY total_articles DESC LIMIT 2;
What are the clinical trial outcomes for drug 'DrugC'?
CREATE TABLE clinical_trials_2 (drug_name VARCHAR(50),trial_outcome VARCHAR(50)); INSERT INTO clinical_trials_2 (drug_name,trial_outcome) VALUES ('DrugC','Approved'),('DrugD','Rejected'),('DrugC','Approved');
SELECT drug_name, trial_outcome FROM clinical_trials_2 WHERE drug_name = 'DrugC';
What is the total number of carbon offset initiatives implemented in India in 2021?
CREATE TABLE carbon_offsets (initiative_name VARCHAR(50),country VARCHAR(50),initiation_year INT); INSERT INTO carbon_offsets (initiative_name,country,initiation_year) VALUES ('Initiative1','India',2021),('Initiative2','India',2019),('Initiative3','India',2021);
SELECT COUNT(*) FROM carbon_offsets WHERE country = 'India' AND initiation_year = 2021;
What is the average budget allocation per public service in the state of California in the last 2 years, ordered by average allocation amount in descending order?
CREATE TABLE PublicServices (ServiceID INT,ServiceName VARCHAR(255),State VARCHAR(255),AllocationDate DATE,Budget DECIMAL(10,2)); INSERT INTO PublicServices (ServiceID,ServiceName,State,AllocationDate,Budget) VALUES (1,'Waste Management','California','2020-03-15',50000.00),(2,'Street Lighting','California','2019-08-28',30000.00);
SELECT AVG(Budget), ServiceName FROM PublicServices WHERE State = 'California' AND AllocationDate >= DATEADD(year, -2, GETDATE()) GROUP BY ServiceName ORDER BY AVG(Budget) DESC;
What is the maximum donation amount given by donors aged 60 or older?
CREATE TABLE donors (id INT,age INT,name VARCHAR(255)); INSERT INTO donors (id,age,name) VALUES (2,63,'Senior Donor'); CREATE TABLE donations (id INT,donor_id INT,organization_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,donor_id,organization_id,amount,donation_date) VALUES (2,2,2,15000,'2021-02-12');
SELECT MAX(amount) FROM donations JOIN donors ON donations.donor_id = donors.id WHERE donors.age >= 60;
List the top 10 most active users in terms of total number of posts, along with the number of followers they have, for users in India.
CREATE TABLE users (id INT,username VARCHAR(50),followers INT,country VARCHAR(50)); CREATE TABLE posts (id INT,user_id INT,content VARCHAR(500));
SELECT u.username, u.followers, COUNT(p.id) as total_posts FROM users u JOIN posts p ON u.id = p.user_id WHERE u.country = 'India' GROUP BY u.id ORDER BY total_posts DESC LIMIT 10;
Delete records in the 'player_transactions' table where the transaction amount is below 10
CREATE TABLE player_transactions (transaction_id INT,player_id INT,amount FLOAT,date DATE);
DELETE FROM player_transactions WHERE amount < 10;
What is the total CO2 emission reduction for each smart city initiative, partitioned by initiative category and ordered by the total reduction?
CREATE TABLE CitySmartInitiatives (City VARCHAR(255),Initiative VARCHAR(255),InitiativeCategory VARCHAR(255),CO2EmissionReduction FLOAT); INSERT INTO CitySmartInitiatives (City,Initiative,InitiativeCategory,CO2EmissionReduction) VALUES ('NYC','SmartGrid','Energy',15000),('LA','SmartTransit','Transportation',20000),('Chicago','SmartBuildings','Energy',10000);
SELECT InitiativeCategory, SUM(CO2EmissionReduction) OVER (PARTITION BY InitiativeCategory) AS Total_Reduction FROM CitySmartInitiatives ORDER BY Total_Reduction DESC;
How many 'WNBA' and 'MLS' events were held in 'June'?
CREATE TABLE Events (event_id INT,event_name VARCHAR(255),team VARCHAR(255),month VARCHAR(255)); INSERT INTO Events VALUES (1,'Match 1','WNBA','June'),(2,'Match 2','MLS','June');
SELECT COUNT(*) FROM Events WHERE (team = 'WNBA' OR team = 'MLS') AND month = 'June';
What's the average environmental impact score for mining operations in each continent, in the last 3 years?
CREATE TABLE environmental_impact (id INT PRIMARY KEY,continent VARCHAR(50),impact_score INT,operation_date DATE); INSERT INTO environmental_impact (id,continent,impact_score,operation_date) VALUES (1,'North America',75,'2020-01-01'),(2,'South America',85,'2019-05-05'),(3,'North America',65,'2021-03-15');
SELECT continent, AVG(impact_score) as avg_score FROM environmental_impact WHERE operation_date >= DATEADD(year, -3, GETDATE()) GROUP BY continent;
What is the maximum preservation score of cultural heritage sites in Madrid?
CREATE TABLE cultural_sites (id INT,city TEXT,preservation_score INT); INSERT INTO cultural_sites (id,city,preservation_score) VALUES (1,'Madrid',7),(2,'Madrid',9),(3,'Madrid',8);
SELECT MAX(preservation_score) FROM cultural_sites WHERE city = 'Madrid';
Update the record of offender with id 1
CREATE TABLE offenders (id INT PRIMARY KEY,name VARCHAR(255),age INT,state VARCHAR(2));
UPDATE offenders SET name = 'Jamal Johnson-Smith', age = 36 WHERE id = 1;
What is the minimum and maximum number of hours worked per week by women in tech roles in Australia?
CREATE TABLE WomenInTech(name VARCHAR(255),role VARCHAR(255),hours_per_week DECIMAL(5,2));INSERT INTO WomenInTech(name,role,hours_per_week) VALUES('Alice','Software Engineer',40.00),('Bob','Product Manager',45.00),('Carol','Data Scientist',50.00),('Dana','QA Engineer',35.00),('Eva','UX Designer',30.00);
SELECT MIN(hours_per_week), MAX(hours_per_week) FROM WomenInTech WHERE role LIKE '%tech%';
What is the minimum billing amount for clients in the 'chicago' region?
CREATE TABLE clients (id INT,name TEXT,region TEXT,billing_amount DECIMAL(10,2)); INSERT INTO clients (id,name,region,billing_amount) VALUES (1,'Alice','chicago',200.00),(2,'Bob','chicago',300.00),(3,'Charlie','chicago',400.00);
SELECT MIN(billing_amount) FROM clients WHERE region = 'chicago';
What is the total number of students and teachers who have access to mental health resources, by building?
CREATE TABLE Buildings (building_id INT,name VARCHAR(255),num_students INT,num_teachers INT,mental_health_resources BOOLEAN);
SELECT building_id, name, SUM(num_students) AS total_students, SUM(num_teachers) AS total_teachers FROM Buildings WHERE mental_health_resources = TRUE GROUP BY building_id, name;
What is the total military expenditure for defense diplomacy by each region in the past decade?
CREATE TABLE Military_Expenditure_Defense_Diplomacy (id INT,region VARCHAR(50),year INT,expenditure INT);
SELECT region, SUM(expenditure) as total_expenditure FROM Military_Expenditure_Defense_Diplomacy WHERE year BETWEEN (YEAR(CURRENT_DATE) - 10) AND YEAR(CURRENT_DATE) GROUP BY region;
What was the total budget spent on 'Education' and 'Health' programs in 2021?
CREATE TABLE Budget (budget_id INT,program_category VARCHAR(255),budget_amount DECIMAL(10,2),budget_date DATE); INSERT INTO Budget (budget_id,program_category,budget_amount,budget_date) VALUES (1,'Education',5000,'2021-01-01'),(2,'Health',3500,'2021-02-01'),(3,'Environment',7000,'2021-03-01'),(4,'Education',2800,'2021-04-01'),(5,'Health',6000,'2021-05-01');
SELECT program_category, SUM(budget_amount) as total_budget FROM Budget WHERE budget_date BETWEEN '2021-01-01' AND '2021-12-31' AND program_category IN ('Education', 'Health') GROUP BY program_category;
Provide a list of all warehouses and their average lead times, grouped by country.
CREATE TABLE Warehouses (WarehouseID int,WarehouseName varchar(255),Country varchar(255));CREATE TABLE Shipments (ShipmentID int,WarehouseID int,LeadTime int); INSERT INTO Warehouses (WarehouseID,WarehouseName,Country) VALUES (1,'W1','USA'); INSERT INTO Shipments (ShipmentID,WarehouseID,LeadTime) VALUES (1,1,5);
SELECT w.Country, AVG(s.LeadTime) as AvgLeadTime FROM Warehouses w INNER JOIN Shipments s ON w.WarehouseID = s.WarehouseID GROUP BY w.Country;
Update the artist_demographics table to include the correct artist_gender for artist 'Alexander' with artist_id 101.
CREATE TABLE artist_demographics (artist_id INT,artist_name TEXT,artist_gender TEXT);
UPDATE artist_demographics SET artist_gender = 'Male' WHERE artist_id = 101 AND artist_name = 'Alexander';
Show the total funding for startups founded by people from underrepresented communities
CREATE TABLE diversity (company_name VARCHAR(50),underrepresented_community BOOLEAN); INSERT INTO diversity (company_name,underrepresented_community) VALUES ('Acme Inc',TRUE),('Beta Corp',FALSE),('Echo Startups',TRUE);
SELECT SUM(funding_amount) FROM funding INNER JOIN company_founding ON funding.company_name = company_founding.company_name INNER JOIN diversity ON funding.company_name = diversity.company_name WHERE diversity.underrepresented_community = TRUE;
Find the top 3 bridges with the highest maintenance costs in the 'Northeast' region, for the year 2020.
CREATE TABLE Bridges (BridgeID INT,Name VARCHAR(255),Region VARCHAR(255),MaintenanceCost DECIMAL(10,2),Year INT);
SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY Region ORDER BY MaintenanceCost DESC) as rank FROM Bridges WHERE Year = 2020 AND Region = 'Northeast') sub WHERE rank <= 3;
What is the total number of legal aid cases handled by each organization, in the last quarter?
CREATE TABLE cases (id INT,date DATE,legal_aid_org_id INT);CREATE VIEW latest_quarter AS SELECT EXTRACT(QUARTER FROM date) as quarter,EXTRACT(MONTH FROM date) as month FROM cases;
SELECT legal_aid_org_id, COUNT(*) as total_cases_handled FROM cases INNER JOIN latest_quarter ON EXTRACT(QUARTER FROM cases.date) = latest_quarter.quarter GROUP BY legal_aid_org_id;
List all disaster preparedness events and their corresponding locations in the 'Westside' district.
CREATE TABLE events (event_id INT,event_name TEXT,location_id INT); CREATE TABLE locations (location_id INT,district_id INT,location_text TEXT);
SELECT e.event_name, l.location_text FROM events e INNER JOIN locations l ON e.location_id = l.location_id WHERE l.district_id = (SELECT district_id FROM districts WHERE district_name = 'Westside');
What is the total amount of climate finance committed by the United States in the climate communication sector?
CREATE TABLE climate_finance (id INT,committer VARCHAR(255),committed_amount DECIMAL(10,2),commit_year INT,sector VARCHAR(255));
SELECT SUM(committed_amount) FROM climate_finance WHERE committer = 'United States' AND sector = 'climate communication';
Retrieve the number of machines that are operational
CREATE TABLE machines (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),status VARCHAR(255)); INSERT INTO machines (id,name,type,status) VALUES (1,'Machine A','CNC','Operational'),(2,'Machine B','Robotic Arm','Under Maintenance'),(3,'Machine C','CNC','Operational');
SELECT COUNT(*) FROM machines WHERE status = 'Operational';
Insert new record into 'dispensary_sales' table with data: customer_id: 101, first_name: 'John', last_name: 'Doe', state: 'NY'
CREATE TABLE dispensary_sales (customer_id INT,first_name VARCHAR(50),last_name VARCHAR(50),state VARCHAR(2));
INSERT INTO dispensary_sales (customer_id, first_name, last_name, state) VALUES (101, 'John', 'Doe', 'NY');
What was the total amount spent on food aid in 2020?
CREATE TABLE expenses (id INT,category TEXT,year INT,amount FLOAT); INSERT INTO expenses (id,category,year,amount) VALUES (1,'Food',2018,5000.00); INSERT INTO expenses (id,category,year,amount) VALUES (2,'Clothing',2019,3000.00); INSERT INTO expenses (id,category,year,amount) VALUES (3,'Food',2020,8000.00);
SELECT SUM(amount) FROM expenses WHERE category = 'Food' AND year = 2020;
How many unique strains were available in California dispensaries in Q1 2022?
CREATE TABLE strains (strain VARCHAR(30),state VARCHAR(20),quarter VARCHAR(10)); INSERT INTO strains (strain,state,quarter) VALUES ('Blue Dream','California','Q1'),('Gorilla Glue','California','Q1'),('Sour Diesel','California','Q1');
SELECT COUNT(DISTINCT strain) as unique_strains FROM strains WHERE state = 'California' AND quarter = 'Q1';
What is the maximum duration for each workout type in the East region?
CREATE TABLE memberships (id INT,member_type VARCHAR(50),region VARCHAR(50)); CREATE TABLE workout_data (member_id INT,workout_type VARCHAR(50),duration INT,heart_rate_avg INT,calories_burned INT,workout_date DATE);
SELECT w.workout_type, MAX(w.duration) as max_duration FROM memberships m JOIN workout_data w ON m.id = w.member_id WHERE m.region = 'East' GROUP BY w.workout_type;
How many emergency calls were received in the 'east' region with a response time greater than 180 minutes?
CREATE TABLE emergency_calls (id INT,region VARCHAR(10),response_time INT); INSERT INTO emergency_calls (id,region,response_time) VALUES (1,'west',120),(2,'west',150),(3,'east',195),(4,'north',105);
SELECT COUNT(*) FROM emergency_calls WHERE region = 'east' AND response_time > 180;