instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total quantity of fish harvested in the Trout_Harvest table for each month? | CREATE TABLE Trout_Harvest (Harvest_ID INT,Farm_ID INT,Harvest_Date DATE,Quantity_Harvested INT); INSERT INTO Trout_Harvest (Harvest_ID,Farm_ID,Harvest_Date,Quantity_Harvested) VALUES (1,1,'2021-08-15',2000),(2,2,'2021-09-20',3000),(3,3,'2021-10-05',2500); | SELECT DATE_FORMAT(Harvest_Date, '%%Y-%%m') AS Month, SUM(Quantity_Harvested) FROM Trout_Harvest GROUP BY Month; |
How many classical songs were released in 2020 that have more than 6000 streams? | CREATE TABLE songs (song_id INT,genre VARCHAR(20),release_year INT,streams INT); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (1,'classical',2020,7000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (2,'classical',2020,8000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES... | SELECT COUNT(*) FROM songs WHERE genre = 'classical' AND release_year = 2020 AND streams > 6000; |
List the names and case numbers of all cases in the justice system that have been open for more than 1 year | CREATE TABLE cases (case_id INT,case_name VARCHAR(255),open_date DATE,close_date DATE,PRIMARY KEY (case_id)); INSERT INTO cases (case_id,case_name,open_date,close_date) VALUES (1,'Case 1','2019-01-01','2020-01-01'),(2,'Case 2','2020-01-01','2021-01-01'),(3,'Case 3','2018-01-01',NULL); | SELECT case_name, case_id FROM cases WHERE close_date IS NULL AND DATEDIFF(CURDATE(), open_date) > 365; |
Which athletes in the 'athlete_details' table have the same name as a team in the 'teams' table? | CREATE TABLE teams (team VARCHAR(50)); INSERT INTO teams (team) VALUES ('Team Alpha'),('Team Bravo'); | SELECT name FROM athlete_details WHERE name IN (SELECT team FROM teams); |
What is the maximum delivery time for packages shipped within the same country? | CREATE TABLE domestic_delivery_data (delivery_id INT,shipment_id INT,delivery_time INT); INSERT INTO domestic_delivery_data (delivery_id,shipment_id,delivery_time) VALUES (1,1,10),(2,2,8),(3,3,12),(4,4,9),(5,5,15); | SELECT MAX(delivery_time) FROM domestic_delivery_data JOIN shipment_data ON domestic_delivery_data.shipment_id = shipment_data.shipment_id WHERE origin_country = destination_country; |
What is the average number of victories for players from Africa in the game "Galactic Conquest"? | CREATE TABLE Players (PlayerID INT,PlayerRegion VARCHAR(10),GameName VARCHAR(20),Victories INT); INSERT INTO Players (PlayerID,PlayerRegion,GameName,Victories) VALUES (1,'Africa','Galactic Conquest',15),(2,'Asia','Galactic Conquest',20),(3,'Africa','Galactic Conquest',25); | SELECT AVG(Victories) FROM Players WHERE PlayerRegion = 'Africa' AND GameName = 'Galactic Conquest'; |
Update the budget for the 'Irrigation System' project in Pakistan to 750000. | CREATE TABLE RuralInfrastructure (id INT,project VARCHAR(255),country VARCHAR(255),budget FLOAT); INSERT INTO RuralInfrastructure (id,project,country,budget) VALUES (1,'Irrigation System','Pakistan',500000); | UPDATE RuralInfrastructure SET budget = 750000 WHERE project = 'Irrigation System' AND country = 'Pakistan'; |
What is the safety rating of the 'HyperHybrid' model? | CREATE TABLE VehicleSafetyRatings (ID INT,Model VARCHAR(255),Manufacturer VARCHAR(255),SafetyRating FLOAT); INSERT INTO VehicleSafetyRatings (ID,Model,Manufacturer,SafetyRating) VALUES (1,'EcoCar','Green Motors',4.8),(2,'HyperHybrid','Blue Cars',4.6),(3,'SolarSedan','FutureAutomobiles',4.9); | SELECT SafetyRating FROM VehicleSafetyRatings WHERE Model = 'HyperHybrid'; |
Count the number of sign language interpreters in the "service_providers" table | CREATE TABLE service_providers (id INT,service_type VARCHAR(255),quantity INT); INSERT INTO service_providers (id,service_type,quantity) VALUES (1,'sign_language_interpreters',5),(2,'assistive_technology_specialists',10),(3,'disability_counselors',8),(4,'accessibility_consultants',6); | SELECT COUNT(*) FROM service_providers WHERE service_type = 'sign_language_interpreters'; |
What is the maximum and minimum capacity (in MW) of wind power projects in Africa? | CREATE TABLE wind_projects_2 (project_id INT,project_name TEXT,country TEXT,capacity_mw FLOAT); INSERT INTO wind_projects_2 (project_id,project_name,country,capacity_mw) VALUES (1,'Wind Farm A','South Africa',100.5),(2,'Wind Farm B','Egypt',250.3); | SELECT country, MAX(capacity_mw), MIN(capacity_mw) FROM wind_projects_2; |
What is the total cargo capacity of vessels registered in Spain? | CREATE TABLE Vessels (ID VARCHAR(10),Name VARCHAR(20),Type VARCHAR(20),Cargo_Capacity FLOAT); INSERT INTO Vessels (ID,Name,Type,Cargo_Capacity) VALUES ('1','Vessel A','Cargo',10000.0),('2','Vessel B','Tanker',15000.0); CREATE TABLE Registry (ID VARCHAR(10),Vessel_ID VARCHAR(10),Registered_Country VARCHAR(20)); INSERT I... | SELECT SUM(Cargo_Capacity) FROM Vessels INNER JOIN Registry ON Vessels.ID = Registry.Vessel_ID WHERE Registered_Country = 'Spain'; |
What is the maximum budget allocated to any public service in the health sector? | CREATE TABLE HealthBudget (ID INT,Service VARCHAR(255),Budget INT); INSERT INTO HealthBudget (ID,Service,Budget) VALUES (1,'Primary Health Care',7000000),(2,'Secondary Health Care',9000000),(3,'Tertiary Health Care',11000000); | SELECT MAX(Budget) FROM HealthBudget WHERE Service LIKE 'Health%' |
What is the minimum market price of Gadolinium in India over the past 3 years? | CREATE TABLE Gadolinium_Market_Prices (id INT,year INT,country VARCHAR(20),market_price DECIMAL(10,2)); | SELECT MIN(market_price) FROM Gadolinium_Market_Prices WHERE country = 'India' AND year BETWEEN 2020 AND 2022; |
List all eco-friendly hotels in Sydney and Melbourne. | CREATE TABLE eco_hotels (hotel_id INT,hotel_name TEXT,city TEXT); INSERT INTO eco_hotels (hotel_id,hotel_name,city) VALUES (1,'EcoHotel Sydney','Sydney'),(2,'GreenHotel Melbourne','Melbourne'),(3,'SustainableSuites Sydney','Sydney'); | SELECT hotel_name, city FROM eco_hotels WHERE city IN ('Sydney', 'Melbourne'); |
How many clinical trials were conducted in 'Asia' in 2017? | CREATE TABLE clinical_trials (country VARCHAR(50),trial_year INT,PRIMARY KEY (country,trial_year)); INSERT INTO clinical_trials (country,trial_year) VALUES ('Asia',2017); | SELECT COUNT(*) FROM clinical_trials WHERE country = 'Asia' AND trial_year = 2017; |
What is the total installed capacity of wind energy in countries that have ratified the Paris Agreement? | CREATE TABLE paris_agreement (country VARCHAR(255),paris_agreement BOOLEAN); INSERT INTO paris_agreement (country,paris_agreement) VALUES ('France',TRUE),('Germany',TRUE),('UK',TRUE),('Italy',TRUE),('Spain',TRUE),('Brazil',FALSE),('Russia',FALSE),('India',TRUE),('China',TRUE),('US',FALSE); CREATE TABLE wind_energy (cou... | SELECT SUM(capacity) FROM wind_energy WHERE country IN (SELECT country FROM paris_agreement WHERE paris_agreement = TRUE); |
What was the total revenue from 'Organic' strains sold in 'Earthly Delights' dispensary in Q4 2022? | CREATE TABLE strains (strain_id INT,name VARCHAR(255),type VARCHAR(255),organic BOOLEAN); INSERT INTO strains (strain_id,name,type,organic) VALUES (9,'Blueberry OG','Hybrid',true); CREATE TABLE dispensaries (dispensary_id INT,name VARCHAR(255)); INSERT INTO dispensaries (dispensary_id,name) VALUES (9,'Earthly Delights'... | SELECT SUM(price * quantity) FROM sales INNER JOIN inventory ON sales.inventory_id = inventory.inventory_id INNER JOIN strains ON inventory.strain_id = strains.strain_id WHERE organic = true AND type = 'Organic' AND dispensary_id = (SELECT dispensary_id FROM dispensaries WHERE name = 'Earthly Delights') AND sale_date B... |
How many lifelong learning programs were offered in each country in 2021? | CREATE TABLE lifelong_learning_programs (program_id INT,country VARCHAR(50),year INT); INSERT INTO lifelong_learning_programs (program_id,country,year) VALUES (1,'USA',2022),(2,'Canada',2021),(3,'Mexico',2022),(4,'Brazil',2021),(5,'USA',2022),(6,'UK',2022),(7,'Germany',2021),(8,'France',2022),(9,'Japan',2021),(10,'Chin... | SELECT country, COUNT(*) as program_count FROM lifelong_learning_programs WHERE year = 2021 GROUP BY country; |
Display the name, location, and energy source of factories that have a higher energy efficiency rating than 80 | CREATE TABLE factories_energy (id INT,name VARCHAR(50),location VARCHAR(50),energy_source VARCHAR(50),energy_efficiency_rating INT); INSERT INTO factories_energy (id,name,location,energy_source,energy_efficiency_rating) VALUES (1,'Factory A','New York','solar',85),(2,'Factory B','California','wind',70),(3,'Factory C','... | SELECT name, location, energy_source FROM factories_energy WHERE energy_efficiency_rating > 80; |
Show all events that are not 'MOBA' or 'RPG' related | CREATE TABLE Esports_Events (event_id INT,event_name VARCHAR(255),game_type VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO Esports_Events (event_id,event_name,game_type,start_date,end_date) VALUES (1,'ESL One','MOBA','2022-01-01','2022-01-05'),(2,'DreamHack','FPS','2022-02-01','2022-02-06'),(3,'Gfinity','Raci... | SELECT * FROM Esports_Events WHERE game_type NOT IN ('MOBA', 'RPG'); |
What is the total revenue generated from warehouse management for customers in the Middle East in H2 2022? | CREATE TABLE WarehouseManagement (id INT,customer VARCHAR(255),revenue FLOAT,region VARCHAR(255),half INT,year INT); | SELECT SUM(revenue) FROM WarehouseManagement WHERE region = 'Middle East' AND half = 2 AND year = 2022; |
How many companies have received funding in the transportation sector, broken down by founder gender? | CREATE TABLE company (id INT,name TEXT,industry TEXT,founder_gender TEXT);CREATE TABLE funding (id INT,company_id INT,amount INT); INSERT INTO company (id,name,industry,founder_gender) VALUES (1,'TransporTech','Transportation','Male'),(2,'GreenWheels','Transportation','Female'); INSERT INTO funding (id,company_id,amoun... | SELECT founder_gender, COUNT(*) FROM company INNER JOIN funding ON company.id = funding.company_id WHERE industry = 'Transportation' GROUP BY founder_gender; |
Delete all records in the 'pollution_incidents' table where the incident type is 'oil spill' and the incident occurred before 2010. | CREATE TABLE pollution_incidents (id INT,type VARCHAR(255),location VARCHAR(255),year INT,volume FLOAT);INSERT INTO pollution_incidents (id,type,location,year,volume) VALUES (1,'oil spill','Gulf of Mexico',2005,400000),(2,'chemical leak','Atlantic Ocean',2015,1000),(3,'oil spill','Mediterranean Sea',2018,20000); | DELETE FROM pollution_incidents WHERE type = 'oil spill' AND year < 2010; |
What are the names of researchers at the Arctic Research Institute who specialize in climate change and have more than 10 publications? | CREATE TABLE Researchers (id INT,name VARCHAR(100),organization VARCHAR(100),expertise VARCHAR(100),publications INT); INSERT INTO Researchers (id,name,organization,expertise,publications) VALUES (1,'Jane Smith','Arctic Research Institute','Climate Change',12); INSERT INTO Researchers (id,name,organization,expertise,pu... | SELECT DISTINCT name FROM Researchers WHERE expertise = 'Climate Change' AND publications > 10 AND organization = 'Arctic Research Institute' |
Update the value of art pieces by artist 'Pablo' by 5% | CREATE TABLE ArtPieces (id INT,title VARCHAR(50),galleryId INT,year INT,value INT,artistId INT,artist VARCHAR(50)); INSERT INTO ArtPieces (id,title,galleryId,year,value,artistId,artist) VALUES (1,'Piece 1',1,2000,10000,1,'Pablo'),(2,'Piece 2',1,2010,15000,2,'Dali'),(3,'Piece 3',2,2020,20000,3,'Picasso'),(4,'Piece 4',3,... | UPDATE ArtPieces SET value = value * 1.05 WHERE artistId = 1; |
Which customers have made transactions in both EUR and USD currencies in the past year? | CREATE TABLE customers (customer_id INT,name VARCHAR(50),region VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2),transaction_date DATE,currency VARCHAR(50)); | SELECT c.name FROM customers c INNER JOIN transactions t1 ON c.customer_id = t1.customer_id AND t1.currency = 'EUR' INNER JOIN transactions t2 ON c.customer_id = t2.customer_id AND t2.currency = 'USD' WHERE t1.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND t2.transaction_date >= DATE_SUB(CURRENT_DATE, ... |
What is the average monthly CO2 emissions for linen fabric in South Korea in 2022? | CREATE TABLE emissions (fabric_type VARCHAR(50),year INT,month INT,co2_emissions DECIMAL(4,2),country VARCHAR(50)); | SELECT AVG(co2_emissions) as avg_monthly_co2_emissions FROM emissions WHERE fabric_type = 'linen' AND country = 'South Korea' AND year = 2022 GROUP BY fabric_type, country, year; |
Show customer preferences for organic and locally sourced items as a percentage of their total orders. | CREATE TABLE customers (customer_id INT,customer_name VARCHAR(255)); CREATE TABLE orders (order_id INT,customer_id INT,order_date DATE,product_organic BOOLEAN,product_local BOOLEAN); | SELECT c.customer_name, (SUM(CASE WHEN o.product_organic THEN 1 ELSE 0 END) * 100.0 / COUNT(*)) as organic_percentage, (SUM(CASE WHEN o.product_local THEN 1 ELSE 0 END) * 100.0 / COUNT(*)) as local_percentage FROM customers c INNER JOIN orders o ON c.customer_id = o.customer_id GROUP BY c.customer_name; |
How many donations were made in the last month for the 'Arts' program? | CREATE TABLE donations (id INT,donor_id INT,program_id INT,donation_date DATE); INSERT INTO donations (id,donor_id,program_id,donation_date) VALUES (1,101,4,'2022-01-01'),(2,102,4,'2022-02-01'),(3,103,3,'2022-03-01'); CREATE TABLE programs (id INT,name VARCHAR(255)); INSERT INTO programs (id,name) VALUES (3,'Environmen... | SELECT COUNT(d.id) as donations_last_month FROM donations d WHERE d.program_id = 4 AND d.donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the average rent for properties built after 2015 in Tokyo? | CREATE TABLE units (id INT,city VARCHAR,build_year INT,rent DECIMAL); | SELECT AVG(rent) FROM units WHERE city = 'Tokyo' AND build_year > 2015; |
What are the unique game genres played by female players? | CREATE TABLE Players (PlayerID INT,Gender VARCHAR(10),GameGenre VARCHAR(20));INSERT INTO Players (PlayerID,Gender,GameGenre) VALUES (1,'Female','RPG'); | SELECT DISTINCT GameGenre FROM Players WHERE Gender = 'Female'; |
What is the average age of players who play VR games in France? | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','France'),(2,30,'Female','Germany'),(3,22,'Male','France'); CREATE TABLE GameTypes (GameID INT,GameName VARCHAR(20),Type VARCHAR(20)); INSERT INTO GameTypes (GameID,G... | SELECT AVG(Players.Age) FROM Players JOIN PlayerGames ON Players.PlayerID = PlayerGames.PlayerID JOIN GameTypes ON PlayerGames.GameID = GameTypes.GameID WHERE Players.Country = 'France' AND GameTypes.Type = 'VR'; |
Delete all records from the 'equipment' table where the 'equipment_type' is 'Sequencer' | CREATE TABLE equipment (equipment_id INT PRIMARY KEY,equipment_type VARCHAR(50),model VARCHAR(50),date_purchased DATE); | WITH cte1 AS (DELETE FROM equipment WHERE equipment_type = 'Sequencer') SELECT * FROM cte1; |
What is the total number of pieces created by artists who have used watercolor as a medium? | CREATE TABLE artists_watercolor (artist_id INT,name VARCHAR(50),medium VARCHAR(50),pieces INT); | SELECT SUM(pieces) FROM artists_watercolor WHERE medium = 'watercolor'; |
Show the number of volunteers for each program, sorted by the number of volunteers in descending order | CREATE TABLE volunteers (id INT,program_id INT,name VARCHAR(50)); INSERT INTO volunteers (id,program_id,name) VALUES (1,1,'Alice'); INSERT INTO volunteers (id,program_id,name) VALUES (2,1,'Bob'); INSERT INTO volunteers (id,program_id,name) VALUES (3,2,'Charlie'); INSERT INTO volunteers (id,program_id,name) VALUES (4,2,... | SELECT program_id, COUNT(*) as num_volunteers FROM volunteers GROUP BY program_id ORDER BY num_volunteers DESC; |
List all countries with marine protected areas in the Pacific Ocean that are larger than 50000 square kilometers. | CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),area_size FLOAT,region VARCHAR(255),country VARCHAR(255)); INSERT INTO marine_protected_areas (id,name,area_size,region,country) VALUES (1,'Great Barrier Reef',344400,'Pacific','Australia'); | SELECT DISTINCT country FROM marine_protected_areas WHERE region = 'Pacific' AND area_size > 50000; |
How many unique game design elements are present in games with a rating of 9 or higher? | CREATE TABLE games (game_id INT,game_name VARCHAR(50),rating INT,design_elements VARCHAR(100)); INSERT INTO games (game_id,game_name,rating,design_elements) VALUES (1,'GameA',9,'action,RPG,puzzle'),(2,'GameB',10,'RPG,adventure,simulation'),(3,'GameC',9,'strategy,simulation,FPS'),(4,'GameD',8,'racing,simulation'); | SELECT COUNT(DISTINCT trimmed_design_elements) FROM (SELECT REGEXP_SPLIT_TO_TABLE(design_elements, ',') AS trimmed_design_elements FROM games WHERE rating >= 9) AS split_design_elements; |
What is the minimum local economic impact of cultural heritage sites in Egypt? | CREATE TABLE heritage_sites (site_id INT,site_name TEXT,country TEXT,local_impact INT); INSERT INTO heritage_sites (site_id,site_name,country,local_impact) VALUES (1,'Cultural Heritage Site 1','Egypt',200000),(2,'Cultural Heritage Site 2','Egypt',250000); | SELECT MIN(local_impact) FROM heritage_sites WHERE country = 'Egypt'; |
What is the maximum donation amount made by donors from each country in Q2 2021? | CREATE TABLE Donors (id INT,name TEXT,country TEXT,donation FLOAT,quarter TEXT,year INT); INSERT INTO Donors (id,name,country,donation,quarter,year) VALUES (1,'Charlie','USA',100.0,'Q2',2021),(2,'David','Mexico',150.0,'Q2',2021),(3,'Eve','Canada',75.0,'Q2',2021),(4,'Frank','USA',200.0,'Q3',2021); | SELECT country, MAX(donation) FROM Donors WHERE quarter = 'Q2' GROUP BY country; |
Display the vessel names, engine capacities, and safety inspection status for vessels that have not had any safety inspections or have an engine capacity greater than 4000, excluding passenger ships? | CREATE TABLE Vessels (ID INT,Name VARCHAR(50),Type VARCHAR(50),Safety_Inspections INT,Engine_Capacity INT); INSERT INTO Vessels (ID,Name,Type,Safety_Inspections,Engine_Capacity) VALUES (1,'MV Pegasus','Cargo Ship',0,4500),(2,'MV Pisces','Passenger Ship',1,2000); | SELECT Name, Engine_Capacity, Safety_Inspections FROM Vessels WHERE Safety_Inspections = 0 OR Engine_Capacity > 4000 AND Type != 'Passenger Ship'; |
Find the number of days since the first measurement for each species in the species_measurements table. | CREATE TABLE species_measurements (species_id INT,measurement_date DATE); | SELECT species_id, DATEDIFF(day, MIN(measurement_date) OVER (PARTITION BY species_id), measurement_date) FROM species_measurements; |
What is the average size of the cyber weapons stockpile for each military branch? | CREATE TABLE military_branch (id INT,name VARCHAR(255)); INSERT INTO military_branch (id,name) VALUES (1,'Army'),(2,'Navy'),(3,'Air Force'); CREATE TABLE cyber_weapons (id INT,military_branch_id INT,size INT); | SELECT m.name, AVG(c.size) as avg_size FROM military_branch m JOIN cyber_weapons c ON m.id = c.military_branch_id GROUP BY m.id; |
What is the total amount spent on waste management services in Texas, only considering cities with a population greater than 500,000? | CREATE TABLE waste_management (service_id INT,service_name TEXT,city TEXT,state TEXT,cost INT); INSERT INTO waste_management (service_id,service_name,city,state,cost) VALUES (1,'City of Houston Waste Services','Houston','Texas',100000000); INSERT INTO waste_management (service_id,service_name,city,state,cost) VALUES (2... | SELECT SUM(cost) FROM waste_management WHERE state = 'Texas' AND city IN ('Houston', 'Dallas', 'San Antonio'); |
What is the minimum number of bikes available in 'park2' on weekdays? | CREATE TABLE bike_availability (location VARCHAR(20),day_of_week VARCHAR(10),bikes_available INT); INSERT INTO bike_availability (location,day_of_week,bikes_available) VALUES ('park1','Monday',20),('park1','Tuesday',15),('park2','Wednesday',10); | SELECT MIN(bikes_available) FROM bike_availability WHERE location = 'park2' AND day_of_week IN ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'); |
How many donors from each country made donations in 2021? | CREATE TABLE Donors (DonorID int,DonorName varchar(100),Country varchar(50),DonationDate date); INSERT INTO Donors (DonorID,DonorName,Country,DonationDate) VALUES (1,'John Doe','USA','2021-01-01'),(2,'Jane Smith','Canada','2021-02-01'),(3,'Ali Khan','Pakistan','2021-03-01'),(4,'Han Lee','South Korea','2021-04-01'),(5,'... | SELECT Country, COUNT(*) as NumDonors FROM Donors WHERE YEAR(DonationDate) = 2021 GROUP BY Country; |
How many public parks are there in 'StateParks' table for each state? | CREATE TABLE StateParks (state VARCHAR(50),park VARCHAR(50)); INSERT INTO StateParks (state,park) VALUES ('State1','ParkA'),('State1','ParkB'),('State2','ParkC'),('State3','ParkD'); | SELECT state, COUNT(park) FROM StateParks GROUP BY state; |
What is the total donation amount for 'Fundraising' events in 'New York' and 'Chicago'? | CREATE TABLE Donors (DonorID INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),DonationAmount DECIMAL(10,2),DonationDate DATE); CREATE TABLE DonationEvents (EventID INT PRIMARY KEY,EventName VARCHAR(100),EventLocation VARCHAR(100),DonationID INT,FOREIGN KEY (DonationID) REFERENCES Donors(DonorID)); | SELECT SUM(DonationAmount) as TotalDonationAmount FROM Donors d JOIN DonationEvents e ON d.DonorID = e.DonationID WHERE e.EventLocation IN ('New York', 'Chicago') AND e.EventName = 'Fundraising'; |
What is the employment rate for veterans in the technology sector? | CREATE TABLE veteran_employment (industry TEXT,employment_rate FLOAT); INSERT INTO veteran_employment (industry,employment_rate) VALUES ('Technology',85.3); | SELECT employment_rate FROM veteran_employment WHERE industry = 'Technology'; |
What is the average depth of all marine protected areas in the Pacific region? | CREATE TABLE marine_protected_areas (name VARCHAR(255),region VARCHAR(255),avg_depth FLOAT); INSERT INTO marine_protected_areas (name,region,avg_depth) VALUES ('Galapagos Marine Reserve','Pacific',220.0),('Great Barrier Reef','Pacific',120.0); | SELECT avg(avg_depth) FROM marine_protected_areas WHERE region = 'Pacific'; |
Find the total expenditure by Canadian tourists in Canadian Dollars in Toronto, given the exchange rate is 1.3? | CREATE TABLE tourism_stats (visitor_country VARCHAR(20),destination VARCHAR(20),expenditure DECIMAL(10,2)); CREATE TABLE exchange_rates (country VARCHAR(20),currency VARCHAR(10),rate DECIMAL(10,2)); INSERT INTO exchange_rates (country,currency,rate) VALUES ('Canada','CAD',1.0),('Canada','USD',1.3); | SELECT SUM(expenditure * (SELECT rate FROM exchange_rates WHERE country = 'Canada' AND currency = 'CAD')) FROM tourism_stats WHERE visitor_country = 'Canada' AND destination = 'Toronto'; |
What is the average cargo weight handled by the top 5 ports in Asia? | CREATE TABLE ports (port_id INT,port_name TEXT,region TEXT,cargo_weight_tonnes FLOAT); INSERT INTO ports VALUES (1,'Port of Shanghai','Asia',55000000),(2,'Port of Singapore','Asia',50000000),(3,'Port of Shenzhen','Asia',42000000),(4,'Port of Ningbo-Zhoushan','Asia',35000000),(5,'Port of Hong Kong','Asia',30000000); | SELECT AVG(cargo_weight_tonnes) FROM (SELECT cargo_weight_tonnes FROM ports WHERE region = 'Asia' ORDER BY cargo_weight_tonnes DESC LIMIT 5) subquery; |
Find the monthly trend in mobile data usage for the top 5 regions with the most subscribers, for the last 2 years. | CREATE TABLE subscribers (subscriber_id INT,data_usage FLOAT,plan_type VARCHAR(10),region VARCHAR(20),subscriber_date DATE); INSERT INTO subscribers (subscriber_id,data_usage,plan_type,region,subscriber_date) VALUES (1,8.5,'postpaid','Northeast','2020-01-01'); INSERT INTO subscribers (subscriber_id,data_usage,plan_type... | SELECT region, EXTRACT(MONTH FROM subscriber_date) as month, AVG(data_usage) as avg_data_usage, RANK() OVER (ORDER BY AVG(data_usage) DESC) as region_rank FROM subscribers WHERE subscriber_date >= DATEADD(year, -2, CURRENT_DATE) GROUP BY region, EXTRACT(MONTH FROM subscriber_date) HAVING region_rank <= 5 ORDER BY regio... |
What was the maximum and minimum investment in agricultural innovation projects in 2020? | CREATE TABLE agri_innovation (country VARCHAR(50),project VARCHAR(50),investment FLOAT); INSERT INTO agri_innovation (country,project,investment) VALUES ('Mexico','Precision Agriculture',500000),('Brazil','GMO Research',800000),('Colombia','Organic Farming',300000),('Peru','Irrigation Systems',700000),('Argentina','Liv... | SELECT MIN(investment) as min_investment, MAX(investment) as max_investment FROM agri_innovation WHERE YEAR(project) = 2020; |
Count the number of publications by graduate students in the Mathematics department in the last 5 years. | CREATE TABLE students (id INT,name VARCHAR(50),department VARCHAR(50),start_year INT); INSERT INTO students (id,name,department,start_year) VALUES (1,'Charlie','Mathematics',2018); INSERT INTO students (id,name,department,start_year) VALUES (2,'Dana','Computer Science',2019); CREATE TABLE publications (id INT,student_i... | SELECT COUNT(p.id) FROM publications p JOIN students s ON p.student_id = s.id WHERE s.department = 'Mathematics' AND p.year BETWEEN YEAR(CURRENT_DATE) - 5 AND YEAR(CURRENT_DATE); |
Delete all shared scooters in Berlin. | CREATE TABLE shared_scooters (scooter_id INT,city VARCHAR(20)); INSERT INTO shared_scooters (scooter_id,city) VALUES (1,'Berlin'),(2,'Berlin'),(3,'Paris'),(4,'Paris'); | DELETE FROM shared_scooters WHERE city = 'Berlin'; |
What is the budget for each language preservation program? | CREATE TABLE Preservation_Programs (Program_ID INT PRIMARY KEY,Name VARCHAR(100),Country VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO Preservation_Programs (Program_ID,Name,Country,Budget) VALUES (1,'Swahili Language Program','Tanzania',50000.00); INSERT INTO Preservation_Programs (Program_ID,Name,Country,Budget) VAL... | SELECT Name, Budget FROM Preservation_Programs; |
What is the total revenue for each hotel category in Q1 2022? | CREATE TABLE hotel_revenue (hotel_category VARCHAR(20),revenue DECIMAL(10,2),date DATE); INSERT INTO hotel_revenue (hotel_category,revenue,date) VALUES ('5 Star',15000,'2022-01-01'),('5 Star',16000,'2022-01-02'),('4 Star',12000,'2022-01-01'),('4 Star',12500,'2022-01-02'); | SELECT hotel_category, SUM(revenue) as total_revenue FROM hotel_revenue WHERE date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY hotel_category; |
List all public services, their budget allocations, and corresponding citizen feedback ratings, if any. | CREATE TABLE public_services (id INT PRIMARY KEY,service VARCHAR(255),location VARCHAR(255),budget DECIMAL(10,2),provider VARCHAR(255)); CREATE TABLE citizen_feedback (id INT PRIMARY KEY,city VARCHAR(255),age INT,feedback TEXT); CREATE TABLE public_feedback (id INT PRIMARY KEY,city VARCHAR(255),service VARCHAR(255),rat... | SELECT p.service, p.budget, pf.rating FROM public_services p LEFT JOIN public_feedback pf ON p.service = pf.service; |
What is the total water usage in Cairo and Istanbul? | CREATE TABLE water_usage_ME (city VARCHAR(50),usage INT); INSERT INTO water_usage_ME (city,usage) VALUES ('Cairo',12000),('Istanbul',8000); | SELECT SUM(usage) FROM water_usage_ME WHERE city IN ('Cairo', 'Istanbul'); |
Identify the top 2 most popular sustainable tour destinations in the Americas. | CREATE TABLE sustainable_tours (tour_id INT,operator_id INT,location VARCHAR,num_tourists INT); CREATE VIEW americas_sustainable_tours AS SELECT * FROM sustainable_tours WHERE location LIKE '%%America%%'; | SELECT location, SUM(num_tourists) AS total_tourists FROM americas_sustainable_tours GROUP BY location ORDER BY total_tourists DESC LIMIT 2; |
List all the clients who have invested in Shariah-compliant funds and their total investment amount. | CREATE TABLE clients (client_id INT,name TEXT); CREATE TABLE shariah_compliant_funds (fund_id INT,client_id INT,investment_amount INT); INSERT INTO clients (client_id,name) VALUES (1,'John Doe'),(2,'Jane Doe'); INSERT INTO shariah_compliant_funds (fund_id,client_id,investment_amount) VALUES (1,1,5000),(2,1,7000),(3,2,8... | SELECT clients.name, SUM(shariah_compliant_funds.investment_amount) FROM clients JOIN shariah_compliant_funds ON clients.client_id = shariah_compliant_funds.client_id GROUP BY clients.name; |
List all donations made before '2021-02-15' in the 'global_emergencies' table. | CREATE TABLE global_emergencies (donation_id INT,donor VARCHAR(50),amount DECIMAL(10,2),donation_date DATE); INSERT INTO global_emergencies (donation_id,donor,amount,donation_date) VALUES (1,'Irene White',75.00,'2021-01-01'),(2,'James Brown',100.00,'2021-02-10'); | SELECT * FROM global_emergencies WHERE donation_date < '2021-02-15'; |
What is the average salary of baseball players from the US? | CREATE TABLE players (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),sport VARCHAR(20),salary INT,country VARCHAR(50)); | SELECT AVG(salary) FROM players WHERE sport = 'Baseball' AND country = 'USA'; |
What is the average cultural competency score for community health workers in each state? | CREATE TABLE community_health_workers (worker_id INT,name VARCHAR(50),state VARCHAR(2),score INT); | SELECT state, AVG(score) FROM community_health_workers GROUP BY state; |
List the total quantity of sustainable materials used in garment production in Latin America. | CREATE TABLE sustainable_materials (id INT,country VARCHAR(50),material VARCHAR(50),quantity INT); INSERT INTO sustainable_materials (id,country,material,quantity) VALUES (1,'Brazil','Organic Cotton',2000),(2,'Argentina','Hemp',1500),(3,'Colombia','Tencel',2500); | SELECT country, SUM(quantity) as total_quantity FROM sustainable_materials WHERE country IN ('Brazil', 'Argentina', 'Colombia') GROUP BY country; |
What is the total tonnage of all vessels that have visited the 'Caribbean' region in the last 6 months? | CREATE TABLE Visits (ID INT,VesselID INT,VisitDate DATE); CREATE TABLE Vessels (ID INT,Name TEXT,Tonnage INT,Region TEXT); INSERT INTO Visits (ID,VesselID,VisitDate) VALUES (1,1,'2022-01-01'),(2,1,'2022-02-01'),(3,2,'2022-01-01'); INSERT INTO Vessels (ID,Name,Tonnage,Region) VALUES (1,'Vessel 1',1000,'Caribbean'),(2,'V... | SELECT SUM(Vessels.Tonnage) FROM Visits INNER JOIN Vessels ON Visits.VesselID = Vessels.ID WHERE VisitDate >= DATEADD(month, -6, GETDATE()) AND Vessels.Region = 'Caribbean'; |
List all autonomous driving research data from Germany. | CREATE TABLE AutonomousDriving (Id INT,Location VARCHAR(255),Data VARCHAR(255)); INSERT INTO AutonomousDriving (Id,Location,Data) VALUES (1,'USA','Data 1'),(2,'Germany','Data 2'),(3,'USA','Data 3'); | SELECT * FROM AutonomousDriving WHERE Location = 'Germany'; |
What is the percentage of volunteers that joined in each region compared to the total number of volunteers? | CREATE TABLE Volunteers (VolunteerID INT,JoinDate DATE,Region VARCHAR(50)); | SELECT v.Region, ROUND(COUNT(*) / (SELECT COUNT(*) FROM Volunteers) * 100, 2) as Percentage FROM Volunteers v GROUP BY v.Region; |
What is the total number of mobile and broadband subscribers for a specific network provider? | CREATE TABLE mobile_subscribers (subscriber_id INT,network_provider VARCHAR(50)); CREATE TABLE broadband_subscribers (subscriber_id INT,network_provider VARCHAR(50)); | SELECT 'Mobile' AS service, COUNT(DISTINCT subscriber_id) FROM mobile_subscribers WHERE network_provider = 'XYZ' UNION ALL SELECT 'Broadband', COUNT(DISTINCT subscriber_id) FROM broadband_subscribers WHERE network_provider = 'XYZ'; |
Which explainable AI techniques were developed in Germany? | CREATE TABLE XAI_Germany (id INT,technique TEXT,location TEXT); INSERT INTO XAI_Germany (id,technique,location) VALUES (1,'SHAP','Germany'),(2,' anchors','Germany'),(3,'TreeExplainer','France'),(4,'LIME','USA'); | SELECT technique FROM XAI_Germany WHERE location = 'Germany'; |
List all completed rural infrastructure projects in 2022 for Country M? | CREATE TABLE rural_infrastructure (id INT,project_name VARCHAR(255),sector VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO rural_infrastructure (id,project_name,sector,location,start_date,end_date) VALUES (1,'Rural Road Project','Infrastructure','Village C,Country M','2022-01-01','2022-12... | SELECT * FROM rural_infrastructure WHERE location LIKE '%Country M%' AND YEAR(end_date) = 2022; |
What is the maximum water conservation initiative budget by country? | CREATE TABLE conservation_budget (country VARCHAR(50),initiative VARCHAR(50),budget INT); INSERT INTO conservation_budget (country,initiative,budget) VALUES ('USA','Project A',500000),('Canada','Project B',600000),('Mexico','Project C',400000),('Brazil','Project D',700000); | SELECT cb.country, MAX(cb.budget) as max_budget FROM conservation_budget cb GROUP BY cb.country; |
What is the total CO2 emissions for each supplier, partitioned by year and ordered by total CO2 emissions? | CREATE TABLE co2 (co2_id INT,supplier_id INT,co2_emissions INT,co2_emission_date DATE); INSERT INTO co2 (co2_id,supplier_id,co2_emissions,co2_emission_date) VALUES (1,1,1000,'2022-01-01'),(2,1,2000,'2022-02-01'); | SELECT supplier_id, DATE_TRUNC('year', co2_emission_date) AS year, SUM(co2_emissions) AS total_co2_emissions, RANK() OVER (ORDER BY SUM(co2_emissions) DESC) AS ranking FROM co2 GROUP BY supplier_id, year ORDER BY total_co2_emissions DESC; |
How many transportation projects were completed in the year 2020? | CREATE TABLE Projects_Timeline (Project_ID INT,Start_Date DATE,Completion_Date DATE); INSERT INTO Projects_Timeline (Project_ID,Start_Date,Completion_Date) VALUES (1,'2019-01-01','2020-06-30'),(2,'2018-05-01','2019-12-31'),(3,'2020-07-01','2021-01-31'),(4,'2017-09-01','2018-08-31'); | SELECT COUNT(*) FROM Projects_Timeline WHERE YEAR(Start_Date) <= 2020 AND YEAR(Completion_Date) >= 2020 AND Project_Type = 'Transportation'; |
Who are the defense contractors involved in the South China Sea geopolitical risk assessment? | CREATE TABLE GeopoliticalRiskAssessments (assessmentID INT,contractor VARCHAR(255),region VARCHAR(255)); INSERT INTO GeopoliticalRiskAssessments (assessmentID,contractor,region) VALUES (1,'Boeing','South China Sea'); INSERT INTO GeopoliticalRiskAssessments (assessmentID,contractor,region) VALUES (2,'Northrop Grumman','... | SELECT DISTINCT contractor FROM GeopoliticalRiskAssessments WHERE region = 'South China Sea'; |
Identify military innovation patents filed by the top 3 countries in defense diplomacy. | CREATE TABLE military_innovation (id INT,patent VARCHAR(50),country VARCHAR(50)); CREATE TABLE defense_diplomacy (id INT,country VARCHAR(50),rank INT); INSERT INTO military_innovation (id,patent,country) VALUES (1,'Stealth technology','United States'),(2,'Artificial Intelligence','China'),(3,'Cybersecurity','Russia'),(... | SELECT military_innovation.country, COUNT(military_innovation.patent) as patent_count FROM military_innovation INNER JOIN defense_diplomacy ON military_innovation.country = defense_diplomacy.country GROUP BY military_innovation.country ORDER BY patent_count DESC LIMIT 3; |
What is the average safety score for chemical manufacturing plants in the US, with at least 100 employees, in Q2 2021? | CREATE TABLE plants (id INT,name TEXT,location TEXT,num_employees INT,safety_score FLOAT,quarter INT,year INT); INSERT INTO plants (id,name,location,num_employees,safety_score,quarter,year) VALUES (1,'PlantA','US',150,88.5,2,2021),(2,'PlantB','CA',80,92.3,2,2021),(3,'PlantC','US',250,85.6,2,2021),(4,'PlantD','MX',120,9... | SELECT AVG(safety_score) FROM plants WHERE location = 'US' AND num_employees >= 100 AND quarter = 2 AND year = 2021; |
Get smart contracts written in Vyper with version greater than 0.2.8. | CREATE TABLE if not exists smart_contracts (id INT PRIMARY KEY,name TEXT,language TEXT,version TEXT); INSERT INTO smart_contracts (id,name,language,version) VALUES (1,'CryptoKitties','Solidity','0.4.24'); INSERT INTO smart_contracts (id,name,language,version) VALUES (2,'Uniswap','Vyper','0.2.6'); | SELECT * FROM smart_contracts WHERE language = 'Vyper' AND version > '0.2.8'; |
List all factories in Asian countries that have not implemented fair labor practices by the end of 2021. | CREATE TABLE factories (factory_id INT,name VARCHAR(255),location VARCHAR(255),fair_labor_practices BOOLEAN);INSERT INTO factories (factory_id,name,location,fair_labor_practices) VALUES (1,'Asian Textiles','Asia',false),(2,'Eastern Fashions','Asia',true),(3,'Pacific Producers','Asia',true); | SELECT name, location FROM factories WHERE location = 'Asia' AND fair_labor_practices = false; |
What is the total funding received by biotech startups in Kenya working on genetic research? | CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),total_funding FLOAT,research_area VARCHAR(255)); INSERT INTO biotech.startups (id,name,country,total_funding,research_area) VALUES (1,'Genetech Kenya','Kenya',2500000,'Genetic Rese... | SELECT SUM(total_funding) FROM biotech.startups WHERE country = 'Kenya' AND research_area = 'Genetic Research'; |
What is the average number of disability accommodations provided per employee in the Northeast region? | CREATE TABLE accommodations_provided (region VARCHAR(20),accommodations INT,employees INT); INSERT INTO accommodations_provided (region,accommodations,employees) VALUES ('Northeast',20,100); INSERT INTO accommodations_provided (region,accommodations,employees) VALUES ('Northeast',25,150); | SELECT region, AVG(accommodations/employees) FROM accommodations_provided WHERE region = 'Northeast'; |
What is the difference in athlete wellbeing scores between the first and last game for each athlete? | CREATE TABLE AthleteWellbeing (ScoreID INT,AthleteID INT,GameID INT,WellbeingScore INT); INSERT INTO AthleteWellbeing VALUES (1,1,1,80),(2,1,2,85),(3,2,1,90),(4,2,2,95),(5,3,1,70),(6,3,2,75); | SELECT AthleteID, FIRST_VALUE(WellbeingScore) OVER (PARTITION BY AthleteID ORDER BY GameID) as FirstGameWellbeingScore, LAST_VALUE(WellbeingScore) OVER (PARTITION BY AthleteID ORDER BY GameID ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as LastGameWellbeingScore, LAST_VALUE(WellbeingScore) OVER (PARTITION ... |
List the top 5 cities with the most ticket sales for the 2022 World Series. | CREATE TABLE IF NOT EXISTS teams (id INT,name VARCHAR(50),league VARCHAR(50)); CREATE TABLE IF NOT EXISTS games (id INT,team_1_id INT,team_2_id INT,location VARCHAR(50),date DATE); CREATE TABLE IF NOT EXISTS sales (id INT,game_id INT,city VARCHAR(50),tickets_sold INT); | SELECT city, SUM(tickets_sold) AS total_sales FROM sales JOIN games ON sales.game_id = games.id JOIN teams ON games.team_1_id = teams.id OR games.team_2_id = teams.id WHERE teams.name IN ('Red Sox', 'Astros') AND date BETWEEN '2022-10-01' AND '2022-10-31' GROUP BY city ORDER BY total_sales DESC LIMIT 5; |
Find defense contractors who received contracts in both the current year and the previous year | CREATE TABLE defense_contracts (contract_id INT,vendor_name VARCHAR(255),contract_date DATE); | SELECT vendor_name FROM defense_contracts WHERE YEAR(contract_date) IN (YEAR(CURRENT_DATE), YEAR(DATEADD(year, -1, CURRENT_DATE))) GROUP BY vendor_name HAVING COUNT(DISTINCT YEAR(contract_date)) = 2; |
What is the average salary of government employees in Washington DC, and how many of them are there? | CREATE TABLE employees (name VARCHAR(255),city VARCHAR(255),salary DECIMAL(10,2),government BOOLEAN); INSERT INTO employees (name,city,salary,government) VALUES ('John Doe','Washington DC',80000.00,TRUE),('Jane Smith','Washington DC',90000.00,TRUE); | SELECT AVG(salary) FROM employees WHERE city = 'Washington DC' AND government = TRUE; SELECT COUNT(*) FROM employees WHERE city = 'Washington DC' AND government = TRUE; |
Who are the top 3 cities with the highest average donation amount in the Climate Change focus area? | CREATE TABLE donations (id INT PRIMARY KEY,donor_id INT,organization_id INT,donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,organization_id,donation_date,donation_amount) VALUES (1,1,1,'2021-01-01',500.00); INSERT INTO donations (id,donor_id,organization_id,donation_date,donation_a... | SELECT d.city, AVG(d.donation_amount) as avg_donation FROM donations d JOIN organizations o ON d.organization_id = o.id WHERE o.cause = 'Climate Change' GROUP BY d.city ORDER BY avg_donation DESC LIMIT 3; |
List the number of IoT sensors of each type that were installed in each year in the 'sensor_deployment' table. | CREATE TABLE sensor_deployment (id INT,sensor_type VARCHAR(255),year INT,quantity INT); | SELECT sensor_type, year, SUM(quantity) as total_quantity FROM sensor_deployment GROUP BY sensor_type, year; |
Calculate the total number of military personnel in Europe | CREATE TABLE military_personnel (id INT,name TEXT,rank TEXT,region TEXT); INSERT INTO military_personnel (id,name,rank,region) VALUES (1,'Jacques Leclerc','Colonel','Europe'),(2,'Sofia Müller','General','Europe'),(3,'Roberto Rossi','Captain','Europe'); | SELECT COUNT(*) FROM military_personnel WHERE region = 'Europe'; |
Who are the top 3 suppliers by average item price? | CREATE TABLE supplier_items (id INT,supplier_id INT,item_id INT,price DECIMAL(5,2)); INSERT INTO supplier_items (id,supplier_id,item_id,price) VALUES (1,1,1,50.99),(2,1,2,45.99),(3,2,3,39.99),(4,3,4,60.99),(5,3,5,65.99),(6,4,6,49.99); CREATE TABLE suppliers (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO sup... | SELECT suppliers.name, AVG(supplier_items.price) AS avg_price FROM supplier_items INNER JOIN suppliers ON supplier_items.supplier_id = suppliers.id GROUP BY suppliers.id ORDER BY avg_price DESC LIMIT 3; |
What is the difference in average salary between the IT and HR departments? | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Salary FLOAT); INSERT INTO Employees (EmployeeID,Name,Department,Salary) VALUES (1,'John Doe','IT',75000.00),(2,'Jane Smith','IT',80000.00),(3,'Mike Johnson','HR',60000.00); | SELECT (AVG(CASE WHEN Department = 'IT' THEN Salary ELSE NULL END) - AVG(CASE WHEN Department = 'HR' THEN Salary ELSE NULL END)) AS salary_difference; |
List the initiatives, cities, and capacities for renewable energy projects related to hydropower energy in countries with BREEAM certified buildings. | CREATE TABLE green_buildings (id INT,name VARCHAR(50),city VARCHAR(50),country VARCHAR(50),certification VARCHAR(50)); INSERT INTO green_buildings (id,name,city,country,certification) VALUES (1,'EcoTowers','Toronto','Canada','BREEAM Excellent'); CREATE TABLE renewable_energy (id INT,project_name VARCHAR(50),city VARCHA... | SELECT r.project_name, r.city, r.capacity FROM green_buildings g INNER JOIN renewable_energy r ON g.country = r.country WHERE g.certification = 'BREEAM Excellent' AND r.energy_type = 'Hydropower'; |
What is the total number of patients in each state? | CREATE TABLE patients (id INT,state TEXT); INSERT INTO patients (id,state) VALUES (1,'California'); INSERT INTO patients (id,state) VALUES (2,'New York'); INSERT INTO patients (id,state) VALUES (3,'Florida'); | SELECT state, COUNT(*) FROM patients GROUP BY state; |
What is the average price of menu items by cuisine? | CREATE TABLE menu_item(menu_item VARCHAR(50),price INT,cuisine VARCHAR(50)); INSERT INTO menu_item VALUES ('Burger',10,'American'),('Pizza',12,'Italian'),('Salad',8,'European'),('Tacos',10,'Mexican'); | SELECT cuisine, AVG(price) AS avg_price FROM menu_item GROUP BY cuisine; |
Update the names of the services 'Police' and 'Fire' to 'Public Safety - Police' and 'Public Safety - Fire' in the 'StateData' schema's 'StateServices' table. | CREATE SCHEMA StateData; CREATE TABLE StateServices (Service varchar(255),Type varchar(255)); INSERT INTO StateServices (Service,Type) VALUES ('Police','Safety'),('Fire','Safety'),('Transportation','Infrastructure'); | UPDATE StateData.StateServices SET Service = CASE Service WHEN 'Police' THEN 'Public Safety - Police' WHEN 'Fire' THEN 'Public Safety - Fire' ELSE Service END; |
What is the maximum age of patients who received therapy in Canada? | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,treatment TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (1,30,'Female','CBT','Texas'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (2,45,'Male','DBT','California'); INSERT INTO patients (patient_id,... | SELECT MAX(age) FROM patients WHERE treatment = 'Therapy' AND state = 'Canada'; |
What is the total number of emergency calls in both 'Fire' and 'Medical' categories? | CREATE TABLE EmergencyCalls (call_id INT,call_type VARCHAR(10)); INSERT INTO EmergencyCalls VALUES (1,'Fire'),(2,'Medical'),(3,'Fire'),(4,'Medical'); | SELECT call_type, COUNT(*) FROM EmergencyCalls WHERE call_type IN ('Fire', 'Medical') GROUP BY call_type; |
Delete any weather records where temperature is below -5 degrees Celsius. | CREATE TABLE weather_data (id INT,farm_id INT,date DATE,temperature FLOAT,humidity FLOAT); INSERT INTO weather_data (id,farm_id,date,temperature,humidity) VALUES (1,1,'2018-01-01',-6.0,80.0); INSERT INTO weather_data (id,farm_id,date,temperature,humidity) VALUES (2,1,'2018-01-02',-1.0,75.0); | DELETE FROM weather_data WHERE temperature < -5; |
What is the average transaction value for users from the United States? | CREATE TABLE Users (UserID INT,UserName VARCHAR(100),Country VARCHAR(50)); INSERT INTO Users (UserID,UserName,Country) VALUES (1,'JamesBond','USA'),(2,'SpyCatcher','Canada'); CREATE TABLE Transactions (TransactionID INT,UserID INT,TransactionValue DECIMAL(10,2)); INSERT INTO Transactions (TransactionID,UserID,Transacti... | SELECT AVG(TransactionValue) FROM Transactions INNER JOIN Users ON Transactions.UserID = Users.UserID WHERE Users.Country = 'USA'; |
Delete a graduate student record from the "students" table | CREATE TABLE students (id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),department VARCHAR(50),email VARCHAR(50)); | WITH deleted_student AS (DELETE FROM students WHERE id = 1 RETURNING *) SELECT * FROM deleted_student; |
What is the daily calorie intake distribution for customers following the paleo diet? | CREATE TABLE customers (id INT,diet TEXT); CREATE TABLE meals (id INT,customer_id INT,date DATE,calories INT); INSERT INTO customers (id,diet) VALUES (1,'paleo'),(2,'non-paleo'),(3,'paleo'); INSERT INTO meals (id,customer_id,date,calories) VALUES (1,1,'2022-01-01',1500),(2,1,'2022-01-02',1800),(3,2,'2022-01-01',2000),(... | SELECT customer_id, date_trunc('day', date) AS date, AVG(calories) FROM meals JOIN customers ON meals.customer_id = customers.id WHERE customers.diet = 'paleo' GROUP BY date, customer_id; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.