instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
How many creative applications were developed for each category in the 'creative_applications' table? | CREATE TABLE creative_applications (id INT,category VARCHAR(50),application_name VARCHAR(100)); | SELECT category, COUNT(*) as num_applications FROM creative_applications GROUP BY category; |
How many community development initiatives were completed in 2021 in Peru? | CREATE TABLE community_development (id INT,completion_year INT,initiative_name VARCHAR(50),completion_date DATE); INSERT INTO community_development (id,completion_year,initiative_name,completion_date) VALUES (1,2020,'School Construction','2020-03-17'),(2,2021,'Community Center','2021-09-28'); | SELECT COUNT(*) FROM community_development WHERE completion_year = 2021; |
Delete all records from the aircraft_manufacturing table where the manufacturing_year is less than or equal to 2010 | CREATE TABLE aircraft_manufacturing (id INT PRIMARY KEY,model VARCHAR(100),manufacturing_year INT); | DELETE FROM aircraft_manufacturing WHERE manufacturing_year <= 2010; |
How many animals are there in the 'endangered_species' table? | CREATE TABLE endangered_species (species_id INT,animal_name VARCHAR(50),population INT); INSERT INTO endangered_species (species_id,animal_name,population) VALUES (1,'Giant Panda',1800),(2,'Black Rhino',5000),(3,'Mountain Gorilla',1000); | SELECT SUM(population) FROM endangered_species; |
Find the number of events attended by each individual in 2021 | CREATE TABLE event_attendance (id INT,individual_id INT,event_year INT);INSERT INTO event_attendance (id,individual_id,event_year) VALUES (1,1,2021),(2,2,2021),(3,1,2021); | SELECT individual_id, COUNT(*) OVER (PARTITION BY individual_id) AS events_attended_by_each_individual FROM event_attendance WHERE event_year = 2021 ORDER BY individual_id; |
What is the number of repeat attendees for each event type in 2021? | CREATE TABLE Events (EventID INT,EventTypeID INT,EventDate DATE); CREATE TABLE EventAttendance (EventID INT,AudienceID INT); CREATE TABLE Audience (AudienceID INT,AudienceName VARCHAR(50)); INSERT INTO Events (EventID,EventTypeID,EventDate) VALUES (1,1,'2021-01-01'),(2,1,'2021-02-01'),(3,2,'2021-03-01'); INSERT INTO EventAttendance (EventID,AudienceID) VALUES (1,1),(1,2),(2,1),(2,3),(3,1),(3,2); INSERT INTO Audience (AudienceID,AudienceName) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'); | SELECT et.EventTypeName, COUNT(DISTINCT ea.AudienceID) as NumRepeatAttendees FROM EventAttendance ea INNER JOIN Events e ON ea.EventID = e.EventID INNER JOIN EventTypes et ON e.EventTypeID = et.EventTypeID INNER JOIN (SELECT AudienceID, COUNT(EventID) as NumEvents FROM EventAttendance GROUP BY AudienceID HAVING COUNT(EventID) > 1) repeat_attendees ON ea.AudienceID = repeat_attendees.AudienceID GROUP BY et.EventTypeName; |
What is the total number of tickets sold for performances with a rating of 5? | CREATE TABLE performance (id INT PRIMARY KEY,name VARCHAR(255),date DATE,artist_id INT,rating INT); INSERT INTO performance (id,name,date,artist_id,rating) VALUES (1,'Dance Recital','2022-03-01',1,5); | SELECT SUM(t.quantity) as total_tickets_sold FROM performance p INNER JOIN ticket t ON p.id = t.performance_id WHERE p.rating = 5; |
How many workers are employed in each state in sustainable building projects? | CREATE TABLE Workers (WorkerID INT,ProjectID INT,State CHAR(2),IsSustainable BOOLEAN); | SELECT State, COUNT(*) FROM Workers WHERE IsSustainable=TRUE GROUP BY State; |
What is the maximum billing amount for cases handled by attorneys from New York who have won more than 80% of their cases? | CREATE TABLE attorneys (attorney_id INT,name VARCHAR(50),state VARCHAR(2),win_rate DECIMAL(5,2)); INSERT INTO attorneys (attorney_id,name,state,win_rate) VALUES (1,'Alex Rodriguez','NY',0.9),(2,'Jennifer Lee','CA',0.6),(3,'Michael Chen','NY',0.85); CREATE TABLE cases (case_id INT,attorney_id INT,billing_amount DECIMAL(10,2),case_outcome VARCHAR(10)); INSERT INTO cases (case_id,attorney_id,billing_amount,case_outcome) VALUES (1,1,5000.00,'Won'),(2,1,6000.00,'Won'),(3,2,9000.00,'Lost'),(4,3,8000.00,'Won'); | SELECT MAX(billing_amount) FROM cases JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.state = 'NY' AND attorneys.win_rate > 0.8 AND cases.case_outcome = 'Won'; |
List the top 3 contributing countries to climate change based on emissions data, excluding the US | CREATE TABLE emissions (id INT PRIMARY KEY,country VARCHAR(50),emissions INT); INSERT INTO emissions (id,country,emissions) VALUES (1,'China',10000),(2,'US',8000),(3,'India',6000),(4,'Russia',5000); | SELECT country, emissions FROM emissions WHERE country NOT IN ('US') ORDER BY emissions DESC LIMIT 3; |
What is the total number of hospitals that offer mental health services in each state? | CREATE TABLE Hospitals (HospitalID INT,Name TEXT,City TEXT,State TEXT,MentalHealth BOOLEAN); INSERT INTO Hospitals (HospitalID,Name,City,State,MentalHealth) VALUES (1,'Jackson Memorial Hospital','Miami','Florida',TRUE); | SELECT State, COUNT(*) FROM Hospitals WHERE MentalHealth = TRUE GROUP BY State; |
What is the average investment amount per round for companies founded by Latinx? | CREATE TABLE investments (company_id INT,round_type TEXT,raised_amount INT); INSERT INTO investments (company_id,round_type,raised_amount) VALUES (1,'Series A',5000000); INSERT INTO investments (company_id,round_type,raised_amount) VALUES (2,'Seed',1000000); CREATE TABLE diversity (company_id INT,latinx_founder BOOLEAN); INSERT INTO diversity (company_id,latinx_founder) VALUES (1,true); INSERT INTO diversity (company_id,latinx_founder) VALUES (2,false); | SELECT AVG(raised_amount) as avg_investment_per_round FROM investments JOIN diversity ON investments.company_id = diversity.company_id WHERE diversity.latinx_founder = true; |
Find the number of students who received accommodations in the "Online Learning" category | CREATE TABLE accommodations (student_id INT,accommodation_category VARCHAR(20)); INSERT INTO accommodations (student_id,accommodation_category) VALUES (1,'Online Learning'),(2,'Exam'),(3,'Note Taking'); | SELECT COUNT(*) FROM accommodations WHERE accommodation_category = 'Online Learning'; |
Delete all records from the CoralReefs table that represent reefs with a health status of "Degraded". | CREATE TABLE CoralReefs (Name VARCHAR(255),Location VARCHAR(255),Health_Status VARCHAR(255)); INSERT INTO CoralReefs (Name,Location,Health_Status) VALUES ('Great Barrier Reef','Australia','Degraded'),('Palau Reef','Palau','Healthy'),('Belize Barrier Reef','Belize','Vulnerable'); | DELETE FROM CoralReefs WHERE Health_Status = 'Degraded'; |
What is the minimum number of daily transactions for smart contracts associated with digital assets issued by companies in Africa? | CREATE TABLE Smart_Contracts (Contract_ID INT,Asset_ID INT,Daily_Transactions INT); INSERT INTO Smart_Contracts (Contract_ID,Asset_ID,Daily_Transactions) VALUES (1,1,500),(2,2,700),(3,1,600),(4,3,800),(5,4,900); CREATE TABLE Digital_Assets (Asset_ID INT,Asset_Name VARCHAR(255),Issuer_Country VARCHAR(50)); INSERT INTO Digital_Assets (Asset_ID,Asset_Name,Issuer_Country) VALUES (1,'Asset1','Egypt'),(2,'Asset2','Nigeria'),(3,'Asset3','South Africa'),(4,'Asset4','Kenya'); | SELECT MIN(Daily_Transactions) AS Min_Transactions FROM Smart_Contracts JOIN Digital_Assets ON Smart_Contracts.Asset_ID = Digital_Assets.Asset_ID WHERE Issuer_Country IN ('Egypt', 'Nigeria', 'South Africa', 'Kenya'); |
What is the regulatory framework status in 'germany'? | CREATE TABLE regulation (id INT,country VARCHAR(20),status VARCHAR(20)); INSERT INTO regulation (id,country,status) VALUES (1,'germany','under_review'); | SELECT status FROM regulation WHERE country = 'germany'; |
What is the total market cap of digital assets that have been involved in at least 1000 transactions? | CREATE TABLE digital_assets (asset_id INT,name VARCHAR(255),market_cap DECIMAL(18,2)); INSERT INTO digital_assets (asset_id,name,market_cap) VALUES (1,'Bitcoin',1000000000000.00),(2,'Ethereum',300000000000.00),(3,'Litecoin',10000000000.00),(4,'Monero',5000000000.00),(5,'Ripple',20000000000.00); CREATE TABLE transactions (transaction_id INT,asset_id INT); INSERT INTO transactions (transaction_id,asset_id) VALUES (1,1),(2,1),(3,1),(4,2),(5,2),(6,2),(7,3),(8,3),(9,3),(10,3),(11,4),(12,4),(13,5),(14,5),(15,5); | SELECT SUM(market_cap) AS total_market_cap FROM digital_assets WHERE asset_id IN (SELECT asset_id FROM transactions GROUP BY asset_id HAVING COUNT(*) >= 1000); |
What is the average number of disaster preparedness trainings held per year in the state of California? | CREATE TABLE DisasterPreparedness (id INT,state VARCHAR(20),year INT,training_count INT); | SELECT AVG(training_count/1.0) FROM DisasterPreparedness WHERE state = 'California' GROUP BY year; |
How many art pieces does each artist have in the museum? | CREATE TABLE MuseumArtists (id INT,artist_name VARCHAR(255),museum_name VARCHAR(255),quantity INT); INSERT INTO MuseumArtists (id,artist_name,museum_name,quantity) VALUES (1,'Artist A','Museum A',10),(2,'Artist B','Museum B',15),(3,'Artist C','Museum C',5),(4,'Artist D','Museum A',20); | SELECT artist_name, museum_name, SUM(quantity) FROM MuseumArtists GROUP BY artist_name, museum_name; |
What is the average attendance for 'Jazz' concerts? | CREATE TABLE concerts(id INT,genre VARCHAR(255),avg_attendance FLOAT); INSERT INTO concerts (id,genre,avg_attendance) VALUES (1,'Jazz',200.0),(2,'Classical',300.0),(3,'Rock',500.0); | SELECT avg_attendance FROM concerts WHERE genre = 'Jazz'; |
Add a new veteran named 'James Smith' to the veteran_employment table with a veteran_id of 888 | CREATE TABLE veteran_employment (veteran_id INT,name VARCHAR(50),job_start_date DATE); | INSERT INTO veteran_employment (veteran_id, name) VALUES (888, 'James Smith'); |
Update the "threat_level" of the "threat_intelligence" table to "medium" where the "threat_source" is "United Nations" and the "threat_date" is before '2022-01-01' | CREATE TABLE threat_intelligence (threat_id INT,threat_source VARCHAR(50),threat_level VARCHAR(50),threat_description VARCHAR(50),threat_date DATE); | UPDATE threat_intelligence SET threat_level = 'medium' WHERE threat_source = 'United Nations' AND threat_date < '2022-01-01'; |
Show all employees who have more than 2 years of experience in 'sustainable_manufacturing' skill | CREATE TABLE employee_skills (employee_id INT,skill_name VARCHAR(50),experience_years INT); INSERT INTO employee_skills (employee_id,skill_name,experience_years) VALUES (1,'sustainable_manufacturing',3),(2,'quality_control',1),(3,'sustainable_manufacturing',5); | SELECT employee_id FROM employee_skills WHERE skill_name = 'sustainable_manufacturing' AND experience_years > 2; |
What were the total number of artifacts found in 2020, grouped by site? | CREATE TABLE excavation_sites (site_id INT,site_name TEXT,year INT,total_artifacts INT); INSERT INTO excavation_sites (site_id,site_name,year,total_artifacts) VALUES (1,'Site A',2018,300),(2,'Site B',2019,550),(3,'Site C',2020,700),(4,'Site D',2021,850); | SELECT site_name, SUM(total_artifacts) FROM excavation_sites WHERE year = 2020 GROUP BY site_name; |
What is the name of the hospital with the lowest patient capacity in the Northeast region? | CREATE TABLE hospitals (id INT,region VARCHAR(255),name VARCHAR(255),patient_capacity INT); INSERT INTO hospitals (id,region,name,patient_capacity) VALUES (1,'Northeast','Hospital A',100),(2,'West','Hospital B',150),(3,'South','Hospital C',120); | SELECT name FROM hospitals WHERE region = 'Northeast' ORDER BY patient_capacity ASC LIMIT 1; |
Insert a new open pedagogy resource 'Critical Thinking in Math Education'. | CREATE TABLE open_pedagogy_resources (resource_name VARCHAR(50),topic VARCHAR(50)); | INSERT INTO open_pedagogy_resources (resource_name, topic) VALUES ('Critical Thinking in Math Education', 'Mathematics Education'); |
List departments with more than one employee. | CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),ManagerID INT); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,ManagerID) VALUES (1,'Jane','Smith','Marketing',2),(2,'Bruce','Johnson','IT',NULL),(3,'Alice','Williams','Marketing',1),(4,'Charlie','Brown','HR',NULL),(5,'Denise','Davis','Marketing',1); | SELECT Department FROM Employees GROUP BY Department HAVING COUNT(DISTINCT EmployeeID) > 1; |
What is the total number of employees hired each year, with a running total? | CREATE TABLE Hiring (HireID INT,EmployeeName VARCHAR(50),HireYear INT,Department VARCHAR(50)); INSERT INTO Hiring (HireID,EmployeeName,HireYear,Department) VALUES (1,'John Doe',2020,'IT'),(2,'Jane Smith',2019,'HR'),(3,'Alice Johnson',2020,'IT'),(4,'Bob Brown',2018,'Finance'),(5,'Charlie Green',2019,'Finance'); | SELECT HireYear, Department, COUNT(*) OVER (PARTITION BY HireYear ORDER BY HireYear) AS Running_Total FROM Hiring; |
What is the percentage of energy efficiency improvement, per sector, compared to 2015 levels? | CREATE TABLE energy_efficiency (id INT,sector VARCHAR(50),year INT,efficiency FLOAT); INSERT INTO energy_efficiency (id,sector,year,efficiency) VALUES (1,'Industry',2015,100.0),(2,'Industry',2020,105.0),(3,'Residential',2015,100.0),(4,'Residential',2020,103.0); | SELECT sector, (SUM(efficiency) / (SELECT SUM(efficiency) FROM energy_efficiency WHERE year = 2015 AND sector = e.sector) * 100.0) - 100.0 AS improvement FROM energy_efficiency e WHERE year = 2020 GROUP BY sector; |
What is the total capacity (MW) of wind farms in Germany and France? | CREATE TABLE windfarm (id INT,country VARCHAR(50),name VARCHAR(50),capacity FLOAT); INSERT INTO windfarm (id,country,name,capacity) VALUES (1,'Germany','Windfarm 1',100.5),(2,'Germany','Windfarm 2',150.2),(3,'France','Windfarm 3',200.1),(4,'France','Windfarm 4',250.3); | SELECT SUM(capacity) FROM windfarm WHERE country IN ('Germany', 'France'); |
Insert a new record for a basketball player 'Marta Santiago' from 'Spain' in the 'basketball_players' table | CREATE TABLE basketball_players (player_id INT,player_name VARCHAR(50),position VARCHAR(50),team VARCHAR(50),country VARCHAR(50)); | INSERT INTO basketball_players (player_id, player_name, position, team, country) VALUES (1, 'Marta Santiago', 'Point Guard', 'Barcelona Basquet', 'Spain'); |
What is the average number of items delivered per day for 'items_delivered' table for 'South America' in Q3 2021? | CREATE TABLE items_delivered (delivery_id INT,item_count INT,delivery_date DATE,country VARCHAR(50)); INSERT INTO items_delivered (delivery_id,item_count,delivery_date,country) VALUES (1,15,'2021-07-01','South America'),(2,20,'2021-07-02','South America'); | SELECT AVG(item_count) FROM items_delivered WHERE EXTRACT(QUARTER FROM delivery_date) = 3 AND country = 'South America'; |
Delete records from the "accessibility_features" table where the "feature_type" is "Voice Command" and the "status" is "Discontinued" | CREATE TABLE accessibility_features (id INT PRIMARY KEY,product_name VARCHAR(50),feature_type VARCHAR(50),status VARCHAR(20)); INSERT INTO accessibility_features (id,product_name,feature_type,status) VALUES (1,'Smart Home Device','Voice Command','Discontinued'); INSERT INTO accessibility_features (id,product_name,feature_type,status) VALUES (2,'AI Chatbot','Voice Command','Active'); | DELETE FROM accessibility_features WHERE feature_type = 'Voice Command' AND status = 'Discontinued'; |
Display the number of AI patents filed by year and company in the 'ai_patents' table | CREATE TABLE ai_patents (id INT PRIMARY KEY,company VARCHAR(50),year INT,patent VARCHAR(50)); | SELECT year, company, COUNT(*) as num_patents FROM ai_patents GROUP BY year, company ORDER BY year; |
Update the start date of an ethical AI project in the EthicalAIPractices table. | CREATE TABLE EthicalAIPractices (Project VARCHAR(50),Description TEXT,StartDate DATE,EndDate DATE); INSERT INTO EthicalAIPractices (Project,Description,StartDate,EndDate) VALUES ('AI for Children','An AI project focused on improving the lives of children.','2022-01-01','2023-12-31'); | UPDATE EthicalAIPractices SET StartDate = '2023-01-01' WHERE Project = 'AI for Children'; |
What is the average number of digital divide projects per year in Asia? | CREATE TABLE digital_divide_projects (project_id INT,country VARCHAR(20),completion_year INT); INSERT INTO digital_divide_projects (project_id,country,completion_year) VALUES (1,'India',2018),(2,'China',2019),(3,'Japan',2020),(4,'India',2021),(5,'China',2017); | SELECT AVG(COUNT(*)) FROM digital_divide_projects GROUP BY completion_year; |
What is the total budget allocated for accessible technology projects in the education sector? | CREATE TABLE accessible_tech (id INT,sector VARCHAR(20),budget INT); INSERT INTO accessible_tech (id,sector,budget) VALUES (1,'education',200000),(2,'healthcare',100000),(3,'finance',150000); | SELECT SUM(budget) FROM accessible_tech WHERE sector = 'education'; |
What is the total fare collected from bus routes that start with the letter 'B'? | CREATE TABLE bus_trips (trip_id INT,route_id INT,fare FLOAT); INSERT INTO bus_trips (trip_id,route_id,fare) VALUES (1,101,2.5),(2,202,3.0),(3,303,1.5),(4,404,2.0),(5,505,2.5),(6,106,3.0); CREATE TABLE bus_routes (route_id INT,route_name TEXT,starting_letter TEXT); INSERT INTO bus_routes (route_id,route_name,starting_letter) VALUES (101,'Broadway','B'),(202,'Park Ave','P'),(303,'Lakeshore','L'),(404,'Sunset Blvd','S'),(505,'Beverly Hills','B'); | SELECT SUM(bt.fare) FROM bus_trips bt JOIN bus_routes br ON bt.route_id = br.route_id WHERE br.starting_letter = 'B'; |
Find the number of days since each brand last used sustainable material and show the result for each brand. | CREATE TABLE Brand_Sustainable_Material_Last_Usage(Brand_ID INT,Last_Usage_Date DATE); INSERT INTO Brand_Sustainable_Material_Last_Usage(Brand_ID,Last_Usage_Date) VALUES (1,'2022-01-01'),(2,'2022-01-03'),(3,NULL),(4,'2022-01-02'); | SELECT Brand_ID, DATEDIFF(DAY, Last_Usage_Date, GETDATE()) as Days_Since_Last_Usage FROM Brand_Sustainable_Material_Last_Usage WHERE Last_Usage_Date IS NOT NULL; |
How many fair labor practice violations have been reported for each region in the ethical fashion industry? | CREATE TABLE labor_practices_violations (region VARCHAR(50),violations INT); INSERT INTO labor_practices_violations (region,violations) VALUES ('Africa',250),('Asia',300),('Latin America',200); | SELECT region, violations FROM labor_practices_violations GROUP BY region; |
Identify the top consumer of ethical fashion by total spending in Africa. | CREATE TABLE african_consumers (id INT,name VARCHAR(100),country VARCHAR(50),spend DECIMAL(10,2)); INSERT INTO african_consumers (id,name,country,spend) VALUES (1,'Eve','Nigeria',700.00),(2,'Fiona','South Africa',800.00),(3,'Grace','Egypt',650.00); | SELECT name, country, SUM(spend) as total_spend FROM african_consumers GROUP BY country ORDER BY total_spend DESC LIMIT 1; |
Which countries have the most manufacturers with sustainable labor practices? | CREATE TABLE ManufacturerLabor (manufacturer_id INT,manufacturer_name VARCHAR(255),country VARCHAR(255),has_sustainable_labor BOOLEAN); INSERT INTO ManufacturerLabor (manufacturer_id,manufacturer_name,country,has_sustainable_labor) VALUES (1,'EcoPure','USA',true),(2,'GreenYarn','Canada',false),(3,'SustainableTimber','Mexico',true),(4,'EthicalMinerals','India',true),(5,'FairTradeFabrics','Bangladesh',true),(6,'EcoDyes','China',false),(7,'EcoPaints','France',true),(8,'GreenBuilding','Germany',true); | SELECT country, COUNT(*) as num_sustainable_manufacturers FROM ManufacturerLabor WHERE has_sustainable_labor = true GROUP BY country ORDER BY num_sustainable_manufacturers DESC; |
How many size 2XL garments were sold in the last month? | CREATE TABLE sales (item VARCHAR(20),size VARCHAR(5),date DATE); INSERT INTO sales (item,size,date) VALUES ('T-Shirt','2XL','2022-07-01'),('Pants','2XL','2022-07-15'); | SELECT COUNT(*) FROM sales WHERE size = '2XL' AND date >= '2022-07-01' AND date <= '2022-07-31'; |
Calculate the sum of donations made by a specific donor 'Aisha' in 2021. | CREATE TABLE donations (donation_id INT,amount DECIMAL(10,2),donor VARCHAR(255),donation_date DATE); INSERT INTO donations (donation_id,amount,donor,donation_date) VALUES (1,100,'Aisha','2021-05-05'); INSERT INTO donations (donation_id,amount,donor,donation_date) VALUES (2,200,'Ali','2021-12-31'); | SELECT SUM(amount) FROM donations WHERE donor = 'Aisha' AND donation_date BETWEEN '2021-01-01' AND '2021-12-31'; |
What is the total number of financial transactions made by volunteers? | CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(50),VolunteerNationality varchar(50),VolunteerSignUpDate date); CREATE TABLE FinancialTransactions (TransactionID int,TransactionAmount numeric(10,2),TransactionDate date,VolunteerID int); INSERT INTO Volunteers (VolunteerID,VolunteerName,VolunteerNationality,VolunteerSignUpDate) VALUES (1,'Sophia Garcia','Mexican','2021-05-10'),(2,'Hamza Ahmed','Pakistani','2021-03-22'),(3,'Lea Kim','South Korean','2021-07-18'); INSERT INTO FinancialTransactions (TransactionID,TransactionAmount,TransactionDate,VolunteerID) VALUES (1,25,'2021-06-01',1),(2,30,'2021-04-01',2),(3,40,'2021-08-01',3); | SELECT COUNT(*) as TotalTransactions FROM FinancialTransactions INNER JOIN Volunteers ON FinancialTransactions.VolunteerID = Volunteers.VolunteerID; |
Update the name of product with id 2 to 'Eco-friendly Product2' in 'OrganicProducts' view | CREATE VIEW OrganicProducts AS SELECT * FROM Products WHERE is_organic = TRUE; INSERT INTO Products (id,name,is_organic) VALUES (1,'Product1',TRUE),(2,'Product2',FALSE),(3,'Product3',TRUE); | UPDATE OrganicProducts SET name = 'Eco-friendly Product2' WHERE id = 2; |
What is the total number of organic fruits in the inventory? | CREATE TABLE Inventory(item_id INT,item_name VARCHAR(50),is_organic BOOLEAN,category VARCHAR(50)); INSERT INTO Inventory VALUES(1,'Apples',TRUE,'Fruit'),(2,'Bananas',TRUE,'Fruit'),(3,'Carrots',FALSE,'Vegetable'); | SELECT COUNT(*) FROM Inventory WHERE is_organic = TRUE AND category = 'Fruit'; |
Get the carrier_name and count of shipments for each carrier from the shipment table grouped by carrier_name | CREATE TABLE shipment (shipment_id VARCHAR(10),status VARCHAR(20),warehouse_id VARCHAR(10),carrier_name VARCHAR(30),shipped_date DATE); | SELECT carrier_name, COUNT(*) as count FROM shipment GROUP BY carrier_name; |
How many unique item types have been shipped via each transportation mode? | CREATE TABLE shipments (id INT,order_id INT,item_type VARCHAR(50),transportation_mode VARCHAR(50),quantity INT); INSERT INTO shipments (id,order_id,item_type,transportation_mode,quantity) VALUES (1,1001,'Item1','Air',50),(2,1002,'Item2','Road',80),(3,1003,'Item1','Rail',75),(4,1004,'Item3','Sea',30); | SELECT transportation_mode, COUNT(DISTINCT item_type) as unique_item_types FROM shipments GROUP BY transportation_mode; |
What is the total number of late deliveries by each warehouse in the Americas region for the past month, excluding warehouses with less than 25 late deliveries? | CREATE TABLE Warehouses (WarehouseID int,WarehouseName varchar(255),Region varchar(255));CREATE TABLE Shipments (ShipmentID int,WarehouseID int,LateDelivery bit,ShippedDate datetime); INSERT INTO Warehouses (WarehouseID,WarehouseName,Region) VALUES (1,'W1','Americas'); INSERT INTO Shipments (ShipmentID,WarehouseID,LateDelivery,ShippedDate) VALUES (1,1,1,'2022-01-01'); | SELECT w.WarehouseName, COUNT(s.ShipmentID) as LateDeliveries FROM Warehouses w INNER JOIN Shipments s ON w.WarehouseID = s.WarehouseID WHERE w.Region = 'Americas' AND s.LateDelivery = 1 AND s.ShippedDate >= DATEADD(month, -1, GETDATE()) GROUP BY w.WarehouseName HAVING COUNT(s.ShipmentID) >= 25; |
List the number of public parks in New York state and their respective areas in square meters. | CREATE TABLE parks (name VARCHAR(255),state VARCHAR(255),area_sqm INT); INSERT INTO parks (name,state,area_sqm) VALUES ('Central Park','New York',341160000),('Prospect Park','New York',58500000); | SELECT name, state, area_sqm FROM parks WHERE state = 'New York'; |
What is the percentage of faculty members who identify as AAPI in the School of Business? | CREATE TABLE faculty_members (id INT,faculty_name VARCHAR(50),faculty_department VARCHAR(50),faculty_race VARCHAR(20)); INSERT INTO faculty_members (id,faculty_name,faculty_department,faculty_race) VALUES (1,'Taylor Smith','Business Administration','AAPI'),(2,'James Johnson','Marketing','White'),(3,'Avery Brown','Finance','Black'),(4,'Katie Davis','Management','White'),(5,'Jamie Wilson','Accounting','Latinx'),(6,'Leah Kim','Business Analytics','AAPI'); | SELECT (COUNT(*) FILTER (WHERE faculty_race = 'AAPI')) * 100.0 / COUNT(*) FROM faculty_members WHERE faculty_department LIKE '%Business%'; |
What is the average budget for green building projects in the green_buildings table? | CREATE TABLE IF NOT EXISTS green_buildings (building_id INT,building_name VARCHAR(255),budget FLOAT,PRIMARY KEY (building_id)); INSERT INTO green_buildings (building_id,building_name,budget) VALUES (1,'Eco-Tower',1000000),(2,'Green Heights',800000),(3,'Sustainable Haven',900000); | SELECT AVG(budget) FROM green_buildings; |
What is the total installed capacity of wind energy projects in Germany? | CREATE TABLE wind_projects (id INT,country VARCHAR(50),capacity FLOAT); INSERT INTO wind_projects (id,country,capacity) VALUES (1,'Germany',2.345),(2,'France',1.234); | SELECT SUM(capacity) FROM wind_projects WHERE country = 'Germany'; |
What is the total investment (in USD) in energy efficient lighting projects, grouped by city and project type, where the total investment is greater than 1,000,000 USD? | CREATE TABLE energy_efficient_lighting (project_id INT,city VARCHAR(50),project_type VARCHAR(50),investment_cost INT); | SELECT city, project_type, SUM(investment_cost) FROM energy_efficient_lighting GROUP BY city, project_type HAVING SUM(investment_cost) > 1000000; |
What is the maximum number of mental health parity violations in the Southern states? | CREATE TABLE mental_health_parity_violations (violation_id INT,state VARCHAR(255),number INT); INSERT INTO mental_health_parity_violations (violation_id,state,number) VALUES (1,'Alabama',10),(2,'Georgia',15),(3,'Florida',20),(4,'North Carolina',12),(5,'South Carolina',18),(6,'Mississippi',14),(7,'Louisiana',16),(8,'Arkansas',11),(9,'Tennessee',13),(10,'Kentucky',17),(11,'Virginia',19); | SELECT MAX(number) as max_violations FROM mental_health_parity_violations WHERE state IN ('Alabama', 'Georgia', 'Florida', 'North Carolina', 'South Carolina', 'Mississippi', 'Louisiana', 'Arkansas', 'Tennessee', 'Virginia', 'Kentucky'); |
List the number of cultural heritage sites in Tokyo and Seoul. | CREATE TABLE asian_sites (site_id INT,name VARCHAR(255),city VARCHAR(255),type VARCHAR(255)); INSERT INTO asian_sites (site_id,name,city,type) VALUES (1,'Todai-ji Temple','Nara','historical'),(2,'Gyeongbokgung Palace','Seoul','historical'); | SELECT city, COUNT(*) FROM asian_sites WHERE city IN ('Tokyo', 'Seoul') AND type = 'historical' GROUP BY city; |
What are the top 5 countries with the most virtual tourism sessions in the first quarter of 2023? | CREATE TABLE virtual_tourism (id INT,country VARCHAR(50),num_sessions INT,session_date DATE); INSERT INTO virtual_tourism (id,country,num_sessions,session_date) VALUES (1,'USA',2500,'2023-01-01'),(2,'Canada',1800,'2023-01-02'); | SELECT country, SUM(num_sessions) as total_sessions FROM virtual_tourism WHERE session_date BETWEEN '2023-01-01' AND '2023-03-31' GROUP BY country ORDER BY total_sessions DESC LIMIT 5; |
What is the total number of virtual tour engagements for hotels in 'Barcelona' with a rating of at least 4.5? | CREATE TABLE TourEngagements (hotel_id INT,city TEXT,rating FLOAT,num_engagements INT); INSERT INTO TourEngagements (hotel_id,city,rating,num_engagements) VALUES (1,'Barcelona',4.8,100),(2,'Barcelona',4.7,120),(3,'Barcelona',3.5,50); | SELECT SUM(num_engagements) FROM TourEngagements WHERE city = 'Barcelona' AND rating >= 4.5; |
Identify the number of artworks in the 'Expressionism' genre, grouped by the artist's country of origin and the artwork's medium. | CREATE TABLE Artwork (artwork_id INT,artwork_name VARCHAR(30),genre VARCHAR(20),artist_id INT,medium VARCHAR(20)); CREATE TABLE Artist (artist_id INT,artist_name VARCHAR(30),country_of_origin VARCHAR(30)); | SELECT Artist.country_of_origin, Artwork.medium, COUNT(Artwork.artwork_id) FROM Artist INNER JOIN Artwork ON Artist.artist_id = Artwork.artist_id WHERE Artwork.genre = 'Expressionism' GROUP BY Artist.country_of_origin, Artwork.medium; |
How many UNESCO heritage sites are there in Oceania? | CREATE TABLE UNESCO_SITES (id INT PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),type VARCHAR(255)); INSERT INTO UNESCO_SITES (id,name,region,type) VALUES (1,'Great Barrier Reef','Oceania','Natural'); | SELECT COUNT(*) FROM UNESCO_SITES WHERE region = 'Oceania'; |
What is the average age of patients who improved after medication? | CREATE TABLE patients (id INT,age INT,improvement VARCHAR(10)); INSERT INTO patients (id,age,improvement) VALUES (1,35,'improved'),(2,42,'did not improve'),(3,28,'improved'),(4,50,'did not improve'),(5,45,'improved'),(6,30,'did not improve'); | SELECT AVG(age) FROM patients WHERE improvement = 'improved'; |
What is the average age of patients who received therapy in Canada? | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,country TEXT); INSERT INTO patients (patient_id,age,gender,country) VALUES (1,30,'Male','Canada'); INSERT INTO patients (patient_id,age,gender,country) VALUES (2,45,'Female','Canada'); CREATE TABLE treatments (treatment_id INT,patient_id INT,treatment_type TEXT,treatment_date DATE); INSERT INTO treatments (treatment_id,patient_id,treatment_type,treatment_date) VALUES (1,1,'Therapy','2020-01-01'); INSERT INTO treatments (treatment_id,patient_id,treatment_type,treatment_date) VALUES (2,2,'Therapy','2020-02-15'); | SELECT AVG(age) FROM patients JOIN treatments ON patients.patient_id = treatments.patient_id WHERE patients.country = 'Canada' AND treatments.treatment_type = 'Therapy'; |
For the 'design_standards' table, add a new row with the following information: ID 4, name 'Bridge Design Standards for Earthquake Zones', version '2022', and description 'New standards for bridge design in earthquake zones'. | CREATE TABLE design_standards (id INT,name VARCHAR(50),version INT,description VARCHAR(100)); | INSERT INTO design_standards (id, name, version, description) VALUES (4, 'Bridge Design Standards for Earthquake Zones', 2022, 'New standards for bridge design in earthquake zones'); |
What is the maximum number of visitors per day at the Grand Canyon National Park? | CREATE TABLE gcnp_visitors (id INT,date DATE,visitors INT); INSERT INTO gcnp_visitors (id,date,visitors) VALUES (1,'2022-01-01',10000),(2,'2022-01-02',12000),(3,'2022-01-03',15000); | SELECT MAX(visitors) FROM gcnp_visitors; |
What was the total revenue generated by sustainable tourism activities in New Zealand and Canada in 2022? | CREATE TABLE sustainable_tourism (country VARCHAR(50),year INT,revenue INT); INSERT INTO sustainable_tourism (country,year,revenue) VALUES ('New Zealand',2022,5000000),('Canada',2022,7000000); | SELECT SUM(revenue) FROM sustainable_tourism WHERE country IN ('New Zealand', 'Canada') AND year = 2022; |
How many unique service types are provided in the 'defendant_services' table? | CREATE TABLE defendant_services (id INT,case_number INT,defendant_name VARCHAR(255),service_type VARCHAR(255)); INSERT INTO defendant_services (id,case_number,defendant_name,service_type) VALUES (1,1234,'Jane Doe','Education'); | SELECT COUNT(DISTINCT service_type) FROM defendant_services; |
List the underwater species and their average depths in the Indian and Pacific Oceans. | CREATE TABLE underwater_species (species TEXT,depth INT,ocean TEXT); INSERT INTO underwater_species (species,depth,ocean) VALUES ('SpeciesA',3000,'Indian'),('SpeciesB',4000,'Indian'),('SpeciesC',5000,'Indian'),('SpeciesD',6000,'Pacific'),('SpeciesE',7000,'Pacific'); | SELECT species, AVG(depth) FROM underwater_species WHERE ocean IN ('Indian', 'Pacific') GROUP BY species; |
Update the maximum depth for 'Research Site A' to 3500 meters. | CREATE TABLE marine_sites (site_id INT,site_name TEXT,max_depth FLOAT); INSERT INTO marine_sites (site_id,site_name,max_depth) VALUES (1,'Research Site A',3000.5),(2,'Research Site B',5500.2),(3,'Research Site C',2000.0); | UPDATE marine_sites SET max_depth = 3500 WHERE site_name = 'Research Site A'; |
Which countries have the highest marine pollution levels in the Atlantic Ocean? | CREATE TABLE CountryPollution (id INT,country VARCHAR(255),pollution_level FLOAT); INSERT INTO CountryPollution (id,country,pollution_level) VALUES (1,'United States',6.2); INSERT INTO CountryPollution (id,country,pollution_level) VALUES (2,'Brazil',5.8); | SELECT country, pollution_level FROM CountryPollution WHERE location = 'Atlantic Ocean' AND pollution_level = (SELECT MAX(pollution_level) FROM CountryPollution WHERE location = 'Atlantic Ocean'); |
Create a table for tracking food waste | CREATE TABLE food_waste (waste_type VARCHAR(255),quantity INT); | CREATE TABLE food_waste (waste_type VARCHAR(255), quantity INT); |
Find the customer order frequency for the top 10 customers in the last 30 days? | CREATE TABLE Customers (id INT,name VARCHAR(255),email VARCHAR(255)); INSERT INTO Customers (id,name,email) VALUES (1,'John Smith','[email protected]'),(2,'Jane Doe','[email protected]'); CREATE TABLE Orders (id INT,customer_id INT,order_date DATE); INSERT INTO Orders (id,customer_id,order_date) VALUES (1,1,'2022-02-01'),(2,1,'2022-02-10'),(3,2,'2022-02-20'),(4,1,'2022-02-28'); | SELECT C.name, COUNT(O.id) as order_frequency, RANK() OVER (ORDER BY COUNT(O.id) DESC) as rank FROM Customers C JOIN Orders O ON C.id = O.customer_id WHERE O.order_date >= DATEADD(day, -30, GETDATE()) GROUP BY C.id, C.name ORDER BY rank; |
What is the maximum contract value for Northrop Grumman's geopolitical risk assessments? | CREATE TABLE contract_values (id INT,contractor VARCHAR(255),service VARCHAR(255),value FLOAT); INSERT INTO contract_values (id,contractor,service,value) VALUES (1,'Northrop Grumman','Geopolitical Risk Assessment',5000000),(2,'Northrop Grumman','Cybersecurity Services',7000000),(3,'Northrop Grumman','Military Satellite Operations',8000000); | SELECT MAX(value) FROM contract_values WHERE contractor = 'Northrop Grumman' AND service = 'Geopolitical Risk Assessment'; |
What is the average labor productivity in coal mining? | CREATE TABLE labor (employee_id INT,employee_name VARCHAR(50),department VARCHAR(20),hours_worked INT,productivity INT); INSERT INTO labor (employee_id,employee_name,department,hours_worked,productivity) VALUES (1,'John Doe','coal',160,500),(2,'Jane Doe','coal',180,600),(3,'Mike Smith','gold',165,700),(4,'Emma Johnson','copper',170,550); | SELECT AVG(l.productivity) AS avg_productivity FROM labor l WHERE l.department = 'coal'; |
What is the average upload speed for broadband customers in a specific continent? | CREATE TABLE broadband_customers (customer_id INT,upload_speed FLOAT,continent VARCHAR(50)); INSERT INTO broadband_customers (customer_id,upload_speed,continent) VALUES (1,80,'Asia'),(2,60,'Europe'),(3,90,'Asia'); CREATE VIEW avg_upload_speed_view AS SELECT continent,AVG(upload_speed) as avg_upload_speed FROM broadband_customers GROUP BY continent; | SELECT continent, avg_upload_speed, avg_upload_speed/AVG(avg_upload_speed) OVER (PARTITION BY continent) as avg_upload_speed_percentage FROM avg_upload_speed_view; |
What is the maximum data usage in the 'urban' region? | CREATE TABLE subscribers (id INT,name VARCHAR(50),data_usage FLOAT,region VARCHAR(20)); INSERT INTO subscribers (id,name,data_usage,region) VALUES (1,'John Doe',20.0,'urban'),(2,'Jane Doe',18.0,'urban'); | SELECT MAX(data_usage) FROM subscribers WHERE region = 'urban'; |
What is the number of mobile and broadband subscribers in each country? | CREATE TABLE subscribers (id INT,name VARCHAR(255),plan_id INT,country VARCHAR(255)); CREATE TABLE mobile_plans (id INT,name VARCHAR(255),type VARCHAR(255),price DECIMAL(10,2)); CREATE TABLE broadband_plans (id INT,name VARCHAR(255),type VARCHAR(255),price DECIMAL(10,2)); CREATE TABLE countries (id INT,name VARCHAR(255)); | SELECT countries.name AS country, COUNT(*) FROM subscribers JOIN mobile_plans ON subscribers.plan_id = mobile_plans.id JOIN broadband_plans ON subscribers.plan_id = broadband_plans.id JOIN countries ON subscribers.country = countries.id GROUP BY countries.name; |
Which concert has the highest ticket sales? | CREATE TABLE Concerts (concert_id INT,city VARCHAR(50),sales INT); INSERT INTO Concerts (concert_id,city,sales) VALUES (1,'Los Angeles',5000),(2,'New York',7000),(3,'Chicago',6000); | SELECT city, MAX(sales) as max_sales FROM Concerts; |
What is the average donation amount per month, for each donor? | CREATE TABLE DonationAmounts (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL(10,2)); INSERT INTO DonationAmounts VALUES (1,1,'2021-04-05',1500.00),(2,1,'2021-08-20',1500.00),(3,2,'2021-04-12',1000.00),(4,3,'2021-08-01',2000.00); | SELECT DonorID, AVG(DonationAmount) OVER (PARTITION BY DonorID, EXTRACT(MONTH FROM DonationDate)) AS AvgDonationPerMonth FROM DonationAmounts WHERE EXTRACT(YEAR FROM DonationDate) = 2021 ORDER BY DonorID, DonationDate; |
What is the average number of donations per month for each donor? | CREATE TABLE donations (id INT,donor_id INT,donation_date DATE); INSERT INTO donations (id,donor_id,donation_date) VALUES (1,1,'2021-01-01'); INSERT INTO donations (id,donor_id,donation_date) VALUES (2,1,'2021-02-01'); | SELECT donor_id, AVG(COUNT(donation_id)) as avg_donations_per_month FROM donations GROUP BY donor_id, DATE_FORMAT(donation_date, '%Y-%m') WITH ROLLUP; |
Which programs received donations in the 'ProgramDonations' table? | CREATE TABLE Programs (ProgramID int,ProgramName varchar(50)); CREATE TABLE Donations (DonationID int,Donation decimal(10,2)); CREATE TABLE ProgramDonations (ProgramID int,DonationID int,ProgramName varchar(50),Donation decimal(10,2)); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); INSERT INTO Donations (DonationID,Donation) VALUES (1,1000.00),(2,1500.00),(3,750.00); INSERT INTO ProgramDonations (ProgramID,DonationID,ProgramName,Donation) VALUES (1,1,'Education',1000.00),(2,2,'Health',1500.00),(3,3,'Environment',750.00); | SELECT DISTINCT ProgramName FROM ProgramDonations; |
What is the average donation frequency for each cause in the 'philanthropy.causes' table? | CREATE TABLE philanthropy.donation_amount_by_cause (donation_id INT,donor_id INT,cause_id INT,donation_date DATE,donation_amount DECIMAL); | SELECT c.cause_name, AVG(dam.donation_frequency) FROM philanthropy.causes c JOIN (SELECT cause_id, COUNT(*) AS donation_frequency FROM philanthropy.donation_amount_by_cause GROUP BY cause_id) dam ON c.cause_id = dam.cause_id GROUP BY c.cause_name; |
What is the maximum playtime in minutes for players who have achieved a rank of Platinum or higher in the game "Cosmic Racers"? | CREATE TABLE CosmicRacersPlayers (PlayerID INT,PlayerName VARCHAR(50),PlaytimeMinutes INT,Rank VARCHAR(10)); INSERT INTO CosmicRacersPlayers VALUES (1,'DavidLee',750,'Platinum'),(2,'MichelleHernandez',600,'Gold'),(3,'KevinWang',900,'Platinum'),(4,'GraceChoi',850,'Diamond'); | SELECT MAX(PlaytimeMinutes) FROM CosmicRacersPlayers WHERE Rank IN ('Platinum', 'Diamond'); |
Identify the total number of players who have played "Fantasy" games and are from "Asia". | CREATE TABLE Game (id INT,name VARCHAR(255)); INSERT INTO Game (id,name) VALUES (1,'Fantasy'); CREATE TABLE Player (id INT,country VARCHAR(255)); CREATE TABLE GamePlayer (PlayerId INT,GameId INT); INSERT INTO Player (id,country) VALUES (1,'India'),(2,'China'),(3,'USA'); INSERT INTO GamePlayer (PlayerId,GameId) VALUES (1,1),(2,1),(3,1); | SELECT COUNT(DISTINCT PlayerId) FROM GamePlayer GP JOIN Player P ON GP.PlayerId = P.id WHERE GP.GameId = (SELECT G.id FROM Game G WHERE G.name = 'Fantasy') AND P.country = 'Asia'; |
List all virtual reality (VR) games with their respective designers and the number of years of experience the designers have in VR game development. | CREATE TABLE VR_Games (GameID INT,GameName VARCHAR(50),Genre VARCHAR(20)); CREATE TABLE Designers (DesignerID INT,DesignerName VARCHAR(50),YearsOfExperience INT); CREATE TABLE VR_GameDesign (GameID INT,DesignerID INT); | SELECT VR_Games.GameName, Designers.DesignerName, Designers.YearsOfExperience FROM VR_Games INNER JOIN VR_GameDesign ON VR_Games.GameID = VR_GameDesign.GameID INNER JOIN Designers ON VR_GameDesign.DesignerID = Designers.DesignerID; |
List the top 3 countries with the most satellite image analysis performed in the last month. | CREATE TABLE satellite_image_analysis (id INT,country VARCHAR(255),analysis_date DATE); INSERT INTO satellite_image_analysis (id,country,analysis_date) VALUES (1,'Brazil','2022-01-03'),(2,'Kenya','2022-01-01'),(3,'Brazil','2022-01-02'),(4,'Indonesia','2022-01-04'),(5,'Kenya','2022-01-02'),(6,'Brazil','2022-01-01'); | SELECT country, COUNT(*) as analysis_count FROM satellite_image_analysis WHERE analysis_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY country ORDER BY analysis_count DESC LIMIT 3; |
What is the average temperature in degree Celsius recorded by sensors in the 'Field1' during the month of July in 2021 and 2022? | CREATE TABLE Field1_Temperature (sensor_id INT,measurement_time TIMESTAMP,temperature DECIMAL(5,2)); INSERT INTO Field1_Temperature (sensor_id,measurement_time,temperature) VALUES (1,'2021-07-01 10:00:00',23.5),(2,'2021-07-01 10:00:00',24.3); | SELECT AVG(temperature) FROM (SELECT temperature FROM Field1_Temperature WHERE EXTRACT(MONTH FROM measurement_time) = 7 AND EXTRACT(YEAR FROM measurement_time) IN (2021, 2022) GROUP BY sensor_id, EXTRACT(DAY FROM measurement_time)) t |
What is the maximum temperature and humidity for each crop type in the past month? | CREATE TABLE crop_temperature (crop_type TEXT,temperature INTEGER,timestamp TIMESTAMP);CREATE TABLE crop_humidity (crop_type TEXT,humidity INTEGER,timestamp TIMESTAMP); | SELECT ct.crop_type, MAX(ct.temperature) as max_temp, MAX(ch.humidity) as max_humidity FROM crop_temperature ct JOIN crop_humidity ch ON ct.timestamp = ch.timestamp WHERE ct.timestamp BETWEEN DATEADD(month, -1, CURRENT_TIMESTAMP) AND CURRENT_TIMESTAMP GROUP BY ct.crop_type; |
How many public services were delivered in the North region in Q2 of 2019? | CREATE TABLE Deliveries (quarter INT,region VARCHAR(255),count INT); INSERT INTO Deliveries (quarter,region,count) VALUES (2,'North',1500),(2,'North',1600),(2,'North',1400),(2,'South',1700),(2,'South',1800); | SELECT SUM(count) FROM Deliveries WHERE quarter = 2 AND region = 'North'; |
What is the minimum budget allocated for the 'Education' department in the year 2022? | CREATE TABLE Budget(year INT,department VARCHAR(20),amount INT); INSERT INTO Budget VALUES (2021,'Healthcare',7000000),(2021,'Education',5000000),(2022,'Healthcare',7800000),(2022,'Education',5300000),(2022,'Education',4800000); | SELECT MIN(amount) FROM Budget WHERE department = 'Education' AND year = 2022; |
Which element had the lowest production in 2019? | CREATE TABLE production (year INT,element VARCHAR(10),quantity INT); INSERT INTO production (year,element,quantity) VALUES (2015,'Neodymium',1200),(2016,'Neodymium',1400),(2017,'Neodymium',1500),(2018,'Neodymium',1700),(2019,'Neodymium',1800),(2020,'Neodymium',2000),(2021,'Neodymium',2200),(2015,'Praseodymium',1100),(2016,'Praseodymium',1300),(2017,'Praseodymium',1400),(2018,'Praseodymium',1600),(2019,'Praseodymium',1500),(2020,'Praseodymium',1900),(2021,'Praseodymium',2100); | SELECT element, MIN(quantity) FROM production WHERE year = 2019 GROUP BY element; |
List the co-owners and their shared property addresses in Portland, OR and Seattle, WA. | CREATE TABLE co_owners (id INT,name VARCHAR(30),property_id INT,city VARCHAR(20)); CREATE TABLE properties (id INT,address VARCHAR(50)); INSERT INTO co_owners (id,name,property_id,city) VALUES (1,'Alex',101,'Portland'),(2,'Bella',101,'Portland'),(3,'Charlie',102,'Seattle'),(4,'Denise',103,'Seattle'); INSERT INTO properties (id,address) VALUES (101,'1234 SE Stark St'),(102,'5678 NE 20th Ave'),(103,'9876 W Olympic Pl'); | SELECT co_owners.name, properties.address FROM co_owners INNER JOIN properties ON co_owners.property_id = properties.id WHERE co_owners.city IN ('Portland', 'Seattle'); |
How many carbon offset programs were initiated in Asia in 2020? | CREATE TABLE if not exists carbon_offset_programs (program_id integer,program_start_date date,program_location varchar(255)); INSERT INTO carbon_offset_programs (program_id,program_start_date,program_location) VALUES (1,'2020-01-01','China'),(2,'2020-06-01','India'),(3,'2020-12-31','Japan'); | SELECT program_location, COUNT(*) as num_programs FROM carbon_offset_programs WHERE program_start_date BETWEEN '2020-01-01' AND '2020-12-31' AND program_location LIKE 'Asia%' GROUP BY program_location; |
What is the average energy efficiency rating for projects in Germany? | CREATE TABLE projects (project_id INT,name TEXT,location TEXT,rating FLOAT); INSERT INTO projects (project_id,name,location,rating) VALUES (1,'Solar Farm','Germany',1.8),(2,'Wind Turbine','France',2.2),(3,'Geothermal Plant','Germany',2.0); | SELECT AVG(rating) FROM projects WHERE location = 'Germany'; |
Which renewable energy projects in the 'renewable_projects' table are located in the US or Canada? | CREATE TABLE renewable_projects (project_name VARCHAR(255),location VARCHAR(255)); | SELECT project_name FROM renewable_projects WHERE location IN ('US', 'Canada'); |
Which menu items were sold the least in the last month, ordered by quantity sold? | CREATE TABLE MenuSales (restaurant_id INT,menu_item_id INT,sale_date DATE,quantity_sold INT); INSERT INTO MenuSales (restaurant_id,menu_item_id,sale_date,quantity_sold) VALUES (1,101,'2021-08-01',5),(1,102,'2021-08-01',12),(1,103,'2021-08-01',3),(1,101,'2021-08-02',2),(1,102,'2021-08-02',8),(1,103,'2021-08-02',7); | SELECT menu_item_id, SUM(quantity_sold) as total_quantity_sold FROM menusales WHERE sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GROUP BY menu_item_id ORDER BY total_quantity_sold ASC; |
What is the distribution of space debris by their sources and average years in orbit? | CREATE TABLE space_debris (id INT,name VARCHAR(255),type VARCHAR(255),source VARCHAR(255),launch_date DATE); INSERT INTO space_debris VALUES (4,'Defunct Satellite','Satellite','Brazil','2005-01-01'),(5,'Rocket Body','Rocket','Indonesia','2010-05-05'); | SELECT source, COUNT(id) as count, AVG(DATEDIFF(CURDATE(), launch_date)) as avg_years_in_orbit FROM space_debris GROUP BY source; |
How many space missions were successfully completed before 2010? | CREATE TABLE SpaceMissions (id INT,mission_name VARCHAR(255),start_date DATE,end_date DATE,status VARCHAR(50)); INSERT INTO SpaceMissions (id,mission_name,start_date,end_date,status) VALUES (1,'Apollo 11','1969-07-16','1969-07-24','Success'),(2,'Apollo 13','1970-04-11','1970-04-17','Failure'); | SELECT COUNT(*) FROM SpaceMissions WHERE status = 'Success' AND start_date < '2010-01-01'; |
What is the total mass of all spacecraft manufactured by SpaceX? | CREATE TABLE Spacecraft (SpacecraftID INT,SpacecraftName VARCHAR(50),Manufacturer VARCHAR(50),Mass FLOAT); INSERT INTO Spacecraft (SpacecraftID,SpacecraftName,Manufacturer,Mass) VALUES (1,'SpaceX Dragon','SpaceX',10000),(2,'Orion','Lockheed Martin',20000),(3,'Starliner','Boeing',15000); | SELECT SUM(Mass) FROM Spacecraft WHERE Manufacturer = 'SpaceX'; |
Count the number of fans from 'fan_demographics' table by gender. | CREATE TABLE fan_demographics (fan_id INT,gender VARCHAR(10),age INT,location VARCHAR(30)); | SELECT gender, COUNT(*) FROM fan_demographics GROUP BY gender; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.