instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total production figure for all wells located in the Caspian Sea?
CREATE TABLE wells (well_id varchar(10),region varchar(20),production_figures int); INSERT INTO wells (well_id,region,production_figures) VALUES ('W005','Caspian Sea',2500),('W006','Caspian Sea',1500);
SELECT SUM(production_figures) FROM wells WHERE region = 'Caspian Sea';
What was the average price per gram for each strain sold at a specific dispensary in Oregon in Q2 2022?
CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT); INSERT INTO Dispensaries (id,name,state) VALUES (1,'Dispensary A','Oregon'); CREATE TABLE Sales (dispid INT,date DATE,strain TEXT,price DECIMAL(10,2)); INSERT INTO Sales (dispid,date,strain,price) VALUES (1,'2022-04-01','Strain X',10.5); INSERT INTO Sales (dispid,date,strain,price) VALUES (1,'2022-04-02','Strain X',10.75);
SELECT s.strain, AVG(s.price) as avg_price_per_gram FROM Dispensaries d JOIN Sales s ON d.id = s.dispid WHERE d.state = 'Oregon' AND d.name = 'Dispensary A' AND QUARTER(s.date) = 2 GROUP BY s.strain;
What is the total cost of all Mars missions launched by any organization in the mission_data table?
CREATE TABLE mission_data (mission_id INT,name VARCHAR(100),organization VARCHAR(100),launch_date DATE,mission_cost FLOAT);
SELECT SUM(mission_cost) FROM mission_data WHERE mission_data.name IN (SELECT missions.name FROM (SELECT mission_data.name FROM mission_data WHERE mission_data.organization != 'NASA' AND mission_data.mission_cost IS NOT NULL) AS missions WHERE missions.name LIKE '%Mars%');
What is the average depth of the oceanic trenches?
CREATE TABLE ocean_trenches (trench_name TEXT,location TEXT,avg_depth FLOAT); INSERT INTO ocean_trenches VALUES ('Mariana Trench','Pacific Ocean',8178),('Tonga Trench','South Pacific Ocean',10820),('Kuril-Kamchatka Trench','Pacific Ocean',8340);
SELECT AVG(avg_depth) FROM ocean_trenches;
What is the total number of artworks in the 'sculpture' category created by artists from Europe?
CREATE TABLE artworks (id INT,name VARCHAR(255),year INT,artist_name VARCHAR(255),artist_birthplace VARCHAR(255),category VARCHAR(255)); INSERT INTO artworks (id,name,year,artist_name,artist_birthplace,category) VALUES (1,'Painting',1920,'John','England','painting'),(2,'Sculpture',1930,'Sara','France','sculpture'),(3,'Print',1940,'Alex','Germany','print');
SELECT COUNT(*) FROM artworks WHERE category = 'sculpture' AND artist_birthplace LIKE 'Europe%';
Which countries did freight forwarding operations take place in, excluding the USA?
CREATE TABLE freight_forwarding (item VARCHAR(255),country VARCHAR(255)); INSERT INTO freight_forwarding (item,country) VALUES ('apple','USA'),('banana','Canada'),('orange','Mexico');
SELECT country FROM freight_forwarding WHERE country != 'USA';
What is the total number of female and male founders for each country?
CREATE TABLE company_founding (id INT,name VARCHAR(50),country VARCHAR(50),founding_year INT,gender VARCHAR(10)); INSERT INTO company_founding (id,name,country,founding_year,gender) VALUES (1,'Acme Inc','USA',2010,'Male'),(2,'Beta Corp','Canada',2005,'Female'),(3,'Gamma Inc','India',2012,'Male'),(4,'Delta Corp','Brazil',2008,'Female');
SELECT country, gender, COUNT(*) as total FROM company_founding GROUP BY ROLLUP(country, gender);
What was the maximum resolution time for insider threats in the healthcare sector in North America in H2 2021?
CREATE TABLE incident_resolution_times (id INT,sector VARCHAR(255),incident_type VARCHAR(255),resolution_time FLOAT,occurrence_date DATE); INSERT INTO incident_resolution_times (id,sector,incident_type,resolution_time,occurrence_date) VALUES (1,'Healthcare','Insider Threat',20,'2021-07-01');
SELECT MAX(resolution_time) AS max_resolution_time FROM incident_resolution_times WHERE sector = 'Healthcare' AND incident_type = 'Insider Threat' AND occurrence_date >= '2021-07-01' AND occurrence_date < '2022-01-01' AND region = 'North America';
Get the chemical code, production_date, and quantity for the records with a production quantity greater than 700
CREATE TABLE chemical_production (production_date DATE,chemical_code VARCHAR(10),quantity INT); INSERT INTO chemical_production (production_date,chemical_code,quantity) VALUES ('2021-01-03','A123',450),('2021-01-07','A123',620),('2021-01-12','A123',390),('2021-02-15','B456',550),('2021-02-19','B456',700),('2021-03-05','C789',800),('2021-03-10','C789',900),('2021-03-15','C789',850);
SELECT chemical_code, production_date, quantity FROM chemical_production WHERE quantity > 700;
Insert a new esports event with the name 'Fantasy Quest World Cup' and date '2023-08-01'
CREATE TABLE esports_events (id INT PRIMARY KEY,name VARCHAR(50),date DATE);
INSERT INTO esports_events (name, date) VALUES ('Fantasy Quest World Cup', '2023-08-01');
What is the total number of permits issued for residential buildings in the city of Chicago in 2021?
CREATE TABLE building_permits (permit_id INT,building_type VARCHAR(50),city VARCHAR(50),issue_date DATE); INSERT INTO building_permits (permit_id,building_type,city,issue_date) VALUES (13,'Residential','Chicago','2021-01-01'); INSERT INTO building_permits (permit_id,building_type,city,issue_date) VALUES (14,'Residential','Chicago','2021-02-01');
SELECT COUNT(*) FROM building_permits WHERE building_type = 'Residential' AND city = 'Chicago' AND YEAR(issue_date) = 2021;
What is the total amount of climate finance provided to projects in Africa by the Green Climate Fund?
CREATE TABLE green_climate_fund (fund_id INT,project_name VARCHAR(100),country VARCHAR(50),amount FLOAT); INSERT INTO green_climate_fund (fund_id,project_name,country,amount) VALUES (1,'Solar Power Africa','Africa',50000000);
SELECT SUM(amount) FROM green_climate_fund WHERE country = 'Africa';
How many classical songs were released before 2000?
CREATE TABLE songs (song_id INT,title VARCHAR(255),release_year INT,genre VARCHAR(50),length FLOAT); INSERT INTO songs (song_id,title,release_year,genre,length) VALUES (1,'Song1',1999,'classical',120.5),(2,'Song2',2005,'rock',210.3),(3,'Song3',1985,'classical',180.7);
SELECT COUNT(*) FROM songs WHERE genre = 'classical' AND release_year < 2000;
What is the minimum and maximum number of agroecology-based NGOs in Asia?
CREATE TABLE agroecology_ngos (country VARCHAR(50),num_ngos INT); INSERT INTO agroecology_ngos (country,num_ngos) VALUES ('India',150),('China',200),('Indonesia',100);
SELECT MIN(num_ngos), MAX(num_ngos) FROM agroecology_ngos WHERE country IN ('India', 'China', 'Indonesia');
What is the total amount of rainfall for each region in the past year?
CREATE TABLE region_rainfall (region TEXT,date DATE,rainfall INTEGER);
SELECT region, SUM(rainfall) as total_rainfall FROM region_rainfall WHERE date >= DATEADD(year, -1, GETDATE()) GROUP BY region;
List all properties co-owned by women and non-binary individuals.
CREATE TABLE properties (property_id INT,price FLOAT,owner_id INT); CREATE TABLE owners (owner_id INT,name VARCHAR(255),gender VARCHAR(6)); INSERT INTO properties (property_id,price,owner_id) VALUES (1,500000,101),(2,600000,102); INSERT INTO owners (owner_id,name,gender) VALUES (101,'Alice','female'),(102,'Alex','non-binary');
SELECT properties.property_id, owners.name FROM properties INNER JOIN owners ON properties.owner_id = owners.owner_id WHERE owners.gender IN ('female', 'non-binary');
What is the average donation amount received from donors in the Asia region?
CREATE TABLE Donors (id INT,name TEXT,region TEXT,donation_amount DECIMAL); INSERT INTO Donors (id,name,region,donation_amount) VALUES (1,'John Doe','Asia',100.00); INSERT INTO Donors (id,name,region,donation_amount) VALUES (2,'Jane Smith','North America',200.00);
SELECT AVG(donation_amount) FROM Donors WHERE region = 'Asia';
Show the total revenue generated by products that are part of a circular supply chain in the 'Product' table
CREATE TABLE Product (product_id INT PRIMARY KEY,product_name VARCHAR(50),price DECIMAL(5,2),is_circular_supply_chain BOOLEAN);
SELECT SUM(price) FROM Product WHERE is_circular_supply_chain = TRUE;
What is the minimum investment value in the energy sector?
CREATE TABLE investments (investment_id INT,investor_id INT,sector VARCHAR(20),investment_value DECIMAL(10,2)); INSERT INTO investments (investment_id,investor_id,sector,investment_value) VALUES (1,1,'technology',5000.00),(2,2,'finance',3000.00),(3,3,'energy',1000.00);
SELECT MIN(investment_value) FROM investments WHERE sector = 'energy';
Show the number of academic publications per author in descending order.
CREATE TABLE AcademicPublications (PublicationID INT,Author VARCHAR(50),Title VARCHAR(100),Journal VARCHAR(50),PublicationYear INT); INSERT INTO AcademicPublications (PublicationID,Author,Title,Journal,PublicationYear) VALUES (1,'Jane Smith','Title 1','Journal 1',2020); INSERT INTO AcademicPublications (PublicationID,Author,Title,Journal,PublicationYear) VALUES (2,'John Doe','Title 2','Journal 2',2019); INSERT INTO AcademicPublications (PublicationID,Author,Title,Journal,PublicationYear) VALUES (3,'Sophia Thompson','Title 3','Journal 3',2018);
SELECT Author, COUNT(*) as PublicationCount FROM AcademicPublications GROUP BY Author ORDER BY PublicationCount DESC;
What is the total revenue of sustainable tourism in Brazil and Argentina?
CREATE TABLE tourism_revenue (revenue_id INT,country TEXT,revenue FLOAT); INSERT INTO tourism_revenue (revenue_id,country,revenue) VALUES (1,'Brazil',1000000),(2,'Argentina',1500000);
SELECT SUM(revenue) FROM tourism_revenue WHERE country IN ('Brazil', 'Argentina');
Find the average age of visitors who engaged with digital installations, grouped by gender for a specific exhibition
CREATE TABLE Visitor_Demographics (visitor_id INT,age INT,gender VARCHAR(10)); CREATE TABLE Digital_Interactions (visitor_id INT,interaction_date DATE,exhibition_id INT); CREATE TABLE Exhibitions (id INT,name VARCHAR(100),location VARCHAR(50)); INSERT INTO Exhibitions (id,name,location) VALUES (5,'Nature & Wildlife','Canada'); INSERT INTO Visitor_Demographics (visitor_id,age,gender) VALUES (15,25,'Male'); INSERT INTO Visitor_Demographics (visitor_id,age,gender) VALUES (16,27,'Female'); INSERT INTO Digital_Interactions (visitor_id,interaction_date,exhibition_id) VALUES (15,'2022-03-01',5); INSERT INTO Digital_Interactions (visitor_id,interaction_date,exhibition_id) VALUES (16,'2022-03-02',5);
SELECT Exhibitions.name, Gender, AVG(Age) AS Avg_Age FROM ( SELECT Visitor_Demographics.gender AS Gender, Visitor_Demographics.age AS Age, Digital_Interactions.exhibition_id FROM Visitor_Demographics JOIN Digital_Interactions ON Visitor_Demographics.visitor_id = Digital_Interactions.visitor_id WHERE Digital_Interactions.exhibition_id = 5 ) AS Subquery JOIN Exhibitions ON Subquery.exhibition_id = Exhibitions.id GROUP BY Exhibitions.name, Gender;
What is the total number of users who have viewed content in each language?
CREATE TABLE content_lang (content_id INT,content_language VARCHAR(20)); CREATE TABLE content_views (view_id INT,user_id INT,content_id INT,view_date DATE);
SELECT content_language, COUNT(DISTINCT users.user_id) as user_count FROM content_views JOIN content_lang ON content_views.content_id = content_lang.content_id JOIN users ON content_views.user_id = users.user_id GROUP BY content_lang.content_language;
How many marine species are there in the Southern Ocean?
CREATE TABLE species_count (ocean VARCHAR(255),total_species INT); INSERT INTO species_count (ocean,total_species) VALUES ('Atlantic',12432),('Pacific',22310),('Indian',9814),('Southern',6321),('Arctic',2837);
SELECT total_species FROM species_count WHERE ocean = 'Southern';
What is the average age of astronauts who have piloted a SpaceX craft?
CREATE TABLE astronauts (astronaut_id INT,name VARCHAR(100),age INT,craft VARCHAR(50)); INSERT INTO astronauts (astronaut_id,name,age,craft) VALUES (1,'John',45,'Dragon'),(2,'Sarah',36,'Starship'),(3,'Mike',50,'Falcon'); CREATE TABLE spacex_crafts (craft VARCHAR(50),manufacturer VARCHAR(50)); INSERT INTO spacex_crafts (craft,manufacturer) VALUES ('Dragon','SpaceX'),('Starship','SpaceX'),('Falcon','SpaceX');
SELECT AVG(a.age) FROM astronauts a INNER JOIN spacex_crafts c ON a.craft = c.craft WHERE c.manufacturer = 'SpaceX' AND a.pilot = TRUE;
Find the minimum and maximum age of trees in the young_forest table.
CREATE TABLE young_forest (id INT,tree_type VARCHAR(255),planted_date DATE,age INT);
SELECT MIN(age), MAX(age) FROM young_forest;
What is the average runtime of all TV shows in the "tv_shows" table?
CREATE TABLE tv_shows (id INT,name VARCHAR(100),genre VARCHAR(50),runtime INT);
SELECT AVG(runtime) FROM tv_shows;
What is the percentage of dispensaries in each city that sell organic cannabis products?
CREATE TABLE DispensaryProducts (dispensary VARCHAR(255),city VARCHAR(255),organic BOOLEAN); INSERT INTO DispensaryProducts (dispensary,city,organic) VALUES ('Dispensary A','Los Angeles',TRUE),('Dispensary A','Denver',FALSE),('Dispensary B','Los Angeles',TRUE),('Dispensary B','Denver',TRUE);
SELECT city, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM DispensaryProducts WHERE organic = TRUE) as percentage FROM DispensaryProducts WHERE organic = TRUE GROUP BY city;
What is the average salary of employees in the 'Engineering' department?
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(20),LastName VARCHAR(20),Department VARCHAR(20),Salary FLOAT); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (1,'John','Doe','Manufacturing',50000); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (2,'Jane','Doe','Engineering',65000); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (3,'Mike','Smith','Engineering',70000);
SELECT AVG(Salary) as 'Average Salary' FROM Employees WHERE Department = 'Engineering';
Calculate the average grant amount for successful grant applications in the Engineering department.
CREATE TABLE grant_applications (id INT,status VARCHAR(10),department VARCHAR(50),amount DECIMAL(10,2));
SELECT AVG(amount) FROM grant_applications WHERE status = 'successful' AND department = 'Engineering';
What is the total billing amount for cases in the southern region?
CREATE TABLE cases (case_id INT,region VARCHAR(20)); INSERT INTO cases (case_id,region) VALUES (1,'Southern'),(2,'Northern'),(3,'Southern'),(4,'Western'),(5,'Eastern'); CREATE TABLE billing_info (bill_id INT,case_id INT,amount DECIMAL(10,2)); INSERT INTO billing_info (bill_id,case_id,amount) VALUES (1,1,500.00),(2,1,750.00),(3,2,1000.00),(4,3,200.00),(5,4,800.00);
SELECT SUM(billing_info.amount) FROM billing_info INNER JOIN cases ON billing_info.case_id = cases.case_id WHERE cases.region = 'Southern';
List the space missions with the most crew members as of 2022
CREATE TABLE SpaceMissions (id INT,mission_name VARCHAR(255),country VARCHAR(255),start_date DATE,end_date DATE,crew_size INT); INSERT INTO SpaceMissions (id,mission_name,country,start_date,end_date,crew_size) VALUES (1,'International Space Station','United States','1998-11-02','2022-02-28',6); INSERT INTO SpaceMissions (id,mission_name,country,start_date,end_date,crew_size) VALUES (2,'Apollo 13','United States','1970-04-11','1970-04-17',3); INSERT INTO SpaceMissions (id,mission_name,country,start_date,end_date,crew_size) VALUES (3,'Soyuz T-15','Russia','1986-03-13','1986-07-16',2);
SELECT mission_name, crew_size as 'Crew Size' FROM SpaceMissions WHERE end_date IS NULL OR end_date >= '2022-01-01' ORDER BY 'Crew Size' DESC;
What's the difference in the number of pieces between 'Painting' and 'Drawing' tables?
CREATE TABLE Painting (id INT PRIMARY KEY,name VARCHAR(50),artist VARCHAR(50),date DATE); CREATE TABLE Drawing (id INT PRIMARY KEY,name VARCHAR(50),artist VARCHAR(50),date DATE);
SELECT COUNT(*) FROM Painting EXCEPT SELECT COUNT(*) FROM Drawing;
Display the number of bridges and tunnels in the Transportation table
CREATE TABLE Transportation (project_id INT,project_name VARCHAR(255),project_type VARCHAR(255),length FLOAT);
SELECT SUM(CASE WHEN project_type = 'Bridge' THEN 1 ELSE 0 END) AS bridges, SUM(CASE WHEN project_type = 'Tunnel' THEN 1 ELSE 0 END) AS tunnels FROM Transportation;
What is the average age of players who have played the game "Galactic Conquest" and spent more than $50 in the last month?
CREATE TABLE Players (PlayerID INT,Name VARCHAR(50),Age INT,Game VARCHAR(50),Spending DECIMAL(5,2)); INSERT INTO Players (PlayerID,Name,Age,Game,Spending) VALUES (1,'John Doe',25,'Galactic Conquest',60.00); INSERT INTO Players (PlayerID,Name,Age,Game,Spending) VALUES (2,'Jane Smith',30,'Galactic Conquest',55.00); CREATE TABLE Transactions (TransactionID INT,PlayerID INT,Amount DECIMAL(5,2),TransactionDate DATE); INSERT INTO Transactions (TransactionID,PlayerID,Amount,TransactionDate) VALUES (1,1,50.00,'2022-01-01'); INSERT INTO Transactions (TransactionID,PlayerID,Amount,TransactionDate) VALUES (2,1,10.00,'2022-01-15'); INSERT INTO Transactions (TransactionID,PlayerID,Amount,TransactionDate) VALUES (3,2,55.00,'2022-01-05');
SELECT AVG(Players.Age) FROM Players INNER JOIN Transactions ON Players.PlayerID = Transactions.PlayerID WHERE Players.Game = 'Galactic Conquest' AND Transactions.Amount > 50.00 AND Transactions.TransactionDate >= DATEADD(month, -1, GETDATE());
Calculate the total transaction amount for each customer in the "Customers" table, excluding transactions with amounts less than $100.
CREATE TABLE Customers (CustomerID INT,TransactionDate DATE,TransactionAmount DECIMAL(10,2));
SELECT CustomerID, SUM(TransactionAmount) as TotalTransactionAmount FROM Customers WHERE TransactionAmount >= 100 GROUP BY CustomerID;
What are the names of the top 2 artists with the highest number of streams on the "platformG" platform, considering only the "rock" genre?
CREATE TABLE platformG (artist_name TEXT,genre TEXT,streams BIGINT);
SELECT artist_name FROM platformG WHERE genre = 'rock' GROUP BY artist_name ORDER BY SUM(streams) DESC LIMIT 2;
Insert a new building permit for a residential project in Texas with permit number 2023001 and a permit date of 2023-01-01.
CREATE TABLE Permits (PermitID INT,ProjectID INT,PermitType CHAR(1),PermitDate DATE);
INSERT INTO Permits (PermitID, ProjectID, PermitType, PermitDate) VALUES (2023001, NULL, 'R', '2023-01-01');
Identify the top 5 most productive departments in terms of publications for female and non-binary faculty in the past 2 years.
CREATE TABLE faculty (faculty_id INT,faculty_name VARCHAR(255),faculty_gender VARCHAR(255),faculty_department VARCHAR(255)); CREATE TABLE publications (publication_id INT,faculty_id INT,publication_title VARCHAR(255),publication_date DATE);
SELECT f.faculty_department, COUNT(*) AS cnt FROM faculty f INNER JOIN publications p ON f.faculty_id = p.faculty_id WHERE f.faculty_gender IN ('Female', 'Non-binary') AND p.publication_date >= DATE_SUB(CURRENT_DATE, INTERVAL 2 YEAR) GROUP BY f.faculty_department ORDER BY cnt DESC LIMIT 5;
What is the average enrollment for community education programs, rounded to the nearest integer?
CREATE TABLE community_education (id INT,program_name VARCHAR(50),enrollment INT); INSERT INTO community_education (id,program_name,enrollment) VALUES (1,'Wildlife Conservation',1500),(2,'Biodiversity Awareness',1200),(3,'Climate Change Education',1800);
SELECT ROUND(AVG(enrollment)) FROM community_education;
Find the total sales of Indica and Sativa strains for each dispensary in Nevada.
CREATE TABLE DispensarySales(id INT,dispensary VARCHAR(255),state VARCHAR(255),strain_type VARCHAR(255),sales_amount DECIMAL(10,2));
SELECT dispensary, SUM(CASE WHEN strain_type = 'Indica' THEN sales_amount ELSE 0 END) + SUM(CASE WHEN strain_type = 'Sativa' THEN sales_amount ELSE 0 END) as total_sales FROM DispensarySales WHERE state = 'Nevada' GROUP BY dispensary;
What is the sum of revenue for fair trade products in London over the last quarter?
CREATE TABLE products(product_id VARCHAR(20),product_name VARCHAR(20),is_fair_trade BOOLEAN,price DECIMAL(5,2)); INSERT INTO products (product_id,product_name,is_fair_trade,price) VALUES ('Product E','Handmade Chocolates',true,5.99),('Product F','Recycled Notebooks',true,12.99); CREATE TABLE sales(product_id VARCHAR(20),store_location VARCHAR(20),sale_date DATE,quantity INTEGER); INSERT INTO sales (product_id,store_location,sale_date,quantity) VALUES ('Product E','London','2021-09-01',20),('Product F','London','2021-10-01',10);
SELECT SUM(quantity * price) FROM products JOIN sales ON products.product_id = sales.product_id WHERE products.is_fair_trade = true AND sales.store_location = 'London' AND sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND CURRENT_DATE;
What is the daily transaction volume of digital asset 'Cardano'?
CREATE TABLE transaction_data (asset_name TEXT,transactions INT,transaction_volume REAL); INSERT INTO transaction_data (asset_name,transactions,transaction_volume) VALUES ('Cardano',50000,1000000);
SELECT SUM(transaction_volume) FROM transaction_data WHERE asset_name = 'Cardano' AND transaction_date = CURDATE();
Find the average temperature per year for the Greenland region.
CREATE TABLE climate_data (id INT,region VARCHAR,year INT,temperature DECIMAL(5,2));
SELECT region, AVG(temperature) as avg_temperature FROM (SELECT region, year, temperature FROM climate_data WHERE region = 'Greenland' GROUP BY region, year) as subquery GROUP BY region;
List the names of companies founded in the US or Canada that have received seed or series A funding.
CREATE TABLE Companies (id INT,name TEXT,country TEXT); CREATE TABLE Funding (id INT,company_id INT,investor_type TEXT,amount INT,funding_round TEXT); INSERT INTO Companies (id,name,country) VALUES (1,'US Co','USA'); INSERT INTO Companies (id,name,country) VALUES (2,'Canada Co','Canada'); INSERT INTO Funding (id,company_id,investor_type,amount,funding_round) VALUES (1,1,'Seed',500000,'Seed'),(2,1,'VC',6000000,'Series A'),(3,2,'Angel',750000,'Seed');
SELECT Companies.name FROM Companies INNER JOIN Funding ON Companies.id = Funding.company_id WHERE Companies.country IN ('USA', 'Canada') AND (Funding.funding_round = 'Seed' OR Funding.funding_round = 'Series A')
Update the names of all agricultural projects in the 'Americas' region with the prefix 'Green'
CREATE TABLE AgriculturalProjects (id INT,name VARCHAR(50),location VARCHAR(20),budget FLOAT,completion_date DATE);
UPDATE AgriculturalProjects SET name = CONCAT('Green ', name) WHERE location LIKE '%Americas%';
Identify the top 3 most expensive wells in the Gulf of Mexico
CREATE TABLE wells (id INT,location VARCHAR(20),cost FLOAT); INSERT INTO wells (id,location,cost) VALUES (1,'Gulf of Mexico',7000000.0),(2,'North Sea',6000000.0),(3,'Gulf of Mexico',9000000.0);
SELECT location, cost FROM wells WHERE cost IN (SELECT * FROM (SELECT DISTINCT cost FROM wells WHERE location = 'Gulf of Mexico' ORDER BY cost DESC LIMIT 3) as subquery) ORDER BY cost DESC;
How many safety incidents have occurred at each manufacturing site in the past six months?
CREATE TABLE manufacturing_sites (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); CREATE TABLE safety_incidents (id INT PRIMARY KEY,site_id INT,incident_type VARCHAR(255),date DATE,FOREIGN KEY (site_id) REFERENCES manufacturing_sites(id));
SELECT manufacturing_sites.name, COUNT(safety_incidents.id) AS incident_count FROM manufacturing_sites INNER JOIN safety_incidents ON manufacturing_sites.id = safety_incidents.site_id WHERE safety_incidents.date >= DATEADD(month, -6, GETDATE()) GROUP BY manufacturing_sites.id;
How many community policing events were held in the last 30 days, broken down by type and location?
CREATE TABLE CommunityEvents (EventID INT,Date DATE,Type VARCHAR(50),Location VARCHAR(50));
SELECT Type, Location, COUNT(*) as EventCount FROM CommunityEvents WHERE Date >= DATEADD(day, -30, GETDATE()) GROUP BY Type, Location;
Calculate the percentage of accessible metro rides in Tokyo by day of the week.
CREATE TABLE tokyo_metro (metro_id INT,ride_date DATE,is_accessible BOOLEAN,is_weekday BOOLEAN); INSERT INTO tokyo_metro (metro_id,ride_date,is_accessible,is_weekday) VALUES (1,'2021-01-01',TRUE,TRUE),(2,'2021-01-02',FALSE,FALSE);
SELECT is_weekday, ROUND(100.0 * SUM(is_accessible) / COUNT(*), 2) AS accessibility_percentage FROM tokyo_metro GROUP BY is_weekday;
List the 10 oldest bike-sharing trips in Barcelona.
CREATE TABLE barcelona_bikes (id INT,ride_id VARCHAR(20),start_time TIMESTAMP,end_time TIMESTAMP,bike_id INT);
SELECT * FROM barcelona_bikes ORDER BY start_time ASC LIMIT 10;
What is the total quantity of 'Organic Cotton' sourced from 'India' and 'China' in the year 2021?
CREATE TABLE Sourcing (id INT,material VARCHAR(20),country VARCHAR(20),quantity INT,year INT); INSERT INTO Sourcing (id,material,country,quantity,year) VALUES (1,'Organic Cotton','India',5000,2020),(2,'Recycled Polyester','China',3000,2020),(3,'Organic Cotton','India',5500,2021),(4,'Organic Cotton','China',6000,2021);
SELECT SUM(quantity) FROM Sourcing WHERE material = 'Organic Cotton' AND (country = 'India' OR country = 'China') AND year = 2021;
What is the average hotel rating for eco-friendly accommodations in Costa Rica?
CREATE TABLE hotels (hotel_id INT,name TEXT,country TEXT,is_eco_friendly BOOLEAN,rating FLOAT); INSERT INTO hotels (hotel_id,name,country,is_eco_friendly,rating) VALUES (1,'Hotel EcoVista','Costa Rica',TRUE,4.6),(2,'Hotel Verde Playa','Costa Rica',TRUE,4.3),(3,'Hotel Playa Mar','Costa Rica',FALSE,4.1);
SELECT AVG(rating) FROM hotels WHERE is_eco_friendly = TRUE AND country = 'Costa Rica';
What are the defense project timelines for all projects with a budget greater than $50 million in Europe?
CREATE TABLE defense_projects (id INT,project_name VARCHAR(255),start_date DATE,end_date DATE,budget DECIMAL(10,2),region VARCHAR(255)); INSERT INTO defense_projects (id,project_name,start_date,end_date,budget,region) VALUES (1,'Project A','2017-01-01','2021-12-31',60000000.00,'Europe'),(2,'Project B','2019-01-01','2023-12-31',45000000.00,'Asia-Pacific');
SELECT project_name, start_date, end_date FROM defense_projects WHERE budget > 50000000.00 AND region = 'Europe';
What is the total number of art pieces and their average value in African museums?
CREATE TABLE Museums (MuseumID INT,MuseumName VARCHAR(50),Country VARCHAR(50)); CREATE TABLE ArtPieces (ArtPieceID INT,MuseumID INT,Value INT); INSERT INTO Museums VALUES (1,'Museum of African Art','Morocco'),(2,'National Museum of African Art','USA'),(3,'South African National Art Gallery','South Africa'); INSERT INTO ArtPieces VALUES (1,1,5000),(2,1,7000),(3,2,8000),(4,2,9000),(5,3,11000),(6,3,13000);
SELECT COUNT(ArtPieces.ArtPieceID) AS TotalArtPieces, AVG(ArtPieces.Value) AS AvgValue FROM ArtPieces INNER JOIN Museums ON ArtPieces.MuseumID = Museums.MuseumID WHERE Museums.Country = 'Africa';
Identify the top 3 countries with the highest total revenue for the 'Pop' genre in Q4 2021.
CREATE TABLE Revenue (RevenueId INT,Platform VARCHAR(255),Genre VARCHAR(255),Revenue DECIMAL(10,2),Country VARCHAR(255),Date DATE); INSERT INTO Revenue (RevenueId,Platform,Genre,Revenue,Country,Date) VALUES (1,'Spotify','Pop',1000,'USA','2021-10-01'),(2,'Apple Music','Pop',1500,'Canada','2021-10-01'),(3,'Deezer','Pop',800,'Mexico','2021-10-01'),(4,'Tidal','Pop',1200,'Brazil','2021-10-01'),(5,'Pandora','Pop',1800,'Argentina','2021-10-01'),(6,'Spotify','Pop',1100,'USA','2021-11-01'),(7,'Apple Music','Pop',1600,'Canada','2021-11-01'),(8,'Deezer','Pop',900,'Mexico','2021-11-01'),(9,'Tidal','Pop',1300,'Brazil','2021-11-01'),(10,'Pandora','Pop',1900,'Argentina','2021-11-01'),(11,'Spotify','Pop',1200,'USA','2021-12-01'),(12,'Apple Music','Pop',1700,'Canada','2021-12-01'),(13,'Deezer','Pop',1000,'Mexico','2021-12-01'),(14,'Tidal','Pop',1400,'Brazil','2021-12-01'),(15,'Pandora','Pop',2000,'Argentina','2021-12-01');
SELECT Country, Genre, SUM(Revenue) AS TotalRevenue FROM Revenue WHERE Genre = 'Pop' AND Date BETWEEN '2021-10-01' AND '2021-12-31' GROUP BY Country, Genre ORDER BY TotalRevenue DESC LIMIT 3;
How many wells were drilled in the Marcellus Shale each year?
CREATE TABLE drilling (drill_id INT,well_id INT,drill_date DATE); INSERT INTO drilling (drill_id,well_id,drill_date) VALUES (6,6,'2016-01-01'),(7,7,'2017-01-01'),(8,8,'2018-01-01'),(9,9,'2019-01-01'),(10,10,'2020-01-01');
SELECT EXTRACT(YEAR FROM drill_date) AS year, COUNT(*) AS num_wells FROM drilling GROUP BY year HAVING year IN (2016, 2017, 2018, 2019, 2020) AND location = 'Marcellus Shale';
What is the total number of crimes reported before January 15, 2021 in 'crime_data' table?
CREATE TABLE crime_data (id INT,type VARCHAR(255),location VARCHAR(255),reported_date DATE); INSERT INTO crime_data (id,type,location,reported_date) VALUES (1,'Theft','Park','2021-01-01');
SELECT COUNT(*) FROM crime_data WHERE reported_date < '2021-01-15';
What is the minimum age of athletes in the 'athlete_wellbeing' table that play 'Hockey'?
CREATE TABLE athlete_wellbeing (athlete_id INT,name VARCHAR(50),age INT,sport VARCHAR(50)); INSERT INTO athlete_wellbeing (athlete_id,name,age,sport) VALUES (1,'John Doe',25,'Basketball'); INSERT INTO athlete_wellbeing (athlete_id,name,age,sport) VALUES (2,'Jane Smith',28,'Basketball'); INSERT INTO athlete_wellbeing (athlete_id,name,age,sport) VALUES (3,'Jim Brown',30,'Football'); INSERT INTO athlete_wellbeing (athlete_id,name,age,sport) VALUES (4,'Lucy Davis',22,'Football'); INSERT INTO athlete_wellbeing (athlete_id,name,age,sport) VALUES (5,'Mark Johnson',20,'Hockey');
SELECT MIN(age) FROM athlete_wellbeing WHERE sport = 'Hockey';
What are the details of projects that started before 2019-06-01?
CREATE TABLE ProjectTimeline (Id INT,ProjectId INT,Activity VARCHAR(50),StartDate DATE,EndDate DATE); INSERT INTO ProjectTimeline (Id,ProjectId,Activity,StartDate,EndDate) VALUES (1,1,'Design','2019-09-01','2019-12-31'); INSERT INTO ProjectTimeline (Id,ProjectId,Activity,StartDate,EndDate) VALUES (2,2,'Planning','2018-12-01','2019-03-31');
SELECT * FROM ProjectTimeline WHERE StartDate < '2019-06-01';
List the total amount spent on athlete wellbeing programs for each sports team.
CREATE TABLE team_expenses (team_id INT,team_name VARCHAR(50),wellbeing_expenses DECIMAL(10,2)); CREATE TABLE team_payments (payment_id INT,team_id INT,amount DECIMAL(10,2));
SELECT team_name, SUM(team_payments.amount) FROM team_expenses INNER JOIN team_payments ON team_expenses.team_id = team_payments.team_id GROUP BY team_name;
Add a new record to the 'charging_stations' table with id 2001, city 'San Francisco', operator 'Green Charge', num_chargers 10, open_date '2018-05-15'
CREATE TABLE charging_stations (id INT,city VARCHAR(20),operator VARCHAR(20),num_chargers INT,open_date DATE);
INSERT INTO charging_stations (id, city, operator, num_chargers, open_date) VALUES (2001, 'San Francisco', 'Green Charge', 10, '2018-05-15');
What was the total value of transactions for 'SmartContract2' that involved the 'BTC' digital asset, excluding transactions before 2022?
CREATE TABLE Transactions (tx_id INT,contract_name VARCHAR(255),asset_name VARCHAR(255),tx_value DECIMAL(10,2),tx_date DATE); INSERT INTO Transactions (tx_id,contract_name,asset_name,tx_value,tx_date) VALUES (1,'SmartContract1','ETH',100.50,'2021-09-01'); INSERT INTO Transactions (tx_id,contract_name,asset_name,tx_value,tx_date) VALUES (2,'SmartContract2','BTC',200.75,'2022-01-01');
SELECT SUM(tx_value) FROM Transactions WHERE contract_name = 'SmartContract2' AND asset_name = 'BTC' AND tx_date >= '2022-01-01';
List all countries and the percentage of players who play VR games.
CREATE TABLE player (player_id INT,player_name VARCHAR(50),age INT,country VARCHAR(50),plays_vr BOOLEAN); INSERT INTO player (player_id,player_name,age,country,plays_vr) VALUES (1,'John Doe',25,'USA',FALSE); INSERT INTO player (player_id,player_name,age,country,plays_vr) VALUES (2,'Jane Smith',19,'Canada',TRUE); INSERT INTO player (player_id,player_name,age,country,plays_vr) VALUES (3,'Bob Johnson',22,'USA',TRUE); INSERT INTO player (player_id,player_name,age,country,plays_vr) VALUES (4,'Alice Davis',24,'Mexico',FALSE);
SELECT country, (COUNT(plays_vr)*100.0/ (SELECT COUNT(*) FROM player)) as vr_percentage FROM player WHERE plays_vr = TRUE GROUP BY country;
How many unique donors have contributed to the 'global_health' sector in the last 6 months?
CREATE TABLE global_health (donor_id INTEGER,donation_date DATE,organization_name TEXT); INSERT INTO global_health (donor_id,donation_date,organization_name) VALUES (1,'2022-01-01','Malaria Consortium'),(2,'2022-02-01','Schistosomiasis Control Initiative');
SELECT COUNT(DISTINCT donor_id) FROM global_health WHERE donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND organization_name LIKE '%global_health%';
How many vehicles of each model and year are due for maintenance, i.e., have not been maintained in the last 60 days?
CREATE TABLE vehicle (vehicle_id INT,model VARCHAR(255),year INT,route_id INT,last_maintenance DATE); INSERT INTO vehicle (vehicle_id,model,year,route_id,last_maintenance) VALUES (3,'Bus A',2019,3,'2022-01-01'); INSERT INTO vehicle (vehicle_id,model,year,route_id,last_maintenance) VALUES (4,'Train B',2017,4,'2021-12-15');
SELECT model, year, COUNT(*) as vehicles_due_for_maintenance FROM vehicle WHERE DATEDIFF(CURDATE(), last_maintenance) > 60 GROUP BY model, year;
What is the average price of ethical fashion products made from sustainable materials in each region?
CREATE TABLE ethical_fashion (product_id INT,product_type VARCHAR(50),region VARCHAR(50),material_type VARCHAR(50),price DECIMAL(5,2)); INSERT INTO ethical_fashion (product_id,product_type,region,material_type,price) VALUES (1,'Ethical Fashion','Europe','Recycled Polyester',50.00),(2,'Ethical Fashion','Asia','Organic Cotton',60.00),(3,'Ethical Fashion','North America','Tencel',70.00);
SELECT region, AVG(price) FROM ethical_fashion WHERE product_type = 'Ethical Fashion' AND material_type IN ('Recycled Polyester', 'Organic Cotton', 'Tencel') GROUP BY region;
Which genetic research has not reached chromosomes 19, 20, 21, X, or Y?
CREATE TABLE GeneticResearch (id INT,gene_name VARCHAR(255),chromosome INT,research_type VARCHAR(255)); INSERT INTO GeneticResearch (id,gene_name,chromosome,research_type) VALUES (1,'GeneA',1,'Genomic Imprinting'); INSERT INTO GeneticResearch (id,gene_name,chromosome,research_type) VALUES (2,'GeneB',2,'Epigenetics');
SELECT gene_name, research_type FROM GeneticResearch WHERE chromosome NOT IN (19, 20, 21, 22, X, Y);
How many investment portfolios were opened in Q1 2021, by region?
CREATE TABLE investment_portfolios (portfolio_id INT,client_id INT,portfolio_date DATE,region VARCHAR(50)); INSERT INTO investment_portfolios (portfolio_id,client_id,portfolio_date,region) VALUES (1,1,'2021-01-10','North'); INSERT INTO investment_portfolios (portfolio_id,client_id,portfolio_date,region) VALUES (2,2,'2021-02-20','South'); INSERT INTO investment_portfolios (portfolio_id,client_id,portfolio_date,region) VALUES (3,3,'2021-03-05','East');
SELECT region, COUNT(*) as num_portfolios FROM investment_portfolios WHERE portfolio_date >= '2021-01-01' AND portfolio_date < '2021-04-01' GROUP BY region;
Create a table to archive old network infrastructure investments
CREATE TABLE old_network_investments (id INT PRIMARY KEY,location TEXT,investment_amount INT,date DATE);
CREATE TABLE old_network_investments AS SELECT * FROM network_investments WHERE date < (CURRENT_DATE - INTERVAL '1 year');
What is the maximum number of cases heard by a judge in a year?
CREATE TABLE judicial_workload (judge_id INT,year INT,cases_heard INT);
SELECT MAX(cases_heard) FROM judicial_workload;
What was the total cost of agricultural innovation projects in the province of Saskatchewan in 2020?
CREATE TABLE agricultural_projects (id INT,province VARCHAR(50),cost FLOAT,project_type VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO agricultural_projects (id,province,cost,project_type,start_date,end_date) VALUES (1,'Saskatchewan',60000.00,'Precision Agriculture','2020-01-01','2020-12-31');
SELECT SUM(cost) FROM agricultural_projects WHERE province = 'Saskatchewan' AND start_date <= '2020-12-31' AND end_date >= '2020-01-01' AND project_type = 'Precision Agriculture';
What is the moving average of food safety inspection violation counts for the last 12 months for each borough in New York City?
CREATE TABLE nyc_inspections (inspection_id INT,borough VARCHAR(20),violation_date DATE,fine_amount INT);
SELECT borough, AVG(violation_count) as moving_average FROM (SELECT borough, DATEADD(month, DATEDIFF(month, 0, violation_date), 0) as month, COUNT(*) as violation_count FROM nyc_inspections GROUP BY borough, month) AS subquery WHERE month >= DATEADD(month, -12, GETDATE()) GROUP BY borough;
Show the total production volume for each mine and year in the "mine_production", "mines", and "calendar" tables
CREATE TABLE mines (id INT,name VARCHAR(20)); INSERT INTO mines (id,name) VALUES (1,'Golden Mine'),(2,'Silver Mine'); CREATE TABLE calendar (year INT); INSERT INTO calendar (year) VALUES (2020),(2021),(2022); CREATE TABLE mine_production (mine_id INT,year INT,volume INT); INSERT INTO mine_production (mine_id,year,volume) VALUES (1,2020,1000),(1,2021,1200),(2,2022,1500);
SELECT m.name, c.year, SUM(mp.volume) as total_volume FROM mines m JOIN mine_production mp ON m.id = mp.mine_id JOIN calendar c ON mp.year = c.year GROUP BY m.name, c.year;
What percentage of waste is generated from plastic, paper, and metal materials in the 'Asia' region?
CREATE TABLE material_waste (region VARCHAR(50),material VARCHAR(50),waste_metric INT); INSERT INTO material_waste (region,material,waste_metric) VALUES ('Asia','Plastic',3000),('Asia','Paper',2000),('Asia','Metal',1000);
SELECT 100.0 * SUM(CASE WHEN material IN ('Plastic', 'Paper', 'Metal') THEN waste_metric ELSE 0 END) / SUM(waste_metric) AS percentage FROM material_waste WHERE region = 'Asia';
Update the status of peacekeeping operations for a specific country in the peacekeeping_operations table.
CREATE TABLE peacekeeping_operations (id INT PRIMARY KEY,operation_name VARCHAR(50),country VARCHAR(50),status VARCHAR(50)); INSERT INTO peacekeeping_operations (id,operation_name,country,status) VALUES (7,'Operation Harmony','Sudan','Active'),(8,'Operation Unity','South Sudan','Planning');
WITH upd_data AS (UPDATE peacekeeping_operations SET status = 'Completed' WHERE country = 'Sudan' RETURNING *) UPDATE peacekeeping_operations SET status = 'Completed' WHERE id IN (SELECT id FROM upd_data);
What was the total revenue for each product category in Q1 2021?
CREATE TABLE sales (id INT,product_id INT,category VARCHAR(50),quantity INT,price DECIMAL(10,2)); INSERT INTO sales (id,product_id,category,quantity,price) VALUES (1,1,'Electronics',10,50.00),(2,2,'Machinery',5,1000.00),(3,3,'Electronics',8,75.00);
SELECT category, SUM(quantity * price) as total_revenue FROM sales WHERE DATE_FORMAT(order_date, '%Y-%m') BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY category;
List the top 3 countries with the highest solar power capacity (in MW)?
CREATE TABLE solar_farms (farm_name VARCHAR(255),country VARCHAR(255),capacity FLOAT); INSERT INTO solar_farms (farm_name,country,capacity) VALUES ('Desert Sunlight','US',550),('Solar Star','US',579),('Longyangxia Dam Solar Park','CN',850),('Tengger Desert Solar Park','CN',1547),('Topaz Solar Farm','US',550),('Huanghe Hydropower Hainan Solar Park','CN',2000),('Ladakh Solar Farm','IN',1500),('Bhadla Solar Park','IN',2245),('Pokhran Solar Park','IN',4000),('Enel Green Power South Africa','ZA',82.5);
SELECT country, SUM(capacity) as total_capacity FROM solar_farms GROUP BY country ORDER BY total_capacity DESC LIMIT 3;
Which social equity dispensaries were added in Los Angeles in Q2 2022?
CREATE TABLE social_equity_dispensaries (dispensary_id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),open_date DATE); INSERT INTO social_equity_dispensaries (dispensary_id,name,city,state,open_date) VALUES (1,'Dispensary 1','Los Angeles','CA','2022-04-01');
SELECT * FROM social_equity_dispensaries WHERE city = 'Los Angeles' AND open_date BETWEEN '2022-04-01' AND '2022-06-30';
What is the name and launch date of the satellites launched by SpaceX?
CREATE TABLE satellites (id INT,name TEXT,launch_date DATE,manufacturer TEXT); INSERT INTO satellites (id,name,launch_date,manufacturer) VALUES (1,'Dragon','2012-05-25','SpaceX');
SELECT name, launch_date FROM satellites WHERE manufacturer = 'SpaceX';
Which customers have accounts in both the 'High Value' and 'Premium' categories?
CREATE TABLE customer_accounts (customer_id INT,account_id INT,account_type TEXT); INSERT INTO customer_accounts (customer_id,account_id,account_type) VALUES (1,1,'High Value'); INSERT INTO customer_accounts (customer_id,account_id,account_type) VALUES (1,2,'Premium'); INSERT INTO customer_accounts (customer_id,account_id,account_type) VALUES (2,3,'Standard');
SELECT customer_id FROM customer_accounts WHERE account_type = 'High Value' INTERSECT SELECT customer_id FROM customer_accounts WHERE account_type = 'Premium';
What was the average economic diversification score for African countries in Q3 2017?
CREATE TABLE economic_diversification (country VARCHAR(50),quarter INT,score FLOAT); INSERT INTO economic_diversification (country,quarter,score) VALUES ('Nigeria',3,6.2),('South Africa',3,8.5),('Egypt',3,7.1),('Kenya',3,5.9),('Ghana',3,6.8),('Morocco',3,7.6);
SELECT AVG(score) as avg_score FROM economic_diversification WHERE country IN ('Nigeria', 'South Africa', 'Egypt', 'Kenya', 'Ghana', 'Morocco') AND quarter = 3;
What is the minimum landfill capacity in the 'Rural' area?
CREATE TABLE Landfills (id INT,area VARCHAR(20),capacity INT); INSERT INTO Landfills (id,area,capacity) VALUES (1,'Rural',3000);
SELECT MIN(capacity) FROM Landfills WHERE area = 'Rural';
What was the total revenue for each region in Q2 of 2021?
CREATE TABLE Regions (id INT,name VARCHAR(255)); INSERT INTO Regions (id,name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); CREATE TABLE Sales (id INT,region_id INT,quarter INT,year INT,revenue INT); INSERT INTO Sales (id,region_id,quarter,year,revenue) VALUES (1,1,2,2021,5000),(2,2,2,2021,6000),(3,3,2,2021,7000),(4,4,2,2021,8000);
SELECT r.name, SUM(s.revenue) FROM Sales s JOIN Regions r ON s.region_id = r.id WHERE s.quarter = 2 AND s.year = 2021 GROUP BY r.name;
What was the average budget for policy advocacy in the "Southeast" region in 2020?
CREATE TABLE Policy_Advocacy (advocacy_id INT,region VARCHAR(20),budget DECIMAL(10,2),year INT); INSERT INTO Policy_Advocacy (advocacy_id,region,budget,year) VALUES (1,'Southeast',5000,2020),(2,'Northwest',6000,2019);
SELECT AVG(budget) FROM Policy_Advocacy WHERE region = 'Southeast' AND year = 2020;
What is the average amount donated by donors from Asia in the year 2020?
CREATE TABLE DonorTransactions (DonorID INT,Amount DECIMAL(10,2),DonorCountry TEXT,TransactionYear INT); INSERT INTO DonorTransactions (DonorID,Amount,DonorCountry,TransactionYear) VALUES (1,500.00,'India',2020),(2,300.00,'USA',2021),(3,250.00,'China',2020);
SELECT AVG(Amount) FROM DonorTransactions WHERE DonorCountry LIKE 'Asi%' AND TransactionYear = 2020;
Show the total number of exits made by startups founded by refugees
CREATE TABLE startups(id INT,name TEXT,founding_year INT,founder_refugee BOOLEAN); CREATE TABLE exits(id INT,startup_id INT,exit_type TEXT,exit_value FLOAT); INSERT INTO startups (id,name,founding_year,founder_refugee) VALUES (1,'Acme Inc',2010,false); INSERT INTO startups (id,name,founding_year,founder_refugee) VALUES (2,'Beta Corp',2015,true); INSERT INTO startups (id,name,founding_year,founder_refugee) VALUES (3,'Gamma LLC',2020,false); INSERT INTO exits (id,startup_id,exit_type,exit_value) VALUES (1,1,'Acquisition',10000000); INSERT INTO exits (id,startup_id,exit_type,exit_value) VALUES (2,3,'IPO',50000000); INSERT INTO exits (id,startup_id,exit_type,exit_value) VALUES (3,2,'Acquisition',7500000);
SELECT COUNT(*) FROM startups s JOIN exits e ON s.id = e.startup_id WHERE s.founder_refugee = true;
What is the average heart rate of female users during their morning workouts in the month of January?
CREATE TABLE users (id INT,gender VARCHAR(10),signup_date DATE); INSERT INTO users (id,gender,signup_date) VALUES (1,'Female','2020-01-05');
SELECT AVG(hr) FROM workout_data w JOIN users u ON w.user_id = u.id WHERE u.gender = 'Female' AND HOUR(w.timestamp) BETWEEN 6 AND 12 AND MONTH(w.timestamp) = 1;
What is the total number of medical and food supplies delivered to each camp?
CREATE TABLE camps (camp_id INT,name VARCHAR(50)); INSERT INTO camps (camp_id,name) VALUES (1,'Camp A'),(2,'Camp B'),(3,'Camp C'); CREATE TABLE supplies (supply_id INT,camp_id INT,type VARCHAR(50),quantity INT); INSERT INTO supplies (supply_id,camp_id,type,quantity) VALUES (1,1,'Medical Supplies',500),(2,1,'Food Supplies',1000),(3,2,'Medical Supplies',800),(4,3,'Food Supplies',1200),(5,2,'Food Supplies',900),(6,3,'Medical Supplies',700)
SELECT c.name, SUM(CASE WHEN s.type = 'Medical Supplies' THEN s.quantity ELSE 0 END) AS total_medical_supplies, SUM(CASE WHEN s.type = 'Food Supplies' THEN s.quantity ELSE 0 END) AS total_food_supplies FROM supplies s JOIN camps c ON s.camp_id = c.camp_id GROUP BY c.name
How many climate mitigation initiatives were implemented in South America between 2015 and 2018?
CREATE TABLE mitigation_initiatives (country VARCHAR(50),start_year INT,end_year INT,initiative_type VARCHAR(50)); INSERT INTO mitigation_initiatives (country,start_year,end_year,initiative_type) VALUES ('Brazil',2015,2018,'Reforestation'),('Colombia',2016,2018,'Clean Transportation');
SELECT COUNT(*) FROM mitigation_initiatives WHERE country IN (SELECT name FROM countries WHERE region = 'South America') AND start_year <= 2018 AND end_year >= 2015;
What is the average price of cosmetics products that are not cruelty-free and were sold in Europe?
CREATE TABLE cost (id INT,product VARCHAR(255),cruelty_free BOOLEAN,price FLOAT,region VARCHAR(255)); INSERT INTO cost (id,product,cruelty_free,price,region) VALUES (1,'Lipstick',false,12.99,'France'),(2,'Mascara',true,8.99,'Germany'),(3,'Eyeliner',false,9.99,'France');
SELECT AVG(price) FROM cost WHERE cruelty_free = false AND region = 'Europe';
List all unique cultural competency training programs offered by providers in New York and New Jersey.
CREATE TABLE cultural_competency_training (id INT,provider_id INT,program_name VARCHAR(100),program_date DATE); INSERT INTO cultural_competency_training (id,provider_id,program_name,program_date) VALUES (1,456,'Cultural Sensitivity 101','2021-02-01'),(2,456,'Working with Diverse Communities','2021-03-15'); CREATE TABLE healthcare_providers (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO healthcare_providers (id,name,region) VALUES (456,'Jane Smith','New York'),(789,'Alex Brown','New Jersey');
SELECT DISTINCT program_name FROM cultural_competency_training INNER JOIN healthcare_providers ON cultural_competency_training.provider_id = healthcare_providers.id WHERE healthcare_providers.region IN ('New York', 'New Jersey');
What is the average monthly electricity consumption for residential buildings in Texas?
CREATE TABLE electricity_consumption (building_type VARCHAR(50),state VARCHAR(50),year INT,month INT,consumption FLOAT); INSERT INTO electricity_consumption (building_type,state,year,month,consumption) VALUES ('Residential','Texas',2020,1,1000),('Residential','Texas',2020,2,1200),('Residential','Texas',2020,3,1100),('Residential','Texas',2020,4,1300),('Residential','Texas',2020,5,1400),('Residential','Texas',2020,6,1200),('Residential','Texas',2020,7,1300),('Residential','Texas',2020,8,1500),('Residential','Texas',2020,9,1400),('Residential','Texas',2020,10,1100),('Residential','Texas',2020,11,900),('Residential','Texas',2020,12,800);
SELECT AVG(consumption) FROM electricity_consumption WHERE building_type = 'Residential' AND state = 'Texas';
What are the top 2 digital assets by market capitalization, excluding those developed by Stellar?
CREATE TABLE digital_assets (asset_name VARCHAR(255),developer VARCHAR(255),market_cap FLOAT); INSERT INTO digital_assets (asset_name,developer,market_cap) VALUES ('Bitcoin','Satoshi Nakamoto',900.5); INSERT INTO digital_assets (asset_name,developer,market_cap) VALUES ('Stellar','Stellar Devs',350.2);
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 digital_assets WHERE developer != 'Stellar Devs') tmp WHERE row_num <= 2;
What is the total number of articles published by female authors in the articles table?
CREATE TABLE articles (title VARCHAR(255),author VARCHAR(255),date DATE,topic VARCHAR(255));
SELECT COUNT(*) FROM articles WHERE author IN ('Alice', 'Bella', 'Charlotte');
How many communities have a population size greater than 500 in the 'community_population' table?
CREATE TABLE community_population (id INT,community VARCHAR(255),population INT); INSERT INTO community_population (id,community,population) VALUES (1,'Inuit',700),(2,'Samí',300);
SELECT COUNT(*) FROM community_population WHERE population > 500;
What was the average response time for emergency calls in January 2022 for the 'Downtown' district?
CREATE TABLE emergency_calls (id INT,call_time TIMESTAMP,district VARCHAR(20)); INSERT INTO emergency_calls (id,call_time,district) VALUES (1,'2022-01-01 10:30:00','Downtown'),(2,'2022-01-02 15:45:00','Uptown');
SELECT AVG(EXTRACT(HOUR FROM call_time) * 60 + EXTRACT(MINUTE FROM call_time)) AS avg_response_time FROM emergency_calls WHERE district = 'Downtown' AND call_time >= '2022-01-01' AND call_time < '2022-02-01';
Create a view named user_activity that displays the number of posts, comments, and reactions made by each user.
CREATE TABLE users (user_id INT,username VARCHAR(20),email VARCHAR(50),follower_count INT); CREATE TABLE posts (post_id INT,user_id INT,content TEXT,post_time TIMESTAMP); CREATE TABLE comments (comment_id INT,post_id INT,user_id INT,comment TEXT,comment_time TIMESTAMP); CREATE TABLE reactions (reaction_id INT,post_id INT,user_id INT,reaction VARCHAR(10),reaction_time TIMESTAMP);
CREATE VIEW user_activity AS SELECT u.username, COUNT(p.post_id) AS posts, COUNT(c.comment_id) AS comments, COUNT(r.reaction_id) AS reactions FROM users u LEFT JOIN posts p ON u.user_id = p.user_id LEFT JOIN comments c ON u.user_id = c.user_id LEFT JOIN reactions r ON u.user_id = r.user_id GROUP BY u.username;
Minimum weight of artifacts in 'european_sites'
CREATE TABLE european_sites (id INT,site_name VARCHAR(50),artifact_name VARCHAR(50),weight INT);
SELECT MIN(weight) FROM european_sites;
What was the total military equipment sales revenue for the defense industry in 2021?
CREATE TABLE defense_contractors_2 (corp varchar(255),sales int); INSERT INTO defense_contractors_2 (corp,sales) VALUES ('ABC Corp',1000000),('DEF Corp',1200000),('GHI Corp',1500000),('JKL Corp',1100000),('MNO Corp',1300000);
SELECT SUM(sales) FROM defense_contractors_2;