instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Identify the number of employees in each department and the percentage of the total workforce, broken down by gender.
CREATE TABLE gender_diversity (id INT,employee_id INT,department TEXT,gender TEXT); INSERT INTO gender_diversity (id,employee_id,department,gender) VALUES (1,101,'mining_operations','male'); INSERT INTO gender_diversity (id,employee_id,department,gender) VALUES (2,125,'geology','female');
SELECT department, gender, COUNT(*) AS count, ROUND(100.0 * COUNT(*) / (SELECT SUM(COUNT(*)) FROM gender_diversity GROUP BY department, gender), 2) AS percentage FROM gender_diversity GROUP BY department, gender;
Insert new records into the virtual_reality_headsets table and update the corresponding vr_headsets_sales table
CREATE TABLE virtual_reality_headsets (id INT PRIMARY KEY,manufacturer TEXT,model TEXT,price DECIMAL(10,2)); CREATE TABLE vr_headsets_sales (id INT PRIMARY KEY,headset_id INT,quantity INT);
INSERT INTO virtual_reality_headsets (id, manufacturer, model, price) VALUES (1, 'Oculus', 'Quest 2', 299.99), (2, 'HTC', 'Vive Pro 2', 799.99); UPDATE vr_headsets_sales SET headset_id = CASE WHEN model = 'Quest 2' THEN 1 WHEN model = 'Vive Pro 2' THEN 2 ELSE NULL END WHERE headset_id IS NULL;
What is the total transaction amount per day for the last week, partitioned by region?
CREATE TABLE users (user_id INT,username VARCHAR(20),region VARCHAR(20));CREATE TABLE transactions (transaction_id INT,user_id INT,amount DECIMAL(10,2),transaction_time TIMESTAMP);
SELECT region, DATE(transaction_time) as transaction_date, SUM(amount) as total_amount FROM transactions JOIN users ON transactions.user_id = users.user_id WHERE transaction_time > DATEADD(week, -1, GETDATE()) GROUP BY region, transaction_date;
Show the inclusion efforts in the IT faculty that are not offered in the Finance faculty.
CREATE TABLE ITInclusion (EffortID INT,Effort VARCHAR(50)); CREATE TABLE FinanceInclusion (EffortID INT,Effort VARCHAR(50)); INSERT INTO ITInclusion VALUES (1,'Diversity Training'),(2,'Accessible Spaces'),(3,'Flexible Work Arrangements'),(4,'Technology Grants'); INSERT INTO FinanceInclusion VALUES (2,'Accessible Spaces...
SELECT Effort FROM ITInclusion WHERE Effort NOT IN (SELECT Effort FROM FinanceInclusion);
What is the average farm size (in hectares) for agroecological farms in Asia?
CREATE TABLE agroecological_farms (farm_id INT,farm_name TEXT,country TEXT,farm_size_ha FLOAT); INSERT INTO agroecological_farms (farm_id,farm_name,country,farm_size_ha) VALUES (1,'Farm D','China',5.0),(2,'Farm E','India',3.5),(3,'Farm F','Japan',7.0);
SELECT AVG(farm_size_ha) FROM agroecological_farms WHERE country = 'Asia';
Who was the most frequent curator in New York art exhibitions in 2019?
CREATE TABLE Curators (id INT,exhibition_id INT,name VARCHAR(50));INSERT INTO Curators (id,exhibition_id,name) VALUES (1,1,'Alice'),(2,1,'Bob'),(3,2,'Alice');
SELECT name, COUNT(*) AS exhibition_count FROM Curators C INNER JOIN (SELECT exhibition_id FROM Exhibitions WHERE city = 'New York' AND year = 2019) E ON C.exhibition_id = E.exhibition_id GROUP BY name ORDER BY exhibition_count DESC LIMIT 1;
What are the top 5 preferred cosmetic products by consumers in the United States?
CREATE TABLE ConsumerPreference (ConsumerID INT,ProductID INT,ProductName VARCHAR(50),Country VARCHAR(50)); INSERT INTO ConsumerPreference (ConsumerID,ProductID,ProductName,Country) VALUES (1,101,'Lipstick','USA'),(2,102,'Mascara','USA'),(3,103,'Foundation','USA'),(4,104,'Eyeshadow','USA'),(5,105,'Blush','USA');
SELECT ProductName, COUNT(*) as ConsumerCount FROM ConsumerPreference WHERE Country = 'USA' GROUP BY ProductName ORDER BY ConsumerCount DESC LIMIT 5;
What is the average number of items sold by each salesperson in the sales database?
CREATE TABLE sales (salesperson VARCHAR(20),items INT); INSERT INTO sales (salesperson,items) VALUES ('John',50),('Jane',70),('Doe',60);
SELECT salesperson, AVG(items) FROM sales GROUP BY salesperson;
How many marine species are there in the Atlantic Ocean?
CREATE TABLE atlantic_ocean (id INT,marine_species_count INT); INSERT INTO atlantic_ocean (id,marine_species_count) VALUES (1,3500);
SELECT marine_species_count FROM atlantic_ocean WHERE id = 1;
How many consumers in Asia are not aware of circular economy principles?
CREATE TABLE consumers (id INT,location VARCHAR(255),aware_of_circular_economy BOOLEAN); INSERT INTO consumers (id,location,aware_of_circular_economy) VALUES (1,'India',true),(2,'China',false),(3,'Indonesia',true),(4,'Japan',false);
SELECT COUNT(*) FROM consumers WHERE location LIKE 'Asia%' AND aware_of_circular_economy = false;
What is the total number of VR games in the 'Simulation' category that have a satisfaction rating above 4.5?
CREATE TABLE VRGames (id INT,name VARCHAR(100),category VARCHAR(50),satisfaction FLOAT);
SELECT COUNT(*) FROM VRGames WHERE category = 'Simulation' AND satisfaction > 4.5;
What is the total funding raised by startups that have a female founder and exited in the last 3 years?
CREATE TABLE startups(id INT,name TEXT,founder_gender TEXT); INSERT INTO startups VALUES (1,'Acme Inc','Female'); INSERT INTO startups VALUES (2,'Beta Corp','Male'); CREATE TABLE funding_rounds(startup_id INT,amount_raised INT); INSERT INTO funding_rounds VALUES (1,5000000); INSERT INTO funding_rounds VALUES (2,7000000...
SELECT SUM(funding_rounds.amount_raised) FROM startups INNER JOIN funding_rounds ON startups.id = funding_rounds.startup_id INNER JOIN exits ON startups.id = exits.startup_id WHERE startups.founder_gender = 'Female' AND exits.exit_year >= YEAR(CURRENT_DATE) - 3;
List policyholders who have a policy in Florida but live outside of Florida.
CREATE TABLE policyholders (id INT,name VARCHAR(100),state VARCHAR(20)); CREATE TABLE policies (id INT,policy_number VARCHAR(50),policyholder_id INT,state VARCHAR(20)); INSERT INTO policyholders (id,name,state) VALUES (1,'Jim Brown','TX'),(2,'Pam Smith','CA'),(3,'Mike Johnson','FL'); INSERT INTO policies (id,policy_num...
SELECT DISTINCT policyholders.name FROM policyholders JOIN policies ON policyholders.id = policies.policyholder_id WHERE policies.state = 'FL' AND policyholders.state != 'FL';
What is the maximum, minimum, and average hourly wage for construction workers in the last year?
CREATE TABLE LaborStatistics (StatID INT,Gender TEXT,Age INT,JobCategory TEXT,HourlyWage NUMERIC,DateRecorded DATE);
SELECT MAX(HourlyWage) AS MaxHourlyWage, MIN(HourlyWage) AS MinHourlyWage, AVG(HourlyWage) AS AvgHourlyWage FROM LaborStatistics WHERE DateRecorded >= DATEADD(year, -1, GETDATE());
Insert data about a publication into the Publications table
CREATE TABLE Publications (id INT PRIMARY KEY,title VARCHAR(255),author_id INT,year INT,FOREIGN KEY (author_id) REFERENCES Archaeologists(id)); INSERT INTO Publications (id,title,author_id,year) VALUES (1,'Uncovering the Secrets of the Maya',2,2018);
INSERT INTO Publications (id, title, author_id, year) VALUES (2, 'The Forgotten Kingdom: Inca Civilization', 3, 2020);
Get the number of songs released per year in the music_releases table, grouped by decade.
CREATE TABLE music_releases (release_year INT,song_title VARCHAR);
SELECT DATE_PART('decade', INTERVAL '1 year' * release_year) AS decade, COUNT(song_title) AS num_songs FROM music_releases GROUP BY decade ORDER BY decade;
What is the number of electric vehicles sold in the United States each year since 2015?
CREATE TABLE VehicleSales (year INT,country VARCHAR(255),vehicle_type VARCHAR(255),sales INT); INSERT INTO VehicleSales (year,country,vehicle_type,sales) VALUES (2015,'United States','Electric',150000),(2016,'United States','Electric',200000),(2017,'United States','Electric',300000),(2018,'United States','Electric',400...
SELECT year, SUM(sales) AS electric_vehicle_sales FROM VehicleSales WHERE country = 'United States' AND vehicle_type = 'Electric' GROUP BY year;
How many military equipment maintenance requests were there in Q1 2020?
CREATE TABLE maintenance_requests (request_id INT,date DATE,type VARCHAR(255)); INSERT INTO maintenance_requests (request_id,date,type) VALUES (3,'2020-01-01','equipment'); INSERT INTO maintenance_requests (request_id,date,type) VALUES (4,'2020-01-15','facility');
SELECT COUNT(*) FROM maintenance_requests WHERE date BETWEEN '2020-01-01' AND '2020-03-31' AND type = 'equipment';
Delete all records from the 'clean_energy_policy_trends' table where the 'policy_type' is 'Regulation'
CREATE TABLE clean_energy_policy_trends (id INT,policy_type VARCHAR(255),start_year INT,end_year INT,description TEXT);
DELETE FROM clean_energy_policy_trends WHERE policy_type = 'Regulation';
Which communities have the highest obesity rates, and what is the average income for those communities?
CREATE TABLE Community (Name VARCHAR(255),ObesityRate DECIMAL(5,2),AvgIncome DECIMAL(10,2)); INSERT INTO Community (Name,ObesityRate,AvgIncome) VALUES ('Community A',22.5,45000.00),('Community B',28.0,52000.00),('Community C',18.5,60000.00);
SELECT Name, ObesityRate FROM Community WHERE ObesityRate >= (SELECT AVG(ObesityRate) FROM Community)
What is the average price of sustainable garments per category?
CREATE TABLE garments(garment_id INT,category VARCHAR(255),sustainable BOOLEAN,price FLOAT); INSERT INTO garments(garment_id,category,sustainable,price) VALUES (1,'T-Shirt',true,20.0),(2,'Pants',false,30.0),(3,'Jacket',true,50.0);
SELECT category, AVG(price) FROM garments WHERE sustainable = true GROUP BY category;
What is the total number of smart contracts deployed on the Ethereum network by developers from India?
CREATE TABLE if not exists smart_contracts (contract_id INT,contract_address VARCHAR(255),developer_country VARCHAR(255)); INSERT INTO smart_contracts (contract_id,contract_address,developer_country) VALUES (1,'0x123...','India'),(2,'0x456...','USA'),(3,'0x789...','India'),(4,'0xabc...','UK'),(5,'0xdef...','India'),(6,...
SELECT COUNT(*) FROM smart_contracts WHERE developer_country = 'India';
How many carbon offset initiatives in Australia have offset more than 10,000 tons of CO2?
CREATE TABLE carbon_offsets (id INT,initiative VARCHAR(255),country VARCHAR(255),offset_type VARCHAR(255),amount INT); INSERT INTO carbon_offsets (id,initiative,country,offset_type,amount) VALUES (2,'Carbon Capture','Australia','CO2',15000);
SELECT COUNT(*) as num_initiatives FROM carbon_offsets WHERE country = 'Australia' AND amount > 10000;
What is the total volume of water saved through water conservation initiatives in the state of California for each year since 2017?
CREATE TABLE conservation_initiatives_california (initiative_id INT,state VARCHAR(20),savings_volume FLOAT,initiative_year INT); INSERT INTO conservation_initiatives_california (initiative_id,state,savings_volume,initiative_year) VALUES (1,'California',3000000,2017); INSERT INTO conservation_initiatives_california (ini...
SELECT initiative_year, SUM(savings_volume) FROM conservation_initiatives_california WHERE state = 'California' GROUP BY initiative_year;
Find all cities with only eco-friendly houses.
CREATE TABLE houses (id INT,city VARCHAR(50),price INT,eco_friendly BOOLEAN); INSERT INTO houses (id,city,price,eco_friendly) VALUES (1,'Vancouver',600000,true),(2,'Toronto',700000,true),(3,'Montreal',500000,false);
SELECT city FROM houses GROUP BY city HAVING MIN(eco_friendly) = 1;
What is the total amount donated by each donor in 2021, including duplicate donations?
CREATE TABLE Donors (DonorID INT,Name TEXT,TotalDonations DECIMAL(10,2));CREATE TABLE Donations (DonationID INT,DonorID INT,Amount DECIMAL(10,2),DonationDate DATE);
SELECT D.Name, SUM(D.Amount) as TotalDonated FROM Donations D JOIN Donors ON D.DonorID = Donors.DonorID WHERE YEAR(DonationDate) = 2021 GROUP BY D.DonorID, D.Name;
What is the minimum number of followers for any user in the 'user_followers' table?
CREATE TABLE user_followers (user_id INT,followers_count INT);
SELECT MIN(followers_count) FROM user_followers;
List all pipelines in the United States that have experienced leaks since 2010.
CREATE TABLE pipelines (pipeline_id INT,location VARCHAR(255),leak_date DATE); INSERT INTO pipelines (pipeline_id,location,leak_date) VALUES (1,'United States','2012-01-01'); INSERT INTO pipelines (pipeline_id,location,leak_date) VALUES (2,'Canada','2011-01-01');
SELECT * FROM pipelines WHERE location = 'United States' AND leak_date IS NOT NULL;
List the carbon offset programs and their start dates in ascending order, along with their corresponding policy IDs in the "PolicyCityData" table.
CREATE TABLE PolicyCityData (PolicyID INT,ProgramName VARCHAR(50),StartDate DATE,City VARCHAR(50));
SELECT PolicyID, ProgramName, StartDate FROM PolicyCityData ORDER BY City, StartDate;
How many patients have been diagnosed with Schizophrenia or Bipolar Disorder?
CREATE TABLE patient (patient_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),condition VARCHAR(50)); INSERT INTO patient (patient_id,name,age,gender,condition) VALUES (1,'John Doe',45,'Male','Schizophrenia'),(2,'Jane Smith',35,'Female','Bipolar Disorder'),(3,'Emily Chen',33,'Female','Depression'),(4,'Ahmed Patel',4...
SELECT COUNT(patient_id) FROM patient WHERE condition IN ('Schizophrenia', 'Bipolar Disorder');
What is the total cost of goods sold (COGS) for each product, for the past 3 months, by each supplier?
CREATE TABLE COGS (cogs_cost DECIMAL(10,2),supplier_id INT,product VARCHAR(255),cogs_date DATE); INSERT INTO COGS (cogs_cost,supplier_id,product,cogs_date) VALUES (100.00,1,'Product A','2021-01-01'); INSERT INTO COGS (cogs_cost,supplier_id,product,cogs_date) VALUES (150.00,2,'Product B','2021-01-01'); INSERT INTO COGS ...
SELECT s.supplier_id, s.product, SUM(s.cogs_cost) as total_cogs FROM COGS s WHERE s.cogs_date BETWEEN DATE_SUB(NOW(), INTERVAL 3 MONTH) AND NOW() GROUP BY s.supplier_id, s.product;
What are the total number of transactions for each regulatory framework?
CREATE TABLE regulatory_frameworks (id INT,name VARCHAR(255)); CREATE TABLE transactions (id INT,framework_id INT,quantity INT); INSERT INTO regulatory_frameworks (id,name) VALUES (1,'FrameworkA'),(2,'FrameworkB'),(3,'FrameworkC'),(4,'FrameworkD'); INSERT INTO transactions (id,framework_id,quantity) VALUES (1,1,100),(2...
SELECT regulatory_frameworks.name AS Framework, SUM(transactions.quantity) AS Total_Transactions FROM regulatory_frameworks JOIN transactions ON regulatory_frameworks.id = transactions.framework_id GROUP BY regulatory_frameworks.name;
Which policyholders in the Pacific region have a policy with a coverage amount greater than $100,000?
CREATE TABLE Policyholders (PolicyholderID INT,Region VARCHAR(20),Coverage DECIMAL(10,2)); INSERT INTO Policyholders (PolicyholderID,Region,Coverage) VALUES (1,'Pacific',120000),(2,'Northeast',80000),(3,'Pacific',75000);
SELECT PolicyholderID, Region, Coverage FROM Policyholders WHERE Region = 'Pacific' AND Coverage > 100000;
What is the maximum production of Gadolinium and Terbium for each quarter in 2019?
CREATE TABLE RareEarthsProduction (year INT,quarter INT,element TEXT,production INT); INSERT INTO RareEarthsProduction (year,quarter,element,production) VALUES (2019,1,'Gadolinium',500); INSERT INTO RareEarthsProduction (year,quarter,element,production) VALUES (2019,1,'Terbium',400); INSERT INTO RareEarthsProduction (y...
SELECT year, quarter, MAX(production) as max_production FROM RareEarthsProduction WHERE element IN ('Gadolinium', 'Terbium') GROUP BY year, quarter;
How many cases were opened in the last quarter for clients in California?
CREATE TABLE Cases (CaseID INT,ClientID INT,OpenDate DATE); INSERT INTO Cases (CaseID,ClientID,OpenDate) VALUES (1,1,'2022-01-15'),(2,2,'2022-04-10'); CREATE TABLE Clients (ClientID INT,State VARCHAR(2)); INSERT INTO Clients (ClientID,State) VALUES (1,'CA'),(2,'NY');
SELECT COUNT(*) FROM Cases INNER JOIN Clients ON Cases.ClientID = Clients.ClientID WHERE Clients.State = 'CA' AND OpenDate >= DATEADD(quarter, -1, GETDATE());
What is the number of open pedagogy resources accessed by students in each state?
CREATE TABLE students (id INT,state TEXT);CREATE TABLE open_pedagogy_resources (id INT,access_date DATE);CREATE TABLE resource_access (student_id INT,resource_id INT);
SELECT students.state, COUNT(DISTINCT open_pedagogy_resources.id) as resources_accessed FROM students INNER JOIN resource_access ON students.id = resource_access.student_id INNER JOIN open_pedagogy_resources ON resource_access.resource_id = open_pedagogy_resources.id GROUP BY students.state;
Count the number of employees in each department.
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(20),LastName VARCHAR(20),Position VARCHAR(20),Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Position,Department) VALUES (1,'John','Doe','Engineer','Manufacturing'); INSERT INTO Employees (EmployeeID,FirstName,LastName,Position,Depa...
SELECT Department, COUNT(*) FROM Employees GROUP BY Department
Which transport infrastructure projects in New York have exceeded their budget since 2015?
CREATE TABLE InfrastructureProjects (ProjectID INT,Name VARCHAR(255),Location VARCHAR(255),Budget DECIMAL(10,2),StartDate DATE); INSERT INTO InfrastructureProjects VALUES (1,'Subway Extension','New York',2500000.00,'2016-01-01'); INSERT INTO InfrastructureProjects VALUES (2,'Highway Widening','California',5000000.00,'2...
SELECT Name, Location, Budget, StartDate FROM InfrastructureProjects WHERE Location = 'New York' AND Budget > (SELECT 1.1 * Budget FROM InfrastructureProjects WHERE InfrastructureProjects.ProjectID = (SELECT ProjectID FROM InfrastructureProjects WHERE Name = 'Subway Extension'));
What is the total amount of Shariah-compliant loans issued by Zakat Bank in 2021?
CREATE TABLE ZakatBank (id INT,loan_type VARCHAR(20),amount INT,issue_date DATE); INSERT INTO ZakatBank (id,loan_type,amount,issue_date) VALUES (1,'ShariahCompliant',5000,'2021-01-01');
SELECT SUM(amount) FROM ZakatBank WHERE loan_type = 'ShariahCompliant' AND YEAR(issue_date) = 2021;
Find the models that have been trained on both the 'creative_ai' and 'ai_safety' datasets.
CREATE TABLE model_datasets (model_id INT,model_name VARCHAR(50),dataset_name VARCHAR(50)); INSERT INTO model_datasets (model_id,model_name,dataset_name) VALUES (1,'CNN','creative_ai'),(2,'LSTM','creative_ai'),(3,'GRU','ai_safety'),(4,'MLP','ai_safety');
SELECT model_name FROM model_datasets WHERE dataset_name IN ('creative_ai', 'ai_safety') GROUP BY model_name HAVING COUNT(DISTINCT dataset_name) = 2;
Update diversity_metrics table to reflect diversity score for 'GreenTech'
CREATE TABLE companies (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE diversity_metrics (id INT PRIMARY KEY,company_id INT,gender VARCHAR(50),diversity_score DECIMAL(3,2));
UPDATE diversity_metrics SET diversity_score = 0.75 WHERE company_id IN (SELECT id FROM companies WHERE name = 'GreenTech');
What is the most common game genre played by players in a specific age range?
CREATE TABLE Players (PlayerID INT,Age INT,GameGenre VARCHAR(10)); INSERT INTO Players (PlayerID,Age,GameGenre) VALUES (1,25,'Action'),(2,30,'Strategy'),(3,22,'Action'),(4,19,'Simulation'),(5,35,'Strategy');
SELECT GameGenre, COUNT(*) AS Count FROM Players WHERE Age BETWEEN 20 AND 30 GROUP BY GameGenre ORDER BY Count DESC LIMIT 1;
What is the percentage of female fans who attended basketball games in the last 6 months, by age group?
CREATE TABLE basketball_fans (fan_id INT,gender VARCHAR(50),age INT,last_game_date DATE); INSERT INTO basketball_fans (fan_id,gender,age,last_game_date) VALUES (1,'Female',25,'2022-01-01'),(2,'Male',35,'2022-02-01'),(3,'Female',28,'2022-03-01'),(4,'Male',45,'2022-04-01'),(5,'Female',32,'2022-05-01');
SELECT age_group, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM basketball_fans WHERE gender = 'Female' AND last_game_date >= CURDATE() - INTERVAL 6 MONTH) AS percentage FROM (SELECT CASE WHEN age < 30 THEN '18-29' WHEN age < 40 THEN '30-39' ELSE '40+' END AS age_group FROM basketball_fans WHERE gender = 'Female' AND last_g...
What is the total installed capacity (in MW) of solar power projects in the 'Middle East' region?
CREATE TABLE solar_projects (project_id INT,project_name VARCHAR(100),region VARCHAR(100),installed_capacity FLOAT); INSERT INTO solar_projects (project_id,project_name,region,installed_capacity) VALUES (1,'Solar Farm 1','Middle East',50.0),(2,'Solar Farm 2','Middle East',75.0),(3,'Solar Farm 3','North America',100.0);
SELECT SUM(installed_capacity) FROM solar_projects WHERE region = 'Middle East';
List the top 3 cities with the most members who have used a wearable device for more than 270 days.
CREATE TABLE City (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO City (id,name,country) VALUES (1,'New York','USA');
SELECT c.name, COUNT(*) as member_count FROM Member m JOIN City c ON m.city = c.name JOIN WearableDevice wd ON m.id = wd.member_id WHERE DATEDIFF('day', device_start_date, device_end_date) > 270 GROUP BY c.name ORDER BY member_count DESC LIMIT 3;
What is the total value of military equipment sales to African countries in 2023?
CREATE TABLE military_sales (id INT PRIMARY KEY,year INT,country VARCHAR(50),value DECIMAL(10,2)); INSERT INTO military_sales (id,year,country,value) VALUES (1,2023,'Algeria',250000.00),(2,2023,'Egypt',750000.00),(3,2023,'South Africa',600000.00);
SELECT SUM(value) FROM military_sales WHERE year = 2023 AND country IN ('Algeria', 'Egypt', 'South Africa');
What is the maximum revenue of sustainable tourism in Asia?
CREATE TABLE asian_tourism (region TEXT,revenue FLOAT); INSERT INTO asian_tourism (region,revenue) VALUES ('Japan',2000000),('India',3000000);
SELECT MAX(revenue) FROM asian_tourism WHERE region = 'Asia';
What is the daily landfill capacity for the city of Toronto?
CREATE TABLE city_landfill (city VARCHAR(255),landfill_capacity INT,capacity_unit VARCHAR(10)); INSERT INTO city_landfill (city,landfill_capacity,capacity_unit) VALUES ('Toronto',3000,'tonnes');
SELECT landfill_capacity FROM city_landfill WHERE city='Toronto';
List all customers and their orders that were delivered through route 999?
CREATE TABLE Customers (CustomerID int,CustomerName varchar(50)); CREATE TABLE Orders (OrderID int,CustomerID int,DeliveryRoute int); CREATE TABLE DeliveryRoutes (DeliveryRoute int,RouteName varchar(50)); INSERT INTO Customers VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO Orders VALUES (100,1,999),(200,2,888),(30...
SELECT Customers.CustomerName, Orders.OrderID FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID INNER JOIN DeliveryRoutes ON Orders.DeliveryRoute = DeliveryRoutes.DeliveryRoute WHERE DeliveryRoutes.RouteName = 'Route999';
List defense projects involving company Z
CREATE TABLE defense_projects (id INT,project_name VARCHAR,start_date DATE,end_date DATE,contracted_company VARCHAR);
SELECT project_name FROM defense_projects WHERE contracted_company = 'Company Z';
What is the total water savings (in cubic meters) achieved by water conservation initiatives in the state of New York in 2021?
CREATE TABLE water_savings (id INT,state VARCHAR(255),savings_cubic_meters INT,year INT); INSERT INTO water_savings (id,state,savings_cubic_meters,year) VALUES (1,'New York',2000000,2021),(2,'New York',2500000,2021),(3,'New York',1800000,2021);
SELECT SUM(savings_cubic_meters) FROM water_savings WHERE state = 'New York' AND year = 2021;
What is the average balance for customers from each country?
CREATE TABLE customers (id INT,name VARCHAR(255),country VARCHAR(255),balance DECIMAL(10,2)); INSERT INTO customers (id,name,country,balance) VALUES (1,'John Doe','USA',5000.00),(2,'Jane Smith','Canada',7000.00),(3,'Alice Johnson','UK',8000.00);
SELECT country, AVG(balance) OVER (PARTITION BY country) FROM customers;
Who are the top 5 clients with the highest financial wellbeing scores?
CREATE TABLE client (id INT,name VARCHAR(50),wellbeing_score INT); INSERT INTO client (id,name,wellbeing_score) VALUES (1,'Alice',75),(2,'Bob',60),(3,'Charlie',80),(4,'David',45),(5,'Eve',70),(6,'Frank',85),(7,'Grace',65),(8,'Heidi',90),(9,'Ivan',55),(10,'Judy',95);
SELECT name, wellbeing_score FROM client ORDER BY wellbeing_score DESC LIMIT 5;
Add a new case to the 'criminal' table with the following data: case_id 3, client_name 'Mike Johnson', case_type 'misdemeanor', case_outcome 'acquitted', case_date '2018-09-01'
CREATE TABLE criminal (case_id INT,client_name VARCHAR(50),case_type VARCHAR(20),case_outcome VARCHAR(20),case_date DATE);
INSERT INTO criminal (case_id, client_name, case_type, case_outcome, case_date) VALUES (3, 'Mike Johnson', 'misdemeanor', 'acquitted', '2018-09-01');
What is the most common cause of death in each country?
CREATE TABLE Causes (Country VARCHAR(50),Cause VARCHAR(50),Count INT); INSERT INTO Causes (Country,Cause,Count) VALUES ('Canada','Heart Disease',20000),('USA','Cancer',30000),('Mexico','Diabetes',15000);
SELECT Country, MAX(Cause) FROM Causes GROUP BY Country;
Calculate the average water usage per household in 'CityA'
CREATE TABLE Household (id INT,city VARCHAR(20),water_usage FLOAT); INSERT INTO Household (id,city,water_usage) VALUES (1,'CityA',10.5),(2,'CityB',12.0),(3,'CityA',11.0);
SELECT AVG(water_usage) FROM Household WHERE city = 'CityA';
What is the average crop yield for farms in the 'Andean region' that have received 'agricultural innovation grants'?
CREATE TABLE farms (id INT,name TEXT,region TEXT,yield FLOAT); INSERT INTO farms (id,name,region,yield) VALUES (1,'Farm 1','Andean region',2.5),(2,'Farm 2','Amazon region',3.2); CREATE TABLE grants (id INT,farm_id INT,grant_type TEXT); INSERT INTO grants (id,farm_id,grant_type) VALUES (1,1,'agricultural innovation gran...
SELECT AVG(farms.yield) FROM farms INNER JOIN grants ON farms.id = grants.farm_id WHERE farms.region = 'Andean region' AND grants.grant_type = 'agricultural innovation grant';
Update the year of 'Festival of Colors' to 2023
CREATE TABLE CommunityEngagements (Id INT,Event TEXT,Year INT); INSERT INTO CommunityEngagements (Id,Event,Year) VALUES (1,'Festival of Colors',2022);
UPDATE CommunityEngagements SET Year = 2023 WHERE Event = 'Festival of Colors';
Remove all records related to the year 2021 from the market_trends table
CREATE TABLE market_trends (id INT PRIMARY KEY,year INT,price_per_kg DECIMAL(10,2),total_kg INT); INSERT INTO market_trends (id,year,price_per_kg,total_kg) VALUES (1,2019,50.65,23000),(2,2019,45.32,25000),(3,2021,60.23,18000),(4,2021,65.11,19000);
DELETE FROM market_trends WHERE year = 2021;
How many users from Mexico have posted more than once in the past month?
CREATE TABLE users (id INT,country VARCHAR(2)); INSERT INTO users (id,country) VALUES (1,'US'),(2,'CA'),(3,'MX'),(4,'US'),(5,'CA'),(6,'MX'); CREATE TABLE posts (id INT,user_id INT,likes INT,timestamp DATETIME); INSERT INTO posts (id,user_id,likes,timestamp) VALUES (1,1,10,'2022-01-01 00:00:00'),(2,1,15,'2022-01-05 12:3...
SELECT COUNT(DISTINCT posts.user_id) FROM posts INNER JOIN users ON posts.user_id = users.id WHERE users.country = 'MX' AND posts.timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) HAVING COUNT(posts.id) > 1;
Which bus stops have more than 1000 visits from passengers with disabilities in the past year?
CREATE TABLE bus_stops (stop_id INT,stop_name VARCHAR(255)); CREATE TABLE bus_stop_visits (visit_id INT,stop_id INT,visit_date DATE,passenger_type VARCHAR(50));
SELECT bs.stop_name FROM bus_stops bs INNER JOIN bus_stop_visits bsv ON bs.stop_id = bsv.stop_id WHERE bsv.passenger_type = 'passenger with disability' AND bsv.visit_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY bs.stop_name HAVING COUNT(bsv.visit_id) > 1000;
How many people in Asia have limited access to technology?
CREATE TABLE technology_access (id INT,person_name TEXT,has_access BOOLEAN,region TEXT); INSERT INTO technology_access (id,person_name,has_access,region) VALUES (1,'John Doe',FALSE,'Asia'),(2,'Jane Smith',TRUE,'North America'),(3,'Alice Johnson',FALSE,'Asia');
SELECT COUNT(*) as limited_access_count FROM technology_access WHERE region = 'Asia' AND has_access = FALSE;
What is the maximum number of animals housed in a wildlife sanctuary in Africa?
CREATE TABLE Wildlife_Sanctuary (Id INT,Name VARCHAR(50),Location VARCHAR(50),Animals_Housed INT); INSERT INTO Wildlife_Sanctuary (Id,Name,Location,Animals_Housed) VALUES (1,'Serengeti','Africa',5000); INSERT INTO Wildlife_Sanctuary (Id,Name,Location,Animals_Housed) VALUES (2,'Kruger','Africa',3000);
SELECT MAX(Animals_Housed) FROM Wildlife_Sanctuary WHERE Location = 'Africa';
How many community education programs were successful in preserving habitats?
CREATE TABLE education_programs (id INT,name VARCHAR(255),habitat_preserved BOOLEAN); INSERT INTO education_programs (id,name,habitat_preserved) VALUES (1,'Save the Wetlands',true),(2,'Trees for Tomorrow',false);
SELECT COUNT(*) FROM education_programs WHERE habitat_preserved = true;
What is the average donation amount for the top 5 donors to the "Education" program?
CREATE TABLE Donations (id INT,donor VARCHAR(50),program VARCHAR(50),amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,donor,program,amount,donation_date) VALUES (1,'John Doe','Education',500.00,'2020-01-01');
SELECT AVG(amount) FROM (SELECT amount FROM Donations WHERE program = 'Education' GROUP BY donor ORDER BY SUM(amount) DESC LIMIT 5) AS Top5Donors;
What is the sum of the 'energy_consumption' for all factories in 'region1' that use renewable energy sources?
CREATE TABLE factories (factory_id INT,region VARCHAR(20),energy_source VARCHAR(20)); CREATE TABLE energy_consumption (factory_id INT,consumption INT); INSERT INTO factories (factory_id,region,energy_source) VALUES (1,'region1','renewable'),(2,'region1','non-renewable'),(3,'region2','renewable'),(4,'region3','non-renew...
SELECT SUM(ec.consumption) FROM energy_consumption ec INNER JOIN factories f ON ec.factory_id = f.factory_id WHERE f.region = 'region1' AND f.energy_source = 'renewable';
What is the average financial capability score for women in Nigeria and Indonesia?
CREATE TABLE afc_scores (name TEXT,gender TEXT,country TEXT,score NUMERIC); INSERT INTO afc_scores (name,gender,country,score) VALUES ('Ada Okora','Female','Nigeria',65),('Dewi Sari','Female','Indonesia',72),('Ali Ahmed','Male','Nigeria',68);
SELECT AVG(score) FROM afc_scores WHERE gender = 'Female' AND country IN ('Nigeria', 'Indonesia');
What are the smart contract addresses for all smart contracts associated with decentralized applications on the EOSIO network?
CREATE TABLE smart_contracts (app_name VARCHAR(255),smart_contract_address VARCHAR(255)); INSERT INTO smart_contracts (app_name,smart_contract_address) VALUES ('EOSDAC','EOS567...'); INSERT INTO smart_contracts (app_name,smart_contract_address) VALUES ('Equilibrium','EOS890...');
SELECT smart_contract_address FROM smart_contracts WHERE app_name IN (SELECT app_name FROM eosio_network);
What is the minimum light intensity in field I in the last month?
CREATE TABLE Light (field VARCHAR(50),date DATE,light_intensity FLOAT); INSERT INTO Light (field,date,light_intensity) VALUES ('Field I','2022-05-01',82.5),('Field I','2022-05-02',85.6),('Field I','2022-05-03',88.2);
SELECT MIN(light_intensity) FROM Light WHERE field = 'Field I' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY);
What is the average length of a tunnel in the 'tunnels' table?
CREATE TABLE tunnels (tunnel_id INT,tunnel_name VARCHAR(50),location VARCHAR(50),length DECIMAL(10,2));
SELECT AVG(length) FROM tunnels;
What is the total budget allocated for policy advocacy efforts for autism spectrum disorder in the Central region for 2024 and 2025?
CREATE TABLE PolicyAdvocacy (PolicyID INT,DisabilityType VARCHAR(50),Region VARCHAR(50),AllocationYear INT,Budget DECIMAL(10,2)); INSERT INTO PolicyAdvocacy (PolicyID,DisabilityType,Region,AllocationYear,Budget) VALUES (1,'Autism Spectrum Disorder','Central',2024,25000),(2,'Autism Spectrum Disorder','Central',2025,3000...
SELECT SUM(Budget) FROM PolicyAdvocacy WHERE DisabilityType = 'Autism Spectrum Disorder' AND Region = 'Central' AND AllocationYear IN (2024, 2025);
What's the maximum budget for an AI project in the USA?
CREATE TABLE ai_projects (id INT,country VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO ai_projects (id,country,budget) VALUES (1,'Canada',500000.00),(2,'USA',700000.00),(3,'Mexico',300000.00);
SELECT MAX(budget) FROM ai_projects WHERE country = 'USA';
Delete the graduate student with id 4 from the 'students' table.
CREATE TABLE students (id INT,region TEXT,start_year INT); INSERT INTO students (id,region,start_year) VALUES (1,'India',2019),(2,'China',2020),(3,'Japan',2018),(4,'Mexico',2021);
DELETE FROM students WHERE id = 4;
What is the total donation amount for donors aged 40-50 supporting disability causes in 2020?
CREATE TABLE Donations (id INT,donor_id INT,donor_age INT,cause VARCHAR(255),amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,donor_id,donor_age,cause,amount,donation_date) VALUES (1,1001,45,'Disability',5000,'2020-12-05'),(2,1002,35,'Climate Change',3000,'2020-08-15'),(3,1003,50,'Disability',7000,'2...
SELECT SUM(amount) as total_donation FROM Donations WHERE donation_date BETWEEN '2020-01-01' AND '2020-12-31' AND donor_age BETWEEN 40 AND 50 AND cause = 'Disability';
What was the social impact of the programs in Q3 2021?
CREATE TABLE SocialImpact (ProgramID int,ProgramName varchar(50),ImpactScore int); INSERT INTO SocialImpact (ProgramID,ProgramName,ImpactScore) VALUES (1,'Environment',75); INSERT INTO SocialImpact (ProgramID,ProgramName,ImpactScore) VALUES (2,'Technology',85);
SELECT 'Q3 2021' as Period, ProgramName, AVG(ImpactScore) as AverageImpact FROM SocialImpact WHERE DonationDate BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY ProgramName ORDER BY AverageImpact DESC, ProgramName ASC;
What is the total funding received by biotech startups in India?
CREATE TABLE biotech_startups (id INT,name VARCHAR(50),budget DECIMAL(10,2),region VARCHAR(50)); INSERT INTO biotech_startups (id,name,budget,region) VALUES (1,'Genetix',5000000.00,'India'); INSERT INTO biotech_startups (id,name,budget,region) VALUES (2,'BioEngineerz',7000000.00,'USA'); INSERT INTO biotech_startups (id...
SELECT SUM(budget) FROM biotech_startups WHERE region = 'India';
What was the average R&D expenditure per country in '2020'?
CREATE TABLE rd_2020(country varchar(20),expenditure int); INSERT INTO rd_2020(country,expenditure) VALUES('US',12000),('Canada',9000);
SELECT country, AVG(expenditure) FROM rd_2020 GROUP BY country
How many employees of color work in the mining industry in California and New York?
CREATE TABLE MiningEmployees (State VARCHAR(50),EmployeeRace VARCHAR(50),EmployeeCount INT); INSERT INTO MiningEmployees(State,EmployeeRace,EmployeeCount) VALUES ('California','Hispanic',500),('California','Black',300),('California','Asian',700),('New York','Hispanic',350),('New York','Black',400),('New York','Asian',6...
SELECT State, SUM(EmployeeCount) FROM MiningEmployees WHERE EmployeeRace IN ('Hispanic', 'Black', 'Asian') AND State IN ('California', 'New York') GROUP BY State;
Insert a new record into the food_inspections table for a food safety inspection that occurred on March 10, 2022 with a score of 95
CREATE TABLE food_inspections (inspection_id INT,restaurant_id INT,inspection_date DATE,inspector_id INT,score INT);
INSERT INTO food_inspections (inspection_id, restaurant_id, inspection_date, inspector_id, score) VALUES (1001, 56, '2022-03-10', 34, 95);
Show the number of marine species in each family in the 'species_families' table, sorted by the number of species in descending order.
CREATE TABLE species_families (family_id INT,family_name VARCHAR(50),species_count INT);
SELECT family_name, COUNT(*) FROM species_families GROUP BY family_id ORDER BY species_count DESC;
Show me the top 3 sustainable seafood options by protein content.
CREATE TABLE SustainableSeafood (id INT,name VARCHAR(50),protein INT); INSERT INTO SustainableSeafood (id,name,protein) VALUES (1,'Albacore Tuna',25),(2,'Pacific Cod',20),(3,'Atlantic Salmon',22),(4,'Wild Shrimp',18);
SELECT * FROM SustainableSeafood ORDER BY protein DESC LIMIT 3;
What is the average salary of all employees in the 'employees' table?
CREATE TABLE employees (id INT PRIMARY KEY,name VARCHAR(50),salary DECIMAL(10,2));
SELECT AVG(salary) FROM employees;
What is the total calorie expenditure for each workout?
CREATE TABLE workout_data (workout_id INT,member_id INT,workout_duration TIME,calories FLOAT); INSERT INTO workout_data (workout_id,member_id,workout_duration,calories) VALUES (1,1,'01:00:00',300),(2,1,'01:30:00',450),(3,2,'02:00:00',600),(4,2,'01:15:00',412.5),(5,3,'01:00:00',250),(6,3,'01:30:00',375),(7,4,'02:00:00',...
SELECT workout_id, SUM(calories) FROM workout_data GROUP BY workout_id;
What is the total CO2 emission for food delivery in Japan?
CREATE TABLE deliveries (id INT,company VARCHAR(50),co2_emission INT); INSERT INTO deliveries (id,company,co2_emission) VALUES (1,'Company A',50),(2,'Company B',30);
SELECT SUM(co2_emission) FROM deliveries WHERE country = 'Japan';
Who is the mayor in the city with the highest population?
CREATE TABLE City (id INT,name VARCHAR(50),population INT); INSERT INTO City (id,name,population) VALUES (1,'CityA',50000); INSERT INTO City (id,name,population) VALUES (2,'CityB',75000); INSERT INTO City (id,name,population) VALUES (3,'CityC',80000); CREATE TABLE GovernmentEmployee (id INT,name VARCHAR(50),position VA...
SELECT GovernmentEmployee.name FROM GovernmentEmployee INNER JOIN City ON GovernmentEmployee.city_id = City.id WHERE City.population = (SELECT MAX(population) FROM City);
What is the total number of satellites launched by each company?
CREATE TABLE satellites (id INT PRIMARY KEY,company VARCHAR(50),launch_year INT); INSERT INTO satellites (id,company,launch_year) VALUES (1,'SpaceX',2018),(2,'Rocket Lab',2019),(3,'SpaceX',2020),(4,'Rocket Lab',2021);
SELECT company, COUNT(*) FROM satellites GROUP BY company;
What is the distribution of articles by word count in the 'investigative' category?
CREATE TABLE categories (id INT,name TEXT); CREATE TABLE articles (id INT,title TEXT,content TEXT,category_id INT); INSERT INTO categories (id,name) VALUES (1,'Politics'),(2,'Technology'),(3,'Sports'),(4,'International'),(5,'Investigative'); INSERT INTO articles (id,title,content,category_id) VALUES (1,'Article 1','Con...
SELECT articles.category_id, LENGTH(articles.content) - LENGTH(REPLACE(articles.content, ' ', '')) + 1 as word_count, COUNT(*) as count FROM articles WHERE category_id = 5 GROUP BY word_count ORDER BY count DESC;
What is the average number of community events attended by visitors from Texas?
CREATE TABLE visitor_attendance (visitor_id INT,state VARCHAR(30),event_name VARCHAR(50)); INSERT INTO visitor_attendance (visitor_id,state,event_name) VALUES (1,'Texas','Art Festival'),(2,'California','Art Exhibition'),(3,'New York','History Day');
SELECT state, AVG(count_events) FROM (SELECT state, event_name, COUNT(event_name) OVER (PARTITION BY visitor_id) as count_events FROM visitor_attendance) as subquery GROUP BY state;
What is the average account balance for customers in the Private Banking division, excluding customers with account balances below $10,000?
CREATE TABLE Private_Banking (customer_id INT,name VARCHAR(50),division VARCHAR(20),account_balance DECIMAL(10,2)); INSERT INTO Private_Banking (customer_id,name,division,account_balance) VALUES (11,'Olivia White','Private Banking',12000.00),(12,'Sophia Black','Private Banking',15000.00),(13,'Isabella Gray','Private Ba...
SELECT AVG(account_balance) FROM Private_Banking WHERE account_balance >= 10000;
How many professional development courses were offered in each region in 2021?
CREATE TABLE regions (region_id INT,region_name VARCHAR(255)); INSERT INTO regions VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); CREATE TABLE courses (course_id INT,course_name VARCHAR(255),region_id INT,course_year INT); INSERT INTO courses VALUES (1,'Teaching Strategies',1,2021),(2,'Curriculum Design',2,2021)...
SELECT r.region_name, COUNT(c.course_id) as total_courses FROM courses c JOIN regions r ON c.region_id = r.region_id WHERE c.course_year = 2021 GROUP BY r.region_name;
What is the average number of hours spent on open pedagogy projects by teachers from each department?
CREATE TABLE departments (department_id INT,department_name TEXT); CREATE TABLE teachers (teacher_id INT,teacher_name TEXT,department_id INT,hours_spent_on_projects INT); INSERT INTO departments VALUES (1,'Mathematics'),(2,'Science'),(3,'English'); INSERT INTO teachers VALUES (1,'Mr. Smith',1,10),(2,'Ms. Johnson',2,15)...
SELECT d.department_name, AVG(t.hours_spent_on_projects) FROM departments d INNER JOIN teachers t ON d.department_id = t.department_id GROUP BY d.department_id;
What are the top 5 most visited cities in the world in 2022?
CREATE TABLE city_visitors (id INT,city TEXT,num_visitors INT,visit_year INT); INSERT INTO city_visitors (id,city,num_visitors,visit_year) VALUES (1,'Paris',15000000,2022),(2,'London',14000000,2022),(3,'Dubai',13000000,2022);
SELECT city, SUM(num_visitors) AS total_visitors FROM city_visitors WHERE visit_year = 2022 GROUP BY city ORDER BY total_visitors DESC LIMIT 5;
What is the total number of social good technology projects implemented in Africa and Asia between 2018 and 2020?
CREATE TABLE Project (ProjectID int,ProjectName varchar(255),Location varchar(255),StartDate date,EndDate date); INSERT INTO Project (ProjectID,ProjectName,Location,StartDate,EndDate) VALUES (1,'AI-based healthcare platform','Kenya','2018-01-01','2020-12-31'),(2,'Smart agriculture platform','India','2019-01-01','2020-1...
SELECT COUNT(*) as NumProjects FROM Project WHERE (Location = 'Africa' OR Location = 'Asia') AND YEAR(StartDate) BETWEEN 2018 AND 2020;
How many articles were published in French and English news websites in 2021, and what is the total word count for each language?
CREATE TABLE articles (id INT,title VARCHAR(255),publish_date DATE,language VARCHAR(5),word_count INT,website VARCHAR(255)); INSERT INTO articles (id,title,publish_date,language,word_count,website) VALUES (1,'Article1','2021-01-01','French',800,'NewsWebsite1'); INSERT INTO articles (id,title,publish_date,language,word_...
SELECT language, COUNT(*) as article_count, SUM(word_count) as total_word_count FROM articles WHERE publish_date >= '2021-01-01' AND publish_date < '2022-01-01' GROUP BY language;
How many cases were opened and closed in each court during the current year?
CREATE TABLE CourtCases (ID INT,Court VARCHAR(20),CaseType VARCHAR(20),OpenDate DATE,CloseDate DATE); INSERT INTO CourtCases (ID,Court,CaseType,OpenDate,CloseDate) VALUES (1,'Court1','Civil','2022-01-01','2022-06-30'),(2,'Court2','Criminal','2022-02-01','2022-12-31'),(3,'Court1','Civil','2022-04-01','2022-11-30');
SELECT Court, COUNT(CASE WHEN EXTRACT(MONTH FROM OpenDate) = EXTRACT(MONTH FROM CURRENT_DATE) AND EXTRACT(YEAR FROM OpenDate) = EXTRACT(YEAR FROM CURRENT_DATE) THEN 1 END) AS CasesOpened, COUNT(CASE WHEN EXTRACT(MONTH FROM CloseDate) = EXTRACT(MONTH FROM CURRENT_DATE) AND EXTRACT(YEAR FROM CloseDate) = EXTRACT(YEAR FRO...
What is the total quantity of sustainable materials used by the top 3 manufacturers in the 'Europe' region, ordered by the total quantity of sustainable materials used?
CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50),Region VARCHAR(50)); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName,Region) VALUES (1,'EcoFriendlyFabrics','Europe'),(2,'GreenYarns','Asia'),(3,'SustainableTextiles','Europe'),(4,'EcoWeaves','Europe'); CREATE TABLE Materials (Materi...
SELECT ManufacturerName, SUM(QuantityUsed) AS TotalQuantity FROM Materials INNER JOIN Manufacturers ON Materials.ManufacturerID = Manufacturers.ManufacturerID WHERE Region = 'Europe' GROUP BY ManufacturerName ORDER BY TotalQuantity DESC FETCH FIRST 3 ROWS ONLY;
Update timber production volume for Canada in 2021
CREATE TABLE timber_production (country_code CHAR(3),year INT,volume INT); INSERT INTO timber_production (country_code,year,volume) VALUES ('CAN',2022,15000),('CAN',2021,14000),('USA',2022,20000),('USA',2021,18000);
UPDATE timber_production SET volume = 14500 WHERE country_code = 'CAN' AND year = 2021;
Show the total revenue for each music genre available on the 'mobile' platform.
CREATE TABLE artists (id INT,name TEXT,genre TEXT); CREATE TABLE albums (id INT,title TEXT,artist_id INT,platform TEXT); CREATE TABLE sales (id INT,album_id INT,quantity INT,revenue DECIMAL); CREATE VIEW genre_sales_mobile AS SELECT ar.genre,SUM(s.revenue) as total_revenue FROM albums a JOIN sales s ON a.id = s.album_i...
SELECT genre, total_revenue FROM genre_sales_mobile;
Insert a new heritage site in Oceania into the 'heritage_sites' table
CREATE TABLE heritage_sites (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),year INT);
INSERT INTO heritage_sites (id, name, location, year) VALUES (1, 'Taputapuatea', 'French Polynesia', 2017);
Identify vessels that have not entered a port in the last 30 days.
CREATE TABLE Vessels (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50),length FLOAT,max_speed FLOAT); CREATE TABLE Port_Visits (id INT PRIMARY KEY,vessel_id INT,port_id INT,visit_date DATE);
SELECT Vessels.name FROM Vessels LEFT JOIN Port_Visits ON Vessels.id = Port_Visits.vessel_id WHERE Port_Visits.visit_date > DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) IS NULL;