instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Delete all records from the 'investigative_projects' table where the project is assigned to 'John Doe'
CREATE TABLE investigative_projects (project_id INT,project_name VARCHAR(255),status VARCHAR(20),assigned_to INT);
DELETE FROM investigative_projects WHERE assigned_to = (SELECT employee_id FROM employees WHERE name = 'John Doe');
What is the total budget for the 'international_programs' view?
CREATE VIEW international_programs AS SELECT * FROM programs WHERE country = 'International';
SELECT SUM(budget) FROM international_programs;
What is the total amount of organic food orders placed before 10 AM in the 'orders' table?
CREATE TABLE orders (order_id INT,order_time TIME,is_organic BOOLEAN); INSERT INTO orders (order_id,order_time,is_organic) VALUES (1,'09:00:00',true),(2,'10:30:00',false),(3,'08:45:00',true);
SELECT SUM(IIF(is_organic, 1, 0)) as total_organic_orders FROM orders WHERE order_time < '10:00:00';
What is the average change in rent from year to year for units in each building, ordered by building type and then by average change?
CREATE TABLE Buildings (building_id INT,name VARCHAR(50),building_type VARCHAR(50));CREATE TABLE Units (unit_id INT,building_id INT,year_built INT,rent INT);
SELECT b.building_type, b.name, AVG(u.change_in_rent) as avg_change_in_rent FROM (SELECT building_id, YEAR(rent_date) as year, AVG(rent) - LAG(AVG(rent)) OVER (PARTITION BY building_id ORDER BY YEAR(rent_date)) as change_in_rent FROM Units JOIN Rent_Dates ON Units.unit_id = Rent_Dates.unit_id GROUP BY building_id, year) u JOIN Buildings b ON u.building_id = b.building_id GROUP BY b.building_type, b.name ORDER BY b.building_type, avg_change_in_rent;
Update the genre of a news article to 'World News' if its title contains 'Global'.
CREATE TABLE news (id INT,title TEXT,category TEXT); INSERT INTO news (id,title,category) VALUES (1,'Global NewsA','National'); INSERT INTO news (id,title,category) VALUES (2,'Local NewsB','Local'); INSERT INTO news (id,title,category) VALUES (3,'World News ArticleC','World News');
UPDATE news SET category = 'World News' WHERE title LIKE '%Global%';
Insert a new record for a package with ID 4, delivered on 2021-08-01, located in 'Warehouse A'
CREATE TABLE packages (package_id INT,delivery_date DATE,warehouse_location VARCHAR(20));
INSERT INTO packages (package_id, delivery_date, warehouse_location) VALUES (4, '2021-08-01', 'Warehouse A');
What is the total revenue per country in the European region?
CREATE TABLE sales (id INT PRIMARY KEY,product_id INT,quantity INT,sale_price DECIMAL(5,2),order_date DATE,country VARCHAR(255),region VARCHAR(255)); INSERT INTO sales (id,product_id,quantity,sale_price,order_date,country,region) VALUES (1,1,2,59.99,'2021-12-01','Germany','Europe'); INSERT INTO sales (id,product_id,quantity,sale_price,order_date,country,region) VALUES (2,2,1,39.99,'2021-12-03','France','Europe');
SELECT region, SUM(quantity * sale_price) as total_revenue FROM sales WHERE region = 'Europe' GROUP BY region;
Who are the top 5 users by number of policy violations?
CREATE TABLE policy_violations (id INT,user_id INT,violation_date DATE); CREATE TABLE users (id INT,name VARCHAR(50)); INSERT INTO policy_violations (id,user_id,violation_date) VALUES (1,1,'2021-12-01'),(2,2,'2021-12-03'),(3,3,'2021-12-04'),(4,1,'2021-12-05'),(5,4,'2021-12-06'),(6,5,'2021-12-07'); INSERT INTO users (id,name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'),(4,'David'),(5,'Eve');
SELECT users.name, COUNT(policy_violations.id) as violation_count FROM policy_violations INNER JOIN users ON policy_violations.user_id = users.id GROUP BY users.name ORDER BY violation_count DESC LIMIT 5;
What is the landfill capacity for each region for the year 2020?
CREATE TABLE LandfillCapacity (region VARCHAR(255),year INT,capacity INT); INSERT INTO LandfillCapacity (region,year,capacity) VALUES ('North',2020,50000),('South',2020,60000),('East',2020,40000),('West',2020,30000);
SELECT region, capacity FROM LandfillCapacity WHERE year = 2020;
What is the average property size for co-owned properties in the city of Austin?
CREATE TABLE co_ownership (id INT,property_id INT,owner TEXT,city TEXT,size INT); INSERT INTO co_ownership (id,property_id,owner,city,size) VALUES (1,101,'Alice','Austin',1200),(2,101,'Bob','Austin',1200),(3,102,'Carol','Seattle',900);
SELECT AVG(size) FROM co_ownership WHERE city = 'Austin';
What is the minimum depth of all trenches in the Atlantic Ocean?
CREATE TABLE atlantic_ocean (name VARCHAR(255),depth FLOAT); INSERT INTO atlantic_ocean VALUES ('Puerto Rico',8380);
SELECT MIN(depth) FROM atlantic_ocean WHERE name = 'Puerto Rico';
Delete all records in the 'ai_ethics' table where the 'developer' column is 'IBM'
CREATE TABLE ai_ethics (developer VARCHAR(255),principle VARCHAR(255)); INSERT INTO ai_ethics (developer,principle) VALUES ('IBM','Fairness'),('Google','Accountability'),('IBM','Transparency');
DELETE FROM ai_ethics WHERE developer = 'IBM';
Update the status column to 'active' for all records in the customers table where country is 'Indonesia'
CREATE TABLE customers (customer_number INT,status VARCHAR(10),country VARCHAR(50),created_at TIMESTAMP);
UPDATE customers SET status = 'active' WHERE country = 'Indonesia';
What is the total revenue generated by museum memberships?
CREATE TABLE memberships (id INT,member_id INT,start_date DATE,end_date DATE,price DECIMAL(5,2)); CREATE TABLE members (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO memberships (id,member_id,start_date,end_date,price) VALUES (1,1,'2022-01-01','2022-12-31',100.00),(2,2,'2022-07-01','2023-06-30',150.00),(3,3,'2022-04-01','2022-12-31',75.00); INSERT INTO members (id,name,type) VALUES (1,'Jane Doe','Individual'),(2,'John Smith','Family'),(3,'Alice Johnson','Senior');
SELECT SUM(price) FROM memberships JOIN members ON memberships.member_id = members.id WHERE members.type = 'Individual' OR members.type = 'Family' OR members.type = 'Senior';
Insert a new case with CaseID '0002' and CaseStatus 'Open' into the Cases table
CREATE TABLE Cases (CaseID VARCHAR(10),CaseStatus VARCHAR(10));
WITH cte AS (VALUES ('0002', 'Open')) INSERT INTO Cases SELECT * FROM cte;
What is the average transaction amount per day?
CREATE TABLE transactions (transaction_id INT,transaction_date DATE,amount DECIMAL(10,2));
SELECT AVG(amount) FROM transactions GROUP BY transaction_date;
How many articles were published by minority authors in 2021?
CREATE TABLE author (author_id INT,author_name VARCHAR(50),is_minority BOOLEAN); INSERT INTO author (author_id,author_name,is_minority) VALUES (1,'Alice Johnson',TRUE),(2,'Bob Smith',FALSE),(3,'Carla Garcia',TRUE); CREATE TABLE article (article_id INT,author_id INT,publication_date DATE); INSERT INTO article (article_id,author_id,publication_date) VALUES (1,1,'2021-01-01'),(2,2,'2021-02-01'),(3,3,'2021-03-01');
SELECT COUNT(*) as num_articles FROM article JOIN author ON article.author_id = author.author_id WHERE is_minority = TRUE AND EXTRACT(YEAR FROM publication_date) = 2021;
What is the average rating of hotels in the 'Budget' category that have more than 100 reviews?
CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(100),category VARCHAR(50),rating FLOAT,num_reviews INT); INSERT INTO hotels (hotel_id,hotel_name,category,rating,num_reviews) VALUES (1,'Hotel A','Budget',4.2,120),(2,'Hotel B','Luxury',4.8,250),(3,'Hotel C','Budget',3.9,65),(4,'Hotel D','Midrange',4.5,180);
SELECT AVG(rating) FROM hotels WHERE category = 'Budget' AND num_reviews > 100;
What is the maximum number of fires in 'downtown' in a single day?
CREATE TABLE fires (id INT,date DATE,location VARCHAR(20)); INSERT INTO fires (id,date,location) VALUES (1,'2022-01-01','downtown'),(2,'2022-01-02','downtown'),(3,'2022-01-03','uptown');
SELECT MAX(count) FROM (SELECT date, COUNT(*) AS count FROM fires WHERE location = 'downtown' GROUP BY date) AS subquery;
Insert a new record in the 'mining_operation_data' table for the 'Mirny' mine, 'Diamond' as the mined_material, and a production_capacity of 70000 tonnes
CREATE TABLE mining_operation_data (mine_name VARCHAR(50),mined_material VARCHAR(20),production_capacity INT);
INSERT INTO mining_operation_data (mine_name, mined_material, production_capacity) VALUES ('Mirny', 'Diamond', 70000);
What is the average word count of articles published in the last month?
CREATE TABLE articles (id INT,title VARCHAR(50),topic VARCHAR(50),word_count INT,publish_date DATE); INSERT INTO articles (id,title,topic,word_count,publish_date) VALUES (1,'Article 1','topic1',1500,'2022-01-01'),(2,'Article 2','topic2',1000,'2022-02-01');
SELECT AVG(word_count) FROM articles WHERE publish_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the total number of news stories published in the "news" table for each country in the "reporters" table?
CREATE TABLE reporters (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,country VARCHAR(50)); CREATE TABLE published_stories (reporter_id INT,news_id INT); CREATE TABLE news (id INT,title VARCHAR(100),views INT,date DATE,country VARCHAR(50));
SELECT r.country, COUNT(*) AS total_stories FROM reporters r INNER JOIN published_stories ps ON r.id = ps.reporter_id INNER JOIN news n ON ps.news_id = n.id GROUP BY r.country;
Show the total quantity of sustainable fabric types used in all clothing items.
CREATE TABLE TextileSourcing (FabricType VARCHAR(255),Quantity INT,IsSustainable BOOLEAN); INSERT INTO TextileSourcing (FabricType,Quantity,IsSustainable) VALUES ('Organic Cotton',1200,TRUE),('Recycled Polyester',800,TRUE),('Tencel',1500,TRUE),('Virgin Polyester',1000,FALSE),('Conventional Cotton',2000,FALSE);
SELECT SUM(Quantity) FROM TextileSourcing WHERE IsSustainable = TRUE;
What is the average number of comments on posts made in the past week, that contain the word "yoga", for accounts located in Brazil?
CREATE TABLE accounts (id INT,name VARCHAR(255),location VARCHAR(255)); CREATE TABLE posts (id INT,account_id INT,content TEXT,comments INT,timestamp TIMESTAMP); INSERT INTO accounts (id,name,location) VALUES (1,'yoga_lover','Brazil'); INSERT INTO posts (id,account_id,content,comments,timestamp) VALUES (1,1,'post1 with yoga',20,'2022-05-01 12:00:00');
SELECT AVG(comments) FROM posts JOIN accounts ON posts.account_id = accounts.id WHERE posts.timestamp >= NOW() - INTERVAL '1 week' AND posts.content LIKE '%yoga%' AND accounts.location = 'Brazil';
Which client has the highest increase in balance in the Shariah-compliant finance database compared to the previous month?
CREATE TABLE shariah_compliant_finance_history (client_id INT,balance DECIMAL(10,2),month DATE); INSERT INTO shariah_compliant_finance_history (client_id,balance,month) VALUES (3,25000.50,'2022-01-01'),(3,28000.75,'2022-02-01'),(4,30000.75,'2022-01-01'),(4,32000.50,'2022-02-01');
SELECT h1.client_id, h1.balance - LAG(h1.balance) OVER (PARTITION BY h1.client_id ORDER BY h1.month) AS balance_change FROM shariah_compliant_finance_history h1 ORDER BY balance_change DESC LIMIT 1;
List all chemical manufacturers in a given region, along with the total amount of CO2 emissions for each.
CREATE TABLE chemical_manufacturers (manufacturer_id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO chemical_manufacturers (manufacturer_id,name,country) VALUES (1,'ManufacturerA','USA'),(2,'ManufacturerB','Canada'),(3,'ManufacturerC','USA'); CREATE TABLE emissions (emission_id INT,manufacturer_id INT,gas_type VARCHAR(255),amount INT); INSERT INTO emissions (emission_id,manufacturer_id,gas_type,amount) VALUES (1,1,'CO2',1000),(2,1,'CH4',200),(3,2,'CO2',1500),(4,3,'CO2',1200),(5,3,'CH4',300);
SELECT cm.name, SUM(e.amount) FROM chemical_manufacturers cm JOIN emissions e ON cm.manufacturer_id = e.manufacturer_id WHERE cm.country = 'USA' AND e.gas_type = 'CO2' GROUP BY cm.name;
List all cosmetics with a rating above 4.5 and less than 25 USD.
CREATE TABLE All_Cosmetics (product_id INT,product_name VARCHAR(255),rating DECIMAL(3,1),price DECIMAL(10,2)); INSERT INTO All_Cosmetics (product_id,product_name,rating,price) VALUES (1,'Cosmetic 1',4.6,24.99),(2,'Cosmetic 2',4.8,34.99),(3,'Cosmetic 3',4.2,19.99);
SELECT * FROM All_Cosmetics WHERE rating > 4.5 AND price < 25;
What is the total revenue generated from ticket sales for the NY Knicks?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50)); INSERT INTO teams (team_id,team_name) VALUES (1,'NY Knicks'),(2,'LA Lakers'); CREATE TABLE ticket_sales (id INT,team_id INT,revenue INT);
SELECT SUM(ticket_sales.revenue) FROM ticket_sales JOIN teams ON ticket_sales.team_id = teams.team_id WHERE teams.team_name = 'NY Knicks';
What is the total sales figure for each drug by manufacturer?
CREATE TABLE drug_manufacturers (manufacturer_id INT,drug_name TEXT,manufacturer TEXT,sales FLOAT); INSERT INTO drug_manufacturers (manufacturer_id,drug_name,manufacturer,sales) VALUES (1,'DrugE','Manufacturer1',7000000),(2,'DrugF','Manufacturer2',8000000);
SELECT manufacturer, SUM(sales) as total_sales FROM drug_manufacturers GROUP BY manufacturer;
List the names and salaries of baseball players who earned more than the average salary in their league in the 2022 season.
CREATE TABLE IF NOT EXISTS players (id INT,name VARCHAR(50),position VARCHAR(50),team VARCHAR(50),league VARCHAR(50),salary INT);
SELECT name, salary FROM players WHERE league = 'MLB' AND salary > (SELECT AVG(salary) FROM players WHERE league = 'MLB') UNION SELECT name, salary FROM players WHERE league = 'MiLB' AND salary > (SELECT AVG(salary) FROM players WHERE league = 'MiLB');
What is the distribution of non-fungible tokens (NFTs) by category on the Polygon network?
CREATE TABLE polygon_nfts (nft_id INT,nft_name VARCHAR(255),nft_category VARCHAR(255),network VARCHAR(50));
SELECT nft_category, COUNT(*) as count FROM polygon_nfts WHERE network = 'Polygon' GROUP BY nft_category;
Find the heritage sites that were established in the same year as the earliest heritage site in their country.
CREATE TABLE heritage_sites (site_id INT,name VARCHAR(50),location VARCHAR(50),year INT,type VARCHAR(50));
SELECT h1.* FROM heritage_sites h1 INNER JOIN (SELECT location, MIN(year) AS min_year FROM heritage_sites GROUP BY location) h2 ON h1.location = h2.location AND h1.year = h2.min_year;
Delete all records with an id greater than 5 from the artifacts table.
CREATE TABLE artifacts (id INT,name VARCHAR(50),description TEXT); INSERT INTO artifacts (id,name,description) VALUES (1,'Pottery','Ancient pottery from the Mayan civilization'),(2,'Totem pole','Wooden totem pole from the Haida nation'),(3,'Woven rug','Hand-woven rug from the Navajo tribe'),(4,'Beaded necklace','Beaded necklace from the Inuit people'),(5,'Drum','Traditional drum from the Apache tribe');
DELETE FROM artifacts WHERE id > 5;
Get the average distance to the nearest star for each constellation in the Astrophysics_Research table.
CREATE TABLE Astrophysics_Research(id INT,constellation VARCHAR(50),distance_to_nearest_star FLOAT);
SELECT constellation, AVG(distance_to_nearest_star) as Average_Distance FROM Astrophysics_Research GROUP BY constellation;
List the bottom 3 carbon offset initiatives by reduction amount for each city?
CREATE TABLE carbon_offset_initiatives (initiative_name TEXT,city TEXT,reduction_amount INTEGER); INSERT INTO carbon_offset_initiatives VALUES ('InitiativeA','City1',500),('InitiativeB','City1',800),('InitiativeC','City2',300),('InitiativeD','City2',700);
SELECT initiative_name, city, reduction_amount, RANK() OVER (PARTITION BY city ORDER BY reduction_amount ASC) AS rank FROM carbon_offset_initiatives WHERE rank <= 3;
What is the total R&D expenditure for the drug 'MedX' in Asia?
CREATE TABLE rd_expenditure (drug_name TEXT,expenditure NUMERIC,region TEXT); INSERT INTO rd_expenditure (drug_name,expenditure,region) VALUES ('Vaxo',5000000,'United States'),('MedX',7000000,'China');
SELECT SUM(expenditure) FROM rd_expenditure WHERE drug_name = 'MedX' AND region = 'Asia';
List all unique schools in the 'Teachers' table
SELECT DISTINCT School FROM Teachers;
SELECT DISTINCT School FROM Teachers;
What is the average price of sustainable fashion products in the tops category?
CREATE TABLE products (product_id INTEGER,name TEXT,category TEXT,sustainable BOOLEAN,price FLOAT); INSERT INTO products (product_id,name,category,sustainable,price) VALUES (1001,'Organic Cotton Dress','dresses',TRUE,80.0),(1002,'Silk Blouse','tops',FALSE,60.0),(1003,'Recycled Polyester Jacket','jackets',TRUE,120.0),(1004,'Bamboo T-Shirt','tops',TRUE,30.0);
SELECT AVG(price) FROM products WHERE sustainable = TRUE AND category = 'tops';
Delete all uranium mines in Australia with productivity below 800?
CREATE TABLE mine (id INT,name TEXT,location TEXT,mineral TEXT,productivity INT); INSERT INTO mine (id,name,location,mineral,productivity) VALUES (1,'Olympic Dam','Australia','Uranium',700),(2,'Ranger','Australia','Uranium',900);
DELETE FROM mine WHERE mineral = 'Uranium' AND location = 'Australia' AND productivity < 800;
Update the record in the "sustainable_practices" table with an ID of 2 to have a description of 'Minimizing water usage in laundry'
CREATE TABLE sustainable_practices (practice_id INT,description TEXT,category VARCHAR(20)); INSERT INTO sustainable_practices (practice_id,description,category) VALUES (2,'Using water-efficient appliances','Water');
UPDATE sustainable_practices SET description = 'Minimizing water usage in laundry' WHERE practice_id = 2;
What is the total CO2 emission from mining operations in the Andes region?
CREATE TABLE co2_emissions (id INT,region VARCHAR(50),co2_emission INT); INSERT INTO co2_emissions (id,region,co2_emission) VALUES (4,'Andes',16000); INSERT INTO co2_emissions (id,region,co2_emission) VALUES (5,'Andes',17000); INSERT INTO co2_emissions (id,region,co2_emission) VALUES (6,'Andes',18000);
SELECT SUM(co2_emission) FROM co2_emissions WHERE region = 'Andes';
List all the genetic data samples with a gene sequence starting with 'AT' and created after January 15th, 2021.
CREATE TABLE genetic_data (id INT PRIMARY KEY,sample_id INT,gene_sequence TEXT,date DATE); INSERT INTO genetic_data (id,sample_id,gene_sequence,date) VALUES (1,1001,'ATGCGAT...','2021-01-01'),(2,1002,'CGATCG...','2021-01-02'),(3,1003,'ATCGATG...','2021-01-16');
SELECT sample_id, gene_sequence FROM genetic_data WHERE gene_sequence LIKE 'AT%' AND date > '2021-01-15';
What is the total number of rural hospitals in Texas and California with a patient satisfaction score greater than 85?
CREATE TABLE rural_hospitals (id INT,state VARCHAR(2),patient_satisfaction_score INT); INSERT INTO rural_hospitals (id,state,patient_satisfaction_score) VALUES (1,'TX',88),(2,'TX',75),(3,'CA',92),(4,'CA',82);
SELECT SUM(CASE WHEN state IN ('TX', 'CA') AND patient_satisfaction_score > 85 THEN 1 ELSE 0 END) FROM rural_hospitals;
What is the average sales per month for the 'Fast Fashion' category in the year 2023?
CREATE TABLE suppliers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),industry VARCHAR(255)); INSERT INTO suppliers (id,name,country,industry) VALUES (1,'Supplier A','Bangladesh','Textile'); CREATE TABLE garments (id INT PRIMARY KEY,supplier_id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2)); CREATE TABLE sales (id INT PRIMARY KEY,garment_id INT,date DATE,quantity INT); CREATE VIEW sales_by_month AS SELECT YEAR(date) as sales_year,MONTH(date) as sales_month,SUM(quantity) as total_sales FROM sales GROUP BY sales_year,sales_month;
SELECT AVG(total_sales) FROM sales_by_month WHERE sales_year = 2023 AND category = 'Fast Fashion' GROUP BY sales_month;
What is the average labor cost for sustainable building projects in California?
CREATE TABLE labor_costs (id INT,project_state TEXT,project_type TEXT,labor_cost DECIMAL(10,2)); INSERT INTO labor_costs (id,project_state,project_type,labor_cost) VALUES (1,'California','Sustainable',12000.00),(2,'California','Conventional',10000.00);
SELECT AVG(labor_cost) FROM labor_costs WHERE project_state = 'California' AND project_type = 'Sustainable';
What was the average monthly naval equipment spending for each customer in 2021?
CREATE TABLE CustomerNavalSpending (customer_name TEXT,purchase_month DATE,amount INTEGER); INSERT INTO CustomerNavalSpending (customer_name,purchase_month,amount) VALUES ('ABC Corp','2021-04-01',5000000),('DEF Inc','2021-10-15',7000000),('GHI Enterprises','2021-07-20',6000000),('JKL Ltd','2021-12-03',8000000);
SELECT customer_name, AVG(amount) FROM CustomerNavalSpending WHERE purchase_month BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY customer_name;
List the beauty products that are labeled 'paraben-free' and have a sale revenue above the average sale revenue for all products, excluding products labeled 'organic'.
CREATE TABLE ProductsParabenFreeSalesData (product_id INT,product_name TEXT,is_paraben_free BOOLEAN,sale_revenue FLOAT,is_organic BOOLEAN); INSERT INTO ProductsParabenFreeSalesData (product_id,product_name,is_paraben_free,sale_revenue,is_organic) VALUES (1,'Product A',true,75,true),(2,'Product B',false,30,false),(3,'Product C',false,60,false),(4,'Product D',true,120,true),(5,'Product E',false,45,false);
SELECT product_id, product_name, sale_revenue FROM ProductsParabenFreeSalesData WHERE is_paraben_free = true AND is_organic = false AND sale_revenue > (SELECT AVG(sale_revenue) FROM ProductsParabenFreeSalesData WHERE is_organic = false);
How many drugs were approved in each year?
CREATE SCHEMA if not exists pharma; CREATE TABLE if not exists pharma.drug_approval (year INT,drug VARCHAR(255)); INSERT INTO pharma.drug_approval (year,drug) VALUES (2018,'Drug A'),(2019,'Drug B'),(2020,'Drug C'),(2020,'Drug D'),(2021,'Drug E');
SELECT year, COUNT(DISTINCT drug) AS drugs_approved FROM pharma.drug_approval GROUP BY year ORDER BY year;
What is the average trip duration in days for Chinese tourists visiting Africa?
CREATE TABLE tourism_stats (id INT PRIMARY KEY,country VARCHAR(255),destination VARCHAR(255),duration INT); INSERT INTO tourism_stats (id,country,destination,duration) VALUES (1,'China','Kenya',12),(2,'China','South Africa',20),(3,'China','Egypt',14);
SELECT AVG(duration) FROM tourism_stats WHERE country = 'China' AND destination LIKE 'Africa%';
Get the names and total carbon offset of all carbon offset initiatives located in Canada.
CREATE TABLE carbon_offset_initiatives (id INT,name VARCHAR(255),description TEXT,total_carbon_offset FLOAT,country VARCHAR(50));
SELECT name, total_carbon_offset FROM carbon_offset_initiatives WHERE country = 'Canada';
What is the total sales volume for Sustainable garments in Toronto during 2021?
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 SustainableGarments AS SELECT * FROM Garments WHERE fabric_source_id IN (SELECT source_id FROM FabricSources WHERE ethical_rating >= 7.0);CREATE VIEW TorontoSales AS SELECT * FROM Sales WHERE location_id IN (SELECT location_id FROM StoreLocations WHERE city = 'Toronto');CREATE VIEW TorontoSustainableGarments AS SELECT * FROM TorontoSales WHERE garment_id IN (SELECT garment_id FROM SustainableGarments);
SELECT SUM(sales_volume) FROM TorontoSustainableGarments WHERE sale_date BETWEEN '2021-01-01' AND '2021-12-31';
How many unique hotels in the 'Economy' category have no bookings?
CREATE TABLE Hotels (hotel_id INT,hotel_name VARCHAR(100),category VARCHAR(50)); CREATE TABLE Bookings (booking_id INT,hotel_id INT,booking_date DATE,revenue FLOAT,channel VARCHAR(50)); INSERT INTO Hotels (hotel_id,hotel_name,category) VALUES (1,'Hotel A','Boutique'),(2,'Hotel B','Boutique'),(3,'Hotel C','Economy'),(4,'Hotel D','Economy'),(10,'Hotel J','Economy'); INSERT INTO Bookings (booking_id,hotel_id,booking_date,revenue,channel) VALUES (1,1,'2022-01-01',200.0,'Direct'),(2,1,'2022-01-03',150.0,'OTA'),(3,2,'2022-01-05',300.0,'Direct');
SELECT COUNT(DISTINCT Hotels.hotel_id) FROM Hotels LEFT JOIN Bookings ON Hotels.hotel_id = Bookings.hotel_id WHERE Hotels.category = 'Economy' AND Bookings.hotel_id IS NULL;
What is the maximum donation amount made by individual donors from Canada?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonorType TEXT,Country TEXT); INSERT INTO Donors (DonorID,DonorName,DonorType,Country) VALUES (1,'Alice Johnson','Individual','Canada'),(2,'Bob Brown','Individual','Canada'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount INT); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (1,1,1000),(2,1,2000),(3,2,500);
SELECT MAX(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID WHERE Donors.Country = 'Canada' AND Donors.DonorType = 'Individual';
What was the total number of shipments from India to Australia in April 2021?
CREATE TABLE shipments (id INT,origin VARCHAR(255),destination VARCHAR(255),shipped_at TIMESTAMP); INSERT INTO shipments (id,origin,destination,shipped_at) VALUES (1,'India','Australia','2021-04-02 10:30:00'),(2,'India','Australia','2021-04-05 15:45:00');
SELECT COUNT(*) FROM shipments WHERE origin = 'India' AND destination = 'Australia' AND shipped_at >= '2021-04-01' AND shipped_at < '2021-05-01';
How many aircraft and shipbuilding contracts are there?
CREATE TABLE contracts (id INT,category VARCHAR(255),value DECIMAL(10,2));INSERT INTO contracts (id,category,value) VALUES (1,'Aircraft',5000000.00),(2,'Missiles',2000000.00),(3,'Shipbuilding',8000000.00),(4,'Cybersecurity',3000000.00),(5,'Aircraft',6000000.00),(6,'Shipbuilding',9000000.00);
SELECT SUM(CASE WHEN category IN ('Aircraft', 'Shipbuilding') THEN 1 ELSE 0 END) as total_contracts FROM contracts;
How many investigative journalism articles were published in 2021, excluding opinion pieces?
CREATE TABLE articles (article_id INT,title TEXT,topic TEXT,is_opinion BOOLEAN,published_at DATETIME); INSERT INTO articles (article_id,title,topic,is_opinion,published_at) VALUES (1,'Investigation of Corruption Scandal','investigative journalism',FALSE,'2021-06-15 12:00:00'),(2,'Opinion: Future of Investigative Journalism','opinion',TRUE,'2021-07-20 09:30:00');
SELECT COUNT(*) FROM articles WHERE topic = 'investigative journalism' AND is_opinion = FALSE AND YEAR(published_at) = 2021;
What is the total revenue generated by each cultural event category?
CREATE TABLE events (id INT,name VARCHAR(50),category VARCHAR(50),revenue INT);
SELECT category, SUM(revenue) FROM events GROUP BY category;
Average population of all animals in forests
CREATE TABLE if not exists animal_population (id INT,animal VARCHAR(255),country VARCHAR(255),population INT); INSERT INTO animal_population (id,animal,country,population) VALUES (1,'Tiger','India',2500),(2,'Elephant','India',5000),(3,'Rhinoceros','India',1500),(4,'Lion','Kenya',3000),(5,'Giraffe','Kenya',1000),(6,'Gorilla','Indonesia',750);
SELECT AVG(population) FROM animal_population WHERE country IN ('India', 'Indonesia', 'Kenya') AND habitat = 'Forest';
Display the names of countries that have participated in defense diplomacy events in the last 5 years
CREATE TABLE defense_diplomacy (id INT,country VARCHAR(255),event_name VARCHAR(255),year INT);
SELECT country FROM defense_diplomacy WHERE year BETWEEN (YEAR(CURRENT_DATE) - 5) AND YEAR(CURRENT_DATE) GROUP BY country;
What is the average landfill capacity in cubic meters for countries in Southeast Asia?
CREATE TABLE LandfillCapacity (country VARCHAR(255),landfill_capacity_cubic_meters DECIMAL(15,2),region VARCHAR(255)); INSERT INTO LandfillCapacity (country,landfill_capacity_cubic_meters,region) VALUES ('Indonesia',12000000.0,'Southeast Asia'),('Thailand',9000000.0,'Southeast Asia'),('Malaysia',7000000.0,'Southeast Asia');
SELECT AVG(landfill_capacity_cubic_meters) FROM LandfillCapacity WHERE region = 'Southeast Asia';
What is the number of dental providers in each county in Texas?
CREATE TABLE counties_tx (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO counties_tx (id,name,state) VALUES (1,'Andrews County','Texas'); CREATE TABLE dental_providers_tx (id INT,name VARCHAR(255),county_id INT); INSERT INTO dental_providers_tx (id,name,county_id) VALUES (1,'Provider X',1);
SELECT c.name, COUNT(dp.id) FROM counties_tx c JOIN dental_providers_tx dp ON c.id = dp.county_id WHERE c.state = 'Texas' GROUP BY c.name;
What is the total number of creative AI applications developed in each country?
CREATE TABLE creative_ai_development (id INT,app_name VARCHAR(50),country VARCHAR(50)); INSERT INTO creative_ai_development (id,app_name,country) VALUES (1,'DeepArt','Germany'),(2,'Artbreeder','Japan'),(3,'Dreamscope','United States'),(4,'DeepDream Generator','Canada'),(5,'Runway ML','United Kingdom'),(6,'DeepArt Effects','France');
SELECT country, COUNT(*) FROM creative_ai_development GROUP BY country;
Show the names of all retailers carrying both "organic" and "gluten-free" products
CREATE TABLE retailers (retailer_id INT,retailer_name VARCHAR(50)); INSERT INTO retailers (retailer_id,retailer_name) VALUES (1,'Whole Foods'); INSERT INTO retailers (retailer_id,retailer_name) VALUES (2,'Trader Joe''s'); CREATE TABLE inventory (product_id INT,product_name VARCHAR(50),retailer_id INT,is_organic BOOLEAN,is_gluten_free BOOLEAN); INSERT INTO inventory (product_id,product_name,retailer_id,is_organic,is_gluten_free) VALUES (1,'Organic Quinoa',1,true,false); INSERT INTO inventory (product_id,product_name,retailer_id,is_organic,is_gluten_free) VALUES (2,'Gluten-Free Pasta',1,false,true); INSERT INTO inventory (product_id,product_name,retailer_id,is_organic,is_gluten_free) VALUES (3,'Organic Almond Milk',2,true,false); INSERT INTO inventory (product_id,product_name,retailer_id,is_organic,is_gluten_free) VALUES (4,'Gluten-Free Bread',2,false,true);
SELECT DISTINCT r.retailer_name FROM retailers r JOIN inventory i ON r.retailer_id = i.retailer_id WHERE i.is_organic = true AND i.is_gluten_free = true;
What is the average budget of transportation projects in African nations that have been completed?
CREATE TABLE transportation_projects (id INT,project_budget INT,project_status TEXT,country TEXT); INSERT INTO transportation_projects (id,project_budget,project_status,country) VALUES (1,50000,'completed','Nigeria'),(2,75000,'in_progress','Kenya'),(3,30000,'completed','Egypt');
SELECT AVG(project_budget) FROM transportation_projects WHERE project_status = 'completed' AND country IN ('Africa');
What is the total number of vaccines administered, broken down by the type of vaccine and the region where it was administered?
CREATE TABLE Vaccines (VaccineID INT,VaccineType VARCHAR(255),Region VARCHAR(255),Date DATE); INSERT INTO Vaccines (VaccineID,VaccineType,Region,Date) VALUES (1,'Flu Shot','Northeast','2021-10-01');
SELECT VaccineType, Region, COUNT(*) FROM Vaccines GROUP BY VaccineType, Region;
List all festivals with a genre specification
CREATE TABLE festivals (festival_id INT PRIMARY KEY,festival_name VARCHAR(100),location VARCHAR(100),genre VARCHAR(50),attendance INT); INSERT INTO festivals (festival_id,festival_name,location,genre,attendance) VALUES (1,'Fyre Festival','Great Exuma,Bahamas','Pop',45000); INSERT INTO festivals (festival_id,festival_name,location,genre,attendance) VALUES (2,'Primavera Sound','Barcelona,Spain','Indie',220000); INSERT INTO festivals (festival_id,festival_name,location,genre,attendance) VALUES (3,'SummerStage','New York City,NY','Jazz',60000);
SELECT festival_name FROM festivals WHERE genre IS NOT NULL;
What is the average age of inmates who have participated in restorative justice programs, grouped by their gender?
CREATE TABLE inmates (id INT,age INT,gender VARCHAR(10),restorative_program BOOLEAN);
SELECT gender, AVG(age) avg_age FROM inmates WHERE restorative_program = TRUE GROUP BY gender;
What was the average donation amount by state in Q1 2022?
CREATE TABLE Donations (id INT,state VARCHAR(2),donation_amount DECIMAL(5,2),donation_date DATE); INSERT INTO Donations (id,state,donation_amount,donation_date) VALUES (1,'NY',50.00,'2022-01-01'),(2,'CA',100.00,'2022-01-15'),(3,'TX',75.00,'2022-03-03');
SELECT AVG(donation_amount) as avg_donation, state FROM Donations WHERE donation_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY state;
What are the names and birthdates of policyholders who have an automotive policy in California?
CREATE TABLE Policyholder (PolicyholderID INT,Name TEXT,Birthdate DATE,PolicyType TEXT,PolicyState TEXT); INSERT INTO Policyholder (PolicyholderID,Name,Birthdate,PolicyType,PolicyState) VALUES (1,'James Smith','1985-03-14','Automotive','California'); INSERT INTO Policyholder (PolicyholderID,Name,Birthdate,PolicyType,PolicyState) VALUES (2,'Ava Jones','1990-08-08','Homeowners','Texas');
SELECT Name, Birthdate FROM Policyholder WHERE PolicyType = 'Automotive' AND PolicyState = 'California';
What is the average mental health score of students per city?
CREATE TABLE schools (school_id INT,school_name VARCHAR(255),city VARCHAR(255)); CREATE TABLE student_mental_health (student_id INT,school_id INT,mental_health_score INT); INSERT INTO schools (school_id,school_name,city) VALUES (1,'School A','City X'),(2,'School B','City X'),(3,'School C','City Y'); INSERT INTO student_mental_health (student_id,school_id,mental_health_score) VALUES (1,1,70),(2,1,80),(3,2,60),(4,2,75),(5,3,90),(6,3,85);
SELECT s.city, AVG(smh.mental_health_score) as avg_score FROM student_mental_health smh JOIN schools s ON smh.school_id = s.school_id GROUP BY s.city;
Top 3 most common topics covered in articles by gender?
CREATE TABLE Articles (id INT,author TEXT,gender TEXT,topic TEXT); INSERT INTO Articles (id,author,gender,topic) VALUES (1,'Author 1','Female','Topic 1'),(2,'Author 1','Female','Topic 2'),(3,'Author 2','Male','Topic 1');
SELECT gender, topic, COUNT(*) as topic_count FROM Articles GROUP BY gender, topic ORDER BY topic_count DESC LIMIT 3;
What is the total amount donated by each education level?
CREATE TABLE DonorDemographics (DonorID INT,Gender VARCHAR(255),Income DECIMAL(10,2),EducationLevel VARCHAR(255));
SELECT EducationLevel, SUM(Amount) as TotalDonated FROM Donations D JOIN DonorDemographics DD ON D.DonorID = DD.DonorID GROUP BY EducationLevel;
What is the total budget allocated for program 'Arts' in 2020?
CREATE TABLE Budget (program_id INT,program_name VARCHAR(255),year INT,allocated_budget DECIMAL(10,2)); INSERT INTO Budget (program_id,program_name,year,allocated_budget) VALUES (1,'Arts',2020,2000.00),(2,'Education',2020,3000.00),(3,'Environment',2020,4000.00),(1,'Arts',2019,1500.00),(2,'Education',2019,2500.00),(3,'Environment',2019,3500.00);
SELECT SUM(allocated_budget) FROM Budget WHERE program_name = 'Arts' AND year = 2020;
What is the maximum policy premium for policyholders living in 'Texas' who have a car make of 'Toyota'?
CREATE TABLE Policyholders (PolicyholderID INT,Premium DECIMAL(10,2),PolicyholderState VARCHAR(10),CarMake VARCHAR(20)); INSERT INTO Policyholders (PolicyholderID,Premium,PolicyholderState,CarMake) VALUES (1,2500,'Texas','Toyota'),(2,1500,'New York','Honda'),(3,1000,'California','Tesla');
SELECT MAX(Premium) FROM Policyholders WHERE PolicyholderState = 'Texas' AND CarMake = 'Toyota';
Who are the artists from South America with the highest average artwork value?
CREATE TABLE artworks (id INT,artist VARCHAR(100),collection VARCHAR(50),value INT); INSERT INTO artworks (id,artist,collection,value) VALUES (1,'Fernando','South American Collection',1000),(2,'Gabriela','European Collection',1500),(3,'Hugo','South American Collection',1200);
SELECT artist, AVG(value) AS avg_value FROM artworks WHERE collection LIKE '%South%American%' GROUP BY artist ORDER BY avg_value DESC LIMIT 1;
List the top 3 garment types with the highest sales quantity in the 'GarmentSales' table.
CREATE TABLE GarmentSales (garment_type VARCHAR(50),quantity INT); INSERT INTO GarmentSales (garment_type,quantity) VALUES ('T-Shirt',500),('Jeans',300),('Hoodie',200),('Jackets',400);
SELECT garment_type, quantity FROM GarmentSales ORDER BY quantity DESC LIMIT 3;
Which animal species have a population greater than 1000 in each of their protected habitats?
CREATE TABLE animals (id INT,species TEXT,population INT); CREATE TABLE habitats (id INT,name TEXT,animal_id INT); INSERT INTO animals (id,species,population) VALUES (1,'Tiger',1200),(2,'Elephant',1500),(3,'Rhinoceros',800); INSERT INTO habitats (id,name,animal_id) VALUES (1,'Habitat1',1),(2,'Habitat2',2),(3,'Habitat3',2),(4,'Habitat4',3);
SELECT a.species FROM animals a JOIN habitats h ON a.id = h.animal_id GROUP BY a.species HAVING COUNT(DISTINCT h.name) = SUM(CASE WHEN a.population > 1000 THEN 1 ELSE 0 END);
What is the total number of cases in the justice system that were resolved through restorative justice programs?
CREATE TABLE cases (id INT,resolution_type VARCHAR(20)); INSERT INTO cases (id,resolution_type) VALUES (1,'Restorative Justice'),(2,'Prison'),(3,'Fine');
SELECT COUNT(*) FROM cases WHERE resolution_type = 'Restorative Justice';
What is the total inventory cost for vegan menu items?
CREATE TABLE menu (item_id INT,item_name TEXT,category TEXT,cost FLOAT); INSERT INTO menu (item_id,item_name,category,cost) VALUES (1,'Quinoa Salad','Vegan',7.50),(2,'Tofu Stir Fry','Vegan',8.99),(3,'Chickpea Curry','Vegan',9.49);
SELECT SUM(cost) FROM menu WHERE category = 'Vegan';
What is the maximum number of members in a union?
CREATE TABLE union_membership (id INT,union VARCHAR(20),member_count INT); INSERT INTO union_membership (id,union,member_count) VALUES (1,'construction',3500),(2,'education',8000),(3,'manufacturing',5000);
SELECT MAX(member_count) FROM union_membership;
Calculate veteran unemployment rates by state, for the past 6 months
CREATE TABLE veteran_employment (veteran_id INT,veteran_state VARCHAR(2),employment_status VARCHAR(255),employment_date DATE);
SELECT veteran_state, AVG(CASE WHEN employment_status = 'Unemployed' THEN 100 ELSE 0 END) as unemployment_rate FROM veteran_employment WHERE employment_date >= DATEADD(month, -6, CURRENT_DATE) GROUP BY veteran_state;
What is the average amount of climate finance provided to small island nations for climate adaptation projects between 2016 and 2020?
CREATE TABLE climate_finance (year INT,country VARCHAR(50),initiative VARCHAR(50),amount FLOAT); INSERT INTO climate_finance (year,country,initiative,amount) VALUES (2016,'Small Island Nation 1','climate adaptation',100000);
SELECT AVG(amount) FROM climate_finance WHERE country LIKE '%small island nation%' AND initiative = 'climate adaptation' AND year BETWEEN 2016 AND 2020;
What are the top 3 digital assets by market capitalization, excluding those developed by Bitcoin developers?
CREATE TABLE assets (asset_name VARCHAR(255),developer VARCHAR(255),market_cap FLOAT); INSERT INTO assets (asset_name,developer,market_cap) VALUES ('Ethereum','Vitalik Buterin',450.3); INSERT INTO assets (asset_name,developer,market_cap) VALUES ('Bitcoin Cash','Bitcoin Devs',220.1);
SELECT asset_name, developer, market_cap FROM (SELECT asset_name, developer, market_cap, ROW_NUMBER() OVER (ORDER BY market_cap DESC) as row_num FROM assets WHERE developer NOT IN ('Bitcoin Devs')) tmp WHERE row_num <= 3;
What is the total number of military bases in the 'US_Military_Bases' table?
CREATE SCHEMA IF NOT EXISTS defense_security;CREATE TABLE IF NOT EXISTS defense_security.US_Military_Bases (id INT PRIMARY KEY,base_name VARCHAR(255),location VARCHAR(255),type VARCHAR(255));INSERT INTO defense_security.US_Military_Bases (id,base_name,location,type) VALUES (1,'Fort Bragg','North Carolina','Army Base');
SELECT COUNT(*) FROM defense_security.US_Military_Bases;
Find the total budget for 'Disability Accommodations' and 'Policy Advocacy' combined.
CREATE TABLE BudgetCategories (ID INT,Category TEXT,Amount FLOAT); INSERT INTO BudgetCategories (ID,Category,Amount) VALUES (1,'Disability Accommodations',75000.00),(2,'Policy Advocacy',25000.00),(3,'Health Care',125000.00);
SELECT SUM(Amount) FROM BudgetCategories WHERE Category IN ('Disability Accommodations', 'Policy Advocacy');
What is the earliest excavation date in the 'africa' region?
CREATE TABLE ExcavationDates (SiteID INT,Region VARCHAR(50),ExcavationDate DATE); INSERT INTO ExcavationDates (SiteID,Region,ExcavationDate) VALUES (1,'africa','2020-01-01'),(2,'americas','2019-01-01');
SELECT MIN(ExcavationDate) AS EarliestExcavationDate FROM ExcavationDates WHERE Region = 'africa';
Show the top 3 products by quantity for the 'metallurgy' department
CREATE TABLE departments (id INT,name VARCHAR(20)); CREATE TABLE products (id INT,department INT,name VARCHAR(20),material VARCHAR(20),quantity INT); INSERT INTO departments (id,name) VALUES (1,'textiles'),(2,'metallurgy'); INSERT INTO products (id,department,name,material,quantity) VALUES (1,1,'beam','steel',100),(2,1,'plate','steel',200),(3,2,'rod','aluminum',150),(4,2,'foil','aluminum',50),(5,1,'yarn','cotton',200),(6,1,'thread','polyester',300),(7,2,'wire','copper',500),(8,2,'screw','steel',800),(9,2,'nut','steel',1000);
SELECT name, material, quantity FROM products WHERE department = 2 ORDER BY quantity DESC LIMIT 3;
What is the minimum funding amount received by a company founded by a person from the BIPOC community?
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,founders TEXT,funding FLOAT,bipoc_founder BOOLEAN); INSERT INTO Companies (id,name,industry,founders,funding,bipoc_founder) VALUES (1,'GreenTech','Green Energy','BIPOC Founder',2000000.00,TRUE); INSERT INTO Companies (id,name,industry,founders,funding,bipoc_founder) VALUES (2,'BlueInnovations','Ocean Technology','White Founder',6000000.00,FALSE);
SELECT MIN(funding) FROM Companies WHERE bipoc_founder = TRUE;
List the top 5 customers by total transaction amount for the year 2021, including their names and account numbers?
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),account_number VARCHAR(20),primary_contact VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE);
SELECT c.customer_name, c.account_number, SUM(t.transaction_amount) as total_transaction_amount FROM customers c JOIN transactions t ON c.customer_id = t.customer_id WHERE transaction_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY c.customer_name, c.account_number ORDER BY total_transaction_amount DESC LIMIT 5;
Update the email address of the participant 'Lucas' in the 'Dance Workshops' table.
CREATE TABLE dance_workshops (workshop_id INT,participant_name VARCHAR(50),email VARCHAR(50)); INSERT INTO dance_workshops (workshop_id,participant_name,email) VALUES (1,'Lucas','[email protected]'),(2,'Nia','[email protected]'),(3,'Kevin','[email protected]');
UPDATE dance_workshops SET email = '[email protected]' WHERE participant_name = 'Lucas';
Insert a new record into the "employee_training" table for employee E003 with the training topic "Environmental Regulations" on February 14, 2022.
CREATE TABLE employee_training (employee_id varchar(10),training_topic varchar(255),training_date date);
INSERT INTO employee_training (employee_id,training_topic,training_date) VALUES ('E003','Environmental Regulations','2022-02-14');
What is the total number of volunteers from historically underrepresented communities who joined in Q1 2022?
CREATE TABLE Volunteers (VolunteerID int,Name varchar(50),Email varchar(50),Community varchar(50),JoinDate date); INSERT INTO Volunteers (VolunteerID,Name,Email,Community,JoinDate) VALUES (1,'Jamila','[email protected]','African American','2022-01-10'),(2,'Hiroshi','[email protected]','Japanese','2022-02-15'),(3,'Marie','[email protected]','French','2022-01-28');
SELECT COUNT(*) as TotalVolunteers FROM Volunteers WHERE QUARTER(JoinDate) = 1 AND Community IN ('African American', 'Hispanic', 'Indigenous', 'LGBTQ+', 'People with Disabilities');
How many critical security incidents have been reported in each region in the past month?
CREATE TABLE security_incidents (id INT,incident_type VARCHAR(255),region VARCHAR(255),severity VARCHAR(255),date DATE); CREATE VIEW incident_summary AS SELECT incident_type,region,severity,date,COUNT(*) OVER (PARTITION BY region ORDER BY date DESC) as incident_count FROM security_incidents;
SELECT region, incident_count FROM incident_summary WHERE severity = 'critical' AND date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY region ORDER BY incident_count DESC;
How many space missions have been recorded for astronauts from China?
CREATE TABLE SpaceMissions (astronaut_name VARCHAR(255),astronaut_country VARCHAR(255),mission_name VARCHAR(255)); INSERT INTO SpaceMissions (astronaut_name,astronaut_country,mission_name) VALUES ('Tayang Yuan','China','Shenzhou 10'),('Fei Junlong','China','Shenzhou 6'),('Nie Haisheng','China','Shenzhou 12');
SELECT COUNT(*) FROM SpaceMissions WHERE astronaut_country = 'China';
Create a table named 'vehicles' with columns 'vehicle_id', 'route_id', 'last_maintenance_date'
CREATE TABLE vehicles (vehicle_id INT,route_id INT,last_maintenance_date DATE);
CREATE TABLE vehicles (vehicle_id INT, route_id INT, last_maintenance_date DATE);
What is the average number of papers published per month by graduate students in the Mathematics department in the past 2 years?
CREATE TABLE graduates (graduate_id INT,name VARCHAR(100),department VARCHAR(50));CREATE TABLE publications (publication_id INT,graduate_id INT,publish_date DATE);
SELECT AVG(paper_count) as avg_papers_per_month FROM (SELECT graduate_id, COUNT(*) as paper_count FROM publications p JOIN graduates g ON p.graduate_id = g.graduate_id WHERE g.department = 'Mathematics' AND p.publish_date >= DATEADD(year, -2, GETDATE()) GROUP BY g.graduate_id, EOMONTH(p.publish_date)) as subquery;
What is the minimum budget for bioprocess engineering projects in 2020?
CREATE TABLE bioprocess_engineering (name VARCHAR(255),year INT,budget FLOAT); INSERT INTO bioprocess_engineering (name,year,budget) VALUES ('ProjectA',2019,8000000),('ProjectB',2020,9000000),('ProjectC',2019,10000000);
SELECT MIN(budget) FROM bioprocess_engineering WHERE year = 2020;
Display the top 3 most profitable restaurants by total revenue. Use the restaurant_revenue table.
CREATE TABLE restaurant_revenue (restaurant_id INT,revenue INT); INSERT INTO restaurant_revenue (restaurant_id,revenue) VALUES (1,1200),(2,1500),(3,800),(4,2000),(5,1700);
SELECT restaurant_id, SUM(revenue) as total_revenue FROM restaurant_revenue GROUP BY restaurant_id ORDER BY total_revenue DESC LIMIT 3;
List the total production and reserves for oil fields in the North Sea.
CREATE TABLE OilFields (FieldID INT,FieldName VARCHAR(50),Country VARCHAR(50),Production INT,Reserves INT); INSERT INTO OilFields (FieldID,FieldName,Country,Production,Reserves) VALUES (1,'Galaxy','USA',20000,500000); INSERT INTO OilFields (FieldID,FieldName,Country,Production,Reserves) VALUES (2,'Apollo','Canada',15000,400000); INSERT INTO OilFields (FieldID,FieldName,Country,Production,Reserves) VALUES (3,'Northstar','North Sea',25000,600000);
SELECT Country, SUM(Production) AS Total_Production, SUM(Reserves) AS Total_Reserves FROM OilFields WHERE Country = 'North Sea' GROUP BY Country;
What is the total number of properties in urban areas with co-ownership agreements, and their average price?
CREATE TABLE property (id INT,price INT,area VARCHAR(255),co_ownership BOOLEAN); INSERT INTO property (id,price,area,co_ownership) VALUES (1,200000,'urban',true),(2,300000,'rural',false);
SELECT SUM(price), AVG(price) FROM property WHERE area = 'urban' AND co_ownership = true;