instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many visitors engaged with digital installations in Tokyo and New York?'
CREATE TABLE Digital_Engagement (id INT,city VARCHAR(20),num_visitors INT); INSERT INTO Digital_Engagement (id,city,num_visitors) VALUES (1,'Tokyo',1500),(2,'Tokyo',2000),(3,'New York',3000);
SELECT SUM(num_visitors) FROM Digital_Engagement WHERE city IN ('Tokyo', 'New York');
How many charging stations are there in 'California' and 'Texas' in the charging_stations table?
CREATE TABLE charging_stations (id INT,state TEXT,station_type TEXT,total_stations INT); INSERT INTO charging_stations (id,state,station_type,total_stations) VALUES (1,'California','Fast',50),(2,'Texas','Standard',40),(3,'California','Standard',60);
SELECT state, COUNT(*) as total_charging_stations FROM charging_stations WHERE state IN ('California', 'Texas') GROUP BY state;
What are the top 5 strains sold in dispensaries in California, ordered by sales quantity?
CREATE TABLE Strains (strain_id INT,strain_name TEXT,state TEXT,sales_quantity INT); INSERT INTO Strains (strain_id,strain_name,state,sales_quantity) VALUES (1,'Blue Dream','California',500),(2,'Girl Scout Cookies','California',400),(3,'Durban Poison','California',300),(4,'OG Kush','California',250),(5,'Sour Diesel','California',200);
SELECT strain_name, SUM(sales_quantity) as total_sales FROM Strains WHERE state = 'California' GROUP BY strain_name ORDER BY total_sales DESC LIMIT 5;
What is the maximum size of a protected habitat for each animal type?
CREATE TABLE Protected_Habitats (id INT,animal_type VARCHAR(50),size INT);
SELECT animal_type, MAX(size) FROM Protected_Habitats GROUP BY animal_type;
What is the total cost of concrete and steel materials used in public works projects?
CREATE TABLE material_costs (id INT,material_type VARCHAR(255),project_type VARCHAR(255),cost FLOAT); INSERT INTO material_costs (id,material_type,project_type,cost) VALUES (1,'Steel','Bridge',150000.00),(2,'Asphalt','Road',50000.00),(3,'Concrete','Building',200000.00),(4,'Steel','Building',300000.00);
SELECT SUM(cost) as total_cost FROM material_costs WHERE material_type IN ('Concrete', 'Steel');
What is the average age of patients who did not improve after therapy sessions?
CREATE TABLE patients_no_improvement (patient_id INT,age INT,improvement CHAR(1)); INSERT INTO patients_no_improvement (patient_id,age,improvement) VALUES (1,30,'N'),(2,25,'N'),(3,45,'N');
SELECT AVG(age) as avg_age_no_improvement FROM patients_no_improvement WHERE improvement = 'N';
How many public parks were renovated each year from 2018 to 2021?
CREATE TABLE Parks (Year INT,Action TEXT); INSERT INTO Parks (Year,Action) VALUES (2018,'Renovated'),(2019,'Renovated'),(2020,'Renovated'),(2021,'Renovated');
SELECT Year, COUNT(*) FROM Parks WHERE Action = 'Renovated' GROUP BY Year;
What is the average population of all shark species in the Atlantic Ocean?
CREATE TABLE shark_species (species_name TEXT,population INTEGER,ocean TEXT);
SELECT AVG(population) FROM shark_species WHERE ocean = 'Atlantic Ocean';
Identify the number of socially responsible lending institutions in Country Y
CREATE TABLE srl_institutions (id INT PRIMARY KEY,institution_name VARCHAR(100),country VARCHAR(50)); INSERT INTO srl_institutions (id,institution_name,country) VALUES (1,'Institution A','Country X'),(2,'Institution B','Country Y'),(3,'Institution C','Country Z');
SELECT COUNT(*) FROM srl_institutions WHERE country = 'Country Y';
What is the total number of refugees assisted by each organization in Asia in 2019?
CREATE TABLE refugees (id INT,organization VARCHAR(255),location VARCHAR(255),assist_date DATE,gender VARCHAR(10),age INT); INSERT INTO refugees (id,organization,location,assist_date,gender,age) VALUES (1,'UNHCR','Asia','2019-02-12','Female',34),(2,'Red Cross','Asia','2019-04-01','Male',27),(3,'Save the Children','Asia','2019-03-21','Female',19),(4,'World Vision','Asia','2019-05-05','Male',45);
SELECT organization, COUNT(*) as total_refugees FROM refugees WHERE location = 'Asia' AND YEAR(assist_date) = 2019 GROUP BY organization;
What is the average word count of articles by gender and region in 'news_articles' table?
CREATE TABLE news_articles (id INT,title VARCHAR(100),publication_date DATE,author VARCHAR(50),word_count INT,gender VARCHAR(10),region VARCHAR(50)); INSERT INTO news_articles (id,title,publication_date,author,word_count,gender,region) VALUES (1,'Article 1','2022-01-01','John Doe',500,'Male','North America'),(2,'Article 2','2022-01-02','Jane Smith',700,'Female','Europe');
SELECT gender, region, AVG(word_count) as avg_word_count FROM news_articles GROUP BY gender, region;
Which artifact categories were most frequently excavated in Egypt?
CREATE TABLE excavation_sites (site_id INT,site_name VARCHAR(50),country VARCHAR(50)); INSERT INTO excavation_sites (site_id,site_name,country) VALUES (1,'Site A','Egypt'); CREATE TABLE artifacts (artifact_id INT,site_id INT,category VARCHAR(50));
SELECT a.category, COUNT(*) as frequency FROM excavation_sites e JOIN artifacts a ON e.site_id = a.site_id WHERE e.country = 'Egypt' GROUP BY a.category ORDER BY frequency DESC;
Calculate the number of diversity metrics recorded
CREATE TABLE diversity_metrics (id INT PRIMARY KEY,startup_id INT,gender VARCHAR(10),underrepresented_group BOOLEAN);
SELECT COUNT(*) FROM diversity_metrics;
Which satellites were deployed by both SpaceTech Inc. and Orbital Inc.?
CREATE TABLE Satellites (satellite_id INT,name VARCHAR(50),launch_date DATE,manufacturer VARCHAR(50)); INSERT INTO Satellites (satellite_id,name,launch_date,manufacturer) VALUES (1,'Sat1','2020-01-01','SpaceTech Inc.'),(2,'Sat2','2019-05-15','Orbital Inc.'),(3,'Sat3','2021-03-27','SpaceTech Inc.'),(4,'Sat4','2018-12-12','Orbital Inc.');
SELECT name FROM Satellites WHERE manufacturer IN ('SpaceTech Inc.', 'Orbital Inc.') GROUP BY name HAVING COUNT(DISTINCT manufacturer) = 2;
List all suppliers, products, and sales quantities for suppliers based in 'India' that use sustainable practices.
CREATE TABLE suppliers (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),sustainable_practices BOOLEAN); CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),supplier_id INT,FOREIGN KEY (supplier_id) REFERENCES suppliers(id)); CREATE TABLE sales (id INT PRIMARY KEY,product_id INT,quantity INT,FOREIGN KEY (product_id) REFERENCES products(id));
SELECT s.name AS supplier_name, p.name AS product_name, sales.quantity FROM sales JOIN products ON sales.product_id = products.id JOIN suppliers ON products.supplier_id = suppliers.id WHERE suppliers.location = 'India' AND suppliers.sustainable_practices = TRUE;
What is the total budget allocated to policy advocacy efforts in 2022?
CREATE TABLE Budget (Id INT,Category VARCHAR(50),Amount DECIMAL(10,2),Year INT); INSERT INTO Budget (Id,Category,Amount,Year) VALUES (1,'Policy Advocacy',50000,2022);
SELECT SUM(Amount) FROM Budget WHERE Category = 'Policy Advocacy' AND Year = 2022;
What is the total number of high severity vulnerabilities found in the last month?
CREATE TABLE Vulnerabilities (id INT,report_date DATE,severity INT); INSERT INTO Vulnerabilities (id,report_date,severity) VALUES (1,'2022-04-01',3),(2,'2022-04-15',5),(3,'2022-05-01',7);
SELECT COUNT(*) FROM Vulnerabilities WHERE severity >= 5 AND report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
How many male and female beneficiaries are there in each country?
CREATE TABLE Beneficiaries (id INT,name VARCHAR(50),gender VARCHAR(50),age INT,country VARCHAR(50),registration_date DATE); INSERT INTO Beneficiaries (id,name,gender,age,country,registration_date) VALUES (1,'Ahmed','Male',25,'Egypt','2020-12-12'),(2,'Bella','Female',35,'Nigeria','2021-01-01'),(3,'Charlie','Male',45,'Mexico','2022-03-03');
SELECT country, gender, COUNT(*) as count FROM Beneficiaries GROUP BY country, gender;
Find the top 3 cities with the highest number of connected devices and the total number of connected devices in each city.
CREATE TABLE network_towers (tower_id INT,city VARCHAR(50),connected_devices INT); INSERT INTO network_towers VALUES (1,'CityA',50),(2,'CityB',60),(3,'CityC',70);
SELECT city, SUM(connected_devices) as total_connected_devices FROM (SELECT city, connected_devices, RANK() OVER(PARTITION BY city ORDER BY connected_devices DESC) as rank FROM network_towers) ranked_towers WHERE rank <= 3 GROUP BY city;
What are the average prices for sculptures and paintings in the modern art market?
CREATE TABLE art_categories (id INT,category TEXT); INSERT INTO art_categories (id,category) VALUES (1,'Sculpture'),(2,'Painting'); CREATE TABLE art_market (id INT,title TEXT,category_id INT,price INT); INSERT INTO art_market (id,title,category_id,price) VALUES (1,'The Persistence of Memory',2,20000000),(2,'Bird in Space',1,27500000);
SELECT AVG(price) as avg_price, category FROM art_market am INNER JOIN art_categories ac ON am.category_id = ac.id WHERE ac.category IN ('Sculpture', 'Painting') GROUP BY category;
What is the average price of items manufactured by factories in 'Asia' and 'Europe'?
CREATE TABLE Factories (FactoryID int,FactoryName varchar(50),Address varchar(100),Country varchar(50)); INSERT INTO Factories VALUES (1,'Factory1','123 Main St,China','China'); INSERT INTO Factories VALUES (2,'Factory2','456 Oak St,Germany','Germany'); INSERT INTO Factories VALUES (3,'Factory3','789 Elm St,India','India'); CREATE TABLE Products (ProductID int,ProductName varchar(50),FactoryID int,Price int); INSERT INTO Products VALUES (1,'Product1',1,50); INSERT INTO Products VALUES (2,'Product2',2,100); INSERT INTO Products VALUES (3,'Product3',3,150); INSERT INTO Products VALUES (4,'Product4',1,55); INSERT INTO Products VALUES (5,'Product5',3,145);
SELECT AVG(Products.Price) FROM Products INNER JOIN Factories ON Products.FactoryID = Factories.FactoryID WHERE Factories.Country = 'China' OR Factories.Country = 'Germany' OR Factories.Country = 'India';
What is the total revenue for each product category in the current year?
CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,revenue INT); INSERT INTO sales (sale_id,product_id,sale_date,revenue) VALUES (1,1,'2022-01-01',1000),(2,2,'2022-01-02',500),(3,1,'2022-01-03',1500);
SELECT p.category, SUM(s.revenue) FROM sales s INNER JOIN products p ON s.product_id = p.product_id WHERE YEAR(s.sale_date) = YEAR(GETDATE()) GROUP BY p.category;
What are the top 3 states with the highest water conservation initiative scores in 2020?
CREATE TABLE Water_Conservation_Initiatives (State VARCHAR(20),Year INT,Score INT); INSERT INTO Water_Conservation_Initiatives (State,Year,Score) VALUES ('California',2020,85),('Texas',2020,78),('Florida',2020,82);
SELECT State, MAX(Score) FROM Water_Conservation_Initiatives WHERE Year = 2020 GROUP BY State ORDER BY Score DESC LIMIT 3;
What is the count of packages in 'received' status at each warehouse?
CREATE TABLE Warehouse (id INT,name VARCHAR(20),city VARCHAR(20)); INSERT INTO Warehouse (id,name,city) VALUES (1,'Seattle Warehouse','Seattle'),(2,'NYC Warehouse','NYC'),(3,'Chicago Warehouse','Chicago'); CREATE TABLE Packages (id INT,warehouse_id INT,status VARCHAR(20)); INSERT INTO Packages (id,warehouse_id,status) VALUES (1,1,'received'),(2,1,'processing'),(3,2,'received'),(4,2,'received'),(5,3,'processing');
SELECT warehouse_id, COUNT(*) FROM Packages WHERE status = 'received' GROUP BY warehouse_id;
Get unique equipment types sold in 'Africa' with sales data
CREATE TABLE equipment_sales (eq_id INT,eq_type VARCHAR(50),sale_amount INT); INSERT INTO equipment_sales (eq_id,eq_type,sale_amount) VALUES (1,'M1 Abrams',5000000);
SELECT DISTINCT eq_type, SUM(sale_amount) AS total_sales_amount FROM equipment_sales es JOIN equipment e ON es.eq_id = e.eq_id WHERE e.region = 'Africa' GROUP BY eq_type;
How many donations have been made by each donor, in descending order?
CREATE TABLE Donations (DonationID int,DonorID int,DonationDate date,DonationAmount numeric); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationAmount) VALUES (1,1,'2022-01-01',500),(2,1,'2022-02-01',300),(3,2,'2022-03-01',800),(4,2,'2022-04-01',900),(5,3,'2022-05-01',700);
SELECT DonorID, COUNT(DonationID) NumDonations, RANK() OVER (ORDER BY COUNT(DonationID) DESC) DonorRank FROM Donations GROUP BY DonorID;
What is the maximum donation amount from donors in Mexico?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL(10,2),Country TEXT);
SELECT MAX(DonationAmount) FROM Donors WHERE Country = 'Mexico';
Show startups with no diversity metrics records.
CREATE TABLE diversity_metrics3 (metric_id INT,company_id INT,diverse_founder BOOLEAN); INSERT INTO diversity_metrics3 (metric_id,company_id,diverse_founder) VALUES (1,1,TRUE),(2,2,FALSE),(3,3,TRUE),(4,4,FALSE); CREATE TABLE company_founding2 (company_id INT,founding_year INT); INSERT INTO company_founding2 (company_id,founding_year) VALUES (1,2015),(2,2016),(3,2015),(5,2017);
SELECT company_id FROM company_founding2 WHERE company_id NOT IN (SELECT company_id FROM diversity_metrics3);
What is the minimum and maximum dissolved oxygen level in marine water farms?
CREATE TABLE water_quality (farm_id INT,water_type VARCHAR(10),dissolved_oxygen FLOAT); INSERT INTO water_quality VALUES (1,'Marine',6.5),(2,'Marine',7.0),(3,'Brackish',5.5),(4,'Freshwater',8.0);
SELECT MIN(dissolved_oxygen) AS 'Minimum Dissolved Oxygen', MAX(dissolved_oxygen) AS 'Maximum Dissolved Oxygen' FROM water_quality WHERE water_type = 'Marine';
Which countries have the highest and lowest number of flight accidents in the last 5 years?
CREATE TABLE flight_safety (id INT,country VARCHAR(255),accident_date DATE,accident_type VARCHAR(255));
SELECT country, COUNT(*) as num_accidents FROM flight_safety WHERE accident_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 5 YEAR) GROUP BY country ORDER BY num_accidents DESC;
What is the total funding amount for companies founded by veterans in the Fintech industry?
CREATE TABLE Companies (id INT,name VARCHAR(50),industry VARCHAR(50),country VARCHAR(50),founding_year INT,founder_veteran VARCHAR(10)); CREATE TABLE Funding (id INT,company_name VARCHAR(50),funding_amount INT); INSERT INTO Companies (id,name,industry,country,founding_year,founder_veteran) VALUES (1,'PayVets','Fintech','USA',2017,'Yes'); INSERT INTO Funding (id,company_name,funding_amount) VALUES (1,'PayVets',5000000);
SELECT SUM(funding_amount) as total_funding FROM Funding INNER JOIN Companies ON Funding.company_name = Companies.name WHERE Companies.industry = 'Fintech' AND Companies.founder_veteran = 'Yes';
What was the average REE production per mine in 2018?
CREATE TABLE mines (id INT,name TEXT,location TEXT,annual_production INT); INSERT INTO mines (id,name,location,annual_production) VALUES (1,'Mine A','Country X',1500),(2,'Mine B','Country Y',2000),(3,'Mine C','Country Z',1750);
SELECT AVG(annual_production) as avg_production FROM mines WHERE YEAR(timestamp) = 2018;
What is the number of policies and total claim amount by agent and month?
CREATE TABLE AgentClaims (ClaimID INT,PolicyID INT,ClaimAmount DECIMAL(10,2),ClaimDate DATE,AgentID INT); INSERT INTO AgentClaims VALUES (1,1,500,'2021-01-05',1),(2,2,1000,'2022-02-10',2),(3,3,750,'2021-03-15',1),(4,4,1200,'2022-01-25',2),(5,5,300,'2021-02-01',3),(6,6,1500,'2022-03-01',3); CREATE TABLE AgentSales (SaleID INT,AgentID INT,PolicyID INT,SaleYear INT,SaleMonth INT); INSERT INTO AgentSales VALUES (1,1,1,2021,1),(2,2,2,2022,2),(3,1,3,2021,3),(4,2,4,2022,1),(5,3,5,2021,2),(6,3,6,2022,3);
SELECT a.AgentID, EXTRACT(MONTH FROM ac.ClaimDate) AS Month, COUNT(DISTINCT ac.PolicyID) AS Policies, SUM(ac.ClaimAmount) AS TotalClaimAmount FROM AgentClaims AS ac JOIN AgentSales AS asa ON ac.PolicyID = asa.PolicyID JOIN Agents AS a ON asa.AgentID = a.AgentID GROUP BY a.AgentID, Month;
What is the average annual CO2 emissions reduction achieved by climate mitigation initiatives in Southeast Asia?
CREATE TABLE co2_emissions_reduction (initiative_id INT,initiative_name VARCHAR(50),region VARCHAR(50),year_started INT,co2_emissions_reduction DECIMAL(5,2)); INSERT INTO co2_emissions_reduction (initiative_id,initiative_name,region,year_started,co2_emissions_reduction) VALUES (1,'Green Energy Transition','Southeast Asia',2015,7.50),(2,'Energy Efficiency','Southeast Asia',2016,8.25),(3,'Carbon Pricing','Southeast Asia',2017,9.00);
SELECT AVG(co2_emissions_reduction) FROM co2_emissions_reduction WHERE region = 'Southeast Asia';
Add a new biotech startup in the USA
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),funding FLOAT);
INSERT INTO biotech.startups (id, name, location, funding) VALUES (4, 'StartupD', 'USA', 8000000);
List all transactions with a value greater than $15,000, along with the customer ID and the transaction date, in descending order of transaction date for customers in Latin America?
CREATE TABLE customer_transactions (transaction_id INT,customer_id INT,transaction_value DECIMAL(10,2),transaction_date DATE,customer_region VARCHAR(20)); INSERT INTO customer_transactions (transaction_id,customer_id,transaction_value,transaction_date,customer_region) VALUES (1,1,20000,'2021-08-01','Latin America'),(2,2,35000,'2021-07-15','North America'),(3,3,12000,'2021-06-05','Latin America');
SELECT * FROM customer_transactions WHERE transaction_value > 15000 AND customer_region = 'Latin America' ORDER BY transaction_date DESC;
Which cybersecurity strategies were implemented in 'Country2' in the CYBER_STRATEGIES table?
CREATE TABLE CYBER_STRATEGIES (id INT PRIMARY KEY,country VARCHAR(255),strategy VARCHAR(255),year INT);
SELECT strategy FROM CYBER_STRATEGIES WHERE country = 'Country2' AND year = (SELECT MAX(year) FROM CYBER_STRATEGIES WHERE country = 'Country2');
How many mental health facilities of each type are there in the mental_health_facilities table?
CREATE TABLE mental_health_facilities (facility_id INT,name VARCHAR(50),type VARCHAR(50),state VARCHAR(50)); INSERT INTO mental_health_facilities (facility_id,name,type,state) VALUES (1,'Example Facility 1','Inpatient','California'); INSERT INTO mental_health_facilities (facility_id,name,type,state) VALUES (2,'Example Facility 2','Outpatient','New York'); INSERT INTO mental_health_facilities (facility_id,name,type,state) VALUES (3,'Example Facility 3','Partial Hospitalization','Texas');
SELECT type, COUNT(*) FROM mental_health_facilities GROUP BY type;
What was the total revenue for the state of New York in the third quarter of 2022?
CREATE TABLE sales (id INT,state VARCHAR(50),month VARCHAR(50),revenue FLOAT); INSERT INTO sales (id,state,month,revenue) VALUES (1,'New York','July',50000.0),(2,'New York','August',60000.0),(3,'New York','September',70000.0);
SELECT SUM(revenue) FROM sales WHERE state = 'New York' AND (month = 'July' OR month = 'August' OR month = 'September');
What is the average response time for emergency incidents in the city of Los Angeles, categorized by incident type?
CREATE TABLE emergency_responses (id INT,incident_id INT,response_time INT); CREATE TABLE emergency_incidents (id INT,incident_type VARCHAR(255),report_date DATE); INSERT INTO emergency_incidents (id,incident_type,report_date) VALUES (1,'Medical Emergency','2022-01-01'),(2,'Fire','2022-01-02'); INSERT INTO emergency_responses (id,incident_id,response_time) VALUES (1,1,10),(2,1,12),(3,2,20);
SELECT incident_type, AVG(response_time) FROM emergency_responses JOIN emergency_incidents ON emergency_responses.incident_id = emergency_incidents.id GROUP BY incident_type;
Delete records from the 'cosmetics_sales' table where the 'units_sold' is less than 10
CREATE TABLE cosmetics_sales (product_id INT,product_name VARCHAR(255),units_sold INT,revenue DECIMAL(10,2),sale_date DATE);
DELETE FROM cosmetics_sales WHERE units_sold < 10;
What is the maximum budget for technology projects in Europe?
CREATE TABLE Tech_Projects (ID INT,Project_Name VARCHAR(100),Location VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO Tech_Projects (ID,Project_Name,Location,Budget) VALUES (1,'Tech4All','Europe',150000.00),(2,'AI4Good','Asia',200000.00),(3,'EqualWeb','Europe',180000.00);
SELECT MAX(Budget) FROM Tech_Projects WHERE Location = 'Europe';
What is the number of fish farms in the Arctic Ocean that have been impacted by climate change since 2018?
CREATE TABLE fish_farms (farm_id INT,temperature FLOAT,year INT,region VARCHAR(255),PRIMARY KEY (farm_id,temperature,year)); INSERT INTO fish_farms (farm_id,temperature,year,region) VALUES (1,2.5,2018,'Arctic Ocean'),(2,3.0,2019,'Arctic Ocean'),(3,3.5,2020,'Arctic Ocean');
SELECT COUNT(*) FROM fish_farms WHERE temperature > (SELECT AVG(temperature) FROM fish_farms WHERE year < 2018 AND region = 'Arctic Ocean') AND region = 'Arctic Ocean';
What is the earliest launch date for each country that has launched a space mission?
CREATE TABLE space_missions (mission_id INT,mission_name VARCHAR(255),launch_country VARCHAR(50),launch_date DATE); INSERT INTO space_missions (mission_id,mission_name,launch_country,launch_date) VALUES (1,'Apollo 11','USA','1969-07-16'),(2,'Sputnik 1','Russia','1957-10-04');
SELECT launch_country, MIN(launch_date) FROM space_missions GROUP BY launch_country;
Which artist has the highest number of concert appearances in 2021?
CREATE TABLE ArtistConcertCount (ArtistID INT,AppearanceCount INT);
SELECT A.Name, ACC.AppearanceCount FROM ArtistConcertCount ACC INNER JOIN Artists A ON ACC.ArtistID = A.ArtistID WHERE YEAR(C.Date) = 2021 GROUP BY A.Name ORDER BY ACC.AppearanceCount DESC LIMIT 1;
Update the public transportation route with ID 402 to include a new stop
CREATE TABLE public_transportation_routes (route_id INT,route_name TEXT,stop_sequence INT,stop_id INT,city TEXT,country TEXT);
UPDATE public_transportation_routes SET stop_id = 803 WHERE route_id = 402 AND stop_sequence = 5;
Add a new diversity metric record into the "diversity_metrics" table
CREATE TABLE diversity_metrics (id INT,gender VARCHAR(10),race VARCHAR(30),department VARCHAR(50),total_count INT,hiring_rate DECIMAL(5,2));
INSERT INTO diversity_metrics (id, gender, race, department, total_count, hiring_rate) VALUES (2001, 'Female', 'Hispanic', 'Marketing', 3, 0.75);
Identify the top 3 most common types of threats and their frequency in the last 3 months, for a specific organization 'Org123'?
CREATE TABLE threats (threat_type VARCHAR(255),organization VARCHAR(255),date DATE); INSERT INTO threats (threat_type,organization,date) VALUES ('Phishing','Org123','2022-01-01'),('Malware','Org123','2022-01-05'),('Ransomware','Org123','2022-01-10'),('Phishing','Org123','2022-02-01'),('Phishing','Org123','2022-02-15'),('Malware','Org123','2022-03-01');
SELECT threat_type, COUNT(threat_type) as frequency FROM threats WHERE organization = 'Org123' AND date >= DATEADD(month, -3, GETDATE()) GROUP BY threat_type ORDER BY frequency DESC LIMIT 3;
How many policy advocacy initiatives were launched per year?
CREATE TABLE Advocacy (AdvocacyID INT,InitiativeName VARCHAR(50),LaunchDate DATE); INSERT INTO Advocacy (AdvocacyID,InitiativeName,LaunchDate) VALUES (1,'Inclusive Education','2018-05-05'),(2,'Employment Equity','2019-08-28'),(3,'Accessible Transportation','2018-12-12'),(4,'Digital Accessibility','2020-01-20'),(5,'Healthcare Equality','2021-02-14');
SELECT EXTRACT(YEAR FROM LaunchDate) as Year, COUNT(*) as InitiativeCount FROM Advocacy GROUP BY Year;
What is the total cost of sustainable building projects in Texas?
CREATE TABLE Sustainable_Projects (project_id INT,project_name VARCHAR(50),state VARCHAR(2),cost FLOAT); INSERT INTO Sustainable_Projects VALUES (1,'Greenville Library','TX',5000000);
SELECT SUM(cost) FROM Sustainable_Projects WHERE state = 'TX';
Delete paintings from artist 'Pablo Picasso' in 'Artwork' table.
CREATE TABLE Artists (id INT,name TEXT); INSERT INTO Artists (id,name) VALUES (1,'Pablo Picasso'); CREATE TABLE Artwork (id INT,title TEXT,artist_id INT); INSERT INTO Artwork (id,title,artist_id) VALUES (1,'Guernica',1),(2,'Three Musicians',1);
DELETE FROM Artwork WHERE artist_id = (SELECT id FROM Artists WHERE name = 'Pablo Picasso');
What is the average donation amount per donor in the Asia-Pacific region, excluding the top 10 donors?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Region TEXT,DonationAmount DECIMAL(10,2)); INSERT INTO Donors VALUES (1,'John Smith','Asia-Pacific',500.00),(2,'Jane Doe','Americas',300.00),(3,'Mary Major','Asia-Pacific',750.00);
SELECT AVG(DonationAmount) FROM (SELECT DonationAmount, ROW_NUMBER() OVER (PARTITION BY Region ORDER BY DonationAmount DESC) as rn FROM Donors WHERE Region = 'Asia-Pacific') tmp WHERE rn > 10;
What are the regulatory frameworks in place for decentralized applications in India?
CREATE TABLE regulatory_frameworks (framework_id INT PRIMARY KEY,framework_name VARCHAR(50),country VARCHAR(50)); INSERT INTO regulatory_frameworks (framework_id,framework_name,country) VALUES (1,'Framework1','USA'); INSERT INTO regulatory_frameworks (framework_id,framework_name,country) VALUES (2,'Framework2','China');
SELECT framework_name FROM regulatory_frameworks WHERE country = 'India';
List all aircraft models manufactured by AeroTech in South America with a manufacturing date on or after 2015-01-01.
CREATE TABLE AircraftManufacturing (aircraft_id INT,model VARCHAR(255),manufacturer VARCHAR(255),manufacturing_date DATE,country VARCHAR(255));
SELECT model FROM AircraftManufacturing WHERE manufacturer = 'AeroTech' AND manufacturing_date >= '2015-01-01' AND country = 'South America';
What is the total sales amount for each sales representative, ordered by total sales in descending order?
CREATE TABLE sales_representatives (id INT,name TEXT,region TEXT,sales FLOAT); INSERT INTO sales_representatives (id,name,region,sales) VALUES (1,'John Doe','North',5000),(2,'Jane Smith','South',6000),(3,'Alice Johnson','East',7000),(4,'Bob Williams','West',8000);
SELECT name, SUM(sales) as total_sales FROM sales_representatives GROUP BY name ORDER BY total_sales DESC;
What is the total funding received by bioprocess engineering startups?
CREATE TABLE Startups (ID INT,Name VARCHAR(50),Funding FLOAT,Year INT,Industry VARCHAR(50)); INSERT INTO Startups (ID,Name,Funding,Year,Industry) VALUES (1,'GreenGenes',5000000,2020,'Genetic Research'); INSERT INTO Startups (ID,Name,Funding,Year,Industry) VALUES (2,'BioSense',3000000,2019,'Biosensors'); INSERT INTO Startups (ID,Name,Funding,Year,Industry) VALUES (3,'ProcessTech',7000000,2021,'Bioprocess Engineering');
SELECT Industry, SUM(Funding) FROM Startups WHERE Industry = 'Bioprocess Engineering' GROUP BY Industry;
Delete community_policing records older than 2 years
CREATE TABLE community_policing (id INT,event_date DATE,event_type VARCHAR(255)); INSERT INTO community_policing (id,event_date,event_type) VALUES (1,'2020-01-01','Meeting'),(2,'2021-01-01','Training');
DELETE FROM community_policing WHERE event_date < (CURRENT_DATE - INTERVAL '2 years');
Identify the top 5 neighborhoods with the highest average housing affordability index and their corresponding city.
CREATE TABLE neighborhoods (neighborhood VARCHAR(255),city VARCHAR(255),housing_affordability_index FLOAT);
SELECT neighborhood, city, AVG(housing_affordability_index) as avg_affordability_index FROM neighborhoods GROUP BY neighborhood, city ORDER BY avg_affordability_index DESC LIMIT 5;
Update the number of complaints for 'Site A' to 6 in the HeritageSites table.
CREATE TABLE HeritageSites (id INT PRIMARY KEY,name VARCHAR(255),visitors INT,complaints INT); INSERT INTO HeritageSites (id,name,visitors,complaints) VALUES (1,'Site A',1000,5),(2,'Site B',1500,3);
UPDATE HeritageSites SET complaints = 6 WHERE name = 'Site A';
Calculate the total volume of wastewater treated in the state of California, USA in the last quarter
CREATE TABLE states (id INT,name VARCHAR(255)); INSERT INTO states (id,name) VALUES (1,'California'); CREATE TABLE wastewater_treatment (id INT,state_id INT,volume FLOAT,treatment_date DATE); INSERT INTO wastewater_treatment (id,state_id,volume,treatment_date) VALUES (1,1,1000,'2022-01-01');
SELECT SUM(wastewater_treatment.volume) as total_volume FROM wastewater_treatment WHERE wastewater_treatment.treatment_date >= (CURRENT_DATE - INTERVAL '3 months')::date AND wastewater_treatment.state_id IN (SELECT id FROM states WHERE name = 'California');
List all protected species in 'Asian' forests.
CREATE TABLE forests (id INT,region VARCHAR(50)); INSERT INTO forests (id,region) VALUES (1,'Asian'); CREATE TABLE species (id INT,name VARCHAR(50),is_protected BOOLEAN); INSERT INTO species (id,name,is_protected) VALUES (1,'Tiger',true);
SELECT species.name FROM species JOIN forests ON FALSE WHERE forests.region = 'Asian' AND species.is_protected = true;
What is the trend of open vulnerabilities by severity over the last year?
CREATE TABLE vulnerabilities (id INT,severity VARCHAR(10),open_date DATE,close_date DATE);
SELECT severity, COUNT(*) as vulnerability_count, DATEADD(month, DATEDIFF(month, 0, open_date), 0) as month FROM vulnerabilities WHERE close_date IS NULL GROUP BY severity, DATEADD(month, DATEDIFF(month, 0, open_date), 0) ORDER BY month, severity;
What is the renewable energy percentage for Australia on 2021-01-03?
CREATE TABLE renewable_mix (id INT,date DATE,country VARCHAR(20),renewable_percentage DECIMAL(5,2)); INSERT INTO renewable_mix (id,date,country,renewable_percentage) VALUES (3,'2021-01-03','Australia',35.00); INSERT INTO renewable_mix (id,date,country,renewable_percentage) VALUES (4,'2021-01-04','Argentina',22.00);
SELECT renewable_percentage FROM renewable_mix WHERE date = '2021-01-03' AND country = 'Australia';
What is the average number of goals scored per game by each soccer player in the last season, broken down by team?
CREATE TABLE games (id INT,game_date DATE,team VARCHAR(20)); CREATE TABLE goals (id INT,game_id INT,player VARCHAR(20),goals INT);
SELECT team, player, AVG(goals) FROM goals JOIN games ON goals.game_id = games.id WHERE games.game_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY team, player;
What is the minimum number of cyber threats detected by the military in South Korea in the last 6 months?
CREATE TABLE CyberThreats (id INT,country VARCHAR(50),threat_type VARCHAR(50),threat_date DATE); INSERT INTO CyberThreats (id,country,threat_type,threat_date) VALUES (1,'South Korea','Phishing','2021-01-12'),(2,'South Korea','Ransomware','2021-03-25'),(3,'South Korea','Malware','2021-05-08');
SELECT MIN(frequency) FROM (SELECT COUNT(*) AS frequency FROM CyberThreats WHERE country = 'South Korea' AND threat_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) GROUP BY threat_type) AS subquery;
What is the total revenue for museum shop sales by month?
CREATE TABLE sales (id INT,date DATE,item VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO sales (id,date,item,revenue) VALUES (1,'2021-01-01','Postcard',1.50),(2,'2021-02-01','Mug',10.00),(3,'2021-03-01','T-shirt',20.00);
SELECT DATE_FORMAT(date, '%Y-%m') as month, SUM(revenue) as total_revenue FROM sales GROUP BY month ORDER BY STR_TO_DATE(month, '%Y-%m');
Display the number of marine protected areas and their total size in the Arctic region.
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(50),size FLOAT,ocean VARCHAR(20)); INSERT INTO marine_protected_areas (id,name,size,ocean) VALUES (1,'Northwest Passage',123000,'Arctic'); INSERT INTO marine_protected_areas (id,name,size,ocean) VALUES (2,'Arctic National Wildlife Refuge',780000,'Arctic');
SELECT COUNT(*), SUM(size) FROM marine_protected_areas WHERE ocean = 'Arctic';
What are the top 3 materials used in road construction in Texas?
CREATE TABLE road_materials (material_id INT,road_id INT,material VARCHAR(50)); CREATE TABLE materials (material_id INT,material_name VARCHAR(50),quantity INT); CREATE TABLE roads (road_id INT,state VARCHAR(50),length INT);
SELECT materials.material_name, SUM(materials.quantity) as total_quantity FROM road_materials JOIN materials ON road_materials.material_id = materials.material_id JOIN roads ON road_materials.road_id = roads.road_id WHERE roads.state = 'Texas' GROUP BY materials.material_name ORDER BY total_quantity DESC LIMIT 3;
What is the minimum and maximum renewable energy capacity (in MW) for solar power projects in the 'renewable_energy' schema?
CREATE TABLE renewable_energy.solar_power (project_name VARCHAR(30),capacity INT);
SELECT MIN(capacity) AS min_capacity, MAX(capacity) AS max_capacity FROM renewable_energy.solar_power;
Show the top 5 most popular workout types by total number of workouts for female members.
CREATE TABLE members (id INT,gender VARCHAR(10)); CREATE TABLE workouts (id INT,member_id INT,workout_type VARCHAR(20),workout_date DATE);
SELECT w.workout_type, COUNT(*) as total_workouts FROM members m INNER JOIN workouts w ON m.id = w.member_id WHERE m.gender = 'female' GROUP BY w.workout_type ORDER BY total_workouts DESC LIMIT 5;
What is the total number of telescopes operated by space agencies and their types?
CREATE TABLE telescopes (id INT,name VARCHAR(255),type VARCHAR(255),agency VARCHAR(255),PRIMARY KEY(id)); INSERT INTO telescopes (id,name,type,agency) VALUES (1,'Telescope1','Optical','Agency1'),(2,'Telescope2','Radio','Agency2'),(3,'Telescope3','Infrared','Agency1');
SELECT telescopes.agency, COUNT(telescopes.id), telescopes.type FROM telescopes GROUP BY telescopes.agency, telescopes.type;
What is the total number of properties and the average price in the state of California?
CREATE TABLE Properties (id INT,price INT,state TEXT); INSERT INTO Properties (id,price,state) VALUES (1,500000,'California'),(2,400000,'California'),(3,700000,'Colorado'),(4,600000,'Texas');
SELECT COUNT(*) AS total_properties, AVG(price) AS avg_price FROM Properties WHERE state = 'California';
Insert new record into 'cannabis_growers' table with data: license_number: 789B, grower_name: 'EcoCann'
CREATE TABLE cannabis_growers (license_number VARCHAR(10),grower_name VARCHAR(50));
INSERT INTO cannabis_growers (license_number, grower_name) VALUES ('789B', 'EcoCann');
What is the total sales of refillable cosmetic products by month?
CREATE TABLE months (month_id INT,month_name VARCHAR(255)); CREATE TABLE products (product_id INT,product_name VARCHAR(255),is_refillable BOOLEAN,sales INT,month_id INT);
SELECT m.month_name, SUM(p.sales) as total_sales FROM months m INNER JOIN products p ON m.month_id = p.month_id WHERE p.is_refillable = TRUE GROUP BY m.month_name;
What are the water conservation initiatives implemented in the Greenville Wastewater Treatment Plant in 2022?
CREATE TABLE WastewaterTreatmentFacilities (FacilityID INT,FacilityName VARCHAR(255),Address VARCHAR(255),City VARCHAR(255),State VARCHAR(255),ZipCode VARCHAR(10)); INSERT INTO WastewaterTreatmentFacilities (FacilityID,FacilityName,Address,City,State,ZipCode) VALUES (1,'Clear Water Plant','1234 5th St','Houston','TX','77002'),(2,'Greenville Wastewater Treatment Plant','450 Powerhouse Rd','Greenville','SC','29605'); CREATE TABLE WaterConservationInitiatives (InitiativeID INT,FacilityID INT,InitiativeName VARCHAR(255),InitiativeDescription VARCHAR(255),StartDate DATE,EndDate DATE); INSERT INTO WaterConservationInitiatives (InitiativeID,FacilityID,InitiativeName,InitiativeDescription,StartDate,EndDate) VALUES (1,2,'Water recycling program','Recycling of water for irrigation purposes','2022-01-01','2022-12-31'),(2,2,'Drought-tolerant landscaping','Replacing lawns with drought-tolerant plants','2022-03-15','2022-11-30');
SELECT InitiativeName FROM WaterConservationInitiatives WHERE FacilityID = 2 AND StartDate <= '2022-12-31' AND EndDate >= '2022-01-01';
What is the maximum hourly rate for attorneys who have never lost a case?
CREATE TABLE Attorneys (AttorneyID int,HourlyRate decimal(5,2),Losses int); INSERT INTO Attorneys (AttorneyID,HourlyRate,Losses) VALUES (1,300.00,0),(2,250.00,1),(3,350.00,0);
SELECT MAX(HourlyRate) AS MaxHourlyRate FROM Attorneys WHERE Losses = 0;
What is the list of fish types farmed in sites with water temperature above 25 degrees Celsius?
CREATE TABLE Farming_Sites (Site_ID INT,Site_Name TEXT,Water_Temperature INT); INSERT INTO Farming_Sites (Site_ID,Site_Name,Water_Temperature) VALUES (1,'Site A',20),(2,'Site B',30),(3,'Site C',25); CREATE TABLE Fish_Stock (Site_ID INT,Fish_Type TEXT,Biomass FLOAT); INSERT INTO Fish_Stock (Site_ID,Fish_Type,Biomass) VALUES (1,'Salmon',5000),(1,'Tuna',3000),(2,'Salmon',7000),(2,'Tilapia',4000),(3,'Salmon',6000),(3,'Tuna',2000);
SELECT Fish_Type FROM Fish_Stock INNER JOIN Farming_Sites ON Fish_Stock.Site_ID = Farming_Sites.Site_ID WHERE Water_Temperature > 25;
What are the total sales for each drug, including sales tax, in the Canadian market?
CREATE TABLE drugs (drug_id INT,drug_name VARCHAR(255),manufacturer VARCHAR(255)); INSERT INTO drugs (drug_id,drug_name,manufacturer) VALUES (1,'DrugA','Manufacturer1'); CREATE TABLE sales (sale_id INT,drug_id INT,sale_amount DECIMAL(10,2),sale_tax DECIMAL(10,2),country VARCHAR(255)); INSERT INTO sales (sale_id,drug_id,sale_amount,sale_tax,country) VALUES (1,1,100.00,15.00,'Canada');
SELECT d.drug_name, SUM(s.sale_amount + s.sale_tax) as total_sales_with_tax FROM drugs d JOIN sales s ON d.drug_id = s.drug_id WHERE s.country = 'Canada' GROUP BY d.drug_name;
How many space missions were attempted by each country?
CREATE TABLE space_missions (mission_id INT,mission_country VARCHAR(100),mission_year INT);
SELECT mission_country, COUNT(*) FROM space_missions GROUP BY mission_country;
What is the total number of players who prefer VR technology, grouped by age?
CREATE TABLE PlayerPreferences (PlayerID INT,AgeGroup VARCHAR(10),VRPreference INT); INSERT INTO PlayerPreferences (PlayerID,AgeGroup,VRPreference) VALUES (1,'18-24',1),(2,'25-34',0),(3,'18-24',1),(4,'35-44',0);
SELECT AgeGroup, SUM(VRPreference) FROM PlayerPreferences GROUP BY AgeGroup;
What is the total investment in 'sustainable_infrastructure' projects?
CREATE TABLE projects (id INT,sector VARCHAR(20),investment_amount FLOAT)
SELECT SUM(investment_amount) FROM projects WHERE sector = 'sustainable_infrastructure'
Show the number of unique visitors for a specific article, including the article's title and author
CREATE TABLE articles (id INT PRIMARY KEY,title TEXT NOT NULL,author_id INT,published_at DATE); CREATE TABLE authors (id INT PRIMARY KEY,name TEXT NOT NULL); CREATE TABLE views (article_id INT,visitor_id INT);
SELECT articles.title, authors.name, COUNT(DISTINCT views.visitor_id) as unique_visitors FROM articles INNER JOIN authors ON articles.author_id = authors.id INNER JOIN views ON articles.id = views.article_id WHERE articles.id = 'specific_article_id' GROUP BY articles.title, authors.name;
How many carbon pricing policies are there in the 'carbon_pricing' schema?
CREATE SCHEMA carbon_pricing; CREATE TABLE carbon_pricing_policies (name TEXT,description TEXT); INSERT INTO carbon_pricing_policies (name,description) VALUES ('Policy A','Text A'),('Policy B','Text B');
SELECT COUNT(*) FROM carbon_pricing.carbon_pricing_policies;
How many events were attended by people aged 25-34 in the last 6 months?
CREATE TABLE Events (EventID INT,EventName TEXT,EventDate DATE,AttendeeAge INT); INSERT INTO Events (EventID,EventName,EventDate,AttendeeAge) VALUES (1,'Art Exhibition','2021-06-01',28),(2,'Theater Performance','2021-07-15',32),(3,'Music Concert','2020-12-31',26);
SELECT COUNT(*) FROM Events WHERE AttendeeAge BETWEEN 25 AND 34 AND EventDate >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
What is the minimum health equity metric score for community health workers in Florida?
CREATE TABLE health_equity_metrics (id INT,community_health_worker_id INT,score INT); INSERT INTO health_equity_metrics (id,community_health_worker_id,score) VALUES (1,1,80),(2,2,90),(3,3,95),(4,4,70),(5,6,65); CREATE TABLE community_health_workers (id INT,name VARCHAR(100),state VARCHAR(50)); INSERT INTO community_health_workers (id,name,state) VALUES (1,'Jane Smith','Florida'),(2,'Jose Garcia','Texas'),(3,'Sophia Lee','California'),(4,'Ali Ahmed','New York'),(6,'Mariana Rodriguez','Florida');
SELECT MIN(score) FROM health_equity_metrics JOIN community_health_workers ON health_equity_metrics.community_health_worker_id = community_health_workers.id WHERE community_health_workers.state = 'Florida';
What is the maximum production capacity for the chemical plants in a specific region?
CREATE TABLE plants (plant_id INT,plant_name VARCHAR(50),region VARCHAR(50),production_capacity INT); INSERT INTO plants (plant_id,plant_name,region,production_capacity) VALUES (1,'Plant A','Northeast',500),(2,'Plant B','Midwest',600);
SELECT plant_name, MAX(production_capacity) FROM plants WHERE region = 'Northeast';
What was the total weight of shipments from Africa to Asia in June 2022?
CREATE TABLE Shipments (id INT,source VARCHAR(50),destination VARCHAR(50),weight FLOAT,ship_date DATE); INSERT INTO Shipments (id,source,destination,weight,ship_date) VALUES (12,'Nigeria','China',500,'2022-06-01'); INSERT INTO Shipments (id,source,destination,weight,ship_date) VALUES (13,'Egypt','Japan',700,'2022-06-15'); INSERT INTO Shipments (id,source,destination,weight,ship_date) VALUES (14,'South Africa','India',900,'2022-06-30');
SELECT SUM(weight) FROM Shipments WHERE (source = 'Nigeria' OR source = 'Egypt' OR source = 'South Africa') AND (destination = 'China' OR destination = 'Japan' OR destination = 'India') AND ship_date = '2022-06-01';
Show the total number of international visitors to all countries in Oceania in the last year.
CREATE TABLE oceania_visitors (id INT,name TEXT,country TEXT,visit_date DATE);
SELECT country, COUNT(*) AS visitor_count FROM oceania_visitors WHERE visit_date > DATEADD(year, -1, GETDATE()) GROUP BY country; SELECT SUM(visitor_count) AS total_visitor_count FROM ( SELECT country, COUNT(*) AS visitor_count FROM oceania_visitors WHERE visit_date > DATEADD(year, -1, GETDATE()) GROUP BY country ) AS oceania_visitor_counts;
What is the total calorie intake for each continent in 2021?
CREATE TABLE CountryFoodIntake (CountryName VARCHAR(50),Continent VARCHAR(50),Year INT,CaloriesPerPerson INT); INSERT INTO CountryFoodIntake (CountryName,Continent,Year,CaloriesPerPerson) VALUES ('United States','North America',2021,3800),('Mexico','North America',2021,3400),('Italy','Europe',2021,3200),('Japan','Asia',2021,2800),('India','Asia',2021,2500);
SELECT Continent, SUM(CaloriesPerPerson) FROM CountryFoodIntake WHERE Year = 2021 GROUP BY Continent;
What is the total investment amount by each investor for diverse founders?
CREATE TABLE Investors (InvestorID INT,InvestorName VARCHAR(50)); CREATE TABLE Founders (FounderID INT,FounderName VARCHAR(50),Ethnicity VARCHAR(20)); CREATE TABLE Investments (InvestmentID INT,InvestorID INT,FounderID INT,InvestmentAmount DECIMAL(10,2));
SELECT I.InvestorName, SUM(I.InvestmentAmount) AS TotalInvestment FROM Investments I JOIN Founders F ON I.FounderID = Founders.FounderID WHERE F.Ethnicity IN ('African', 'Hispanic', 'Asian', 'Indigenous') GROUP BY I.InvestorID;
What is the total volume of timber production for each species in the African region in 2017 and 2018?
CREATE TABLE timber_production_volume_2(year INT,region VARCHAR(255),species VARCHAR(255),volume FLOAT); INSERT INTO timber_production_volume_2(year,region,species,volume) VALUES (2016,'Asia','Pine',1100.0),(2016,'Asia','Oak',1400.0),(2017,'Africa','Pine',1200.0),(2017,'Africa','Oak',1500.0),(2018,'Africa','Pine',1300.0),(2018,'Africa','Oak',1700.0);
SELECT species, SUM(volume) as total_volume FROM timber_production_volume_2 WHERE region = 'Africa' AND year IN (2017, 2018) GROUP BY species;
What is the average duration of songs in the jazz genre?
CREATE TABLE Song (Title VARCHAR(30),Genre VARCHAR(10),Duration FLOAT); INSERT INTO Song (Title,Genre,Duration) VALUES ('Song1','Jazz',3.45),('Song2','Jazz',4.23),('Song3','Jazz',2.87),('Song4','Pop',3.12),('Song5','Rock',2.98),('Song6','Jazz',3.66);
SELECT AVG(Duration) FROM Song WHERE Genre = 'Jazz';
Update the "technology_access" table to set the "internet_speed" to "High" for the records with "region" as "Asia-Pacific"
CREATE TABLE technology_access (id INT PRIMARY KEY,country VARCHAR(50),region VARCHAR(50),internet_speed VARCHAR(10)); INSERT INTO technology_access (id,country,region,internet_speed) VALUES (1,'India','Asia-Pacific','Low'); INSERT INTO technology_access (id,country,region,internet_speed) VALUES (2,'Australia','Asia-Pacific','Medium');
UPDATE technology_access SET internet_speed = 'High' WHERE region = 'Asia-Pacific';
How many students with invisible disabilities are not included in social events?
CREATE TABLE InvisibleDisabilities (StudentID INT,StudentName VARCHAR(50),Disability VARCHAR(20)); INSERT INTO InvisibleDisabilities (StudentID,StudentName,Disability) VALUES (7,'Olivia Thompson','Autism'); INSERT INTO InvisibleDisabilities (StudentID,StudentName,Disability) VALUES (8,'Mason Taylor','ADHD'); CREATE TABLE Events (Event VARCHAR(20),StudentID INT,Included BOOLEAN); INSERT INTO Events (Event,StudentID,Included) VALUES ('Holiday Party',7,FALSE); INSERT INTO Events (Event,StudentID,Included) VALUES ('Sports Day',8,FALSE);
SELECT COUNT(DISTINCT s.StudentID) FROM InvisibleDisabilities s JOIN Events e ON s.StudentID = e.StudentID WHERE e.Included = FALSE;
Show the daily total calorie count for each dish type.
CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(50),dish_type VARCHAR(20),calorie_count INT,added_date DATE); INSERT INTO dishes (dish_id,dish_name,dish_type,calorie_count,added_date) VALUES (1,'Veggie Delight','vegan',300,'2021-05-01'),(2,'Tofu Stir Fry','vegan',450,'2021-05-02'),(3,'Chickpea Curry','vegan',500,'2021-05-03'),(4,'Lamb Korma','non-veg',900,'2021-05-04'),(5,'Chicken Tikka','non-veg',600,'2021-05-05'),(6,'Falafel','vegan',400,'2021-05-05');
SELECT dish_type, added_date, SUM(calorie_count) OVER (PARTITION BY dish_type ORDER BY added_date) total_calorie_count FROM dishes;
How many customers in each size category have made a purchase in the past year?
CREATE TABLE Purchases (PurchaseID INT,CustomerID INT,PurchaseDate DATE); INSERT INTO Purchases (PurchaseID,CustomerID,PurchaseDate) VALUES (1,1,'2021-01-01'),(2,2,'2021-02-01'),(3,3,'2021-03-01'),(4,4,'2021-04-01'),(5,5,'2021-05-01');
SELECT Customers.Size, COUNT(DISTINCT Customers.CustomerID) FROM Customers INNER JOIN Purchases ON Customers.CustomerID = Purchases.CustomerID WHERE Purchases.PurchaseDate BETWEEN '2020-01-01' AND '2021-12-31' GROUP BY Customers.Size;
How many medical incidents were recorded each month in 'incidents' table for the year 2021?
CREATE TABLE incidents (incident_id INT,incident_date DATE,category VARCHAR(20)); INSERT INTO incidents (incident_id,incident_date,category) VALUES (1,'2021-01-01','Medical'),(2,'2021-02-15','Fire'),(3,'2021-03-01','Traffic');
SELECT DATE_FORMAT(incident_date, '%Y-%m') AS month, COUNT(*) FROM incidents WHERE YEAR(incident_date) = 2021 AND category = 'Medical' GROUP BY month;
What is the average housing affordability index for each city?
CREATE TABLE affordability (id INT,index FLOAT,city VARCHAR(20)); INSERT INTO affordability (id,index,city) VALUES (1,100,'Denver'),(2,120,'Portland'),(3,80,'NYC');
SELECT city, AVG(index) FROM affordability GROUP BY city;
Identify the number of times a drone malfunction occurred in each country for the past six months.
CREATE TABLE DroneFlight (date DATE,country VARCHAR(20),malfunction BOOLEAN);
SELECT country, COUNT(*) FROM DroneFlight WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND malfunction = TRUE GROUP BY country;
What is the total number of articles about corruption in the past year, categorized by the region where the corruption occurred?
CREATE TABLE articles (id INT,title VARCHAR(100),date DATE,topic VARCHAR(50),region VARCHAR(50)); INSERT INTO articles VALUES (1,'Corruption scandal','2022-01-01','Corruption','Asia');
SELECT articles.region, COUNT(articles.id) FROM articles WHERE articles.date >= DATEADD(year, -1, GETDATE()) AND articles.topic = 'Corruption' GROUP BY articles.region;