instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Identify legal technology initiatives and their respective countries, excluding those launched before 2010. | CREATE TABLE historical_legal_tech (id INT,initiative VARCHAR(255),launch_date DATE,country VARCHAR(255)); INSERT INTO historical_legal_tech (id,initiative,launch_date,country) VALUES (1,'Legacy AI Platform','2005-02-28','US'),(2,'Traditional Contracts','2000-01-01','Canada'),(3,'Legal Chatbot','2011-08-15','US'); | SELECT initiative, country FROM historical_legal_tech WHERE launch_date >= '2010-01-01' ORDER BY country; |
What is the total number of marine life research stations and pollution control initiatives in the Southern Ocean? | CREATE TABLE marine_life_research_stations (id INT,name VARCHAR(255),region VARCHAR(255)); CREATE TABLE pollution_control_initiatives (id INT,name VARCHAR(255),region VARCHAR(255)); | SELECT SUM(cnt) FROM (SELECT COUNT(*) cnt FROM marine_life_research_stations WHERE region = 'Southern Ocean' UNION ALL SELECT COUNT(*) FROM pollution_control_initiatives WHERE region = 'Southern Ocean') x; |
What is the total quantity of locally sourced ingredients used in dishes? | CREATE TABLE ingredients (ingredient VARCHAR(255),is_local BOOLEAN); INSERT INTO ingredients VALUES ('Carrots',TRUE); INSERT INTO ingredients VALUES ('Celery',FALSE); CREATE TABLE dish_ingredients (ingredient VARCHAR(255),dish VARCHAR(255),quantity INT); INSERT INTO dish_ingredients VALUES ('Carrots','Carrot Soup',5); INSERT INTO dish_ingredients VALUES ('Celery','Chicken Soup',3); | SELECT SUM(quantity) AS total_local_ingredients FROM dish_ingredients DI INNER JOIN ingredients I ON DI.ingredient = I.ingredient WHERE I.is_local = TRUE; |
What is the geopolitical risk level for 'Country Y' in 2021? | CREATE TABLE geopolitical_risks_2 (country varchar(255),year int,risk_level int); INSERT INTO geopolitical_risks_2 (country,year,risk_level) VALUES ('Country X',2022,3),('Country X',2021,2),('Country Y',2021,5); | SELECT risk_level FROM geopolitical_risks_2 WHERE country = 'Country Y' AND year = 2021; |
How many mobile customers in the telecom company's database live in each city? | CREATE TABLE mobile_customers (customer_id INT,city VARCHAR(20)); INSERT INTO mobile_customers (customer_id,city) VALUES (1,'Seattle'),(2,'Seattle'),(3,'Portland'); | SELECT city, COUNT(*) FROM mobile_customers GROUP BY city; |
How many unique sources are there in the 'investigative_journalism' category? | CREATE TABLE articles (article_id INT,title VARCHAR(50),category VARCHAR(20),source VARCHAR(20)); INSERT INTO articles (article_id,title,category,source) VALUES (1,'Investigative Article 1','investigative_journalism','Source A'),(2,'Investigative Article 2','investigative_journalism','Source B'),(3,'News Article 1','news','Source A'); | SELECT COUNT(DISTINCT source) FROM articles WHERE category = 'investigative_journalism'; |
What is the difference in ocean acidity levels between the Atlantic and Pacific Oceans? | CREATE TABLE ocean_ph (location TEXT,ph FLOAT); INSERT INTO ocean_ph (location,ph) VALUES ('Atlantic Ocean',8.1),('Pacific Ocean',7.9),('Indian Ocean',8.0),('Southern Ocean',8.1),('North Pacific Ocean',8.2); | SELECT MAX(ph) - MIN(ph) FROM ocean_ph WHERE location IN ('Atlantic Ocean', 'Pacific Ocean'); |
What is the total amount donated by each donor in each country? | CREATE TABLE Donations (DonationID INT,DonorID INT,RecipientID INT,Amount DECIMAL(10,2),Country TEXT); INSERT INTO Donations (DonationID,DonorID,RecipientID,Amount,Country) VALUES (1,1,101,1000.00,'USA'),(2,1,102,2000.00,'Canada'),(3,2,101,500.00,'USA'),(4,3,103,3000.00,'Mexico'); | SELECT DonorName, Country, SUM(Amount) AS TotalDonated FROM Donations GROUP BY DonorName, Country; |
What is the name of the game genre with the most players? | CREATE TABLE player (player_id INT,name VARCHAR(50),age INT,game_genre VARCHAR(20)); INSERT INTO player (player_id,name,age,game_genre) VALUES (1,'John Doe',25,'Racing'); INSERT INTO player (player_id,name,age,game_genre) VALUES (2,'Jane Smith',30,'RPG'); INSERT INTO player (player_id,name,age,game_genre) VALUES (3,'Alice Johnson',35,'Racing'); | SELECT game_genre FROM player GROUP BY game_genre ORDER BY COUNT(*) DESC LIMIT 1; |
Delete records in the 'sensor_data' table where the 'sensor_type' is 'temperature' and the reading is greater than 30 | CREATE TABLE sensor_data (sensor_id INT,sensor_type VARCHAR(20),reading FLOAT,timestamp TIMESTAMP); | DELETE FROM sensor_data WHERE sensor_type = 'temperature' AND reading > 30; |
Update the 'location' column for the 'field' table where 'field_id' is 501 to 'Brazil' | CREATE TABLE field (field_id INT,name VARCHAR(50),location VARCHAR(50)); | UPDATE field SET location = 'Brazil' WHERE field_id = 501; |
Identify cities with the highest citizen feedback ratings and the corresponding number of public services provided in each city. | CREATE TABLE cities (city_id INT,city_name VARCHAR(255),region VARCHAR(255)); CREATE TABLE public_services (service_id INT,service_name VARCHAR(255),city_id INT,rating INT); | SELECT c.city_name, MAX(ps.rating) as max_rating, COUNT(ps.service_id) as num_services FROM cities c JOIN public_services ps ON c.city_id = ps.city_id GROUP BY c.city_name HAVING MAX(ps.rating) >= ALL (SELECT MAX(ps2.rating) FROM public_services ps2 GROUP BY ps2.city_id); |
What is the policy impact on air quality in industrial regions? | CREATE TABLE air_quality (air_quality_id INT,region VARCHAR(20),pollution_level INT); INSERT INTO air_quality (air_quality_id,region,pollution_level) VALUES (1,'North',60),(2,'North',65),(3,'South',40),(4,'South',42),(5,'East',50),(6,'East',55),(7,'West',30),(8,'West',32); CREATE TABLE policies (policy_id INT,region VARCHAR(20),policy_type VARCHAR(20),start_date DATE); INSERT INTO policies (policy_id,region,policy_type,start_date) VALUES (1,'North','Industrial','2015-01-01'),(2,'South','Green','2016-01-01'),(3,'East','Industrial','2017-01-01'),(4,'West','Green','2018-01-01'); | SELECT aq.region, AVG(aq.pollution_level) AS avg_pollution, p.policy_type FROM air_quality aq INNER JOIN policies p ON aq.region = p.region WHERE p.policy_type = 'Industrial' OR p.policy_type = 'Green' GROUP BY aq.region, p.policy_type; |
What is the total budget allocated for education and healthcare services in 2020, for regions with a population over 1 million? | CREATE TABLE regions (id INT,name TEXT,population INT); INSERT INTO regions (id,name,population) VALUES (1,'RegionA',1200000),(2,'RegionB',700000),(3,'RegionC',2000000); CREATE TABLE budget (service TEXT,year INT,amount INT,region_id INT); INSERT INTO budget (service,year,amount,region_id) VALUES ('Education',2020,5000000,1),('Healthcare',2020,7000000,1),('Education',2020,3000000,3),('Healthcare',2020,6000000,3); | SELECT SUM(b.amount) FROM budget b INNER JOIN regions r ON b.region_id = r.id WHERE b.service IN ('Education', 'Healthcare') AND b.year = 2020 AND r.population > 1000000; |
What was the maximum budget allocated for transportation in each region? | CREATE TABLE Budget (region VARCHAR(255),category VARCHAR(255),amount INT); INSERT INTO Budget (region,category,amount) VALUES ('North','Transportation',3000000),('South','Transportation',4000000),('East','Transportation',5000000),('West','Transportation',2000000); | SELECT region, MAX(amount) FROM Budget WHERE category = 'Transportation' GROUP BY region; |
List all Dysprosium transactions with prices over 50 dollars in European countries. | CREATE TABLE dysprosium_transactions (country VARCHAR(20),element VARCHAR(20),price DECIMAL(5,2),transaction_date DATE); INSERT INTO dysprosium_transactions (country,element,price,transaction_date) VALUES ('France','Dysprosium',60,'2020-01-01'),('Germany','Dysprosium',45,'2020-02-01'),('France','Dysprosium',70,'2020-03-01'); | SELECT * FROM dysprosium_transactions WHERE country IN ('France', 'Germany') AND element = 'Dysprosium' AND price > 50; |
What is the minimum size, in square feet, of properties with inclusive housing policies in the city of Washington D.C.? | CREATE TABLE property (id INT,size INT,city VARCHAR(20),inclusive_housing_policy BOOLEAN); | SELECT MIN(size) FROM property WHERE city = 'Washington D.C.' AND inclusive_housing_policy = TRUE; |
What is the average CO2 emission (in metric tons) for the top 5 most populous countries in Africa? | CREATE TABLE co2_emissions (country VARCHAR(100),population INT,co2_emissions FLOAT); INSERT INTO co2_emissions (country,population,co2_emissions) VALUES ('Nigeria',206 million,5.2),('Egypt',102 million,3.2),('South Africa',59 million,9.4),('Ethiopia',115 million,0.7),('Kenya',53 million,1.3); | SELECT AVG(co2_emissions) FROM (SELECT co2_emissions FROM co2_emissions WHERE country IN ('Nigeria', 'Egypt', 'South Africa', 'Ethiopia', 'Kenya') ORDER BY population DESC LIMIT 5) subquery; |
Determine the percentage of sales for each product category in each state | CREATE TABLE sales (sale_id INT,product_id INT,product_category VARCHAR(255),sales FLOAT,state VARCHAR(255)); INSERT INTO sales (sale_id,product_id,product_category,sales,state) VALUES (1,1,'Electronics',100,'WA'),(2,2,'Clothing',200,'NY'),(3,3,'Electronics',150,'CA'); | SELECT s1.product_category, s1.state, SUM(s1.sales) / (SELECT SUM(s2.sales) FROM sales s2 WHERE s2.state = s1.state) FROM sales s1 GROUP BY s1.product_category, s1.state; |
Which spacecraft have been used in the most missions? | CREATE TABLE spacecraft (craft_name VARCHAR(50),manufacturer VARCHAR(50),first_flight DATE,total_flights INT); | SELECT craft_name, total_flights FROM spacecraft ORDER BY total_flights DESC LIMIT 5; |
Delete all records from the 'fan_demographics' table where the location is 'Texas' | CREATE TABLE fan_demographics (age INT,gender VARCHAR(10),location VARCHAR(20)); INSERT INTO fan_demographics (age,gender,location) VALUES (35,'Female','California'),(28,'Male','Texas'); | DELETE FROM fan_demographics WHERE location = 'Texas'; |
What is the total revenue for VR headset ticket sales by team, per month? | CREATE TABLE ticket_sales (ticket_sale_id INT,team_id INT,sale_quarter INT,sale_year INT,quantity INT,is_vr BOOLEAN); CREATE TABLE teams (team_id INT,team_name VARCHAR(255),sport_id INT); INSERT INTO ticket_sales VALUES (1,101,1,2020,500,true),(2,102,2,2020,750,false),(3,101,3,2020,800,true),(4,103,4,2020,600,false); INSERT INTO teams VALUES (101,'TeamA',1),(102,'TeamB',2),(103,'TeamC',1); | SELECT t.team_name, DATE_TRUNC('month', make_date(sale_year, sale_quarter*3, 1)) as sale_month, SUM(quantity * CASE WHEN is_vr THEN 200 ELSE 100 END) as total_revenue FROM ticket_sales ts JOIN teams t ON ts.team_id = t.team_id GROUP BY t.team_name, sale_month; |
Find the total number of unique IP addresses involved in ransomware and phishing attacks in the last six months, excluding any repeat offenders. | CREATE TABLE attack_ips (ip_address TEXT,attack_type TEXT,occurrence_count INT,last_updated DATETIME);INSERT INTO attack_ips (ip_address,attack_type,occurrence_count,last_updated) VALUES ('192.168.0.1','Ransomware',2,'2022-03-01 10:00:00'),('192.168.0.2','Phishing',1,'2022-03-02 11:00:00'),('192.168.0.3','Ransomware',3,'2022-03-03 12:00:00'),('192.168.0.4','Phishing',4,'2022-03-04 13:00:00'),('192.168.0.5','Ransomware',1,'2022-03-05 14:00:00'); | SELECT ip_address FROM attack_ips WHERE attack_type IN ('Ransomware', 'Phishing') AND last_updated >= DATEADD(month, -6, GETDATE()) GROUP BY ip_address HAVING COUNT(*) = 1; |
What is the average CO2 emission of public buses in Los Angeles and London? | CREATE TABLE public_buses(id INT,make VARCHAR(20),model VARCHAR(20),city VARCHAR(20),co2_emission FLOAT); | SELECT AVG(co2_emission) FROM public_buses WHERE city IN ('Los Angeles', 'London'); |
What is the total quantity of 'Tencel Lyocell' and 'Bamboo Viscose' fabrics in stock? | CREATE TABLE inventory (id INT PRIMARY KEY,fabric_name VARCHAR(50),size VARCHAR(10),quantity INT,color VARCHAR(10)); INSERT INTO inventory (id,fabric_name,size,quantity,color) VALUES (1,'Organic Cotton','S',100,'White'); INSERT INTO inventory (id,fabric_name,size,quantity,color) VALUES (2,'Tencel Lyocell','M',75,'Green'); INSERT INTO inventory (id,fabric_name,size,quantity,color) VALUES (3,'Bamboo Viscose','L',50,'Natural'); | SELECT SUM(quantity) as total_quantity FROM inventory WHERE fabric_name IN ('Tencel Lyocell', 'Bamboo Viscose'); |
What is the average number of union members per workplace in the healthcare sector? | CREATE TABLE workplaces (id INT,name TEXT,location TEXT,sector TEXT,total_employees INT,union_members INT,successful_cb BOOLEAN,cb_year INT); | SELECT AVG(union_members / total_employees) FROM workplaces WHERE sector = 'healthcare'; |
What is the total number of auto shows attended by each manufacturer? | CREATE TABLE Auto_Shows (id INT,manufacturer VARCHAR(50),show_name VARCHAR(50),year INT); CREATE TABLE Manufacturers (id INT,name VARCHAR(50)); | SELECT Manufacturers.name, COUNT(DISTINCT Auto_Shows.show_name) FROM Auto_Shows JOIN Manufacturers ON Auto_Shows.manufacturer = Manufacturers.name GROUP BY Manufacturers.name; |
What is the total number of electric vehicles sold in 'California' in the 'sales' schema? | CREATE TABLE sales_regions (id INT,name VARCHAR(50)); CREATE TABLE sales (id INT,region_id INT,vehicle_count INT); CREATE TABLE vehicles (id INT,type VARCHAR(50)); INSERT INTO sales_regions VALUES (1,'California'); INSERT INTO sales VALUES (1,1,5000); INSERT INTO vehicles VALUES (1,'electric'); | SELECT SUM(sales.vehicle_count) FROM sales INNER JOIN sales_regions ON sales.region_id = sales_regions.id INNER JOIN vehicles ON sales.id = vehicles.id WHERE vehicles.type = 'electric' AND sales_regions.name = 'California'; |
How many vessels have not had an inspection in the past year? | CREATE TABLE safety_records(id INT,vessel_name VARCHAR(50),inspection_date DATE); CREATE TABLE vessels(id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO vessels(id,name,country) VALUES (1,'Vessel A','Philippines'),(2,'Vessel B','Philippines'); INSERT INTO safety_records(id,vessel_name,inspection_date) VALUES (1,'Vessel A','2022-01-01'); | SELECT COUNT(*) FROM vessels WHERE name NOT IN (SELECT vessel_name FROM safety_records WHERE inspection_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW()); |
Which states have a landfill tipping fee greater than $60? | CREATE TABLE landfill (state VARCHAR(2),tipping_fee DECIMAL(5,2)); INSERT INTO landfill (state,tipping_fee) VALUES ('NY',65.30),('NJ',71.50),('CA',51.75); | SELECT state, AVG(tipping_fee) as avg_tipping_fee FROM landfill GROUP BY state HAVING avg_tipping_fee > 60; |
Calculate the average daily water consumption in 'DailyWaterUsage' table for the month of January | CREATE TABLE DailyWaterUsage (day DATE,usage INT,month DATE); | SELECT AVG(usage) FROM DailyWaterUsage WHERE month = '2022-01-01'::DATE; |
Update records in the 'creative_applications' table where the 'application_name' is 'AI Poet' and the 'user_rating' is less than 4 | CREATE TABLE creative_applications (id INT PRIMARY KEY,application_name VARCHAR(50),art_form VARCHAR(20),num_users INT,user_rating INT); | UPDATE creative_applications SET user_rating = user_rating + 2 WHERE application_name = 'AI Poet' AND user_rating < 4; |
What is the number of agricultural innovation patents filed by each organization? | CREATE TABLE innovation_patents (org VARCHAR(50),patent_count INT); INSERT INTO innovation_patents (org,patent_count) VALUES ('Agritech Inc.',15),('FarmMate',20),('GreenFields',25); | SELECT org, patent_count FROM innovation_patents; |
What is the percentage of accidents for each aircraft model? | CREATE SCHEMA if not exists aerospace;CREATE TABLE if not exists aerospace.aircraft (id INT PRIMARY KEY,name VARCHAR(50),model VARCHAR(50),accidents INT); INSERT INTO aerospace.aircraft (id,name,model,accidents) VALUES (1,'Boeing','737',3),(2,'Boeing','747',2),(3,'Airbus','A320',6); | SELECT model, (SUM(accidents) OVER (PARTITION BY model) * 100.0 / (SELECT SUM(accidents) FROM aerospace.aircraft)) as accident_percentage FROM aerospace.aircraft; |
Delete the 'Forest Friends' program record in the 'education_programs' table | CREATE TABLE education_programs (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),attendance INT,target_audience VARCHAR(50)); | DELETE FROM education_programs WHERE name = 'Forest Friends'; |
Determine the total population of each animal | CREATE TABLE if not exists animal_population (id INT,animal VARCHAR(255),country VARCHAR(255),population INT); INSERT INTO animal_population (id,animal,country,population) VALUES (1,'Tiger','India',2500),(2,'Tiger','Bangladesh',150),(3,'Elephant','India',5000),(4,'Elephant','Sri Lanka',2500); | SELECT animal, SUM(population) FROM animal_population GROUP BY animal; |
Find the total population of each animal species in the reserve, ordered by total population in descending order. | CREATE TABLE animal_population (species VARCHAR(255),reserve VARCHAR(255),population INT); INSERT INTO animal_population (species,reserve,population) VALUES ('Tiger','Bandhavgarh',63),('Lion','Savuti',50),('Elephant','Kruger',250); | SELECT species, SUM(population) AS total_population FROM animal_population GROUP BY species ORDER BY total_population DESC; |
What is the maximum feeding rate by feed type and farm size? | CREATE TABLE Feed (id INT PRIMARY KEY,type VARCHAR(50)); CREATE TABLE Farm (id INT PRIMARY KEY,feed_id INT,size INT,FOREIGN KEY (feed_id) REFERENCES Feed(id)); CREATE TABLE FeedingRate (farm_id INT,feed_id INT,rate INT,FOREIGN KEY (farm_id) REFERENCES Farm(id),FOREIGN KEY (feed_id) REFERENCES Feed(id)); | SELECT Feed.type, Farm.size, MAX(FeedingRate.rate) FROM Feed INNER JOIN FeedingRate ON Feed.id = FeedingRate.feed_id INNER JOIN Farm ON FeedingRate.farm_id = Farm.id GROUP BY Feed.type, Farm.size; |
What is the total biomass of fish in each farming region? | CREATE TABLE FarmingRegions (RegionID INT,RegionName VARCHAR(50),Biomass INT); INSERT INTO FarmingRegions VALUES (1,'Atlantic Coast',1200),(2,'Gulf Coast',1800),(3,'Pacific Coast',2500); | SELECT RegionName, SUM(Biomass) FROM FarmingRegions GROUP BY RegionName; |
Determine the percentage of funding for each program | CREATE TABLE program_funding (program_id INT,amount DECIMAL(10,2)); INSERT INTO program_funding (program_id,amount) VALUES (1,5000.00),(2,7000.00),(3,3000.00); | SELECT p.name, (SUM(f.amount)/(SELECT SUM(amount) FROM program_funding))*100 AS percentage FROM program_funding f JOIN programs p ON f.program_id = p.id GROUP BY p.id; |
How many dance performances had more than 50 attendees? | CREATE TABLE dance (id INT,num_attendees INT); INSERT INTO dance (id,num_attendees) VALUES (1,40),(2,60),(3,30),(4,70),(5,20); | SELECT COUNT(*) FROM dance WHERE num_attendees > 50; |
What is the total funding received by dance programs in urban areas? | CREATE SCHEMA if not exists arts_culture; CREATE TABLE if not exists arts_culture.programs(program_id INT,program_name VARCHAR(50),location VARCHAR(20),category VARCHAR(20)); CREATE TABLE if not exists arts_culture.funding(funding_id INT,program_id INT,amount INT); | SELECT SUM(funding.amount) FROM arts_culture.funding JOIN arts_culture.programs ON funding.program_id = programs.program_id WHERE programs.location = 'urban' AND programs.category = 'dance'; |
Insert a new TV show into the database? | CREATE TABLE tv_shows (id INT,title VARCHAR(100),genre VARCHAR(50),viewership INT); | INSERT INTO tv_shows (id, title, genre, viewership) VALUES (4, 'Show7', 'Crime', 5000000); |
Delete records from the 'communication_campaigns' table where the 'start_date' is before 2010-01-01 | CREATE TABLE communication_campaigns (id INT,campaign VARCHAR(255),start_date DATE,end_date DATE); | DELETE FROM communication_campaigns WHERE start_date < '2010-01-01'; |
How many climate communication projects were initiated before 2018 in the European region? | CREATE TABLE climate_communication_projects (project_id INT,project_name VARCHAR(255),start_year INT,region VARCHAR(255)); INSERT INTO climate_communication_projects (project_id,project_name,start_year,region) VALUES (1,'European Climate Change Awareness Campaign',2014,'Europe'),(2,'Global Warming Education Program',2017,'Global'); | SELECT COUNT(*) FROM climate_communication_projects WHERE start_year < 2018 AND region = 'Europe'; |
Update the 'infection_rates' table with new data | CREATE TABLE infection_rates (id INT PRIMARY KEY,state VARCHAR(50),infection_rate FLOAT); INSERT INTO infection_rates (id,state,infection_rate) VALUES (1,'Texas',5.6); | UPDATE infection_rates SET infection_rate = 5.7 WHERE state = 'Texas'; |
What is the obesity prevalence in Australia? | CREATE TABLE countries (id INT PRIMARY KEY,name VARCHAR(255),continent VARCHAR(255)); INSERT INTO countries (id,name,continent) VALUES (1,'Afghanistan','Asia'); CREATE TABLE health_metrics (id INT PRIMARY KEY,country_id INT,metric_type VARCHAR(255),metric_value DECIMAL(3,2)); INSERT INTO health_metrics (id,country_id,metric_type,metric_value) VALUES (1,1,'Obesity Prevalence',32.5),(2,1,'Diabetes Prevalence',12.0); | SELECT metric_value FROM health_metrics WHERE metric_type = 'Obesity Prevalence' AND country_id = (SELECT id FROM countries WHERE name = 'Australia'); |
What is the average diversity metric for companies founded in the same year as the company with the highest funding amount? | CREATE TABLE companies (id INT,name TEXT,founding_date DATE,diversity_metric FLOAT); INSERT INTO companies (id,name,founding_date,diversity_metric) VALUES (1,'InnoVentures','2012-01-01',0.75); | SELECT AVG(diversity_metric) FROM companies WHERE YEAR(founding_date) = (SELECT YEAR(founding_date) FROM companies WHERE funding_amount = (SELECT MAX(funding_amount) FROM funding_records JOIN companies ON funding_records.company_id = companies.id)); |
What is the total area of farmland for each crop type? | CREATE TABLE crop (id INT PRIMARY KEY,name VARCHAR(50),area_in_hectares INT); INSERT INTO crop (id,name,area_in_hectares) VALUES (1,'Corn',30000),(2,'Soybeans',25000),(3,'Wheat',20000); | SELECT name, SUM(area_in_hectares) FROM crop GROUP BY name; |
Which farmers are located in Asia? | CREATE TABLE Farmers (id INT,name VARCHAR(50),location VARCHAR(50),expertise VARCHAR(50)); INSERT INTO Farmers (id,name,location,expertise) VALUES (1,'Bella Chen','Asia','Rice Farming'); | SELECT * FROM Farmers WHERE location = 'Asia'; |
What is the average disability accommodation cost per program by state, ordered from highest to lowest? | CREATE TABLE Disability_Accommodations (State VARCHAR(2),Program VARCHAR(50),Cost DECIMAL(5,2)); INSERT INTO Disability_Accommodations VALUES ('CA','ASL Interpretation',1500.00),('CA','Wheelchair Ramp',3500.00),('NY','ASL Interpretation',1200.00),('NY','Wheelchair Ramp',3200.00); | SELECT AVG(Cost) as Avg_Cost, State FROM Disability_Accommodations GROUP BY State ORDER BY Avg_Cost DESC; |
What is the regulatory status of digital assets that have been involved in more than 1000 transactions? | CREATE TABLE digital_assets_regulatory (asset_id INT,asset_name VARCHAR(50),network VARCHAR(10),status VARCHAR(20)); INSERT INTO digital_assets_regulatory (asset_id,asset_name,network,status) VALUES (1,'ETH','ETH','Unregulated'); CREATE TABLE transactions (transaction_id INT,asset_id INT,block_number INT); | SELECT d.asset_name, d.status FROM digital_assets_regulatory d JOIN (SELECT asset_id, COUNT(transaction_id) as transaction_count FROM transactions GROUP BY asset_id) t ON d.asset_id = t.asset_id WHERE t.transaction_count > 1000; |
What is the minimum age of a tree in the Trees table? | CREATE TABLE Trees (id INT,species VARCHAR(255),age INT); INSERT INTO Trees (id,species,age) VALUES (1,'Oak',50),(2,'Pine',30),(3,'Maple',40); | SELECT MIN(age) FROM Trees; |
What is the total revenue of organic cosmetics sold in the UK in Q3 2021? | CREATE TABLE Cosmetics_Sales (SaleID int,ProductName varchar(100),SaleDate date,QuantitySold int,Price decimal(5,2),Organic bit); INSERT INTO Cosmetics_Sales (SaleID,ProductName,SaleDate,QuantitySold,Price,Organic) VALUES (1,'Organic Lip Balm','2021-07-05',100,4.50,1); INSERT INTO Cosmetics_Sales (SaleID,ProductName,SaleDate,QuantitySold,Price,Organic) VALUES (2,'Natural Skin Cream','2021-10-10',200,12.99,1); | SELECT SUM(QuantitySold * Price) FROM Cosmetics_Sales WHERE Organic = 1 AND SaleDate >= '2021-07-01' AND SaleDate <= '2021-09-30'; |
What is the total sales revenue of organic skincare products? | CREATE TABLE SkincareSales (product_id INT,product_name VARCHAR(100),category VARCHAR(50),price DECIMAL(10,2),revenue DECIMAL(10,2),is_organic BOOLEAN); | SELECT SUM(revenue) FROM SkincareSales WHERE is_organic = TRUE; |
What is the total number of emergency incidents by type in 2022 in Portland?" | CREATE TABLE emergency_incidents (id INT,type VARCHAR(255),city VARCHAR(255),incident_date DATE); INSERT INTO emergency_incidents (id,type,city,incident_date) VALUES (1,'Medical','Portland','2022-01-01'); | SELECT type, COUNT(*) as total FROM emergency_incidents WHERE city = 'Portland' AND incident_date >= '2022-01-01' AND incident_date < '2023-01-01' GROUP BY type; |
How many clients have a compliance status of 'Non-compliant'? | CREATE TABLE regulatory_compliance (client_id INT,compliance_status VARCHAR(50),compliance_date DATE); INSERT INTO regulatory_compliance (client_id,compliance_status,compliance_date) VALUES (3,'Compliant','2022-02-15'); INSERT INTO regulatory_compliance (client_id,compliance_status,compliance_date) VALUES (4,'Non-compliant','2022-02-20'); | SELECT COUNT(*) as number_of_non_compliant_clients FROM regulatory_compliance WHERE compliance_status = 'Non-compliant'; |
What are the names and locations of factories with unethical labor practices? | CREATE TABLE factories (factory_id INT,name TEXT,location TEXT,practices TEXT); | SELECT name, location FROM factories WHERE practices = 'unethical'; |
What is the average age of all female individuals from the 'ancient_burials' table? | CREATE TABLE ancient_burials (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),grave_contents VARCHAR(255)); INSERT INTO ancient_burials (id,name,age,gender,grave_contents) VALUES (1,'John Doe',45,'Male','Pottery,coins'),(2,'Jane Doe',30,'Female','Beads,pottery'); | SELECT AVG(age) FROM ancient_burials WHERE gender = 'Female'; |
How many social impact investments were made in India in 2020? | CREATE TABLE investments (id INT,investment_year INT,investment_type VARCHAR(50),country VARCHAR(50)); | SELECT COUNT(*) FROM investments WHERE investment_year = 2020 AND country = 'India' AND investment_type = 'social impact'; |
How many military personnel are in each department in the 'MilitaryPersonnel' table? | CREATE TABLE MilitaryPersonnel (id INT PRIMARY KEY,name VARCHAR(50),rank VARCHAR(50),country VARCHAR(50),department VARCHAR(50)); INSERT INTO MilitaryPersonnel (id,name,rank,country,department) VALUES (1,'Mohammed Al-Hassan','Captain','Saudi Arabia','Navy'); INSERT INTO MilitaryPersonnel (id,name,rank,country,department) VALUES (2,'Jessica Chen','Lieutenant','Taiwan','Air Force'); INSERT INTO MilitaryPersonnel (id,name,rank,country,department) VALUES (3,'Alexei Ivanov','Sergeant','Ukraine','Army'); | SELECT department, COUNT(*) FROM MilitaryPersonnel GROUP BY department; |
List all the unique song-genre combinations, based on the 'genre' and 'song' tables, with no duplicates. | CREATE TABLE genre (genre_id INT,genre_name VARCHAR(255)); CREATE TABLE song (song_id INT,song_name VARCHAR(255),genre_id INT); | SELECT DISTINCT s.song_id, g.genre_id FROM genre g INNER JOIN song s ON g.genre_id = s.genre_id; |
What is the average revenue per stream for the "Rock" genre? | CREATE TABLE music_streaming (id INT,artist VARCHAR(50),song VARCHAR(50),genre VARCHAR(20),streamed_on DATE,revenue DECIMAL(10,2),streams INT); CREATE VIEW genre_revenue AS SELECT genre,SUM(revenue) AS total_revenue,SUM(streams) AS total_streams FROM music_streaming GROUP BY genre; | SELECT total_revenue / total_streams AS avg_revenue_per_stream FROM genre_revenue WHERE genre = 'Rock'; |
What is the percentage of plays for each track on a given playlist, ordered from highest to lowest? | CREATE TABLE playlist_tracks (playlist_id INT,track_id INT,plays INT); CREATE VIEW track_plays AS SELECT playlist_id,track_id,SUM(plays) as total_plays FROM playlist_tracks GROUP BY playlist_id,track_id; CREATE VIEW total_plays_per_playlist AS SELECT playlist_id,SUM(total_plays) as total_plays FROM track_plays GROUP BY playlist_id; CREATE VIEW percentage_of_plays AS SELECT pt.playlist_id,pt.track_id,pt.total_plays,pt.total_plays/tppp.total_plays as percentage FROM track_plays pt JOIN total_plays_per_playlist tppp ON pt.playlist_id = tppp.playlist_id ORDER BY percentage DESC; | SELECT * FROM percentage_of_plays; |
How many volunteers signed up for each program in the last week? | CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,ProgramID INT,VolunteerDate DATE); CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); INSERT INTO Volunteers (VolunteerID,Name,ProgramID,VolunteerDate) VALUES (1,'John Doe',1,'2021-05-01'),(2,'Jane Smith',2,'2021-05-03'); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Education'),(2,'Health'); | SELECT COUNT(VolunteerID) AS NumVolunteers, Programs.ProgramName FROM Volunteers INNER JOIN Programs ON Volunteers.ProgramID = Programs.ProgramID WHERE VolunteerDate >= DATEADD(week, -1, GETDATE()) GROUP BY Programs.ProgramName |
How many professional development courses were completed by teachers in the English department? | CREATE TABLE teachers (teacher_id INT,department_id INT,teacher_name VARCHAR(255)); INSERT INTO teachers VALUES (1,1,'Ms. Hernandez'); INSERT INTO teachers VALUES (2,2,'Mr. Johnson'); CREATE TABLE departments (department_id INT,department_name VARCHAR(255)); INSERT INTO departments VALUES (1,'English'); INSERT INTO departments VALUES (2,'Physical Education'); CREATE TABLE course_enrollment (enrollment_id INT,teacher_id INT,course_id INT); | SELECT d.department_name, COUNT(c.course_id) FROM course_enrollment ce INNER JOIN teachers t ON ce.teacher_id = t.teacher_id INNER JOIN departments d ON t.department_id = d.department_id WHERE d.department_name = 'English'; |
What is the average mental health score for male teachers? | CREATE TABLE teachers (id INT,name VARCHAR(50),gender VARCHAR(10),years_experience INT); INSERT INTO teachers (id,name,gender,years_experience) VALUES (1,'John Doe','Male',5); | SELECT AVG(m.mental_health_score) as average_score FROM teachers t JOIN teacher_mental_health m ON t.id = m.teacher_id WHERE t.gender = 'Male'; |
What is the average mental health score of female students? | CREATE TABLE students (student_id INT,gender VARCHAR(10),school_id INT,mental_health_score INT); INSERT INTO students (student_id,gender,school_id,mental_health_score) VALUES (1,'Female',1001,75),(2,'Female',1001,80),(3,'Male',1002,60); | SELECT AVG(s.mental_health_score) as avg_mental_health_score FROM students s WHERE s.gender = 'Female'; |
What is the distribution of mental health scores for students in each grade? | CREATE TABLE student_grades (student_id INT,grade INT,mental_health_score INT); INSERT INTO student_grades (student_id,grade,mental_health_score) VALUES (1,9,75),(2,9,80),(3,10,60),(4,10,65),(5,11,85),(6,11,90),(7,12,70),(8,12,75),(9,12,80); | SELECT grade, AVG(mental_health_score) AS avg_score, STDDEV(mental_health_score) AS stddev_score FROM student_grades GROUP BY grade; |
What is the minimum salary for each job title in the IT department? | CREATE TABLE JobSalaries (JobTitle VARCHAR(50),EmployeeSalary DECIMAL(10,2),Department VARCHAR(50)); INSERT INTO JobSalaries (JobTitle,EmployeeSalary,Department) VALUES ('Software Engineer',80000.00,'IT'),('Software Engineer',85000.00,'IT'); | SELECT JobTitle, MIN(EmployeeSalary) FROM JobSalaries WHERE Department = 'IT' GROUP BY JobTitle; |
Delete records in the "power_plants" table where the "fuel_type" is 'coal' and the "capacity_mw" is less than 100 | CREATE TABLE power_plants (id INT PRIMARY KEY,name VARCHAR(255),fuel_type VARCHAR(50),capacity_mw INT); INSERT INTO power_plants (id,name,fuel_type,capacity_mw) VALUES (1,'Plant A','coal',50),(2,'Plant B','gas',200),(3,'Plant C','wind',150); | DELETE FROM power_plants WHERE fuel_type = 'coal' AND capacity_mw < 100; |
What is the total energy storage capacity (GWh) added in Australia and Canada since 2018? | CREATE TABLE energy_storage (id INT,name TEXT,country TEXT,capacity FLOAT,year INT); INSERT INTO energy_storage (id,name,country,capacity,year) VALUES (1,'Hornsdale Power Reserve','Australia',100,2018),(2,'Manitoba-Minnesota Transmission Project','Canada',800,2018),(3,'Tesla Big Battery','Australia',100,2019),(4,'Cameron-Clarendon II','Canada',800,2019); | SELECT SUM(capacity) FROM energy_storage WHERE country IN ('Australia', 'Canada') AND year >= 2018; |
What is the total number of hours volunteered for 'Women Empowerment' programs in '2019'? | CREATE TABLE Volunteers (volunteer_id INT,volunteer_name VARCHAR(255)); CREATE TABLE Volunteer_Hours (volunteer_id INT,hours_donated INT,volunteer_date DATE,program_area VARCHAR(255)); INSERT INTO Volunteers (volunteer_id,volunteer_name) VALUES (2,'Laura Johnson'); INSERT INTO Volunteer_Hours (volunteer_id,hours_donated,volunteer_date,program_area) VALUES (2,15,'2019-01-01','Women Empowerment'); | SELECT SUM(Volunteer_Hours.hours_donated) FROM Volunteer_Hours INNER JOIN Volunteers ON Volunteer_Hours.volunteer_id = Volunteers.volunteer_id WHERE Volunteer_Hours.program_area = 'Women Empowerment' AND YEAR(Volunteer_Hours.volunteer_date) = 2019; |
How many labor violations have been reported in the supply chain for vegan leather products? | CREATE TABLE VeganLeatherSupplyChain (id INT,labor_violation ENUM('yes','no')); | SELECT COUNT(*) FROM VeganLeatherSupplyChain WHERE labor_violation = 'yes'; |
What is the total revenue generated from the sales of products made from recycled materials in the North American market? | CREATE TABLE products (product_id INT,material VARCHAR(20),price DECIMAL(5,2),market VARCHAR(20)); INSERT INTO products (product_id,material,price,market) VALUES (1,'recycled polyester',70.00,'North America'),(2,'recycled cotton',80.00,'North America'),(3,'recycled nylon',90.00,'Europe'),(4,'recycled polyester',75.00,'North America'),(5,'recycled wool',100.00,'North America'); | SELECT SUM(sales.quantity * products.price) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.market = 'North America' AND products.material LIKE '%recycled%'; |
What is the total number of likes received by posts containing the hashtag "#climateaction" in India, in the past month, and how many of these posts were sponsored? | CREATE TABLE posts (id INT,country VARCHAR(255),hashtags VARCHAR(255),likes INT,sponsored BOOLEAN,created_at TIMESTAMP); | SELECT SUM(likes) as total_likes, SUM(sponsored) as sponsored_posts FROM posts WHERE hashtags LIKE '%#climateaction%' AND country = 'India' AND created_at > NOW() - INTERVAL '1 month'; |
What is the total number of posts made by users from the top 3 countries with the most followers? | CREATE TABLE users (id INT,name VARCHAR(50),country VARCHAR(2),followers INT); INSERT INTO users (id,name,country,followers) VALUES (1,'Alice','US',1000),(2,'Bob','IN',2000),(3,'Charlie','CA',1500),(4,'David','US',2500),(5,'Eve','US',3000); | SELECT COUNT(*) as total_posts FROM posts INNER JOIN (SELECT country, MAX(followers) as max_followers FROM users GROUP BY country LIMIT 3) as top_countries ON posts.user_id = top_countries.country; |
What was the average number of comments per post in Oceania in the last month? | CREATE TABLE comments_posts(region VARCHAR(20),post_date DATE,comments INT,posts INT); INSERT INTO comments_posts(region,post_date,comments,posts) VALUES('Oceania','2021-09-01',10,10),('Oceania','2021-09-02',12,12),('Oceania','2021-09-03',14,14),('Oceania','2021-09-04',16,16),('Oceania','2021-09-05',18,18),('Oceania','2021-09-06',20,20),('Oceania','2021-09-07',22,22); | SELECT AVG(comments/posts) FROM comments_posts WHERE region = 'Oceania' AND post_date >= DATEADD(month, -1, CURRENT_DATE) |
What is the maximum number of items of clothing produced per week by factories in Bangladesh and Vietnam, and how many factories can produce that many items? | CREATE TABLE factory_production (factory_id INT,factory_name VARCHAR(50),country VARCHAR(50),items_per_week INT); INSERT INTO factory_production VALUES (1,'Factory A','Bangladesh',5000); INSERT INTO factory_production VALUES (2,'Factory B','Bangladesh',6000); INSERT INTO factory_production VALUES (3,'Factory C','Vietnam',7000); INSERT INTO factory_production VALUES (4,'Factory D','Vietnam',5500); | SELECT MAX(items_per_week) as max_items, COUNT(*) as num_factories FROM factory_production WHERE country IN ('Bangladesh', 'Vietnam') HAVING items_per_week = MAX(items_per_week); |
What is the total amount of socially responsible loans issued by financial institutions in the European region for the year 2021? | CREATE TABLE financial_institutions (institution_id INT,institution_name TEXT,region TEXT);CREATE TABLE loans (loan_id INT,institution_id INT,loan_amount INT,issue_date DATE); INSERT INTO financial_institutions (institution_id,institution_name,region) VALUES (1,'Institution A','Asia'),(2,'Institution B','Europe'),(3,'Institution C','Europe'); INSERT INTO loans (loan_id,institution_id,loan_amount,issue_date) VALUES (1,1,5000,'2021-01-01'),(2,1,7000,'2021-06-15'),(3,2,6000,'2021-03-20'),(4,3,8000,'2021-05-10'); | SELECT SUM(loan_amount) FROM loans JOIN financial_institutions ON loans.institution_id = financial_institutions.institution_id WHERE region = 'Europe' AND EXTRACT(YEAR FROM issue_date) = 2021 AND loans.loan_amount IN (SELECT loan_amount FROM loans WHERE loan_amount >= 0); |
What was the total amount donated by individuals in the US in Q2 2022? | CREATE TABLE donors (id INT,name TEXT,country TEXT,donation_amount DECIMAL,donation_date DATE); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (1,'John Doe','USA',50.00,'2022-04-01'); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (2,'Jane Smith','USA',100.00,'2022-04-15'); | SELECT SUM(donation_amount) FROM donors WHERE country = 'USA' AND donation_date BETWEEN '2022-04-01' AND '2022-06-30'; |
Which warehouse has the lowest quantity of item 'ORG-01'? | CREATE TABLE warehouse (id INT,name VARCHAR(255),location VARCHAR(255)); INSERT INTO warehouse (id,name,location) VALUES (1,'NY','New York'),(2,'LA','Los Angeles'); CREATE TABLE inventory (item_code VARCHAR(255),quantity INT,warehouse_id INT); INSERT INTO inventory (item_code,quantity,warehouse_id) VALUES ('EGG-01',300,1),('APP-01',200,1),('ORG-01',150,1),('ORG-01',50,2); | SELECT warehouse_id, MIN(quantity) FROM inventory WHERE item_code = 'ORG-01' GROUP BY warehouse_id; |
Find the total number of virtual tour bookings by users from Asia? | CREATE TABLE user_profiles (user_id INT,name VARCHAR(50),region VARCHAR(30)); CREATE TABLE user_bookings (booking_id INT,user_id INT,tour_id INT,booking_date DATE); INSERT INTO user_profiles (user_id,name,region) VALUES (1,'Hiroshi','Japan'),(2,'Mei-Ling','China'),(3,'Siti','Indonesia'),(4,'Heinz','Germany'); INSERT INTO user_bookings (booking_id,user_id,tour_id,booking_date) VALUES (1,1,2,'2022-01-01'),(2,1,3,'2022-01-02'),(3,2,1,'2022-01-01'),(4,3,2,'2022-01-03'),(5,4,1,'2022-01-01'); | SELECT COUNT(*) FROM user_bookings JOIN user_profiles ON user_bookings.user_id = user_profiles.user_id WHERE user_profiles.region = 'Asia'; |
What is the maximum revenue generated by eco-tours in a single month in 2022? | CREATE TABLE eco_tours (id INT,name TEXT,revenue DECIMAL(10,2),tour_date DATE); INSERT INTO eco_tours (id,name,revenue,tour_date) VALUES (1,'Rainforest Adventure',12000.00,'2022-03-20'),(2,'Marine Life Encounter',15000.00,'2022-08-05'),(3,'Mountain Biking Tour',9000.00,'2022-11-27'); | SELECT MAX(monthly_revenue) FROM (SELECT EXTRACT(MONTH FROM tour_date) AS month, SUM(revenue) AS monthly_revenue FROM eco_tours WHERE YEAR(tour_date) = 2022 GROUP BY EXTRACT(MONTH FROM tour_date)) AS subquery; |
Show the distribution of hotel tech adoption timelines in South America. | CREATE TABLE tech_adoption (hotel_id INT,location VARCHAR(20),adoption_date DATE); | SELECT YEAR(adoption_date) as adoption_year, COUNT(hotel_id) as num_hotels FROM tech_adoption WHERE location = 'South America' GROUP BY adoption_year |
How many works were exhibited in the year 1950? | CREATE TABLE exhibitions (exhibition_id INT PRIMARY KEY,exhibition_name TEXT,year INT,location TEXT);CREATE TABLE exhibits (exhibit_id INT PRIMARY KEY,work_id INT,exhibition_id INT,FOREIGN KEY (work_id) REFERENCES works(work_id),FOREIGN KEY (exhibition_id) REFERENCES exhibitions(exhibition_id));INSERT INTO exhibitions (exhibition_id,exhibition_name,year,location) VALUES (1,'Documenta',1950,'Kassel,Germany'); INSERT INTO exhibits (exhibit_id,work_id,exhibition_id) VALUES (1,1,1); | SELECT COUNT(*) FROM exhibits e JOIN exhibitions ex ON e.exhibition_id = ex.exhibition_id WHERE ex.year = 1950; |
What is the average founding year of all art galleries in the database? | CREATE TABLE art_galleries (name TEXT,founding_year INTEGER); INSERT INTO art_galleries (name,founding_year) VALUES ('Uffizi Gallery',1581),('Louvre Museum',1793),('Prado Museum',1819); | SELECT AVG(founding_year) FROM art_galleries; |
What is the total value of all 'Expressionist' artworks? | CREATE TABLE Artworks (artwork_id INT,style VARCHAR(20),price DECIMAL(10,2)); INSERT INTO Artworks (artwork_id,style,price) VALUES (1,'Impressionist',1200.00),(2,'Expressionist',2000.00),(3,'Impressionist',1800.00),(4,'Expressionist',2500.00),(5,'Impressionist',1500.00); | SELECT SUM(price) FROM Artworks WHERE style = 'Expressionist'; |
Add a record for a depression screening campaign | CREATE TABLE public_awareness_campaigns (id INT PRIMARY KEY,name VARCHAR(255),description TEXT,start_date DATE,end_date DATE); | INSERT INTO public_awareness_campaigns (id, name, description, start_date, end_date) VALUES (1, 'Depression Screening Campaign', 'A nationwide campaign aimed at increasing depression awareness and screening.', '2022-05-01', '2022-05-31'); |
Find the average age of patients who received group therapy in India? | CREATE TABLE patient_demographics (patient_id INT,age INT,treatment VARCHAR(255),country VARCHAR(255)); INSERT INTO patient_demographics (patient_id,age,treatment,country) VALUES (1,28,'Group','India'); INSERT INTO patient_demographics (patient_id,age,treatment,country) VALUES (2,32,'Individual','India'); | SELECT AVG(age) FROM patient_demographics WHERE treatment = 'Group' AND country = 'India'; |
Which projects were completed before 2022 in the Transportation_Infrastructure table? | CREATE TABLE Transportation_Infrastructure (id INT,project_name VARCHAR(50),completion_date DATE); INSERT INTO Transportation_Infrastructure (id,project_name,completion_date) VALUES (1,'Light Rail Extension','2023-01-01'); INSERT INTO Transportation_Infrastructure (id,project_name,completion_date) VALUES (2,'Bicycle Lane Network','2024-05-15'); | SELECT project_name FROM Transportation_Infrastructure WHERE completion_date < '2022-01-01'; |
Which destinations had more than 50 international tourists in 2020 and 2021? | CREATE TABLE tourism_stats (country VARCHAR(50),visitors INT,year INT); INSERT INTO tourism_stats (country,visitors,year) VALUES ('Italy',61,2020),('Canada',55,2020),('Italy',63,2021),('Canada',57,2021); | SELECT country FROM tourism_stats WHERE visitors > 50 AND year IN (2020, 2021) GROUP BY country HAVING COUNT(DISTINCT year) = 2; |
Update the name of the research vessel 'RV Ocean Explorer' to 'RV Ocean Guardian'. | CREATE TABLE research_vessels (id INT,name VARCHAR(50),type VARCHAR(20),year INT); INSERT INTO research_vessels (id,name,type,year) VALUES (1,'RV Ocean Explorer','Oceanographic',2015),(2,'RV Deep Diver','Underwater',2018),(3,'RV Sea Rover','Hydrographic',2020); | UPDATE research_vessels SET name = 'RV Ocean Guardian' WHERE name = 'RV Ocean Explorer'; |
Which countries have no military equipment sales from any defense contractors? | CREATE TABLE military_equipment_sales (sale_id INT,country VARCHAR(50),equipment_type VARCHAR(50),sale_amount DECIMAL(10,2)); | SELECT country FROM military_equipment_sales GROUP BY country HAVING COUNT(*) = 0; |
What is the total revenue for concerts in Canada for artists who identify as non-binary and are from Asia in 2023? | CREATE TABLE concert_events (event_id INT,artist_id INT,event_date DATE,event_location VARCHAR(255),attendance INT,revenue DECIMAL(10,2),country VARCHAR(50)); INSERT INTO concert_events (event_id,artist_id,event_date,event_location,attendance,revenue,country) VALUES (1,1,'2023-01-01','NYC',15000,500000.00,'Canada'); CREATE TABLE artist_demographics (artist_id INT,artist_name VARCHAR(255),gender VARCHAR(50),ethnicity VARCHAR(50),country VARCHAR(50)); INSERT INTO artist_demographics (artist_id,artist_name,gender,ethnicity,country) VALUES (1,'Li Zhang','non-binary','Asian','Canada'); | SELECT SUM(revenue) FROM concert_events ce JOIN artist_demographics ad ON ce.artist_id = ad.artist_id WHERE ce.country = 'Canada' AND ad.gender = 'non-binary' AND ad.ethnicity = 'Asian' AND ce.event_date BETWEEN '2023-01-01' AND '2023-12-31'; |
What is the total revenue from concert ticket sales for artists who identify as transgender, in the last year? | CREATE TABLE concerts (id INT,artist_id INT,location VARCHAR(255),revenue DECIMAL(10,2),concert_date DATE); CREATE TABLE artists (id INT,gender VARCHAR(255)); | SELECT SUM(revenue) FROM concerts INNER JOIN artists ON concerts.artist_id = artists.id WHERE artists.gender LIKE '%transgender%' AND concert_date >= NOW() - INTERVAL 1 YEAR; |
Find the top 5 donors by summed donation amounts for each country? | CREATE TABLE Donors (DonorID INT,Country VARCHAR(50)); INSERT INTO Donors (DonorID,Country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'Australia'),(5,'UK'),(6,'USA'),(7,'Canada'),(8,'Mexico'),(9,'Germany'),(10,'USA'); CREATE TABLE Donations (DonationID INT,DonorID INT,Amount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonorID,Amount) VALUES (1,1,500),(2,1,250),(3,2,300),(4,3,1000),(5,3,500),(6,4,200),(7,5,800),(8,6,300),(9,6,500),(10,7,250),(11,8,100),(12,9,1500),(13,10,400); | SELECT d.Country, d.DonorID, SUM(donations.Amount) AS TotalDonated FROM Donors d JOIN Donations ON d.DonorID = Donations.DonorID GROUP BY d.Country, d.DonorID ORDER BY TotalDonated DESC LIMIT 5; |
Insert new records into the game_sessions table with the following data: (1, 1, 'Deathmatch', 1), (2, 2, 'Team Deathmatch', 2), (3, 3, 'Free for All', 3) | CREATE TABLE game_sessions (session_id INT,player_id INT,game_mode VARCHAR(20),map_id INT); | INSERT INTO game_sessions (session_id, player_id, game_mode, map_id) VALUES (1, 1, 'Deathmatch', 1), (2, 2, 'Team Deathmatch', 2), (3, 3, 'Free for All', 3); |
Count the number of images taken for each crop variety in the month of June | CREATE TABLE images (id INT,crop_variety VARCHAR(50),timestamp DATETIME); INSERT INTO images (id,crop_variety,timestamp) VALUES (1,'Corn','2022-06-01 10:00:00'),(2,'Soybean','2022-06-02 10:00:00'),(3,'Cotton','2022-05-31 10:00:00'); | SELECT crop_variety, COUNT(*) as total_images FROM images WHERE MONTH(timestamp) = 6 GROUP BY crop_variety; |
How many public healthcare facilities and public parks are there in total, in the 'StateData' schema's 'StateHealthcare' and 'StateParks' tables? | CREATE SCHEMA StateData; CREATE TABLE StateHealthcare (Name varchar(255),Type varchar(255)); INSERT INTO StateHealthcare (Name,Type) VALUES ('FacilityA','Public'),('FacilityB','Public'),('FacilityC','Private'); CREATE TABLE StateParks (Name varchar(255),Type varchar(255)); INSERT INTO StateParks (Name,Type) VALUES ('ParkA','Public'),('ParkB','Public'),('ParkC','Private'); | SELECT COUNT(*) FROM StateData.StateHealthcare WHERE Type = 'Public' UNION ALL SELECT COUNT(*) FROM StateData.StateParks WHERE Type = 'Public'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.