instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
How many users have posted more than 10 times in 'Twitter' or 'Pinterest' in the last month? | CREATE TABLE Twitter(id INT,user_id INT,post_time TIMESTAMP,content TEXT); CREATE TABLE Pinterest(id INT,user_id INT,post_time TIMESTAMP,content TEXT); | SELECT COUNT(DISTINCT user_id) FROM (SELECT user_id FROM Twitter WHERE post_time >= NOW() - INTERVAL '1 month' GROUP BY user_id HAVING COUNT(*) > 10 UNION ALL SELECT user_id FROM Pinterest WHERE post_time >= NOW() - INTERVAL '1 month' GROUP BY user_id HAVING COUNT(*) > 10) AS total_users; |
Delete records with landfill capacity below 50000 in 'landfill_capacity' table for 2019. | CREATE TABLE landfill_capacity (year INT,location TEXT,capacity INT); INSERT INTO landfill_capacity (year,location,capacity) VALUES (2019,'SiteA',60000),(2019,'SiteB',45000),(2019,'SiteC',52000),(2020,'SiteA',62000),(2020,'SiteB',46000),(2020,'SiteC',53000); | DELETE FROM landfill_capacity WHERE year = 2019 AND capacity < 50000; |
How many smart contracts have been deployed on the Binance Smart Chain in the last month? | CREATE TABLE SmartContracts (id INT,blockchain VARCHAR(50),address VARCHAR(100),deployment_date DATE); INSERT INTO SmartContracts (id,blockchain,address,deployment_date) VALUES (1,'Binance Smart Chain','0x123...','2022-01-01'),(2,'Binance Smart Chain','0x456...','2022-02-10'); | SELECT COUNT(*) FROM SmartContracts WHERE blockchain = 'Binance Smart Chain' AND deployment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
Get the details of the defense contract with the second highest value | CREATE TABLE second_highest_contracts (id INT,contract_type VARCHAR(255),contract_value INT); INSERT INTO second_highest_contracts (id,contract_type,contract_value) VALUES (1,'Service',5000000),(2,'Supply',7000000),(3,'Research',6000000); | SELECT * FROM second_highest_contracts WHERE contract_value = (SELECT MAX(contract_value) FROM second_highest_contracts WHERE contract_value < (SELECT MAX(contract_value) FROM second_highest_contracts)); |
What was the total revenue generated from events in the Atlantic region in Q1 2020? | CREATE TABLE Events (event_id INT,region VARCHAR(50),revenue DECIMAL(10,2),event_date DATE); INSERT INTO Events (event_id,region,revenue,event_date) VALUES (50,'Atlantic',12000,'2020-01-01'),(51,'Atlantic',15000,'2020-02-01'),(52,'Central',10000,'2020-01-01'); | SELECT SUM(revenue) FROM Events WHERE region = 'Atlantic' AND MONTH(event_date) BETWEEN 1 AND 3; |
What is the maximum temperature of pallets stored in Warehouse C? | CREATE TABLE WarehouseTemperatureC (id INT,temperature FLOAT,location VARCHAR(20)); INSERT INTO WarehouseTemperatureC (id,temperature,location) VALUES (1,30,'Warehouse C'),(2,25,'Warehouse D'); | SELECT MAX(temperature) FROM WarehouseTemperatureC WHERE location = 'Warehouse C'; |
Find the name and height of the five shortest buildings in Tokyo, Japan. | CREATE TABLE Buildings (BuildingID INT,Name TEXT,Height INT,City TEXT,Country TEXT); INSERT INTO Buildings (BuildingID,Name,Height,City,Country) VALUES (1,'BuildingA',300,'Tokyo','Japan'); INSERT INTO Buildings (BuildingID,Name,Height,City,Country) VALUES (2,'BuildingB',250,'Tokyo','Japan'); INSERT INTO Buildings (BuildingID,Name,Height,City,Country) VALUES (3,'BuildingC',400,'Tokyo','Japan'); | SELECT Name, Height FROM Buildings WHERE Country = 'Japan' AND City = 'Tokyo' ORDER BY Height ASC LIMIT 5; |
update Donors set Donation_Amount = Donation_Amount * 1.10 where Country = 'USA' | CREATE TABLE Donors (Donor_ID int,Name varchar(50),Donation_Amount decimal(10,2),Country varchar(50)); INSERT INTO Donors (Donor_ID,Name,Donation_Amount,Country) VALUES (1,'John Doe',7000,'USA'),(2,'Jane Smith',3000,'Canada'),(3,'Mike Johnson',4000,'USA'); | UPDATE Donors SET Donation_Amount = Donation_Amount * 1.10 WHERE Country = 'USA'; |
What is the total number of workers in the supply chain for sustainable wood sources? | CREATE TABLE SupplyChainWorkers (id INT,sustainable_wood BOOLEAN,num_workers INT); | SELECT SUM(num_workers) FROM SupplyChainWorkers WHERE sustainable_wood = TRUE; |
What is the change in the number of criminal justice reform events per month in a given year? | CREATE TABLE CriminalJusticeReformEvents (id INT,event_date DATE,events INT); INSERT INTO CriminalJusticeReformEvents (id,event_date,events) VALUES (1,'2022-01-01',10),(2,'2022-02-01',15),(3,'2022-03-01',18),(4,'2022-04-01',20),(5,'2022-05-01',25),(6,'2022-06-01',28),(7,'2022-07-01',30),(8,'2022-08-01',35),(9,'2022-09-01',38),(10,'2022-10-01',40),(11,'2022-11-01',45),(12,'2022-12-01',48); | SELECT EXTRACT(MONTH FROM event_date) as month, (LEAD(events) OVER (ORDER BY event_date) - events) as change FROM CriminalJusticeReformEvents WHERE EXTRACT(YEAR FROM event_date) = 2022; |
What is the highest number of goals scored by a cricket player in a single season in the IPL, by team? | CREATE TABLE ipl_batters (batter_id INT,batter_name VARCHAR(50),team_id INT,season INT,goals INT); INSERT INTO ipl_batters (batter_id,batter_name,team_id,season,goals) VALUES (1,'Virat Kohli',1,2019,46),(2,'David Warner',2,2019,692); | SELECT team_id, MAX(goals) FROM ipl_batters GROUP BY team_id; |
What are the details of cybersecurity incidents in the last 6 months? | CREATE TABLE cybersecurity_incidents (id INT,incident_type VARCHAR(50),incident_date DATE); INSERT INTO cybersecurity_incidents (id,incident_type,incident_date) VALUES (1,'Phishing','2022-01-05'),(2,'Malware','2022-03-17'),(3,'Ransomware','2022-05-29'); | SELECT * FROM cybersecurity_incidents WHERE incident_date >= DATE(NOW()) - INTERVAL 6 MONTH; |
What are the ingredient sources for all vegan cosmetic products in the US market? | CREATE TABLE ingredients (product_id INT,ingredient VARCHAR(50),source_country VARCHAR(50)); CREATE TABLE products (product_id INT,is_vegan BOOLEAN,market VARCHAR(10)); INSERT INTO ingredients (product_id,ingredient,source_country) VALUES (1,'Vitamin E','Brazil'),(2,'Beeswax','France'),(3,'Mica','India'); INSERT INTO products (product_id,is_vegan,market) VALUES (1,true,'US'),(2,false,'CA'),(3,true,'US'); | SELECT i.ingredient, i.source_country FROM ingredients i JOIN products p ON i.product_id = p.product_id WHERE p.is_vegan = true AND p.market = 'US'; |
How many patients were treated with therapy in 2020? | CREATE TABLE patients (id INT,name TEXT,age INT,treatment TEXT,treated_year INT); INSERT INTO patients (id,name,age,treatment,treated_year) VALUES (1,'John Doe',35,'CBT',2020),(2,'Jane Smith',40,'DBT',2021); | SELECT COUNT(*) FROM patients WHERE treatment LIKE '%CBT%' OR treatment LIKE '%DBT%' AND treated_year = 2020; |
What is the total number of mental health parity violations and the total number of patients treated for mental health issues in each community? | CREATE TABLE ParityViolations (ViolationID int,CommunityID int,ViolationCount int);CREATE TABLE CommunityMentalHealth (CommunityID int,PatientID int); | SELECT CommunityID, SUM(ViolationCount) as TotalViolations, COUNT(PatientID) as PatientCount FROM ParityViolations JOIN CommunityMentalHealth ON ParityViolations.CommunityID = CommunityMentalHealth.CommunityID GROUP BY CommunityID; |
What is the total oil production in the North Sea in 2020? | CREATE TABLE production_figures (well_id INT,year INT,oil_production INT,gas_production INT); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (1,2019,120000,50000); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (2,2018,130000,60000); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (3,2020,110000,45000); | SELECT SUM(oil_production) FROM production_figures WHERE year = 2020 AND region = 'North Sea'; |
What are the names and production quantities of the top 5 producing wells in the North Sea? | CREATE TABLE wells (well_id INT,well_name TEXT,production_qty FLOAT,region TEXT); INSERT INTO wells (well_id,well_name,production_qty,region) VALUES (1,'Well A',1000,'North Sea'),(2,'Well B',1500,'North Sea'),(3,'Well C',800,'North Sea'); | SELECT well_name, production_qty FROM wells WHERE region = 'North Sea' ORDER BY production_qty DESC LIMIT 5; |
Which members joined the gym in January 2022, but have not attended any workout sessions since then? | CREATE TABLE Members (MemberID INT,FirstName VARCHAR(50),LastName VARCHAR(50),DateJoined DATE); INSERT INTO Members (MemberID,FirstName,LastName,DateJoined) VALUES (1,'John','Doe','2022-01-10'); INSERT INTO Members (MemberID,FirstName,LastName,DateJoined) VALUES (2,'Jane','Doe','2022-01-15'); CREATE TABLE Workouts (WorkoutID INT,MemberID INT,WorkoutDate DATE); INSERT INTO Workouts (WorkoutID,MemberID,WorkoutDate) VALUES (1,1,'2022-01-12'); | SELECT m.MemberID, m.FirstName, m.LastName FROM Members m LEFT JOIN Workouts w ON m.MemberID = w.MemberID WHERE m.DateJoined >= '2022-01-01' AND m.DateJoined < '2022-02-01' AND w.WorkoutDate IS NULL; |
Find the number of clinical trials initiated per month in 2021, with a 12-month trailing average. | CREATE TABLE clinical_trial_timeline (id INT,trial_initiation_date DATE,trial_type VARCHAR(255)); | SELECT trial_initiation_date, COUNT(*) OVER (PARTITION BY trial_initiation_date ORDER BY trial_initiation_date ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) as moving_avg_trials_per_month FROM clinical_trial_timeline WHERE trial_initiation_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY trial_initiation_date ORDER BY trial_initiation_date; |
Insert new dish 'Rajma Masala' with ingredients: Rajma, Onions, Tomatoes, Garlic, Ginger, Turmeric, Garam Masala, Salt, Oil. | CREATE TABLE dishes (dish_id INT PRIMARY KEY,dish_name VARCHAR(50)); INSERT INTO dishes (dish_id,dish_name) VALUES (1,'Soy Milk Smoothie'),(2,'Tofu Curry'); CREATE TABLE dishes_ingredients (dish_id INT,ingredient_id INT,quantity INT); | INSERT INTO dishes (dish_id, dish_name) VALUES (3, 'Rajma Masala'); INSERT INTO dishes_ingredients (dish_id, ingredient_id, quantity) VALUES (3, 5, 300), (3, 6, 150), (3, 1, 150), (3, 7, 50), (3, 8, 25), (3, 9, 25), (3, 10, 2), (3, 11, 50), (3, 12, 50); |
What is the average price of foundation products with SPF 30 or higher? | CREATE TABLE Foundations (product_id INT,product_name VARCHAR(255),spf INT,price DECIMAL(10,2)); INSERT INTO Foundations (product_id,product_name,spf,price) VALUES (1,'Foundation 1',15,25.99),(2,'Foundation 2',30,35.99),(3,'Foundation 3',20,29.99),(4,'Foundation 4',50,45.99); | SELECT AVG(price) FROM Foundations WHERE spf >= 30; |
List all species in the 'Endangered' status from the 'conservation_status' table. | CREATE TABLE conservation_status (species_id INTEGER,species_name VARCHAR(255),status VARCHAR(50)); | SELECT species_name FROM conservation_status WHERE status = 'Endangered'; |
What is the percentage of the population with health insurance in California? | CREATE TABLE health_insurance (id INT,insured BOOLEAN,state TEXT); INSERT INTO health_insurance (id,insured,state) VALUES (1,true,'California'); INSERT INTO health_insurance (id,insured,state) VALUES (2,false,'California'); | SELECT (SUM(insured) * 100.0 / COUNT(*)) FROM health_insurance WHERE state = 'California'; |
How many faculty members work in the 'humanities' department? | CREATE TABLE department (id INT,name TEXT); INSERT INTO department (id,name) VALUES (1,'sciences'),(2,'humanities'),(3,'engineering'); CREATE TABLE faculty (id INT,department_id INT); INSERT INTO faculty (id,department_id) VALUES (1,1),(2,1),(3,2),(4,2),(5,3); | SELECT COUNT(*) FROM faculty WHERE department_id = (SELECT id FROM department WHERE name = 'humanities'); |
What is the average financial capability score for customers? | CREATE TABLE customers (customer_id INT,name VARCHAR(50),financial_capability_score INT); INSERT INTO customers (customer_id,name,financial_capability_score) VALUES (101,'John Doe',75),(102,'Jane Smith',80); | SELECT AVG(financial_capability_score) FROM customers; |
Find the first non-repeat customer for each branch in 2021. | CREATE TABLE branches (id INT,name VARCHAR(255)); CREATE TABLE customers (id INT,name VARCHAR(255),branch_id INT,transaction_date DATE); | SELECT ROW_NUMBER() OVER (PARTITION BY branch_id ORDER BY transaction_date) as rn, c.* FROM customers c WHERE c.transaction_date >= '2021-01-01' AND c.transaction_date < '2022-01-01' AND rn = 1; |
Find the total number of streams for Hip Hop artists in France and Germany combined in 2022. | CREATE TABLE streams (id INT,artist VARCHAR(50),country VARCHAR(50),streams INT,year INT); INSERT INTO streams (id,artist,country,streams,year) VALUES (1,'Booba','France',3000000,2022); INSERT INTO streams (id,artist,country,streams,year) VALUES (2,'Stromae','Belgium',4000000,2022); INSERT INTO streams (id,artist,country,streams,year) VALUES (3,'Kollegah','Germany',5000000,2022); INSERT INTO streams (id,artist,country,streams,year) VALUES (4,'Farid Bang','Germany',6000000,2022); | SELECT SUM(streams) FROM streams WHERE genre = 'Hip Hop' AND (country = 'France' OR country = 'Germany') AND year = 2022; |
Which Tilapia Farm has the highest dissolved oxygen level? | CREATE TABLE Tilapia_Farms (Farm_ID INT,Farm_Name TEXT,Dissolved_Oxygen FLOAT); INSERT INTO Tilapia_Farms (Farm_ID,Farm_Name,Dissolved_Oxygen) VALUES (1,'Farm C',7.5); INSERT INTO Tilapia_Farms (Farm_ID,Farm_Name,Dissolved_Oxygen) VALUES (2,'Farm D',8.0); INSERT INTO Tilapia_Farms (Farm_ID,Farm_Name,Dissolved_Oxygen) VALUES (3,'Farm E',7.0); | SELECT Farm_Name, MAX(Dissolved_Oxygen) FROM Tilapia_Farms; |
Find the total cost of satellite deployment projects. | CREATE TABLE SatelliteProjects (project_id INT,launch_cost INT,satellite_cost INT); | SELECT project_id, launch_cost + satellite_cost AS total_cost FROM SatelliteProjects; |
What is the maximum revenue generated by a single cultural heritage site in Greece? | CREATE TABLE cultural_heritage_greece (id INT,country VARCHAR(20),site VARCHAR(20),revenue FLOAT); INSERT INTO cultural_heritage_greece (id,country,site,revenue) VALUES (1,'Greece','Acropolis',3000.0),(2,'Greece','Parthenon',2500.0),(3,'Greece','Epidaurus',2000.0); | SELECT MAX(revenue) FROM cultural_heritage_greece WHERE country = 'Greece'; |
How many virtual tours were engaged in 'Paris'? | CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,city TEXT,engagement INT); INSERT INTO virtual_tours (tour_id,hotel_id,city,engagement) VALUES (1,3,'Paris',200),(2,3,'Paris',250),(3,4,'Rome',150); | SELECT SUM(engagement) FROM virtual_tours WHERE city = 'Paris'; |
Find properties with size less than 1000 sq ft in affordable_homes table. | CREATE TABLE affordable_homes (id INT,size FLOAT,location VARCHAR(255)); INSERT INTO affordable_homes (id,size,location) VALUES (1,1200.0,'San Francisco'),(2,900.0,'New York'),(3,1300.0,'Los Angeles'),(4,800.0,'New York'); | SELECT * FROM affordable_homes WHERE size < 1000; |
Update the basketball player's points for a specific game. | CREATE TABLE Players (player_id INTEGER,name TEXT,team TEXT); INSERT INTO Players (player_id,name,team) VALUES (1,'Player 1','Team A'),(2,'Player 2','Team A'),(3,'Player 3','Team B'); CREATE TABLE Games (game_id INTEGER,team TEXT,player_id INTEGER,points INTEGER); INSERT INTO Games (game_id,team,player_id,points) VALUES (1,'Team A',1,20),(1,'Team A',2,15),(1,'Team A',3,5); | UPDATE Games SET points = 25 WHERE game_id = 1 AND player_id = 1; |
What is the percentage of patients in each region who have visited a hospital or clinic in the past year, grouped by region? | CREATE TABLE patients (patient_id INT,region VARCHAR(20),visited_last_year BOOLEAN); INSERT INTO patients (patient_id,region,visited_last_year) VALUES (1,'Rural',true),(2,'Urban',false),(3,'Rural',true); CREATE TABLE hospitals (hospital_id INT,region VARCHAR(20),beds INT); INSERT INTO hospitals (hospital_id,region,beds) VALUES (1,'Rural',50),(2,'Urban',100); CREATE TABLE clinics (clinic_id INT,region VARCHAR(20),beds INT); INSERT INTO clinics (clinic_id,region,beds) VALUES (1,'Rural',10),(2,'Urban',20); CREATE TABLE visits (patient_id INT,hospital_id INT,clinic_id INT,visit_year INT); INSERT INTO visits (patient_id,hospital_id,clinic_id,visit_year) VALUES (1,1,NULL,2022),(2,NULL,2,2022),(3,1,NULL,2022); | SELECT s.region, (COUNT(p.patient_id) FILTER (WHERE p.visited_last_year = true) * 100.0 / COUNT(p.patient_id)) as percentage FROM patients p JOIN hospitals h ON p.region = h.region JOIN clinics c ON p.region = c.region JOIN states s ON p.region = s.region JOIN visits v ON p.patient_id = v.patient_id WHERE v.visit_year = 2022 GROUP BY s.region; |
Drop the table for European landfill capacities. | CREATE TABLE european_cities_landfill_capacity (city VARCHAR(20),capacity INT); | DROP TABLE european_cities_landfill_capacity; |
What is the total quantity of unsold inventory for each category? | CREATE TABLE inventory (inventory_id INT,inventory_category TEXT,inventory_quantity INT); | SELECT inventory_category, SUM(inventory_quantity) AS total_unsold_inventory FROM inventory WHERE inventory_quantity > 0 GROUP BY inventory_category |
Find the top 5 donors by total donation amount, including their names and countries | CREATE TABLE donors (id INT,name VARCHAR(50),country VARCHAR(50),total_donations DECIMAL(10,2)); INSERT INTO donors (id,name,country,total_donations) VALUES (1,'John Doe','USA',7000.00); INSERT INTO donors (id,name,country,total_donations) VALUES (2,'Jane Smith','Canada',12000.00); INSERT INTO donors (id,name,country,total_donations) VALUES (3,'Bob Johnson','USA',6000.00); INSERT INTO donors (id,name,country,total_donations) VALUES (4,'Charlie Brown','UK',9000.00); INSERT INTO donors (id,name,country,total_donations) VALUES (5,'David Williams','Australia',15000.00); | SELECT id, name, country, total_donations FROM donors ORDER BY total_donations DESC LIMIT 5; |
What is the total research grant funding received by each department in the College of Science, ordered from highest to lowest? | CREATE TABLE College_of_Science (department VARCHAR(50),grant_funding NUMERIC(15,2)); INSERT INTO College_of_Science (department,grant_funding) VALUES ('Biology',1250000.00),('Chemistry',1785000.00),('Physics',2500000.00),('Mathematics',1150000.00),('Computer_Science',3000000.00); | SELECT department, grant_funding FROM College_of_Science ORDER BY grant_funding DESC; |
What was the total revenue from the 'Art Exhibition' event? | CREATE TABLE Events (event_name VARCHAR(255),revenue INT); INSERT INTO Events (event_name,revenue) VALUES ('Dance Performance',5000),('Art Exhibition',8000),('Theater Play',6000); | SELECT revenue FROM Events WHERE event_name = 'Art Exhibition'; |
What percentage of cosmetic products sourced from France contain a paraben ingredient? | CREATE TABLE ingredients (product_id INT,ingredient TEXT); INSERT INTO ingredients (product_id,ingredient) VALUES (1,'paraben'),(2,'alcohol'),(3,'water'),(4,'paraben'),(5,'lavender'),(6,'paraben'); CREATE TABLE products (product_id INT,product_name TEXT,country TEXT); INSERT INTO products (product_id,product_name,country) VALUES (1,'Lipstick A','France'),(2,'Eye Shadow B','Canada'),(3,'Mascara C','France'),(4,'Foundation D','USA'),(5,'Blush E','Mexico'),(6,'Moisturizer F','France'); | SELECT 100.0 * COUNT(i.product_id) / (SELECT COUNT(*) FROM products p WHERE p.country = 'France') AS paraben_percentage FROM ingredients i WHERE i.ingredient = 'paraben' AND i.product_id IN (SELECT product_id FROM products WHERE country = 'France'); |
What is the total donation amount from volunteers in the United States? | CREATE TABLE donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,is_volunteer BOOLEAN); INSERT INTO donations (id,donor_name,donation_amount,donation_date,is_volunteer) VALUES (1,'John Doe',50.00,'2021-01-05',true),(2,'Jane Smith',100.00,'2021-03-15',false),(3,'Alice Johnson',75.00,'2021-01-20',true),(4,'Bob Brown',150.00,'2021-02-01',false); | SELECT SUM(donation_amount) FROM donations WHERE is_volunteer = true AND donor_country = 'USA'; |
What is the rank of each genetic research startup by total funding, for the past year? | CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups_funding (id INT,name VARCHAR(50),location VARCHAR(50),industry VARCHAR(50),funding DECIMAL(10,2),funded_year INT); INSERT INTO biotech.startups_funding (id,name,location,industry,funding,funded_year) VALUES (1,'StartupA','India','Genetic Research',6000000,2021),(2,'StartupB','Brazil','Bioprocess Engineering',4500000,2020),(3,'StartupC','South Africa','Synthetic Biology',5000000,2019),(4,'StartupD','USA','Genetic Research',8000000,2022),(5,'StartupE','Mexico','Genetic Research',7000000,2021),(6,'StartupF','China','Genetic Research',9000000,2020); | SELECT name, ROW_NUMBER() OVER (PARTITION BY funded_year ORDER BY funding DESC) as startup_rank FROM biotech.startups_funding WHERE industry = 'Genetic Research' AND funded_year = YEAR(CURRENT_DATE) - 1; |
Find the number of donors from each country who made donations in 2021. | CREATE TABLE Donors (DonorID int,DonorName varchar(50),Country varchar(50),DonationAmount numeric(18,2)); INSERT INTO Donors (DonorID,DonorName,Country,DonationAmount) VALUES (1,'Donor1','USA',5000),(2,'Donor2','Canada',7000),(3,'Donor3','USA',8000),(4,'Donor4','Mexico',9000); | SELECT Country, COUNT(*) FROM Donors WHERE YEAR(DonationDate) = 2021 GROUP BY Country; |
What is the total revenue for online travel agencies (OTAs) in Europe in the past year? | CREATE TABLE otas (id INT,name TEXT,region TEXT,daily_revenue FLOAT); CREATE VIEW past_year AS SELECT date_sub(current_date(),INTERVAL n DAY) AS date FROM (SELECT generate_series(0,365) AS n) AS sequence; | SELECT SUM(otas.daily_revenue) FROM otas JOIN past_year ON date_trunc('day', otas.date) = past_year.date WHERE otas.region = 'Europe'; |
What are the geopolitical risk assessments for the United States? | CREATE TABLE geopolitical_risk_us (id INT,country VARCHAR(255),assessment TEXT); INSERT INTO geopolitical_risk_us (id,country,assessment) VALUES (1,'United States','Medium Risk'); INSERT INTO geopolitical_risk_us (id,country,assessment) VALUES (2,'Canada','Low Risk'); | SELECT country, assessment FROM geopolitical_risk_us WHERE country = 'United States'; |
List all equipment manufactured in 'Germany' | CREATE TABLE manufacturing_equipment (equipment_id INT,equipment_name VARCHAR(50),year_manufactured INT,manufacturer_country VARCHAR(50)); INSERT INTO manufacturing_equipment (equipment_id,equipment_name,year_manufactured,manufacturer_country) VALUES (1,'CNC Mill',2018,'Germany'),(2,'Injection Molding Machine',2020,'China'),(3,'Robot Arm',2019,'Japan'); | SELECT equipment_name FROM manufacturing_equipment WHERE manufacturer_country = 'Germany'; |
How many unique donors have donated to each country in the past 3 years? | CREATE TABLE donor_country (donor_id INT,country_id INT,donation_year INT); INSERT INTO donor_country (donor_id,country_id,donation_year) VALUES (1,1,2019),(2,1,2020),(3,1,2021),(4,2,2019),(5,2,2020),(6,2,2021),(7,3,2019),(8,3,2020),(9,3,2021); | SELECT country_id, COUNT(DISTINCT donor_id) num_donors FROM donor_country WHERE donation_year BETWEEN (YEAR(CURRENT_DATE) - 3) AND YEAR(CURRENT_DATE) GROUP BY country_id; |
List the IDs and names of all teachers who have taken a professional development course in the past year, along with the number of courses taken, from the 'teacher_trainings' and 'teachers' tables. | CREATE TABLE teacher_trainings (teacher_id INT,course_id INT,training_date DATE); CREATE TABLE teachers (teacher_id INT,teacher_name VARCHAR(50)); | SELECT t.teacher_id, t.teacher_name, COUNT(tt.course_id) as num_courses FROM teachers t JOIN teacher_trainings tt ON t.teacher_id = tt.teacher_id WHERE tt.training_date >= DATE(NOW()) - INTERVAL 1 YEAR GROUP BY t.teacher_id; |
How many renewable energy projects are there in each state? | CREATE TABLE Renewable_Energy_Projects (project_id INT,state VARCHAR(20)); INSERT INTO Renewable_Energy_Projects (project_id,state) VALUES (1,'California'),(2,'Oregon'),(3,'Washington'),(4,'Nevada'); | SELECT state, COUNT(*) FROM Renewable_Energy_Projects GROUP BY state; |
What is the average monthly resource depletion from diamond mining operations worldwide? | CREATE TABLE resource_depletion (id INT,location VARCHAR(50),operation_type VARCHAR(50),monthly_resource_depletion INT); INSERT INTO resource_depletion (id,location,operation_type,monthly_resource_depletion) VALUES (1,'Australia','Gold',500),(2,'South Africa','Gold',700),(3,'Canada','Diamond',600); | SELECT AVG(monthly_resource_depletion) as avg_depletion FROM resource_depletion WHERE operation_type = 'Diamond'; |
What is the number of flu deaths in the past 12 months in each state? | CREATE TABLE flu_deaths (death_id INT,date TEXT,state TEXT,cause TEXT); INSERT INTO flu_deaths (death_id,date,state,cause) VALUES (1,'2022-01-01','California','Flu'); INSERT INTO flu_deaths (death_id,date,state,cause) VALUES (2,'2022-02-15','New York','Heart Attack'); | SELECT state, COUNT(*) FROM flu_deaths WHERE date >= (CURRENT_DATE - INTERVAL '12 months') GROUP BY state; |
How many artists from underrepresented communities had exhibitions in Asia in 2020? | CREATE TABLE Artists (id INT,region VARCHAR(20),year INT,community VARCHAR(50),exhibitions INT); INSERT INTO Artists (id,region,year,community,exhibitions) VALUES (5,'Asia',2020,'Underrepresented',2); INSERT INTO Artists (id,region,year,community,exhibitions) VALUES (6,'Asia',2020,'Well-represented',3); | SELECT SUM(exhibitions) FROM Artists WHERE region = 'Asia' AND year = 2020 AND community = 'Underrepresented'; |
What is the percentage of donations made in each quarter compared to the total donations? | CREATE TABLE Donations (DonationID INT,DonationQuarter INT,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonationQuarter,DonationAmount) VALUES (1,1,1000.00),(2,4,1500.00),(3,3,2000.00),(4,2,500.00),(5,1,800.00),(6,4,1200.00); | SELECT DonationQuarter, SUM(DonationAmount) AS TotalDonation, SUM(DonationAmount) OVER () AS TotalDonations, (SUM(DonationAmount) / SUM(DonationAmount) OVER ()) * 100.0 AS DonationPercentage FROM Donations GROUP BY DonationQuarter; |
Calculate the percentage of donations received from each state in the past year. | CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationDate DATE,Amount DECIMAL(10,2),State TEXT); | SELECT State, SUM(Amount) AS TotalDonated, (SUM(Amount) / (SELECT SUM(Amount) FROM Donors WHERE DonationDate >= DATEADD(year, -1, GETDATE()))) * 100 AS Percentage FROM Donors WHERE DonationDate >= DATEADD(year, -1, GETDATE()) GROUP BY State; |
Find the total amount of untreated wastewater in the province of Quebec, Canada in the last month | CREATE TABLE provinces (id INT,name VARCHAR(255)); INSERT INTO provinces (id,name) VALUES (1,'Quebec'); CREATE TABLE wastewater_treatment (id INT,province_id INT,treatment_status VARCHAR(255),volume FLOAT,treatment_date DATE); INSERT INTO wastewater_treatment (id,province_id,treatment_status,volume,treatment_date) VALUES (1,1,'untreated',500,'2022-08-01'); | SELECT SUM(wastewater_treatment.volume) as total_untreated_volume FROM wastewater_treatment WHERE wastewater_treatment.treatment_status = 'untreated' AND wastewater_treatment.treatment_date >= (CURRENT_DATE - INTERVAL '1 month')::date AND wastewater_treatment.province_id IN (SELECT id FROM provinces WHERE name = 'Quebec'); |
Delete the record with the lowest explainability score in the 'explainable_ai' table. | CREATE TABLE explainable_ai (model_name TEXT,explainability_score INTEGER); INSERT INTO explainable_ai (model_name,explainability_score) VALUES ('modelA',65),('modelB',72),('modelC',68); | DELETE FROM explainable_ai WHERE explainability_score = (SELECT MIN(explainability_score) FROM explainable_ai); |
What is the minimum data usage for postpaid mobile customers in the city of Los Angeles? | CREATE TABLE mobile_customers (customer_id INT,data_usage FLOAT,city VARCHAR(20),plan_type VARCHAR(10)); INSERT INTO mobile_customers (customer_id,data_usage,city,plan_type) VALUES (1,3.5,'Los Angeles','postpaid'),(2,4.2,'New York','postpaid'),(3,3.8,'Los Angeles','prepaid'); | SELECT MIN(data_usage) FROM mobile_customers WHERE city = 'Los Angeles' AND plan_type = 'postpaid'; |
Show the number of new garments added per month by each manufacturer. | CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50));CREATE TABLE GarmentDates (GarmentID INT,ManufacturerID INT,AddedDate DATE); | SELECT M.ManufacturerName, EXTRACT(MONTH FROM G.AddedDate) AS Month, COUNT(G.GarmentID) AS NewGarments FROM GarmentDates G JOIN Manufacturers M ON G.ManufacturerID = M.ManufacturerID GROUP BY M.ManufacturerName, EXTRACT(MONTH FROM G.AddedDate); |
What is the maximum data usage by a single subscriber in 'rural' regions? | CREATE TABLE subscribers (id INT,name TEXT,data_usage FLOAT,region TEXT); INSERT INTO subscribers (id,name,data_usage,region) VALUES (1,'John Doe',15.0,'urban'); INSERT INTO subscribers (id,name,data_usage,region) VALUES (2,'Jane Smith',20.0,'urban'); INSERT INTO subscribers (id,name,data_usage,region) VALUES (3,'Bob Johnson',25.0,'rural'); INSERT INTO subscribers (id,name,data_usage,region) VALUES (4,'Alice Williams',30.0,'rural'); | SELECT MAX(data_usage) FROM subscribers WHERE region = 'rural'; |
How many streams did artist 'Ariana Grande' get in Germany? | CREATE TABLE Streams (id INT,artist VARCHAR(100),country VARCHAR(100),streams INT); INSERT INTO Streams (id,artist,country,streams) VALUES (1,'Ariana Grande','Germany',1000000); | SELECT SUM(streams) FROM Streams WHERE artist = 'Ariana Grande' AND country = 'Germany' |
List the top five departments with the highest percentage of female employees. | CREATE TABLE EmployeeDemographics (EmployeeID INT,Department VARCHAR(20),Gender VARCHAR(10)); INSERT INTO EmployeeDemographics (EmployeeID,Department,Gender) VALUES (1,'IT','Male'),(2,'IT','Female'),(3,'HR','Female'),(4,'HR','Male'),(5,'Finance','Female'),(6,'Finance','Female'); | SELECT Department, PERCENT_RANK() OVER (ORDER BY COUNT(*) FILTER (WHERE Gender = 'Female') / COUNT(*) DESC) AS Percent_Female FROM EmployeeDemographics GROUP BY Department ORDER BY Percent_Female DESC LIMIT 5; |
What is the total amount of resources depleted from each mining site in 2019? | CREATE TABLE Resources (ResourceID INT,SiteID INT,Year INT,Quantity INT); INSERT INTO Resources (ResourceID,SiteID,Year,Quantity) VALUES (1,1,2019,500),(2,2,2019,700),(3,3,2019,800); | SELECT SiteID, SUM(Quantity) FROM Resources WHERE Year = 2019 GROUP BY SiteID; |
What is the financial wellbeing score for individuals with an annual income greater than $75,000 in Canada? | CREATE TABLE financial_wellbeing (id INT,individual_id INT,annual_income DECIMAL(10,2),financial_wellbeing_score INT); | SELECT financial_wellbeing_score FROM financial_wellbeing WHERE annual_income > 75000 AND country = 'Canada'; |
What is the maximum number of public park visits in the "ParkVisits" table, per month, for parks located in urban areas? | CREATE TABLE ParkVisits (id INT,park_name VARCHAR(50),visit_date DATE,location VARCHAR(50),visitors INT); INSERT INTO ParkVisits (id,park_name,visit_date,location,visitors) VALUES (1,'Central Park','2022-01-01','Urban',5000),(2,'Golden Gate Park','2022-02-01','Urban',6000),(3,'Stanley Park','2022-03-01','Urban',4000),(4,'High Park','2022-01-15','Urban',5500); | SELECT EXTRACT(MONTH FROM visit_date) as month, MAX(visitors) as max_visitors FROM ParkVisits WHERE location = 'Urban' GROUP BY month; |
Identify counties where the average income is above the state average income. | CREATE TABLE Counties (CountyName VARCHAR(50),State VARCHAR(50),AverageIncome FLOAT); INSERT INTO Counties (CountyName,State,AverageIncome) VALUES ('Santa Clara','California',120000),('Travis','Texas',90000),('Westchester','New York',85000),('Miami-Dade','Florida',70000),('Cook','Illinois',75000); CREATE TABLE States (State VARCHAR(50),AverageIncome FLOAT); INSERT INTO States (State,AverageIncome) VALUES ('California',70000),('Texas',60000),('New York',65000),('Florida',50000),('Illinois',60000); | SELECT CountyName, AverageIncome FROM Counties C WHERE AverageIncome > (SELECT AVG(AverageIncome) FROM States S WHERE S.State = C.State); |
What is the average number of fans that attend the home games of each team in the 'teams' table? | CREATE TABLE teams (team VARCHAR(50),location VARCHAR(50),capacity INT,avg_attendance INT); INSERT INTO teams (team,location,capacity,avg_attendance) VALUES ('Barcelona','Spain',100000,80000); INSERT INTO teams (team,location,capacity,avg_attendance) VALUES ('Real Madrid','Spain',120000,95000); | SELECT team, AVG(avg_attendance) FROM teams GROUP BY team; |
Get the total number of wells in each state | CREATE TABLE wells (id INT,state VARCHAR(2),cost FLOAT); INSERT INTO wells (id,state,cost) VALUES (1,'TX',500000.0),(2,'TX',600000.0),(3,'OK',400000.0); | SELECT state, COUNT(*) FROM wells GROUP BY state; |
What is the average transaction amount for 'Southeast Asia' customers? | CREATE TABLE transactions (id INT,customer_region VARCHAR(20),transaction_amount DECIMAL(10,2)); INSERT INTO transactions (id,customer_region,transaction_amount) VALUES (1,'Southeast Asia',500.00),(2,'Southeast Asia',750.00),(3,'Africa',800.00),(4,'Europe',900.00); | SELECT AVG(transaction_amount) FROM transactions WHERE customer_region = 'Southeast Asia'; |
Identify the vendors who supplied materials for the 'MachineA' and 'MachineB' in the 'Factory' location. | CREATE TABLE Vendors (VendorID INT,VendorName VARCHAR(50),MachineName VARCHAR(50),Location VARCHAR(50)); INSERT INTO Vendors (VendorID,VendorName,MachineName,Location) VALUES (1,'VendorX','MachineA','Factory'),(2,'VendorY','MachineB','Factory'),(3,'VendorZ','MachineC','Warehouse'); | SELECT DISTINCT VendorName FROM Vendors WHERE MachineName IN ('MachineA', 'MachineB') AND Location = 'Factory'; |
What is the total revenue generated from members in the "Young Adults" age group? | CREATE TABLE Members (MemberID INT,AgeGroup VARCHAR(20),MembershipType VARCHAR(20),Revenue DECIMAL(5,2)); INSERT INTO Members (MemberID,AgeGroup,MembershipType,Revenue) VALUES (1,'Young Adults','Premium',50.00),(2,'Seniors','Basic',30.00),(3,'Young Adults','Basic',25.00); | SELECT SUM(Revenue) FROM Members WHERE AgeGroup = 'Young Adults'; |
What is the total biomass of coral reefs in the Atlantic Ocean region in the 'MarineLife' schema? | CREATE SCHEMA MarineLife;CREATE TABLE CoralReefs (id INT,region TEXT,biomass REAL); INSERT INTO CoralReefs (id,region,biomass) VALUES (1,'Indo-Pacific',230000),(2,'Atlantic Ocean',85000),(3,'Caribbean',92000),(4,'Mediterranean Sea',50000),(5,'Red Sea',120000); | SELECT region, SUM(biomass) AS total_biomass FROM MarineLife.CoralReefs WHERE region = 'Atlantic Ocean' GROUP BY region; |
Identify the top 3 countries with the highest number of successful satellite deployments in the past 5 years. | CREATE TABLE SatelliteDeployments (Id INT,Country VARCHAR(20),Year INT,Success BOOLEAN); INSERT INTO SatelliteDeployments VALUES (1,'USA',2017,true),(2,'China',2017,true),(3,'India',2017,false),(4,'Germany',2018,true),(5,'Japan',2018,true),(6,'Brazil',2018,true),(7,'USA',2018,true),(8,'China',2018,false),(9,'India',2019,true),(10,'Germany',2019,true),(11,'Japan',2019,false),(12,'Brazil',2019,true),(13,'USA',2019,true),(14,'China',2020,true),(15,'India',2020,true),(16,'Germany',2020,true),(17,'Japan',2020,true),(18,'Brazil',2020,false),(19,'USA',2021,true),(20,'China',2021,true); | SELECT Country, COUNT(*) as SuccessfulDeployments FROM SatelliteDeployments WHERE Year >= 2017 AND Success = true GROUP BY Country ORDER BY SuccessfulDeployments DESC LIMIT 3; |
Which mobile subscribers have exceeded their data limit in Australia? | CREATE TABLE mobile_subscriber_limits (subscriber_id INT,data_limit FLOAT,data_usage FLOAT,country VARCHAR(20)); INSERT INTO mobile_subscriber_limits (subscriber_id,data_limit,data_usage,country) VALUES (1,50,60,'Australia'); INSERT INTO mobile_subscriber_limits (subscriber_id,data_limit,data_usage,country) VALUES (2,75,85,'Australia'); | SELECT subscriber_id, name FROM mobile_subscriber_limits INNER JOIN (SELECT subscriber_id FROM mobile_subscriber_limits WHERE data_usage > data_limit GROUP BY subscriber_id HAVING COUNT(*) > 1) subscriber_exceed_limit ON mobile_subscriber_limits.subscriber_id = subscriber_exceed_limit.subscriber_id; |
Delete records of citizens who have provided negative feedback from the 'citizen_feedback' table | CREATE TABLE citizen_feedback (citizen_id INT,feedback TEXT,feedback_date DATE); | DELETE FROM citizen_feedback WHERE feedback < 0; |
What is the average depth in the Pacific Ocean where marine mammals reside, grouped by species? | CREATE TABLE marine_species_pacific_ocean (id INT,species_name VARCHAR(255),population INT,habitat VARCHAR(255)); INSERT INTO marine_species_pacific_ocean (id,species_name,population,habitat) VALUES (1,'Bottlenose Dolphin',60000,'Pacific Ocean'),(2,'Leatherback Sea Turtle',34000,'Pacific Ocean'),(3,'Sperm Whale',5000,'Pacific Ocean'); CREATE TABLE oceanography_pacific_ocean (region VARCHAR(255),depth FLOAT,temperature FLOAT,salinity FLOAT); INSERT INTO oceanography_pacific_ocean (region,depth,temperature,salinity) VALUES ('Pacific Ocean',5000,25,35.5); | SELECT m.species_name, AVG(o.depth) AS avg_depth FROM marine_species_pacific_ocean m INNER JOIN oceanography_pacific_ocean o ON m.habitat = o.region WHERE m.species_name LIKE '%mammal%' GROUP BY m.species_name; |
What is the average budget for infrastructure projects in California? | CREATE TABLE infrastructure_projects (id INT,project_name VARCHAR(50),location VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO infrastructure_projects (id,project_name,location,budget) VALUES (1,'Highway 101 Expansion','California',5000000),(2,'Bridge Replacement','New York',3000000),(3,'Transit System Upgrade','Texas',8000000); | SELECT AVG(budget) as avg_budget FROM infrastructure_projects WHERE location = 'California'; |
Calculate the total water consumption for the first half of the year for the city of Chicago. | CREATE TABLE water_consumption (city VARCHAR(50),consumption FLOAT,month INT,year INT); INSERT INTO water_consumption (city,consumption,month,year) VALUES ('Chicago',150.2,1,2021),('Chicago',140.5,2,2021),('Chicago',160.8,3,2021); | SELECT SUM(consumption) FROM water_consumption WHERE city = 'Chicago' AND year = 2021 AND month BETWEEN 1 AND 6; |
What is the percentage of hospitals in rural areas of Tennessee with an emergency room? | CREATE TABLE tennessee_rural_hospitals (hospital_id INT,hospital_name VARCHAR(255),rural BOOLEAN,emergency_room BOOLEAN); INSERT INTO tennessee_rural_hospitals VALUES (1,'Hospital A',true,true),(2,'Hospital B',false,true); | SELECT (COUNT(*) FILTER (WHERE emergency_room = true)) * 100.0 / COUNT(*) FROM tennessee_rural_hospitals WHERE rural = true; |
What is the average capacity of renewable energy sources in MW? | CREATE TABLE energy_sources (id INT PRIMARY KEY,source VARCHAR(50),capacity_mw FLOAT); INSERT INTO energy_sources (id,source,capacity_mw) VALUES (1,'Wind',1200.0),(2,'Solar',800.0),(3,'Hydro',1500.0); | SELECT AVG(capacity_mw) FROM energy_sources WHERE source IN ('Wind', 'Solar', 'Hydro'); |
List all employees who have not been involved in any transactions in the past month. | CREATE TABLE employees (employee_id INT,name VARCHAR(50),department VARCHAR(20),hire_date DATE); | SELECT employee_id, name FROM employees e WHERE NOT EXISTS (SELECT 1 FROM transactions t WHERE t.employee_id = e.employee_id AND t.transaction_date >= (CURRENT_DATE - INTERVAL '1 month')); |
What are the names and ranks of all military personnel in country Z who were promoted in the year 2020? | CREATE TABLE military_promotions (id INT,name TEXT,country TEXT,rank TEXT,promotion_year INT);INSERT INTO military_promotions (id,name,country,rank,promotion_year) VALUES (1,'John Doe','Country Z','Sergeant',2020),(2,'Jane Smith','Country Z','Captain',2020); | SELECT name, rank FROM military_promotions WHERE country = 'Country Z' AND promotion_year = 2020; |
Find the number of bridges in the state of California | 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 (1,'Golden Gate Bridge','Bridge','San Francisco','California'); | SELECT COUNT(*) FROM Infrastructure WHERE state = 'California' AND type = 'Bridge'; |
How many distinct unions are there and their minimum rates? | CREATE TABLE union_workplaces (id INT,union_id INT,workplace_name VARCHAR(50),injury_rate DECIMAL(5,2)); INSERT INTO union_workplaces (id,union_id,workplace_name,injury_rate) VALUES (1,1001,'ABC Factory',6.5),(2,1001,'DEF Warehouse',2.9),(3,1002,'XYZ Inc',3.2),(4,1003,'LMN Corp',9.1),(5,1003,'OPQ Office',4.7); | SELECT COUNT(DISTINCT union_id) as num_unions, MIN(injury_rate) as min_injury_rate FROM union_workplaces; |
What is the average number of assists per game for the 'Golden State Warriors' in the 'basketball_stats' table? | CREATE TABLE basketball_stats (team VARCHAR(50),player VARCHAR(50),assists INT,date DATE); INSERT INTO basketball_stats (team,player,assists,date) VALUES ('Golden State Warriors','Stephen Curry',8,'2022-01-01'),('Golden State Warriors','Draymond Green',10,'2022-01-01'),('Brooklyn Nets','Kyrie Irving',5,'2022-01-02'); | SELECT AVG(assists) FROM basketball_stats WHERE team = 'Golden State Warriors'; |
How many players registered in 2022 play multiplayer online battle arena (MOBA) games on PC? | CREATE TABLE players (player_id INT,name VARCHAR(30),age INT,gender VARCHAR(10),country VARCHAR(30),registration_date DATE,platform VARCHAR(20)); | SELECT COUNT(*) FROM players WHERE YEAR(registration_date) = 2022 AND genre = 'MOBA' AND platform = 'PC'; |
Show the number of players who played a specific game in the last month, grouped by country and age. | CREATE TABLE players(id INT,name VARCHAR(50),country VARCHAR(50),age INT,last_login DATETIME); CREATE TABLE game_sessions(id INT,player_id INT,game_name VARCHAR(50),start_time DATETIME); | SELECT game_name, country, age, COUNT(DISTINCT players.id) as num_players FROM game_sessions JOIN players ON game_sessions.player_id = players.id WHERE start_time >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY game_name, country, age; |
What is the total number of community education programs conducted in '2022' and '2023' with less than 50 attendees? | CREATE TABLE education_programs (id INT,program_name VARCHAR(50),year INT,attendees INT); INSERT INTO education_programs (id,program_name,year,attendees) VALUES (1,'Wildlife Conservation',2023,40),(2,'Habitat Protection',2022,30); | SELECT COUNT(*) FROM education_programs WHERE year IN (2022, 2023) AND attendees < 50; |
What is the total donation amount per quarter in 2023? | CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount FLOAT); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationAmount) VALUES (1,1,'2023-01-01',75.00),(2,2,'2023-02-14',125.00),(3,3,'2023-04-05',50.00); | SELECT DATE_FORMAT(DonationDate, '%Y-%m') AS Quarter, SUM(DonationAmount) AS TotalDonation FROM Donations WHERE YEAR(DonationDate) = 2023 GROUP BY Quarter; |
What is the minimum cargo weight handled by port 'Busan' and 'Incheon'? | CREATE TABLE ports (port_id INT,port_name VARCHAR(255)); INSERT INTO ports (port_id,port_name) VALUES (1,'Busan'),(2,'Incheon'),(3,'Daegu'); CREATE TABLE cargo (cargo_id INT,port_id INT,weight FLOAT); INSERT INTO cargo (cargo_id,port_id,weight) VALUES (1,1,1000),(2,1,1500),(3,2,800),(4,3,1200); | SELECT MIN(weight) FROM cargo WHERE port_name IN ('Busan', 'Incheon'); |
What is the total number of visitors who traveled to Japan for eco-tourism in 2020 and 2021? | CREATE TABLE tourism_stats (id INT,country VARCHAR(255),visit_year INT,visit_type VARCHAR(255)); INSERT INTO tourism_stats (id,country,visit_year,visit_type) VALUES (1,'Japan',2020,'eco-tourism'),(2,'Japan',2021,'eco-tourism'); | SELECT SUM(id) FROM tourism_stats WHERE country = 'Japan' AND visit_year IN (2020, 2021) AND visit_type = 'eco-tourism'; |
Display the smart contracts with the lowest and highest transaction counts for each developer, in ascending order by developer name. | CREATE TABLE Transactions (TransactionID int,ContractAddress varchar(50),Developer varchar(50),Transactions int); INSERT INTO Transactions (TransactionID,ContractAddress,Developer,Transactions) VALUES (1,'ContractA','Alice',100),(2,'ContractB','Bob',200),(3,'ContractC','Charlie',300); | SELECT Developer, MIN(Transactions) as MinTransactions, MAX(Transactions) as MaxTransactions FROM Transactions GROUP BY Developer ORDER BY Developer; |
What is the total biomass of fish for each species in a given month? | CREATE TABLE Stock (StockID INT,FarmID INT,FishSpecies VARCHAR(255),Weight DECIMAL(10,2),StockDate DATE); INSERT INTO Stock (StockID,FarmID,FishSpecies,Weight,StockDate) VALUES (1,1,'Tilapia',5.5,'2022-01-01'),(2,1,'Salmon',12.3,'2022-01-02'),(3,1,'Tilapia',6.0,'2022-01-03'),(4,1,'Catfish',8.2,'2022-01-04'); | SELECT FishSpecies, DATE_TRUNC('month', StockDate) as Month, SUM(Weight) OVER (PARTITION BY FishSpecies, DATE_TRUNC('month', StockDate)) as TotalBiomass FROM Stock WHERE FarmID = 1; |
What is the average funding amount for startups in the healthcare industry? | CREATE TABLE company (id INT,name TEXT,industry TEXT,founding_year INT); INSERT INTO company (id,name,industry,founding_year) VALUES (1,'Acme Corp','Tech',2010),(2,'Beta Inc','Healthcare',2012); CREATE TABLE investment (id INT,company_id INT,funding_amount INT,investment_year INT); INSERT INTO investment (id,company_id,funding_amount,investment_year) VALUES (1,1,5000000,2015),(2,2,7000000,2017); | SELECT AVG(funding_amount) FROM investment JOIN company ON investment.company_id = company.id WHERE company.industry = 'Healthcare'; |
What is the maximum age of patients diagnosed with PTSD in Japan? | CREATE TABLE ptsd_diagnosis (patient_id INT,age INT,condition VARCHAR(255),country VARCHAR(255)); INSERT INTO ptsd_diagnosis (patient_id,age,condition,country) VALUES (1,35,'PTSD','Japan'); INSERT INTO ptsd_diagnosis (patient_id,age,condition,country) VALUES (2,40,'Anxiety','Japan'); | SELECT MAX(age) FROM ptsd_diagnosis WHERE condition = 'PTSD' AND country = 'Japan'; |
What is the maximum production of wheat per hectare in Germany? | CREATE TABLE wheat_production (id INT,quantity INT,yield_per_hectare DECIMAL(5,2),country VARCHAR(255)); INSERT INTO wheat_production (id,quantity,yield_per_hectare,country) VALUES (1,12,9.00,'Germany'); | SELECT MAX(yield_per_hectare) FROM wheat_production WHERE country = 'Germany'; |
List the total production and number of unique manufacturing dates for each aircraft model, excluding the models with total production less than 100. | CREATE TABLE Aircrafts (AircraftID INT,Model VARCHAR(20),ManufacturingDate DATE,TotalProduced INT); CREATE TABLE ManufacturingDates (ManufacturingDate DATE); INSERT INTO ManufacturingDates (ManufacturingDate) VALUES ('1976-08-01'),('2006-01-01'); INSERT INTO Aircrafts (AircraftID,Model,ManufacturingDate,TotalProduced) VALUES (1,'F-16','1976-08-01',450),(2,'F-35','2006-01-01',50),(3,'F-35B','2009-05-01',70); | SELECT Model, SUM(TotalProduced) as 'Total Production', COUNT(DISTINCT ManufacturingDate) as 'Number of Manufacturing Dates' FROM Aircrafts WHERE TotalProduced >= 100 GROUP BY Model; |
What is the total budget allocated for healthcare in the city of "Chicago" in the year 2020? | CREATE TABLE budget_allocation (year INT,city TEXT,category TEXT,amount FLOAT); INSERT INTO budget_allocation (year,city,category,amount) VALUES (2020,'Chicago','Healthcare',15000000),(2020,'Chicago','Education',12000000),(2020,'Chicago','Transportation',10000000); | SELECT SUM(amount) FROM budget_allocation WHERE city = 'Chicago' AND category = 'Healthcare' AND year = 2020; |
List all cybersecurity strategies and their respective national security advisors from the 'cybersecurity' and 'advisors' tables. | CREATE TABLE cybersecurity (strategy_id INT,strategy_name VARCHAR(50),description TEXT,last_updated TIMESTAMP); CREATE TABLE advisors (advisor_id INT,name VARCHAR(50),position VARCHAR(50),agency VARCHAR(50),last_updated TIMESTAMP); | SELECT cybersecurity.strategy_name, advisors.name FROM cybersecurity INNER JOIN advisors ON cybersecurity.strategy_id = advisors.advisor_id WHERE advisors.position = 'National Security Advisor'; |
What's the minimum and maximum rating of movies released in 2010? | CREATE TABLE movie_info (id INT,title VARCHAR(255),release_year INT,rating DECIMAL(3,2)); INSERT INTO movie_info (id,title,release_year,rating) VALUES (1,'Movie1',2010,4.5),(2,'Movie2',2009,3.5),(3,'Movie3',2010,2.5),(4,'Movie4',2011,5.0); | SELECT MIN(rating), MAX(rating) FROM movie_info WHERE release_year = 2010; |
What is the average quantity of eco-friendly fabric sourced from Africa? | CREATE TABLE fabric_sourcing (fabric_id INTEGER,material TEXT,region TEXT,quantity INTEGER,sustainable BOOLEAN); INSERT INTO fabric_sourcing (fabric_id,material,region,quantity,sustainable) VALUES (1,'cotton','Africa',120,TRUE),(2,'silk','Asia',80,FALSE),(3,'polyester','Europe',180,TRUE),(4,'wool','South America',90,FALSE); | SELECT AVG(quantity) FROM fabric_sourcing WHERE region = 'Africa' AND sustainable = TRUE; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.