instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Which cities in Japan have populations over 2 million, and what are their populations?
CREATE TABLE japan_cities (name TEXT,population INTEGER); INSERT INTO japan_cities (name,population) VALUES ('Tokyo',37400068),('Yokohama',3668000);
SELECT name, population FROM japan_cities WHERE population > 2000000;
Find the top 3 largest properties by size in the affordable_housing table.
CREATE TABLE affordable_housing (id INT,property_price FLOAT,size INT); INSERT INTO affordable_housing (id,property_price,size) VALUES (1,300000,200),(2,250000,180),(3,350000,250),(4,200000,150);
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY size DESC) as rn FROM affordable_housing) as t WHERE rn <= 3;
What is the total claim amount paid to policyholders from 'California'?
CREATE TABLE claims (policyholder_id INT,claim_amount DECIMAL(10,2),policyholder_state VARCHAR(20)); INSERT INTO claims (policyholder_id,claim_amount,policyholder_state) VALUES (1,500.00,'California'),(2,300.00,'California');
SELECT SUM(claim_amount) FROM claims WHERE policyholder_state = 'California';
Which endangered animals have been introduced to new habitats through conservation efforts?
CREATE TABLE if NOT EXISTS endangered_animals (animal_id INT,animal_name VARCHAR(50),conservation_status VARCHAR(20)); INSERT INTO endangered_animals (animal_id,animal_name,conservation_status) VALUES (1,'Amur Leopard','Critically Endangered'); INSERT INTO endangered_animals (animal_id,animal_name,conservation_status) ...
SELECT animal_name FROM endangered_animals e JOIN introductions i ON e.animal_id = i.animal_id JOIN habitats h ON i.habitat_id = h.habitat_id WHERE conservation_status = 'Critically Endangered';
What is the average R&D expenditure for 'PharmaCorp' in '2022'?
CREATE TABLE RnD (company TEXT,year INTEGER,expenditure INTEGER); INSERT INTO RnD (company,year,expenditure) VALUES ('PharmaCorp',2022,8000000);
SELECT AVG(expenditure) FROM RnD WHERE company = 'PharmaCorp' AND year = 2022;
What is the maximum number of followers for users in the 'social_media' database who are female?
CREATE TABLE users (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,location VARCHAR(50),followers INT); CREATE TABLE following (user_id INT,following_id INT);
SELECT MAX(users.followers) AS max_followers FROM users WHERE users.gender = 'female';
What is the total number of flu cases reported in Europe?
CREATE TABLE Disease (Name TEXT,Region TEXT,Cases INT); INSERT INTO Disease (Name,Region,Cases) VALUES ('Flu','North America',12500); INSERT INTO Disease (Name,Region,Cases) VALUES ('Malaria','Africa',25000);
SELECT SUM(Cases) FROM Disease WHERE Name = 'Flu' AND Region = 'Europe';
What is the total CO2 emission of all Machinery that is older than 10 years?
CREATE TABLE Machinery (MachineryID INT,Type VARCHAR(50),Age INT,CO2Emission INT); INSERT INTO Machinery (MachineryID,Type,Age,CO2Emission) VALUES (1,'Excavator',8,50); INSERT INTO Machinery (MachineryID,Type,Age,CO2Emission) VALUES (2,'Dumper',12,70); INSERT INTO Machinery (MachineryID,Type,Age,CO2Emission) VALUES (3,...
SELECT SUM(CO2Emission) as TotalCO2Emission FROM Machinery WHERE Age > 10;
What is the average horsepower of electric vehicles released in the USA since 2018?
CREATE TABLE Electric_Vehicles (Id INT,Name VARCHAR(50),Horsepower INT,Origin_Country VARCHAR(50)); INSERT INTO Electric_Vehicles (Id,Name,Horsepower,Origin_Country) VALUES (1,'Model S',417,'USA'),(2,'Model 3',261,'USA'),(3,'e-Tron',355,'Germany');
SELECT AVG(Horsepower) FROM Electric_Vehicles WHERE Origin_Country = 'USA' AND YEAR(Release_Date) >= 2018;
What is the maximum duration of a virtual tour?
CREATE TABLE virtual_tours(id INT,name TEXT,country TEXT,duration INT); INSERT INTO virtual_tours (id,name,country,duration) VALUES (1,'Tokyo Sky Tree Virtual Tour','Japan',60),(2,'Paris Virtual Tour','France',90);
SELECT MAX(duration) FROM virtual_tours;
What is the minimum wage in factories that produce the most ethical denim jeans?
CREATE TABLE Factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),num_workers INT,wage DECIMAL(5,2)); CREATE TABLE Products (product_id INT,name VARCHAR(100),factory_id INT); INSERT INTO Factories VALUES (1,'Factory X','Los Angeles',100,15.00),(2,'Factory Y','Jakarta',250,5.00),(3,'Factory Z','Rome',300,12...
SELECT MIN(Factories.wage) FROM Factories JOIN Products ON Factories.factory_id = Products.factory_id WHERE Products.name = 'Eco Denim Jeans';
Insert a new record into the menu_items table for item_name 'Tofu Stir Fry' with price set to 11.99
CREATE TABLE menu_items (item_name VARCHAR(255),price DECIMAL(5,2));
INSERT INTO menu_items (item_name, price) VALUES ('Tofu Stir Fry', 11.99);
How many VR games were released per year?
CREATE TABLE Games (GameID INT,Title VARCHAR(50),ReleaseYear INT,Genre VARCHAR(20),VR BOOLEAN); INSERT INTO Games (GameID,Title,ReleaseYear,Genre,VR) VALUES (1,'Star Shooter',2017,'Action',true); INSERT INTO Games (GameID,Title,ReleaseYear,Genre,VR) VALUES (2,'Galactic Explorer',2018,'Adventure',true);
SELECT ReleaseYear, COUNT(*) FROM Games WHERE VR = true GROUP BY ReleaseYear;
Determine the maximum altitude reached by a spacecraft from the USA
CREATE TABLE spacecraft (id INT,name VARCHAR(50),country VARCHAR(50),launch_date DATE,max_altitude INT);
SELECT MAX(max_altitude) FROM spacecraft WHERE country = 'USA';
What is the average depth of all marine species in the 'marine_species' table, grouped by conservation_status?
CREATE TABLE marine_species (id INT,name VARCHAR(255),conservation_status VARCHAR(255),depth FLOAT); INSERT INTO marine_species (id,name,conservation_status,depth) VALUES (1,'Pacific salmon','Vulnerable',50.0),(2,'Blue whale','Endangered',500.0),(3,'Sea anemone','Least Concern',0.01);
SELECT conservation_status, AVG(depth) AS avg_depth FROM marine_species GROUP BY conservation_status;
What is the total waste generation in kg for the year 2020 across all districts?
CREATE TABLE districts (district_id INT,district_name TEXT,total_waste_kg INT); INSERT INTO districts (district_id,district_name,total_waste_kg) VALUES (1,'District A',5000),(2,'District B',7000),(3,'District C',6000);
SELECT SUM(total_waste_kg) FROM districts WHERE YEAR(districts.date) = 2020;
What is the correlation between the number of attendees and the average donation per attendee for charity fundraising events in the last 12 months, organized by cause?
CREATE TABLE CharityEvents (ID INT,EventName VARCHAR(255),EventDate DATE,Attendees INT,EventCause VARCHAR(255)); CREATE TABLE Donations (ID INT,EventID INT,Donor VARCHAR(255),Donation DECIMAL(10,2));
SELECT e.EventCause, AVG(d.Donation) as AverageDonation, COUNT(e.Attendees) as AttendeesCount, AVG(d.Donation) * COUNT(e.Attendees) as Correlation FROM CharityEvents e JOIN Donations d ON e.ID = d.EventID WHERE e.EventDate >= DATEADD(month, -12, GETDATE()) GROUP BY e.EventCause;
What is the minimum temperature ever recorded on Uranus?
CREATE TABLE PlanetaryTemperature (id INT,planet VARCHAR(50),temperature FLOAT); INSERT INTO PlanetaryTemperature (id,planet,temperature) VALUES (1,'Uranus',-224);
SELECT MIN(temperature) FROM PlanetaryTemperature WHERE planet = 'Uranus';
Which countries have the highest number of satellite launches in the last decade, and what companies were responsible for these launches?
CREATE TABLE satellites(launch_country VARCHAR(255),launch_company VARCHAR(255),launch_date DATE);
SELECT launch_country, launch_company, COUNT(*) as Total FROM satellites WHERE launch_date >= DATE_SUB(CURDATE(), INTERVAL 10 YEAR) GROUP BY launch_country, launch_company ORDER BY Total DESC;
What is the year-over-year change in the number of volunteers for each program, sorted by the largest positive change?
CREATE TABLE volunteers (volunteer_id INT,volunteer_name TEXT,program TEXT,volunteer_year INT,volunteer_hours INT);
SELECT program, volunteer_year, (LAG(volunteer_hours, 1) OVER (PARTITION BY program ORDER BY volunteer_year) - volunteer_hours) as year_over_year_change FROM volunteers ORDER BY year_over_year_change DESC;
How many explainable AI models have been developed in Antarctica?
CREATE TABLE ExplainableAI (model_name TEXT,confidence FLOAT,country TEXT); INSERT INTO ExplainableAI (model_name,confidence,country) VALUES ('ModelA',0.85,'Antarctica');
SELECT COUNT(*) FROM ExplainableAI WHERE country = 'Antarctica';
What is the minimum population for each indigenous community in the Arctic region and how many communities are there in total?
CREATE TABLE IndigenousCommunities (id INT,name VARCHAR(50),region VARCHAR(50),population INT); INSERT INTO IndigenousCommunities (id,name,region,population) VALUES (1,'Community A','Arctic',500); INSERT INTO IndigenousCommunities (id,name,region,population) VALUES (2,'Community B','Arctic',700); INSERT INTO Indigenous...
SELECT region, MIN(population), COUNT(name) FROM IndigenousCommunities GROUP BY region;
What is the average energy efficiency (in kWh/m2) of residential buildings in 'Mumbai' that were constructed after 2010?
CREATE TABLE residential_buildings (id INT,city TEXT,year INT,efficiency FLOAT); INSERT INTO residential_buildings (id,city,year,efficiency) VALUES (1,'Building A',2015,80.7),(2,'Building B',2005,50.2);
SELECT AVG(efficiency) FROM residential_buildings WHERE city = 'Mumbai' AND year > 2010;
What is the total revenue per customer by product category?
CREATE TABLE sales_2 (sale_id INT,product VARCHAR(20),category VARCHAR(20),customer VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO sales_2 (sale_id,product,category,customer,revenue) VALUES (1,'Software','Technology','John Smith',5000.00),(2,'Laptop','Technology','Jane Smith',3000.00),(3,'Consulting','Services','Bob J...
SELECT customer, category, SUM(revenue) as total_revenue FROM sales_2 GROUP BY customer, category;
What is the average soil moisture level in the past 3 days?
CREATE TABLE soil_moisture (date DATE,moisture_level INT); INSERT INTO soil_moisture (date,moisture_level) VALUES ('2021-05-01',60),('2021-05-02',65),('2021-05-03',70),('2021-05-04',75),('2021-05-05',80),('2021-05-06',85),('2021-05-07',90);
SELECT AVG(moisture_level) FROM soil_moisture WHERE date >= DATE_SUB(CURDATE(), INTERVAL 3 DAY);
What is the success rate of missions for each space agency?
CREATE TABLE missions (mission_id INT,name VARCHAR(50),space_agency VARCHAR(50),mission_status VARCHAR(10));
SELECT space_agency, COUNT(*) FILTER (WHERE mission_status = 'successful') * 100.0 / COUNT(*) AS success_rate FROM missions GROUP BY space_agency;
List all makeup products with vegan ingredients sold in the UK.
CREATE TABLE MakeupIngredients (product_id INT,product_name VARCHAR(100),ingredient TEXT,country VARCHAR(50)); INSERT INTO MakeupIngredients VALUES (101,'Liquid Foundation','Aqua,Glycerin,Mica,Iron Oxides','UK'),(102,'Mascara','Aqua,Stearic Acid,Kaolin,Iron Oxides','UK'),(103,'Eyeshadow Palette','Talc,Mica,Zinc Stearat...
SELECT product_id, product_name FROM MakeupIngredients WHERE country = 'UK' AND ingredient LIKE '%vegan%';
What is the total area (in hectares) of farmland dedicated to organic crops in the 'agroecology' schema?
CREATE SCHEMA agroecology;CREATE TABLE organic_farms (id INT,name VARCHAR(50),area_ha FLOAT);INSERT INTO agroecology.organic_farms (id,name,area_ha) VALUES (1,'Farm A',50.3),(2,'Farm B',75.8);
SELECT SUM(area_ha) FROM agroecology.organic_farms;
What is the maximum number of clients an attorney has had in a month?
CREATE TABLE monthly_client_data (month_id INT PRIMARY KEY,attorney_id INT,total_clients INT,month DATE);
SELECT attorney_id, MAX(total_clients) FROM monthly_client_data GROUP BY attorney_id;
Change the court id from 3 to 4 for judge with id 4
CREATE TABLE judges (id INT,first_name VARCHAR(20),last_name VARCHAR(20),court_id INT); INSERT INTO judges (id,first_name,last_name,court_id) VALUES (4,'Fatima','Adebayo',3); CREATE TABLE courts (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO courts (id,name,location) VALUES (3,'High Court of New Zealand','...
UPDATE judges SET court_id = 4 WHERE id = 4;
List the names and genres of Asian authors who have published at least one award-winning book.
CREATE TABLE authors (id INT PRIMARY KEY,name VARCHAR(255),ethnicity VARCHAR(255)); INSERT INTO authors (id,name,ethnicity) VALUES (1,'Kevin Kwan','Asian'); INSERT INTO authors (id,name,ethnicity) VALUES (2,'Celeste Ng','Asian'); CREATE TABLE books (id INT PRIMARY KEY,title VARCHAR(255),author_id INT,publication_year I...
SELECT a.name, g.genre FROM authors a INNER JOIN books b ON a.id = b.author_id INNER JOIN genres g ON b.genre = g.genre WHERE a.ethnicity = 'Asian' AND b.award = true;
Find the daily net transaction amount (total transaction value - total withdrawal value) for the past month, grouped by day and ordered by day in descending order for customers in Oceania?
CREATE TABLE customer_transactions_4 (transaction_id INT,customer_id INT,transaction_value DECIMAL(10,2),transaction_type VARCHAR(10),transaction_date DATE,customer_region VARCHAR(20)); INSERT INTO customer_transactions_4 (transaction_id,customer_id,transaction_value,transaction_type,transaction_date,customer_region) V...
SELECT customer_region, transaction_date, SUM(CASE WHEN transaction_type = 'deposit' THEN transaction_value ELSE -transaction_value END) as daily_net_transaction_amount FROM customer_transactions_4 WHERE transaction_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) AND CURRENT_DATE AND customer_region = 'Oceania' GR...
Insert a new volunteer with ID 6 who signed up on 2022-07-15
CREATE TABLE volunteers (volunteer_id INT,signup_date DATE); INSERT INTO volunteers (volunteer_id,signup_date) VALUES (1,'2022-01-05'),(2,'2022-03-30'),(3,'2022-04-15'),(4,'2022-06-10');
INSERT INTO volunteers (volunteer_id, signup_date) VALUES (6, '2022-07-15');
What are the total number of satellites launched by each company?
CREATE TABLE satellites (launch_year INT,launch_company VARCHAR(50),num_satellites INT); INSERT INTO satellites (launch_year,launch_company,num_satellites) VALUES (2018,'SpaceX',200),(2019,'OneWeb',300),(2020,'SpaceX',600),(2021,'OneWeb',400);
SELECT launch_company, SUM(num_satellites) as total_satellites FROM satellites GROUP BY launch_company ORDER BY total_satellites DESC;
List the hotels in Germany with a rating above 4.5.
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,rating FLOAT); INSERT INTO hotels (hotel_id,hotel_name,country,rating) VALUES (1,'Hotel A','Germany',4.6),(2,'Hotel B','Germany',4.4),(3,'Hotel C','Germany',4.7);
SELECT hotel_name FROM hotels WHERE country = 'Germany' AND rating > 4.5;
How many streams did the song 'Bohemian Rhapsody' get?
CREATE TABLE StreamingData (StreamID INT,SongID INT,StreamDate DATE,Genre VARCHAR(50),SongName VARCHAR(100),StreamCount INT); INSERT INTO StreamingData (StreamID,SongID,StreamDate,Genre,SongName,StreamCount) VALUES (3,3,'2022-02-01','Rock','Bohemian Rhapsody',200); INSERT INTO StreamingData (StreamID,SongID,StreamDate,...
SELECT SUM(StreamCount) FROM StreamingData WHERE SongName = 'Bohemian Rhapsody';
What is the maximum bridge length in Florida?
CREATE TABLE bridges (id INT,name VARCHAR(50),state VARCHAR(50),length FLOAT); INSERT INTO bridges (id,name,state,length) VALUES (1,'Bridge A','Florida',700.00),(2,'Bridge B','Florida',500.33),(3,'Bridge C','Texas',800.00);
SELECT MAX(length) FROM bridges WHERE state = 'Florida';
How many crimes were committed in the last 30 days in each district in Los Angeles?
CREATE TABLE la_districts (id INT,district_name VARCHAR(255));CREATE TABLE crimes (id INT,district_id INT,crime_date DATE);INSERT INTO la_districts (id,district_name) VALUES (1,'Hollywood'),(2,'Downtown'),(3,'Venice');INSERT INTO crimes (id,district_id,crime_date) VALUES (1,1,'2022-03-01'),(2,1,'2022-03-15'),(3,2,'2022...
SELECT d.district_name, COUNT(c.id) crimes_in_last_30_days FROM la_districts d JOIN crimes c ON d.id = c.district_id WHERE c.crime_date >= CURDATE() - INTERVAL 30 DAY GROUP BY d.id;
Insert a new sustainable cosmetic product into the database.
CREATE TABLE Product (ProductID INT,ProductName VARCHAR(50),IsSustainable BOOLEAN); INSERT INTO Product (ProductID,ProductName,IsSustainable) VALUES (101,'Organic Lipstick',TRUE),(102,'Natural Mascara',FALSE),(103,'Vegan Foundation',TRUE);
INSERT INTO Product (ProductID, ProductName, IsSustainable) VALUES (104, 'Eco-Friendly Blush', TRUE);
What is the maximum billing amount for cases in the 'Civil Law' category?
CREATE TABLE cases (case_id INT,category VARCHAR(20),billing_amount DECIMAL(5,2)); INSERT INTO cases (case_id,category,billing_amount) VALUES (1,'Criminal Law',1500.00),(2,'Civil Law',3000.00);
SELECT MAX(billing_amount) FROM cases WHERE category = 'Civil Law';
What is the total number of rural hospitals in Africa and how many of these hospitals have more than 100 beds?
CREATE TABLE rural_hospitals (hospital_id INT,hospital_name VARCHAR(100),country VARCHAR(50),num_beds INT); INSERT INTO rural_hospitals (hospital_id,hospital_name,country,num_beds) VALUES (1,'Hospital A','Nigeria',150),(2,'Hospital B','Nigeria',120),(3,'Hospital C','South Africa',80),(4,'Hospital D','South Africa',130)...
SELECT COUNT(*) AS total_rural_hospitals, COUNT(*) FILTER (WHERE num_beds > 100) AS hospitals_with_more_than_100_beds FROM rural_hospitals WHERE country IN (SELECT name FROM countries WHERE continent = 'Africa');
What was the average construction spending per month in the state of New York in 2020?
CREATE TABLE construction_spending (spending_id INT,amount FLOAT,state VARCHAR(50),spend_date DATE); INSERT INTO construction_spending (spending_id,amount,state,spend_date) VALUES (11,90000,'New York','2020-01-01'); INSERT INTO construction_spending (spending_id,amount,state,spend_date) VALUES (12,110000,'New York','20...
SELECT EXTRACT(MONTH FROM spend_date) AS month, AVG(amount) AS avg_spending FROM construction_spending WHERE state = 'New York' AND YEAR(spend_date) = 2020 GROUP BY month;
What is the average speed of vessels that have a maximum speed greater than 20 knots?
CREATE TABLE Vessels (ID INT PRIMARY KEY,Name TEXT,MaxSpeed FLOAT); INSERT INTO Vessels (ID,Name,MaxSpeed) VALUES (1,'Fishing Vessel 1',18.5),(2,'Cargo Ship 1',22.3),(3,'Tug Boat 1',12.8);
SELECT AVG(MaxSpeed) FROM Vessels WHERE MaxSpeed > 20;
What is the minimum price of Samarium in the given dataset?
CREATE TABLE price_data (element VARCHAR(10),price DECIMAL(5,2)); INSERT INTO price_data VALUES ('Samarium',18.50),('Samarium',19.10),('Samarium',17.90),('Samarium',18.80),('Samarium',19.30);
SELECT MIN(price) FROM price_data WHERE element = 'Samarium';
List all 'travel_advisories' issued for 'Europe' region and their respective advisory counts.
CREATE TABLE travel_advisories (region VARCHAR(50),advisory_count INT); INSERT INTO travel_advisories (region,advisory_count) VALUES ('Asia Pacific',120),('Europe',80),('Americas',150);
SELECT region, advisory_count FROM travel_advisories WHERE region = 'Europe';
What are the names and birthplaces of artists with more than 30 paintings in the 'Paintings' table?
CREATE TABLE Artists (ArtistID INT,Name TEXT,Birthplace TEXT); INSERT INTO Artists (ArtistID,Name,Birthplace) VALUES (1,'Claude Monet','Paris,France'),(2,'Jackson Pollock','Cody,Wyoming'),(3,'Frida Kahlo','Coyoacán,Mexico'); CREATE TABLE Paintings (PaintingID INT,Title TEXT,ArtistID INT); INSERT INTO Paintings (Paintin...
SELECT Artists.Name, Artists.Birthplace FROM Artists INNER JOIN (SELECT ArtistID, COUNT(*) as PaintingCount FROM Paintings GROUP BY ArtistID) as PaintingCounts ON Artists.ArtistID = PaintingCounts.ArtistID WHERE PaintingCounts.PaintingCount > 30;
How many items were shipped from each warehouse in Canada?
CREATE TABLE Warehouse (id INT,city VARCHAR(50),country VARCHAR(50)); INSERT INTO Warehouse (id,city,country) VALUES (1,'Vancouver','Canada'),(2,'Toronto','Canada'); CREATE TABLE Shipment (id INT,quantity INT,warehouse_id INT,destination_country VARCHAR(50)); INSERT INTO Shipment (id,quantity,warehouse_id,destination_c...
SELECT Warehouse.city, SUM(Shipment.quantity) FROM Warehouse INNER JOIN Shipment ON Warehouse.id = Shipment.warehouse_id WHERE Warehouse.country = 'Canada' GROUP BY Warehouse.city;
What is the average mobile data usage in Canada for users in the age range of 25-40?
CREATE TABLE canada_data (user_id INT,age INT,data_usage FLOAT); INSERT INTO canada_data (user_id,age,data_usage) VALUES (1,27,3.9),(2,32,4.3),(3,45,3.5),(4,38,4.7),(5,23,3.2);
SELECT AVG(data_usage) as avg_data_usage FROM canada_data WHERE age BETWEEN 25 AND 40;
Show the top 3 countries with the highest number of international visitors in 2021 and 2022.
CREATE TABLE VisitorStatistics (id INT,country VARCHAR(50),year INT,visitors INT,PRIMARY KEY(id)); INSERT INTO VisitorStatistics (id,country,year,visitors) VALUES (1,'CountryA',2021,10000),(2,'CountryB',2022,15000),(3,'CountryC',2021,12000),(4,'CountryA',2022,11000),(5,'CountryB',2021,14000);
SELECT country, SUM(visitors) AS total_visitors FROM VisitorStatistics WHERE year IN (2021, 2022) GROUP BY country ORDER BY total_visitors DESC LIMIT 3;
What is the percentage of total revenue from grants and donations for each program offered at 'TheaterZ' in the past two years?
CREATE TABLE TheaterZ (event_id INT,event_name VARCHAR(50),event_date DATE,program VARCHAR(50),revenue INT,grant_donation VARCHAR(50));
SELECT program, 100.0 * SUM(CASE WHEN grant_donation = 'grant' THEN revenue ELSE 0 END) / SUM(revenue) AS pct_grant_revenue, 100.0 * SUM(CASE WHEN grant_donation = 'donation' THEN revenue ELSE 0 END) / SUM(revenue) AS pct_donation_revenue FROM TheaterZ WHERE event_date >= DATEADD(year, -2, GETDATE()) GROUP BY program;
List all properties in Portland with inclusive housing policies.
CREATE TABLE properties (property_id INT,city VARCHAR(50),has_inclusive_policy BOOLEAN); INSERT INTO properties (property_id,city,has_inclusive_policy) VALUES (1,'Portland',TRUE),(2,'Seattle',FALSE),(3,'Portland',FALSE);
SELECT property_id, city FROM properties WHERE city = 'Portland' AND has_inclusive_policy = TRUE;
Get the total amount spent on raw materials for each factory in the past month.
CREATE TABLE factories (id INT,name VARCHAR(255),raw_materials_cost DECIMAL(10,2));CREATE TABLE raw_materials_invoices (id INT,factory_id INT,invoice_date DATE,cost DECIMAL(10,2));
SELECT factories.name, SUM(raw_materials_invoices.cost) AS total_cost FROM factories INNER JOIN raw_materials_invoices ON factories.id = raw_materials_invoices.factory_id WHERE raw_materials_invoices.invoice_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY factories.id;
Select all military equipment manufactured before 1985
CREATE TABLE military_equipment (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),manufacturer VARCHAR(255),year INT,country VARCHAR(255)); INSERT INTO military_equipment (id,name,type,manufacturer,year,country) VALUES (1,'M1 Abrams','Tank','General Dynamics',1980,'USA'),(2,'F-15 Eagle','Fighter','McDonnell Dougl...
SELECT * FROM military_equipment WHERE year < 1985;
Display the number of products sourced from each continent.
CREATE TABLE Products (id INT,name VARCHAR(50),type VARCHAR(20),country VARCHAR(50),continent VARCHAR(20)); INSERT INTO Products (id,name,type,country,continent) VALUES (1,'Cleanser','Skincare','Brazil','South America'),(2,'Toner','Skincare','Canada','North America'),(3,'Moisturizer','Skincare','Australia','Australia')...
SELECT continent, COUNT(*) as product_count FROM Products GROUP BY continent;
Calculate the total military equipment sales amount for each region in Q3 2022.
CREATE TABLE MilitaryEquipmentSales (id INT,region VARCHAR(50),amount FLOAT,sale_date DATE); INSERT INTO MilitaryEquipmentSales (id,region,amount,sale_date) VALUES (1,'North America',15000000,'2022-07-10'); INSERT INTO MilitaryEquipmentSales (id,region,amount,sale_date) VALUES (2,'Europe',17000000,'2022-09-01'); INSERT...
SELECT region, SUM(amount) FROM MilitaryEquipmentSales WHERE sale_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY region;
Which organizations have been involved in humanitarian assistance missions in Africa?
CREATE TABLE humanitarian_assistance (org_name VARCHAR(255),mission_location VARCHAR(255));
SELECT org_name FROM humanitarian_assistance WHERE mission_location LIKE '%Africa%';
What is the total number of events and total amount spent on each event, for events in the 'Events' table that have a budget greater than 5000?
CREATE TABLE Events (EventID INT,EventName VARCHAR(50),Budget DECIMAL(10,2));
SELECT EventID, EventName, COUNT(*) AS NumberOfEvents, SUM(Budget) AS TotalAmountSpent FROM Events WHERE Budget > 5000 GROUP BY EventID, EventName;
What is the total number of hospitals and clinics in the 'rural_healthcare' schema?
CREATE TABLE hospitals (id INT,name TEXT,location TEXT,capacity INT); INSERT INTO hospitals (id,name,location,capacity) VALUES (1,'Rural General Hospital','Springfield',100); CREATE TABLE clinics (id INT,name TEXT,location TEXT,capacity INT); INSERT INTO clinics (id,name,location,capacity) VALUES (1,'Rural Community Cl...
SELECT COUNT(*) FROM hospitals UNION SELECT COUNT(*) FROM clinics;
Get menu items that are sourced from vendors with no certifications
CREATE TABLE menu_items (menu_item_id INT PRIMARY KEY,restaurant_id INT,menu_item VARCHAR(255),vendor VARCHAR(255),product VARCHAR(255)); CREATE TABLE orders (order_id INT PRIMARY KEY,menu_item_id INT,order_date DATE);
SELECT m.menu_item, m.vendor FROM menu_items m LEFT JOIN sustainable_sources s ON m.vendor = s.vendor WHERE s.source_id IS NULL;
Which recycling rates are higher: for plastic or for paper, in the 'North East' region?
CREATE TABLE recycling_rates (region VARCHAR(255),material VARCHAR(255),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (region,material,recycling_rate) VALUES ('North East','plastic',0.35),('North East','paper',0.45);
SELECT material, recycling_rate FROM recycling_rates WHERE region = 'North East' AND material IN ('plastic', 'paper') INTERSECT SELECT 'paper' AS material, MAX(recycling_rate) FROM recycling_rates WHERE region = 'North East' UNION ALL SELECT 'plastic' AS material, MAX(recycling_rate) FROM recycling_rates WHERE region =...
What is the most common word used in posts for each user in the social_media database?
CREATE TABLE users (user_id INT PRIMARY KEY,username VARCHAR(255),location VARCHAR(255)); INSERT INTO users (user_id,username,location) VALUES (1,'user1','NYC'),(2,'user2','LA'),(3,'user3','NYC'),(4,'user4','SF');CREATE TABLE posts (post_id INT PRIMARY KEY,user_id INT,content TEXT); INSERT INTO posts (post_id,user_id,c...
SELECT users.username, REGEXP_SPLIT_TO_TABLE(REGEXP_REPLACE(posts.content, 'W+', ' '), ' ') AS word, COUNT(*) AS frequency FROM users INNER JOIN posts ON users.user_id = posts.user_id GROUP BY users.username, word ORDER BY users.username, frequency DESC;
How many bike-share stations in the city of San Francisco have less than 10 bikes available?
CREATE TABLE bikeshare (station_id INT,city VARCHAR(20),num_bikes INT); INSERT INTO bikeshare (station_id,city,num_bikes) VALUES (1,'San Francisco',8),(2,'San Francisco',12),(3,'San Francisco',7);
SELECT COUNT(*) FROM bikeshare WHERE city = 'San Francisco' AND num_bikes < 10;
What is the distribution of player levels in "EpicQuest" for players from historically underrepresented communities, grouped by region?
CREATE TABLE epicquest_underrepresented_players (player_id INT,level INT,region VARCHAR(20),underrepresented_community VARCHAR(20)); INSERT INTO epicquest_underrepresented_players (player_id,level,region,underrepresented_community) VALUES (1,25,'North America','African American'),(2,30,'Europe','Female'),(3,22,'Asia','...
SELECT region, AVG(level) AS avg_level, MIN(level) AS min_level, MAX(level) AS max_level FROM epicquest_underrepresented_players GROUP BY region;
Update the jersey number for player 'Kevin Durant' to 35
CREATE TABLE players (id INT,name VARCHAR(255),jersey_number INT); INSERT INTO players (id,name,jersey_number) VALUES (1,'Kevin Durant',7),(2,'Stephen Curry',30);
UPDATE players SET jersey_number = 35 WHERE name = 'Kevin Durant';
Delete all records from the Claims table that are older than 3 years.
CREATE TABLE Claims (ClaimID INT,PolicyholderName VARCHAR(50),ClaimDate DATE); INSERT INTO Claims VALUES (1,'John Doe','2019-01-01'); INSERT INTO Claims VALUES (2,'Jane Smith','2020-05-05'); INSERT INTO Claims VALUES (3,'John Doe','2021-12-31'); INSERT INTO Claims VALUES (4,'Jim Brown','2018-09-09');
DELETE FROM Claims WHERE ClaimDate < NOW() - INTERVAL '3 years';
What are the names and types of military technology that were updated in the year 2019 in the TECH_UPDATES table?
CREATE TABLE TECH_UPDATES (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),year INT,country VARCHAR(255));
SELECT name, type FROM TECH_UPDATES WHERE year = 2019 AND country = (SELECT country FROM TECH_UPDATES WHERE name = (SELECT MAX(name) FROM TECH_UPDATES WHERE year = 2019) AND type = (SELECT MAX(type) FROM TECH_UPDATES WHERE year = 2019) LIMIT 1);
What are the top 5 countries with the highest CO2 emissions from tourism?
CREATE TABLE tourism_emissions (id INT,country VARCHAR(255),co2_emissions INT,visit_date DATE); INSERT INTO tourism_emissions (id,country,co2_emissions,visit_date) VALUES (1,'United States',5000,'2022-01-01'),(2,'China',4000,'2022-03-15'),(3,'India',3000,'2022-06-01'),(4,'Russia',2500,'2022-04-01'),(5,'Germany',2000,'2...
SELECT country, SUM(co2_emissions) FROM tourism_emissions WHERE visit_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY country ORDER BY SUM(co2_emissions) DESC LIMIT 5;
What is the maximum carbon offset per project in the carbon offset program in Canada?
CREATE TABLE carbon_offset_programs (id INT,country VARCHAR(255),project VARCHAR(255),carbon_offsets INT); INSERT INTO carbon_offset_programs (id,country,project,carbon_offsets) VALUES (1,'Canada','Project A',2000),(2,'Canada','Project B',2500),(3,'Canada','Project C',3000);
SELECT MAX(carbon_offsets) FROM carbon_offset_programs WHERE country = 'Canada';
What are the names of the chemicals that are produced in both 'Alabama' and 'Louisiana' but not in 'Mississippi'?
CREATE TABLE Chemical_Plant (plant_name VARCHAR(255),location VARCHAR(255),chemical VARCHAR(255),quantity INT);INSERT INTO Chemical_Plant (plant_name,location,chemical,quantity) VALUES ('Chemical Plant I','Alabama','Phosphoric Acid',700),('Chemical Plant J','Alabama','Nitric Acid',800),('Chemical Plant K','Louisiana','...
SELECT chemical FROM Chemical_Plant WHERE location = 'Alabama' INTERSECT SELECT chemical FROM Chemical_Plant WHERE location = 'Louisiana' EXCEPT SELECT chemical FROM Chemical_Plant WHERE location = 'Mississippi';
What is the average speed of spacecraft in the "space_exploration" table, grouped by mission type?
CREATE TABLE space_exploration (mission_name VARCHAR(50),mission_type VARCHAR(50),launch_date DATE,max_speed NUMERIC(8,2)); INSERT INTO space_exploration (mission_name,mission_type,launch_date,max_speed) VALUES ('Voyager 1','Flyby','1977-09-05',61000),('Voyager 2','Flyby','1977-08-20',57000),('Cassini','Orbiter','1997-...
SELECT mission_type, AVG(max_speed) OVER (PARTITION BY mission_type) AS avg_speed FROM space_exploration;
What is the total number of shipments that were handled by the 'Montreal' warehouse?
CREATE TABLE Warehouse (id INT,name VARCHAR(20),city VARCHAR(20)); INSERT INTO Warehouse (id,name,city) VALUES (1,'Chicago','Chicago'),(2,'Montreal','Montreal'); CREATE TABLE Handling (id INT,shipment_id INT,warehouse_id INT,pallets INT); INSERT INTO Handling (id,shipment_id,warehouse_id,pallets) VALUES (1,101,2,500),(...
SELECT COUNT(*) FROM Handling JOIN Warehouse ON Handling.warehouse_id = Warehouse.id WHERE Warehouse.city = 'Montreal';
What is the average transaction amount for customers living in Texas?
CREATE TABLE customers (customer_id INT,name TEXT,state TEXT,transaction_amount DECIMAL); INSERT INTO customers (customer_id,name,state,transaction_amount) VALUES (1,'John Doe','Texas',50.00),(2,'Jane Smith','California',100.00);
SELECT AVG(transaction_amount) FROM customers WHERE state = 'Texas';
List the auto show events that are not happening in 2023.
CREATE TABLE AutoShows (name VARCHAR(20),year INT); INSERT INTO AutoShows (name,year) VALUES ('Tokyo Auto Salon',2023); INSERT INTO AutoShows (name,year) VALUES ('Paris Motor Show',2022);
SELECT name FROM AutoShows WHERE year != 2023;
What is the average energy efficiency rating for renewable energy projects in the state of Washington?
CREATE TABLE Projects (project_id INT,project_name VARCHAR(100),state VARCHAR(100),energy_efficiency_rating FLOAT);
SELECT AVG(energy_efficiency_rating) FROM Projects WHERE state = 'Washington';
How many 'Urban Development' initiatives were inserted into the database in Q2 of 2021?
CREATE TABLE Initiatives (Initiative VARCHAR(50),Department VARCHAR(50),InsertDate DATE); INSERT INTO Initiatives (Initiative,Department,InsertDate) VALUES ('New Park','Urban Development','2021-04-05'),('Traffic Light Upgrade','Urban Development','2021-06-12'),('Waste Management Plan','Urban Development','2021-03-20');
SELECT COUNT(*) FROM Initiatives WHERE Department = 'Urban Development' AND InsertDate >= '2021-04-01' AND InsertDate < '2021-07-01';
Determine the number of disability support requests received in each quarter of the year, for the past 2 years.
CREATE TABLE Request (RequestID INT,RequestDate DATE,City VARCHAR(50),RequestType VARCHAR(50)); INSERT INTO Request (RequestID,RequestDate,City,RequestType) VALUES (1,'2021-01-01','San Francisco','Disability Support'); INSERT INTO Request (RequestID,RequestDate,City,RequestType) VALUES (2,'2021-02-15','New York','Disab...
SELECT DATEPART(YEAR, RequestDate) AS Year, DATEPART(QUARTER, RequestDate) AS Quarter, COUNT(*) AS Requests FROM Request WHERE RequestType = 'Disability Support' AND RequestDate >= DATEADD(YEAR, -2, GETDATE()) GROUP BY DATEPART(YEAR, RequestDate), DATEPART(QUARTER, RequestDate);
What was the total energy consumption for each factory in the past 6 months, ordered from highest to lowest?
CREATE TABLE sustainability_metrics (factory_id INT,energy_consumption FLOAT,measurement_date DATE); INSERT INTO sustainability_metrics (factory_id,energy_consumption,measurement_date) VALUES (1,25000.5,'2021-09-01'),(2,18000.3,'2021-09-01'),(3,22000.0,'2021-02-01');
SELECT factory_id, SUM(energy_consumption) as six_month_energy FROM sustainability_metrics WHERE measurement_date >= DATEADD(month, -6, CURRENT_DATE) GROUP BY factory_id ORDER BY six_month_energy DESC;
What is the average carbon offset for each smart city initiative, broken down by location?
CREATE TABLE carbon_offsets (initiative VARCHAR(50),location VARCHAR(50),carbon_offset INT); INSERT INTO carbon_offsets (initiative,location,carbon_offset) VALUES ('Smart Grid','Seattle',1000),('Smart Grid','Portland',1200),('Smart Transit','Seattle',1500),('Smart Transit','Portland',1800);
SELECT initiative, location, AVG(carbon_offset) FROM carbon_offsets GROUP BY initiative, location;
What is the total waste generated by each ethical fashion brand in the past year, and what percentage of it is recycled?
CREATE TABLE EthicalBrands (id INT,brand VARCHAR,waste_kg INT); CREATE TABLE BrandWasteData (brand VARCHAR,year INT,waste_kg INT,is_recycled BOOLEAN);
SELECT e.brand, SUM(e.waste_kg) as total_waste, 100.0 * AVG(CAST(bw.is_recycled AS FLOAT)) as recycled_percentage FROM EthicalBrands e JOIN BrandWasteData bw ON e.brand = bw.brand WHERE bw.year = YEAR(CURRENT_DATE()) - 1 GROUP BY e.brand;
Show the percentage of female fans who purchased season tickets
CREATE TABLE fan_gender (fan_id INT,gender VARCHAR(10),ticket_type VARCHAR(10));
SELECT ((SUM(CASE WHEN gender = 'female' THEN 1 ELSE 0 END) / COUNT(*)) * 100) AS percentage FROM fan_gender WHERE ticket_type = 'season';
What is the average age of rural male patients with diabetes?
CREATE TABLE Patients (PatientID INT,Age INT,Gender VARCHAR(10),Rural BOOLEAN,Disease VARCHAR(20)); INSERT INTO Patients (PatientID,Age,Gender,Rural,Disease) VALUES (1,34,'Male',TRUE,'Diabetes'),(2,55,'Female',FALSE,'Diabetes');
SELECT AVG(Age) FROM Patients WHERE Rural = TRUE AND Gender = 'Male' AND Disease = 'Diabetes';
How many support programs were offered in the "Midwest" region in 2019?
CREATE TABLE Support_Programs (program_id INT,region VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO Support_Programs (program_id,region,start_date,end_date) VALUES (1,'Midwest','2019-01-01','2019-12-31'),(2,'Northeast','2018-12-01','2020-01-01');
SELECT COUNT(*) FROM Support_Programs WHERE region = 'Midwest' AND EXTRACT(YEAR FROM start_date) = 2019 AND EXTRACT(YEAR FROM end_date) = 2019;
What are the top 5 cities with the highest average ticket sales for home games across all teams?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50),city VARCHAR(50)); INSERT INTO teams (team_id,team_name,city) VALUES (1,'Atlanta Hawks','Atlanta'); INSERT INTO teams (team_id,team_name,city) VALUES (2,'Boston Celtics','Boston');
SELECT city, AVG(ticket_sales) as avg_ticket_sales FROM games JOIN teams ON games.team_id = teams.team_id GROUP BY city ORDER BY avg_ticket_sales DESC LIMIT 5;
What is the average age of vessels in the registry?
CREATE TABLE Vessels (VesselID INT,Name TEXT,Type TEXT,YearBuilt INT); INSERT INTO Vessels VALUES (1,'Tanker 1','Oil Tanker',2000),(2,'Cargo Ship 1','Cargo Ship',2010);
SELECT AVG(YEAR(CURRENT_DATE) - Vessels.YearBuilt) FROM Vessels;
List the top 3 menu items by revenue for each restaurant in Q1 2022.
CREATE TABLE menu_engineering (menu_item_id INT,menu_item_name VARCHAR(255),restaurant_id INT,revenue DECIMAL(10,2),transaction_date DATE); INSERT INTO menu_engineering (menu_item_id,menu_item_name,restaurant_id,revenue,transaction_date) VALUES (1,'Margherita Pizza',1,3000,'2022-01-01'),(2,'Guacamole',2,1500,'2022-01-0...
SELECT restaurant_id, menu_item_name, SUM(revenue) as total_revenue FROM menu_engineering WHERE transaction_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY restaurant_id, menu_item_name HAVING COUNT(*) <= 3 ORDER BY restaurant_id, total_revenue DESC;
What is the number of electric vehicle charging stations in each city in Germany?
CREATE TABLE ChargingStations(id INT,city VARCHAR(20),state VARCHAR(20),quantity INT);
SELECT city, COUNT(*) as quantity FROM ChargingStations WHERE state = 'Germany' GROUP BY city ORDER BY quantity DESC;
How many electric vehicle charging stations were installed in New York and Los Angeles before 2020?
CREATE TABLE charging_stations (id INT,city VARCHAR(255),year INT,num_stations INT); INSERT INTO charging_stations (id,city,year,num_stations) VALUES (1,'New York',2018,300),(2,'Los Angeles',2019,400);
SELECT SUM(num_stations) FROM charging_stations WHERE city IN ('New York', 'Los Angeles') AND year < 2020;
List all unions that have increased their membership by more than 10% since 2019, sorted by the percentage increase.
CREATE TABLE Union_Membership (Union_Name VARCHAR(255),Members_2019 INT,Members_2020 INT); INSERT INTO Union_Membership (Union_Name,Members_2019,Members_2020) VALUES ('UnionA',5000,5500),('UnionB',6000,6200),('UnionC',4500,4000);
SELECT Union_Name, ((Members_2020 - Members_2019) * 100.0 / Members_2019) as Percentage_Increase FROM Union_Membership WHERE ((Members_2020 - Members_2019) * 100.0 / Members_2019) > 10 ORDER BY Percentage_Increase DESC;
What is the daily waste generation for the top 5 municipalities with the highest population?
CREATE TABLE municipalities (id INT,name VARCHAR(255),population INT); INSERT INTO municipalities (id,name,population) VALUES (1,'CityA',50000),(2,'CityB',75000),(3,'CityC',100000),(4,'CityD',125000),(5,'CityE',150000),(6,'CityF',175000),(7,'CityG',200000); CREATE TABLE waste_generation (municipality_id INT,date DATE,g...
SELECT municipality_id, date, generation FROM (SELECT municipality_id, date, generation, ROW_NUMBER() OVER (PARTITION BY municipality_id ORDER BY generation DESC) as rn FROM waste_generation) t WHERE rn <= 5;
What is the minimum investment required for any project in the EMEA region?
CREATE TABLE projects_emea (id INT,region VARCHAR(50),investment FLOAT); INSERT INTO projects_emea (id,region,investment) VALUES (1,'EMEA',500000); INSERT INTO projects_emea (id,region,investment) VALUES (2,'EMEA',750000);
SELECT MIN(investment) FROM projects_emea WHERE region = 'EMEA';
What is the total duration of all documentaries about Indigenous cultures?
CREATE TABLE documentaries (id INT,title VARCHAR(255),duration INT,topic VARCHAR(255)); INSERT INTO documentaries (id,title,duration,topic) VALUES (1,'Doc1',90,'Indigenous Culture'),(2,'Doc2',120,'Nature'),(3,'Doc3',100,'Indigenous Culture');
SELECT SUM(duration) FROM documentaries WHERE topic = 'Indigenous Culture';
What is the average income of clients who have won cases, grouped by their respective attorneys?
CREATE TABLE Clients (ClientID INT,Age INT,Gender VARCHAR(10),Income FLOAT,WonCase BOOLEAN); CREATE TABLE Attorneys (AttorneyID INT,Name VARCHAR(50));
SELECT A.Name, AVG(C.Income) AS AverageIncome FROM Clients C INNER JOIN Attorneys A ON C.AttorneyID = A.AttorneyID WHERE C.WonCase = TRUE GROUP BY A.Name;
What is the total revenue of fair trade products?
CREATE TABLE Products (ProductID INT,ProductName TEXT,Price DECIMAL,FairTrade BOOLEAN,QuantitySold INT); INSERT INTO Products (ProductID,ProductName,Price,FairTrade,QuantitySold) VALUES (1,'Product1',15.99,true,10),(2,'Product2',12.49,false,20),(3,'Product3',20.99,true,15),(4,'Product4',10.99,false,5);
SELECT SUM(Price * QuantitySold) FROM Products WHERE FairTrade = true;
What is the total revenue for each service in the first quarter of 2023?
CREATE TABLE revenue (service text,date date,amount int); INSERT INTO revenue (service,date,amount) VALUES ('subway','2023-01-01',5000),('bus','2023-01-02',6000),('subway','2023-02-01',7000),('bus','2023-02-02',8000),('subway','2023-03-01',9000),('bus','2023-03-02',10000);
SELECT service, SUM(amount) FROM revenue WHERE date BETWEEN '2023-01-01' AND '2023-03-31' GROUP BY service;
What is the total revenue generated from sponsored posts in the gaming category?
CREATE TABLE sponsored_posts (id INT,category VARCHAR(50),revenue FLOAT); INSERT INTO sponsored_posts (id,category,revenue) VALUES (1,'gaming',100.50),(2,'sports',150.25),(3,'gaming',200.75);
SELECT SUM(revenue) FROM sponsored_posts WHERE category = 'gaming';
Delete companies that have not reported diversity metrics and have no investments.
CREATE TABLE Companies (id INT,name TEXT,diversity_reported INT); INSERT INTO Companies (id,name,diversity_reported) VALUES (1,'Tech Start',1),(2,'Green Visions',0); CREATE TABLE Investment_Rounds (id INT,company_name TEXT); INSERT INTO Investment_Rounds (id,company_name) VALUES (1,'Tech Start');
DELETE FROM Companies WHERE diversity_reported = 0 AND id NOT IN (SELECT company_name FROM Investment_Rounds);
Who are the lead researchers for the neurological disorder related projects?
CREATE SCHEMA if not exists genetic_research;CREATE TABLE if not exists genetic_research.projects(id INT,name TEXT,lead_researcher TEXT,disease_category TEXT);INSERT INTO genetic_research.projects (id,name,lead_researcher,disease_category) VALUES (1,'ProjectX','Dr. Jane Smith','Cancer'),(2,'ProjectY','Dr. John Doe','Ne...
SELECT lead_researcher FROM genetic_research.projects WHERE disease_category = 'Neurological Disorders';
Which city has the highest number of shared bicycles?
CREATE TABLE public.shared_mobility(id serial PRIMARY KEY,city varchar(255),mode varchar(255),num_vehicles int);
SELECT city, MAX(num_vehicles) FROM public.shared_mobility WHERE mode = 'Bicycle' GROUP BY city;
What is the total CO2 emissions for makeup products by country?
CREATE TABLE countries (country_id INT,country_name VARCHAR(255)); CREATE TABLE products (product_id INT,product_name VARCHAR(255),country_id INT,co2_emissions INT);
SELECT c.country_name, SUM(p.co2_emissions) as total_co2_emissions FROM countries c INNER JOIN products p ON c.country_id = p.country_id WHERE p.product_name LIKE '%makeup%' GROUP BY c.country_name;
What is the total number of users who have posted a message containing the word 'vote' in the last week, broken down by region?
CREATE TABLE posts (id INT,user_id INT,post TEXT,date DATE); INSERT INTO posts (id,user_id,post,date) VALUES (1,1,'I am going to vote today','2022-03-23'),(2,2,'I voted yesterday','2022-03-24'),(3,3,'I will vote next week','2022-03-25'); CREATE TABLE users (id INT,region VARCHAR(255)); INSERT INTO users (id,region) VAL...
SELECT COUNT(DISTINCT user_id) AS users_posted_vote, region FROM posts INNER JOIN users ON posts.user_id = users.id WHERE post LIKE '%vote%' AND date >= DATE(NOW()) - INTERVAL 1 WEEK GROUP BY region;