instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the average salary of employees in the 'research' department?
|
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(20),salary DECIMAL(10,2)); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','manufacturing',50000.00),(2,'Jane Smith','engineering',60000.00),(3,'Alice Johnson','HR',55000.00),(4,'Bob Brown','research',70000.00),(5,'Charlie Davis','sales',65000.00);
|
SELECT AVG(salary) FROM employees WHERE department = 'research';
|
List the facilities located outside of the United States and their corresponding environmental impact scores from the 'facilities' and 'scores' tables.
|
CREATE TABLE facilities(facility_id INT,facility_name TEXT,country TEXT); CREATE TABLE scores(facility_id INT,environmental_score INT);
|
SELECT facilities.facility_name, scores.environmental_score FROM facilities INNER JOIN scores ON facilities.facility_id = scores.facility_id WHERE facilities.country NOT IN ('United States', 'USA', 'US');
|
What is the total amount of research grants awarded to each faculty member in the Physics department?
|
CREATE TABLE faculty (faculty_id INT,name VARCHAR(50),department VARCHAR(50)); CREATE TABLE grants (grant_id INT,faculty_id INT,amount FLOAT);
|
SELECT faculty.name, SUM(grants.amount) FROM faculty JOIN grants ON faculty.faculty_id = grants.faculty_id WHERE faculty.department = 'Physics' GROUP BY faculty.name;
|
Show the diversity score for companies founded by immigrants
|
CREATE TABLE companies (id INT,name VARCHAR(50),founder_immigrant INT); CREATE TABLE diversity_data (id INT,company_id INT,gender_diversity INT,racial_diversity INT); INSERT INTO companies VALUES (1,'Ada Tech',1); INSERT INTO companies VALUES (2,'Beta Corp',0); INSERT INTO diversity_data VALUES (1,1,50,30); INSERT INTO diversity_data VALUES (2,2,40,60);
|
SELECT companies.name, (diversity_data.gender_diversity + diversity_data.racial_diversity)/2 AS diversity_score FROM companies INNER JOIN diversity_data ON companies.id = diversity_data.company_id WHERE companies.founder_immigrant = 1;
|
What is the average temperature for each day of the week for the last 6 months?
|
CREATE TABLE Temperature (id INT,timestamp DATE,temperature REAL);
|
SELECT EXTRACT(DOW FROM timestamp) as day_of_week, AVG(temperature) as avg_temperature FROM Temperature WHERE timestamp >= DATEADD(MONTH, -6, CURRENT_DATE) GROUP BY day_of_week;
|
List the number of unique mental health conditions treated in the 'treatment' table.
|
CREATE TABLE treatment (treatment_id INT,patient_id INT,condition VARCHAR(50),provider VARCHAR(50),date DATE); INSERT INTO treatment (treatment_id,patient_id,condition,provider,date) VALUES (1,1,'Anxiety Disorder','Dr. Jane','2021-01-01'); INSERT INTO treatment (treatment_id,patient_id,condition,provider,date) VALUES (2,1,'PTSD','Dr. Bob','2021-02-01');
|
SELECT COUNT(DISTINCT condition) FROM treatment;
|
List all marine species that are endemic to the Indian Ocean.
|
CREATE TABLE marine_species (id INT,species VARCHAR(255),region VARCHAR(255),endemic BOOLEAN);
|
SELECT species FROM marine_species WHERE region LIKE '%Indian%' AND endemic = TRUE;
|
Show the average 'League of Legends' match duration for the top 5 longest matches played in the 'Diamond' rank.
|
CREATE TABLE matches (id INT,game VARCHAR(10),rank VARCHAR(20),match_duration INT); INSERT INTO matches (id,game,rank,match_duration) VALUES (1,'League of Legends','Diamond',45);
|
SELECT AVG(match_duration) FROM matches WHERE game = 'League of Legends' AND rank = 'Diamond' AND match_duration IN (SELECT DISTINCT match_duration FROM matches WHERE game = 'League of Legends' AND rank = 'Diamond' ORDER BY match_duration DESC LIMIT 5);
|
What is the average rating of each hotel in the luxury_hotels view?
|
CREATE VIEW luxury_hotels AS SELECT * FROM hotels WHERE revenue > 1000000; CREATE TABLE hotel_ratings (hotel_id INT,rating INT);
|
SELECT h.hotel_name, AVG(hr.rating) FROM luxury_hotels h JOIN hotel_ratings hr ON h.id = hr.hotel_id GROUP BY h.hotel_name;
|
What is the average CO2 emission of transportation methods used for tourism in Cairo?
|
CREATE TABLE transportation (transport_id INT,name TEXT,city TEXT,co2_emission FLOAT); INSERT INTO transportation (transport_id,name,city,co2_emission) VALUES (1,'Taxi','Cairo',2.5),(2,'Bus','Cairo',1.8);
|
SELECT AVG(co2_emission) FROM transportation WHERE city = 'Cairo';
|
Find the number of new employees hired each month in 2021, by department.
|
CREATE TABLE employee_history (employee_id INT,hire_date DATE,department VARCHAR(255));
|
SELECT department, COUNT(DISTINCT employee_id) FROM employee_history WHERE hire_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY department;
|
What is the maximum number of peacekeeping personnel trained by the United Nations in counter-terrorism between 2016 and 2021, inclusive?
|
CREATE TABLE peacekeeping_training(id INT,personnel_id INT,trained_by VARCHAR(255),trained_in VARCHAR(255),training_year INT); INSERT INTO peacekeeping_training(id,personnel_id,trained_by,trained_in,training_year) VALUES (1,111,'UN','Counter-Terrorism',2016),(2,222,'AU','Peacekeeping Tactics',2017),(3,333,'UN','Counter-Terrorism',2018),(4,444,'UN','Counter-Terrorism',2019),(5,555,'UN','Counter-Terrorism',2020),(6,666,'UN','Counter-Terrorism',2021);
|
SELECT MAX(personnel_id) FROM peacekeeping_training WHERE trained_by = 'UN' AND trained_in = 'Counter-Terrorism' AND training_year BETWEEN 2016 AND 2021;
|
How many teachers have not participated in any professional development programs in the last 3 years, grouped by subject area and highest degree obtained?
|
CREATE TABLE teachers_pd (teacher_id INT,subject_area TEXT,highest_degree TEXT,last_pd_program_date DATE); INSERT INTO teachers_pd (teacher_id,subject_area,highest_degree,last_pd_program_date) VALUES (1,'Math','Master','2020-01-01'),(2,'Science','Doctorate','2019-06-15'),(3,'English','Bachelor','2021-02-20');
|
SELECT subject_area, highest_degree, COUNT(*) FROM teachers_pd WHERE last_pd_program_date < DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) GROUP BY subject_area, highest_degree;
|
What was the total budget for policy advocacy in "Africa" region in 2018?
|
CREATE TABLE Policy_Advocacy (advocacy_id INT,region VARCHAR(20),budget DECIMAL(10,2),year INT); INSERT INTO Policy_Advocacy (advocacy_id,region,budget,year) VALUES (1,'Southeast',5000,2020),(2,'Northwest',6000,2019),(3,'East Coast',7000,2020),(4,'East Coast',6000,2019),(5,'Northeast',8000,2019),(6,'Northeast',9000,2018),(7,'West Coast',10000,2019),(8,'Africa',11000,2018);
|
SELECT SUM(budget) FROM Policy_Advocacy WHERE region = 'Africa' AND year = 2018;
|
How many rare earth element producers are there in Africa?
|
CREATE TABLE producers (id INT PRIMARY KEY,name VARCHAR(50),country VARCHAR(50)); INSERT INTO producers (id,name,country) VALUES (1,'ABC Rare Earths','Morocco'); INSERT INTO producers (id,name,country) VALUES (2,'XYZ Mining','South Africa'); INSERT INTO producers (id,name,country) VALUES (3,'DEF Rare Earths','Egypt');
|
SELECT COUNT(DISTINCT p.country) AS num_producers FROM producers p WHERE p.country IN ('Morocco', 'South Africa', 'Egypt', 'Nigeria', 'Madagascar');
|
What is the average funding round size for startups founded by women?
|
CREATE TABLE startup (id INT,name TEXT,founder_gender TEXT,funding_round_size INT); INSERT INTO startup (id,name,founder_gender,funding_round_size) VALUES (1,'StartupX','Female',5000000);
|
SELECT AVG(funding_round_size) FROM startup WHERE founder_gender = 'Female';
|
Who are the top 5 students with the most accommodations in the past academic year?
|
CREATE TABLE Students (StudentID INT,FirstName VARCHAR(50),LastName VARCHAR(50)); INSERT INTO Students (StudentID,FirstName,LastName) VALUES (1,'Mia','Smith'); INSERT INTO Students (StudentID,FirstName,LastName) VALUES (2,'Jamal','Johnson'); CREATE TABLE Accommodations (AccommodationID INT,StudentID INT,AccommodationType VARCHAR(50),Date DATE); INSERT INTO Accommodations (AccommodationID,StudentID,AccommodationType,Date) VALUES (1,1,'Note Taker','2022-01-01'); INSERT INTO Accommodations (AccommodationID,StudentID,AccommodationType,Date) VALUES (2,1,'Extended Testing Time','2022-02-01');
|
SELECT Students.FirstName, Students.LastName, COUNT(Accommodations.AccommodationID) as NumberOfAccommodations FROM Students INNER JOIN Accommodations ON Students.StudentID = Accommodations.StudentID WHERE Accommodations.Date BETWEEN DATEADD(year, -1, GETDATE()) AND GETDATE() GROUP BY Students.FirstName, Students.LastName ORDER BY NumberOfAccommodations DESC LIMIT 5;
|
Delete records with a population less than 500 from the 'rural_settlements' table
|
CREATE TABLE rural_settlements (name VARCHAR(255),population INT,country VARCHAR(255));
|
DELETE FROM rural_settlements WHERE population < 500;
|
What are the names of the rural health departments that have more than one physician?
|
CREATE TABLE departments (name VARCHAR(255),physician_count INT); INSERT INTO departments (name,physician_count) VALUES (1,2),(2,1);
|
SELECT name FROM departments WHERE physician_count > 1;
|
Delete the record for 'Tokyo' on '2022-08-01'.
|
CREATE TABLE weather (city VARCHAR(255),temperature FLOAT,date DATE); INSERT INTO weather (city,temperature,date) VALUES ('Tokyo',80,'2022-08-01');
|
DELETE FROM weather WHERE city = 'Tokyo' AND date = '2022-08-01';
|
What is the total number of virtual tours of historical sites in Europe?
|
CREATE TABLE tour (id INT,name TEXT,type TEXT); INSERT INTO tour (id,name,type) VALUES (1,'Historical Tour','Virtual'); INSERT INTO tour (id,name,type) VALUES (2,'Cultural Tour','In-person'); INSERT INTO tour (id,name,type) VALUES (3,'Nature Tour','Virtual');
|
SELECT COUNT(*) as total_virtual_tours FROM tour WHERE type = 'Virtual' AND name LIKE '%historical%';
|
Delete all employees who were part of the 'Internship' program and hired before 2020
|
CREATE TABLE Employees (Employee_ID INT,Name VARCHAR(100),Department VARCHAR(50),Salary DECIMAL(10,2),Hire_Date DATE,Program VARCHAR(50)); INSERT INTO Employees (Employee_ID,Name,Department,Salary,Hire_Date,Program) VALUES (1,'John Doe','Marketing',70000,'2021-05-15','Diversity_Hiring'); INSERT INTO Employees (Employee_ID,Name,Department,Salary,Hire_Date,Program) VALUES (2,'Jane Smith','IT',80000,'2021-06-20','Diversity_Hiring'); INSERT INTO Employees (Employee_ID,Name,Department,Salary,Hire_Date,Program) VALUES (3,'Alice Johnson','Finance',90000,'2020-08-01','Internship'); INSERT INTO Employees (Employee_ID,Name,Department,Salary,Hire_Date,Program) VALUES (4,'Bob Brown','Finance',85000,'2019-11-10','Internship');
|
DELETE FROM Employees WHERE Program = 'Internship' AND Hire_Date < '2020-01-01';
|
How many international visitors arrived in New Zealand from Asia in the last 3 months?
|
CREATE TABLE international_visitors (visitor_id INT,country TEXT,arrival_date DATE); INSERT INTO international_visitors (visitor_id,country,arrival_date) VALUES (1,'China','2022-01-01'),(2,'Japan','2022-02-01'),(3,'India','2022-03-01'),(4,'Australia','2022-01-15'),(5,'New Zealand','2022-02-20'),(6,'Indonesia','2022-03-10');
|
SELECT COUNT(*) FROM international_visitors WHERE country IN ('China', 'Japan', 'India') AND arrival_date >= DATE('now', '-3 month');
|
What is the average age of archaeologists who have excavated at the 'Ancient City' site?
|
CREATE TABLE Archaeologists (ArchaeologistID INT,Age INT,Name VARCHAR(50)); INSERT INTO Archaeologists (ArchaeologistID,Age,Name) VALUES (1,35,'John Doe'); INSERT INTO Archaeologists (ArchaeologistID,Age,Name) VALUES (2,42,'Jane Smith'); INSERT INTO Archaeologists (ArchaeologistID,Age,Name) VALUES (3,50,'Michael Lee'); CREATE TABLE Excavations (ExcavationID INT,Site VARCHAR(50),ArchaeologistID INT); INSERT INTO Excavations (ExcavationID,Site,ArchaeologistID) VALUES (1,'Ancient City',1); INSERT INTO Excavations (ExcavationID,Site,ArchaeologistID) VALUES (2,'Lost Village',2); INSERT INTO Excavations (ExcavationID,Site,ArchaeologistID) VALUES (3,'Ancient City',3);
|
SELECT AVG(A.Age) FROM Archaeologists A INNER JOIN Excavations E ON A.ArchaeologistID = E.ArchaeologistID WHERE E.Site = 'Ancient City';
|
Show the average installed capacity of solar power projects for each location in the renewable_projects table.
|
CREATE TABLE renewable_projects (project_id INT,project_name VARCHAR(255),location VARCHAR(255),technology VARCHAR(255),installed_capacity FLOAT);
|
SELECT location, AVG(installed_capacity) FROM renewable_projects WHERE technology = 'Solar' GROUP BY location;
|
What is the total number of emergency incidents reported in urban areas, broken down by incident type, and the total population of those urban areas?
|
CREATE TABLE urban_areas (id INT,area TEXT,population INT); INSERT INTO urban_areas (id,area,population) VALUES (1,'Area 1',900000),(2,'Area 2',1050000),(3,'Area 3',850000); CREATE TABLE emergency_incidents (id INT,area TEXT,incident_type TEXT,incident_count INT); INSERT INTO emergency_incidents (id,area,incident_type,incident_count) VALUES (1,'Area 1','Fire',1200),(2,'Area 1','Medical',1800),(3,'Area 2','Fire',1400),(4,'Area 2','Medical',2200),(5,'Area 3','Fire',1500),(6,'Area 3','Medical',2300);
|
SELECT area, incident_type, SUM(incident_count) AS total_incidents, population FROM urban_areas u JOIN emergency_incidents e ON u.area = e.area GROUP BY area, incident_type;
|
What is the average price of eco-friendly materials sourced from Italy?
|
CREATE TABLE eco_materials (id INT,country VARCHAR(20),price DECIMAL(5,2)); INSERT INTO eco_materials (id,country,price) VALUES (1,'Italy',25.99),(2,'France',30.49),(3,'Italy',28.50);
|
SELECT AVG(price) FROM eco_materials WHERE country = 'Italy';
|
How many autonomous driving research papers were published by Waymo in 2020?
|
CREATE TABLE ResearchPapers (Id INT,Publisher VARCHAR(50),Year INT,Title VARCHAR(100)); INSERT INTO ResearchPapers (Id,Publisher,Year,Title) VALUES (1,'Waymo',2018,'Autonomous Driving and Its Impact'),(2,'Waymo',2020,'Improving Perception for Autonomous Vehicles'),(3,'Waymo',2019,'Deep Learning for Autonomous Driving'),(4,'Cruise',2020,'Advancements in Autonomous Driving');
|
SELECT COUNT(*) FROM ResearchPapers WHERE Publisher = 'Waymo' AND Year = 2020;
|
Which technology for social good initiatives in South Asia have the highest accessibility score?
|
CREATE TABLE social_good_initiatives (id INT,initiative_name VARCHAR(255),location VARCHAR(255),accessibility_score FLOAT);
|
SELECT initiative_name, accessibility_score FROM social_good_initiatives WHERE location = 'South Asia' ORDER BY accessibility_score DESC LIMIT 1;
|
What is the earliest date a package was shipped from Japan to India?
|
CREATE TABLE Shipments (id INT,item VARCHAR(50),shipped_date DATE,source_country VARCHAR(50),destination_country VARCHAR(50)); INSERT INTO Shipments (id,item,shipped_date,source_country,destination_country) VALUES (1,'Foo','2022-01-01','Japan','India'),(2,'Bar','2022-01-05','India','Japan');
|
SELECT MIN(shipped_date) FROM Shipments WHERE source_country = 'Japan' AND destination_country = 'India';
|
What is the average age of patients who received cognitive behavioral therapy (CBT) in Canada?
|
CREATE TABLE mental_health_treatments (id INT,patient_id INT,treatment_name TEXT,country TEXT); INSERT INTO mental_health_treatments (id,patient_id,treatment_name,country) VALUES (1,123,'CBT','Canada');
|
SELECT AVG(patient_age) FROM patients JOIN mental_health_treatments ON patients.id = mental_health_treatments.patient_id WHERE treatment_name = 'CBT' AND country = 'Canada';
|
Delete records of athletes who left the team before 2020
|
CREATE TABLE athletes (athlete_id INT,name VARCHAR(50),sport VARCHAR(50),join_year INT,leave_year INT); INSERT INTO athletes (athlete_id,name,sport,join_year,leave_year) VALUES (1,'Jane Doe','Basketball',2021,2022),(2,'John Smith','Soccer',2019,NULL);
|
DELETE FROM athletes WHERE leave_year IS NOT NULL AND leave_year < 2020;
|
What is the average donation amount per month in 2021?
|
CREATE TABLE Donations (DonationID INT,DonationDate DATE,Amount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonationDate,Amount) VALUES (1,'2021-01-01',100.00),(2,'2021-02-01',200.00);
|
SELECT AVG(Amount) as AvgDonation, DATE_FORMAT(DonationDate, '%Y-%m') as Month FROM Donations WHERE YEAR(DonationDate) = 2021 GROUP BY Month;
|
Insert a new record of crop 'taro' for farm 'Lush Prairies' in 2024
|
CREATE TABLE farms (id INT,name TEXT,location TEXT,size FLOAT); INSERT INTO farms (id,name,location,size) VALUES (1,'Lush Prairies','Canada',250.0); CREATE TABLE crops (id INT,farm_id INT,crop TEXT,yield INT,year INT);
|
INSERT INTO crops (id, farm_id, crop, yield, year) VALUES (6, (SELECT id FROM farms WHERE name = 'Lush Prairies'), 'taro', 80, 2024);
|
Which AI researchers have published papers in AI conferences held in Canada?
|
CREATE TABLE ai_researcher(id INT PRIMARY KEY,name VARCHAR(50),country VARCHAR(50)); INSERT INTO ai_researcher (id,name,country) VALUES (1,'Alice','USA'),(2,'Bob','Canada'),(3,'Charlie','UK'); CREATE TABLE ai_papers(id INT PRIMARY KEY,title VARCHAR(50),researcher_id INT,conference_id INT); INSERT INTO ai_papers (id,title,researcher_id,conference_id) VALUES (1,'Fair AI',1,2),(2,'AI Safety',3,2); CREATE TABLE researcher_conferences(researcher_id INT,conference_id INT); INSERT INTO researcher_conferences (researcher_id,conference_id) VALUES (1,2),(2,2),(3,2);
|
SELECT DISTINCT r.name FROM ai_researcher r INNER JOIN researcher_conferences rc ON r.id = rc.researcher_id WHERE rc.conference_id IN (SELECT id FROM ai_conferences WHERE location = 'Canada');
|
Calculate the total funding amount for companies in specific geographic regions.
|
CREATE TABLE companies (id INT,name TEXT,founded_date DATE,founder_gender TEXT,region TEXT); INSERT INTO companies (id,name,founded_date,founder_gender,region) VALUES (1,'Acme Inc','2010-01-01','male','NA'); INSERT INTO companies (id,name,founded_date,founder_gender,region) VALUES (2,'Beta Corp','2015-05-15','male','EU'); INSERT INTO companies (id,name,founded_date,founder_gender,region) VALUES (3,'Gamma Startup','2018-09-09','female','AP'); CREATE TABLE investments (id INT,company_id INT,round_number INT,funding_amount INT); INSERT INTO investments (id,company_id,round_number,funding_amount) VALUES (1,1,1,500000); INSERT INTO investments (id,company_id,round_number,funding_amount) VALUES (2,2,1,2000000); INSERT INTO investments (id,company_id,round_number,funding_amount) VALUES (3,3,1,800000);
|
SELECT companies.region, SUM(investments.funding_amount) FROM companies JOIN investments ON companies.id = investments.company_id GROUP BY companies.region;
|
Update the annual salary of all employees in the Accessibility department to 85000.
|
CREATE TABLE departments (dept_id INT,dept_name TEXT); CREATE TABLE employees (emp_id INT,dept_id INT,hire_date DATE,annual_salary INT); INSERT INTO departments (dept_id,dept_name) VALUES (1,'HR'),(2,'IT'),(4,'Accessibility'); INSERT INTO employees (emp_id,dept_id,hire_date,annual_salary) VALUES (1,1,'2018-01-01',70000),(2,2,'2019-05-05',60000),(3,4,'2020-07-01',80000);
|
UPDATE employees SET annual_salary = 85000 WHERE dept_id = 4;
|
What is the average contract negotiation duration in days for each sales representative?
|
CREATE TABLE ContractNegotiations (NegotiationID INT,SalesRepID INT,NegotiationStartDate DATE,NegotiationEndDate DATE); INSERT INTO ContractNegotiations (NegotiationID,SalesRepID,NegotiationStartDate,NegotiationEndDate) VALUES (1,1,'2020-01-01','2020-01-10'),(2,1,'2020-02-01','2020-02-15'),(3,2,'2020-03-01','2020-03-20'),(4,2,'2020-04-01','2020-04-25');
|
SELECT SalesRepName, AVG(DATEDIFF(day, NegotiationStartDate, NegotiationEndDate)) AS AvgNegotiationDuration FROM ContractNegotiations JOIN SalesReps ON ContractNegotiations.SalesRepID = SalesReps.SalesRepID GROUP BY SalesRepName;
|
What is the total revenue for each product in the 'seafood_sales' table?
|
CREATE TABLE seafood_sales (region VARCHAR(255),product VARCHAR(255),revenue DECIMAL(8,2),quantity INT); INSERT INTO seafood_sales (region,product,revenue,quantity) VALUES ('North','Tilapia',1250.00,500),('South','Salmon',3500.00,800),('North','Catfish',2000.00,600),('East','Tilapia',1750.00,450),('East','Salmon',3000.00,700),('West','Tilapia',2500.00,550),('West','Catfish',2200.00,400),('South','Tilapia',2750.00,700);
|
SELECT product, SUM(revenue) as total_revenue FROM seafood_sales GROUP BY product;
|
What is the average number of artifacts excavated per site in 'Asia'?
|
CREATE TABLE Artifacts (ArtifactID int,Name text,SiteID int,ExcavationYear int); INSERT INTO Artifacts (ArtifactID,Name,SiteID,ExcavationYear) VALUES (1,'Artifact1',1,2005); CREATE TABLE Sites (SiteID int,Name text,Country text); INSERT INTO Sites (SiteID,Name,Country) VALUES (1,'SiteA','Asia');
|
SELECT AVG(ArtifactCount) FROM (SELECT COUNT(*) as ArtifactCount FROM Artifacts INNER JOIN Sites ON Artifacts.SiteID = Sites.SiteID WHERE Sites.Country = 'Asia' GROUP BY SiteID) as Subquery;
|
What is the maximum number of citizens participating in public meetings for each meeting type in 'Meetings' table?
|
CREATE TABLE Meetings (MeetingID INT,MeetingType VARCHAR(20),Citizens INT); INSERT INTO Meetings (MeetingID,MeetingType,Citizens) VALUES (1,'TownHall',50),(2,'Committee',30),(3,'TownHall',60);
|
SELECT MeetingType, MAX(Citizens) AS MaxCitizens FROM Meetings GROUP BY MeetingType
|
What is the average population of the regions?
|
CREATE TABLE regions (id INT PRIMARY KEY,region VARCHAR(50),population INT); INSERT INTO regions (id,region,population) VALUES (1,'Middle East',2000),(2,'Europe',1500),(3,'Asia',800);
|
SELECT region, AVG(population) as avg_population FROM regions GROUP BY region;
|
Get the average number of AI-powered features in online travel agencies in the region of North America
|
CREATE TABLE otas (ota_id INT,ota_name TEXT,region TEXT,num_ai_features INT);
|
SELECT AVG(num_ai_features) FROM otas WHERE region = 'North America';
|
Which indica strains are sold in both California and Nevada?
|
CREATE TABLE StrainData2 (StrainName VARCHAR(30),State VARCHAR(20)); INSERT INTO StrainData2 (StrainName,State) VALUES ('Blue Dream','California'),('Sour Diesel','California'),('OG Kush','California'),('Durban Poison','Nevada'),('Girl Scout Cookies','Nevada'),('Blue Dream','Nevada');
|
SELECT StrainName FROM StrainData2 WHERE State IN ('California', 'Nevada') GROUP BY StrainName HAVING COUNT(DISTINCT State) = 2 AND StrainName LIKE '%Indica%';
|
Identify the top 5 investors by total investment in the healthcare sector?
|
CREATE TABLE Investors (InvestorID INT,Name VARCHAR(50),Sector VARCHAR(50)); INSERT INTO Investors (InvestorID,Name,Sector) VALUES (1,'Alice','Healthcare'),(2,'Bob','Technology'),(3,'Carol','Healthcare'); CREATE TABLE InvestmentDetails (InvestmentID INT,InvestorID INT,Sector VARCHAR(50),Amount FLOAT); INSERT INTO InvestmentDetails (InvestmentID,InvestorID,Sector,Amount) VALUES (1,1,'Healthcare',10000),(2,1,'Healthcare',15000),(3,2,'Technology',20000);
|
SELECT InvestorID, Name, SUM(Amount) AS TotalInvestment FROM InvestmentDetails INNER JOIN Investors ON InvestmentDetails.InvestorID = Investors.InvestorID WHERE Sector = 'Healthcare' GROUP BY InvestorID, Name ORDER BY TotalInvestment DESC LIMIT 5;
|
What is the name of the brand with the highest number of ethical certifications?
|
CREATE TABLE Brands (brand_id INT PRIMARY KEY,name VARCHAR(50),ethical_certifications INT); INSERT INTO Brands (brand_id,name,ethical_certifications) VALUES (1,'Sustainable Fashion',3),(2,'Eco Friendly Wear',2);
|
SELECT name FROM (SELECT name, MAX(ethical_certifications) AS max_certifications FROM Brands) AS max_certified_brands;
|
What is the average age of bridges in 'Bridges' table for each state?
|
CREATE TABLE Bridges(bridge_id INT,age INT,state VARCHAR(255)); INSERT INTO Bridges VALUES(1,25,'California'),(2,18,'California'),(3,22,'Texas'),(4,12,'Texas'),(5,30,'NewYork'),(6,15,'NewYork');
|
SELECT state, AVG(age) FROM Bridges GROUP BY state;
|
Determine the percentage of cruelty-free hair care products in the European market that contain natural ingredients.
|
CREATE TABLE products(product_id INT,product_name VARCHAR(50),is_cruelty_free BOOLEAN,is_natural BOOLEAN,product_category VARCHAR(50)); INSERT INTO products VALUES (22,'Shampoo',TRUE,TRUE,'Hair Care'); INSERT INTO products VALUES (23,'Conditioner',TRUE,FALSE,'Hair Care'); CREATE TABLE sales(product_id INT,sale_date DATE,country VARCHAR(50)); INSERT INTO sales VALUES (22,'2022-01-01','DE'); INSERT INTO sales VALUES (23,'2022-02-01','FR');
|
SELECT ROUND(COUNT(CASE WHEN products.is_cruelty_free = TRUE AND products.is_natural = TRUE THEN 1 END)/COUNT(CASE WHEN products.is_cruelty_free = TRUE THEN 1 END) * 100, 2) as percentage FROM products JOIN sales ON products.product_id = sales.product_id WHERE products.product_category = 'Hair Care' AND sales.country = 'Europe';
|
What are the names and types of all digital assets that have a balance greater than 150?
|
CREATE TABLE digital_assets (name TEXT,balance INTEGER,type TEXT); INSERT INTO digital_assets (name,balance,type) VALUES ('Asset1',100,'ERC20'),('Asset2',200,'ERC721');
|
SELECT name, type FROM digital_assets WHERE balance > 150;
|
What is the maximum funding received in a single round by startups founded by individuals who identify as veterans in the transportation industry?
|
CREATE TABLE startups(id INT,name TEXT,founders TEXT,founding_year INT,industry TEXT); INSERT INTO startups VALUES (1,'StartupA','Aisha,Bob',2012,'Transportation'); INSERT INTO startups VALUES (2,'StartupB','Eve',2015,'Healthcare'); INSERT INTO startups VALUES (3,'StartupC','Carlos',2018,'Tech'); CREATE TABLE investments(startup_id INT,round INT,funding INT); INSERT INTO investments VALUES (1,1,1000000); INSERT INTO investments VALUES (1,2,2000000); INSERT INTO investments VALUES (2,1,3000000); INSERT INTO investments VALUES (3,1,4000000); INSERT INTO investments VALUES (3,2,5000000);
|
SELECT MAX(funding) FROM (SELECT startup_id, funding FROM investments JOIN startups ON investments.startup_id = startups.id WHERE startups.industry = 'Transportation' AND founders LIKE '%Bob%' GROUP BY startup_id, round) subquery;
|
What is the average capacity of energy storage units in Country T?
|
CREATE TABLE storage_average (name TEXT,location TEXT,capacity_MW INTEGER); INSERT INTO storage_average (name,location,capacity_MW) VALUES ('Unit 1','Country T',60),('Unit 2','Country U',80),('Unit 3','Country T',70);
|
SELECT AVG(capacity_MW) FROM storage_average WHERE location = 'Country T';
|
What is the average time taken for cases to be resolved for each gender of lawyers?
|
CREATE TABLE public.lawyers (id SERIAL PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(255),license_date DATE); CREATE TABLE public.cases (id SERIAL PRIMARY KEY,lawyer_id INT,case_number VARCHAR(255),case_date DATE,case_type VARCHAR(255),court_location VARCHAR(255));
|
SELECT l.gender, AVG(c.case_date - l.license_date) as average_time_to_resolve FROM public.lawyers l JOIN public.cases c ON l.id = c.lawyer_id GROUP BY l.gender;
|
Which causes have not received any donations in the last 6 months?
|
CREATE TABLE DonationsByCause (DonationID int,DonorID int,Amount float,Cause varchar(255),DonationDate date); INSERT INTO DonationsByCause VALUES (1,1,500000,'Education','2022-01-01'); INSERT INTO DonationsByCause VALUES (2,2,300000,'Health','2021-12-31'); INSERT INTO DonationsByCause VALUES (3,1,700000,'Environment','2022-03-01');
|
SELECT Cause FROM DonationsByCause GROUP BY Cause HAVING COUNT(CASE WHEN DonationDate >= DATEADD(month, -6, GETDATE()) THEN 1 END) = 0;
|
Identify the player with the highest number of wins in the 'Strategy' genre, and their total wins.
|
CREATE TABLE PlayerWins (PlayerID int,PlayerName varchar(50),Country varchar(50),GameType varchar(50),Wins int); INSERT INTO PlayerWins (PlayerID,PlayerName,Country,GameType,Wins) VALUES (1,'John Doe','USA','Strategy',55),(2,'Jane Smith','Canada','Strategy',60),(3,'Alice Johnson','Mexico','Simulation',45);
|
SELECT PlayerID, MAX(Wins) FROM PlayerWins WHERE GameType = 'Strategy';
|
How many shipments were delayed by more than 2 days in Germany?
|
CREATE TABLE Shipments (ShipmentID INT,WarehouseID INT,DeliveryTime INT,ExpectedDeliveryTime INT);
|
SELECT COUNT(*) FROM Shipments WHERE DeliveryTime > ExpectedDeliveryTime + 2 AND WarehouseID IN (SELECT WarehouseID FROM Warehouses WHERE Country = 'Germany');
|
Find the total size of fish farms in 'rivers' schema greater than 30.
|
CREATE SCHEMA rivers; CREATE TABLE fish_farms (id INT,size FLOAT,location VARCHAR(20)); INSERT INTO fish_farms (id,size,location) VALUES (1,25.2,'river'),(2,36.5,'river'),(3,50.3,'river');
|
SELECT SUM(size) FROM rivers.fish_farms WHERE size > 30;
|
What is the maximum energy consumption of buildings in each location that have been certified by the LEED standard in the 'GreenBuildings' table?
|
CREATE TABLE GreenBuildings (id INT,name VARCHAR(50),location VARCHAR(50),energyConsumption DECIMAL(5,2),leedCertified BOOLEAN); INSERT INTO GreenBuildings (id,name,location,energyConsumption,leedCertified) VALUES (1,'Building A','Location A',50.0,TRUE),(2,'Building B','Location B',75.0,FALSE),(3,'Building C','Location A',35.0,TRUE);
|
SELECT location, MAX(energyConsumption) as max_energy FROM GreenBuildings WHERE leedCertified = TRUE GROUP BY location;
|
Retrieve the names and industry of biotech companies located in Canada or the United Kingdom.
|
CREATE TABLE companies (id INT PRIMARY KEY,name VARCHAR(255),industry VARCHAR(255),location VARCHAR(255)); INSERT INTO companies (id,name,industry,location) VALUES (1,'Genetech','Biotechnology','San Francisco'),(2,'Biotrend','Biotechnology','Paris'),(3,'BioCan','Biotechnology','Toronto'),(4,'BioUK','Biotechnology','London');
|
SELECT name, industry FROM companies WHERE industry = 'Biotechnology' AND location LIKE '%Canada%' OR location LIKE '%United Kingdom%';
|
What are the top 5 vessels by total travel time (in days) between the Port of Rotterdam and the Port of New York?
|
CREATE TABLE Vessels (vessel_id INT,vessel_name VARCHAR(30)); CREATE TABLE VesselTravel (vessel_id INT,route INT,departure_date DATE,travel_time INT); INSERT INTO Vessels (vessel_id,vessel_name) VALUES (1,'Ever Given'),(2,'Ever Summit'),(3,'Ever Leader'); INSERT INTO VesselTravel (vessel_id,route,departure_date,travel_time) VALUES (1,1,'2021-01-01',7),(1,1,'2021-04-01',8),(2,1,'2021-02-01',6),(2,1,'2021-05-01',9),(3,1,'2021-03-01',10);
|
SELECT vessel_name, SUM(travel_time) as total_travel_time FROM VesselTravel WHERE route = 1 GROUP BY vessel_name ORDER BY total_travel_time DESC LIMIT 5;
|
What is the minimum amount of a language preservation grant in Europe?
|
CREATE TABLE GrantsEurope (id INT,name TEXT,type TEXT,amount INT,region TEXT); INSERT INTO GrantsEurope (id,name,type,amount,region) VALUES (1,'Grant 1','Language',50000,'Europe'),(2,'Grant 2','Heritage',200000,'Europe'),(3,'Grant 3','Language',75000,'Europe');
|
SELECT MIN(amount) FROM GrantsEurope WHERE type = 'Language'
|
What is the minimum depth in the Southern Ocean among all marine research stations?
|
CREATE TABLE ocean_depths (station_name VARCHAR(50),southern_depth FLOAT); INSERT INTO ocean_depths (station_name,southern_depth) VALUES ('Australian Antarctic Division',4500.0),('Scott Polar Research Institute',3000.0);
|
SELECT MIN(southern_depth) FROM ocean_depths WHERE station_name IN ('Australian Antarctic Division', 'Scott Polar Research Institute');
|
Find the transaction date with the second highest transaction amount for each customer.
|
CREATE TABLE customer_transactions (transaction_date DATE,customer_id INT,transaction_amt DECIMAL(10,2)); INSERT INTO customer_transactions (transaction_date,customer_id,transaction_amt) VALUES ('2022-01-01',1,200.00),('2022-01-02',2,300.50),('2022-01-03',3,150.25);
|
SELECT transaction_date, customer_id, transaction_amt, DENSE_RANK() OVER (PARTITION BY customer_id ORDER BY transaction_amt DESC) AS rank FROM customer_transactions WHERE rank = 2;
|
Which countries have had zero security incidents in the past year from the 'security_incidents' table?
|
CREATE TABLE security_incidents (id INT,country VARCHAR(50),incidents INT,year INT);
|
SELECT country FROM security_incidents WHERE year = YEAR(CURRENT_DATE) - 1 AND incidents = 0 GROUP BY country HAVING COUNT(*) > 0;
|
Which manufacturers in Sweden have invested more than 400,000 in Industry 4.0?
|
CREATE TABLE manufacturers (manufacturer_id INT,name VARCHAR(255),location VARCHAR(255),industry_4_0_investment FLOAT); INSERT INTO manufacturers (manufacturer_id,name,location,industry_4_0_investment) VALUES (1,'Smart Machines','Germany',350000),(2,'Eco Engines','Sweden',420000),(3,'Precision Robotics','Japan',500000),(4,'Green Innovations','Sweden',375000),(5,'FutureTech','USA',410000);
|
SELECT m.name, m.industry_4_0_investment FROM manufacturers m WHERE m.location = 'Sweden' AND m.industry_4_0_investment > 400000;
|
What's the average media literacy score for users aged 25-34 in the United States?
|
CREATE TABLE users (id INT,age INT,media_literacy_score FLOAT); INSERT INTO users (id,age,media_literacy_score) VALUES (1,25,75.3),(2,34,82.1),(3,45,68.9);
|
SELECT AVG(media_literacy_score) FROM users WHERE age BETWEEN 25 AND 34 AND country = 'United States';
|
How many autonomous driving research projects were initiated in India between 2016 and 2021?
|
CREATE TABLE AutonomousDrivingResearch (Id INT,Project VARCHAR(50),Country VARCHAR(50),StartDate DATE); INSERT INTO AutonomousDrivingResearch (Id,Project,Country,StartDate) VALUES (1,'Project A','USA','2017-05-15'); INSERT INTO AutonomousDrivingResearch (Id,Project,Country,StartDate) VALUES (2,'Project B','Germany','2018-02-28'); INSERT INTO AutonomousDrivingResearch (Id,Project,Country,StartDate) VALUES (3,'Project C','China','2019-11-11'); INSERT INTO AutonomousDrivingResearch (Id,Project,Country,StartDate) VALUES (4,'Project D','Japan','2020-08-01');
|
SELECT COUNT(*) FROM AutonomousDrivingResearch WHERE Country = 'India' AND StartDate >= '2016-01-01' AND StartDate <= '2021-12-31';
|
Create a new table named 'fish_growth' with columns 'fish_id', 'species', 'weight', and 'growth_rate'
|
CREATE TABLE fish_stock (fish_id INT PRIMARY KEY,species VARCHAR(50),location VARCHAR(50),biomass FLOAT); CREATE TABLE feeding (feed_id INT PRIMARY KEY,feed_type VARCHAR(50),nutrients FLOAT);
|
CREATE TABLE fish_growth (fish_id INT PRIMARY KEY, species VARCHAR(50), weight FLOAT, growth_rate FLOAT);
|
List the top 3 most popular workout types by total duration.
|
CREATE TABLE Workouts (WorkoutID INT,MemberID INT,Duration INT,WorkoutType VARCHAR(20)); INSERT INTO Workouts (WorkoutID,MemberID,Duration,WorkoutType) VALUES (1,1,60,'Yoga'),(2,2,90,'Weightlifting'),(3,3,60,'Yoga'),(4,1,45,'Running');
|
SELECT WorkoutType, SUM(Duration) AS TotalDuration FROM Workouts GROUP BY WorkoutType ORDER BY TotalDuration DESC LIMIT 3;
|
What is the average recycling rate per month in 'CityE'?
|
CREATE TABLE CityE (RecyclingQuantity INT,GenerationDate DATE); INSERT INTO CityE (RecyclingQuantity,GenerationDate) VALUES (250,'2021-01-01'),(300,'2021-02-01'),(350,'2021-03-01');
|
SELECT AVG(RecyclingQuantity) FROM (SELECT RecyclingQuantity, ROW_NUMBER() OVER (PARTITION BY EXTRACT(MONTH FROM GenerationDate) ORDER BY GenerationDate) as rn FROM CityE) tmp WHERE rn = 1;
|
List all cybersecurity policies that were last updated in '2021'.
|
CREATE TABLE policies (policy_id INT PRIMARY KEY,policy_name VARCHAR(100),last_updated DATE); INSERT INTO policies (policy_id,policy_name,last_updated) VALUES (1,'Acceptable Use Policy','2021-12-31'),(2,'Incident Response Policy','2022-02-14');
|
SELECT policy_name, last_updated FROM policies WHERE last_updated LIKE '2021-%';
|
What is the total amount of research grants awarded to each department in the last two years?
|
CREATE TABLE departments (department VARCHAR(50),num_grants INT); INSERT INTO departments VALUES ('Computer Science',10),('Mathematics',8),('Physics',12); CREATE TABLE grants (grant_id INT,department VARCHAR(50),year INT,amount FLOAT); INSERT INTO grants VALUES (1,'Computer Science',2020,50000),(2,'Physics',2019,75000),(3,'Mathematics',2021,45000),(4,'Computer Science',2019,60000),(5,'Physics',2018,80000),(6,'Mathematics',2020,55000);
|
SELECT d.department, SUM(g.amount) FROM departments d JOIN grants g ON d.department = g.department WHERE g.year BETWEEN YEAR(CURRENT_DATE) - 2 AND YEAR(CURRENT_DATE) GROUP BY d.department;
|
Delete records of accommodations that cost more than $100000 in the Asian region.
|
CREATE TABLE accommodations (id INT,name TEXT,region TEXT,cost FLOAT); INSERT INTO accommodations (id,name,region,cost) VALUES (1,'Wheelchair Ramp','Asian',120000.00),(2,'Sign Language Interpreter','Asian',60000.00);
|
DELETE FROM accommodations WHERE cost > 100000 AND region = 'Asian';
|
Insert a new vessel into the "vessels" table
|
CREATE TABLE vessels (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),year INT);
|
INSERT INTO vessels (id, name, type, year) VALUES (1, 'MV Horizon', 'Container Ship', 2010);
|
Display the names and fairness scores of models that do not have the same fairness score as any other model.
|
CREATE TABLE model_fairness (model_id INT,fairness_score DECIMAL(3,2)); INSERT INTO model_fairness (model_id,fairness_score) VALUES (1,0.85),(2,0.70),(3,0.92),(4,0.68),(5,0.89);
|
SELECT model_id, fairness_score FROM model_fairness WHERE fairness_score NOT IN (SELECT fairness_score FROM model_fairness GROUP BY fairness_score HAVING COUNT(*) > 1);
|
What is the average word count for news articles published in 2022?
|
CREATE TABLE news_articles_extended_2 (title VARCHAR(100),publication DATE,word_count INT); INSERT INTO news_articles_extended_2 (title,publication,word_count) VALUES ('Article 6','2022-01-01',1200),('Article 7','2022-02-03',800),('Article 8','2022-02-15',1500),('Article 9','2022-03-05',900),('Article 10','2022-04-10',700),('Article 11','2022-05-12',1000);
|
SELECT AVG(word_count) FROM news_articles_extended_2 WHERE EXTRACT(YEAR FROM publication) = 2022;
|
List all vessels with maritime safety violations in the last year.
|
CREATE TABLE vessels (vessel_name TEXT,last_inspection_date DATE); CREATE TABLE safety_violations (vessel_name TEXT,violation_date DATE); INSERT INTO vessels (vessel_name,last_inspection_date) VALUES ('Queen Mary 2','2021-08-12'),('Oasis of the Seas','2021-03-20'); INSERT INTO safety_violations (vessel_name,violation_date) VALUES ('Queen Mary 2','2022-01-10'),('Oasis of the Seas','2022-02-05');
|
SELECT vessels.vessel_name FROM vessels INNER JOIN safety_violations ON vessels.vessel_name = safety_violations.vessel_name WHERE safety_violations.violation_date >= vessels.last_inspection_date AND vessels.last_inspection_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
|
What is the average collective bargaining agreement length for each industry?
|
CREATE TABLE industry (industry_id INT,industry_name VARCHAR(255)); INSERT INTO industry (industry_id,industry_name) VALUES (1,'Manufacturing'),(2,'Healthcare'),(3,'Education'); CREATE TABLE cb_agreements (agreement_id INT,industry_id INT,length INT); INSERT INTO cb_agreements (agreement_id,industry_id,length) VALUES (1,1,36),(2,2,48),(3,1,24),(4,3,36),(5,2,24);
|
SELECT industry_name, AVG(length) OVER (PARTITION BY industry_id) as avg_length FROM industry INNER JOIN cb_agreements ON industry.industry_id = cb_agreements.industry_id ORDER BY industry_name;
|
What is the average energy production of wind farms in Germany?
|
CREATE TABLE wind_farms (id INT,name TEXT,country TEXT,energy_production FLOAT); INSERT INTO wind_farms (id,name,country,energy_production) VALUES (1,'Windpark Nordsee','Germany',250.5),(2,' alpha ventus','Germany',236.8);
|
SELECT AVG(energy_production) FROM wind_farms WHERE country = 'Germany';
|
Delete all records from the Employees table where the employee has been with the company for less than 3 months
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),StartDate DATE,MonthsAtCompany INT); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,StartDate,MonthsAtCompany) VALUES (1,'John','Doe','IT','2021-01-01',15); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,StartDate,MonthsAtCompany) VALUES (2,'Jane','Doe','HR','2022-01-15',1);
|
DELETE FROM Employees WHERE MonthsAtCompany < 3;
|
What is the name of the most recent military innovation in the area of unmanned aerial vehicles?
|
CREATE TABLE military_innovation (innovation_id INT,innovation_name VARCHAR(255),category VARCHAR(255),date DATE); INSERT INTO military_innovation (innovation_id,innovation_name,category,date) VALUES (1,'Innovation A','Unmanned Aerial Vehicles','2018-01-01'),(2,'Innovation B','Cybersecurity','2017-01-01'),(3,'Innovation C','Unmanned Aerial Vehicles','2020-01-01'); CREATE TABLE categories (category VARCHAR(255));
|
SELECT innovation_name FROM military_innovation INNER JOIN categories ON military_innovation.category = categories.category WHERE category = 'Unmanned Aerial Vehicles' AND date = (SELECT MAX(date) FROM military_innovation);
|
What is the count of students who received accommodations for 'Extended Testing Time' in the 'StudentAccommodations' table?
|
CREATE TABLE StudentAccommodations (student_id INT,accommodation_type VARCHAR(255)); INSERT INTO StudentAccommodations (student_id,accommodation_type) VALUES (1,'Sign Language Interpreter'),(2,'Assistive Technology'),(3,'Extended Testing Time'),(4,'Extended Testing Time');
|
SELECT COUNT(*) FROM StudentAccommodations WHERE accommodation_type = 'Extended Testing Time';
|
Insert a new astronaut record for 'Mae Jemison' with a birthdate of '1956-10-17' into the Astronauts table.
|
CREATE TABLE Astronauts (AstronautName VARCHAR(255),Birthdate DATE); INSERT INTO Astronauts (AstronautName,Birthdate) VALUES ('Neil Armstrong','1930-08-05'),('Buzz Aldrin','1930-01-20');
|
INSERT INTO Astronauts (AstronautName, Birthdate) VALUES ('Mae Jemison', '1956-10-17');
|
Delete all records with a penalty higher than 100 from regulatory_frameworks
|
CREATE TABLE regulatory_frameworks (id INT,country VARCHAR(50),penalty DECIMAL(5,2)); INSERT INTO regulatory_frameworks (id,country,penalty) VALUES
|
DELETE FROM regulatory_frameworks
|
What is the number of employees hired each month in the year 2022?
|
CREATE TABLE employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),department VARCHAR(50),hire_date DATE); INSERT INTO employees (id,first_name,last_name,department,hire_date) VALUES (1,'John','Doe','Marketing','2021-04-01'); INSERT INTO employees (id,first_name,last_name,department,hire_date) VALUES (2,'Jane','Smith','IT','2021-05-15'); INSERT INTO employees (id,first_name,last_name,department,hire_date) VALUES (4,'Bob','Johnson','IT','2022-01-10');
|
SELECT MONTH(hire_date) AS month, COUNT(*) AS hired_count FROM employees WHERE YEAR(hire_date) = 2022 GROUP BY month;
|
What are the names and weights of the five heaviest satellites?
|
CREATE TABLE heavy_satellites (satellite_name TEXT,satellite_weight REAL); INSERT INTO heavy_satellites (satellite_name,satellite_weight) VALUES ('Envisat',8212),('GOES 16',6595),('Metop-A',4680),('Metop-B',4680),('Metop-C',4680);
|
SELECT satellite_name, satellite_weight FROM heavy_satellites ORDER BY satellite_weight DESC LIMIT 5;
|
What is the average price of natural products in Canada?
|
CREATE TABLE Products (ProductID INT,ProductName VARCHAR(100),IsNatural BOOLEAN,Price DECIMAL(10,2)); INSERT INTO Products (ProductID,ProductName,IsNatural,Price) VALUES (1,'Product A',true,15),(2,'Product B',false,20),(3,'Product C',true,25),(4,'Product D',false,18),(5,'Product E',true,30);
|
SELECT AVG(Price) FROM Products WHERE IsNatural = true AND Country = 'Canada';
|
What's the total number of volunteers for each program category?
|
CREATE TABLE ProgramCategories (CategoryID INT,Category VARCHAR(20)); INSERT INTO ProgramCategories (CategoryID,Category) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE Programs (ProgramID INT,CategoryID INT,ProgramName VARCHAR(50)); INSERT INTO Programs (ProgramID,CategoryID,ProgramName) VALUES (100,1,'Youth Education'),(200,2,'Health Awareness'),(300,3,'Environmental Cleanup'); CREATE TABLE Volunteers (VolunteerID INT,ProgramID INT,VolunteerName VARCHAR(50)); INSERT INTO Volunteers (VolunteerID,ProgramID,VolunteerName) VALUES (1001,100,'Alex'),(1002,100,'Bella'),(2001,200,'Charlie'),(3001,300,'David'),(3002,300,'Ella');
|
SELECT pc.Category, COUNT(v.VolunteerID) AS TotalVolunteers FROM ProgramCategories pc JOIN Programs p ON pc.CategoryID = p.CategoryID JOIN Volunteers v ON p.ProgramID = v.ProgramID GROUP BY pc.Category;
|
What are the names and launch dates of satellites launched by private companies?
|
CREATE TABLE private_satellites (id INT,name VARCHAR(255),launch_date DATE,company VARCHAR(255),PRIMARY KEY(id)); INSERT INTO private_satellites (id,name,launch_date,company) VALUES (1,'Satellite4','2022-03-20','CompanyA'),(2,'Satellite5','2023-01-05','CompanyB'),(3,'Satellite6','2021-12-14','CompanyA');
|
SELECT private_satellites.name, private_satellites.launch_date FROM private_satellites;
|
What is the average number of restorative justice cases per month?
|
CREATE TABLE RestorativeJusticeCases (id INT,case_date DATE,cases INT); INSERT INTO RestorativeJusticeCases (id,case_date,cases) VALUES (1,'2022-01-01',30),(2,'2022-01-15',45),(3,'2022-02-03',20),(4,'2022-03-01',50),(5,'2022-03-10',60);
|
SELECT EXTRACT(MONTH FROM case_date) as month, AVG(cases) as avg_cases_per_month FROM RestorativeJusticeCases GROUP BY month;
|
What is the average monthly data usage of broadband subscribers in each state?
|
CREATE TABLE broadband_subscribers (subscriber_id INT,subscriber_name VARCHAR(50),state VARCHAR(20),monthly_data_usage DECIMAL(10,2)); INSERT INTO broadband_subscribers (subscriber_id,subscriber_name,state,monthly_data_usage) VALUES (1,'John Doe','New York',50.50),(2,'Jane Smith','California',70.75),(3,'Bob Johnson','Texas',60.25);
|
SELECT state, AVG(monthly_data_usage) as avg_monthly_data_usage FROM broadband_subscribers GROUP BY state;
|
What is the average ocean acidity level in the Indian Ocean?
|
CREATE TABLE ocean_ph (location TEXT,ph FLOAT); INSERT INTO ocean_ph (location,ph) VALUES ('Indian Ocean',8.0),('Southern Ocean',8.1),('North Pacific Ocean',8.2);
|
SELECT AVG(ph) FROM ocean_ph WHERE location = 'Indian Ocean';
|
What is the average time between contract negotiations for each project, sorted from longest to shortest?
|
CREATE TABLE defense_projects (project_id INT,project_name VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO defense_projects VALUES (1,'Project A','2021-01-01','2021-04-30'); INSERT INTO defense_projects VALUES (2,'Project B','2021-02-01','2021-06-15'); INSERT INTO defense_projects VALUES (3,'Project C','2021-03-01','2021-07-31'); CREATE TABLE contract_negotiations (negotiation_id INT,project_id INT,negotiation_date DATE); INSERT INTO contract_negotiations VALUES (1,1,'2021-01-15'); INSERT INTO contract_negotiations VALUES (2,1,'2021-03-30'); INSERT INTO contract_negotiations VALUES (3,2,'2021-03-01'); INSERT INTO contract_negotiations VALUES (4,2,'2021-05-10');
|
SELECT project_id, AVG(DATEDIFF(day, LAG(negotiation_date) OVER (PARTITION BY project_id ORDER BY negotiation_date), negotiation_date)) as avg_time_between_negotiations FROM contract_negotiations GROUP BY project_id ORDER BY avg_time_between_negotiations DESC;
|
Insert a new donation record for each volunteer.
|
CREATE TABLE volunteers (id INT,name VARCHAR(255)); CREATE TABLE donations (id INT,volunteer_id INT,amount DECIMAL(10,2)); INSERT INTO volunteers (id,name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie');
|
INSERT INTO donations (id, volunteer_id, amount) SELECT ROW_NUMBER() OVER (ORDER BY v.id) AS id, v.id AS volunteer_id, 50 AS amount FROM volunteers v;
|
What is the maximum number of children in the refugee_support program who have been relocated to a single country?
|
CREATE TABLE refugee_support (child_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),country VARCHAR(50)); INSERT INTO refugee_support (child_id,name,age,gender,country) VALUES (1,'John Doe',12,'Male','Syria'),(2,'Jane Doe',15,'Female','Afghanistan'),(3,'Ahmed',10,'Male','Syria'),(4,'Aisha',8,'Female','Syria');
|
SELECT MAX(count_children) FROM (SELECT country, COUNT(*) AS count_children FROM refugee_support GROUP BY country) AS children_per_country;
|
Insert new program outcome data
|
CREATE TABLE Program_Outcomes (id INT,program_id INT,outcome_type VARCHAR,value INT,outcome_date DATE); INSERT INTO Program_Outcomes (id,program_id,outcome_type,value,outcome_date) VALUES (1,1001,'participants',50,'2021-01-01');
|
INSERT INTO Program_Outcomes (id, program_id, outcome_type, value, outcome_date) VALUES (2, 1002, 'hours_donated', 1000, '2021-01-01');
|
Insert a new record for an energy efficiency project in Florida with a budget of 80000.00.
|
CREATE TABLE energy_efficiency_projects (project_name VARCHAR(50),state VARCHAR(20),budget DECIMAL(10,2));
|
INSERT INTO energy_efficiency_projects (project_name, state, budget) VALUES ('Project D', 'Florida', 80000.00);
|
List all food justice organizations and the number of projects they have in the database.
|
CREATE TABLE orgs (id INT,name TEXT,type TEXT); INSERT INTO orgs (id,name,type) VALUES (1,'Seeds of Hope','Food Justice'); INSERT INTO orgs (id,name,type) VALUES (2,'Green Urban','Urban Agriculture'); INSERT INTO orgs (id,name,type) VALUES (3,'Harvest Together','Food Justice'); CREATE TABLE projects (id INT,org_id INT,name TEXT); INSERT INTO projects (id,org_id,name) VALUES (1,1,'Community Garden'); INSERT INTO projects (id,org_id,name) VALUES (2,1,'Cooking Classes'); INSERT INTO projects (id,org_id,name) VALUES (3,3,'Food Co-op');
|
SELECT o.name, COUNT(p.id) FROM orgs o JOIN projects p ON o.id = p.org_id WHERE o.type = 'Food Justice' GROUP BY o.name;
|
What is the maximum quantity of products sold by a single supplier to Africa?
|
CREATE TABLE SupplierSales (SSID INT,SupplierID INT,Product VARCHAR(20),Quantity INT,Country VARCHAR(20)); INSERT INTO SupplierSales VALUES (1,1,'Clothes',500,'Africa'); INSERT INTO SupplierSales VALUES (2,2,'Shoes',600,'Africa');
|
SELECT SupplierID, MAX(Quantity) FROM SupplierSales WHERE Country = 'Africa' GROUP BY SupplierID;
|
Present average safety stock for all chemicals in 'chemical_inventory' table
|
CREATE TABLE chemical_inventory (id INT,chemical_name VARCHAR(50),safety_stock INT);
|
SELECT AVG(safety_stock) FROM chemical_inventory;
|
What is the average number of genres per artist?
|
CREATE TABLE artists (id INT,name TEXT); CREATE TABLE artist_genres (artist_id INT,genre TEXT); INSERT INTO artists (id,name) VALUES (1,'Taylor Swift'),(2,'Eminem'); INSERT INTO artist_genres (artist_id,genre) VALUES (1,'Pop'),(1,'Country'),(2,'Hip Hop'),(2,'Rap');
|
SELECT AVG(genre_count) FROM (SELECT artist_id, COUNT(DISTINCT genre) AS genre_count FROM artist_genres GROUP BY artist_id) AS artist_genre_counts;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.