instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many policyholders have a policy start date within the last 30 days, and what is the total number of policies?
CREATE TABLE policyholders (id INT,policy_start_date DATE); INSERT INTO policyholders (id,policy_start_date) VALUES (1,'2022-01-01'),(2,'2022-01-15'),(3,'2021-12-30');
SELECT COUNT(DISTINCT id), COUNT(*) FROM policyholders WHERE policy_start_date >= NOW() - INTERVAL 30 DAY;
Identify unions in New York with the highest increase in wage increases in collective bargaining contracts compared to the previous contract.
CREATE TABLE UnionNegotiations (id INT PRIMARY KEY,union_id INT,negotiation_date DATE); CREATE TABLE CollectiveBargaining (id INT PRIMARY KEY,union_id INT,contract_start DATE,contract_end DATE,wage_increase DECIMAL(5,2)); CREATE TABLE UnionMembers (id INT PRIMARY KEY,name VARCHAR(50),state VARCHAR(2),union_id INT,FOREIGN KEY (union_id) REFERENCES UnionNegotiations(union_id));
SELECT u.name, u.state, c.wage_increase, c.contract_end, (SELECT wage_increase FROM CollectiveBargaining cb WHERE cb.contract_end < c.contract_end AND cb.union_id = c.union_id ORDER BY contract_end DESC LIMIT 1) AS previous_wage_increase FROM UnionMembers u JOIN UnionNegotiations n ON u.union_id = n.union_id JOIN CollectiveBargaining c ON u.union_id = c.union_id WHERE u.state = 'NY' ORDER BY c.wage_increase - (SELECT wage_increase FROM CollectiveBargaining cb WHERE cb.contract_end < c.contract_end AND cb.union_id = c.union_id ORDER BY contract_end DESC LIMIT 1) DESC LIMIT 10;
What is the total number of labor rights advocacy events for each region, by region name?
CREATE TABLE Region (Id INT,Name VARCHAR(50)); INSERT INTO Region (Id,Name) VALUES (1,'Region A'),(2,'Region B'),(3,'Region C'); CREATE TABLE AdvocacyEvents (Id INT,RegionId INT,EventCount INT); INSERT INTO AdvocacyEvents (Id,RegionId,EventCount) VALUES (1,1,50),(2,1,30),(3,2,70),(4,2,80),(5,3,60),(6,3,40);
SELECT R.Name, SUM(A.EventCount) as TotalEvents FROM Region R JOIN AdvocacyEvents A ON R.Id = A.RegionId GROUP BY R.Name;
Create a view for the top 5 manufacturers with the highest average safety test scores
CREATE TABLE vehicle_safety_testing (id INT PRIMARY KEY,manufacturer VARCHAR(255),model VARCHAR(255),test_score INT);
CREATE VIEW top_safety_scores AS SELECT manufacturer, AVG(test_score) as avg_score FROM vehicle_safety_testing GROUP BY manufacturer ORDER BY avg_score DESC LIMIT 5;
Delete vessels that have not been inspected in the last 12 months
CREATE TABLE vessel_inspection (vessel_id INT,inspection_date DATE); INSERT INTO vessel_inspection (vessel_id,inspection_date) VALUES (1,'2020-01-01'),(2,'2021-06-15'),(3,'2019-12-20');
DELETE FROM vessel_inspection WHERE vessel_id IN (SELECT vessel_id FROM vessel_inspection WHERE inspection_date < DATE_SUB(CURDATE(), INTERVAL 12 MONTH));
Find the total number of visitors from Asian countries in the last 2 years.
CREATE TABLE Visitors (id INT,country VARCHAR(50),visit_year INT,gender VARCHAR(10)); CREATE VIEW Asian_Countries AS SELECT 'China' AS country UNION ALL SELECT 'Japan' UNION ALL SELECT 'India';
SELECT COUNT(*) FROM Visitors INNER JOIN Asian_Countries ON Visitors.country = Asian_Countries.country WHERE visit_year BETWEEN 2020 AND 2021;
List all visitors who have attended the 'Digital Impressionist' installation
CREATE TABLE Visitors (id INT,age INT,gender VARCHAR(255)); CREATE TABLE Interactive_Installations (id INT,name VARCHAR(255),type VARCHAR(255)); CREATE TABLE Interactions (id INT,visitor_id INT,installation_id INT);
SELECT Visitors.id, Visitors.age, Visitors.gender FROM Visitors JOIN Interactions ON Visitors.id = Interactions.visitor_id WHERE Interactions.installation_id = (SELECT id FROM Interactive_Installations WHERE name = 'Digital Impressionist');
What is the number of visitors from the LGBTQ+ community who visited the museum in 2021?
CREATE TABLE Visitors (id INT,community_identifier VARCHAR(255),visit_date DATE); CREATE TABLE CommunityIdentifiers (id INT,name VARCHAR(255));
SELECT COUNT(*) FROM Visitors INNER JOIN CommunityIdentifiers ON Visitors.community_identifier = CommunityIdentifiers.name WHERE CommunityIdentifiers.name = 'LGBTQ+ Community' AND Visitors.visit_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the average landfill capacity in megatons in the United States and Canada?
CREATE TABLE LandfillCapacity (country VARCHAR(50),capacity_mt FLOAT);
SELECT AVG(capacity_mt) FROM LandfillCapacity WHERE country IN ('United States', 'Canada');
What is the change in recycling rate for Australia between the years 2017 and 2018?
CREATE TABLE recycling_rates (country VARCHAR(50),year INT,recycling_rate FLOAT); INSERT INTO recycling_rates (country,year,recycling_rate) VALUES ('Australia',2017,0.52),('Australia',2018,0.54);
SELECT (LAG(recycling_rate, 1) OVER (PARTITION BY country ORDER BY year) - recycling_rate) * 100 FROM recycling_rates WHERE country = 'Australia';
How many droughts were declared in Florida and New York between 2015 and 2020?
CREATE TABLE drought_declarations (state VARCHAR(50),year INT,number_of_droughts INT); INSERT INTO drought_declarations (state,year,number_of_droughts) VALUES ('Florida',2015,1),('Florida',2016,2),('Florida',2017,3),('Florida',2018,4),('Florida',2019,5),('Florida',2020,6),('New York',2015,1),('New York',2016,2),('New York',2017,3),('New York',2018,4),('New York',2019,5),('New York',2020,6);
SELECT state, SUM(number_of_droughts) AS total_droughts FROM drought_declarations WHERE state IN ('Florida', 'New York') AND year BETWEEN 2015 AND 2020 GROUP BY state;
Identify the sector with the highest water usage in the Asian region.
CREATE TABLE water_usage (region VARCHAR(20),sector VARCHAR(20),usage INT); INSERT INTO water_usage (region,sector,usage) VALUES ('Asia','Agriculture',800),('Asia','Domestic',500),('Asia','Industrial',1000),('Africa','Agriculture',600),('Africa','Domestic',300),('Africa','Industrial',700);
SELECT sector, MAX(usage) FROM water_usage WHERE region = 'Asia'
Insert a new record for Arizona in 2021 with a water usage of 8000.
CREATE TABLE water_usage(state VARCHAR(20),year INT,usage FLOAT);
INSERT INTO water_usage (state, year, usage) VALUES ('Arizona', 2021, 8000);
What is the total water conservation spending for each state in the US?
CREATE TABLE us_conservation (state VARCHAR(255),year INT,spending FLOAT); INSERT INTO us_conservation (state,year,spending) VALUES ('California',2010,2500000),('California',2011,2700000),('California',2012,3000000),('Texas',2010,2000000),('Texas',2011,2200000),('Texas',2012,2400000),('Florida',2010,1800000),('Florida',2011,2000000),('Florida',2012,2200000);
SELECT state, SUM(spending) FROM us_conservation GROUP BY state;
Identify the most active users in the last week.
CREATE TABLE user_activity (id INT,user_id INT,activity_level INT,activity_date DATE);
SELECT user_id, AVG(activity_level) as avg_activity_level FROM user_activity WHERE activity_date >= (CURRENT_DATE - INTERVAL '7 days') GROUP BY user_id ORDER BY avg_activity_level DESC;
What is the total duration of workout sessions for users who have completed at least 5 sessions of a specific workout type (e.g. cycling)?
CREATE TABLE workout_sessions_details (id INT,user_id INT,workout_type VARCHAR(20),duration TIME); INSERT INTO workout_sessions_details (id,user_id,workout_type,duration) VALUES (1,1,'Cycling','01:00:00'),(2,1,'Yoga','00:45:00'),(3,2,'Cycling','01:15:00');
SELECT SUM(duration) FROM workout_sessions_details WHERE workout_type = 'Cycling' AND user_id IN (SELECT user_id FROM workout_sessions_details GROUP BY user_id HAVING COUNT(*) >= 5);
What is the maximum size, in hectares, of rural infrastructure projects in India?
CREATE TABLE rural_infrastructure_projects (id INT,name TEXT,size_ha FLOAT,country TEXT); INSERT INTO rural_infrastructure_projects (id,name,size_ha,country) VALUES (1,'Project E',75.6,'India'); INSERT INTO rural_infrastructure_projects (id,name,size_ha,country) VALUES (2,'Project F',98.2,'India');
SELECT MAX(size_ha) FROM rural_infrastructure_projects WHERE country = 'India';
What is the total funding (in USD) for rural infrastructure projects in Africa?
CREATE TABLE Rural_Infrastructure_Projects (id INT,project_name TEXT,funding_amount FLOAT,region TEXT); INSERT INTO Rural_Infrastructure_Projects (id,project_name,funding_amount,region) VALUES (1,'Water Access',200000.00,'Africa'),(2,'Road Upgrade',300000.00,'Africa');
SELECT SUM(funding_amount) FROM Rural_Infrastructure_Projects WHERE region = 'Africa';
What is the total number of satellites manufactured by SpaceTech in 2020?
CREATE TABLE Satellites (id INT,name VARCHAR(100),manufacturer VARCHAR(100),launch_date DATE); INSERT INTO Satellites (id,name,manufacturer,launch_date) VALUES (1,'Sat1','SpaceTech','2020-01-01'); INSERT INTO Satellites (id,name,manufacturer,launch_date) VALUES (2,'Sat2','SpaceTech','2019-12-15');
SELECT COUNT(*) FROM Satellites WHERE manufacturer = 'SpaceTech' AND EXTRACT(YEAR FROM launch_date) = 2020;
How many farms of each type are there, grouped by farm type?
CREATE TABLE farm_count_by_type (farm_id INT,farm_type VARCHAR(255)); INSERT INTO farm_count_by_type (farm_id,farm_type) VALUES (1,'Pond'),(2,'Cage'),(3,'Recirculating'),(4,'Pond'),(5,'Cage'),(6,'Pond'),(7,'Cage'),(8,'Recirculating');
SELECT farm_type, COUNT(*) FROM farm_count_by_type GROUP BY farm_type;
Find the number of unique audience demographics
CREATE TABLE Audience (id INT,name TEXT,age INT,gender TEXT,city TEXT); INSERT INTO Audience (id,name,age,gender,city) VALUES (1,'John Doe',25,'Male','New York'),(2,'Jane Smith',35,'Female','Los Angeles'),(3,'Bob Johnson',45,'Male','Chicago');
SELECT COUNT(DISTINCT city, age, gender) FROM Audience;
How many visitors attended events by city in 2020?
CREATE TABLE Events (event_id INT,city VARCHAR(50),num_visitors INT,event_date DATE); INSERT INTO Events (event_id,city,num_visitors,event_date) VALUES (1,'New York',100,'2020-01-01'),(2,'London',150,'2020-02-01'),(3,'Tokyo',75,'2020-03-01');
SELECT city, SUM(num_visitors) AS total_visitors FROM Events WHERE YEAR(event_date) = 2020 GROUP BY city;
What is the number of performances in the 'Performances' table with a duration greater than 60 minutes?
CREATE TABLE Performances (id INT,name VARCHAR(50),date DATE,duration INT); INSERT INTO Performances (id,name,date,duration) VALUES (1,'Play','2020-01-01',90);
SELECT COUNT(*) FROM Performances WHERE duration > 60;
How many movies were released by Studio Ghibli between 1985 and 2010?
CREATE TABLE Studio_Ghibli (title TEXT,year INTEGER); INSERT INTO Studio_Ghibli (title,year) VALUES ('Movie1',1986),('Movie2',1988),('Movie3',1992),('Movie4',1997),('Movie5',2001),('Movie6',2004),('Movie7',2008),('Movie8',2010);
SELECT COUNT(*) FROM Studio_Ghibli WHERE year BETWEEN 1985 AND 2010;
What is the minimum number of days to complete a green construction project in Rio de Janeiro with a budget of over $10 million?
CREATE TABLE Green_Project_Timelines (Project_ID INT,City VARCHAR(50),Budget DECIMAL(10,2),Days_To_Complete INT);
SELECT MIN(Days_To_Complete) FROM Green_Project_Timelines WHERE City = 'Rio de Janeiro' AND Budget > 10000000;
What is the total budget for construction projects in Texas that started in 2016?
CREATE TABLE Project_Budget (id INT,project_name TEXT,state TEXT,start_date DATE,budget INT); INSERT INTO Project_Budget (id,project_name,state,start_date,budget) VALUES (1,'Highway Expansion','Texas','2016-03-15',2500000),(2,'School Addition','Texas','2016-12-31',1500000);
SELECT SUM(budget) FROM Project_Budget WHERE state = 'Texas' AND start_date LIKE '2016-%';
How many unique customers made purchases in the state of California in the month of January 2021?
CREATE TABLE customers (id INT,state VARCHAR(50),month INT,year INT,purchase INT); INSERT INTO customers (id,state,month,year,purchase) VALUES (1,'California',1,2021,1);
SELECT COUNT(DISTINCT customer_id) FROM (SELECT customer_id FROM purchases WHERE state = 'California' AND month = 1 AND year = 2021) AS subquery;
Delete the view for displaying redundant billing data
CREATE VIEW redundant_billing_view AS SELECT bill_id,attorney_id,amount FROM billing_information WHERE amount < 0;
DROP VIEW redundant_billing_view;
What is the number of climate communication campaigns launched in each month for the year 2022?
CREATE TABLE climate_communication (campaign_name VARCHAR(255),launch_date DATE);
SELECT EXTRACT(MONTH FROM launch_date) AS month, COUNT(DISTINCT campaign_name) FROM climate_communication WHERE EXTRACT(YEAR FROM launch_date) = 2022 GROUP BY month;
What are the maximum and minimum R&D expenses for drugs approved in the US?
CREATE TABLE drug_rd_expenses (drug_name TEXT,rd_expenses INTEGER,approval_country TEXT); INSERT INTO drug_rd_expenses (drug_name,rd_expenses,approval_country) VALUES ('DrugX',300000000,'US'),('DrugY',450000000,'US'),('DrugZ',275000000,'US'); CREATE TABLE drug_approval (drug_name TEXT,approval_status TEXT,approval_country TEXT); INSERT INTO drug_approval (drug_name,approval_status,approval_country) VALUES ('DrugX','approved','US'),('DrugY','approved','US'),('DrugW','rejected','US'),('DrugZ','approved','US');
SELECT MAX(rd_expenses) as max_rd_expenses, MIN(rd_expenses) as min_rd_expenses FROM drug_rd_expenses INNER JOIN drug_approval ON drug_rd_expenses.drug_name = drug_approval.drug_name WHERE drug_approval.approval_status = 'approved' AND drug_approval.approval_country = 'US';
Find the name and age of all patients who have received the flu vaccine.
CREATE TABLE patients (id INT,name TEXT,age INT,flu_vaccine BOOLEAN); INSERT INTO patients (id,name,age,flu_vaccine) VALUES (1,'John',65,TRUE); INSERT INTO patients (id,name,age,flu_vaccine) VALUES (2,'Sarah',70,FALSE);
SELECT name, age FROM patients WHERE flu_vaccine = TRUE;
How many flu shots were given in Texas during the month of November in the year 2020?
CREATE TABLE flu_shots (patient_id INT,shot_date DATE,state VARCHAR(2)); INSERT INTO flu_shots (patient_id,shot_date,state) VALUES (1,'2020-11-05','TX');
SELECT COUNT(*) FROM flu_shots WHERE state = 'TX' AND MONTH(shot_date) = 11 AND YEAR(shot_date) = 2020;
What is the average soil pH for each region in the past 3 months?
CREATE TABLE SoilPH (date DATE,soil_pH FLOAT,region VARCHAR(20));
SELECT region, AVG(soil_pH) OVER(PARTITION BY region ORDER BY date ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) as avg_soil_pH FROM SoilPH WHERE date >= DATEADD(month, -3, CURRENT_DATE);
How many employees in 'Accessibility Services' have a master's degree or higher?
CREATE TABLE EmployeeEducation (ID INT,Department TEXT,Degree TEXT); INSERT INTO EmployeeEducation (ID,Department,Degree) VALUES (1,'Accessibility Services','Master''s'),(2,'IT','Bachelor''s'),(3,'Accessibility Services','Doctorate');
SELECT COUNT(*) FROM EmployeeEducation WHERE Department = 'Accessibility Services' AND Degree IN ('Master''s', 'Doctorate');
Delete the species with the lowest primary productivity value.
CREATE TABLE marine_species (id INT PRIMARY KEY,name VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO marine_species (id,name,conservation_status) VALUES (1,'Giant Pacific Octopus','Least Concern'); CREATE TABLE oceanography (id INT PRIMARY KEY,species_id INT,primary_productivity INT); INSERT INTO oceanography (id,species_id,primary_productivity) VALUES (1,1,50);
DELETE FROM marine_species m WHERE m.id = (SELECT o.species_id FROM oceanography o JOIN (SELECT species_id, MIN(primary_productivity) AS min_pp FROM oceanography GROUP BY species_id) o2 ON o.species_id = o2.species_id WHERE o.primary_productivity = o2.min_pp);
What are the top 5 warmest seas and their average temperatures?
CREATE TABLE sea_temps (id INTEGER,name VARCHAR(255),avg_temp REAL);
SELECT name, avg_temp FROM sea_temps ORDER BY avg_temp DESC LIMIT 5;
What is the maximum depth ever recorded for a marine species habitat?
CREATE TABLE species (id INT,name VARCHAR(255),max_habitat_depth FLOAT); INSERT INTO species (id,name,max_habitat_depth) VALUES (1,'Atlantic Salmon',100.0),(2,'Blue Whale',500.0);
SELECT MAX(max_habitat_depth) FROM species;
How many decentralized applications were created by developers from Asia in the year 2021?
CREATE TABLE Developers (id INT,name VARCHAR(255),region VARCHAR(255)); CREATE TABLE DApps (id INT,developer_id INT,creation_date DATE); INSERT INTO Developers (id,name,region) VALUES (1,'DevA','Asia'),(2,'DevB','Europe'),(3,'DevC','Asia'); INSERT INTO DApps (id,developer_id,creation_date) VALUES (1,1,'2021-01-01'),(2,2,'2021-02-01'),(3,3,'2021-03-01'),(4,1,'2021-04-01');
SELECT COUNT(*) FROM DApps JOIN Developers ON DApps.developer_id = Developers.id WHERE Developers.region = 'Asia' AND DApps.creation_date >= '2021-01-01' AND DApps.creation_date < '2022-01-01';
What are the names and balances of all digital assets with a type of 'ERC20'?
CREATE TABLE digital_assets (name TEXT,balance INTEGER,type TEXT); INSERT INTO digital_assets (name,balance,type) VALUES ('Asset1',100,'ERC20'),('Asset2',200,'ERC721');
SELECT name, balance FROM digital_assets WHERE type = 'ERC20';
What are the top 5 digital assets by market capitalization?
CREATE TABLE digital_assets (asset_id INT,name VARCHAR(100),market_cap DECIMAL(20,2)); INSERT INTO digital_assets (asset_id,name,market_cap) VALUES (1,'Asset1',500000),(2,'Asset2',350000),(3,'Asset3',275000),(4,'Asset4',200000),(5,'Asset5',150000);
SELECT name, market_cap FROM digital_assets ORDER BY market_cap DESC LIMIT 5;
What is the average age of artists ('artist_demographics' table) by nationality?
CREATE TABLE artist_demographics (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),nationality VARCHAR(50));
SELECT nationality, AVG(age) FROM artist_demographics GROUP BY nationality;
What is the total transaction amount for each employee in the Risk Management department?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO employees (id,name,department) VALUES (1,'John Doe','Compliance'),(2,'Jane Smith','Risk Management'); CREATE TABLE transactions (employee_id INT,transaction_amount DECIMAL(10,2)); INSERT INTO transactions (employee_id,transaction_amount) VALUES (1,200.00),(1,300.00),(2,100.00),(2,400.00);
SELECT e.name, SUM(t.transaction_amount) as total_transaction_amount FROM employees e JOIN transactions t ON e.id = t.employee_id WHERE e.department = 'Risk Management' GROUP BY e.name;
Update the names of vessels with the word 'Star' in their current name to 'Galaxy'.
CREATE TABLE vessels (id INT,name TEXT); INSERT INTO vessels (id,name) VALUES (1,'Star Vessel A'); INSERT INTO vessels (id,name) VALUES (2,'Star Vessel B'); INSERT INTO vessels (id,name) VALUES (3,'Non-Star Vessel');
UPDATE vessels SET name = REPLACE(name, 'Star', 'Galaxy') WHERE name LIKE '%Star%';
List the names, types, and last maintenance dates of machines in factories with circular economy initiatives.
CREATE TABLE machines (machine_id INT,name TEXT,type TEXT,last_maintenance DATE); CREATE TABLE factories (factory_id INT,initiative TEXT);
SELECT machines.name, machines.type, machines.last_maintenance FROM machines INNER JOIN factories ON machines.factory_id = factories.factory_id WHERE factories.initiative = 'circular economy';
What are the intelligence agencies in the Asia-Pacific region?
CREATE TABLE IntelligenceAgencies (Country VARCHAR(255),Agency VARCHAR(255)); INSERT INTO IntelligenceAgencies (Country,Agency) VALUES ('China','Ministry of State Security'),('China','National Security Commission'),('Australia','Australian Security Intelligence Organisation'),('Japan','Public Security Intelligence Agency');
SELECT Agency FROM IntelligenceAgencies WHERE Country IN ('China', 'Australia', 'Japan');
Which genres have the highest average track length?
CREATE TABLE music_genres (id INT,genre VARCHAR(255)); INSERT INTO music_genres (id,genre) VALUES (1,'Pop'),(2,'Rock'),(3,'Jazz'),(4,'Hip Hop'); CREATE TABLE tracks (id INT,title VARCHAR(255),length DECIMAL(5,2),genre_id INT); INSERT INTO tracks (id,title,length,genre_id) VALUES (1,'Song 1',3.45,1),(2,'Song 2',4.20,2),(3,'Song 3',5.12,3),(4,'Song 4',2.85,4);
SELECT genre, AVG(length) as avg_length FROM tracks JOIN music_genres ON tracks.genre_id = music_genres.id GROUP BY genre ORDER BY avg_length DESC LIMIT 1;
What is the average donation amount for each program, excluding anonymous donations?
CREATE TABLE donations (id INT,donation_amount DECIMAL(10,2),donation_date DATE,program_name VARCHAR(50)); INSERT INTO donations (id,donation_amount,donation_date,program_name) VALUES (1,50.00,'2021-01-05','Program A'),(2,100.00,'2021-03-15','Program B'),(3,75.00,'2021-01-20','Program A'),(4,150.00,'2021-02-01','Program C'),(5,200.00,'2021-04-01','Program A'); CREATE TABLE programs (id INT,program_name VARCHAR(50)); INSERT INTO programs (id,program_name) VALUES (1,'Program A'),(2,'Program B'),(3,'Program C');
SELECT p.program_name, AVG(d.donation_amount) AS avg_donation FROM donations d JOIN programs p ON d.program_name = p.program_name WHERE d.donor_name != 'Anonymous' GROUP BY p.program_name;
Insert a new record into the 'fields' table for field 'F-02' with operator 'Chevron' and discovery date '2015-01-01'
CREATE TABLE fields (field_id INT,field_name VARCHAR(255),operator VARCHAR(255),discovery_date DATE);
INSERT INTO fields (field_id, field_name, operator, discovery_date) VALUES (NULL, 'F-02', 'Chevron', '2015-01-01');
List the names and nationalities of coaches in the 'coaches' table.
CREATE TABLE coaches (coach_id INT,name VARCHAR(50),nationality VARCHAR(30));
SELECT name, nationality FROM coaches;
Who is the top points scorer for the Lakers?
CREATE TABLE players (player_id INT,player_name VARCHAR(50),team_id INT); INSERT INTO players (player_id,player_name,team_id) VALUES (1,'James',5),(2,'Davis',5),(3,'Green',5); CREATE TABLE games (game_id INT,player_id INT,team_id INT,points INT); INSERT INTO games (game_id,player_id,team_id,points) VALUES (1,1,5,30),(2,2,5,40),(3,1,5,50),(4,3,5,20),(5,1,5,60);
SELECT player_id, player_name, SUM(points) as total_points FROM games JOIN players ON games.player_id = players.player_id WHERE team_id = 5 GROUP BY player_id ORDER BY total_points DESC LIMIT 1;
Find the average number of refugees per country in 'refugee_data' table?
CREATE TABLE refugee_data (id INT,country VARCHAR(255),num_refugees INT); INSERT INTO refugee_data (id,country,num_refugees) VALUES (1,'Country1',1000),(2,'Country2',2000),(3,'Country1',3000);
SELECT country, AVG(num_refugees) as avg_refugees FROM refugee_data GROUP BY country;
What is the total number of refugee families supported by each NGO in the last 6 months in Asia?
CREATE TABLE NGOs (NGOID int,NGOName varchar(50)); INSERT INTO NGOs (NGOID,NGOName) VALUES (1,'Save the Children Asia'),(2,'Plan International Asia'); CREATE TABLE RefugeeSupport (SupportID int,NGOID int,FamilyID int,SupportDate date); INSERT INTO RefugeeSupport (SupportID,NGOID,FamilyID,SupportDate) VALUES (1,1,1,'2022-02-01'),(2,1,2,'2022-03-01'),(3,2,1,'2022-04-01');
SELECT NGOName, COUNT(DISTINCT FamilyID) as SupportedFamilies FROM NGOs INNER JOIN RefugeeSupport ON NGOs.NGOID = RefugeeSupport.NGOID WHERE SupportDate >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND Country = 'Asia' GROUP BY NGOName;
List the names and number of employees of organizations that have participated in digital divide reduction initiatives in the United States and Canada.
CREATE TABLE organizations (organization_id INT,name VARCHAR(50),employees INT,country VARCHAR(50)); INSERT INTO organizations (organization_id,name,employees,country) VALUES (1,'OrgA',1000,'USA'),(2,'OrgB',2000,'Canada'),(3,'OrgC',1500,'USA'),(4,'OrgD',2500,'Canada'); CREATE VIEW digital_divide_initiatives AS SELECT organization_id FROM initiatives WHERE initiative_type = 'digital_divide';
SELECT o.name, COUNT(d.organization_id) FROM organizations o JOIN digital_divide_initiatives d ON o.organization_id = d.organization_id WHERE o.country IN ('USA', 'Canada') GROUP BY o.name;
Update the production cost of all items in the 'summer 2021' collection with a production cost below 15 to 15.
CREATE TABLE production_costs (item_type VARCHAR(20),collection VARCHAR(20),cost NUMERIC(10,2),quantity INT); INSERT INTO production_costs (item_type,collection,cost,quantity) VALUES ('linen blouse','summer 2021',12.99,200),('linen pants','summer 2021',14.99,150),('linen shorts','summer 2021',11.99,100),('linen skirt','summer 2021',13.99,125);
UPDATE production_costs SET cost = 15 WHERE collection = 'summer 2021' AND cost < 15;
What is the total amount spent on recycling programs in Oceania?
CREATE TABLE recycling_programs (id INT,program VARCHAR(100),location VARCHAR(100),amount_spent DECIMAL(10,2)); INSERT INTO recycling_programs (id,program,location,amount_spent) VALUES (1,'Australia Program','Australia',50000),(2,'New Zealand Program','New Zealand',30000),(3,'Fiji Program','Fiji',20000);
SELECT SUM(amount_spent) FROM recycling_programs WHERE location = 'Oceania';
What is the average number of followers gained per day for influencers in the beauty genre?
CREATE TABLE influencers (influencer_id INT,influencer_name VARCHAR(50),genre VARCHAR(50),followers_start INT,followers_end INT,start_date DATE,end_date DATE); INSERT INTO influencers VALUES (201,'Influencer P','Beauty',1000,1500,'2022-01-01','2022-01-10'),(202,'Influencer Q','Beauty',2000,2500,'2022-01-01','2022-01-15');
SELECT genre, AVG(followers_gained_per_day) as avg_followers_gained_per_day FROM (SELECT genre, influencer_name, (followers_end - followers_start) / DATEDIFF(end_date, start_date) as followers_gained_per_day FROM influencers) AS subquery WHERE genre = 'Beauty';
What was the average advertising spend per post in South America in Q4 2022?
CREATE SCHEMA socialmedia;CREATE TABLE ads (id INT,post_id INT,ad_spend DECIMAL(10,2));INSERT INTO ads (id,post_id,ad_spend) VALUES (1,1,25.00),(2,2,35.00);CREATE TABLE posts (id INT,post_type VARCHAR(255),region VARCHAR(255),ad_indicator BOOLEAN);INSERT INTO posts (id,post_type,region,ad_indicator) VALUES (1,'video','South America',TRUE),(2,'image','South America',FALSE);
SELECT AVG(ad_spend) FROM socialmedia.ads INNER JOIN socialmedia.posts ON ads.post_id = posts.id WHERE posts.region = 'South America' AND EXTRACT(MONTH FROM ads.timestamp) BETWEEN 10 AND 12 AND posts.ad_indicator = TRUE;
How many customers in Asia have purchased sustainable fabrics?
CREATE TABLE Customers (customer_id INT,customer_name VARCHAR(50),customer_country VARCHAR(50)); CREATE TABLE Purchases (purchase_id INT,purchase_date DATE,customer_id INT,fabric_id INT); INSERT INTO Customers (customer_id,customer_name,customer_country) VALUES (1,'John Smith','China'),(2,'Jane Doe','Japan'),(3,'Jim Brown','South Korea'); INSERT INTO Purchases (purchase_id,purchase_date,customer_id,fabric_id) VALUES (1,'2021-01-01',1,1),(2,'2021-01-02',2,2),(3,'2021-01-03',3,3);
SELECT COUNT(*) FROM Customers c INNER JOIN Purchases p ON c.customer_id = p.customer_id WHERE c.customer_country = 'Asia';
What is the maximum consecutive number of days with a financial wellbeing score below 60 for each customer?
CREATE TABLE customer_scores (customer_id INT,score_date DATE,financial_wellbeing_score INT); INSERT INTO customer_scores (customer_id,score_date,financial_wellbeing_score) VALUES (1,'2021-01-01',65),(1,'2021-01-02',60),(1,'2021-01-03',55),(1,'2021-01-04',60),(2,'2021-01-01',70),(2,'2021-01-02',75),(2,'2021-01-03',80),(2,'2021-01-04',85);
SELECT customer_id, MAX(consecutive_below_60) FROM (SELECT customer_id, score_date, financial_wellbeing_score, COUNT(*) FILTER (WHERE financial_wellbeing_score < 60) OVER (PARTITION BY customer_id ORDER BY score_date ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING) AS consecutive_below_60 FROM customer_scores) subquery GROUP BY customer_id;
What is the total number of volunteers for each nationality?
CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(50),VolunteerNationality varchar(50),VolunteerSignUpDate date); INSERT INTO Volunteers (VolunteerID,VolunteerName,VolunteerNationality,VolunteerSignUpDate) VALUES (1,'Sophia Garcia','Mexican','2021-05-10'),(2,'Hamza Ahmed','Pakistani','2021-03-22'),(3,'Lea Kim','South Korean','2021-07-18');
SELECT VolunteerNationality, COUNT(*) as TotalVolunteers FROM Volunteers GROUP BY VolunteerNationality;
List all suppliers who provide vegan products, sorted by country
CREATE TABLE products (product_id INT,product_name TEXT,vegan BOOLEAN,supplier_id INT); INSERT INTO products (product_id,product_name,vegan,supplier_id) VALUES (1,'Tofu',true,1),(2,'Carrots',true,1),(3,'Beef',false,2),(4,'Chicken',false,3);
SELECT DISTINCT supplier_id, country FROM products JOIN suppliers ON products.supplier_id = suppliers.supplier_id WHERE vegan = true ORDER BY country;
What was the total weight of shipments from Canada to the United States in January 2021?
CREATE TABLE shipments (id INT,weight FLOAT,origin VARCHAR(255),destination VARCHAR(255),shipped_at TIMESTAMP); INSERT INTO shipments (id,weight,origin,destination,shipped_at) VALUES (1,500.0,'Canada','United States','2021-01-02 10:30:00'),(2,700.0,'Canada','United States','2021-01-05 15:45:00');
SELECT SUM(weight) FROM shipments WHERE origin = 'Canada' AND destination = 'United States' AND shipped_at >= '2021-01-01' AND shipped_at < '2021-02-01';
Which biosensors were developed by 'BioCorp'?
CREATE TABLE Biosensor (biosensor_id INT,name TEXT,developer TEXT); INSERT INTO Biosensor (biosensor_id,name,developer) VALUES (1,'BS1','BioCorp'),(2,'BS2','BioInnov'),(3,'BS3','BioCorp');
SELECT name FROM Biosensor WHERE developer = 'BioCorp';
List the top 5 states with the highest percentage of public participation
CREATE TABLE State (id INT,name VARCHAR(50),population INT,participation DECIMAL(5,2)); INSERT INTO State (id,name,population,participation) VALUES (1,'California',39512223,0.12); INSERT INTO State (id,name,population,participation) VALUES (2,'Texas',29528404,0.15);
SELECT State.name, ROUND(State.participation * 100, 2) AS participation_percentage FROM State ORDER BY participation_percentage DESC LIMIT 5;
Find the average annual research funding for each department in the College of Arts and Humanities, from 2015 to 2020. Order the results by the average annual funding in ascending order.
CREATE TABLE ArtsFunding (id INT,department VARCHAR(255),year INT,funding DECIMAL(10,2));
SELECT department, AVG(funding) as avg_annual_funding FROM ArtsFunding WHERE department LIKE 'Arts%' AND year BETWEEN 2015 AND 2020 GROUP BY department ORDER BY avg_annual_funding ASC;
What is the total number of renewable energy projects in the renewable_energy schema?
CREATE SCHEMA IF NOT EXISTS renewable_energy; CREATE TABLE IF NOT EXISTS renewable_energy.solar_panels (panel_id INT,installed_capacity FLOAT,PRIMARY KEY (panel_id)); CREATE TABLE IF NOT EXISTS renewable_energy.wind_turbines (turbine_id INT,installed_capacity FLOAT,PRIMARY KEY (turbine_id)); INSERT INTO renewable_energy.solar_panels (panel_id,installed_capacity) VALUES (1,1.2),(2,2.1),(3,3.0); INSERT INTO renewable_energy.wind_turbines (turbine_id,installed_capacity) VALUES (1,2.5),(2,3.5),(3,4.5);
SELECT SUM(s.installed_capacity + w.installed_capacity) FROM renewable_energy.solar_panels s CROSS JOIN renewable_energy.wind_turbines w;
What is the total number of language access programs by hospital type?
CREATE TABLE language_access (hospital_type VARCHAR(255),programs INT); INSERT INTO language_access (hospital_type,programs) VALUES ('Teaching',15),('Community',10),('Rural',8),('Urban',12);
SELECT hospital_type, SUM(programs) FROM language_access GROUP BY hospital_type;
Insert a new record into the 'tour_operators' table
CREATE TABLE tour_operators (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),sustainable_tourism BOOLEAN);
INSERT INTO tour_operators (id, name, country, sustainable_tourism) VALUES (1, 'EcoTravel Peru', 'Peru', true);
What is the total revenue generated by eco-friendly hotels in New York?
CREATE TABLE hotel_revenue (hotel_id INT,revenue INT,is_eco_friendly BOOLEAN); INSERT INTO hotel_revenue (hotel_id,revenue,is_eco_friendly) VALUES (1,500000,true),(2,600000,false);
SELECT SUM(revenue) FROM hotel_revenue WHERE is_eco_friendly = true AND city = 'New York';
What is the maximum revenue of online travel agencies in Australia in the past year?
CREATE TABLE australian_agencies (agency_id INT,country TEXT,revenue FLOAT,year INT); INSERT INTO australian_agencies (agency_id,country,revenue,year) VALUES (1,'Australia',120000,2021),(2,'Australia',150000,2022),(3,'Australia',170000,2022);
SELECT MAX(revenue) FROM australian_agencies WHERE country = 'Australia' AND year = 2021;
What is the total food and beverage revenue last month for hotels in 'Bangkok'?
CREATE TABLE revenue (hotel_id INT,revenue_source VARCHAR(50),revenue INT,revenue_date DATE); INSERT INTO revenue (hotel_id,revenue_source,revenue,revenue_date) VALUES (5,'Room revenue',12000,'2022-03-01'),(5,'Food and beverage',4000,'2022-03-02'),(5,'Other revenue',1000,'2022-03-03'); CREATE TABLE hotels (hotel_id INT,city VARCHAR(50)); INSERT INTO hotels (hotel_id,city) VALUES (5,'Bangkok'); CREATE TABLE dates (date DATE); INSERT INTO dates (date) VALUES ('2022-03-01'),('2022-03-02'),('2022-03-03');
SELECT SUM(revenue) FROM revenue JOIN hotels ON revenue.hotel_id = hotels.hotel_id JOIN dates ON revenue.revenue_date = dates.date WHERE hotels.city = 'Bangkok' AND revenue_source = 'Food and beverage' AND dates.date >= DATEADD(month, -1, GETDATE());
What is the total revenue for the 'virtual tours' feature?
CREATE TABLE features (id INT,name TEXT,price FLOAT); INSERT INTO features (id,name,price) VALUES (1,'Virtual tours',10),(2,'Concierge service',20),(3,'Room service',30);
SELECT SUM(price) FROM features WHERE name = 'Virtual tours';
What is the average age of patients who received cognitive behavioral therapy (CBT) in the state of California?
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,state) VALUES (1,35,'Female','California'); INSERT INTO patients (patient_id,age,gender,state) VALUES (2,45,'Male','Texas'); CREATE TABLE treatments (treatment_id INT,patient_id INT,treatment TEXT,date DATE); INSERT INTO treatments (treatment_id,patient_id,treatment,date) VALUES (1,1,'CBT','2021-01-01'); INSERT INTO treatments (treatment_id,patient_id,treatment,date) VALUES (2,2,'Medication','2021-01-02');
SELECT AVG(patients.age) FROM patients INNER JOIN treatments ON patients.patient_id = treatments.patient_id WHERE treatments.treatment = 'CBT' AND patients.state = 'California';
What is the number of patients who received CBT in each region?
CREATE TABLE patients (id INT,region VARCHAR(255),country VARCHAR(255)); INSERT INTO patients (id,region,country) VALUES (1,'North','USA'),(2,'South','USA'),(3,'North','Canada'); CREATE TABLE therapy (patient_id INT,therapy_type VARCHAR(255)); INSERT INTO therapy (patient_id,therapy_type) VALUES (1,'CBT'),(2,'CBT'),(3,'DBT');
SELECT region, COUNT(*) as patient_count FROM patients JOIN therapy ON patients.id = therapy.patient_id WHERE therapy_type = 'CBT' GROUP BY region;
Delete all rows in the comments table with a rating of 1.
CREATE TABLE comments (id INT,article_id INT,user VARCHAR(255),comment TEXT,rating INT);
DELETE FROM comments WHERE rating = 1;
Delete all orders with total less than $10.00
CREATE TABLE orders (order_id INT,customer_id INT,order_date DATE,total DECIMAL(5,2));
DELETE FROM orders WHERE total < 10.00;
What is the average time taken for contract negotiations in the Middle East region?
CREATE TABLE contract_negotiations(id INT,region VARCHAR(20),negotiation_duration INT);
SELECT AVG(negotiation_duration) FROM contract_negotiations WHERE region = 'Middle East';
List all environmental impact assessments for mining operations in Africa.
CREATE TABLE mining_operation (id INT,name VARCHAR(255),location VARCHAR(255));CREATE TABLE environmental_assessment (id INT,mining_operation_id INT,date DATE,impact VARCHAR(255)); INSERT INTO mining_operation (id,name,location) VALUES (1,'African Gold','Ghana'); INSERT INTO mining_operation (id,name,location) VALUES (2,'Diamond Mining','Botswana'); INSERT INTO environmental_assessment (id,mining_operation_id,date,impact) VALUES (1,1,'2020-01-01','Water pollution');
SELECT mining_operation.name, environmental_assessment.date, environmental_assessment.impact FROM mining_operation JOIN environmental_assessment ON mining_operation.id = environmental_assessment.mining_operation_id WHERE mining_operation.location = 'Africa';
What is the average age of employees working in the 'Mining Operations' department?
CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Age INT); INSERT INTO Employees (EmployeeID,Name,Department,Age) VALUES (1,'John Doe','Mining Operations',35); INSERT INTO Employees (EmployeeID,Name,Department,Age) VALUES (2,'Jane Smith','Mining Operations',40);
SELECT AVG(Age) FROM Employees WHERE Department = 'Mining Operations';
Which mines had more than 10 accidents in 2020?
CREATE TABLE accident (id INT,mine_id INT,date DATE,description TEXT); INSERT INTO accident (id,mine_id,date,description) VALUES (1,1,'2020-01-01','Equipment malfunction'),(2,2,'2020-02-01','Power outage');
SELECT mine_id FROM accident WHERE date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY mine_id HAVING COUNT(*) > 10;
What is the average data usage per mobile subscriber in each state?
CREATE TABLE mobile_subscriber_data (subscriber_id INT,state VARCHAR(20),data_usage FLOAT); INSERT INTO mobile_subscriber_data (subscriber_id,state,data_usage) VALUES (1,'California',500),(2,'Texas',600),(3,'Florida',700);
SELECT state, AVG(data_usage) AS avg_data_usage FROM mobile_subscriber_data GROUP BY state;
What is the minimum data usage for postpaid mobile customers in the city of Detroit?
CREATE TABLE postpaid_mobile (customer_id INT,data_usage FLOAT,city VARCHAR(20)); INSERT INTO postpaid_mobile (customer_id,data_usage,city) VALUES (1,2.5,'Detroit'),(2,3.2,'Detroit'),(3,1.8,'Detroit');
SELECT MIN(data_usage) FROM postpaid_mobile WHERE city = 'Detroit';
What is the total number of articles published by each author in a specific year and month from the 'investigative_reports' table?
CREATE TABLE investigative_reports (id INT,title VARCHAR(255),author VARCHAR(255),publication_date DATE);
SELECT author, EXTRACT(YEAR FROM publication_date) as year, EXTRACT(MONTH FROM publication_date) as month, COUNT(*) as total_articles FROM investigative_reports WHERE EXTRACT(YEAR FROM publication_date) = 2021 AND EXTRACT(MONTH FROM publication_date) = 12 GROUP BY author, year, month;
What is the total word count for news articles, grouped by the day they were published?
CREATE TABLE News (news_id INT,title TEXT,word_count INT,publish_date DATE); INSERT INTO News (news_id,title,word_count,publish_date) VALUES (1,'Article1',500,'2023-02-22'),(2,'Article2',300,'2023-02-23'),(3,'Article3',600,'2023-02-22');
SELECT DATE(publish_date) as publish_day, SUM(word_count) as total_word_count FROM News GROUP BY publish_day;
What is the average playtime for players who have played the game 'Shooter' and are older than 20?
CREATE TABLE PlayerGameData (PlayerID INT,Age INT,Game VARCHAR(20),Playtime INT); INSERT INTO PlayerGameData (PlayerID,Age,Game,Playtime) VALUES (1,22,'Shooter',30),(2,25,'Shooter',50),(3,28,'Racing',70);
SELECT AVG(Playtime) FROM PlayerGameData WHERE Game = 'Shooter' AND Age > 20;
How many times has each type of maintenance been performed on the farming equipment in the past month?
CREATE TABLE maintenance_log (equipment_id INTEGER,maintenance_type TEXT,maintenance_date DATE);
SELECT maintenance_type, COUNT(*) as maintenance_count FROM maintenance_log WHERE maintenance_date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY maintenance_type;
What is the total area of corn fields in the United States?
CREATE TABLE if NOT EXISTS crop_planting_2 (id int,crop varchar(50),planting_area float,country varchar(50)); INSERT INTO crop_planting_2 (id,crop,planting_area,country) VALUES (1,'Corn',80000,'United States');
SELECT SUM(planting_area) FROM crop_planting_2 WHERE crop = 'Corn' AND country = 'United States';
How many public libraries are there in each region?
CREATE TABLE Libraries (Region TEXT,NumLibraries INTEGER); INSERT INTO Libraries (Region,NumLibraries) VALUES ('North',5),('South',7),('East',6),('West',4);
SELECT Region, NumLibraries FROM Libraries;
What was the total production of Europium and Gadolinium in 2018?
CREATE TABLE Europium_Production (Year INT,Quantity INT); INSERT INTO Europium_Production (Year,Quantity) VALUES (2018,1200); CREATE TABLE Gadolinium_Production (Year INT,Quantity INT); INSERT INTO Gadolinium_Production (Year,Quantity) VALUES (2018,1500);
SELECT SUM(Quantity) FROM Europium_Production WHERE Year = 2018; SELECT SUM(Quantity) FROM Gadolinium_Production WHERE Year = 2018;
How many ethically sourced products are sold in each state?
CREATE TABLE States (state_id INT,state_name VARCHAR(20)); INSERT INTO States (state_id,state_name) VALUES (1,'California'),(2,'Texas'),(3,'Florida'),(4,'New York');
SELECT S.state_name, COUNT(DISTINCT EP.product_id) FROM Ethical_Products EP JOIN Sales S ON EP.product_id = S.product_id GROUP BY S.state_name HAVING is_ethically_sourced = true;
What are the names and prices of all products that are not made in the US and are not on sale?
CREATE TABLE products (product_id INT,product_name TEXT,price DECIMAL,country_of_manufacture TEXT,is_on_sale BOOLEAN); INSERT INTO products (product_id,product_name,price,country_of_manufacture,is_on_sale) VALUES (1,'Regular Shirt',25.99,'Canada',FALSE);
SELECT product_name, price FROM products WHERE country_of_manufacture != 'United States' AND is_on_sale = FALSE;
Who are the top 3 customers in terms of total value of ethical fashion purchases in 2020?
CREATE TABLE customers (id INT,customer_name VARCHAR(50),total_spent DECIMAL(10,2)); CREATE TABLE ethical_fashion_purchases (id INT,purchase_id INT,customer_id INT,purchase_value DECIMAL(10,2)); INSERT INTO customers (id,customer_name,total_spent) VALUES (1,'EcoShopper',1500.00),(2,'GreenBuyer',2000.00),(3,'SustainableSpender',2500.00); INSERT INTO ethical_fashion_purchases (id,purchase_id,customer_id,purchase_value) VALUES (1,10,1,100.00),(2,11,1,150.00),(3,12,2,200.00),(4,13,2,300.00),(5,14,3,500.00);
SELECT customer_name, SUM(purchase_value) FROM customers JOIN ethical_fashion_purchases ON customers.id = ethical_fashion_purchases.customer_id GROUP BY customer_name ORDER BY SUM(purchase_value) DESC LIMIT 3;
Who are the top 5 vendors with the highest revenue from circular supply chain products?
CREATE TABLE vendors (vendor_id INT,name TEXT); CREATE TABLE sales (sale_id INT,vendor_id INT,product_id INT,price DECIMAL(5,2)); INSERT INTO vendors (vendor_id,name) VALUES (1,'Vendor A'),(2,'Vendor B'),(3,'Vendor C'),(4,'Vendor D'),(5,'Vendor E'); INSERT INTO sales (sale_id,vendor_id,product_id,price) VALUES (1,1,1,20.99),(2,1,3,75.00),(3,2,2,50.00),(4,3,1,20.99),(5,3,3,75.00),(6,4,2,50.00),(7,5,3,75.00); CREATE TABLE circular_supply_chain_products (product_id INT); INSERT INTO circular_supply_chain_products (product_id) VALUES (1),(3);
SELECT vendors.name, SUM(sales.price) FROM vendors INNER JOIN sales ON vendors.vendor_id = sales.vendor_id INNER JOIN circular_supply_chain_products ON sales.product_id = circular_supply_chain_products.product_id GROUP BY vendors.name ORDER BY SUM(sales.price) DESC LIMIT 5;
What is the average number of moons for planets in our solar system?
CREATE TABLE SolarSystem (Planet VARCHAR(50),Moons INT); INSERT INTO SolarSystem (Planet,Moons) VALUES ('Mercury',0),('Venus',0),('Earth',1),('Mars',2),('Jupiter',79),('Saturn',82),('Uranus',27),('Neptune',14);
SELECT AVG(Moons) FROM SolarSystem WHERE Moons > 0;
What is the total cost of Mars missions led by each country?
CREATE TABLE missions (mission_name VARCHAR(50),country VARCHAR(50),cost INT); INSERT INTO missions (mission_name,country,cost) VALUES ('Mars Pathfinder','USA',265000000),('Mars Curiosity Rover','USA',2800000000),('Mars Express','Europe',300000000);
SELECT country, SUM(cost) as total_mars_cost FROM missions WHERE mission_name LIKE '%Mars%' GROUP BY country ORDER BY total_mars_cost DESC;
Update the severity score of the vulnerability assessment with ID 2 to 4.
CREATE TABLE vulnerability_assessments (id INT,name VARCHAR(255),last_assessment_date DATE,severity_score INT); INSERT INTO vulnerability_assessments (id,name,last_assessment_date,severity_score) VALUES (1,'Vulnerability Assessment 1','2021-11-01',5),(2,'Vulnerability Assessment 2','2021-12-01',3),(3,'Vulnerability Assessment 3','2021-12-10',7);
UPDATE vulnerability_assessments SET severity_score = 4 WHERE id = 2;
What is the average severity score of security incidents in the retail sector?
CREATE TABLE security_incidents (id INT,sector VARCHAR(20),severity FLOAT); INSERT INTO security_incidents (id,sector,severity) VALUES (1,'Retail',6.5);
SELECT AVG(severity) FROM security_incidents WHERE sector = 'Retail';
Obtain the total number of policies issued in 'Q2 2021'
CREATE TABLE policies (id INT,issue_date DATE);
SELECT COUNT(*) FROM policies WHERE issue_date BETWEEN '2021-04-01' AND '2021-06-30';
What is the average number of workplace safety incidents for unions in the 'services' sector that have more than 2000 members?
CREATE TABLE union_stats (id INT,union_name VARCHAR(30),sector VARCHAR(20),num_members INT,num_safety_incidents INT); INSERT INTO union_stats (id,union_name,sector,num_members,num_safety_incidents) VALUES (1,'Union A','services',3000,15),(2,'Union B','education',2000,8),(3,'Union C','services',1000,2),(4,'Union D','technology',2500,10);
SELECT AVG(num_safety_incidents) FROM union_stats WHERE sector = 'services' AND num_members > 2000;
What is the maximum contract length for 'Transportation' union collective bargaining agreements?
CREATE TABLE CollectiveBargaining (agreement_id INT,union_id INT,terms TEXT,contract_length INT); CREATE TABLE Unions (union_id INT,industry TEXT);
SELECT MAX(CollectiveBargaining.contract_length) FROM CollectiveBargaining INNER JOIN Unions ON CollectiveBargaining.union_id = Unions.union_id WHERE Unions.industry = 'Transportation';