instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Delete all planting records that are more than two years old.
|
CREATE TABLE planting_records (record_id INT,user_id INT,crop_type VARCHAR(255),planting_date DATE);
|
DELETE pr FROM planting_records pr WHERE pr.planting_date < DATE_SUB(CURDATE(), INTERVAL 2 YEAR);
|
What is the latest safety inspection date for vessels in the 'Mediterranean'?
|
CREATE TABLE vessel_inspections (id INT,vessel_id INT,region TEXT,inspection_date DATE); INSERT INTO vessel_inspections (id,vessel_id,region,inspection_date) VALUES (1,1,'Mediterranean','2022-02-01'); INSERT INTO vessel_inspections (id,vessel_id,region,inspection_date) VALUES (2,2,'Mediterranean','2022-02-05');
|
SELECT MAX(inspection_date) FROM vessel_inspections WHERE region = 'Mediterranean'
|
What was the average community development initiative score for each country in the Pacific Islands in Q3 2017?
|
CREATE TABLE community_development (country VARCHAR(50),quarter INT,score FLOAT); INSERT INTO community_development (country,quarter,score) VALUES ('Fiji',3,5.2),('Samoa',3,7.5),('Tonga',3,6.1),('Vanuatu',3,4.9),('Papua New Guinea',3,5.8),('Solomon Islands',3,6.6);
|
SELECT country, AVG(score) as avg_score FROM community_development WHERE quarter = 3 GROUP BY country;
|
Find the number of unique users who streamed a given artist's music in a given year, grouped by city.
|
CREATE TABLE Artists (id INT,name VARCHAR(100)); CREATE TABLE Users (id INT,name VARCHAR(100)); CREATE TABLE Streams (id INT,user_id INT,artist_id INT,minutes DECIMAL(10,2),year INT,city VARCHAR(50));
|
SELECT artist_id, city, COUNT(DISTINCT user_id) AS unique_users FROM Streams WHERE year = 2021 GROUP BY artist_id, city;
|
Which vessels belonging to carriers from the United States have carried cargo weighing more than 15000 tons?
|
CREATE TABLE Vessel (VesselID INT,Name VARCHAR(255),CarrierID INT,Type VARCHAR(255)); INSERT INTO Vessel (VesselID,Name,CarrierID,Type) VALUES (12,'Independence',10,'Container Ship'); INSERT INTO Vessel (VesselID,Name,CarrierID,Type) VALUES (13,'Liberty',10,'Container Ship'); INSERT INTO Vessel (VesselID,Name,CarrierID,Type) VALUES (14,'Freedom',10,'Container Ship');
|
SELECT Vessel.Name FROM Vessel JOIN Cargo ON Vessel.VesselID = Cargo.VesselID JOIN Carrier ON Vessel.CarrierID = Carrier.CarrierID WHERE Cargo.Weight > 15000 AND Carrier.Country = 'United States';
|
What are the names and start years of the programs in the 'government_programs' database that started after 2015?
|
CREATE TABLE program (id INT,name VARCHAR(50),start_year INT,end_year INT); INSERT INTO program (id,name,start_year,end_year) VALUES (1,'Green City Initiative',2005,2015),(2,'Public Art Program',2008,2022),(3,'Safe Streets',2010,2020),(4,'Youth Mentorship',2018,2025);
|
SELECT name, start_year FROM program WHERE start_year > 2015;
|
Find the number of unique donors in each category?
|
CREATE TABLE DonorCategories (DonorID INT,Category TEXT); INSERT INTO DonorCategories (DonorID,Category) VALUES (1,'Effective Altruism'),(2,'Impact Investing'),(3,'Effective Altruism'),(4,'Impact Investing'),(5,'Effective Altruism'),(6,'Social Entrepreneurship');
|
SELECT Category, COUNT(DISTINCT DonorID) as UniqueDonors FROM DonorCategories GROUP BY Category;
|
What is the minimum age of visitors who attended family-friendly exhibitions in London last year?
|
CREATE TABLE Family_Friendly_Exhibitions (id INT,city VARCHAR(255),year INT,visitor_age INT);
|
SELECT MIN(visitor_age) FROM Family_Friendly_Exhibitions WHERE city = 'London' AND year = 2021;
|
Find the top 3 types of crimes with the most reports in the state of California in the year 2020.
|
CREATE TABLE crimes (id INT,state VARCHAR(20),year INT,crime_type VARCHAR(20),num_crimes INT); INSERT INTO crimes (id,state,year,crime_type,num_crimes) VALUES (1,'California',2020,'Theft',2000),(2,'California',2020,'Assault',1500),(3,'California',2020,'Vandalism',1000);
|
SELECT crime_type, SUM(num_crimes) as total_crimes FROM crimes WHERE state = 'California' AND year = 2020 GROUP BY crime_type ORDER BY total_crimes DESC LIMIT 3;
|
What is the average duration of stays in Egypt for tourists from the United States?
|
CREATE TABLE tourism (visitor_country VARCHAR(50),host_country VARCHAR(50),duration INT); INSERT INTO tourism (visitor_country,host_country,duration) VALUES ('United States','Egypt',10),('United States','Egypt',14),('Canada','Egypt',12);
|
SELECT AVG(duration) FROM tourism WHERE visitor_country = 'United States' AND host_country = 'Egypt';
|
How many players have played a game in each genre, and what is the average playtime per genre?
|
CREATE TABLE game_genres (game_id INT,genre VARCHAR(20)); INSERT INTO game_genres (game_id,genre) VALUES (1,'Action'),(2,'Adventure'),(3,'Strategy'),(4,'Puzzle'); CREATE TABLE user_games (user_id INT,game_id INT,playtime INT); INSERT INTO user_games (user_id,game_id,playtime) VALUES (1,1,50),(1,2,20),(1,3,0),(2,2,100),(2,3,80),(3,1,60),(3,4,100);
|
SELECT genre, COUNT(DISTINCT user_id) AS num_players, AVG(playtime) AS avg_playtime FROM user_games JOIN game_genres ON user_games.game_id = game_genres.game_id GROUP BY genre;
|
What is the name and accessibility score of the technology with the lowest accessibility score?
|
CREATE TABLE tech_accessibility (id INT,name VARCHAR(50),accessibility_score DECIMAL(3,2)); INSERT INTO tech_accessibility (id,name,accessibility_score) VALUES (1,'Tech1',3.5); INSERT INTO tech_accessibility (id,name,accessibility_score) VALUES (2,'Tech2',2.8);
|
SELECT name, accessibility_score, RANK() OVER (ORDER BY accessibility_score) AS rank FROM tech_accessibility;
|
get movies with budget greater than 150 million
|
CREATE TABLE movies(id INT PRIMARY KEY,name VARCHAR(255),budget INT);
|
SELECT name FROM movies WHERE budget > 150000000;
|
Determine the total amount of resources depleted by each mine, by resource type
|
CREATE TABLE mine (id INT,name TEXT,location TEXT); CREATE TABLE depletion (mine_id INT,date DATE,resource TEXT,quantity INT); INSERT INTO mine VALUES (1,'Mine A','Country A'); INSERT INTO mine VALUES (2,'Mine B','Country B'); INSERT INTO depletion VALUES (1,'2021-01-01','Gold',100); INSERT INTO depletion VALUES (1,'2021-02-01','Gold',120); INSERT INTO depletion VALUES (1,'2021-03-01','Gold',150); INSERT INTO depletion VALUES (2,'2021-01-01','Silver',50); INSERT INTO depletion VALUES (2,'2021-02-01','Silver',75); INSERT INTO depletion VALUES (2,'2021-03-01','Silver',85);
|
SELECT mine.name, depletion.resource, SUM(depletion.quantity) AS total_depleted FROM mine INNER JOIN depletion ON mine.id = depletion.mine_id GROUP BY mine.name, depletion.resource;
|
What is the maximum cost of therapy for patients in 'clinic_m'?
|
CREATE TABLE clinic_m (patient_id INT,cost INT,treatment VARCHAR(10)); INSERT INTO clinic_m (patient_id,cost,treatment) VALUES (25,200,'therapy'),(26,100,'medication');
|
SELECT MAX(cost) FROM clinic_m WHERE treatment = 'therapy';
|
What is the cultural competency score for each hospital in the last week?
|
CREATE TABLE Hospitals (HospitalID INT,CulturalCompetencyScore DECIMAL(5,2),HospitalName VARCHAR(255),ReportDate DATE); INSERT INTO Hospitals (HospitalID,CulturalCompetencyScore,HospitalName,ReportDate) VALUES (1,85.6,'Johns Hopkins Hospital','2022-06-01'); INSERT INTO Hospitals (HospitalID,CulturalCompetencyScore,HospitalName,ReportDate) VALUES (2,92.3,'Massachusetts General Hospital','2022-06-15'); INSERT INTO Hospitals (HospitalID,CulturalCompetencyScore,HospitalName,ReportDate) VALUES (3,78.9,'University of California San Francisco Medical Center','2022-06-05'); INSERT INTO Hospitals (HospitalID,CulturalCompetencyScore,HospitalName,ReportDate) VALUES (4,96.1,'Mayo Clinic','2022-06-10');
|
SELECT ReportDate, CulturalCompetencyScore, HospitalName FROM Hospitals WHERE ReportDate >= DATEADD(week, -1, GETDATE());
|
Which countries have active military operations in Africa in 2021?
|
CREATE TABLE MilitaryOperations (ID INT,OperationYear INT,Country TEXT,Region TEXT); INSERT INTO MilitaryOperations (ID,OperationYear,Country,Region) VALUES (1,2020,'USA','Africa'),(2,2021,'France','Africa'),(3,2019,'UK','Europe');
|
SELECT DISTINCT Country FROM MilitaryOperations WHERE OperationYear = 2021 AND Region = 'Africa';
|
Add a new sustainable sourcing record for restaurant 4 with a rating of 90. Use the sustainable_sourcing table.
|
CREATE TABLE sustainable_sourcing (restaurant_id INT,rating INT); INSERT INTO sustainable_sourcing (restaurant_id,rating) VALUES (2,95),(4,90);
|
INSERT INTO sustainable_sourcing (restaurant_id, rating) VALUES (4, 90);
|
What is the minimum energy efficiency rating for industrial buildings in the 'building_efficiency' table?
|
CREATE TABLE building_efficiency (building_id INT,building_type VARCHAR(50),energy_efficiency_rating FLOAT); INSERT INTO building_efficiency (building_id,building_type,energy_efficiency_rating) VALUES (1,'Residential',70.0),(2,'Industrial',60.0),(3,'Commercial',65.0);
|
SELECT MIN(energy_efficiency_rating) FROM building_efficiency WHERE building_type = 'Industrial';
|
What is the number of tourists visiting Japan from each continent?
|
CREATE TABLE tourists (tourist_id INT,name TEXT,country TEXT,continent TEXT); INSERT INTO tourists (tourist_id,name,country,continent) VALUES (1,'John Doe','USA','North America'),(2,'Jane Smith','Brazil','South America'),(3,'Minh Nguyen','Vietnam','Asia'),(4,'Pierre Dupont','France','Europe'),(5,'Emily Chen','Australia','Australia');
|
SELECT continent, COUNT(DISTINCT country) FROM tourists WHERE country = 'Japan' GROUP BY continent;
|
What was the total cost of satellites deployed in 2022?
|
CREATE TABLE Satellites (satellite_id INT,deployment_year INT,cost FLOAT); INSERT INTO Satellites (satellite_id,deployment_year,cost) VALUES (1,2022,20000000.0),(2,2021,15000000.0);
|
SELECT SUM(cost) FROM Satellites WHERE deployment_year = 2022;
|
What is the total number of workplace incidents reported for each industry?
|
CREATE TABLE WorkplaceSafety (union_id INT,year INT,incidents INT); CREATE TABLE Unions (union_id INT,industry TEXT);
|
SELECT Unions.industry, SUM(WorkplaceSafety.incidents) FROM WorkplaceSafety INNER JOIN Unions ON WorkplaceSafety.union_id = Unions.union_id GROUP BY Unions.industry;
|
What is the average funding amount received by startups in the 'Tech' industry?
|
CREATE TABLE startups (id INT,name VARCHAR(255),founding_year INT,industry VARCHAR(255),average_funding INT); INSERT INTO startups (id,name,founding_year,industry,average_funding) VALUES (1,'Acme Inc',2015,'Tech',500000),(2,'Bravo Corp',2017,'Retail',750000);
|
SELECT AVG(startups.average_funding) FROM startups WHERE startups.industry = 'Tech';
|
What is the average temperature recorded in the Arctic per year?
|
CREATE TABLE weather_data (id INT,year INT,avg_temp FLOAT);
|
SELECT AVG(avg_temp) FROM weather_data GROUP BY year;
|
What is the average price of products made by sustainable manufacturers?
|
CREATE TABLE manufacturers (id INT PRIMARY KEY,name TEXT,location TEXT,sustainability_score INT); CREATE TABLE products (id INT PRIMARY KEY,name TEXT,category TEXT,price DECIMAL,manufacturer_id INT,FOREIGN KEY (manufacturer_id) REFERENCES manufacturers(id));
|
SELECT AVG(p.price) FROM products p JOIN manufacturers m ON p.manufacturer_id = m.id WHERE m.sustainability_score >= 80;
|
Display the names and types of all the attractions in Africa that are not yet sustainable.
|
CREATE TABLE africa_attractions (id INT,name TEXT,country TEXT,sustainable BOOLEAN);
|
SELECT name, type FROM africa_attractions WHERE sustainable = 'false';
|
Which materials are used by 'FairTradeFashions' but not by 'EcoFriendlyFashions'?
|
CREATE TABLE SupplierMaterials (SupplierName TEXT,Material TEXT); INSERT INTO SupplierMaterials (SupplierName,Material) VALUES ('FairTradeFashions','Silk'),('FairTradeFashions','Wool'),('EcoFriendlyFashions','Cotton'),('EcoFriendlyFashions','Polyester');
|
SELECT s1.SupplierName, s1.Material FROM SupplierMaterials s1 LEFT JOIN SupplierMaterials s2 ON s1.Material = s2.Material AND s2.SupplierName = 'EcoFriendlyFashions' WHERE s2.SupplierName IS NULL AND s1.SupplierName = 'FairTradeFashions';
|
How many marine protected areas (MPAs) are there in the Atlantic Ocean that are larger than 1000 square kilometers?
|
CREATE TABLE marine_protected_areas (id INT,name TEXT,location TEXT,size FLOAT); INSERT INTO marine_protected_areas (id,name,location,size) VALUES (1,'Atlantic MPAs','Atlantic Ocean',1500.0),(2,'Pacific MPAs','Pacific Ocean',1200.5),(3,'Caribbean MPAs','Atlantic Ocean',800.3);
|
SELECT COUNT(*) FROM marine_protected_areas WHERE location = 'Atlantic Ocean' AND size > 1000;
|
Who are the top 3 donors by total donation?
|
CREATE TABLE Donors (DonorID INT,DonorName TEXT,TotalDonation DECIMAL); INSERT INTO Donors (DonorID,DonorName,TotalDonation) VALUES (1,'John Doe',500.00),(2,'Jane Smith',350.00),(3,'Bob Johnson',700.00),(4,'Alice Davis',200.00),(5,'Charlie Brown',800.00),(6,'David Williams',100.00);
|
SELECT DonorName, TotalDonation FROM (SELECT DonorName, TotalDonation, ROW_NUMBER() OVER (ORDER BY TotalDonation DESC) AS Rank FROM Donors) AS SubQuery WHERE Rank <= 3;
|
How many labor rights violations occurred in the 'construction' industry in the last 6 months?
|
CREATE TABLE if not exists labor_violations (id INT PRIMARY KEY,industry VARCHAR(255),violation_date DATE); INSERT INTO labor_violations (id,industry,violation_date) VALUES (1,'construction','2022-01-05'),(2,'construction','2022-02-10'),(3,'manufacturing','2022-03-15');
|
SELECT COUNT(*) FROM labor_violations WHERE industry = 'construction' AND violation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
What is the average duration of security incidents for each department, only showing departments with more than 15 incidents?
|
CREATE TABLE SecurityIncidents (id INT,department VARCHAR(255),incident_start_date DATE,incident_end_date DATE,incident_type VARCHAR(255)); INSERT INTO SecurityIncidents (id,department,incident_start_date,incident_end_date,incident_type) VALUES (1,'IT','2022-01-01','2022-01-05','Phishing');
|
SELECT department, AVG(DATEDIFF(incident_end_date, incident_start_date)) as avg_duration FROM SecurityIncidents GROUP BY department HAVING COUNT(*) > 15;
|
Which metro lines in Barcelona have the least number of passengers?
|
CREATE TABLE MetroLines (LineID int,Passengers int); INSERT INTO MetroLines (LineID,Passengers) VALUES (1,1000),(2,800),(3,800);
|
SELECT LineID, MIN(Passengers) FROM MetroLines;
|
What is the cumulative water usage for the Blue Ridge Wastewater Treatment Plant up to a specific date?
|
CREATE TABLE WastewaterTreatmentFacilities (FacilityID INT,FacilityName VARCHAR(255),Address VARCHAR(255),City VARCHAR(255),State VARCHAR(255),ZipCode VARCHAR(10)); INSERT INTO WastewaterTreatmentFacilities (FacilityID,FacilityName,Address,City,State,ZipCode) VALUES (1,'Blue Ridge Wastewater Treatment Plant','1200 W Main St','Blue Ridge','GA','30513'); CREATE TABLE WaterUsage (UsageID INT,FacilityID INT,UsageDate DATE,TotalGallons INT); INSERT INTO WaterUsage (UsageID,FacilityID,UsageDate,TotalGallons) VALUES (1,1,'2022-01-01',500000),(2,1,'2022-01-02',550000),(3,1,'2022-01-03',600000);
|
SELECT UsageID, SUM(TotalGallons) OVER (ORDER BY UsageDate) FROM WaterUsage WHERE FacilityID = 1;
|
What is the maximum number of security incidents in a single day in the last month?
|
CREATE TABLE security_incidents (id INT,incident_date DATE);
|
SELECT MAX(COUNT(*)) FROM security_incidents WHERE incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY DATE(incident_date);
|
Insert a new network security policy for the IT department with a policy strength of high.
|
CREATE TABLE network_security_policies (policy_id INT,department VARCHAR(255),policy_name VARCHAR(255),policy_strength VARCHAR(255));
|
INSERT INTO network_security_policies (policy_id, department, policy_name, policy_strength) VALUES (1, 'IT', 'Example Network Security Policy', 'High');
|
What is the daily count and average number of access control policies in Europe?
|
CREATE TABLE policies(id INT,date DATE,region VARCHAR(50),policy_type VARCHAR(50),policy_id VARCHAR(50)); INSERT INTO policies(id,date,region,policy_type,policy_id) VALUES (1,'2021-01-01','Europe','access_control','POL-2021-01'),(2,'2021-01-02','Europe','security_management','POL-2021-02');
|
SELECT date, COUNT(*) as total_policies, AVG(policy_type = 'access_control'::int) as avg_access_control FROM policies WHERE region = 'Europe' GROUP BY date ORDER BY date;
|
What is the total revenue generated from recycled material products for the current year?
|
CREATE TABLE Sales (sale_id INT,sale_date DATE,sale_amount FLOAT,product_material VARCHAR(50));
|
SELECT SUM(Sales.sale_amount) as total_revenue FROM Sales WHERE EXTRACT(YEAR FROM Sales.sale_date) = EXTRACT(YEAR FROM CURRENT_DATE) AND Sales.product_material LIKE '%recycled%';
|
How many police officers are assigned to each community policing program?
|
CREATE TABLE programs (id INT,name VARCHAR(255));CREATE TABLE officers (id INT,program_id INT,assigned BOOLEAN);
|
SELECT p.name, COUNT(o.id) FROM programs p INNER JOIN officers o ON p.id = o.program_id WHERE o.assigned = TRUE GROUP BY p.name;
|
What was the total agricultural innovation investment in Indonesia, in descending order of investment amount?
|
CREATE TABLE agri_investment (country TEXT,year INT,investment_amount NUMERIC); INSERT INTO agri_investment (country,year,investment_amount) VALUES ('Indonesia',2017,1000000),('Indonesia',2018,1250000),('Indonesia',2019,1500000),('Indonesia',2020,1750000),('Indonesia',2021,2000000);
|
SELECT year, SUM(investment_amount) OVER (ORDER BY SUM(investment_amount) DESC) AS total_investment FROM agri_investment WHERE country = 'Indonesia' GROUP BY year ORDER BY total_investment DESC;
|
How many startups were founded by individuals from the LGBTQ+ community in the retail sector before 2018?
|
CREATE TABLE venture (id INT,name VARCHAR(255),sector VARCHAR(255),founding_date DATE,founder_lgbtq BOOLEAN); INSERT INTO venture (id,name,sector,founding_date,founder_lgbtq) VALUES (1,'Echo Inc','Technology','2010-01-01',FALSE); INSERT INTO venture (id,name,sector,founding_date,founder_lgbtq) VALUES (2,'Foxtrot LLC','Healthcare','2012-05-15',FALSE); INSERT INTO venture (id,name,sector,founding_date,founder_lgbtq) VALUES (3,'Golf Alpha Bravo','Technology','2015-09-09',FALSE); INSERT INTO venture (id,name,sector,founding_date,founder_lgbtq) VALUES (4,'Hotel India','Retail','2018-01-01',TRUE); INSERT INTO venture (id,name,sector,founding_date,founder_lgbtq) VALUES (5,'Kilo Lima','Technology','2020-06-19',TRUE);
|
SELECT COUNT(*) FROM venture WHERE sector = 'Retail' AND founding_date < '2018-01-01' AND founder_lgbtq = TRUE;
|
What is the name and phone number of policyholders in New York?
|
CREATE TABLE policies (policy_number INT,policyholder_name TEXT,issue_date DATE,state TEXT,phone_number TEXT); INSERT INTO policies (policy_number,policyholder_name,issue_date,state,phone_number) VALUES (12345,'John Doe','2021-06-01','California','555-555-5555'); INSERT INTO policies (policy_number,policyholder_name,issue_date,state,phone_number) VALUES (67890,'Jane Smith','2021-07-01','New York','555-555-5556');
|
SELECT policyholder_name, phone_number FROM policies WHERE state = 'New York';
|
Display the average age of astronauts from each country at the time of their first spaceflight.
|
CREATE TABLE Astronauts (AstronautID INT,Name VARCHAR(50),Nationality VARCHAR(50),FirstFlightDate DATE); INSERT INTO Astronauts (AstronautID,Name,Nationality,FirstFlightDate) VALUES (1,'Sergei Krikalev','Russia','1988-05-30'); INSERT INTO Astronauts (AstronautID,Name,Nationality,FirstFlightDate) VALUES (2,'John Young','USA','1965-06-03'); INSERT INTO Astronauts (AstronautID,Name,Nationality,FirstFlightDate) VALUES (3,'Roberta Bondar','Canada','1992-01-22');
|
SELECT Nationality, AVG(DATEDIFF(day, BirthDate, FirstFlightDate)) / 365.25 AS AvgAgeAtFirstFlight FROM (SELECT AstronautID, Name, Nationality, BirthDate, MIN(FirstFlightDate) OVER (PARTITION BY AstronautID) FirstFlightDate FROM Astronauts) t GROUP BY Nationality;
|
Find the average transaction value for the 'North America' region.
|
CREATE TABLE customers (customer_id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO customers (customer_id,name,region) VALUES (1,'James Johnson','North America'); INSERT INTO customers (customer_id,name,region) VALUES (2,'Sophia Rodriguez','South America'); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,transaction_value) VALUES (1,1,100.00); INSERT INTO transactions (transaction_id,customer_id,transaction_value) VALUES (2,2,200.00);
|
SELECT AVG(transaction_value) FROM transactions JOIN customers ON transactions.customer_id = customers.customer_id WHERE customers.region = 'North America';
|
List all defense diplomacy events that have taken place in the North Atlantic Treaty Organization (NATO) countries in the last 5 years, along with the number of participating countries.
|
CREATE TABLE DefenseDiplomacy (ID INT,EventName TEXT,EventDate DATE,ParticipatingCountries TEXT); INSERT INTO DefenseDiplomacy VALUES (1,'Event 1','2018-01-01','USA,Canada,UK'); CREATE VIEW NATO AS SELECT Country FROM DefenseDiplomacy WHERE Country IN ('USA','Canada','UK','France','Germany');
|
SELECT EventName, ParticipatingCountries, COUNT(DISTINCT SUBSTRING_INDEX(ParticipatingCountries, ',', n)) as NumberOfCountries FROM DefenseDiplomacy d CROSS JOIN (SELECT numbers.N FROM (SELECT 1 as N UNION ALL SELECT 2 UNION ALL SELECT 3) numbers) n JOIN NATO nato ON FIND_IN_SET(nato.Country, ParticipatingCountries) > 0 WHERE EventDate BETWEEN DATEADD(year, -5, GETDATE()) AND GETDATE() GROUP BY EventName, ParticipatingCountries;
|
What is the minimum number of hospital beds per state in Rural West?
|
CREATE TABLE Hospitals (name TEXT,location TEXT,type TEXT,num_beds INTEGER,state TEXT); INSERT INTO Hospitals (name,location,type,num_beds,state) VALUES ('Hospital A','City A,Rural West','General',250,'Rural West'),('Hospital B','City B,Rural West','Specialty',125,'Rural West');
|
SELECT state, MIN(num_beds) as min_beds FROM Hospitals WHERE state IN ('Rural West', 'Rural West') GROUP BY state;
|
What was the total oil production in the Permian Basin in 2017?
|
CREATE TABLE basin_production (basin VARCHAR(50),year INT,oil_production FLOAT,gas_production FLOAT); INSERT INTO basin_production (basin,year,oil_production,gas_production) VALUES ('Permian',2015,1234.5,678.9); INSERT INTO basin_production (basin,year,oil_production,gas_production) VALUES ('Permian',2016,2345.6,789.0); INSERT INTO basin_production (basin,year,oil_production,gas_production) VALUES ('Permian',2017,3456.7,890.1);
|
SELECT SUM(oil_production) as total_oil_production FROM basin_production WHERE basin = 'Permian' AND year = 2017;
|
List the top 3 producing countries of Dysprosium in 2019, ordered by production amount.
|
CREATE TABLE production (country VARCHAR(255),element VARCHAR(255),amount INT,year INT); INSERT INTO production (country,element,amount,year) VALUES ('China','Dysprosium',12000,2019),('Malaysia','Dysprosium',2000,2019),('United States','Dysprosium',3000,2019); CREATE TABLE price (element VARCHAR(255),year INT,price DECIMAL(10,2)); INSERT INTO price (element,year,price) VALUES ('Dysprosium',2019,250.50);
|
SELECT country, SUM(amount) as total_production FROM production WHERE element = 'Dysprosium' AND year = 2019 GROUP BY country ORDER BY total_production DESC LIMIT 3;
|
Update the 'Workouts' table to increase the duration of workouts by 5% for members with a 'Basic' membership type
|
CREATE TABLE Workouts (WorkoutID INT,MemberID INT,Duration INT,MembershipType VARCHAR(20));
|
UPDATE Workouts w SET Duration = w.Duration * 1.05 WHERE w.MemberID IN (SELECT m.MemberID FROM Members m WHERE m.MembershipType = 'Basic');
|
How many dispensaries exist in Colorado with a valid license in 2023?
|
CREATE TABLE dispensaries (id INT,name TEXT,state TEXT,license_expiry DATE); INSERT INTO dispensaries (id,name,state,license_expiry) VALUES (1,'Dispensary C','Colorado','2023-05-01');
|
SELECT COUNT(*) as num_dispensaries FROM dispensaries WHERE state = 'Colorado' AND license_expiry >= '2023-01-01';
|
Which newspapers were most popular among 25-34 year olds in the US in 2021?
|
CREATE TABLE newspapers (id INT,name VARCHAR(255),country VARCHAR(255));CREATE TABLE readership (id INT,newspaper_id INT,age_group VARCHAR(255),year INT); INSERT INTO newspapers (id,name,country) VALUES (1,'New York Times','USA'); INSERT INTO readership (id,newspaper_id,age_group,year) VALUES (1,1,'25-34',2021);
|
SELECT newspapers.name FROM newspapers INNER JOIN readership ON newspapers.id = readership.newspaper_id WHERE readership.age_group = '25-34' AND readership.year = 2021;
|
Which industries have the lowest average salary for union members, compared to non-union members?
|
CREATE TABLE workers (id INT,name TEXT,industry TEXT,union_member BOOLEAN,salary REAL); INSERT INTO workers (id,name,industry,union_member,salary) VALUES (1,'John Doe','construction',true,60000.00),(2,'Jane Smith','retail',false,35000.00);
|
SELECT industry, AVG(salary) FROM workers WHERE union_member = true GROUP BY industry HAVING AVG(salary) < (SELECT AVG(salary) FROM workers WHERE union_member = false AND industry = workers.industry);
|
What are the top 3 most popular art mediums in each city?
|
CREATE TABLE artists (id INT,name TEXT,city TEXT,country TEXT);CREATE TABLE art_pieces (id INT,title TEXT,medium TEXT,artist_id INT);
|
SELECT a.city, ap.medium, COUNT(ap.id) as num_pieces, RANK() OVER (PARTITION BY a.city ORDER BY COUNT(ap.id) DESC) as rank FROM artists a JOIN art_pieces ap ON a.id = ap.artist_id GROUP BY a.city, ap.medium HAVING rank <= 3;
|
Who are the customers with the lowest number of returned items?
|
CREATE TABLE CustomerReturns2(id INT,customer_name VARCHAR(50),returned_items INT); INSERT INTO CustomerReturns2(id,customer_name,returned_items) VALUES (1,'Greg Black',1),(2,'Heidi Green',0);
|
SELECT customer_name, returned_items FROM CustomerReturns2 ORDER BY returned_items ASC;
|
Which region had the highest total attendance at dance events?
|
CREATE TABLE if not exists events (id INT,name VARCHAR(255),region VARCHAR(255),attendance INT); INSERT INTO events (id,name,region,attendance) VALUES (1,'Ballet','Northeast',200),(2,'Tango','Southwest',150),(3,'Salsa','Southeast',250),(4,'Hip Hop','Northwest',120);
|
SELECT region, MAX(attendance) FROM events WHERE name LIKE '%dance%';
|
What is the average arrival time of flights for each airline?
|
CREATE TABLE Flights (Airline VARCHAR(255),ArrivalTime TIME);
|
SELECT Airline, AVG(ArrivalTime) OVER (PARTITION BY Airline) AS AvgArrivalTime FROM Flights;
|
What is the average policy advocacy expenditure per region, partitioned by fiscal year and ordered from highest to lowest?
|
CREATE TABLE Policy_Advocacy (Fiscal_Year INT,Region VARCHAR(10),Expenditure DECIMAL(7,2)); INSERT INTO Policy_Advocacy VALUES (2022,'Northeast',50000.00),(2022,'Southeast',40000.00),(2023,'Northeast',55000.00),(2023,'Southeast',45000.00);
|
SELECT Fiscal_Year, Region, AVG(Expenditure) as Avg_Expenditure, RANK() OVER (PARTITION BY Fiscal_Year ORDER BY AVG(Expenditure) DESC) as Rank FROM Policy_Advocacy GROUP BY Fiscal_Year, Region ORDER BY Fiscal_Year, Avg_Expenditure DESC;
|
What is the total circular economy initiatives count for the year 2018 for countries in Africa with a population between 5 and 15 million?
|
CREATE TABLE circular_economy(country VARCHAR(20),year INT,population INT,initiatives INT); INSERT INTO circular_economy(country,year,population,initiatives) VALUES ('Nigeria',2018,196,15),('Ethiopia',2018,114,12),('Egypt',2018,102,18),('South Africa',2018,58,23),('Kenya',2018,53,19),('Tanzania',2018,58,14),('Uganda',2018,45,11),('Algeria',2018,43,16),('Sudan',2018,41,10),('Morocco',2018,36,15);
|
SELECT SUM(initiatives) FROM circular_economy WHERE year = 2018 AND population BETWEEN 5000000 AND 15000000 GROUP BY year;
|
Find the top 3 factories with the highest recycling rate in the past month.
|
CREATE TABLE factories (id INT,name VARCHAR(255),recycling_rate DECIMAL(10,2));CREATE TABLE recycling_reports (id INT,factory_id INT,report_date DATE);
|
SELECT factories.name, factories.recycling_rate FROM factories INNER JOIN recycling_reports ON factories.id = recycling_reports.factory_id WHERE recycling_reports.report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY factories.id ORDER BY factories.recycling_rate DESC LIMIT 3;
|
Which countries have more than 75 violations of maritime laws related to plastic waste disposal?
|
CREATE TABLE Maritime_Laws (id INT PRIMARY KEY,country VARCHAR(255),law_name VARCHAR(255),description TEXT); CREATE TABLE Vessel_Violations (id INT PRIMARY KEY,vessel_id INT,maritime_law_id INT,violation_date DATE,FOREIGN KEY (vessel_id) REFERENCES Vessels(id),FOREIGN KEY (maritime_law_id) REFERENCES Maritime_Laws(id));
|
SELECT Maritime_Laws.country, COUNT(Vessel_Violations.id) FROM Maritime_Laws JOIN Vessel_Violations ON Maritime_Laws.id = Vessel_Violations.maritime_law_id WHERE law_name LIKE '%plastic%' GROUP BY Maritime_Laws.country HAVING COUNT(Vessel_Violations.id) > 75;
|
What is the total investment in rural infrastructure in Brazil for the past decade, grouped by year?
|
CREATE TABLE rural_infrastructure (country TEXT,year INT,investment NUMERIC); INSERT INTO rural_infrastructure (country,year,investment) VALUES ('Brazil',2012,1500000),('Brazil',2013,1700000),('Brazil',2014,1800000),('Brazil',2015,2000000),('Brazil',2016,2200000),('Brazil',2017,2400000),('Brazil',2018,2600000),('Brazil',2019,2800000),('Brazil',2020,3000000),('Brazil',2021,3200000);
|
SELECT year, SUM(investment) OVER (PARTITION BY NULL ORDER BY year) AS total_investment FROM rural_infrastructure WHERE country = 'Brazil' AND year BETWEEN 2012 AND 2021;
|
List the types of rural infrastructure projects and their respective budgets from the 'rural_infrastructure' table
|
CREATE TABLE rural_infrastructure (project_id INT,project_type VARCHAR(50),budget INT);
|
SELECT project_type, budget FROM rural_infrastructure;
|
List all customers who have never made a transaction?
|
CREATE TABLE Customers (CustomerID int,Name varchar(50),Age int); INSERT INTO Customers (CustomerID,Name,Age) VALUES (1,'John Smith',35),(2,'Jane Doe',42),(3,'Michael Lee',28); CREATE TABLE Transactions (TransactionID int,CustomerID int,Amount decimal(10,2)); INSERT INTO Transactions (TransactionID,CustomerID,Amount) VALUES (1,1,500.00),(2,1,750.00),(3,2,250.00),(4,2,1000.00);
|
SELECT Contexts.CustomerID, Contexts.Name FROM Contexts WHERE Contexts.CustomerID NOT IN (SELECT Transactions.CustomerID FROM Transactions) ORDER BY Contexts.CustomerID;
|
What is the total number of emergency responses for each disaster type?
|
CREATE TABLE emergency_responses (id INT PRIMARY KEY,disaster_id INT,response_type VARCHAR(50),FOREIGN KEY (disaster_id) REFERENCES disasters(id));
|
SELECT response_type, COUNT(*) as total_responses FROM emergency_responses er JOIN disasters d ON er.disaster_id = d.id GROUP BY response_type;
|
Delete a farmer and their related data in South Africa
|
CREATE TABLE Farmers (id INT PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(10),location VARCHAR(255),farmer_id INT); CREATE TABLE Equipment (id INT PRIMARY KEY,type VARCHAR(255),model VARCHAR(255),purchased_date DATE,last_service_date DATE,status VARCHAR(255),farmer_id INT,FOREIGN KEY (farmer_id) REFERENCES Farmers(farmer_id)); CREATE TABLE Fields (id INT PRIMARY KEY,acres FLOAT,crop VARCHAR(255),farmer_id INT,FOREIGN KEY (farmer_id) REFERENCES Farmers(farmer_id));
|
DELETE f, e, fd FROM Farmers f INNER JOIN Equipment e ON f.farmer_id = e.farmer_id INNER JOIN Fields fd ON f.farmer_id = fd.farmer_id WHERE f.name = 'Sipho Ndlovu';
|
What are the production forecasts for the wells in the North Sea, ranked by production volume in descending order for each production year?
|
CREATE TABLE production_forecasts (forecast_id INT,well_id INT,production_year INT,production_volume FLOAT,region VARCHAR(50)); INSERT INTO production_forecasts (forecast_id,well_id,production_year,production_volume,region) VALUES (5,5,2022,250.6,'North Sea'); INSERT INTO production_forecasts (forecast_id,well_id,production_year,production_volume,region) VALUES (6,6,2023,235.4,'North Sea');
|
SELECT forecast_id, well_id, production_year, production_volume, region, ROW_NUMBER() OVER (PARTITION BY production_year ORDER BY production_volume DESC) as rank FROM production_forecasts WHERE region = 'North Sea';
|
How many cultural heritage sites are preserved in Mexico?
|
CREATE TABLE heritage_sites(site_id INT,name TEXT,country TEXT,protected BOOLEAN); INSERT INTO heritage_sites (site_id,name,country,protected) VALUES (1,'Ancient Ruins','Mexico',TRUE),(2,'Historic Monastery','Spain',TRUE);
|
SELECT COUNT(*) FROM heritage_sites WHERE country = 'Mexico' AND protected = TRUE;
|
How many unique fabric sources are used in sustainable fashion production?
|
CREATE TABLE fabric_sources (source_id INT,sustainable BOOLEAN);CREATE VIEW sustainable_fabric_sources AS SELECT * FROM fabric_sources WHERE sustainable = TRUE;
|
SELECT COUNT(DISTINCT source_id) FROM sustainable_fabric_sources;
|
Which suppliers have no contracts?
|
CREATE TABLE Suppliers (SupplierID INT,SupplierName VARCHAR(100)); INSERT INTO Suppliers (SupplierID,SupplierName) VALUES (1,'Alpha Corp'),(2,'Beta Inc'),(3,'Charlie Ltd'); CREATE TABLE Contracts (ContractID INT,SupplierID INT); INSERT INTO Contracts (ContractID,SupplierID) VALUES (1,1),(2,2);
|
SELECT Suppliers.SupplierName FROM Suppliers LEFT JOIN Contracts ON Suppliers.SupplierID = Contracts.SupplierID WHERE Contracts.ContractID IS NULL;
|
What is the most common crime in Chicago?
|
CREATE TABLE chicago_crimes (id INT,crime_date DATE,crime_type VARCHAR(20)); INSERT INTO chicago_crimes (id,crime_date,crime_type) VALUES (1,'2022-02-01','Theft'),(2,'2022-02-15','Vandalism'),(3,'2022-02-15','Theft');
|
SELECT crime_type, COUNT(*) AS count FROM chicago_crimes GROUP BY crime_type ORDER BY count DESC LIMIT 1;
|
List the biosensor technology patents filed before 2020.
|
CREATE TABLE patents (technology TEXT,year INTEGER,filed BOOLEAN); INSERT INTO patents (technology,year,filed) VALUES ('BioSensor1',2019,true),('BioSensor2',2020,true),('BioSensor3',2018,false);
|
SELECT technology FROM patents WHERE year < 2020;
|
What was the average monthly wind energy production (in MWh) in 2021?
|
CREATE TABLE wind_energy (month INT,year INT,production FLOAT);
|
SELECT AVG(production) FROM wind_energy WHERE year = 2021 GROUP BY month;
|
What is the total amount of resources depleted for each mining site in Q2 of 2019?
|
CREATE TABLE Resources (ResourceID INT,Site VARCHAR(50),Quantity INT,DepletionDate DATE); INSERT INTO Resources (ResourceID,Site,Quantity,DepletionDate) VALUES (1,'Site A',500,'2019-04-15'); INSERT INTO Resources (ResourceID,Site,Quantity,DepletionDate) VALUES (2,'Site A',700,'2019-07-12'); INSERT INTO Resources (ResourceID,Site,Quantity,DepletionDate) VALUES (3,'Site B',300,'2019-03-01'); INSERT INTO Resources (ResourceID,Site,Quantity,DepletionDate) VALUES (4,'Site B',800,'2019-08-23');
|
SELECT Site, SUM(Quantity) FROM Resources WHERE MONTH(DepletionDate) BETWEEN 4 AND 6 GROUP BY Site;
|
Find the top 2 menu items with highest daily revenue.
|
CREATE TABLE menu_engineering (menu_item VARCHAR(30),daily_revenue DECIMAL(10,2)); INSERT INTO menu_engineering (menu_item,daily_revenue) VALUES ('Cheese Burger',250.00),('Veggie Pizza',300.00),('Garden Salad',150.00),('BBQ Ribs',400.00);
|
SELECT menu_item, daily_revenue FROM (SELECT menu_item, daily_revenue, ROW_NUMBER() OVER (ORDER BY daily_revenue DESC) as rn FROM menu_engineering) tmp WHERE rn <= 2;
|
What is the total number of members in unions that are involved in collective bargaining in Florida?
|
CREATE TABLE union_bargaining (id INT,union_name TEXT,state TEXT,involved_in_bargaining BOOLEAN); INSERT INTO union_bargaining (id,union_name,state,involved_in_bargaining) VALUES (1,'Union D','Florida',true),(2,'Union E','Florida',false),(3,'Union F','Florida',true);
|
SELECT SUM(involved_in_bargaining) FROM union_bargaining WHERE state = 'Florida';
|
How many unique volunteers were engaged in each program in Q3 2022?
|
CREATE TABLE Volunteers (id INT,program VARCHAR(50),volunteer VARCHAR(50),engagement_date DATE); INSERT INTO Volunteers (id,program,volunteer,engagement_date) VALUES (1,'Arts Education','John Smith','2022-07-05'),(2,'Environment','Jane Doe','2022-07-07'),(3,'Arts Education','Sara Connor','2022-07-10'),(4,'Environment','James Lee','2022-07-12');
|
SELECT program, DATE_FORMAT(engagement_date, '%Y-%m') as quarter, COUNT(DISTINCT volunteer) as unique_volunteers FROM Volunteers WHERE engagement_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY program, quarter;
|
Delete the workout_equipment table
|
CREATE TABLE workout_equipment (id INT,member_id INT,equipment_name VARCHAR(50));
|
DROP TABLE workout_equipment;
|
Which locations in South Africa had the highest drought impact in the last 10 years?
|
CREATE TABLE drought_impact_south_africa(id INT,location VARCHAR(50),impact FLOAT,year INT); INSERT INTO drought_impact_south_africa(id,location,impact,year) VALUES (1,'Cape Town',28.1,2018);
|
SELECT location, MAX(impact) as max_impact FROM drought_impact_south_africa WHERE year BETWEEN (SELECT MAX(year) - 10 FROM drought_impact_south_africa) AND MAX(year) GROUP BY location ORDER BY max_impact DESC;
|
What are the total research grant funds awarded to faculty members in the Mathematics department?
|
CREATE SCHEMA research;CREATE TABLE grants(faculty_name TEXT,department TEXT,amount INTEGER);INSERT INTO grants(faculty_name,department,amount)VALUES('Charlie','Mathematics',100000),('Dave','Physics',200000);
|
SELECT SUM(amount) FROM research.grants WHERE department='Mathematics';
|
How many patients in each state received medication for depression?
|
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,state TEXT,condition TEXT,medication TEXT); INSERT INTO patients (patient_id,age,gender,state,condition,medication) VALUES (1,30,'Female','Texas','Depression','Yes'); INSERT INTO patients (patient_id,age,gender,state,condition,medication) VALUES (2,45,'Male','Texas','Anxiety','No'); INSERT INTO patients (patient_id,age,gender,state,condition,medication) VALUES (3,50,'Non-binary','California','Depression','Yes');
|
SELECT state, COUNT(*) FROM patients WHERE condition = 'Depression' AND medication = 'Yes' GROUP BY state;
|
Show the number of wind farms in Oklahoma
|
CREATE TABLE Infrastructure (id INT,name VARCHAR(100),type VARCHAR(50),location VARCHAR(100),state VARCHAR(50)); INSERT INTO Infrastructure (id,name,type,location,state) VALUES (9,'Western Plains Wind Farm','Wind Farm','Woodward','Oklahoma');
|
SELECT COUNT(*) FROM Infrastructure WHERE type = 'Wind Farm' AND state = 'Oklahoma';
|
Find the minimum retail price of hemp garments in the UK
|
CREATE TABLE garments (id INT,garment_type VARCHAR(255),material VARCHAR(255),price DECIMAL(5,2),country VARCHAR(255));
|
SELECT MIN(price) FROM garments WHERE garment_type = 'Shirt' AND material = 'Hemp' AND country = 'United Kingdom';
|
How many hospitals are there in Florida and Massachusetts?
|
CREATE TABLE hospitals (id INT,name TEXT,city TEXT,state TEXT,beds INT); INSERT INTO hospitals (id,name,city,state,beds) VALUES (1,'General Hospital','Miami','Florida',500); INSERT INTO hospitals (id,name,city,state,beds) VALUES (2,'Memorial Hospital','Boston','Massachusetts',600);
|
SELECT state, COUNT(*) as hospital_count FROM hospitals WHERE state IN ('Florida', 'Massachusetts') GROUP BY state;
|
How many properties are for sale in Oakland?
|
CREATE TABLE properties_for_sale (id INT,property_id INT,city TEXT,state TEXT,is_for_sale BOOLEAN);
|
SELECT COUNT(*) FROM properties_for_sale WHERE city = 'Oakland' AND is_for_sale = TRUE;
|
What is the percentage of hotels in MEA region that have adopted mobile check-in?
|
CREATE TABLE hotels_3 (hotel_id INT,hotel_name TEXT,region TEXT,has_mobile_checkin BOOLEAN); INSERT INTO hotels_3 (hotel_id,hotel_name,region,has_mobile_checkin) VALUES (1,'Hotel C','MEA',true),(2,'Hotel D','MEA',false);
|
SELECT (COUNT(*) FILTER (WHERE has_mobile_checkin = true) * 100.0 / COUNT(*))::decimal(5,2) as percentage FROM hotels_3 WHERE region = 'MEA';
|
Find the lanthanum production difference between 2018 and 2017 for each processor.
|
CREATE TABLE LanthanumProduction (Processor VARCHAR(50),Year INT,Production FLOAT); INSERT INTO LanthanumProduction(Processor,Year,Production) VALUES ('ProcessorA',2017,451.5),('ProcessorA',2018,456.7),('ProcessorA',2019,462.1),('ProcessorB',2017,389.1),('ProcessorB',2018,393.5),('ProcessorB',2019,399.8);
|
SELECT Processor, Production - LAG(Production) OVER (PARTITION BY Processor ORDER BY Year) as Difference FROM LanthanumProduction WHERE Processor IN ('ProcessorA', 'ProcessorB');
|
How many posts were made by users with more than 10,000 followers, in the past week, that contain the word "travel"?
|
CREATE TABLE accounts (id INT,name VARCHAR(255),followers INT); CREATE TABLE posts (id INT,account_id INT,content TEXT,timestamp TIMESTAMP); INSERT INTO accounts (id,name,followers) VALUES (1,'user1',15000); INSERT INTO posts (id,account_id,content,timestamp) VALUES (1,1,'post1 with travel','2022-05-01 12:00:00');
|
SELECT COUNT(*) FROM posts JOIN accounts ON posts.account_id = accounts.id WHERE accounts.followers > 10000 AND posts.timestamp >= NOW() - INTERVAL '1 week' AND posts.content LIKE '%travel%';
|
Which mine has the highest copper reserves?
|
CREATE TABLE Resource_Depletion(Mine_Name TEXT,Reserves_Copper INT,Reserves_Gold INT); INSERT INTO Resource_Depletion(Mine_Name,Reserves_Copper,Reserves_Gold) VALUES('Tasiast',2500000,15000); INSERT INTO Resource_Depletion(Mine_Name,Reserves_Copper,Reserves_Gold) VALUES('Katanga',3500000,20000);
|
SELECT Mine_Name, Reserves_Copper FROM Resource_Depletion ORDER BY Reserves_Copper DESC LIMIT 1;
|
What is the percentage of the population that is obese in each country in the European region?
|
CREATE TABLE countries (id INT,name TEXT,region TEXT,obesity_rate INT); INSERT INTO countries (id,name,region,obesity_rate) VALUES (1,'France','Europe',25); INSERT INTO countries (id,name,region,obesity_rate) VALUES (2,'Germany','Europe',30);
|
SELECT name, region, obesity_rate FROM countries WHERE region = 'Europe';
|
What is the total revenue generated from customers in the Asia-Pacific region?
|
CREATE TABLE customers (customer_id INT,name VARCHAR(100),region VARCHAR(50)); INSERT INTO customers (customer_id,name,region) VALUES (1,'John Doe','Asia-Pacific'),(2,'Jane Smith','Europe'),(3,'Alice Johnson','Asia-Pacific'); CREATE TABLE sales (sale_id INT,customer_id INT,revenue DECIMAL(10,2)); INSERT INTO sales (sale_id,customer_id,revenue) VALUES (1,1,500),(2,1,750),(3,2,600),(4,3,800),(5,3,900);
|
SELECT SUM(sales.revenue) FROM sales JOIN customers ON sales.customer_id = customers.customer_id WHERE customers.region = 'Asia-Pacific';
|
What is the minimum number of visitors for an exhibition?
|
CREATE TABLE Exhibitions (id INT,name TEXT,visitor_count INT); INSERT INTO Exhibitions (id,name,visitor_count) VALUES (1,'Dinosaurs',1000),(2,'Egypt',800);
|
SELECT MIN(visitor_count) FROM Exhibitions;
|
List the number of unique electric vehicle models and their average price in the vehicle_sales and autonomous_vehicles tables.
|
CREATE TABLE vehicle_sales (id INT,vehicle_model VARCHAR(50),vehicle_type VARCHAR(50),price FLOAT); INSERT INTO vehicle_sales (id,vehicle_model,vehicle_type,price) VALUES (1,'Tesla Model 3','electric',45000),(2,'Nissan Leaf','electric',30000),(3,'Honda Civic','gasoline',25000),(4,'Toyota Prius','hybrid',35000); CREATE TABLE autonomous_vehicles (id INT,vehicle_model VARCHAR(50),vehicle_type VARCHAR(50),price FLOAT); INSERT INTO autonomous_vehicles (id,vehicle_model,vehicle_type,price) VALUES (1,'Wayve Pod','electric',150000),(2,'Nuro R2','electric',120000),(3,'Zoox','electric',180000),(4,'Aptiv','autonomous',160000),(5,'Baidu Apollo','autonomous',140000);
|
SELECT COUNT(DISTINCT vehicle_model) AS unique_models, AVG(price) AS average_price FROM (SELECT vehicle_model, price FROM vehicle_sales WHERE vehicle_type = 'electric' UNION ALL SELECT vehicle_model, price FROM autonomous_vehicles WHERE vehicle_type = 'electric');
|
What is the average temperature change in the Arctic region for each month since 2000?
|
CREATE TABLE temperature_data (id INT,date DATE,arctic_region VARCHAR(255),temperature FLOAT); INSERT INTO temperature_data (id,date,arctic_region,temperature) VALUES (1,'2000-01-01','North Pole',-25.0),(2,'2000-02-01','North Pole',-28.5);
|
SELECT EXTRACT(MONTH FROM date) AS month, AVG(temperature) FROM temperature_data WHERE date >= '2000-01-01' GROUP BY month;
|
What is the maximum number of accommodations provided to a single student?
|
CREATE TABLE Students (student_id INT,department VARCHAR(255)); CREATE TABLE Accommodations (accommodation_id INT,student_id INT,accommodation_type VARCHAR(255));
|
SELECT MAX(accommodation_count) as max_accommodations FROM ( SELECT student_id, COUNT(accommodation_id) as accommodation_count FROM Accommodations GROUP BY student_id ) as subquery;
|
What is the maximum number of attendees for any theater performance in the last month?
|
CREATE TABLE TheaterPerformances (performanceID INT,attendeeCount INT,performanceDate DATE); INSERT INTO TheaterPerformances (performanceID,attendeeCount,performanceDate) VALUES (1,120,'2022-03-01'),(2,80,'2022-02-15'),(3,150,'2022-01-10');
|
SELECT MAX(attendeeCount) FROM TheaterPerformances WHERE performanceDate >= DATEADD(month, -1, GETDATE());
|
Find incidents related to electrical issues in the Avionics department.
|
CREATE TABLE Incidents (IncidentID INT,Date DATE,Type VARCHAR(20),Description TEXT,Department VARCHAR(20)); INSERT INTO Incidents (IncidentID,Date,Type,Description,Department) VALUES (1,'2021-05-01','Electrical','Power distribution failure','Avionics');
|
SELECT * FROM Incidents WHERE Department = 'Avionics' AND Type = 'Electrical'
|
Which countries have the most ethical labor practices?
|
CREATE TABLE countries (country_id INT,country TEXT,ethical_practice_score INT); INSERT INTO countries (country_id,country,ethical_practice_score) VALUES (1,'Italy',85); INSERT INTO countries (country_id,country,ethical_practice_score) VALUES (2,'France',90); INSERT INTO countries (country_id,country,ethical_practice_score) VALUES (3,'Spain',80); INSERT INTO countries (country_id,country,ethical_practice_score) VALUES (4,'Portugal',95); INSERT INTO countries (country_id,country,ethical_practice_score) VALUES (5,'Greece',75);
|
SELECT country, MAX(ethical_practice_score) FROM countries GROUP BY country;
|
What is the minimum playtime for players who have played games with a price greater than 50, by gender?
|
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'),(2,30,'Female','Canada'),(3,22,'Male','Mexico'); CREATE TABLE GamePlay (PlayerID INT,Playtime INT,GamePrice DECIMAL(5,2)); INSERT INTO GamePlay (PlayerID,Playtime,GamePrice) VALUES (1,120,60.00),(2,90,45.00),(3,150,55.00),(4,100,70.00),(5,80,75.00);
|
SELECT Gender, MIN(Playtime) FROM Players INNER JOIN GamePlay ON Players.PlayerID = GamePlay.PlayerID WHERE GamePrice > 50 GROUP BY Gender;
|
List all smart contracts associated with decentralized applications that have been involved in regulatory actions in the Arctic region.
|
CREATE TABLE smart_contracts (contract_id INT,dapp_id INT,contract_name VARCHAR(50),region VARCHAR(50)); CREATE TABLE regulatory_actions (action_id INT,contract_id INT,action_date DATE);
|
SELECT s.contract_name FROM smart_contracts s INNER JOIN regulatory_actions r ON s.contract_id = r.contract_id WHERE s.region = 'Arctic';
|
What is the total water usage for cities in Texas on January 15, 2022?
|
CREATE TABLE WaterUsage (Id INT PRIMARY KEY,City VARCHAR(255),Usage FLOAT,Date DATE); INSERT INTO WaterUsage (Id,City,Usage,Date) VALUES (1,'Dallas',1200,'2022-01-15'); INSERT INTO WaterUsage (Id,City,Usage,Date) VALUES (2,'Houston',1500,'2022-01-15'); INSERT INTO WaterUsage (Id,City,Usage,Date) VALUES (3,'Austin',1800,'2022-01-15');
|
SELECT City, SUM(Usage) FROM WaterUsage WHERE Date = '2022-01-15' AND City IN ('Dallas', 'Houston', 'Austin') GROUP BY City;
|
What is the average water temperature in the Arctic Ocean for the months of June, July, and August since 2010?
|
CREATE TABLE weather (id INT PRIMARY KEY,location VARCHAR(255),temperature DECIMAL(5,2),measurement_date DATE); INSERT INTO weather (id,location,temperature,measurement_date) VALUES (1,'Arctic Ocean',2.1,'2010-06-01'),(2,'Arctic Ocean',3.5,'2010-07-01'),(3,'Arctic Ocean',4.2,'2010-08-01');
|
SELECT AVG(temperature) FROM weather WHERE location = 'Arctic Ocean' AND EXTRACT(MONTH FROM measurement_date) IN (6, 7, 8) AND EXTRACT(YEAR FROM measurement_date) >= 2010;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.