instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Display the total population of fish for each species in the 'AquaticSpecies' table
|
CREATE TABLE AquaticSpecies (id INT,species VARCHAR(255),population INT); INSERT INTO AquaticSpecies (id,species,population) VALUES (1,'Salmon',50000); INSERT INTO AquaticSpecies (id,species,population) VALUES (2,'Trout',25000); INSERT INTO AquaticSpecies (id,species,population) VALUES (3,'Carp',40000); INSERT INTO AquaticSpecies (id,species,population) VALUES (4,'Tuna',30000);
|
SELECT species, SUM(population) FROM AquaticSpecies GROUP BY species;
|
How many malaria cases were reported in 'disease_data' for the year 2019?
|
CREATE SCHEMA disease_data; CREATE TABLE malaria_cases (id INT,clinic_id INT,date DATE,cases INT); INSERT INTO disease_data.malaria_cases (id,clinic_id,date,cases) VALUES (1,1001,'2019-01-01',2),(2,1001,'2019-02-01',3),(3,1002,'2019-03-01',1),(4,1002,'2019-04-01',5),(5,1003,'2019-05-01',4);
|
SELECT SUM(cases) FROM disease_data.malaria_cases WHERE date BETWEEN '2019-01-01' AND '2019-12-31';
|
What is the average survival rate of salmon by farm location?
|
CREATE TABLE Farm (id INT PRIMARY KEY,location VARCHAR(50)); CREATE TABLE Salmon (id INT,survival_rate DECIMAL(5,2),farm_id INT,FOREIGN KEY (farm_id) REFERENCES Farm(id));
|
SELECT Farm.location, AVG(Salmon.survival_rate) FROM Farm INNER JOIN Salmon ON Farm.id = Salmon.farm_id GROUP BY Farm.location;
|
Get the circular economy initiative name and start date with the lowest budget for 'South America'.
|
CREATE TABLE south_america_initiatives (region VARCHAR(50),initiative_name VARCHAR(50),budget NUMERIC(10,2),start_date DATE); INSERT INTO south_america_initiatives (region,initiative_name,budget,start_date) VALUES ('South America','Green Schools',25000,'2019-01-01'),('South America','Sustainable Agriculture',50000,'2020-01-01');
|
SELECT initiative_name, start_date FROM (SELECT initiative_name, start_date, ROW_NUMBER() OVER (PARTITION BY region ORDER BY budget ASC) AS rn FROM south_america_initiatives WHERE region = 'South America') x WHERE rn = 1;
|
What is the latest launch date of a satellite by the Japan Aerospace Exploration Agency (JAXA)?
|
CREATE TABLE jaxa_satellites (id INT,satellite_name VARCHAR(255),launch_date DATE,organization VARCHAR(255)); INSERT INTO jaxa_satellites (id,satellite_name,launch_date,organization) VALUES (1,'Hayabusa 2','2014-12-03','JAXA');
|
SELECT MAX(launch_date) FROM jaxa_satellites WHERE organization = 'JAXA';
|
What is the percentage of employees who have completed leadership training, by department?
|
CREATE TABLE EmployeeTraining (EmployeeID INT,Department VARCHAR(255),TrainingID INT); CREATE TABLE TrainingCourses (TrainingID INT,TrainingName VARCHAR(255),Completed DATE); INSERT INTO EmployeeTraining (EmployeeID,Department,TrainingID) VALUES (1,'HR',1),(2,'IT',2),(3,'IT',1),(4,'HR',NULL); INSERT INTO TrainingCourses (TrainingID,TrainingName,Completed) VALUES (1,'Leadership','2022-01-01'),(2,'Diversity and Inclusion',NULL);
|
SELECT Department, COUNT(DISTINCT e.EmployeeID) * 100.0 / (SELECT COUNT(DISTINCT EmployeeID) FROM Employees WHERE Department = e.Department) AS Percentage FROM EmployeeTraining e JOIN TrainingCourses t ON e.TrainingID = t.TrainingID WHERE t.Completed IS NOT NULL GROUP BY e.Department;
|
What are the top 3 sustainable brands with the highest average sustainability scores?
|
CREATE TABLE sustainability (product_id INT,product_name VARCHAR(100),brand VARCHAR(50),sustainability_score DECIMAL(3,2)); INSERT INTO sustainability (product_id,product_name,brand,sustainability_score) VALUES (1,'Cleanser','Green Essentials',4.2),(2,'Toner','Natural Path',4.5);
|
SELECT brand, AVG(sustainability_score) AS avg_sustainability_score FROM sustainability GROUP BY brand ORDER BY avg_sustainability_score DESC LIMIT 3;
|
What is the total number of smart contracts associated with digital assets that were created after 2020-01-01?
|
CREATE TABLE digital_assets (asset_id INT,asset_name TEXT,creation_date DATE); INSERT INTO digital_assets (asset_id,asset_name,creation_date) VALUES (1,'Asset1','2021-05-15'); INSERT INTO digital_assets (asset_id,asset_name,creation_date) VALUES (2,'Asset2','2022-08-20'); CREATE TABLE smart_contracts (contract_id INT,asset_id INT,creation_date DATE); INSERT INTO smart_contracts (contract_id,asset_id,creation_date) VALUES (101,1,'2021-06-01'); INSERT INTO smart_contracts (contract_id,asset_id,creation_date) VALUES (102,2,'2022-08-21');
|
SELECT COUNT(*) FROM smart_contracts JOIN digital_assets ON smart_contracts.asset_id = digital_assets.asset_id WHERE smart_contracts.creation_date > '2020-01-01';
|
What is the average environmental impact score of mining operations in each state of Australia?
|
CREATE TABLE mining_operations (id INT,state VARCHAR(255),environmental_impact_score INT); INSERT INTO mining_operations (id,state,environmental_impact_score) VALUES (1,'New South Wales',60),(2,'New South Wales',70),(3,'Queensland',80),(4,'Queensland',90),(5,'Western Australia',50),(6,'Western Australia',60);
|
SELECT state, AVG(environmental_impact_score) FROM mining_operations GROUP BY state;
|
What is the percentage of patients who received CBT and reported improvement?
|
CREATE TABLE patients (id INT,country VARCHAR(255),improvement VARCHAR(255)); INSERT INTO patients (id,country,improvement) VALUES (1,'USA','Improved'),(2,'USA','Not Improved'),(3,'USA','Improved'); CREATE TABLE therapy (patient_id INT,therapy_type VARCHAR(255)); INSERT INTO therapy (patient_id,therapy_type) VALUES (1,'CBT'),(2,'CBT'),(3,'DBT');
|
SELECT 100.0 * COUNT(CASE WHEN improvement = 'Improved' AND therapy_type = 'CBT' THEN 1 END) / COUNT(*) as percentage FROM patients JOIN therapy ON patients.id = therapy.patient_id;
|
How many security incidents were there in healthcare organizations in Q2 2021, grouped by country?
|
CREATE TABLE security_incidents (id INT,organization TEXT,country TEXT,incident_date DATE); INSERT INTO security_incidents (id,organization,country,incident_date) VALUES (1,'Healthcare Organization A','USA','2021-04-05'); INSERT INTO security_incidents (id,organization,country,incident_date) VALUES (2,'Healthcare Organization B','Canada','2021-04-10');
|
SELECT country, COUNT(*) FROM security_incidents WHERE organization LIKE '%Healthcare Organization%' AND incident_date >= '2021-04-01' AND incident_date < '2021-07-01' GROUP BY country;
|
Find the number of electric vehicles produced in Japan in the year 2020.
|
CREATE TABLE EV_Sales (id INT,vehicle_model VARCHAR(255),production_year INT,is_electric BOOLEAN); INSERT INTO EV_Sales (id,vehicle_model,production_year,is_electric) VALUES (1,'Nissan Leaf',2020,true); INSERT INTO EV_Sales (id,vehicle_model,production_year,is_electric) VALUES (2,'Toyota Prius',2019,true); INSERT INTO EV_Sales (id,vehicle_model,production_year,is_electric) VALUES (3,'Mitsubishi Outlander PHEV',2020,true);
|
SELECT COUNT(*) FROM EV_Sales WHERE production_year = 2020 AND is_electric = true AND vehicle_model IN (SELECT vehicle_model FROM EV_Sales WHERE production_year = 2020 GROUP BY vehicle_model HAVING COUNT(DISTINCT production_year) > 1);
|
What was the total sustainable investment in water conservation projects in 2020?
|
CREATE TABLE sustainable_water_projects (id INT,investment_date DATE,project_type VARCHAR(255),investment_amount FLOAT);
|
SELECT SUM(investment_amount) FROM sustainable_water_projects WHERE project_type = 'water conservation' AND investment_date BETWEEN '2020-01-01' AND '2020-12-31';
|
Which train stations have accessibility features?
|
CREATE TABLE train_stations (station_id INT,station_name TEXT,is_accessible BOOLEAN); INSERT INTO train_stations (station_id,station_name,is_accessible) VALUES (1,'Union Station',true),(2,'City Hall',false),(3,'Downtown Crossing',true);
|
SELECT station_id, station_name, is_accessible FROM train_stations WHERE is_accessible = true;
|
What is the total revenue generated by venues with more than 50 jobs created?
|
CREATE TABLE Economic_Impact (id INT,venue_id INT,revenue INT,jobs_created INT); INSERT INTO Economic_Impact (id,venue_id,revenue,jobs_created) VALUES (1,1,100000,50); INSERT INTO Economic_Impact (id,venue_id,revenue,jobs_created) VALUES (2,2,150000,75); INSERT INTO Economic_Impact (id,venue_id,revenue,jobs_created) VALUES (3,3,200000,60);
|
SELECT SUM(revenue) as 'Total Revenue' FROM Economic_Impact WHERE venue_id IN (SELECT venue_id FROM Economic_Impact GROUP BY venue_id HAVING SUM(jobs_created) > 50);
|
List the top 3 threat intelligence sources that provided the most actionable intelligence in the past month, along with the number of actionable intelligence reports.
|
CREATE TABLE threat_intelligence (id INT PRIMARY KEY,source VARCHAR(50),actionable_report BOOLEAN); INSERT INTO threat_intelligence (id,source,actionable_report) VALUES (1,'FireEye',TRUE),(2,'CrowdStrike',FALSE),(3,'Mandiant',TRUE);
|
SELECT source, COUNT(*) as actionable_reports FROM threat_intelligence WHERE actionable_report = TRUE AND id IN (SELECT id FROM threat_intelligence WHERE occurrence_time >= NOW() - INTERVAL '1 month' ORDER BY id DESC LIMIT 3) GROUP BY source ORDER BY actionable_reports DESC;
|
Delete all records in the 'Projects' table where the country is 'Indonesia'
|
CREATE TABLE Projects (id INT PRIMARY KEY,project_name VARCHAR(255),country VARCHAR(255),budget FLOAT);
|
DELETE FROM Projects WHERE country = 'Indonesia';
|
Which maritime laws were enacted in the Mediterranean Sea since 2010?
|
CREATE TABLE maritime_laws (region TEXT,year INT,law_name TEXT); INSERT INTO maritime_laws (region,year,law_name) VALUES ('Mediterranean Sea',2010,'MARPOL Annex V'); INSERT INTO maritime_laws (region,year,law_name) VALUES ('Mediterranean Sea',2012,'MSFD'); INSERT INTO maritime_laws (region,year,law_name) VALUES ('Mediterranean Sea',2015,'IMO Paris MOU');
|
SELECT * FROM maritime_laws WHERE region = 'Mediterranean Sea' AND year >= 2010;
|
Show the number of unions by 'Union_Type' in the 'Labor_Unions' table.
|
CREATE TABLE Labor_Unions (id INT,union_type VARCHAR(20)); INSERT INTO Labor_Unions (id,union_type) VALUES (1,'Trade'),(2,'Industrial'),(3,'Trade'),(4,'Professional');
|
SELECT union_type, COUNT(*) FROM Labor_Unions GROUP BY union_type;
|
What is the average occupancy rate for eco-friendly accommodations in Brazil?
|
CREATE TABLE accommodation(accommodation_id INT,accommodation_name TEXT,country TEXT,is_eco_friendly BOOLEAN,occupancy_rate INT); INSERT INTO accommodation (accommodation_id,accommodation_name,country,is_eco_friendly,occupancy_rate) VALUES (1,'Eco Lodge','Brazil',true,85),(2,'Luxury Resort','Brazil',false,75),(3,'Green Hotel','Brazil',true,90);
|
SELECT AVG(occupancy_rate) FROM accommodation WHERE country = 'Brazil' AND is_eco_friendly = true;
|
How many peacekeeping operations were conducted by African nations between 2017 and 2021?
|
CREATE TABLE PeacekeepingOperations (nation VARCHAR(50),year INT,operation_count INT); INSERT INTO PeacekeepingOperations (nation,year,operation_count) VALUES ('Egypt',2017,3),('Nigeria',2017,4),('South Africa',2017,2),('Algeria',2017,1),('Morocco',2017,5),('Egypt',2018,3),('Nigeria',2018,4),('South Africa',2018,2),('Algeria',2018,1),('Morocco',2018,5);
|
SELECT SUM(operation_count) FROM PeacekeepingOperations WHERE nation IN ('Egypt', 'Nigeria', 'South Africa', 'Algeria', 'Morocco') AND year BETWEEN 2017 AND 2021;
|
What is the NTILE rank of spacecraft models based on their manufacturing cost?
|
CREATE TABLE SpacecraftManufacturing (id INT,model VARCHAR,cost FLOAT);
|
SELECT model, NTILE(4) OVER (ORDER BY cost) FROM SpacecraftManufacturing;
|
Calculate the total number of menu items in the Vegan category
|
CREATE TABLE Menu (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2));
|
SELECT COUNT(*) FROM Menu WHERE category = 'Vegan';
|
Identify countries in Asia with climate adaptation projects that have a higher budget than any project in Europe.
|
CREATE TABLE climate_adaptation(project_name TEXT,country TEXT,budget FLOAT); INSERT INTO climate_adaptation(project_name,country,budget) VALUES ('Project C','China',500000.00),('Project D','Germany',200000.00);
|
SELECT country FROM climate_adaptation WHERE budget > (SELECT MAX(budget) FROM climate_adaptation WHERE country = 'Europe') AND country = 'Asia';
|
How many artists are associated with each genre?
|
CREATE TABLE genres (id INT,genre TEXT); CREATE TABLE artist_genres (artist_id INT,genre_id INT); INSERT INTO genres (id,genre) VALUES (1,'Pop'),(2,'Rock'),(3,'Hip Hop'); INSERT INTO artist_genres (artist_id,genre_id) VALUES (1,1),(2,3),(3,1),(3,2);
|
SELECT genre, COUNT(DISTINCT artist_id) FROM artist_genres JOIN genres ON artist_genres.genre_id = genres.id GROUP BY genre;
|
What is the average time between maintenance for each type of naval equipment?
|
CREATE TABLE Equipment_Maintenance (Equipment_Type VARCHAR(255),Maintenance_Date DATE); INSERT INTO Equipment_Maintenance (Equipment_Type,Maintenance_Date) VALUES ('Aircraft','2020-01-01'),('Vehicles','2020-02-15'),('Naval','2020-03-01'),('Naval','2020-03-05'),('Naval','2020-03-10');
|
SELECT Equipment_Type, AVG(DATEDIFF(day, LAG(Maintenance_Date) OVER (PARTITION BY Equipment_Type ORDER BY Maintenance_Date), Maintenance_Date)) as Avg_Maintenance_Interval FROM Equipment_Maintenance WHERE Equipment_Type = 'Naval' GROUP BY Equipment_Type;
|
Insert new records for 3 items in a warehouse in Mexico City with the warehouse_id 30
|
CREATE TABLE item_inventory (item_id INT,item_name VARCHAR(50),quantity INT,warehouse_id INT); CREATE TABLE warehouse (warehouse_id INT,warehouse_name VARCHAR(50),city VARCHAR(50),country VARCHAR(50));
|
INSERT INTO item_inventory (item_id, item_name, quantity, warehouse_id) VALUES (1001, 'Item 1', 100, 30), (1002, 'Item 2', 200, 30), (1003, 'Item 3', 300, 30); INSERT INTO warehouse (warehouse_id, warehouse_name, city, country) VALUES (30, 'Mexico City Warehouse', 'Mexico City', 'Mexico');
|
List the number of mental health parity violations by state and violation type in Q2 2022.
|
CREATE TABLE mental_health_parity_violations (id INT,state VARCHAR(50),violation_type VARCHAR(50),violation_date DATE); INSERT INTO mental_health_parity_violations (id,state,violation_type,violation_date) VALUES (1,'California','Denial of Coverage','2022-04-15'),(2,'Texas','Inadequate Facilities','2022-05-20'),(3,'New York','Denial of Coverage','2022-06-05'),(4,'California','Inadequate Treatment','2022-04-25'),(5,'Texas','Denial of Coverage','2022-05-10');
|
SELECT state, violation_type, COUNT(*) as num_violations FROM mental_health_parity_violations WHERE violation_date >= '2022-04-01' AND violation_date < '2022-07-01' GROUP BY state, violation_type;
|
What is the number of graduate students in each department and their average GPA?
|
CREATE TABLE department (id INT,name TEXT); CREATE TABLE graduate_students (id INT,department_id INT,gpa REAL);
|
SELECT d.name, AVG(gs.gpa), COUNT(gs.id) FROM department d JOIN graduate_students gs ON d.id = gs.department_id GROUP BY d.name;
|
Which artists are most popular on streaming platforms?
|
CREATE TABLE Artists (artist_id INT,artist_name TEXT); CREATE TABLE Streams (stream_id INT,artist_id INT,streams INT);
|
SELECT artist_name, SUM(streams) as total_streams FROM Artists JOIN Streams ON Artists.artist_id = Streams.artist_id GROUP BY artist_name ORDER BY total_streams DESC;
|
Count the number of cargo incidents in the Mediterranean sea in the last 6 months.
|
CREATE TABLE cargo_incidents (id INT,vessel_name TEXT,location TEXT,incident_date DATE);
|
SELECT COUNT(*) FROM cargo_incidents WHERE location = 'Mediterranean sea' AND incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
Identify the defense projects with the longest and shortest timelines in North America.
|
CREATE TABLE DefenseProjects (project_id INT,region VARCHAR(50),timeline_days INT); INSERT INTO DefenseProjects (project_id,region,timeline_days) VALUES (1,'North America',365),(2,'North America',90);
|
SELECT project_id, timeline_days FROM DefenseProjects WHERE region = 'North America' AND timeline_days = (SELECT MAX(timeline_days) FROM DefenseProjects WHERE region = 'North America') UNION SELECT project_id, timeline_days FROM DefenseProjects WHERE region = 'North America' AND timeline_days = (SELECT MIN(timeline_days) FROM DefenseProjects WHERE region = 'North America')
|
List the top 3 countries with the most startup founders and the number of founders in each.
|
CREATE TABLE founders (id INT,name VARCHAR(50),country VARCHAR(30));
|
SELECT country, COUNT(*) AS founder_count FROM founders GROUP BY country ORDER BY founder_count DESC LIMIT 3;
|
What are the total sales for each category in the last month?
|
CREATE TABLE menus (menu_id INT,name VARCHAR(100),category VARCHAR(50),price DECIMAL(5,2),quantity INT); INSERT INTO menus (menu_id,name,category,price,quantity) VALUES (1,'Chicken Caesar Salad','Salad',12.99,300),(2,'Margherita Pizza','Pizza',9.99,450);
|
SELECT category, SUM(quantity * price) as total_sales FROM menus WHERE MONTH(order_date) = MONTH(CURRENT_DATE()) - 1 GROUP BY category;
|
What is the total number of research grants awarded to female and male faculty members?
|
CREATE TABLE faculty (id INT,gender TEXT,total_grants_awarded INT);
|
SELECT f.gender, SUM(f.total_grants_awarded) FROM faculty f GROUP BY f.gender;
|
How many medical examinations have been conducted on astronauts from Russia?
|
CREATE TABLE Astronauts (AstronautID INT,Name VARCHAR(50),Age INT,CountryOfOrigin VARCHAR(50)); INSERT INTO Astronauts (AstronautID,Name,Age,CountryOfOrigin) VALUES (1,'Anna Ivanova',35,'Russia'),(2,'John Doe',45,'USA'),(3,'Pedro Gomez',50,'Mexico'); CREATE TABLE MedicalExaminations (ExaminationID INT,AstronautID INT,ExaminationDate DATE); INSERT INTO MedicalExaminations (ExaminationID,AstronautID,ExaminationDate) VALUES (1,1,'2020-01-01'),(2,1,'2021-01-01'),(3,2,'2020-01-01'),(4,3,'2021-01-01');
|
SELECT COUNT(*) FROM Astronauts INNER JOIN MedicalExaminations ON Astronauts.AstronautID = MedicalExaminations.AstronautID WHERE Astronauts.CountryOfOrigin = 'Russia';
|
Which IP addresses have been associated with the most malicious activities in the last month from the 'threat_intel' table?
|
CREATE TABLE threat_intel (id INT,ip_address VARCHAR(50),activity VARCHAR(50),timestamp TIMESTAMP);
|
SELECT ip_address, COUNT(*) FROM threat_intel WHERE activity = 'malicious' AND timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY ip_address ORDER BY COUNT(*) DESC;
|
What is the total installed capacity (in MW) of renewable energy projects for each country, grouped by energy type?
|
CREATE TABLE project (id INT,country VARCHAR(50),energy_type VARCHAR(50),capacity INT); INSERT INTO project VALUES (1,'USA','Wind',200),(2,'Canada','Solar',150),(3,'Mexico','Hydro',250);
|
SELECT energy_type, country, SUM(capacity) FROM project GROUP BY energy_type, country;
|
What is the maximum depth at which a shipwreck has been discovered in the Atlantic Ocean?
|
CREATE TABLE shipwreck (id INT,name TEXT,location TEXT,depth FLOAT); INSERT INTO shipwreck (id,name,location,depth) VALUES (1,'Titanic','Atlantic Ocean',3784); INSERT INTO shipwreck (id,name,location,depth) VALUES (2,'Bismarck','Atlantic Ocean',4791);
|
SELECT MAX(depth) FROM shipwreck WHERE location = 'Atlantic Ocean';
|
Which excavation site has the most bone fragments?
|
CREATE TABLE SiteD (site_id INT,site_name VARCHAR(20),artifact_type VARCHAR(20),quantity INT); INSERT INTO SiteD (site_id,site_name,artifact_type,quantity) VALUES (1,'SiteD','Bone Fragments',30),(2,'SiteE','Pottery',40),(3,'SiteF','Bone Fragments',20);
|
SELECT site_name, MAX(quantity) FROM SiteD WHERE artifact_type = 'Bone Fragments';
|
Find the number of garments produced by each manufacturer, and the average lead time for each manufacturer, for the year 2022.
|
CREATE TABLE garment_manufacturing (manufacturer_id INT,garment_id INT,production_date DATE,lead_time INT); INSERT INTO garment_manufacturing VALUES (1,1,'2022-01-01',7),(1,2,'2022-01-05',10),(2,3,'2022-02-01',5),(2,4,'2022-02-03',8),(3,5,'2022-03-01',6);
|
SELECT manufacturer_id, COUNT(*) as num_garments, AVG(lead_time) as avg_lead_time FROM garment_manufacturing WHERE EXTRACT(YEAR FROM production_date) = 2022 GROUP BY manufacturer_id ORDER BY num_garments DESC;
|
Insert a new claim for policyholder 'David Kim' with a claim amount of $20,000 into the claims_table
|
CREATE TABLE claims_table (claim_id INT,policy_holder TEXT,claim_amount INT);
|
INSERT INTO claims_table (claim_id, policy_holder, claim_amount) VALUES (1, 'David Kim', 20000);
|
Which spacecraft were used in missions that had both a scientist and an engineer as crew members?
|
CREATE TABLE spacecrafts (spacecraft_id INT,name VARCHAR(50)); CREATE TABLE missions (mission_id INT,spacecraft_id INT,crew VARCHAR(50));
|
SELECT s.name FROM spacecrafts s INNER JOIN missions m ON s.spacecraft_id = m.spacecraft_id INNER JOIN (SELECT crew FROM crew_members WHERE role = 'scientist' INTERSECT SELECT crew FROM crew_members WHERE role = 'engineer') cm ON m.crew = cm.crew;
|
Identify the top 2 countries with the highest total Yttrium production in 2022, using a window function.
|
CREATE TABLE production (id INT,country VARCHAR(255),element VARCHAR(255),quantity INT,year INT); INSERT INTO production (id,country,element,quantity,year) VALUES (1,'China','Yttrium',1200,2022),(2,'China','Yttrium',1400,2022),(3,'USA','Yttrium',1000,2022),(4,'USA','Yttrium',1100,2022),(5,'Australia','Yttrium',800,2022),(6,'Australia','Yttrium',900,2022);
|
SELECT country, SUM(quantity) as total_quantity FROM production WHERE element = 'Yttrium' AND year = 2022 GROUP BY country ORDER BY total_quantity DESC FETCH FIRST 2 ROWS ONLY;
|
How many students have experienced mental health issues in 'OpenMindedSchool' district in the last year?
|
CREATE TABLE Student (StudentID INT,District VARCHAR(20)); CREATE TABLE MentalHealth (StudentID INT,Issue DATE); INSERT INTO Student (StudentID,District) VALUES (1,'OpenMindedSchool'); INSERT INTO Student (StudentID,District) VALUES (2,'ClosedMindedSchool'); INSERT INTO MentalHealth (StudentID,Issue) VALUES (1,'2022-01-01'); CREATE VIEW StudentMentalHealthView AS SELECT * FROM Student s JOIN MentalHealth m ON s.StudentID = m.StudentID WHERE m.Issue >= DATE(CURRENT_DATE) - 365;
|
SELECT COUNT(*) FROM StudentMentalHealthView WHERE District = 'OpenMindedSchool';
|
What are the unique types of rural infrastructure projects in the 'rural_infrastructure' table?
|
CREATE TABLE rural_infrastructure (id INT,name VARCHAR(50),type VARCHAR(50),budget FLOAT); INSERT INTO rural_infrastructure (id,name,type,budget) VALUES (1,'Solar Irrigation','Agricultural Innovation',150000.00),(2,'Wind Turbines','Rural Infrastructure',200000.00);
|
SELECT DISTINCT type FROM rural_infrastructure WHERE type = 'Rural Infrastructure';
|
Show the total amount of water saved through conservation efforts in the state of California for the year 2020
|
CREATE TABLE water_savings (savings_id INT,savings_date DATE,state VARCHAR(50),amount FLOAT); INSERT INTO water_savings (savings_id,savings_date,state,amount) VALUES (1,'2020-01-01','California',10000),(2,'2020-02-01','California',12000),(3,'2020-03-01','Texas',15000),(4,'2020-04-01','California',18000);
|
SELECT SUM(amount) as total_savings FROM water_savings WHERE savings_date BETWEEN '2020-01-01' AND '2020-12-31' AND state = 'California';
|
How many investments were made in total in Q2 2021?
|
CREATE TABLE investments (id INT,region VARCHAR(20),date DATE); INSERT INTO investments (id,region,date) VALUES (1,'Asia-Pacific','2021-01-05'),(2,'Europe','2021-02-10'),(3,'Asia-Pacific','2021-03-25'),(4,'Africa','2021-04-15'),(5,'Europe','2021-06-01');
|
SELECT COUNT(*) FROM investments WHERE date BETWEEN '2021-04-01' AND '2021-06-30';
|
What are the average delays in days for each space mission, calculated as the difference between the actual and planned launch date?
|
CREATE TABLE SpaceMissions (MissionID INT,MissionName VARCHAR(50),PlannedLaunchDate DATE,ActualLaunchDate DATE,Duration INT); INSERT INTO SpaceMissions (MissionID,MissionName,PlannedLaunchDate,ActualLaunchDate,Duration) VALUES (1,'Mission1','2022-01-01','2022-01-05',30);
|
SELECT MissionName, AVG(DATEDIFF(day, PlannedLaunchDate, ActualLaunchDate)) AS AverageDelay FROM SpaceMissions GROUP BY MissionName;
|
What is the maximum age of animals in the rehabilitation center in the month of January 2022?
|
CREATE TABLE rehab_ages (animal_id INT,age INT,admission_date DATE); INSERT INTO rehab_ages (animal_id,age,admission_date) VALUES (1,3,'2022-01-02'),(2,7,'2022-01-15'),(3,5,'2022-01-31'),(4,6,'2022-02-03');
|
SELECT MAX(age) FROM rehab_ages WHERE admission_date BETWEEN '2022-01-01' AND '2022-01-31';
|
What is the average monthly water consumption per capita in the United States?
|
CREATE TABLE water_usage (id INT,state VARCHAR(2),city VARCHAR(50),year INT,monthly_consumption FLOAT); INSERT INTO water_usage (id,state,city,year,monthly_consumption) VALUES (1,'CA','Los Angeles',2020,150),(2,'CA','Los Angeles',2021,155),(3,'NY','New York',2020,200),(4,'NY','New York',2021,210);
|
SELECT AVG(monthly_consumption) FROM water_usage WHERE state IN ('CA', 'NY');
|
What was the average daily revenue for cultural heritage tours in Greece for the year 2021?
|
CREATE TABLE cult_tours (tour_id INT,tour_name TEXT,country TEXT,revenue FLOAT,tour_date DATE); INSERT INTO cult_tours (tour_id,tour_name,country,revenue,tour_date) VALUES (1,'Acropolis Tour','Greece',3000.00,'2021-05-01'); INSERT INTO cult_tours (tour_id,tour_name,country,revenue,tour_date) VALUES (2,'Delphi Tour','Greece',2500.00,'2021-07-15'); INSERT INTO cult_tours (tour_id,tour_name,country,revenue,tour_date) VALUES (3,'Mykonos Windmill Tour','Greece',1500.00,'2021-12-30');
|
SELECT AVG(revenue/100) FROM cult_tours WHERE country = 'Greece' AND YEAR(tour_date) = 2021;
|
What is the maximum depth reached by a marine species in the Arctic basin?
|
CREATE TABLE marine_species_depths_arctic (name VARCHAR(255),basin VARCHAR(255),depth FLOAT); INSERT INTO marine_species_depths_arctic (name,basin,depth) VALUES ('Species5','Arctic',210.43),('Species6','Atlantic',123.45);
|
SELECT MAX(depth) as max_depth FROM marine_species_depths_arctic WHERE basin = 'Arctic';
|
Identify the number of rural hospitals in each state with more than 50 employees.
|
CREATE TABLE hospitals (id INT,name TEXT,state TEXT,num_employees INT);
|
SELECT state, COUNT(*) FROM hospitals WHERE num_employees > 50 GROUP BY state;
|
What is the maximum altitude reached by any satellite launched by Japan?
|
CREATE TABLE satellites (satellite_id INT,satellite_name VARCHAR(100),country VARCHAR(50),launch_date DATE,apogee FLOAT); INSERT INTO satellites (satellite_id,satellite_name,country,launch_date,apogee) VALUES (1,'Himawari 8','Japan','2014-10-07',35786); INSERT INTO satellites (satellite_id,satellite_name,country,launch_date,apogee) VALUES (2,'ETS-8','Japan','1998-12-02',22338);
|
SELECT MAX(apogee) FROM satellites WHERE country = 'Japan';
|
What is the total number of women farmers in the 'agriculture_innovation' table, partitioned by their country and sorted by the number of women farmers in descending order?;
|
CREATE TABLE agriculture_innovation (id INT,name VARCHAR(50),country VARCHAR(50),is_woman BOOLEAN); INSERT INTO agriculture_innovation VALUES (1,'John Doe','USA',false),(2,'Jane Smith','Canada',true),(3,'Pedro Sanchez','Mexico',false),(4,'Maria Garcia','Brazil',true),(5,'Jacques Dupont','France',false);
|
SELECT country, SUM(is_woman) as total_women_farmers FROM agriculture_innovation GROUP BY country ORDER BY total_women_farmers DESC;
|
How many students have enrolled in lifelong learning programs in the last month?
|
CREATE TABLE students_enrollment (id INT,student_id INT,country VARCHAR(255),enrollment_date DATE); INSERT INTO students_enrollment (id,student_id,country,enrollment_date) VALUES (1,1,'USA','2021-08-01'),(2,2,'Canada','2021-07-15'),(3,3,'USA','2021-01-01');
|
SELECT COUNT(DISTINCT student_id) FROM students_enrollment WHERE enrollment_date >= DATEADD(month, -1, GETDATE());
|
What is the average water usage by province for the year 2020 in Canada?
|
CREATE TABLE water_usage_canada(id INT,province VARCHAR(50),usage FLOAT,year INT); INSERT INTO water_usage_canada(id,province,usage,year) VALUES (1,'Ontario',550.2,2020);
|
SELECT province, AVG(usage) as avg_usage FROM water_usage_canada WHERE year = 2020 GROUP BY province;
|
find the total cost of projects in the 'infrastructure_projects' table that were completed in the second quarter of 2021, partitioned by the project's location and ordered by the total cost.
|
CREATE TABLE infrastructure_projects (id INT,name VARCHAR(50),location VARCHAR(50),start_date DATE,completion_date DATE,total_cost FLOAT);
|
SELECT location, SUM(total_cost) as total_cost, ROW_NUMBER() OVER (PARTITION BY location ORDER BY SUM(total_cost) DESC) as rn FROM infrastructure_projects WHERE DATEPART(quarter, completion_date) = 2 AND DATEPART(year, completion_date) = 2021 GROUP BY location ORDER BY total_cost DESC;
|
What is the average number of pallets handled per day by 'Warehouse C'?
|
CREATE TABLE Warehouse (name varchar(20),pallets_handled int,handling_date date); INSERT INTO Warehouse (name,pallets_handled,handling_date) VALUES ('Warehouse C',50,'2022-01-01'),('Warehouse C',60,'2022-01-02');
|
SELECT AVG(pallets_handled / (EXTRACT(DAY FROM handling_date) - EXTRACT(DAY FROM LAG(handling_date) OVER (PARTITION BY name ORDER BY handling_date)))) FROM Warehouse WHERE name = 'Warehouse C';
|
List all transactions in December 2021 that exceeded the customer's average transaction value.
|
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(255),city VARCHAR(255)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_date DATE,transaction_value DECIMAL(10,2)); INSERT INTO customers (customer_id,customer_name,city) VALUES (1,'John Doe','New York'),(2,'Jane Smith','Los Angeles'),(3,'Bob Johnson','Chicago'); INSERT INTO transactions (transaction_id,customer_id,transaction_date,transaction_value) VALUES (1,1,'2021-12-01',250.00),(2,1,'2021-12-05',300.00),(3,2,'2021-12-03',100.00);
|
SELECT t.transaction_id, t.customer_id, t.transaction_date, t.transaction_value FROM transactions t INNER JOIN (SELECT customer_id, AVG(transaction_value) as avg_transaction_value FROM transactions WHERE transaction_date BETWEEN '2021-12-01' AND '2021-12-31' GROUP BY customer_id) avg_tv ON t.customer_id = avg_tv.customer_id WHERE t.transaction_value > avg_tv.avg_transaction_value;
|
Find the total number of posts, comments, and likes from users in India, Japan, and Brazil.
|
CREATE TABLE users (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,content TEXT); CREATE TABLE comments (id INT,post_id INT,content TEXT); CREATE TABLE likes (id INT,user_id INT,post_id INT);
|
SELECT COUNT(*) FROM posts JOIN users ON posts.user_id = users.id WHERE users.country IN ('India', 'Japan', 'Brazil') UNION ALL SELECT COUNT(*) FROM comments JOIN users ON comments.post_id = posts.id JOIN users ON posts.user_id = users.id WHERE users.country IN ('India', 'Japan', 'Brazil') UNION ALL SELECT COUNT(*) FROM likes JOIN users ON likes.user_id = users.id WHERE users.country IN ('India', 'Japan', 'Brazil');
|
How many unique cargo types were transported by each vessel in the Mediterranean Sea?
|
CREATE TABLE vessel_cargo (id INT,vessel_id INT,cargo_type VARCHAR(255)); INSERT INTO vessel_cargo (id,vessel_id,cargo_type) VALUES (1,4,'Containers'); INSERT INTO vessel_cargo (id,vessel_id,cargo_type) VALUES (2,4,'Coal');
|
SELECT vessel_id, COUNT(DISTINCT cargo_type) as unique_cargo_types FROM vessel_cargo WHERE latitude BETWEEN 30 AND 46 AND longitude BETWEEN -10 AND 36 GROUP BY vessel_id;
|
Which public health policies related to vaccination were implemented in each state?
|
CREATE TABLE state_vaccination_policies (policy_id INT,policy_name VARCHAR(100),state_abbr CHAR(2)); INSERT INTO state_vaccination_policies VALUES (1,'Mandatory Vaccination for School Children','NY'),(2,'Influenza Vaccination Program for Healthcare Workers','CA'),(3,'Optional Vaccination for Adults','TX');
|
SELECT policy_name FROM state_vaccination_policies;
|
What is the total number of military personnel in each branch of the armed forces?
|
CREATE TABLE MilitaryPersonnel (id INT,branch VARCHAR(255),personnel_count INT); INSERT INTO MilitaryPersonnel (id,branch,personnel_count) VALUES (1,'Army',500000),(2,'Navy',350000),(3,'Air Force',300000);
|
SELECT branch, SUM(personnel_count) FROM MilitaryPersonnel GROUP BY branch;
|
What is the average number of artworks created by artists from Mexico?
|
CREATE TABLE Artworks (id INT,title VARCHAR(255),artist_id INT); CREATE TABLE Artists (id INT,name VARCHAR(255),nationality VARCHAR(255)); INSERT INTO Artists (id,name,nationality) VALUES (1,'Frida Kahlo','Mexico'); INSERT INTO Artworks (id,title,artist_id) VALUES (1,'Self-Portrait with Thorn Necklace and Hummingbird',1); INSERT INTO Artworks (id,title,artist_id) VALUES (2,'The Two Fridas',1);
|
SELECT AVG(COUNT(*)) FROM Artworks GROUP BY artist_id HAVING nationality = 'Mexico';
|
What is the average daily number of transactions for each smart contract in the 'smart_contracts' table?
|
CREATE TABLE smart_contracts (contract_id INT,contract_name VARCHAR(50),daily_transactions INT); INSERT INTO smart_contracts (contract_id,contract_name,daily_transactions) VALUES (1,'Uniswap',10000); INSERT INTO smart_contracts (contract_id,contract_name,daily_transactions) VALUES (2,'SushiSwap',8000);
|
SELECT contract_name, AVG(daily_transactions) FROM smart_contracts GROUP BY contract_name;
|
What is the average assets value for customers in 'Asia'?
|
CREATE TABLE customers (id INT,name VARCHAR(50),region VARCHAR(20),assets DECIMAL(10,2)); INSERT INTO customers (id,name,region,assets) VALUES (1,'John Doe','Southwest',50000.00),(2,'Jane Smith','Northeast',75000.00),(3,'Ali Ahmed','Asia',100000.00),(4,'Min Ji','Asia',120000.00);
|
SELECT AVG(assets) FROM customers WHERE region = 'Asia';
|
How many electric vehicles were sold in Japan in Q1 2021?
|
CREATE TABLE AsianSales (id INT,vehicle_type VARCHAR(50),quantity INT,country VARCHAR(50),quarter INT,year INT); INSERT INTO AsianSales (id,vehicle_type,quantity,country,quarter,year) VALUES (1,'Electric',1500,'Japan',1,2021),(2,'Electric',1200,'Japan',2,2021),(3,'Electric',1800,'China',1,2021),(4,'Electric',2000,'China',2,2021);
|
SELECT SUM(quantity) FROM AsianSales WHERE vehicle_type = 'Electric' AND country = 'Japan' AND quarter = 1 AND year = 2021;
|
Determine the average number of posts per day for the 'social_media' database.
|
CREATE TABLE posts (post_id INT,user_id INT,post_date DATE); INSERT INTO posts (post_id,user_id,post_date) VALUES (1,1,'2021-01-01'),(2,1,'2021-01-02'),(3,2,'2021-01-01'),(4,3,'2021-01-02'),(5,3,'2021-01-03'),(6,4,'2021-01-01');
|
SELECT AVG(num_posts_per_day) FROM (SELECT user_id, COUNT(*) / COUNT(DISTINCT post_date) AS num_posts_per_day FROM posts GROUP BY user_id) AS subquery;
|
What is the average speed of vessels that docked in the Port of Oakland in the last month?
|
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(255),AvgSpeed DECIMAL(5,2)); INSERT INTO Vessels (VesselID,VesselName,AvgSpeed) VALUES (1,'VesselA',15.5),(2,'VesselB',17.3),(3,'VesselC',13.9); CREATE TABLE Docking (DockingID INT,VesselID INT,Port VARCHAR(255),DockingTime TIMESTAMP); INSERT INTO Docking (DockingID,VesselID,Port,DockingTime) VALUES (1,1,'Oakland','2022-01-01 10:00:00'),(2,2,'Oakland','2022-01-05 14:30:00'),(3,3,'Los Angeles','2022-01-08 08:00:00');
|
SELECT AVG(V.AvgSpeed) FROM Vessels V INNER JOIN Docking D ON V.VesselID = D.VesselID WHERE D.Port = 'Oakland' AND DockingTime BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH) AND CURRENT_TIMESTAMP;
|
Display union names that have workplace safety metrics in both 'north_region' and 'east_region' but no labor rights advocacy activities?
|
CREATE TABLE union_safety (union_name TEXT,region TEXT); INSERT INTO union_safety (union_name,region) VALUES ('Union A','north_region'),('Union B','east_region'),('Union C','north_region'),('Union D','east_region'); CREATE TABLE union_advocacy (union_name TEXT,region TEXT); INSERT INTO union_advocacy (union_name,region) VALUES ('Union A','central_region'),('Union E','west_region'),('Union B','south_region'),('Union F','central_region');
|
SELECT union_name FROM union_safety WHERE region = 'north_region' INTERSECT SELECT union_name FROM union_safety WHERE region = 'east_region' EXCEPT SELECT union_name FROM union_advocacy;
|
Calculate the average delivery time for each carrier in the Europe region over the past year, including only carriers with at least 500 shipments.
|
CREATE TABLE Carriers (CarrierID int,CarrierName varchar(255),Region varchar(255));CREATE TABLE Shipments (ShipmentID int,CarrierID int,DeliveryTime int,ShippedDate datetime); INSERT INTO Carriers (CarrierID,CarrierName,Region) VALUES (1,'Carrier A','Europe'); INSERT INTO Shipments (ShipmentID,CarrierID,DeliveryTime,ShippedDate) VALUES (1,1,10,'2022-01-01');
|
SELECT c.CarrierName, AVG(s.DeliveryTime) as AverageDeliveryTime FROM Carriers c INNER JOIN Shipments s ON c.CarrierID = s.CarrierID WHERE c.Region = 'Europe' AND s.ShippedDate >= DATEADD(year, -1, GETDATE()) GROUP BY c.CarrierName HAVING COUNT(*) >= 500;
|
Create a table for storing COVID-19 testing data
|
CREATE TABLE covid_testing (id INT PRIMARY KEY,hospital_id INT,test_date DATE,tests_conducted INT);
|
INSERT INTO covid_testing (id, hospital_id, test_date, tests_conducted) VALUES (1, 1, '2023-02-01', 100), (2, 1, '2023-02-03', 120), (3, 2, '2023-02-01', 150);
|
Find the number of marine species with a vulnerable or endangered IUCN status.
|
CREATE TABLE marine_species (id INT,species_name VARCHAR(255),iucn_status VARCHAR(255));
|
(SELECT COUNT(*) FROM marine_species WHERE iucn_status IN ('Vulnerable', 'Endangered'))
|
What is the average CO2 emission rate per production batch, for each chemical product, in the past year?
|
CREATE TABLE production_batch (batch_id INT,batch_date DATE,product_id INT,product_name TEXT,co2_emission FLOAT); INSERT INTO production_batch (batch_id,batch_date,product_id,product_name,co2_emission) VALUES (1,'2021-01-01',1,'Product A',50.5),(2,'2021-02-05',2,'Product B',75.3),(3,'2021-03-10',3,'Product C',88.9);
|
SELECT product_name, AVG(co2_emission) OVER (PARTITION BY product_id ORDER BY batch_date ROWS BETWEEN 11 PRECEDING AND CURRENT ROW) AS avg_co2_rate FROM production_batch WHERE batch_date >= DATEADD(year, -1, CURRENT_DATE);
|
Determine the number of community development initiatives in North America having a budget between $100,000 and $500,000.
|
CREATE TABLE community_dev (id INT,name VARCHAR(255),region VARCHAR(255),budget FLOAT); INSERT INTO community_dev (id,name,region,budget) VALUES (1,'Healthcare Center','North America',350000.00);
|
SELECT COUNT(*) FROM community_dev WHERE region = 'North America' AND budget BETWEEN 100000 AND 500000;
|
What is the total number of accessible vehicles in the 'South' region?
|
CREATE TABLE Vehicles (VehicleID int,VehicleType varchar(255),Region varchar(255)); INSERT INTO Vehicles (VehicleID,VehicleType,Region) VALUES (1,'Bus','East'),(2,'Tram','West'),(3,'Wheelchair Bus','South');
|
SELECT COUNT(*) FROM Vehicles WHERE VehicleType = 'Wheelchair Bus' OR VehicleType = 'Accessible Tram' AND Region = 'South';
|
How many bikes and e-scooters are available in Berlin and Paris?
|
CREATE TABLE ride_sharing_berlin_paris (id INT,vehicle VARCHAR(20),city VARCHAR(20)); INSERT INTO ride_sharing_berlin_paris (id,vehicle,city) VALUES (1,'bike','Berlin'),(2,'e-scooter','Berlin'),(3,'bike','Paris'),(4,'e-scooter','Paris');
|
SELECT COUNT(*) FROM ride_sharing_berlin_paris WHERE city IN ('Berlin', 'Paris') AND vehicle IN ('bike', 'e-scooter');
|
What is the total number of vessels that complied with regulations in the South China Sea in the last quarter?
|
CREATE TABLE RegulatoryCompliance (Id INT,VesselName VARCHAR(50),Area VARCHAR(50),ComplianceDate DATETIME);
|
SELECT COUNT(DISTINCT VesselName) FROM RegulatoryCompliance WHERE Area = 'South China Sea' AND ComplianceDate >= DATEADD(QUARTER, -1, GETDATE()) GROUP BY VesselName HAVING COUNT(*) = 4;
|
Show the number of followers gained by users from Africa, grouped by week.
|
CREATE TABLE user_activity (id INT,user_id INT,activity_type VARCHAR(50),activity_date DATE,followers INT); INSERT INTO user_activity (id,user_id,activity_type,activity_date,followers) VALUES (1,1,'Followers Gained','2021-01-01',100),(2,2,'Followers Lost','2021-01-02',50); CREATE TABLE users (id INT,country VARCHAR(50)); INSERT INTO users (id,country) VALUES (1,'Egypt'),(2,'South Africa');
|
SELECT WEEK(activity_date) as week, COUNT(*) as follower_gain FROM user_activity JOIN users ON user_activity.user_id = users.id WHERE users.country IN ('Egypt', 'South Africa') AND activity_type = 'Followers Gained' GROUP BY WEEK(activity_date);
|
What is the total amount of research grants awarded to faculty members in the College of Engineering who have authored more than 5 publications?
|
CREATE TABLE department (id INT,name TEXT);CREATE TABLE faculty (id INT,department_id INT,publication_count INT);CREATE TABLE research_grant (id INT,faculty_id INT,amount INT);
|
SELECT SUM(rg.amount) FROM research_grant rg JOIN faculty f ON rg.faculty_id = f.id JOIN department d ON f.department_id = d.id WHERE d.name = 'College of Engineering' AND f.publication_count > 5;
|
List all defense projects with timelines ending in 2023 or later
|
CREATE TABLE defense_projects (project_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO defense_projects (project_name,start_date,end_date) VALUES ('Project A','2021-01-01','2023-12-31'),('Project B','2019-01-01','2022-12-31'),('Project F','2020-01-01','2023-12-31');
|
SELECT project_name FROM defense_projects WHERE end_date >= '2023-01-01';
|
What is the maximum number of workers in unions advocating for workplace safety in California?
|
CREATE TABLE unions (id INT,state VARCHAR(2),workers INT,issue VARCHAR(14));
|
SELECT MAX(workers) FROM unions WHERE state = 'CA' AND issue = 'workplace_safety';
|
Who is the user with the highest number of posts containing "#gaming" in the past year, with at least 20 posts?
|
CREATE TABLE users (id INT,name VARCHAR(255),posts INT); CREATE TABLE posts (id INT,user INT,content TEXT,timestamp TIMESTAMP);
|
SELECT u.name FROM users u JOIN (SELECT user, COUNT(*) AS post_count FROM posts WHERE content LIKE '%#gaming%' AND timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW() GROUP BY user HAVING COUNT(*) >= 20) pc ON u.id = pc.user ORDER BY u.posts DESC, pc.post_count DESC LIMIT 1;
|
What is the total budget allocated for accessibility improvements in urban areas?
|
CREATE TABLE budget_allocation (location VARCHAR(20),category VARCHAR(30),amount DECIMAL); INSERT INTO budget_allocation (location,category,amount) VALUES ('Urban','Accessibility Improvements',250000.00); INSERT INTO budget_allocation (location,category,amount) VALUES ('Urban','Accessibility Improvements',300000.00);
|
SELECT SUM(amount) FROM budget_allocation WHERE location = 'Urban' AND category = 'Accessibility Improvements';
|
Update the warehouse table to set the city for warehouse_id 001 to 'New York'
|
CREATE TABLE warehouse (warehouse_id VARCHAR(10),city VARCHAR(20),state VARCHAR(20),country VARCHAR(20));
|
UPDATE warehouse SET city = 'New York' WHERE warehouse_id = '001';
|
What is the average response time to security incidents for IT companies in Q4 2020, grouped by country?
|
CREATE TABLE security_incidents (id INT,company TEXT,country TEXT,incident_date DATE,response_time INT); INSERT INTO security_incidents (id,company,country,incident_date,response_time) VALUES (1,'IT Company A','USA','2020-10-15',120); INSERT INTO security_incidents (id,company,country,incident_date,response_time) VALUES (2,'IT Company B','Canada','2020-11-02',180);
|
SELECT country, AVG(response_time) FROM security_incidents WHERE company LIKE '%IT Company%' AND incident_date >= '2020-10-01' AND incident_date < '2021-01-01' GROUP BY country;
|
How many posts were created by users from underrepresented communities in Q1 2022?
|
CREATE TABLE posts (user_id INT,post_date DATE); CREATE TABLE users (id INT,community VARCHAR(20)); INSERT INTO posts (user_id,post_date) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2022-03-01'); INSERT INTO users (id,community) VALUES (1,'Women in Tech'),(2,'LGBTQ+'),(3,'Minority Owned Business'); INSERT INTO users (id,community) VALUES (4,'Allies'),(5,'Underrepresented');
|
SELECT COUNT(*) FROM posts JOIN users ON posts.user_id = users.id WHERE users.community IN ('Women in Tech', 'LGBTQ+', 'Minority Owned Business') AND posts.post_date BETWEEN '2022-01-01' AND '2022-03-31';
|
How many cruelty-free products does the company have?
|
CREATE TABLE products (id INT,company VARCHAR(255),cruelty_free BOOLEAN); INSERT INTO products (id,company,cruelty_free) VALUES (1,'ABC',TRUE),(2,'DEF',FALSE),(3,'ABC',TRUE);
|
SELECT COUNT(*) FROM products WHERE cruelty_free = TRUE;
|
What is the number of public libraries and the total square footage of each library in the state of New York?
|
CREATE TABLE libraries (library_name VARCHAR(255),district_name VARCHAR(255),square_footage INT); INSERT INTO libraries (library_name,district_name,square_footage) VALUES ('Library1','DistrictA',15000),('Library2','DistrictA',20000),('Library3','DistrictB',25000),('Library4','DistrictB',30000);
|
SELECT district_name, COUNT(library_name) AS num_libraries, SUM(square_footage) AS total_square_footage FROM libraries GROUP BY district_name;
|
List the total number of pollution control initiatives implemented in the Atlantic and Arctic regions.
|
CREATE TABLE PollutionControl (id INT,initiative VARCHAR(50),region VARCHAR(20)); INSERT INTO PollutionControl (id,initiative,region) VALUES (1,'Ocean Cleanup','Arctic'),(2,'Plastic Reduction','Atlantic'),(3,'Carbon Capture','Global');
|
SELECT region, COUNT(*) as total_initiatives FROM PollutionControl WHERE region IN ('Atlantic', 'Arctic') GROUP BY region;
|
Find the total acreage of farm A and farm B
|
CREATE TABLE farm_details (farm_name TEXT,acreage INTEGER); INSERT INTO farm_details (farm_name,acreage) VALUES ('Farm A',500),('Farm B',700);
|
SELECT SUM(acreage) FROM farm_details WHERE farm_name IN ('Farm A', 'Farm B');
|
Determine the number of volunteers for each program and the total number of volunteers
|
CREATE TABLE volunteers (id INT,name VARCHAR,email VARCHAR,phone VARCHAR); CREATE TABLE volunteer_assignments (id INT,volunteer_id INT,program_id INT);
|
SELECT volunteer_assignments.program_id, COUNT(DISTINCT volunteers.id) as total_volunteers, COUNT(DISTINCT volunteer_assignments.volunteer_id) as num_volunteers FROM volunteers JOIN volunteer_assignments ON volunteers.id = volunteer_assignments.volunteer_id GROUP BY volunteer_assignments.program_id;
|
What is the average size of properties in the 'properties' table?
|
CREATE TABLE properties (id INT,size FLOAT,PRIMARY KEY (id)); INSERT INTO properties (id,size) VALUES (1,1200.0),(2,800.0),(3,1500.0),(4,1000.0);
|
SELECT AVG(size) FROM properties;
|
What is the total number of community development initiatives in each province, sorted by initiative count in descending order?
|
CREATE TABLE provinces (province_id INT,province_name VARCHAR(255)); CREATE TABLE initiatives (initiative_id INT,initiative_name VARCHAR(255),province_id INT);
|
SELECT p.province_name, COUNT(i.initiative_id) as initiative_count FROM provinces p JOIN initiatives i ON p.province_id = i.province_id GROUP BY p.province_name ORDER BY initiative_count DESC;
|
List all spacecraft that have been used for missions to the International Space Station, and display them in alphabetical order.
|
CREATE TABLE ISSMissions (SpacecraftName TEXT,MissionType TEXT);
|
SELECT SpacecraftName FROM ISSMissions ORDER BY SpacecraftName ASC;
|
What is the total number of eco-friendly accommodations in Africa and their average sustainability scores?
|
CREATE TABLE Scores (id INT,country VARCHAR(50),score INT); INSERT INTO Scores (id,country,score) VALUES (1,'Egypt',80),(2,'South Africa',85); CREATE TABLE Accommodations_Africa (id INT,country VARCHAR(50),type VARCHAR(50)); INSERT INTO Accommodations_Africa (id,country,type) VALUES (1,'Egypt','Eco-Friendly'),(2,'South Africa','Eco-Friendly');
|
SELECT AVG(Scores.score) FROM Scores INNER JOIN Accommodations_Africa ON Scores.country = Accommodations_Africa.country WHERE Accommodations_Africa.type = 'Eco-Friendly' AND Scores.country IN ('Egypt', 'South Africa');
|
What is the difference between the total donations for 'Habitats for Tigers' and 'Habitats for Lions'?
|
CREATE TABLE Donations (id INT,campaign VARCHAR(255),amount DECIMAL(10,2));
|
SELECT (SELECT SUM(amount) FROM Donations WHERE campaign = 'Habitats for Tigers') - (SELECT SUM(amount) FROM Donations WHERE campaign = 'Habitats for Lions');
|
Insert a new record for a disaster with ID 11, name 'Tornado', and start date 2022-03-01 into the "disasters" table
|
CREATE TABLE disasters (id INT PRIMARY KEY,name TEXT,start_date DATE);
|
INSERT INTO disasters (id, name, start_date) VALUES (11, 'Tornado', '2022-03-01');
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.