instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Find the number of unique IP addresses involved in each type of attack, for the last month, partitioned by attack type and day?
CREATE TABLE attacks (attack_type VARCHAR(255),ip_address VARCHAR(255),attack_date DATE); INSERT INTO attacks (attack_type,ip_address,attack_date) VALUES ('DDOS','192.168.1.1','2022-06-01'),('DDOS','192.168.1.2','2022-06-01'),('Phishing','192.168.1.3','2022-06-02'),('Phishing','192.168.1.4','2022-06-02'),('Phishing','1...
SELECT attack_type, attack_date, COUNT(DISTINCT ip_address) as unique_ip_addresses FROM attacks WHERE attack_date >= DATEADD(month, -1, GETDATE()) GROUP BY attack_type, attack_date;
Delete all records in the 'military_equipment' table where 'country' is 'China'
CREATE TABLE military_equipment (equipment_id INT PRIMARY KEY,equipment_type VARCHAR(20),country VARCHAR(20),in_service BOOLEAN);
DELETE FROM military_equipment WHERE country = 'China';
What is the success rate (exit or IPO) of startups founded by BIPOC founders?
CREATE TABLE startups (id INT,name TEXT,founding_date DATE,founding_team TEXT,total_funding FLOAT,exit_status TEXT); INSERT INTO startups (id,name,founding_date,founding_team,total_funding,exit_status) VALUES (1,'Acme Inc','2010-01-01','John,Jane',5000000,'IPO');
SELECT COUNT(*) / (SELECT COUNT(*) FROM startups WHERE founding_team LIKE '%, BIPOC%') AS success_rate FROM startups WHERE exit_status IS NOT NULL AND founding_team LIKE '%, BIPOC%';
Find the projects that have been completed in both the 'rural_development' and 'urban_development' databases.
CREATE TABLE RuralDevelopment_InfrastructureProjects (id INT PRIMARY KEY,name VARCHAR(100),status VARCHAR(20),evaluation_date DATE); INSERT INTO RuralDevelopment_InfrastructureProjects (id,name,status,evaluation_date) VALUES (1,'Water Treatment Plant','completed',NULL),(2,'Renewable Energy Center','in_progress','2023-0...
SELECT RuralDevelopment_InfrastructureProjects.name FROM RuralDevelopment_InfrastructureProjects INNER JOIN UrbanDevelopment_InfrastructureProjects ON RuralDevelopment_InfrastructureProjects.name = UrbanDevelopment_InfrastructureProjects.name WHERE RuralDevelopment_InfrastructureProjects.status = 'completed' AND UrbanD...
Update the date of the community engagement event in 'Nigeria' with id 2
CREATE TABLE community_engagement (id INT PRIMARY KEY,name TEXT,location TEXT,date DATE);
UPDATE community_engagement SET date = '2023-12-31' WHERE id = 2 AND location = 'Nigeria';
What is the total energy storage capacity (in MWh) for the United States as of January 1, 2022?
CREATE TABLE energy_storage (id INT,country VARCHAR(50),capacity FLOAT,timestamp TIMESTAMP); INSERT INTO energy_storage (id,country,capacity,timestamp) VALUES (1,'United States',1200.5,'2022-01-01 00:00:00');
SELECT country, SUM(capacity) as total_capacity FROM energy_storage WHERE country = 'United States' AND timestamp = '2022-01-01 00:00:00' GROUP BY country;
What is the score for the tool with the highest score in the Data category?
CREATE TABLE tool (category VARCHAR(20),tool VARCHAR(20),score INT); INSERT INTO tool (category,tool,score) VALUES ('AI','Chatbot',85),('AI','Image Recognition',90),('Data','Data Visualization',80),('Data','Data Analysis',85);
SELECT score FROM tool WHERE category = 'Data' AND tool = (SELECT tool FROM tool WHERE category = 'Data' AND score = (SELECT MAX(score) FROM tool WHERE category = 'Data'));
Which programs had the most impact in the last three months?
CREATE TABLE Programs (Program TEXT,Impact DECIMAL); INSERT INTO Programs (Program,Impact) VALUES ('Tree Planting',1000); INSERT INTO Programs (Program,Impact) VALUES ('Food Bank',2000);
SELECT Program, Impact FROM Programs WHERE Program IN (SELECT Program FROM Volunteers WHERE VolunteerDate >= DATEADD(month, -3, GETDATE()) GROUP BY Program HAVING COUNT(*) >= (SELECT AVG(COUNT(*)) FROM Volunteers WHERE VolunteerDate >= DATEADD(month, -3, GETDATE()) GROUP BY Program));
What is the maximum number of hours spent on open pedagogy projects by students in each school?
CREATE TABLE open_pedagogy_projects (project_id INT,student_id INT,school_id INT,hours_spent INT); INSERT INTO open_pedagogy_projects (project_id,student_id,school_id,hours_spent) VALUES (1,1,1,10),(2,2,1,12),(3,3,2,15),(4,4,2,18),(5,5,3,20),(6,6,3,22);
SELECT schools.school_name, MAX(open_pedagogy_projects.hours_spent) as max_hours FROM schools JOIN open_pedagogy_projects ON schools.school_id = open_pedagogy_projects.school_id GROUP BY schools.school_id;
What is the number of unique vessels that visited the port of Los Angeles in February 2021?
CREATE TABLE vessel_visits (id INT,vessel_id INT,port_id INT,visit_date DATE); INSERT INTO vessel_visits (id,vessel_id,port_id,visit_date) VALUES (1,1,3,'2021-02-10'); INSERT INTO vessel_visits (id,vessel_id,port_id,visit_date) VALUES (2,2,3,'2021-02-12');
SELECT COUNT(DISTINCT vessel_id) FROM vessel_visits WHERE port_id = (SELECT id FROM ports WHERE name = 'Los Angeles') AND visit_date BETWEEN '2021-02-01' AND '2021-02-28';
What is the average heart rate of users aged 25-30?
CREATE TABLE users (id INT,age INT,heart_rate INT); INSERT INTO users (id,age,heart_rate) VALUES (1,25,80),(2,30,90),(3,27,75);
SELECT AVG(heart_rate) FROM users WHERE age BETWEEN 25 AND 30;
What's the minimum donation amount made by donors from Texas in the third quarter of 2021?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(100),DonationAmount DECIMAL(10,2),DonationDate DATE,DonorState VARCHAR(50));
SELECT MIN(DonationAmount) FROM Donors WHERE DonorState = 'Texas' AND QUARTER(DonationDate) = 3 AND YEAR(DonationDate) = 2021;
Which beauty products contain the ingredient 'paraben'?
CREATE TABLE ProductIngredients (product VARCHAR(255),ingredient VARCHAR(255));
SELECT DISTINCT product FROM ProductIngredients WHERE ingredient = 'paraben';
List all biotech startups that have received funding from venture capital firms based in Silicon Valley, along with the funding amounts.
CREATE SCHEMA if not exists startups; USE startups; CREATE TABLE if not exists companies (id INT,name VARCHAR(100),industry VARCHAR(100),location VARCHAR(100)); CREATE TABLE if not exists funding (id INT,company_id INT,source VARCHAR(100),amount DECIMAL(10,2)); INSERT INTO companies (id,name,industry,location) VALUES (...
SELECT companies.name, funding.source, SUM(funding.amount) FROM startups.companies INNER JOIN startups.funding ON companies.id = funding.company_id WHERE companies.industry = 'Biotech' AND location = 'California' AND source LIKE 'VC Firm%' GROUP BY companies.name, funding.source;
What is the minimum age of visitors who participated in the "Family Day" event?
CREATE TABLE events (event_id INT,event_name VARCHAR(255)); INSERT INTO events (event_id,event_name) VALUES (1,'Family Day'); CREATE TABLE visitors_events (visitor_id INT,event_id INT,age INT); INSERT INTO visitors_events (visitor_id,event_id,age) VALUES (1,1,10),(2,1,12),(3,1,8);
SELECT MIN(age) FROM visitors_events WHERE event_id = 1;
Number of patents filed in clean energy in 2020
CREATE TABLE clean_energy_patents (id INT,patent_number VARCHAR(255),title VARCHAR(255),inventor VARCHAR(255),filing_date DATE,country VARCHAR(255));
SELECT COUNT(*) FROM clean_energy_patents WHERE filing_date >= '2020-01-01' AND filing_date < '2021-01-01';
Delete all environmental impact records for mine with ID 3 in the year 2019.
CREATE TABLE EnvironmentalImpact (ImpactID INT,MineID INT,Year INT,ImpactScore INT); INSERT INTO EnvironmentalImpact (ImpactID,MineID,Year,ImpactScore) VALUES (1,1,2019,50); INSERT INTO EnvironmentalImpact (ImpactID,MineID,Year,ImpactScore) VALUES (2,1,2018,55); INSERT INTO EnvironmentalImpact (ImpactID,MineID,Year,Imp...
DELETE FROM EnvironmentalImpact WHERE MineID = 3 AND Year = 2019;
Delete records in circular_economy_initiatives where initiative_type is 'Composting'
CREATE TABLE circular_economy_initiatives (id INT,initiative_type VARCHAR(20),start_year INT,end_year INT);
WITH data_to_delete AS (DELETE FROM circular_economy_initiatives WHERE initiative_type = 'Composting' RETURNING *) DELETE FROM circular_economy_initiatives WHERE id IN (SELECT id FROM data_to_delete);
What is the total funding for startups in the 'Sustainability' industry founded before 2017?
CREATE TABLE startups(id INT,name TEXT,founded_year INT,industry TEXT,total_funding DECIMAL(10,2)); INSERT INTO startups (id,name,founded_year,industry,total_funding) VALUES (1,'Acme Inc',2010,'Tech',1500000.00); INSERT INTO startups (id,name,founded_year,industry,total_funding) VALUES (2,'Beta Corp',2015,'Biotech',200...
SELECT SUM(total_funding) FROM startups WHERE industry = 'Sustainability' AND founded_year < 2017;
List all artists who have performed in a music festival in the United Kingdom.
CREATE TABLE Artists (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE Festivals (id INT,artist_id INT,country VARCHAR(255));
SELECT Artists.name FROM Artists INNER JOIN Festivals ON Artists.id = Festivals.artist_id WHERE Festivals.country = 'United Kingdom';
Display the number of unique specialties for community health workers.
CREATE TABLE CommunityHealthWorkers (WorkerID INT,Name VARCHAR(50),Specialty VARCHAR(50)); CREATE TABLE Cases (WorkerID INT,CaseID INT,CaseType VARCHAR(20)); INSERT INTO CommunityHealthWorkers (WorkerID,Name,Specialty) VALUES (1,'John Doe','Mental Health'); INSERT INTO CommunityHealthWorkers (WorkerID,Name,Specialty) V...
SELECT COUNT(DISTINCT Specialty) FROM CommunityHealthWorkers;
Find the top 5 cities with the highest total network investment in the first quarter of 2021.
CREATE TABLE network_investments(city VARCHAR(20),investment_date DATE,amount DECIMAL(10,2)); INSERT INTO network_investments(city,investment_date,amount) VALUES ('New York','2021-01-01',150000.00),('New York','2021-02-15',120000.00),('Chicago','2021-04-01',180000.00);
SELECT city, SUM(amount) FROM network_investments WHERE investment_date BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY city ORDER BY SUM(amount) DESC LIMIT 5;
Which sites have both wooden and stone artifacts?
CREATE TABLE excavation_sites (site_id INT,site_name TEXT); CREATE TABLE artifacts (artifact_id INT,site_id INT,artifact_type TEXT); INSERT INTO excavation_sites (site_id,site_name) VALUES (1,'Site A'),(2,'Site B'),(3,'Site C'); INSERT INTO artifacts (artifact_id,site_id,artifact_type) VALUES (1,1,'wooden'),(2,1,'stone...
SELECT e.site_name FROM excavation_sites e JOIN artifacts a ON e.site_id = a.site_id WHERE a.artifact_type IN ('wooden', 'stone') GROUP BY e.site_id HAVING COUNT(DISTINCT a.artifact_type) = 2;
Update the engine model of aircraft with ID 105 to CFM LEAP
CREATE TABLE aircraft (id INT PRIMARY KEY,model VARCHAR(50),engine VARCHAR(50)); INSERT INTO aircraft (id,model,engine) VALUES (101,'747','CFM56'),(102,'A320','IAE V2500'),(103,'A350','Rolls-Royce Trent XWB'),(104,'787','GE GEnx'),(105,'737','CFM56');
UPDATE aircraft SET engine = 'CFM LEAP' WHERE id = 105;
What is the daily revenue trend for a specific restaurant?
CREATE TABLE daily_revenue (date DATE,restaurant_id INT,revenue FLOAT); INSERT INTO daily_revenue VALUES ('2021-01-01',1,500),('2021-01-02',1,700),('2021-01-03',1,600),('2021-01-01',2,800),('2021-01-02',2,900),('2021-01-03',2,700);
SELECT date, revenue FROM daily_revenue WHERE restaurant_id = 1;
How many workers are there in factories located in urban areas compared to rural areas?
CREATE TABLE Factory_Location (id INT,factory_id INT,area VARCHAR(255),workers INT); INSERT INTO Factory_Location (id,factory_id,area,workers) VALUES (1,1001,'Urban',200),(2,1002,'Rural',150);
SELECT area, SUM(workers) FROM Factory_Location GROUP BY area;
Show the total number of volunteers and total amount donated in each country, ordered by the total donation amount in descending order.
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Country TEXT,TotalDonation DECIMAL); CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,Country TEXT);
SELECT V.Country, COUNT(DISTINCT V.VolunteerID) as Volunteers, SUM(D.TotalDonation) as TotalDonation FROM Volunteers V JOIN Donors D ON V.Country = D.Country GROUP BY V.Country ORDER BY TotalDonation DESC;
Which African countries have the highest sustainable seafood production?
CREATE TABLE African_Countries (country VARCHAR(20),production FLOAT); INSERT INTO African_Countries (country,production) VALUES ('Morocco',650.3); INSERT INTO African_Countries (country,production) VALUES ('Senegal',420.1);
SELECT country, production FROM African_Countries WHERE production IN (SELECT MAX(production) FROM African_Countries WHERE production <= 650.3);
What is the total number of car-sharing programs in Toronto?
CREATE TABLE car_sharing (program_id INT,program_type VARCHAR(20)); INSERT INTO car_sharing (program_id,program_type) VALUES (1,'Round-trip'),(2,'One-way'),(3,'Peer-to-peer'),(4,'Corporate'),(5,'Fractional');
SELECT COUNT(*) as num_programs FROM car_sharing WHERE program_type IN ('Round-trip', 'One-way', 'Peer-to-peer', 'Corporate', 'Fractional');
What is the total biomass of squids in the Indian Ocean?
CREATE TABLE squid_biomass (species TEXT,biomass REAL,ocean TEXT); INSERT INTO squid_biomass (species,biomass,ocean) VALUES ('Giant Squid',750.0,'Indian'),('Colossal Squid',1000.0,'Indian'),('Humboldt Squid',500.0,'Pacific');
SELECT SUM(biomass) FROM squid_biomass WHERE ocean = 'Indian';
What is the minimum number of mental health parity violations for facilities in the Western region?
CREATE TABLE mental_health_parity_violations (violation_id INT,region VARCHAR(255),number INT); INSERT INTO mental_health_parity_violations (violation_id,region,number) VALUES (1,'Northeast',10),(2,'Southeast',15),(3,'Midwest',20),(4,'West',5),(5,'Northeast',8),(6,'Southeast',12),(7,'Midwest',18),(8,'West',7),(9,'North...
SELECT MIN(number) as min_violations FROM mental_health_parity_violations WHERE region = 'West';
What is the most common category for articles with more than 50 likes?
CREATE TABLE articles (id INT,title TEXT,category TEXT,likes INT,created_at DATETIME); INSERT INTO articles (id,title,category,likes,created_at) VALUES (1,'Climate crisis: 12 years to save the planet','climate change',100,'2022-01-01 10:30:00');
SELECT category, COUNT(*) as article_count FROM articles WHERE likes > 50 GROUP BY category ORDER BY article_count DESC LIMIT 1
How many marine species are currently being researched?
CREATE TABLE marine_species (species_name TEXT,conservation_status TEXT,is_being_researched INTEGER);
SELECT COUNT(*) FROM marine_species WHERE is_being_researched = 1;
What is the number of players living in each country?
CREATE TABLE players (id INT,name VARCHAR(255),age INT,country VARCHAR(255)); INSERT INTO players (id,name,age,country) VALUES (1,'John Doe',25,'USA'),(2,'Jane Doe',30,'Canada'),(3,'Jim Brown',30,'Canada'),(4,'Jamie Smith',28,'USA');
SELECT country, COUNT(DISTINCT id) AS players_count FROM players GROUP BY country;
Display the least common size in the 'Customer_Sizes' table, across all clothing categories.
CREATE TABLE Customer_Sizes (clothing_category VARCHAR(20),size VARCHAR(10),count INT); INSERT INTO Customer_Sizes (clothing_category,size,count) VALUES ('Tops','XS',500),('Tops','S',700),('Tops','M',900),('Tops','L',800),('Tops','XL',600),('Bottoms','S',400),('Bottoms','M',500),('Bottoms','L',600),('Bottoms','XL',700)...
SELECT size, MIN(count) FROM Customer_Sizes GROUP BY size;
What is the distribution of citations for explainable AI papers by author?
CREATE TABLE explainable_ai_papers (author_id INT,author_name VARCHAR(255),num_citations INT); INSERT INTO explainable_ai_papers (author_id,author_name,num_citations) VALUES ('1','Jane Smith','100');
SELECT author_name, num_citations, NTILE(5) OVER (ORDER BY num_citations DESC) as citation_group FROM explainable_ai_papers;
Determine the number of threat intelligence reports created each month in 2022.
CREATE TABLE threat_intelligence (report_id INT,report_date DATE); INSERT INTO threat_intelligence (report_id,report_date) VALUES (1,'2022-01-05'); INSERT INTO threat_intelligence (report_id,report_date) VALUES (2,'2022-02-12'); INSERT INTO threat_intelligence (report_id,report_date) VALUES (3,'2022-03-20');
SELECT DATE_FORMAT(report_date, '%Y-%m') AS month, COUNT(report_id) FROM threat_intelligence GROUP BY month;
What is the average price of Japanese artworks sold in galleries established since 2000?
CREATE TABLE Galleries (GalleryID int,Name varchar(50),EstablishDate date); INSERT INTO Galleries VALUES (1,'Gallery A','2005-01-01'); INSERT INTO Galleries VALUES (2,'Gallery B','2008-05-15'); CREATE TABLE Artworks (ArtworkID int,Name varchar(50),Price decimal(5,2),GalleryID int,ArtCountry varchar(20)); INSERT INTO Ar...
SELECT AVG(Price) FROM (SELECT Price FROM Artworks WHERE ArtCountry = 'Japan' AND GalleryID IN (SELECT GalleryID FROM Galleries WHERE EstablishDate >= '2000-01-01')) AS art_gallery_data;
Which region has the most factories with fair trade certification?
CREATE TABLE factories (factory_id INT,region VARCHAR(255),certification VARCHAR(255)); INSERT INTO factories (factory_id,region,certification) VALUES (1,'Asia','fair trade'),(2,'Africa','not fair trade'),(3,'Asia','fair trade'),(4,'Europe','fair trade'),(5,'South America','fair trade');
SELECT region, COUNT(*) as factory_count FROM factories WHERE certification = 'fair trade' GROUP BY region ORDER BY factory_count DESC LIMIT 1;
What is the total quantity of items in warehouse 1, 4, and 6?
CREATE TABLE warehouses (id INT,location VARCHAR(10),item VARCHAR(10),quantity INT); INSERT INTO warehouses (id,location,item,quantity) VALUES (1,'NY','A101',200),(2,'NJ','A101',300),(3,'CA','B203',150),(4,'NY','C304',50),(5,'MX','B203',250),(6,'IN','A101',400);
SELECT SUM(quantity) FROM warehouses WHERE id IN (1, 4, 6);
What's the total transaction volume for digital assets in the last month?
CREATE TABLE digital_assets (id INT,name VARCHAR(255),transaction_volume DECIMAL(10,2)); INSERT INTO digital_assets (id,name,transaction_volume) VALUES (1,'Asset 1',1000.50),(2,'Asset 2',1500.25),(3,'Asset 3',2000.00); CREATE TABLE transactions (id INT,digital_asset_id INT,transaction_date DATE); INSERT INTO transactio...
SELECT SUM(transaction_volume) FROM digital_assets JOIN transactions ON digital_assets.id = transactions.digital_asset_id WHERE transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the average production cost of garments made with hemp in Europe?
CREATE TABLE HempGarments (id INT,production_cost DECIMAL(5,2),production_location TEXT); INSERT INTO HempGarments (id,production_cost,production_location) VALUES (1,40.00,'Europe'),(2,42.00,'Europe'),(3,38.00,'Asia'),(4,39.00,'Europe');
SELECT AVG(production_cost) FROM HempGarments WHERE production_location = 'Europe';
What is the number of diversity and inclusion training hours for each employee in the IT department?
CREATE TABLE EmployeeTraining (EmployeeID INT,Department VARCHAR(20),TrainingType VARCHAR(20),TrainingHours DECIMAL(10,2),TrainingDate DATE); INSERT INTO EmployeeTraining (EmployeeID,Department,TrainingType,TrainingHours,TrainingDate) VALUES (1,'IT','Diversity and Inclusion',2.00,'2022-01-15'),(2,'IT','Diversity and In...
SELECT EmployeeID, Department, SUM(TrainingHours) FROM EmployeeTraining WHERE Department = 'IT' AND TrainingType = 'Diversity and Inclusion' GROUP BY EmployeeID, Department;
What is the average number of days taken to resolve a vulnerability in the education sector, for vulnerabilities with a severity of 8 or higher?
CREATE TABLE vulnerability_resolution_time (id INT,sector VARCHAR(255),severity FLOAT,resolution_date DATE,detection_date DATE); INSERT INTO vulnerability_resolution_time (id,sector,severity,resolution_date,detection_date) VALUES (1,'education',8.5,'2021-03-01','2021-01-15');
SELECT AVG(DATEDIFF(resolution_date, detection_date)) FROM vulnerability_resolution_time WHERE sector = 'education' AND severity >= 8;
List all campaigns in Canada and their respective budgets.
CREATE TABLE mental_health.campaigns (campaign_id INT,campaign_name VARCHAR(255),country VARCHAR(255)); INSERT INTO mental_health.campaigns (campaign_id,campaign_name,country) VALUES (1,'End the Stigma','Canada'),(2,'Mental Health Matters','USA'),(3,'Break the Barrier','Canada'); CREATE TABLE mental_health.campaign_bud...
SELECT c.campaign_name, cb.budget FROM mental_health.campaigns c INNER JOIN mental_health.campaign_budgets cb ON c.campaign_id = cb.campaign_id WHERE c.country = 'Canada';
What is the number of community health workers who have received cultural competency training by race?
CREATE TABLE community_health_workers (worker_id INT,age INT,race VARCHAR(255),cultural_competency_trained BOOLEAN); INSERT INTO community_health_workers (worker_id,age,race,cultural_competency_trained) VALUES (1,35,'Asian',true),(2,40,'Black',false),(3,45,'White',true);
SELECT race, COUNT(worker_id) FROM community_health_workers WHERE cultural_competency_trained = true GROUP BY race;
What is the market share of electric vehicle manufacturers in Germany for the year 2020?
CREATE TABLE ev_sales(id INT,manufacturer VARCHAR(20),model VARCHAR(20),year INT,units_sold INT);
SELECT manufacturer, 100.0 * SUM(units_sold) / (SELECT SUM(units_sold) FROM ev_sales WHERE year = 2020) AS market_share FROM ev_sales WHERE year = 2020 GROUP BY manufacturer;
How many users are from each country?
CREATE TABLE users (id INT,country VARCHAR(255)); INSERT INTO users (id,country) VALUES (1,'United States'),(2,'Canada'),(3,'Mexico'),(4,'Brazil');
SELECT country, COUNT(*) FROM users GROUP BY country;
What are the recycling programs implemented in the city of New Delhi between 2015 and 2025?
CREATE TABLE nd_recycling_programs (city varchar(255),start_year int,end_year int,program_name varchar(255)); INSERT INTO nd_recycling_programs (city,start_year,end_year,program_name) VALUES ('New Delhi',2015,2017,'Paper Recycling'),('New Delhi',2018,2020,'Plastic Recycling'),('New Delhi',2021,2023,'Metal Recycling'),(...
SELECT program_name FROM nd_recycling_programs WHERE city = 'New Delhi' AND start_year BETWEEN 2015 AND 2025;
What is the total landfill capacity in North America as of 2022, separated by region?
CREATE TABLE LandfillCapacity (region VARCHAR(50),year INT,capacity INT); INSERT INTO LandfillCapacity (region,year,capacity) VALUES ('North America/East',2022,5000000),('North America/West',2022,7000000),('North America/Central',2022,6000000);
SELECT region, SUM(capacity) FROM LandfillCapacity WHERE year = 2022 AND region IN ('North America/East', 'North America/West', 'North America/Central') GROUP BY region;
What are the marine species and their average depths in the Indian Ocean?
CREATE TABLE marine_species (id INT,name VARCHAR(50),region VARCHAR(50),avg_depth DECIMAL(5,2)); INSERT INTO marine_species (id,name,region,avg_depth) VALUES (1,'Giant Clam','Indian Ocean',15.00),(2,'Whale Shark','Indian Ocean',70.00); CREATE TABLE ocean_depth_scale (id INT,name VARCHAR(50),value DECIMAL(5,2));
SELECT marine_species.name, marine_species.avg_depth FROM marine_species INNER JOIN ocean_depth_scale ON marine_species.avg_depth = ocean_depth_scale.value WHERE ocean_depth_scale.name = 'Meters' AND marine_species.region = 'Indian Ocean';
What is the number of community projects in each country that have been completed?
CREATE TABLE community_projects (id INT,name VARCHAR(100),completed INT,country VARCHAR(50)); INSERT INTO community_projects (id,name,completed,country) VALUES (1,'Projeto X',1,'Brazil');
SELECT country, COUNT(*) FROM community_projects WHERE completed = 1 GROUP BY country
How many high-severity vulnerabilities exist for each software product?
CREATE TABLE vulnerabilities (id INT,product VARCHAR(255),severity INT); INSERT INTO vulnerabilities (id,product,severity) VALUES (1,'ProductA',5),(2,'ProductB',9),(3,'ProductA',3);
SELECT product, COUNT(*) as high_severity_vulnerabilities FROM vulnerabilities WHERE severity >= 8 GROUP BY product;
Select active recycling initiatives
CREATE TABLE recycling_initiatives (id INT PRIMARY KEY,region VARCHAR(255),initiative_name VARCHAR(255),initiative_description TEXT,start_date DATE,end_date DATE); INSERT INTO recycling_initiatives (id,region,initiative_name,initiative_description,start_date,end_date) VALUES (1,'Africa','Plastic Bottle Collection','Col...
SELECT * FROM active_recycling_initiatives;
What is the average CO2 emissions of factories in Germany and France?
CREATE TABLE factories (id INT,name VARCHAR(50),location VARCHAR(50),co2_emissions INT); INSERT INTO factories (id,name,location,co2_emissions) VALUES (1,'EcoFactory','Germany',100),(2,'SmartTech','France',120),(3,'GreenInnovations','France',90);
SELECT AVG(co2_emissions) FROM factories WHERE location IN ('Germany', 'France');
What is the average funding received by heritage sites in 'Region Z' for the last 5 years?
CREATE TABLE Funding (id INT,site_name VARCHAR(50),region VARCHAR(50),year INT,amount DECIMAL(5,2)); INSERT INTO Funding (id,site_name,region,year,amount) VALUES (1,'Site A','Region Z',2017,25000);
SELECT AVG(amount) FROM Funding WHERE region = 'Region Z' AND year BETWEEN 2017 AND 2021 GROUP BY region;
What is the total duration (in minutes) that visitors spent on digital exhibits in Chicago?
CREATE TABLE Visitors (id INT,city VARCHAR(50),digital_exhibits_duration INT,visit_year INT); INSERT INTO Visitors (id,city,digital_exhibits_duration,visit_year) VALUES (1,'Chicago',150,2022);
SELECT SUM(digital_exhibits_duration) FROM Visitors WHERE city = 'Chicago';
Add new endangered language to the languages table
CREATE TABLE languages (id INT,language VARCHAR(50),region VARCHAR(50),num_speakers INT);
INSERT INTO languages (id, language, region, num_speakers) VALUES (5, 'Ainu', 'Japan', 500)
What is the distribution of sentiment scores for creative AI applications in different countries?
CREATE TABLE creative_ai (id INT,country VARCHAR,timestamp TIMESTAMP,sentiment FLOAT);
SELECT country, PERCENT_RANK() OVER (PARTITION BY country ORDER BY timestamp, sentiment) FROM creative_ai;
Which departments have a budget over $500,000?
CREATE TABLE CityBudget (BudgetID INT PRIMARY KEY,Department VARCHAR(50),BudgetAmount DECIMAL(10,2)); INSERT INTO CityBudget (BudgetID,Department,BudgetAmount) VALUES (1,'Public Works',250000.00),(2,'Education',750000.00),(3,'Parks and Recreation',150000.00),(4,'Police',600000.00),(5,'Fire',550000.00);
SELECT Department FROM CityBudget WHERE BudgetAmount > 500000.00;
What is the percentage of organic certified fish farms in the Gulf of Mexico in 2020?
CREATE TABLE fish_farms (farm_id INT,region VARCHAR(50),certification_status VARCHAR(50),year INT);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM fish_farms WHERE year = 2020)) as percentage FROM fish_farms WHERE region = 'Gulf of Mexico' AND certification_status = 'organic' AND year = 2020;
Find the maximum number of bikes available at any bike-share station in the city of Denver.
CREATE TABLE bikeshare (station_id INT,city VARCHAR(20),num_bikes INT); INSERT INTO bikeshare (station_id,city,num_bikes) VALUES (1,'Denver',30),(2,'Denver',20),(3,'Denver',40);
SELECT MAX(num_bikes) FROM bikeshare WHERE city = 'Denver';
Find the total number of transactions and trading volume for each developer and smart contract status ('active', 'inactive', or 'pending') in the 'smart_contracts' and 'decentralized_exchanges' tables, and display the results in ascending order by the total trading volume.
CREATE TABLE smart_contracts (contract_name VARCHAR(255),developer_id INT,contract_status VARCHAR(10)); CREATE TABLE decentralized_exchanges (exchange_name VARCHAR(255),developer_id INT,transaction_count INT,trading_volume DECIMAL(10,2));
SELECT s.contract_status, d.developer_name, SUM(de.transaction_count) as total_transactions, SUM(de.trading_volume) as total_volume FROM smart_contracts s INNER JOIN decentralized_exchanges de ON s.developer_id = de.developer_id INNER JOIN developers d ON s.developer_id = d.developer_id GROUP BY s.contract_status, d.de...
List all customers and their transaction amounts who have made a transaction over 100 in France.
CREATE TABLE transactions (customer_id INT,transaction_amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO transactions (customer_id,transaction_amount,country) VALUES (1,120.50,'France'),(2,75.30,'France'),(3,50.00,'France'),(4,150.00,'France');
SELECT customer_id, transaction_amount FROM transactions WHERE country = 'France' AND transaction_amount > 100;
Which athletes have the highest number of social media followers in the Eastern Conference?
CREATE TABLE athletes (id INT,name VARCHAR(50),team VARCHAR(50),conference VARCHAR(50),followers INT); INSERT INTO athletes (id,name,team,conference,followers) VALUES (1,'John Doe','TeamA','Eastern',500000),(2,'Jane Smith','TeamB','Eastern',700000),(3,'Mike Johnson','TeamC','Western',800000);
SELECT name, followers FROM athletes WHERE conference = 'Eastern' ORDER BY followers DESC LIMIT 1;
What is the average rating of artworks in the 'Fauvism' genre, excluding artworks with a rating of 0, and also show the total number of artworks in this genre.
CREATE TABLE Artwork (artwork_id INT,artwork_name VARCHAR(30),genre VARCHAR(20),rating INT);
SELECT AVG(Artwork.rating) AS avg_rating, COUNT(Artwork.artwork_id) AS total_artworks FROM Artwork WHERE Artwork.genre = 'Fauvism' AND Artwork.rating > 0;
Find the total number of military technologies that were discontinued before 2010.
CREATE TABLE MilitaryTechnologies (Tech VARCHAR(50),YearDiscontinued INT); INSERT INTO MilitaryTechnologies (Tech,YearDiscontinued) VALUES ('Landmines',2015),('Chemical Weapons',2016),('Biological Weapons',2017),('Cluster Bombs',2018),('Tactical Nuclear Weapons',2005);
SELECT COUNT(*) FROM MilitaryTechnologies WHERE YearDiscontinued < 2010;
List the clinical trials that have a start date on or after 2020-01-01 and their respective end dates.
CREATE TABLE clinical_trials_2(trial_name TEXT,start_date DATE,end_date DATE); INSERT INTO clinical_trials_2(trial_name,start_date,end_date) VALUES('Trial1','2019-05-01','2020-02-15'),('Trial2','2020-07-15','2021-06-30'),('Trial3','2021-01-01','2022-12-31'),('Trial4','2018-04-05','2019-09-30');
SELECT trial_name, end_date FROM clinical_trials_2 WHERE start_date >= '2020-01-01';
What is the total number of construction workers employed in the US and Canada, and how many of them are women?
CREATE TABLE workers (id INT,country VARCHAR(50),gender VARCHAR(10),is_construction_worker BOOLEAN); INSERT INTO workers (id,country,gender,is_construction_worker) VALUES (1,'USA','Male',true),(2,'Canada','Female',true),(3,'USA','Female',false),(4,'Canada','Male',true);
SELECT w.country, COUNT(w.id) as total_workers, SUM(CASE WHEN w.gender = 'Female' AND w.is_construction_worker = true THEN 1 ELSE 0 END) as female_construction_workers FROM workers w WHERE w.country IN ('USA', 'Canada') GROUP BY w.country;
What is the trend in energy consumption over time for solar projects?
CREATE TABLE project (id INT,name TEXT,date TEXT,project_type TEXT,energy_consumption FLOAT); INSERT INTO project (id,name,date,project_type,energy_consumption) VALUES (1,'Solar Farm','2020-01-01','Solar',2.5);
SELECT date, energy_consumption, ROW_NUMBER() OVER (ORDER BY date) AS rank FROM project WHERE project_type = 'Solar' ORDER BY date;
What is the total number of employees in pharmacies in Miami, FL?
CREATE TABLE pharmacies (id INT,name TEXT,city TEXT,state TEXT,num_employees INT,last_inspection_date DATE); INSERT INTO pharmacies (id,name,city,state,num_employees,last_inspection_date) VALUES (1,'CVS Pharmacy','Miami','FL',25,'2019-11-05'); INSERT INTO pharmacies (id,name,city,state,num_employees,last_inspection_dat...
SELECT SUM(num_employees) FROM pharmacies WHERE city = 'Miami' AND state = 'FL';
What is the total number of naval and air force personnel in the 'military_personnel' table?
CREATE TABLE military_personnel (id INT PRIMARY KEY,name VARCHAR(100),rank VARCHAR(50),department VARCHAR(50),num_personnel INT); INSERT INTO military_personnel (id,name,rank,department,num_personnel) VALUES (1,'Ali Ahmed','Captain','Navy',5000),(2,'Zara Ali','Colonel','Air Force',3000);
SELECT SUM(num_personnel) FROM military_personnel WHERE department IN ('Navy', 'Air Force');
What is the total number of farmers in each country who grow a specific crop?
CREATE TABLE farmers (id INT,name VARCHAR(100),crop VARCHAR(50),country VARCHAR(50)); INSERT INTO farmers (id,name,crop,country) VALUES (1,'Ali','wheat','Pakistan');
SELECT country, COUNT(*) FROM farmers WHERE crop = 'wheat' GROUP BY country
What is the total number of emergency incidents reported by each community policing center, broken down by incident type?
CREATE TABLE community_policing_centers (id INT,center_name TEXT); INSERT INTO community_policing_centers (id,center_name) VALUES (1,'Center A'),(2,'Center B'),(3,'Center C'); CREATE TABLE emergency_incidents (id INT,center_id INT,incident_type TEXT,incident_count INT); INSERT INTO emergency_incidents (id,center_id,inc...
SELECT center_id, incident_type, SUM(incident_count) AS total_incidents FROM emergency_incidents GROUP BY center_id, incident_type;
What is the maximum budget allocated to ethical AI projects in Asia?
CREATE TABLE ethical_ai_asia (budget INT); INSERT INTO ethical_ai_asia (budget) VALUES (50000),(60000),(70000);
SELECT MAX(budget) FROM ethical_ai_asia;
Which teams have the highest and lowest average ticket prices for regular seats?
CREATE TABLE Teams (TeamID INT,TeamName VARCHAR(50),AvgRegularTicketPrice DECIMAL(5,2));
SELECT TeamName FROM Teams WHERE AvgRegularTicketPrice = (SELECT MAX(AvgRegularTicketPrice) FROM Teams) OR AvgRegularTicketPrice = (SELECT MIN(AvgRegularTicketPrice) FROM Teams);
List all the marine species and their corresponding regions.
CREATE TABLE marine_species (id INT,species_name TEXT,region TEXT);INSERT INTO marine_species (id,species_name,region) VALUES (1,'Great White Shark','Pacific'),(2,'Blue Whale','Atlantic'),(3,'Giant Pacific Octopus','Pacific'),(4,'Green Sea Turtle','Atlantic');
SELECT species_name, region FROM marine_species;
How many esports events have been hosted in each continent?
CREATE TABLE esports_events (event_id INT,location VARCHAR(50),genre VARCHAR(50)); INSERT INTO esports_events (event_id,location,genre) VALUES (1,'Seoul,Korea','MOBA'),(2,'Beijing,China','FPS'),(3,'Tokyo,Japan','RTS'),(4,'Paris,France','MOBA'),(5,'New York,USA','FPS');
SELECT SUBSTRING(location, 1, INSTR(location, ',') - 1) AS continent, COUNT(*) AS num_events FROM esports_events GROUP BY continent;
List all startups that have had an investment round of at least $1,000,000 and have a founder from an underrepresented racial or ethnic group.
CREATE TABLE startup (id INT,name TEXT,founder_race TEXT); CREATE TABLE investment (startup_id INT,investment_amount INT); INSERT INTO startup (id,name,founder_race) VALUES (1,'Kappa Enterprises','African American'); INSERT INTO investment (startup_id,investment_amount) VALUES (1,1500000); INSERT INTO startup (id,name,...
SELECT s.name FROM startup s INNER JOIN investment i ON s.id = i.startup_id WHERE i.investment_amount >= 1000000 AND s.founder_race IN ('African American', 'Latinx', 'Native American', 'Pacific Islander');
Who are the top 3 contributors to algorithmic fairness research by number of publications?
CREATE TABLE Researchers (id INT,name VARCHAR(255),affiliation VARCHAR(255),publications INT); INSERT INTO Researchers (id,name,affiliation,publications) VALUES (1,'Alice','University of California,Berkeley',20),(2,'Bob','MIT',15),(3,'Charlie','Stanford University',30),(4,'David','Carnegie Mellon University',25),(5,'Ev...
SELECT name, affiliation, publications FROM (SELECT name, affiliation, publications, RANK() OVER (ORDER BY publications DESC) as rank FROM Researchers) subquery WHERE rank <= 3;
List the top 3 states with the highest claim amounts?
CREATE TABLE Claims (ClaimID int,PolicyID int,State varchar(50),ClaimAmount decimal(10,2)); INSERT INTO Claims (ClaimID,PolicyID,State,ClaimAmount) VALUES (1,1001,'California',4500.00),(2,1002,'Texas',3200.00),(3,1003,'California',5700.00),(4,1004,'New York',6100.00);
SELECT State, SUM(ClaimAmount) AS TotalClaimAmount FROM Claims GROUP BY State ORDER BY TotalClaimAmount DESC LIMIT 3
What is the average wingspan of aircraft manufactured by 'Bombardier'?
CREATE TABLE AircraftDimensions (Company VARCHAR(50),Model VARCHAR(50),Wingspan INT); INSERT INTO AircraftDimensions (Company,Model,Wingspan) VALUES ('Boeing','747',211),('Boeing','787 Dreamliner',197),('Airbus','A320',118),('Airbus','A380',262),('Bombardier','CRJ700',91);
SELECT AVG(Wingspan) FROM AircraftDimensions WHERE Company = 'Bombardier';
Calculate the total production cost for wells in the Gulf of Mexico
CREATE TABLE wells (id INT,location VARCHAR(20),cost FLOAT); INSERT INTO wells (id,location,cost) VALUES (1,'Gulf of Mexico',1000000.0),(2,'Alaska',1500000.0);
SELECT SUM(cost) FROM wells w WHERE w.location = 'Gulf of Mexico';
Update the address of donor with ID 3 to '123 Main St'?
CREATE TABLE donors (donor_id INT,donor_name TEXT,address TEXT); INSERT INTO donors (donor_id,donor_name,address) VALUES (1,'John Doe','456 Elm St'),(2,'Jane Smith','789 Oak Rd');
UPDATE donors SET address = '123 Main St' WHERE donor_id = 3;
What are the top 5 most purchased lipsticks by customers located in California, considering sales from the past 6 months?
CREATE TABLE sales (product_id INT,product_name TEXT,customer_location TEXT,purchase_date DATE); INSERT INTO sales (product_id,product_name,customer_location,purchase_date) VALUES (1,'Lipstick A','California','2021-06-01'),(2,'Lipstick B','California','2021-07-15'),(3,'Lipstick C','California','2021-08-05'),(4,'Lipstic...
SELECT product_name, COUNT(*) AS sales_count FROM sales WHERE customer_location = 'California' AND purchase_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE GROUP BY product_name ORDER BY sales_count DESC LIMIT 5;
List the unique wearable device types for members doing yoga.
CREATE TABLE Members (MemberID INT,Age INT,FavoriteExercise VARCHAR(20)); CREATE TABLE Wearables (DeviceID INT,MemberID INT,Type VARCHAR(20)); INSERT INTO Members (MemberID,Age,FavoriteExercise) VALUES (1,35,'Yoga'); INSERT INTO Members (MemberID,Age,FavoriteExercise) VALUES (2,28,'Running'); INSERT INTO Wearables (Dev...
SELECT DISTINCT Type FROM Members JOIN Wearables ON Members.MemberID = Wearables.MemberID WHERE FavoriteExercise = 'Yoga';
What is the average budget for disability services initiatives per year?
CREATE TABLE budgets (budget_id INT,budget_year INT,budget_amount DECIMAL(10,2));
SELECT AVG(budget_amount) FROM budgets WHERE budget_category = 'Disability Services';
Insert a new record for a donation of $500 made by a corporate donor named "ABC Corp" on March 15, 2022.
CREATE TABLE donations (id INT,donor_id INT,donation_date DATE,amount_donated DECIMAL(10,2)); CREATE TABLE donors (id INT,name TEXT,donor_type TEXT);
INSERT INTO donations (id, donor_id, donation_date, amount_donated) VALUES (1, (SELECT id FROM donors WHERE name = 'ABC Corp' AND donor_type = 'Corporate' LIMIT 1), '2022-03-15', 500); INSERT INTO donors (id, name, donor_type) VALUES (1, 'ABC Corp', 'Corporate') ON DUPLICATE KEY UPDATE id = id;
Show ocean temperatures for locations with high coral bleaching risk.
CREATE TABLE ocean_temperature (id INT PRIMARY KEY,location VARCHAR(255),temperature FLOAT,month DATE); INSERT INTO ocean_temperature (id,location,temperature,month) VALUES (1,'Great_Barrier_Reef',28.5,'2022-04-01');
SELECT location, temperature FROM ocean_temperature WHERE location IN ('Great_Barrier_Reef', 'Coral_Triangle');
Identify the top 5 threat actors by the number of security incidents they have been involved in, during the current year, both internal and external incidents.
CREATE TABLE security_incidents (threat_actor VARCHAR(50),is_internal BOOLEAN,incident_year INTEGER); INSERT INTO security_incidents (threat_actor,is_internal,incident_year) VALUES ('APT28',true,2022); INSERT INTO security_incidents (threat_actor,is_internal,incident_year) VALUES ('Lazarus Group',false,2022);
SELECT threat_actor, COUNT(*) AS incident_count FROM security_incidents WHERE incident_year = EXTRACT(YEAR FROM NOW()) GROUP BY threat_actor ORDER BY incident_count DESC LIMIT 5
What was the total number of open data initiatives in the world in 2017?
CREATE TABLE world_countries (id INT PRIMARY KEY,country VARCHAR(20)); INSERT INTO world_countries (id,country) VALUES (1,'France'); INSERT INTO world_countries (id,country) VALUES (2,'Germany'); INSERT INTO open_data (id,country,year,num_initiatives) VALUES (1,'France',2017,25); INSERT INTO open_data (id,country,year,...
SELECT SUM(num_initiatives) FROM open_data INNER JOIN world_countries ON open_data.country = world_countries.country WHERE open_data.year = 2017;
What is the average number of virtual tours per hotel in Germany?
CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,date DATE); INSERT INTO virtual_tours (tour_id,hotel_id,date) VALUES (1,4,'2022-02-15'),(2,4,'2022-02-17'),(3,5,'2022-03-01'),(4,5,'2022-03-05'); CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT); INSERT INTO hotels (hotel_id,hotel_name,country) VALUES ...
SELECT AVG(vt.count) FROM (SELECT hotel_id, COUNT(*) as count FROM virtual_tours GROUP BY hotel_id) as vt INNER JOIN hotels h ON vt.hotel_id = h.hotel_id WHERE h.country = 'Germany';
What is the average mental health score for students in each school that has more than 2 grade levels?
CREATE TABLE student_mental_health (student_id INT,school_id INT,grade_level INT,score INT); INSERT INTO student_mental_health (student_id,school_id,grade_level,score) VALUES (1,100,6,80),(2,100,6,75),(3,200,7,90),(4,200,7,85),(5,300,8,70);
SELECT school_id, AVG(score) as avg_score FROM student_mental_health GROUP BY school_id HAVING COUNT(DISTINCT grade_level) > 2;
Find the average age of all elephants in African conservation programs
CREATE TABLE african_conservation_programs (id INT,program_name VARCHAR(255),region VARCHAR(255)); INSERT INTO african_conservation_programs (id,program_name,region) VALUES (1,'Samburu National Reserve','Kenya'),(2,'Garamba National Park','DRC'); CREATE TABLE elephants (id INT,name VARCHAR(255),age INT,conservation_pro...
SELECT AVG(elephants.age) FROM elephants INNER JOIN african_conservation_programs ON elephants.conservation_program_id = african_conservation_programs.id WHERE african_conservation_programs.region = 'Africa';
What is the total budget allocated for education in Canada?
CREATE TABLE budgets (id INT,category TEXT,amount FLOAT,country TEXT); INSERT INTO budgets (id,category,amount,country) VALUES (1,'education',20000000,'Canada');
SELECT SUM(budgets.amount) FROM budgets WHERE budgets.category = 'education' AND budgets.country = 'Canada';
What is the total revenue of all products sold by suppliers in 'California'?
CREATE TABLE Suppliers (SupplierID int,SupplierName varchar(50),Address varchar(100),Country varchar(50)); INSERT INTO Suppliers VALUES (1,'Supplier1','123 Main St,California','USA'); INSERT INTO Suppliers VALUES (2,'Supplier2','456 Oak St,New York','USA'); CREATE TABLE Products (ProductID int,ProductName varchar(50),S...
SELECT SUM(Products.Revenue) FROM Products INNER JOIN Suppliers ON Products.SupplierID = Suppliers.SupplierID WHERE Suppliers.Country = 'USA' AND Suppliers.State = 'California';
How many food safety inspection violations occurred in each borough of New York City in 2020, and what was the total fine amount per borough?
CREATE TABLE nyc_inspections (inspection_id INT,borough VARCHAR(20),violation_date DATE,fine_amount INT);
SELECT borough, COUNT(*) as violation_count, SUM(fine_amount) as total_fine FROM nyc_inspections WHERE violation_date >= '2020-01-01' AND violation_date < '2021-01-01' GROUP BY borough;
Decrease sales of 'DrugG' by 20% in Q1 2021.
CREATE TABLE sales_2 (drug_name TEXT,qty_sold INTEGER,sale_date DATE); INSERT INTO sales_2 (drug_name,qty_sold,sale_date) VALUES ('DrugG',400,'2021-01-01'),('DrugG',450,'2021-02-01'),('DrugG',500,'2021-03-01');
UPDATE sales_2 SET qty_sold = FLOOR(qty_sold * 0.80) WHERE drug_name = 'DrugG' AND sale_date BETWEEN '2021-01-01' AND '2021-03-31';
What is the average age of fans for each team?
CREATE TABLE teams (team_id INT,team_name VARCHAR(255)); INSERT INTO teams (team_id,team_name) VALUES (1,'Atlanta Hawks'),(2,'Boston Celtics'); CREATE TABLE fan_demographics (fan_id INT,team_id INT,age INT); INSERT INTO fan_demographics (fan_id,team_id,age) VALUES (1,1,35),(2,1,45),(3,2,25),(4,2,30);
SELECT t.team_name, AVG(fd.age) as avg_age FROM teams t INNER JOIN fan_demographics fd ON t.team_id = fd.team_id GROUP BY t.team_name;
What is the percentage of uninsured individuals in Canada and Mexico?
CREATE TABLE healthcare_access (country VARCHAR(20),uninsured_percentage DECIMAL(5,2)); INSERT INTO healthcare_access (country,uninsured_percentage) VALUES ('Canada',5.0),('Mexico',40.0);
SELECT AVG(uninsured_percentage) FROM healthcare_access WHERE country IN ('Canada', 'Mexico');