instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What are the names and types of all tankers in the 'tankers' table that have a capacity greater than 100000 tons?
CREATE TABLE tankers (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50),capacity INT);
SELECT name, type FROM tankers WHERE capacity > 100000;
List manufacturers and their ethical manufacturing certifications
CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),region VARCHAR(50)); INSERT INTO Manufacturers (manufacturer_id,manufacturer_name,region) VALUES (1,'ManufacturerA','North America'),(2,'ManufacturerB','Europe'),(3,'ManufacturerC','Asia-Pacific'); CREATE TABLE EthicalCertifications (certification_id INT,certification_name VARCHAR(50),manufacturer_id INT); INSERT INTO EthicalCertifications (certification_id,certification_name,manufacturer_id) VALUES (1,'FairTrade',1),(2,'BCorp',2),(3,'EthicalTrade',3);
SELECT m.manufacturer_name, c.certification_name FROM Manufacturers m INNER JOIN EthicalCertifications c ON m.manufacturer_id = c.manufacturer_id;
What is the name and production date of the machines in the 'circular_economy' category that have a production date after 2015?
CREATE TABLE machines (id INT,name VARCHAR(255),category VARCHAR(255),production_date DATE); INSERT INTO machines (id,name,category,production_date) VALUES (1,'ABC Machine','circular_economy','2016-01-01'),(2,'XYZ Machine','circular_economy','2014-01-01'),(3,'DEF Machine','circular_economy','2017-01-01');
SELECT name, production_date FROM machines WHERE category = 'circular_economy' AND production_date > '2015-01-01';
List the top 3 countries with the highest average artifact weight, along with the year and total weight of artifacts?
CREATE TABLE ExcavationSites (SiteID INT,SiteName VARCHAR(50),Country VARCHAR(50),Year INT,ArtifactWeight FLOAT); INSERT INTO ExcavationSites (SiteID,SiteName,Country,Year,ArtifactWeight) VALUES (1,'Site A','USA',2020,23.5),(2,'Site B','Mexico',2020,14.2),(3,'Site C','USA',2019,34.8),(4,'Site D','Canada',2019,45.6),(5,'Site E','Canada',2019,56.7);
SELECT Country, Year, SUM(ArtifactWeight) AS TotalWeight, AVG(ArtifactWeight) OVER (PARTITION BY Country) AS AvgWeight FROM ExcavationSites WHERE Year IN (2019, 2020) GROUP BY Country, Year ORDER BY AvgWeight DESC, TotalWeight DESC, Year DESC LIMIT 3;
Show artifacts excavated before a certain date and still under analysis
CREATE TABLE ExcavationSites (SiteID INT,SiteName TEXT,Country TEXT,StartDate DATE,EndDate DATE);CREATE TABLE Artifacts (ArtifactID INT,SiteID INT,ArtifactName TEXT,AnalysisDate DATE);
SELECT a.ArtifactName FROM Artifacts a JOIN ExcavationSites es ON a.SiteID = es.SiteID WHERE es.StartDate < '2010-01-01' AND a.AnalysisDate IS NULL;
What is the sum of ESG scores for 'Green Horizons' in H2 2021?
CREATE TABLE company_scores (id INT,company VARCHAR(255),esg_score FLOAT,year INT,quarter INT); INSERT INTO company_scores (id,company,esg_score,year,quarter) VALUES (19,'Green Horizons',72,2021,3); INSERT INTO company_scores (id,company,esg_score,year,quarter) VALUES (20,'Green Horizons',75,2021,4);
SELECT SUM(esg_score) FROM company_scores WHERE company = 'Green Horizons' AND year = 2021 AND quarter BETWEEN 3 AND 4;
What is the total number of military bases located in the US and their corresponding defense budget?
CREATE TABLE MilitaryBases (id INT,base_name TEXT,location TEXT,budget FLOAT); INSERT INTO MilitaryBases (id,base_name,location,budget) VALUES (1,'Fort Bragg','USA',5000000); CREATE TABLE DefenseBudget (id INT,country TEXT,amount FLOAT); INSERT INTO DefenseBudget (id,country,amount) VALUES (1,'USA',7400000000);
SELECT SUM(MilitaryBases.budget) as total_budget, MilitaryBases.location FROM MilitaryBases INNER JOIN DefenseBudget ON MilitaryBases.location = DefenseBudget.country WHERE DefenseBudget.country = 'USA';
What was the average budget for programs in the Education category?
CREATE TABLE Programs (ProgramID INT,Category TEXT,Budget DECIMAL(10,2)); INSERT INTO Programs (ProgramID,Category,Budget) VALUES (1,'Education',5000.00),(2,'Healthcare',7000.00);
SELECT AVG(Budget) as 'Average Budget' FROM Programs WHERE Category = 'Education';
What is the total production of oil from the 'North Sea' region in 2020?
CREATE TABLE wells (well_id INT,field VARCHAR(50),region VARCHAR(50),production_oil FLOAT,production_gas FLOAT); INSERT INTO wells (well_id,field,region,production_oil,production_gas) VALUES (1,'Alvheim','North Sea',15000.0,5000.0),(2,'Ekofisk','North Sea',20000.0,10000.0);
SELECT SUM(production_oil) FROM wells WHERE region = 'North Sea' AND YEAR(wells.production_date) = 2020;
Update the 'tenure' of the coach of the 'Patriots' team to 25 years.
CREATE TABLE coaches (id INT PRIMARY KEY,name VARCHAR(50),team VARCHAR(30),tenure INT); INSERT INTO coaches (id,name,team,tenure) VALUES (1,'Bill Belichick','Patriots',20);
UPDATE coaches SET tenure = 25 WHERE team = 'Patriots';
What is the average budget allocated for ethical AI initiatives across all organizations?
CREATE TABLE organization (org_id INT,org_name TEXT,budget FLOAT); INSERT INTO organization (org_id,org_name,budget) VALUES (1,'OrgA',50000),(2,'OrgB',75000),(3,'OrgC',100000);
SELECT AVG(budget) FROM organization WHERE initiative = 'ethical AI';
What is the total fare and trip count for each route based on payment type for the bus routes?
CREATE TABLE fares (fare_id INT,route_id INT,fare_amount DECIMAL(5,2),payment_type VARCHAR(255)); INSERT INTO fares (fare_id,route_id,fare_amount,payment_type) VALUES (1,1,2.50,'Credit Card'),(2,1,3.00,'Cash'),(3,2,1.75,'Credit Card');
SELECT route_id, payment_type, SUM(fare_amount) AS total_fare, COUNT(*) AS trip_count FROM fares WHERE route_id IN (1, 2) GROUP BY route_id, payment_type;
What is the total fare collected for each bus route during off-peak hours?
CREATE TABLE bus_routes (route_id INT,route_name TEXT,starting_point TEXT,ending_point TEXT,off_peak_hour BOOLEAN); CREATE TABLE bus_fares (fare_id INT,route_id INT,fare_amount DECIMAL,fare_date DATE,fare_time TIME);
SELECT br.route_name, SUM(bf.fare_amount) as total_off_peak_fare FROM bus_routes br INNER JOIN bus_fares bf ON br.route_id = bf.route_id WHERE br.off_peak_hour = TRUE GROUP BY br.route_name;
Update the record of sustainable materials certification for the manufacturer with ID 6.
CREATE TABLE manufacturer_sustainable_materials (manufacturer_id INT,certification DATE); INSERT INTO manufacturer_sustainable_materials (manufacturer_id,certification) VALUES (1,'2020-01-01'),(2,'2019-05-15'),(3,'2018-09-30'),(4,NULL),(5,'2017-01-01'),(6,NULL);
UPDATE manufacturer_sustainable_materials SET certification = '2022-06-25' WHERE manufacturer_id = 6;
Find the top 3 countries with the highest ad spend in Q3 2021.
CREATE TABLE if not exists ads (ad_id INT,country VARCHAR(50),spend FLOAT,quarter INT,year INT); INSERT INTO ads (ad_id,country,spend,quarter,year) VALUES (1,'United States',500.00,3,2021),(2,'Canada',300.00,3,2021),(3,'Mexico',400.00,3,2021);
SELECT country, SUM(spend) AS total_spend FROM ads GROUP BY country ORDER BY total_spend DESC LIMIT 3;
Update the privacy setting of users who reside in California to 'high'
CREATE TABLE users (id INT,state VARCHAR(20),privacy_setting VARCHAR(20)); INSERT INTO users (id,state,privacy_setting) VALUES (1,'California','medium'),(2,'New York','high'),(3,'Texas','low');
UPDATE users SET privacy_setting = 'high' WHERE state = 'California';
Find customers who have purchased items from both sustainable and non-sustainable categories.
CREATE TABLE Customers (CustomerID INT,PurchaseHistory VARCHAR(255)); INSERT INTO Customers (CustomerID,PurchaseHistory) VALUES (1,'Organic Cotton T-Shirt,Conventional Cotton Pants'),(2,'Recycled Polyester Leggings,Viscose Dress'),(3,'Tencel Skirt'),(4,'Bamboo Blouse'),(5,'Recycled Nylon Jacket');
SELECT CustomerID FROM Customers WHERE PurchaseHistory LIKE '%Organic Cotton%' AND PurchaseHistory LIKE '%Conventional Cotton%' OR PurchaseHistory LIKE '%Recycled Polyester%' AND PurchaseHistory LIKE '%Viscose%';
Show the total number of volunteers and total hours volunteered, grouped by program
CREATE TABLE volunteers (id INT,program_id INT,name VARCHAR(50),hours_volunteered DECIMAL(10,2));
SELECT p.name, COUNT(v.id) as num_volunteers, SUM(v.hours_volunteered) as total_hours_volunteered FROM programs p JOIN volunteers v ON p.id = v.program_id GROUP BY p.name;
What is the total amount donated to 'Environment' programs in 'Germany' in the first half of 2022?
CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,program_name TEXT); INSERT INTO donations (donation_id,donor_id,donation_amount,donation_date,program_name) VALUES (1,5,100,'2022-01-01','Environment');
SELECT SUM(donation_amount) FROM donations WHERE program_name = 'Environment' AND country = 'Germany' AND donation_date BETWEEN '2022-01-01' AND '2022-06-30';
Insert new nutrition data for the menu item "Veggie Burger"
CREATE TABLE nutrition_data (menu_item VARCHAR(255),calories INT,protein INT,fat INT);
INSERT INTO nutrition_data (menu_item, calories, protein, fat) VALUES ('Veggie Burger', 400, 20, 15);
What is the total budget allocated to healthcare in Australia for the current fiscal year and what is the percentage of the total budget that is allocated to healthcare?
CREATE TABLE countries (id INT,name VARCHAR(255)); INSERT INTO countries (id,name) VALUES (1,'Australia'); CREATE TABLE budget_categories (id INT,name VARCHAR(255),budget INT); INSERT INTO budget_categories (id,name,budget) VALUES (1,'Healthcare',100000),(2,'Education',80000),(3,'Defense',70000);
SELECT budget_categories.name, SUM(budget_categories.budget) AS total_budget, (SUM(budget_categories.budget) / (SELECT SUM(budget) FROM budget_categories WHERE name = 'Australia')) * 100 AS pct_of_total_budget FROM budget_categories WHERE budget_categories.name = 'Healthcare';
What are the green building certifications in France?
CREATE TABLE GreenBuildings (id INT,name VARCHAR(50),city VARCHAR(50),state VARCHAR(50),country VARCHAR(50),certification VARCHAR(50)); INSERT INTO GreenBuildings (id,name,city,state,country,certification) VALUES (3,'GreenHaus','Berlin','Berlin','Germany','DGNB Gold');
SELECT g.certification FROM GreenBuildings g WHERE g.country = 'France';
What is the total number of green buildings in the 'green_buildings' schema, and the total CO2 emission reduction (in metric tons) achieved by carbon offset initiatives in the 'carbon_offset' schema?
CREATE TABLE green_buildings.green_buildings_data (green_building BOOLEAN); CREATE TABLE carbon_offset.offset_initiatives (co2_reduction_tons INT);
SELECT (SELECT COUNT(*) FROM green_buildings.green_buildings_data WHERE green_building = TRUE) AS green_buildings_count, (SELECT SUM(co2_reduction_tons) FROM carbon_offset.offset_initiatives) AS co2_reduction_tons_total;
Add a new training to the table
CREATE TABLE cultural_competency_training (id INT PRIMARY KEY,organization_name VARCHAR(50),training_title TEXT,training_date DATE);
INSERT INTO cultural_competency_training (id, organization_name, training_title, training_date) VALUES (1, 'University Hospital', 'Cultural Competency Training', '2023-01-01');
How many local businesses benefited from sustainable tourism initiatives in 2021?
CREATE TABLE sustainable_tourism (business_id INT,year INT,benefited BOOLEAN); INSERT INTO sustainable_tourism (business_id,year,benefited) VALUES (1,2021,TRUE),(2,2021,TRUE),(3,2021,FALSE);
SELECT COUNT(*) FROM sustainable_tourism WHERE year = 2021 AND benefited = TRUE;
Insert a new record into the "attractions" table with id 202, name "Aboriginal Cultural Centre", city "Sydney", country "Australia", and type "Cultural"
CREATE TABLE attractions (id INT,name VARCHAR(50),city VARCHAR(50),country VARCHAR(50),type VARCHAR(50));
INSERT INTO attractions VALUES (202, 'Aboriginal Cultural Centre', 'Sydney', 'Australia', 'Cultural');
Which countries had the highest virtual tourism revenue in Q2 2022?
CREATE TABLE tourism_revenue (country VARCHAR(50),revenue FLOAT,quarter INT,year INT); INSERT INTO tourism_revenue (country,revenue,quarter,year) VALUES ('USA',1200000,2,2022),('Canada',800000,2,2022),('Mexico',500000,2,2022);
SELECT country, SUM(revenue) as total_revenue FROM tourism_revenue WHERE quarter = 2 AND year = 2022 GROUP BY country ORDER BY total_revenue DESC;
Find the total number of glacier retreats in Norway from 2015 to 2020.
CREATE TABLE GlacierRetreats (location TEXT,year INTEGER,retreats INTEGER);
SELECT SUM(retreats) FROM GlacierRetreats WHERE location = 'Norway' AND year BETWEEN 2015 AND 2020;
Which countries have the highest number of eco-friendly accommodations in Asia?
CREATE TABLE asia_accommodations (country VARCHAR(50),type VARCHAR(50)); INSERT INTO asia_accommodations VALUES ('Japan','Eco-friendly'),('Thailand','Eco-friendly'),('Indonesia','Eco-friendly'),('Malaysia','Eco-friendly'),('Vietnam','Eco-friendly');
SELECT country, COUNT(*) as count FROM asia_accommodations WHERE type = 'Eco-friendly' GROUP BY country ORDER BY count DESC;
What is the average time taken for family court cases in New York to reach a verdict in the last 2 years?
CREATE TABLE FamilyCourtCases (CaseID INT,CaseType TEXT,StartDate DATE,VerdictDate DATE,State TEXT); INSERT INTO FamilyCourtCases (CaseID,CaseType,StartDate,VerdictDate,State) VALUES (1,'Family Court','2020-01-01','2020-06-01','New York');
SELECT AVG(DATEDIFF(VerdictDate, StartDate)) as AvgTime FROM FamilyCourtCases WHERE State = 'New York' AND YEAR(StartDate) BETWEEN YEAR(CURRENT_DATE) - 2 AND YEAR(CURRENT_DATE);
What is the maximum pollution level recorded in Southeast Asian countries in the 'Pollution' schema?
CREATE SCHEMA Pollution;CREATE TABLE PollutionData (id INT,country TEXT,region TEXT,pollution_level REAL); INSERT INTO PollutionData (id,country,region,pollution_level) VALUES (1,'Indonesia','Southeast Asia',9.0),(2,'Malaysia','Southeast Asia',7.5),(3,'Philippines','Southeast Asia',8.2),(4,'Thailand','Southeast Asia',6.9),(5,'Singapore','Southeast Asia',5.4),(6,'Vietnam','Southeast Asia',7.8);
SELECT MAX(pollution_level) FROM Pollution.PollutionData WHERE region = 'Southeast Asia';
What is the total production volume of copper in Chile for the year 2020?
CREATE TABLE production (id INT,mine_id INT,year INT,product TEXT,production_volume INT); INSERT INTO production (id,mine_id,year,product,production_volume) VALUES (1,1,2020,'Copper',25000);
SELECT SUM(production_volume) FROM production WHERE year = 2020 AND product = 'Copper' AND mine_id IN (SELECT id FROM mines WHERE location = 'Chile');
Identify the top 2 countries with the highest concert revenue, excluding the United States.
CREATE TABLE Concerts (id INT,country VARCHAR(50),revenue FLOAT);
SELECT country, SUM(revenue) FROM Concerts WHERE country NOT IN ('United States') GROUP BY country ORDER BY SUM(revenue) DESC LIMIT 2;
Calculate the total donation amount for environmental causes in Q1 2022.
CREATE TABLE donations (id INT PRIMARY KEY,cause VARCHAR(20),donation_amount INT,donation_date DATE); INSERT INTO donations (id,cause,donation_amount,donation_date) VALUES (1,'environment',100,'2022-01-01');
SELECT SUM(donation_amount) FROM donations WHERE cause = 'environment' AND donation_date BETWEEN '2022-01-01' AND '2022-03-31';
Find the total number of underwater volcanoes in the Atlantic region with a depth greater than 3500 meters.
CREATE TABLE underwater_volcanoes (id INT,name VARCHAR(255),region VARCHAR(50),depth INT); INSERT INTO underwater_volcanoes (id,name,region,depth) VALUES (1,'Atlantic Volcano 1','Atlantic',3500),(2,'Atlantic Volcano 2','Atlantic',3000);
SELECT COUNT(*) FROM underwater_volcanoes WHERE region = 'Atlantic' AND depth > 3500;
What are the names and categories of donors who have contributed more than $1,000,000 in total?
CREATE TABLE Donors (DonorID INT,Name TEXT,Category TEXT,TotalContributions DECIMAL(18,2)); INSERT INTO Donors (DonorID,Name,Category,TotalContributions) VALUES (1,'DonorA','Effective Altruism',1200000),(2,'DonorB','Impact Investing',800000),(3,'DonorC','Effective Altruism',1500000),(4,'DonorD','Impact Investing',900000),(5,'DonorE','Effective Altruism',700000);
SELECT Name, Category FROM Donors WHERE TotalContributions > 1000000;
What is the average playtime for all players who have played 'Cybernetic Shift'?
CREATE TABLE Player_Details (Player_ID INT,Player_Name VARCHAR(50),Country VARCHAR(50),Playtime INT,Game_Name VARCHAR(50)); INSERT INTO Player_Details (Player_ID,Player_Name,Country,Playtime,Game_Name) VALUES (1,'Alex Rodriguez','Brazil',210,'Cybernetic Shift'),(2,'Pia Johnson','South Africa',360,'Cybernetic Shift'),(3,'Leila Ahmed','Egypt',420,'Cybernetic Shift'),(4,'Hiroshi Tanaka','Japan',180,'Cybernetic Shift'),(5,'Kim Nguyen','Vietnam',300,'Cybernetic Shift');
SELECT AVG(Playtime) FROM Player_Details WHERE Game_Name = 'Cybernetic Shift';
What is the average playtime, in hours, for players from Egypt, for games in the 'Strategy' genre?
CREATE TABLE games (game_id INT,game_genre VARCHAR(255),player_id INT,playtime_mins INT); CREATE TABLE players (player_id INT,player_country VARCHAR(255));
SELECT AVG(playtime_mins / 60) FROM games JOIN players ON games.player_id = players.player_id WHERE players.player_country = 'Egypt' AND game_genre = 'Strategy';
How many buildings are there in each neighborhood?
CREATE TABLE neighborhoods (neighborhood VARCHAR(50),building_id INT); INSERT INTO neighborhoods (neighborhood,building_id) VALUES ('NeighborhoodA',1),('NeighborhoodB',2),('NeighborhoodA',3),('NeighborhoodC',4),('NeighborhoodB',5);
SELECT neighborhood, COUNT(DISTINCT building_id) FROM neighborhoods GROUP BY neighborhood;
What is the average size of units in co-living buildings?
CREATE TABLE co_living_buildings (building_id INT,unit_size FLOAT); INSERT INTO co_living_buildings (building_id,unit_size) VALUES (1,500.5),(2,450.3),(3,600.7);
SELECT AVG(unit_size) FROM co_living_buildings;
Update the food_safety table to set the score to 90 for inspection_date '2022-08-05'
CREATE TABLE food_safety (id INT PRIMARY KEY,restaurant_id INT,inspection_date DATE,score INT);
UPDATE food_safety SET score = 90 WHERE inspection_date = '2022-08-05';
What is the average carbon footprint of products made in each country?
CREATE TABLE products (product_id INT,country VARCHAR(50),carbon_footprint DECIMAL(10,2)); CREATE VIEW country_products AS SELECT country,carbon_footprint FROM products GROUP BY country;
SELECT country, AVG(carbon_footprint) FROM country_products GROUP BY country;
What is the total quantity of products sold by each brand, pivoted by month?
CREATE TABLE products (product_id INT,brand VARCHAR(255),quantity INT,sale_date DATE); INSERT INTO products (product_id,brand,quantity,sale_date) VALUES (1,'BrandA',10,'2021-01-01'); CREATE TABLE brands (brand_id INT,brand VARCHAR(255)); INSERT INTO brands (brand_id,brand) VALUES (1,'BrandA'),(2,'BrandB');
SELECT brand, SUM(quantity) AS total_quantity, EXTRACT(MONTH FROM sale_date) AS month FROM products p JOIN brands b ON p.brand = b.brand GROUP BY brand, month ORDER BY brand, month;
Which countries have launched the most satellites in the SpaceRadar table?
CREATE TABLE SpaceRadar (id INT,country VARCHAR(50),year INT,satellites INT); INSERT INTO SpaceRadar (id,country,year,satellites) VALUES (1,'USA',2000,10),(2,'China',2005,8),(3,'Russia',1995,12);
SELECT country, SUM(satellites) AS total_satellites FROM SpaceRadar GROUP BY country ORDER BY total_satellites DESC;
What is the maximum duration of space missions led by astronauts from the USA?
CREATE TABLE space_missions(id INT,mission_name VARCHAR(50),leader_name VARCHAR(50),leader_country VARCHAR(50),duration INT); INSERT INTO space_missions VALUES(1,'Apollo 11','Neil Armstrong','USA',195.),(2,'Gemini 12','James Lovell','USA',94.);
SELECT MAX(duration) FROM space_missions WHERE leader_country = 'USA';
What is the total number of threat indicators in the 'threat_intelligence' table for each threat category?
CREATE TABLE threat_intelligence (id INT PRIMARY KEY,threat_category TEXT,indicator TEXT);
SELECT threat_category, COUNT(*) FROM threat_intelligence GROUP BY threat_category;
Which policies have been violated by the most users in the past year from the 'policy_violations' and 'policy_library' tables?
CREATE TABLE policy_violations (id INT,policy_id INT,user_id INT,violation_date DATE); CREATE TABLE policy_library (id INT,policy_name VARCHAR(255),description VARCHAR(255));
SELECT policy_name, COUNT(DISTINCT user_id) as total_users FROM policy_violations JOIN policy_library ON policy_violations.policy_id = policy_library.id WHERE violation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY policy_id ORDER BY total_users DESC;
Find the total number of electric vehicle charging stations
CREATE TABLE Stations (StationID INT,StationType VARCHAR(50),Electric BOOLEAN); INSERT INTO Stations (StationID,StationType,Electric) VALUES (1,'Gas Station',false),(2,'Charging Station',true),(3,'Parking Garage',false),(4,'Charging Station',true),(5,'Convenience Store',false),(6,'Charging Station',true);
SELECT COUNT(*) as TotalChargingStations FROM Stations WHERE Electric = true;
List the top 3 states with the highest average claim amount for auto policies, ordered by the average claim amount in descending order.
CREATE TABLE Claims (ClaimID INT,PolicyType VARCHAR(255),PolicyholderID INT,ClaimAmount DECIMAL(10,2),State VARCHAR(255)); INSERT INTO Claims VALUES (1,'Auto',1,5000,'NY'),(2,'Home',2,7000,'CA'),(3,'Auto',3,8000,'ON'),(4,'Life',4,6000,'CA'),(5,'Auto',5,9000,'CA');
SELECT State, AVG(ClaimAmount) as AvgClaimAmount FROM Claims WHERE PolicyType = 'Auto' GROUP BY State ORDER BY AvgClaimAmount DESC LIMIT 3;
Show policy types that have not resulted in any claims yet.
CREATE TABLE Policy (PolicyID INT,PolicyType VARCHAR(20)); CREATE TABLE Claims (ClaimID INT,PolicyID INT); INSERT INTO Policy VALUES (1,'Auto'),(2,'Home'),(3,'Life'); INSERT INTO Claims VALUES (1,1),(2,1),(3,2);
SELECT DISTINCT PolicyType FROM Policy P WHERE NOT EXISTS (SELECT 1 FROM Claims C WHERE P.PolicyID = C.PolicyID);
How many unions are present in each country?
CREATE TABLE UnionMembers (id INT,union_name VARCHAR(50),country VARCHAR(50),member_count INT); INSERT INTO UnionMembers (id,union_name,country,member_count) VALUES (1,'United Steelworkers','USA',200000),(2,'UNITE HERE','USA',300000),(3,'TUC','UK',6000000),(4,'CUPE','Canada',650000),(5,'USW','Canada',120000);
SELECT country, COUNT(DISTINCT union_name) as num_unions FROM UnionMembers GROUP BY country;
Show the collective bargaining agreements that expire in 2024 for unions in the 'west_region'?
CREATE TABLE cb_agreements (union_name TEXT,expiration_year INTEGER,region TEXT); INSERT INTO cb_agreements (union_name,expiration_year,region) VALUES ('Union A',2023,'east_region'),('Union D',2024,'west_region'),('Union E',2025,'west_region');
SELECT union_name FROM cb_agreements WHERE region = 'west_region' AND expiration_year = 2024;
What is the average salary of female workers in the manufacturing industry?
CREATE TABLE manufacturing (id INT,gender TEXT,salary FLOAT); INSERT INTO manufacturing (id,gender,salary) VALUES (1,'Male',50000),(2,'Female',45000);
SELECT AVG(salary) FROM manufacturing WHERE gender = 'Female';
What is the average weekly wage for each job category in the 'labor_stats' table?
CREATE TABLE labor_stats (id INT,job_category VARCHAR(255),weekly_wage FLOAT); INSERT INTO labor_stats (id,job_category,weekly_wage) VALUES (1,'Engineering',1500.50),(2,'Management',2000.75),(3,'Service',800.00);
SELECT job_category, AVG(weekly_wage) as avg_wage FROM labor_stats GROUP BY job_category;
How many landfills are there in Texas and what is their total capacity in cubic yards?
CREATE TABLE landfills (location VARCHAR(255),name VARCHAR(255),capacity_cubic_yards INT); INSERT INTO landfills (location,name,capacity_cubic_yards) VALUES ('Texas','Landfill A',1000000),('Texas','Landfill B',1500000);
SELECT COUNT(*) as num_landfills, SUM(capacity_cubic_yards) as total_capacity FROM landfills WHERE location = 'Texas';
What is the total waste generation in 2012 for all sectors?
CREATE TABLE waste_generation (id INT,sector VARCHAR(20),year INT,amount INT); INSERT INTO waste_generation (id,sector,year,amount) VALUES (1,'residential',2010,4000),(2,'residential',2011,4500),(3,'residential',2012,4700),(4,'commercial',2010,6000),(5,'commercial',2011,6500),(6,'commercial',2012,7000),(7,'industrial',2010,8000),(8,'industrial',2011,8500),(9,'industrial',2012,9000);
SELECT SUM(amount) FROM waste_generation WHERE year = 2012;
What is the trend of sentiment scores for creative AI applications over time?
CREATE TABLE creative_ai (id INT,timestamp TIMESTAMP,sentiment FLOAT);
SELECT timestamp, AVG(sentiment) OVER (ORDER BY timestamp RANGE BETWEEN INTERVAL '1 day' PRECEDING AND CURRENT ROW) FROM creative_ai;
How many satellites have been deployed by each space company?
CREATE SCHEMA aerospace; USE aerospace; CREATE TABLE space_company (name VARCHAR(255),satellites_deployed INT); INSERT INTO space_company (name,satellites_deployed) VALUES ('SpaceX',2423),('Rocket Lab',135),('Blue Origin',20),('Virgin Orbit',4);
SELECT name, satellites_deployed FROM aerospace.space_company;
What are the total number of aircraft manufactured by each company?
CREATE TABLE aircraft (id INT PRIMARY KEY,manufacturer VARCHAR(50),model VARCHAR(50)); INSERT INTO aircraft (id,manufacturer,model) VALUES (1,'Boeing','737'),(2,'Airbus','A320'),(3,'Boeing','787'),(4,'Airbus','A350');
SELECT manufacturer, COUNT(*) FROM aircraft GROUP BY manufacturer;
What is the average attendee_age for music_concert events in Toronto?
CREATE TABLE music_concert_attendance (id INT,attendee_age INT,concert_location VARCHAR(50)); INSERT INTO music_concert_attendance (id,attendee_age,concert_location) VALUES (1,30,'Toronto'),(2,35,'Toronto'),(3,40,'Montreal'),(4,45,'Montreal'),(5,32,'Vancouver'),(6,42,'Vancouver');
SELECT AVG(attendee_age) FROM music_concert_attendance WHERE concert_location = 'Toronto';
Calculate the total amount of climate mitigation investments for each country in Asia in 2019 and 2020.
CREATE TABLE climate_mitigation (country VARCHAR(50),investment INT,year INT,region VARCHAR(50)); INSERT INTO climate_mitigation (country,investment,year,region) VALUES ('India',1000000,2019,'Asia'),('China',1500000,2019,'Asia'),('India',1200000,2020,'Asia'),('China',1800000,2020,'Asia');
SELECT country, SUM(investment) as total_investment FROM climate_mitigation WHERE year IN (2019, 2020) AND region = 'Asia' GROUP BY country;
What's the total investment in climate communication in Africa and Oceania from 2010 to 2020?
CREATE TABLE communication_investments (region TEXT,year INT,amount FLOAT); INSERT INTO communication_investments (region,year,amount) VALUES ('Africa',2010,100000); INSERT INTO communication_investments (region,year,amount) VALUES ('Oceania',2010,50000);
SELECT SUM(amount) FROM communication_investments WHERE region IN ('Africa', 'Oceania') AND year BETWEEN 2010 AND 2020;
List the top 3 companies by R&D expenditures in the oncology department that have the highest sales growth between 2017 and 2018, excluding companies from North America.
CREATE TABLE companies (id INT,name VARCHAR(255),department VARCHAR(255),expenditures FLOAT,sales FLOAT,company_location VARCHAR(255)); INSERT INTO companies (id,name,department,expenditures,sales,company_location) VALUES (1,'Global Pharma','Oncology',15000000,50000000,'Europe'),(2,'BioTech Asia','Oncology',12000000,40000000,'Asia'),(3,'Pharma Oceania','Cardiology',9000000,30000000,'Oceania'),(4,'American Health','Oncology',10000000,60000000,'North America'),(5,'South American Bio','Oncology',11000000,45000000,'South America');
SELECT a.name, a.expenditures, a.sales, ((a.sales / b.sales - 1) * 100) AS sales_growth FROM companies a INNER JOIN companies b ON a.name = b.name AND a.department = b.department AND a.company_location = b.company_location WHERE a.department = 'Oncology' AND a.company_location NOT IN ('North America') AND b.department = 'Oncology' AND b.company_location NOT IN ('North America') GROUP BY a.name, a.expenditures, a.sales ORDER BY a.expenditures DESC, sales_growth DESC LIMIT 3;
What is the maximum R&D expenditure for a specific drug company in a certain year?
CREATE TABLE companies (id INT,name VARCHAR(255)); CREATE TABLE rd_expenditures (id INT,company_id INT,year INT,amount DECIMAL(10,2));
SELECT MAX(rd_expenditures.amount) FROM rd_expenditures JOIN companies ON rd_expenditures.company_id = companies.id WHERE companies.name = 'PharmaCorp' AND rd_expenditures.year = 2019;
Insert a new record into the covid_cases table with a case number of 6006 from the country of India.
CREATE TABLE covid_cases (id INT,country VARCHAR(255),case_number INT);
INSERT INTO covid_cases (id, country, case_number) VALUES (6, 'India', 6006);
What is the total number of immunization records in Nigeria over the past month?
CREATE TABLE immunization_records (id INT,patient_id INT,vaccine_type TEXT,record_date TIMESTAMP); INSERT INTO immunization_records (id,patient_id,vaccine_type,record_date) VALUES (1,1,'Measles','2022-06-10 14:30:00'),(2,2,'Polio','2022-05-15 09:00:00');
SELECT COUNT(*) FROM immunization_records WHERE record_date >= DATEADD(month, -1, CURRENT_TIMESTAMP) AND country = 'Nigeria';
How many students with hearing impairments received accommodations in the past year?
CREATE TABLE student (id INT,disability VARCHAR(255)); INSERT INTO student (id,disability) VALUES (1,'Visual Impairment'),(2,'Hearing Impairment'),(3,'Mobility Impairment'); CREATE TABLE accommodation (id INT,student_id INT,type VARCHAR(255),date DATE); INSERT INTO accommodation (id,student_id,type,date) VALUES (1,1,'Sign Language Interpreter','2022-01-01'),(2,2,'Assistive Listening Devices','2022-02-15'),(3,3,'Wheelchair Access','2022-03-03');
SELECT COUNT(a.id) as hearing_impairment_accommodations FROM accommodation a JOIN student s ON a.student_id = s.id WHERE a.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND s.disability = 'Hearing Impairment';
Delete all marine species in the 'marine_species' table that belong to the 'Mollusca' phylum.
CREATE TABLE marine_species (id INT,name VARCHAR(255),phylum VARCHAR(255)); INSERT INTO marine_species (id,name,phylum) VALUES (1,'Pacific salmon','Chordata'),(2,'Blue whale','Chordata'),(3,'Sea anemone','Cnidaria');
DELETE FROM marine_species WHERE phylum = 'Mollusca';
What is the total number of marine protected areas in the Caribbean region?
CREATE TABLE ProtectedAreas(id INT,name VARCHAR(50),region VARCHAR(30)); INSERT INTO ProtectedAreas(id,name,region) VALUES (1,'Bonaire National Marine Park','Caribbean'),(2,'Bahamas Exuma Cays Land and Sea Park','Caribbean'),(3,'Galapagos Marine Reserve','South America');
SELECT COUNT(*) FROM ProtectedAreas WHERE region = 'Caribbean';
What is the total number of tokens held by the 'AAVE' smart contract?
CREATE TABLE smart_contracts (id INT,name VARCHAR(255)); INSERT INTO smart_contracts (id,name) VALUES (7,'AAVE'); CREATE TABLE token_balances (smart_contract_id INT,token_balance INT); INSERT INTO token_balances (smart_contract_id,token_balance) VALUES (7,2000000);
SELECT token_balance FROM token_balances WHERE smart_contract_id = (SELECT id FROM smart_contracts WHERE name = 'AAVE');
Count the number of halal makeup products sold in the USA
CREATE TABLE sales (id INT,product_id INT,quantity INT,country VARCHAR(50)); CREATE TABLE products (id INT,name VARCHAR(50),category VARCHAR(50),halal BOOLEAN);
SELECT COUNT(*) FROM sales JOIN products ON sales.product_id = products.id WHERE products.category = 'makeup' AND products.halal = TRUE AND sales.country = 'USA';
What percentage of hair care products are free from sulfates and parabens in the EU?
CREATE TABLE hair_care_products (product_id INT,name VARCHAR(255),is_sulfate_free BOOLEAN,is_paraben_free BOOLEAN,region VARCHAR(255));
SELECT (COUNT(product_id) * 100.0 / (SELECT COUNT(*) FROM hair_care_products WHERE region = 'EU')) AS percentage FROM hair_care_products WHERE is_sulfate_free = TRUE AND is_paraben_free = TRUE AND region = 'EU';
What is the average attendance for cultural events by day of the week?
CREATE TABLE cultural_events (id INT,city VARCHAR(50),event VARCHAR(50),day_of_week VARCHAR(50),attendance INT); INSERT INTO cultural_events (id,city,event,day_of_week,attendance) VALUES (1,'New York','Art Exhibit','Monday',2500),(2,'Los Angeles','Theater Performance','Tuesday',1800),(3,'Chicago','Music Concert','Wednesday',2200);
SELECT day_of_week, AVG(attendance) as avg_attendance FROM cultural_events GROUP BY day_of_week;
How many defense contracts were signed in each quarter of 2020?
CREATE TABLE defense_contracts (contract_id INT,contract_date DATE); INSERT INTO defense_contracts VALUES (1,'2020-03-15'),(2,'2020-06-01'),(3,'2020-09-15');
SELECT TO_CHAR(contract_date, 'YYYY-Q') AS quarter, COUNT(*) FROM defense_contracts WHERE contract_date >= DATE '2020-01-01' AND contract_date < DATE '2021-01-01' GROUP BY quarter;
Which defense contractors have signed contracts worth over 5 million in the last 6 months?
CREATE TABLE contract_timeline (contract_value NUMERIC,contractor VARCHAR(255),contract_date DATE); INSERT INTO contract_timeline (contract_value,contractor,contract_date) VALUES (6000000,'Contractor C','2022-01-01'),(4000000,'Contractor D','2022-02-15');
SELECT contractor FROM contract_timeline WHERE contract_value > 5000000 AND contract_date > DATEADD(month, -6, CURRENT_DATE);
What is the total transaction value per weekday for the first half of 2022?
CREATE TABLE transactions (transaction_id INT,transaction_date DATE,transaction_category VARCHAR(255),transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,transaction_category,transaction_value) VALUES (1,'2022-01-02','Food',75.00),(2,'2022-01-05','Electronics',350.00),(3,'2022-01-10','Clothing',200.00);
SELECT DATE_FORMAT(transaction_date, '%W') as day_of_week, SUM(transaction_value) as total_value FROM transactions WHERE transaction_date BETWEEN '2022-01-01' AND '2022-06-30' GROUP BY day_of_week;
Which vessels have not handled any cargo with a weight above a certain threshold?
CREATE TABLE vessels (id INT,name VARCHAR(255),port_id INT); CREATE TABLE cargo (id INT,vessel_id INT,weight INT); INSERT INTO vessels (id,name,port_id) VALUES (1,'Vessel A',1),(2,'Vessel B',1),(3,'Vessel C',2); INSERT INTO cargo (id,vessel_id,weight) VALUES (1,1,5000),(2,1,7000),(3,2,3000),(4,3,4000);
SELECT vessels.name FROM vessels LEFT JOIN cargo ON vessels.id = cargo.vessel_id WHERE cargo.weight IS NULL OR cargo.weight <= 5000;
Insert new records for a 'sustainable_manufacturing' program into the 'energy_efficiency' table, along with the corresponding energy savings.
CREATE TABLE energy_efficiency (program VARCHAR(50),energy_savings FLOAT);
INSERT INTO energy_efficiency (program, energy_savings) VALUES ('sustainable_manufacturing', 12.5), ('energy_audits', 7.8), ('smart_meters', 10.2);
What is the average number of primary care physicians per hospital in rural areas of Texas?
CREATE TABLE hospital (hospital_id INT,hospital_name TEXT,location TEXT); INSERT INTO hospital (hospital_id,hospital_name,location) VALUES (1,'Rural Hospital A','Texas'); CREATE TABLE medical_staff (staff_id INT,staff_name TEXT,hospital_id INT,position TEXT); INSERT INTO medical_staff (staff_id,staff_name,hospital_id,position) VALUES (1,'Dr. Jane Smith',1,'Primary Care');
SELECT AVG(staff_count) FROM (SELECT hospital_id, COUNT(*) as staff_count FROM medical_staff WHERE position = 'Primary Care' GROUP BY hospital_id) as subquery JOIN hospital ON subquery.hospital_id = hospital.hospital_id WHERE hospital.location = 'Texas';
How many investments were made in the healthcare sector in Q4 2022?
CREATE TABLE investments (id INT,company_id INT,investment_date DATE); CREATE TABLE companies (id INT,name VARCHAR(255),sector VARCHAR(255)); INSERT INTO companies (id,name,sector) VALUES (1,'Pfizer','Healthcare'),(2,'Microsoft','Technology'); INSERT INTO investments (id,company_id,investment_date) VALUES (1,1,'2022-10-01'),(2,1,'2022-11-15'),(3,2,'2022-12-20');
SELECT COUNT(*) FROM investments i JOIN companies c ON i.company_id = c.id WHERE c.sector = 'Healthcare' AND YEAR(i.investment_date) = 2022 AND QUARTER(i.investment_date) = 4;
What is the number of military personnel in each branch of the US military?
CREATE TABLE MilitaryPersonnel (id INT,name VARCHAR(255),branch VARCHAR(255),personnel_count INT); INSERT INTO MilitaryPersonnel (id,name,branch,personnel_count) VALUES (1,'John Doe','Army',500000),(2,'Jane Smith','Navy',450000),(3,'Bob Johnson','Air Force',375000);
SELECT branch, personnel_count FROM MilitaryPersonnel WHERE branch IN ('Army', 'Navy', 'Air Force') GROUP BY branch;
Delete all songs from the jazz genre released before 1960.
CREATE TABLE songs (song_id INT,song_name VARCHAR(100),genre VARCHAR(50),release_year INT); INSERT INTO songs (song_id,song_name,genre,release_year) VALUES (1,'So What','jazz',1959),(2,'Take Five','jazz',1959),(3,'Misty','jazz',1954),(4,'All of Me','jazz',1931),(5,'What a Wonderful World','jazz',1967);
DELETE FROM songs WHERE genre = 'jazz' AND release_year < 1960;
Find the average donation amount for the 'Education for All' campaign in 2021.
CREATE TABLE donations (id INT,donor_name TEXT,campaign TEXT,amount INT,donation_date DATE); INSERT INTO donations (id,donor_name,campaign,amount,donation_date) VALUES (1,'John Doe','Education for All',50,'2021-01-01'); INSERT INTO donations (id,donor_name,campaign,amount,donation_date) VALUES (2,'Jane Smith','Education for All',100,'2021-05-15');
SELECT AVG(amount) FROM donations WHERE campaign = 'Education for All' AND YEAR(donation_date) = 2021;
How many donations were made by Indian volunteers?
CREATE TABLE Volunteers (id INT,name TEXT,country TEXT); INSERT INTO Volunteers (id,name,country) VALUES (1,'Ravi','India'),(2,'Neha','Nepal'); CREATE TABLE Donations (id INT,volunteer_id INT,amount FLOAT); INSERT INTO Donations (id,volunteer_id,amount) VALUES (3,1,200.0),(4,2,75.0);
SELECT COUNT(*) FROM Donations INNER JOIN Volunteers ON Donations.volunteer_id = Volunteers.id WHERE Volunteers.country = 'India';
What is the change in mental health score between consecutive school years?
CREATE TABLE mental_health_changes (student_id INT,year INT,score INT); INSERT INTO mental_health_changes (student_id,year,score) VALUES (1,2018,80),(1,2019,85),(2,2018,70),(2,2019,75),(3,2018,80),(3,2019,85);
SELECT year, score, LAG(score, 1) OVER (PARTITION BY student_id ORDER BY year) AS previous_score, score - LAG(score, 1) OVER (PARTITION BY student_id ORDER BY year) AS score_change FROM mental_health_changes;
Insert a new 'tanker' record for 'Theta Shipping' from 'Norway' to 'Canada' with a 'capacity' of 100000
CREATE TABLE tanker (id INT PRIMARY KEY,name TEXT,operator TEXT,source TEXT,destination TEXT,capacity INT);
INSERT INTO tanker (name, operator, source, destination, capacity) VALUES ('Norwegian Titan', 'Theta Shipping', 'Norway', 'Canada', 100000);
Insert a new record into the 'oil_market' table with the following details: market_id = 105, market_name = 'Asian Market', crude_oil_price_usd = 85.99
CREATE TABLE oil_market (market_id INT PRIMARY KEY,market_name VARCHAR(255),crude_oil_price_usd DECIMAL(10,2));
INSERT INTO oil_market (market_id, market_name, crude_oil_price_usd) VALUES (105, 'Asian Market', 85.99);
Insert new well record for Brazil with 4000m depth.
CREATE TABLE wells (id INT,location VARCHAR(20),depth FLOAT);
INSERT INTO wells (id, location, depth) VALUES (1, 'Brazil', 4000);
What is the name and age of the oldest donor by gender?
CREATE TABLE donors (id INT,name TEXT,age INT,gender TEXT,contribution FLOAT,location TEXT); INSERT INTO donors (id,name,age,gender,contribution,location) VALUES (1,'Alice Johnson',45,'Female',500.00,'San Francisco'); INSERT INTO donors (id,name,age,gender,contribution,location) VALUES (2,'Bob Brown',50,'Male',1000.00,'Chicago');
SELECT gender, MAX(age) as max_age, MIN(name) as oldest_donor FROM donors GROUP BY gender;
For the technology_accessibility table, return the device_type and user_count for the rows with the 50th, 75th, and 90th percentile user_count values, in ascending order.
CREATE TABLE technology_accessibility (device_type VARCHAR(255),user_count INT);
SELECT device_type, user_count FROM (SELECT device_type, user_count, NTILE(4) OVER (ORDER BY user_count) as percentile FROM technology_accessibility) tmp WHERE percentile IN (2, 3, 4) ORDER BY user_count ASC;
What are the total fares collected from each vehicle type, sorted in descending order?
CREATE TABLE Fares (id INT,vehicle_type VARCHAR(10),fare DECIMAL(5,2)); INSERT INTO Fares (id,vehicle_type,fare) VALUES (1,'Bus',2.50),(2,'Tram',3.00),(3,'Train',5.00);
SELECT vehicle_type, SUM(fare) FROM Fares GROUP BY vehicle_type ORDER BY SUM(fare) DESC;
What is the average number of subway delays in 'uptown' per month?
CREATE TABLE subway_delays (station VARCHAR(20),delay_time INT,delay_date DATE); INSERT INTO subway_delays (station,delay_time,delay_date) VALUES ('uptown',10,'2022-01-01'),('downtown',5,'2022-01-02'),('uptown',15,'2022-01-03');
SELECT AVG(delay_time) FROM subway_delays WHERE station = 'uptown' GROUP BY EXTRACT(MONTH FROM delay_date);
What is the average production cost of recycled polyester garments per factory?
CREATE TABLE garments (garment_id INT,garment_name TEXT,production_cost FLOAT,factory_id INT); INSERT INTO garments (garment_id,garment_name,production_cost,factory_id) VALUES (1,'Organic Cotton Tee',15.50,1),(2,'Cotton Tote Bag',8.25,1),(3,'Recycled Polyester Hoodie',28.99,2),(4,'Organic Cotton Dress',22.00,1),(5,'Hemp Trousers',35.00,3),(6,'Bamboo Shirt',27.50,3),(7,'Recycled Polyester Jacket',45.00,2),(8,'Hemp Blouse',28.00,3),(9,'Hemp Skirt',32.00,3),(10,'Recycled Polyester Shirt',24.00,4);
SELECT AVG(g.production_cost) FROM garments g GROUP BY g.factory_id HAVING COUNT(*) FILTER (WHERE g.garment_name LIKE '%Recycled Polyester%') > 0;
What are the user privacy settings related to data sharing?
CREATE TABLE privacy_settings (id INT PRIMARY KEY,user_id INT,data_sharing BOOLEAN,sharing_preferences TEXT); INSERT INTO privacy_settings (id,user_id,data_sharing,sharing_preferences) VALUES (1,1,FALSE,'{"location": false,"purchase_history": true}'); INSERT INTO privacy_settings (id,user_id,data_sharing,sharing_preferences) VALUES (2,2,TRUE,'{"location": true,"purchase_history": false}');
SELECT u.name, ps.data_sharing, JSON_EXTRACT(ps.sharing_preferences, '$.location') as location_sharing FROM users u INNER JOIN privacy_settings ps ON u.id = ps.user_id WHERE JSON_EXTRACT(ps.sharing_preferences, '$.location') = 'true';
What is the maximum number of followers for users who posted content related to "sustainable living" in the last month?
CREATE TABLE users (id INT,followers INT); CREATE TABLE posts (id INT,user_id INT,content VARCHAR(255),post_date DATE); INSERT INTO users (id,followers) VALUES (1,7000),(2,9000); INSERT INTO posts (id,user_id,content,post_date) VALUES (1,1,'Sustainable living is important','2022-03-15'),(2,2,'Love sustainable living','2022-03-20');
SELECT MAX(users.followers) FROM users JOIN posts ON users.id = posts.user_id WHERE posts.content ILIKE '%sustainable living%' AND posts.post_date >= NOW() - INTERVAL '1 month';
What is the total revenue generated from sponsored posts in the beauty category?
CREATE TABLE sponsored_posts (id INT,category VARCHAR(50),revenue FLOAT); INSERT INTO sponsored_posts (id,category,revenue) VALUES (1,'gaming',100.50),(2,'sports',150.25),(3,'gaming',200.75),(4,'beauty',50.00);
SELECT SUM(revenue) FROM sponsored_posts WHERE category = 'beauty';
Delete all nutrition data for product 'P001' in the nutrition_facts table.
CREATE TABLE nutrition_facts (product_id VARCHAR(255),calories INT,protein INT,fat INT);
DELETE FROM nutrition_facts WHERE product_id = 'P001';
Identify the top 3 suppliers with the highest number of organic vegetable shipments
CREATE TABLE suppliers (supplier_id INT,name VARCHAR(50),certified_organic BOOLEAN); INSERT INTO suppliers (supplier_id,name,certified_organic) VALUES (1,'Green Earth Farms',true),(2,'Sunny Harvest',false),(3,'Organic Roots',true); CREATE TABLE shipments (shipment_id INT,supplier_id INT,product VARCHAR(50),organic BOOLEAN); INSERT INTO shipments (shipment_id,supplier_id,product,organic) VALUES (1,1,'carrots',true),(2,1,'broccoli',true),(3,2,'apples',false),(4,3,'spinach',true),(5,3,'kale',true);
SELECT supplier_id, COUNT(*) as shipment_count FROM shipments WHERE organic = true GROUP BY supplier_id ORDER BY shipment_count DESC LIMIT 3;
What is the total quantity of all items shipped from warehouse 'NYC'?
CREATE TABLE shipments (shipment_id INT,item_code VARCHAR(5),warehouse_id VARCHAR(5),quantity INT); CREATE TABLE warehouses (warehouse_id VARCHAR(5),city VARCHAR(5),state VARCHAR(3)); INSERT INTO shipments VALUES (1,'AAA','LAX',200),(2,'BBB','NYC',300),(3,'AAA','LAX',100),(4,'CCC','NYC',50); INSERT INTO warehouses VALUES ('LAX','Los',' Angeles'),('NYC','New',' York'),('JFK','New',' York');
SELECT SUM(quantity) FROM shipments JOIN warehouses ON shipments.warehouse_id = warehouses.warehouse_id WHERE warehouses.city = 'NYC';
Calculate the total budget for biosensor technology development projects in H2 2021.
CREATE TABLE biosensor_tech(id INT,project_name TEXT,budget DECIMAL(10,2),quarter INT,year INT);
SELECT SUM(budget) FROM biosensor_tech WHERE quarter IN (3, 4) AND year = 2021;