instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total number of readers and their preferred genres for articles about social justice issues in the past month?
|
CREATE TABLE social_justice_articles (id INT,title VARCHAR(100),date DATE,reader_id INT);CREATE TABLE readers (id INT,name VARCHAR(50),genre VARCHAR(50)); INSERT INTO social_justice_articles VALUES (1,'Racial justice','2022-03-01',1); INSERT INTO readers VALUES (1,'John Doe','Investigative');
|
SELECT readers.genre, COUNT(DISTINCT readers.id) FROM readers INNER JOIN social_justice_articles ON readers.id = social_justice_articles.reader_id WHERE social_justice_articles.date >= DATEADD(month, -1, GETDATE()) GROUP BY readers.genre;
|
Find the total number of smart city projects in 'NY' and 'FL'
|
CREATE TABLE SmartCityProjects (id INT,project_name VARCHAR(100),project_type VARCHAR(50),city VARCHAR(50),state VARCHAR(50),capacity INT);
|
SELECT COUNT(*) FROM SmartCityProjects WHERE state IN ('NY', 'FL');
|
List all algorithms that have contributed to 'unfavorable' outcomes for 'gender' and 'race' biases
|
CREATE TABLE unfair_outcomes (id INT PRIMARY KEY,algorithm_name VARCHAR(50),outcome VARCHAR(20),bias_type VARCHAR(20),description TEXT); CREATE TABLE algorithm_details (id INT PRIMARY KEY,algorithm_name VARCHAR(50),developer VARCHAR(50),release_year INT);
|
SELECT algorithm_details.algorithm_name, algorithm_details.developer, algorithm_details.release_year FROM unfair_outcomes JOIN algorithm_details ON unfair_outcomes.algorithm_name = algorithm_details.algorithm_name WHERE unfair_outcomes.outcome = 'unfavorable' AND unfair_outcomes.bias_type IN ('gender', 'race');
|
What is the minimum age of users who have posted in the 'sports' category on Twitter?
|
CREATE TABLE user_data (user_id INT,age INT,category VARCHAR(50),platform VARCHAR(20)); INSERT INTO user_data (user_id,age,category,platform) VALUES (1,25,'sports','Twitter'),(2,35,'music','Twitter'),(3,22,'sports','Twitter');
|
SELECT MIN(age) FROM user_data WHERE category = 'sports' AND platform = 'Twitter';
|
How many users have interacted with political ads in the last month?
|
CREATE TABLE interactions (id INT,user_id INT,ad_type VARCHAR(50),interaction_date DATE); INSERT INTO interactions (id,user_id,ad_type,interaction_date) VALUES (1,1,'political','2022-01-01'),(2,1,'non-political','2022-01-02'),(3,2,'political','2022-01-03');
|
SELECT COUNT(DISTINCT user_id) FROM interactions WHERE ad_type = 'political' AND interaction_date >= DATEADD(month, -1, GETDATE());
|
Insert a new record of a carbon offset initiative in the city of New York with an offset value of 5000 tons.
|
CREATE TABLE carbon_offsets (initiative_id INT,initiative_name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),offset_value INT);
|
INSERT INTO carbon_offsets (initiative_id, initiative_name, city, state, offset_value) VALUES (1, 'Carbon Offset Initiative 1', 'New York', 'New York', 5000);
|
How many vegan meals were sold in the month of January 2022?
|
CREATE TABLE Menu (MenuID INT,MenuItem VARCHAR(50),MenuType VARCHAR(50),Price DECIMAL(5,2)); INSERT INTO Menu (MenuID,MenuItem,MenuType,Price) VALUES (1,'Vegan Tofu Stir Fry','Meal',9.99); CREATE TABLE Orders (OrderID INT,MenuID INT,OrderDate DATE,Quantity INT); INSERT INTO Orders (OrderID,MenuID,OrderDate,Quantity) VALUES (1,1,'2022-01-05',5);
|
SELECT SUM(Quantity) FROM Orders JOIN Menu ON Orders.MenuID = Menu.MenuID WHERE Menu.MenuType = 'Meal' AND Orders.OrderDate >= '2022-01-01' AND Orders.OrderDate < '2022-02-01' AND Menu.MenuItem LIKE '%vegan%';
|
Which companies have manufactured aircraft with a wingspan greater than 200 feet?
|
CREATE TABLE AircraftSpecs (Company VARCHAR(50),Model VARCHAR(50),Wingspan INT); INSERT INTO AircraftSpecs (Company,Model,Wingspan) VALUES ('Boeing','747',211),('Boeing','787 Dreamliner',197),('Airbus','A320',118),('Airbus','A380',262),('Bombardier','CRJ700',91);
|
SELECT DISTINCT Company FROM AircraftSpecs WHERE Wingspan > 200;
|
What is the name and type of each facility?
|
CREATE TABLE facilities (id INT,name TEXT,type TEXT); INSERT INTO facilities (id,name,type) VALUES (1,'Rural Clinic','Primary Care'),(2,'Urgent Care','Urgent Care'),(3,'General Hospital','Hospital');
|
SELECT name, type FROM facilities;
|
What is the average production capacity of the chemical manufacturing plants in Brazil?
|
CREATE TABLE chemical_plants (id INT,plant_name VARCHAR(100),country VARCHAR(50),production_capacity INT); INSERT INTO chemical_plants (id,plant_name,country,production_capacity) VALUES (1,'Brazil Plant 1','Brazil',3000),(2,'Brazil Plant 2','Brazil',4000);
|
SELECT AVG(production_capacity) FROM chemical_plants WHERE country = 'Brazil';
|
What is the maximum and minimum age of customers in the Northwest region?
|
CREATE TABLE customers (customer_id INT,name VARCHAR(50),age INT,region VARCHAR(20)); INSERT INTO customers (customer_id,name,age,region) VALUES (1,'John Doe',35,'Southeast'),(2,'Jane Smith',45,'Northeast'),(3,'Mike Johnson',50,'Southeast'),(4,'Alice Davis',25,'Midwest'),(5,'Bob Brown',60,'Northwest');
|
SELECT MAX(age), MIN(age) FROM customers WHERE region = 'Northwest';
|
How many garments were sold in each quarter of the year 2022?
|
CREATE TABLE sales (sale_id INT,sale_date DATE,quantity_sold INT);
|
SELECT DATE_FORMAT(sale_date, '%Y-%m') AS quarter, SUM(quantity_sold) AS total_sold FROM sales WHERE YEAR(sale_date) = 2022 GROUP BY quarter;
|
What is the number of schools in 'CityE' with a budget over 500000?
|
CREATE TABLE cities (id INT,name VARCHAR(50)); INSERT INTO cities (id,name) VALUES (1,'CityA'),(2,'CityB'),(3,'CityC'),(4,'CityD'),(5,'CityE'); CREATE TABLE budget (id INT,city_id INT,department VARCHAR(50),amount INT); INSERT INTO budget (id,city_id,department,amount) VALUES (1,1,'Education',500000),(2,1,'Health',700000),(3,2,'Education',300000),(4,2,'Health',600000),(5,3,'Transportation',900000),(6,4,'Transportation',1200000),(7,5,'Education',600000),(8,5,'Health',800000);
|
SELECT COUNT(*) FROM budget WHERE department = 'Education' AND city_id IN (SELECT id FROM cities WHERE name = 'CityE') AND amount > 500000;
|
What is the total revenue for products that have more than 5 unique ingredients sourced from African countries?
|
CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(50),price FLOAT,cruelty_free BOOLEAN); CREATE TABLE ingredients (id INT PRIMARY KEY,product_id INT,ingredient_name VARCHAR(255),source_country VARCHAR(50),safety_rating FLOAT); CREATE TABLE ingredient_sources (id INT PRIMARY KEY,ingredient_id INT,source_id INT,FOREIGN KEY (ingredient_id) REFERENCES ingredients(id)); CREATE TABLE product_sales (id INT PRIMARY KEY,product_id INT,revenue FLOAT,sale_date DATE);
|
SELECT SUM(product_sales.revenue) FROM product_sales INNER JOIN products ON product_sales.product_id = products.id INNER JOIN ingredients ON products.id = ingredients.product_id INNER JOIN ingredient_sources ON ingredients.id = ingredient_sources.ingredient_id WHERE ingredient_sources.source_id IN (SELECT id FROM sources WHERE source_country LIKE 'Africa%') GROUP BY products.id HAVING COUNT(DISTINCT ingredients.id) > 5;
|
List all users associated with a specific smart contract '0xdef...'.
|
CREATE TABLE smart_contracts (contract_address VARCHAR(64),user_address VARCHAR(64));
|
SELECT user_address FROM smart_contracts WHERE contract_address = '0xdef...';
|
Identify the top 5 countries with the highest number of sustainable fabric manufacturers.
|
CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name TEXT,country TEXT); CREATE TABLE Fabric_Manufacturers (fabric_id INT,manufacturer_id INT,is_sustainable BOOLEAN);
|
SELECT m.country, COUNT(DISTINCT fm.manufacturer_id) as manufacturer_count FROM Manufacturers m JOIN Fabric_Manufacturers fm ON m.manufacturer_id = fm.manufacturer_id WHERE fm.is_sustainable = TRUE GROUP BY m.country ORDER BY manufacturer_count DESC LIMIT 5;
|
What is the total number of defense projects initiated by CACI International in the Asia-Pacific region in 2020 and 2021?
|
CREATE TABLE defense_projects (company VARCHAR(255),region VARCHAR(255),year INT,num_projects INT); INSERT INTO defense_projects (company,region,year,num_projects) VALUES ('CACI International','Asia-Pacific',2020,20),('CACI International','Asia-Pacific',2021,25);
|
SELECT SUM(num_projects) FROM defense_projects WHERE company = 'CACI International' AND region = 'Asia-Pacific' AND year IN (2020, 2021);
|
What is the average monthly balance for all Shariah-compliant savings accounts, partitioned by account type and ranked by average balance in descending order?
|
CREATE TABLE Savings (AccountID INT,AccountType VARCHAR(255),Balance DECIMAL(10,2),IsShariahCompliant BOOLEAN); INSERT INTO Savings (AccountID,AccountType,Balance,IsShariahCompliant) VALUES (1,'Savings1',5000.00,true),(2,'Savings2',7000.00,true),(3,'Savings3',3000.00,false);
|
SELECT AccountType, AVG(Balance) as AvgBalance, ROW_NUMBER() OVER (ORDER BY AvgBalance DESC) as Rank FROM Savings WHERE IsShariahCompliant = true GROUP BY AccountType;
|
What is the total number of hospital beds in rural areas of each state?
|
CREATE TABLE beds (bed_id INT,hospital_id INT,location VARCHAR(20));
|
SELECT hospital_id, COUNT(*) FROM beds WHERE location = 'Rural' GROUP BY hospital_id;
|
List all chemical compounds with their respective safety data sheet (SDS) expiration dates and countries of origin.
|
CREATE TABLE chemical_compounds (compound_id INT,compound_name TEXT,country TEXT,sds_expiration_date DATE); INSERT INTO chemical_compounds (compound_id,compound_name,country,sds_expiration_date) VALUES (1,'Compound A','Mexico','2024-06-01'),(2,'Compound B','Brazil','2025-02-15'),(3,'Compound C','Argentina','2023-10-30');
|
SELECT compound_name, sds_expiration_date, country FROM chemical_compounds;
|
List all autonomous vehicles in 'autonomous_vehicles' table that have a total distance greater than 1000 miles, along with the make, model, and the total distance.
|
CREATE TABLE autonomous_vehicles (id INT,make VARCHAR(20),model VARCHAR(20),total_distance INT);
|
SELECT make, model, total_distance FROM autonomous_vehicles WHERE total_distance > 1000;
|
List the top 3 cities with the highest mobile subscriber count in 'Asia'
|
CREATE TABLE subscribers (id INT,type TEXT,city TEXT,region TEXT); INSERT INTO subscribers (id,type,city,region) VALUES (1,'mobile','Tokyo','Asia'); INSERT INTO subscribers (id,type,city,region) VALUES (2,'mobile','Mumbai','Asia'); INSERT INTO subscribers (id,type,city,region) VALUES (3,'mobile','Seoul','Asia'); INSERT INTO subscribers (id,type,city,region) VALUES (4,'broadband','Shanghai','Asia');
|
SELECT city, COUNT(*) as subscriber_count FROM subscribers WHERE type = 'mobile' AND region = 'Asia' GROUP BY city ORDER BY subscriber_count DESC LIMIT 3;
|
List all cybersecurity strategies and their corresponding budgets for the Asia-Pacific region.
|
CREATE TABLE CyberSecurityStrategies (StrategyID INT,Strategy TEXT,Region TEXT,Budget INT); INSERT INTO CyberSecurityStrategies (StrategyID,Strategy,Region,Budget) VALUES (1,'Firewall Implementation','Asia-Pacific',1500000); INSERT INTO CyberSecurityStrategies (StrategyID,Strategy,Region,Budget) VALUES (2,'Intrusion Detection System','Asia-Pacific',1200000);
|
SELECT Strategy, Budget FROM CyberSecurityStrategies WHERE Region = 'Asia-Pacific';
|
Identify the number of ad impressions in Italy for the 'Carousel' ad format in the last month.
|
CREATE TABLE ad_impressions (id INT,country VARCHAR(255),ad_format VARCHAR(255),timestamp TIMESTAMP); INSERT INTO ad_impressions (id,country,ad_format,timestamp) VALUES (1,'Italy','Carousel','2022-07-01 12:00:00'),(2,'Italy','Image','2022-07-02 14:30:00');
|
SELECT COUNT(*) FROM ad_impressions WHERE country = 'Italy' AND ad_format = 'Carousel' AND timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH);
|
maximum retail sales for garments manufactured in the 'Europe' region in the 'Spring' season
|
CREATE TABLE Seasons (season VARCHAR(10)); INSERT INTO Seasons (season) VALUES ('Spring'),('Summer'),('Fall'),('Winter'); CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),region VARCHAR(25)); INSERT INTO Manufacturers (manufacturer_id,manufacturer_name,region) VALUES (1,'ABC Manufacturing','Asia'),(2,'XYZ Manufacturing','Europe'),(3,'LMN Manufacturing','Asia'); CREATE TABLE Garments (garment_id INT,price DECIMAL(5,2),manufacturer_id INT,season VARCHAR(10)); INSERT INTO Garments (garment_id,price,manufacturer_id,season) VALUES (1,50.00,2,'Spring'),(2,75.00,2,'Spring'),(3,30.00,1,'Spring');
|
SELECT MAX(price) FROM Garments INNER JOIN Manufacturers ON Garments.manufacturer_id = Manufacturers.manufacturer_id WHERE region = 'Europe' AND season = 'Spring';
|
Which ethical AI organizations have a founder with the last name 'Lee'?
|
CREATE TABLE ethical_ai (id INT,organization_name TEXT,founder TEXT,region TEXT); INSERT INTO ethical_ai (id,organization_name,founder,region) VALUES (1,'AI Ethics Inc','Alex Lee','North America'),(2,'Ethical Tech Co','Jessica Chen','Canada'),(3,'AI for Good Ltd','Michael Brown','UK');
|
SELECT organization_name, founder FROM ethical_ai WHERE founder LIKE '%Lee%';
|
What is the average budget allocated for education in the city of Austin?
|
CREATE TABLE city_budget (city VARCHAR(20),category VARCHAR(20),budget INT); INSERT INTO city_budget (city,category,budget) VALUES ('Austin','Education',5000000);
|
SELECT AVG(budget) FROM city_budget WHERE city = 'Austin' AND category = 'Education';
|
What is the average time to resolution for security incidents that were caused by a specific type of malware?
|
CREATE TABLE incident (incident_id INT,incident_date DATE,incident_type VARCHAR(255),resolution_date DATE);CREATE TABLE malware (malware_id INT,malware_name VARCHAR(255),incident_id INT);
|
SELECT AVG(DATEDIFF(resolution_date, incident_date)) AS avg_resolution_time FROM incident i JOIN malware m ON i.incident_id = m.incident_id WHERE incident_type = 'malware_type';
|
What is the total contract value and average length for each contract, partitioned by vendor and ordered by total contract value in descending order?
|
CREATE TABLE contract (id INT,vendor_id INT,value FLOAT,length INT,contract_date DATE); INSERT INTO contract (id,vendor_id,value,length,contract_date) VALUES (1,1,50000,3,'2021-01-01'); INSERT INTO contract (id,vendor_id,value,length,contract_date) VALUES (2,2,25000,2,'2022-02-01'); CREATE TABLE vendor (id INT,name VARCHAR(255)); INSERT INTO vendor (id,name) VALUES (1,'Raytheon'); INSERT INTO vendor (id,name) VALUES (2,'Northrop Grumman');
|
SELECT v.name as vendor, SUM(c.value) as total_contract_value, AVG(c.length) as avg_contract_length, ROW_NUMBER() OVER (PARTITION BY v.name ORDER BY SUM(c.value) DESC) as rank FROM contract c JOIN vendor v ON c.vendor_id = v.id GROUP BY v.name ORDER BY total_contract_value DESC;
|
What is the average number of streams per user for songs released in 2019 or earlier, and longer than 4 minutes?
|
CREATE TABLE Users (user_id INT,user_name TEXT); INSERT INTO Users (user_id,user_name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'); CREATE TABLE Streams (stream_id INT,user_id INT,song_id INT,stream_date DATE); INSERT INTO Streams (stream_id,user_id,song_id,stream_date) VALUES (1,1,1,'2021-01-01'),(2,1,2,'2021-01-02'),(3,2,3,'2021-01-03'); CREATE TABLE Songs (song_id INT,song_name TEXT,release_year INT,duration INT); INSERT INTO Songs (song_id,song_name,release_year,duration) VALUES (1,'Bohemian Rhapsody',1975,351),(2,'Shape of You',2016,205),(3,'Watermelon Sugar',2020,198);
|
SELECT AVG(s.streams_per_user) FROM (SELECT COUNT(*) / COUNT(DISTINCT user_id) AS streams_per_user FROM Streams s JOIN Songs st ON s.song_id = st.song_id WHERE st.release_year <= 2019 AND st.duration > 240) s;
|
What is the average sale price of 'Joint Light Tactical Vehicles' (JLTV) sold by 'Beta Corp' in the 'Asia-Pacific' region?
|
CREATE TABLE MilitaryEquipmentSales (seller VARCHAR(255),buyer VARCHAR(255),equipment_model VARCHAR(255),sale_price DECIMAL(10,2),sale_date DATE,region VARCHAR(255));
|
SELECT AVG(sale_price) FROM MilitaryEquipmentSales WHERE seller = 'Beta Corp' AND equipment_model = 'JLTV' AND region = 'Asia-Pacific';
|
What is the average age of trees in the 'Boreal' region?
|
CREATE TABLE trees (id INT,age FLOAT,species TEXT,region TEXT); INSERT INTO trees (id,age,species,region) VALUES (1,55.3,'Pine','Boreal'),(2,82.1,'Spruce','Boreal');
|
SELECT AVG(age) FROM trees WHERE region = 'Boreal';
|
What is the average chemical waste produced per site, partitioned by region and ordered by the highest average?
|
CREATE TABLE chemical_sites (id INT,site_name VARCHAR(50),region VARCHAR(50),total_waste FLOAT); INSERT INTO chemical_sites (id,site_name,region,total_waste) VALUES (1,'Site A','Asia',150.5),(2,'Site B','Europe',125.7),(3,'Site C','Asia',200.3),(4,'Site D','Africa',75.9);
|
SELECT region, AVG(total_waste) as avg_waste FROM chemical_sites GROUP BY region ORDER BY avg_waste DESC;
|
What is the average hotel rating for each country, ordered by the highest rating first?
|
CREATE TABLE Hotels (HotelID int,HotelName varchar(255),Country varchar(255),Rating float); INSERT INTO Hotels (HotelID,HotelName,Country,Rating) VALUES (1,'Hotel X','France',4.5),(2,'Hotel Y','Spain',4.2),(3,'Hotel Z','Italy',4.7);
|
SELECT Country, AVG(Rating) as AvgRating FROM Hotels GROUP BY Country ORDER BY AvgRating DESC;
|
What is the average number of runs scored by the New York Mets in their home games in the 2023 MLB season?
|
CREATE TABLE mlb_games (id INT,home_team VARCHAR(50),away_team VARCHAR(50),runs_scored INT,season VARCHAR(10)); INSERT INTO mlb_games (id,home_team,away_team,runs_scored,season) VALUES (1,'New York Mets','Philadelphia Phillies',4,'2023'),(2,'Atlanta Braves','New York Mets',3,'2023');
|
SELECT AVG(runs_scored) FROM mlb_games WHERE home_team = 'New York Mets' AND season = '2023';
|
Which high severity vulnerabilities were found in the Americas?
|
CREATE TABLE vulnerabilities (id INT,region VARCHAR(20),severity VARCHAR(10));INSERT INTO vulnerabilities (id,region,severity) VALUES (1,'Asia Pacific','High');INSERT INTO vulnerabilities (id,region,severity) VALUES (2,'Europe','Medium');INSERT INTO vulnerabilities (id,region,severity) VALUES (3,'North America','Low');INSERT INTO vulnerabilities (id,region,severity) VALUES (4,'South America','High');
|
SELECT * FROM vulnerabilities WHERE region LIKE 'America%' AND severity = 'High';
|
What is the average amount of donations given per donor from Oceania?
|
CREATE TABLE donors (id INT,name VARCHAR(100),country VARCHAR(50),donation DECIMAL(10,2)); INSERT INTO donors (id,name,country,donation) VALUES (1,'John Doe','Australia',50.00),(2,'Jane Smith','USA',100.00),(3,'Alice Johnson','New Zealand',75.00),(4,'Bob Brown','Africa',25.00),(5,'Charlie Green','Africa',100.00);
|
SELECT AVG(donation) FROM donors WHERE country IN ('Australia', 'New Zealand');
|
What is the average duration of TV shows produced in the UK?
|
CREATE TABLE tv_shows (title VARCHAR(255),duration MINUTE,production_country VARCHAR(64));
|
SELECT AVG(duration) FROM tv_shows WHERE production_country = 'UK';
|
Identify pollution control initiatives that are not present in the pollution_control table.
|
CREATE TABLE marine_species (id INT,species VARCHAR(255)); INSERT INTO marine_species (id,species) VALUES (1,'Dolphin'),(2,'Shark'); CREATE TABLE pollution_control (id INT,initiative VARCHAR(255)); INSERT INTO pollution_control (id,initiative) VALUES (1,'Beach Cleanup'),(2,'Ocean Floor Mapping'),(3,'Coral Restoration');
|
SELECT pollution_control.initiative FROM pollution_control LEFT JOIN marine_species ON pollution_control.initiative = marine_species.species WHERE marine_species.id IS NULL;
|
Find the maximum temperature for all crops
|
CREATE TABLE crop (id INT,type VARCHAR(255),temperature FLOAT); INSERT INTO crop (id,type,temperature) VALUES (1,'corn',22.5),(2,'soybean',20.0),(3,'cotton',24.3),(4,'corn',27.5),(5,'soybean',24.5);
|
SELECT MAX(temperature) FROM crop;
|
What is the maximum investment in climate adaptation projects in the Middle East and North Africa in 2018?
|
CREATE TABLE climate_adaptation_projects (project_id INT,location VARCHAR(50),investment_amount FLOAT,investment_year INT); INSERT INTO climate_adaptation_projects (project_id,location,investment_amount,investment_year) VALUES (1,'Egypt',5000000,2018),(2,'Morocco',4000000,2018),(3,'Jordan',3000000,2018),(4,'Iraq',6000000,2018),(5,'Tunisia',2000000,2018);
|
SELECT MAX(investment_amount) FROM climate_adaptation_projects WHERE location LIKE 'Middle East%' AND investment_year = 2018;
|
List the top 3 countries with the highest number of green buildings in the 'green_buildings' table
|
CREATE TABLE green_buildings (id INT,building_name VARCHAR(50),country VARCHAR(50),certification_level VARCHAR(50));
|
SELECT country, COUNT(*) as building_count FROM green_buildings GROUP BY country ORDER BY building_count DESC LIMIT 3;
|
What is the earliest issue date for policies in Florida?
|
CREATE TABLE policyholders (id INT,name TEXT,state TEXT,policy_type TEXT,issue_date DATE); INSERT INTO policyholders (id,name,state,policy_type,issue_date) VALUES (1,'John Doe','FL','Auto','2021-01-01'); INSERT INTO policyholders (id,name,state,policy_type,issue_date) VALUES (2,'Jane Smith','FL','Home','2021-03-01'); INSERT INTO policyholders (id,name,state,policy_type,issue_date) VALUES (3,'Mike Johnson','FL','Auto','2020-12-15');
|
SELECT MIN(issue_date) FROM policyholders WHERE state = 'FL';
|
Identify the number of companies founded by individuals with disabilities
|
CREATE TABLE companies (company_id INT,company_name VARCHAR(50),founder_disability VARCHAR(20)); INSERT INTO companies VALUES (1,'Iota Inc','Yes'); INSERT INTO companies VALUES (2,'Kappa Corp',NULL);
|
SELECT COUNT(*) FROM companies WHERE founder_disability IS NOT NULL;
|
Insert data into the table for mental health parity
|
CREATE TABLE mental_health_parity (id INT PRIMARY KEY,state VARCHAR(2),year INT,accessibility FLOAT,quality FLOAT);
|
INSERT INTO mental_health_parity (id, state, year, accessibility, quality) VALUES (1, 'NY', 2020, 7.5, 8.3), (2, 'CA', 2020, 8.1, 8.7);
|
Which cruelty-free certification ratings are associated with product 105?
|
CREATE TABLE cruelty_free_certifications (id INT,product_id INT,country VARCHAR(50),rating INT); INSERT INTO cruelty_free_certifications (id,product_id,country,rating) VALUES (1,101,'USA',9),(2,102,'Canada',8),(3,101,'UK',10),(4,103,'Australia',9),(5,102,'Germany',7),(6,105,'USA',8);
|
SELECT rating FROM cruelty_free_certifications WHERE product_id = 105;
|
Delete all records from the 'fields' table where the location is not in the Gulf of Mexico.
|
CREATE TABLE fields (field_id INT,field_name TEXT,location TEXT); INSERT INTO fields (field_id,field_name,location) VALUES (1,'Field A','Gulf of Mexico'),(2,'Field B','North Sea'),(3,'Field C','Brazil');
|
DELETE FROM fields WHERE location NOT IN ('Gulf of Mexico');
|
How many deep-sea expeditions reached a depth greater than 8000 meters in the Pacific Ocean?
|
CREATE TABLE deep_sea_expeditions (id INT,mission VARCHAR(50),location VARCHAR(50),depth DECIMAL(5,2),date DATE); INSERT INTO deep_sea_expeditions (id,mission,location,depth,date) VALUES (2,'PACIFIC_PLATEAU','Pacific Ocean',8500,'2021-10-01');
|
SELECT COUNT(*) FROM deep_sea_expeditions WHERE location = 'Pacific Ocean' AND depth > 8000;
|
What is the total quantity of sustainable materials used by each brand, excluding 'Organic Cotton'?
|
CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50),Material VARCHAR(50),Quantity INT);INSERT INTO Brands (BrandID,BrandName,Material,Quantity) VALUES (1,'BrandA','Organic Cotton',3000),(2,'BrandB','Recycled Polyester',2500),(1,'BrandA','Organic Silk',1000),(3,'BrandC','Organic Cotton',2000),(2,'BrandB','Tencel',1800);
|
SELECT BrandName, SUM(Quantity) as TotalQuantity FROM Brands WHERE Material != 'Organic Cotton' GROUP BY BrandName;
|
Delete records of clients who have not made any loan payments in the Financial Wellbeing database
|
CREATE TABLE financial_wellbeing_payment (payment_id INT PRIMARY KEY,client_id INT,payment_amount DECIMAL(10,2),payment_date DATE);CREATE TABLE financial_wellbeing_client (client_id INT PRIMARY KEY,name VARCHAR(100),age INT,income DECIMAL(10,2));INSERT INTO financial_wellbeing_payment (payment_id,client_id,payment_amount,payment_date) VALUES (1,1,100.00,'2022-01-05'),(2,1,100.00,'2022-02-05'); INSERT INTO financial_wellbeing_client (client_id,name,age,income) VALUES (1,'John Doe',30,5000.00);
|
DELETE p FROM financial_wellbeing_payment p INNER JOIN financial_wellbeing_client c ON p.client_id = c.client_id WHERE NOT EXISTS (SELECT 1 FROM financial_wellbeing_payment p2 WHERE p2.client_id = c.client_id);
|
What is the average safety rating for all creative AI applications, grouped by country?
|
CREATE TABLE creative_ai (app_id INT,app_name TEXT,safety_rating REAL,country TEXT); INSERT INTO creative_ai VALUES (1,'Dalle',4.3,'USA'),(2,'GTP-3',4.5,'Canada'),(3,'Midjourney',4.7,'Australia');
|
SELECT country, AVG(safety_rating) as avg_safety_rating FROM creative_ai GROUP BY country;
|
What is the total number of words spoken by male and female characters in the 'Sci-Fi' genre in the last 3 years?
|
CREATE TABLE movies (id INT,title VARCHAR(50),genre VARCHAR(20));CREATE TABLE characters (id INT,movie_id INT,name VARCHAR(50),gender VARCHAR(10),lines_spoken INT);
|
SELECT genre, SUM(CASE WHEN gender = 'male' THEN lines_spoken ELSE 0 END) AS total_male_lines, SUM(CASE WHEN gender = 'female' THEN lines_spoken ELSE 0 END) AS total_female_lines FROM movies m JOIN characters c ON m.id = c.movie_id WHERE m.genre = 'Sci-Fi' AND publish_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) AND CURRENT_DATE GROUP BY genre;
|
List all critically endangered marine species.
|
CREATE TABLE marine_species (species_name VARCHAR(50),conservation_status VARCHAR(20)); INSERT INTO marine_species (species_name,conservation_status) VALUES ('Vaquita Porpoise','critically endangered'),('Black Abalone','endangered');
|
SELECT species_name FROM marine_species WHERE conservation_status = 'critically endangered';
|
What is the maximum depth of any marine protected area in the Atlantic?
|
CREATE TABLE marine_protected_areas (name TEXT,location TEXT,min_depth INTEGER,max_depth INTEGER); INSERT INTO marine_protected_areas (name,location,min_depth,max_depth) VALUES ('Area A','Atlantic',50,200),('Area B','Atlantic',75,175),('Area C','Indian',100,250);
|
SELECT MAX(max_depth) FROM marine_protected_areas WHERE location = 'Atlantic';
|
How many security incidents were reported in the last month from the APAC region?
|
CREATE TABLE incidents (incident_id INT,incident_date DATE,incident_region VARCHAR(255)); INSERT INTO incidents (incident_id,incident_date,incident_region) VALUES (1,'2022-01-01','North America'); INSERT INTO incidents (incident_id,incident_date,incident_region) VALUES (2,'2022-01-15','APAC'); INSERT INTO incidents (incident_id,incident_date,incident_region) VALUES (3,'2022-02-01','Europe'); INSERT INTO incidents (incident_id,incident_date,incident_region) VALUES (4,'2022-02-10','APAC'); INSERT INTO incidents (incident_id,incident_date,incident_region) VALUES (5,'2022-03-01','North America');
|
SELECT COUNT(*) FROM incidents WHERE incident_region = 'APAC' AND incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
|
How many employees were hired in Q1 of 2020?
|
CREATE TABLE Hiring (HireID INT,HireDate DATE); INSERT INTO Hiring (HireID,HireDate) VALUES (1,'2020-01-01'),(2,'2020-01-15'),(3,'2020-03-01'),(4,'2019-12-31');
|
SELECT COUNT(*) FROM Hiring WHERE HireDate BETWEEN '2020-01-01' AND '2020-03-31';
|
Delete records of Shariah-compliant loans older than 2018.
|
CREATE TABLE shariah_compliant_finance (id INT PRIMARY KEY,loan_amount DECIMAL(10,2),approval_date DATE);
|
DELETE FROM shariah_compliant_finance WHERE approval_date < '2018-01-01';
|
Delete records of donations less than $10,000 in the 'impact_investing' table.
|
CREATE TABLE impact_investing (organization_name TEXT,donation_amount INTEGER); INSERT INTO impact_investing (organization_name,donation_amount) VALUES ('Effctive Altruism Funds',50000),('GiveWell',40000),('The Life You Can Save',30000),('EIN',12000),('Impact Matters',9000);
|
DELETE FROM impact_investing WHERE donation_amount < 10000;
|
What is the clearance rate for property crimes in the city of Chicago?
|
CREATE TABLE property_crimes (id INT,city VARCHAR(20),clearance_rate FLOAT); INSERT INTO property_crimes (id,city,clearance_rate) VALUES (1,'Chicago',0.45);
|
SELECT clearance_rate FROM property_crimes WHERE city = 'Chicago';
|
What is the sales trend of ethical products in the past year, broken down by month?
|
CREATE TABLE ethical_sales (sale_id int,sale_date date,product_id int,revenue decimal,is_ethical boolean);
|
SELECT DATEPART(YEAR, sale_date) AS year, DATEPART(MONTH, sale_date) AS month, SUM(revenue) AS total_revenue FROM ethical_sales WHERE is_ethical = true GROUP BY DATEPART(YEAR, sale_date), DATEPART(MONTH, sale_date);
|
What is the count of policies issued to policyholders in 'Washington' and 'Oregon'?
|
CREATE TABLE policies (policy_id INT,policyholder_state VARCHAR(20)); INSERT INTO policies (policy_id,policyholder_state) VALUES (1,'Washington'),(2,'Oregon'),(3,'Washington');
|
SELECT COUNT(*) FROM policies WHERE policyholder_state IN ('Washington', 'Oregon');
|
Calculate the percentage of mobile subscribers who have upgraded to 5G plans, in each region.
|
CREATE TABLE subscribers (subscriber_id INT,plan_type VARCHAR(10),region VARCHAR(20)); INSERT INTO subscribers (subscriber_id,plan_type,region) VALUES (1,'5G','Northeast'); INSERT INTO subscribers (subscriber_id,plan_type,region) VALUES (2,'4G','Southeast');
|
SELECT region, COUNT(*) FILTER (WHERE plan_type = '5G') * 100.0 / COUNT(*) OVER (PARTITION BY region) as pct_5g_subscribers FROM subscribers GROUP BY region;
|
How many employees from underrepresented communities have been hired by mining operations in Australia in the last 3 months, partitioned by the mining type?
|
CREATE TABLE mining_operations (id INT,mining_type VARCHAR(255),country VARCHAR(255),num_employees INT); INSERT INTO mining_operations (id,mining_type,country,num_employees) VALUES (1,'open pit','Australia',100),(2,'underground','Australia',150),(3,'open pit','Australia',120); CREATE TABLE employee_demographics (id INT,mining_operation_id INT,employee_group VARCHAR(255)); INSERT INTO employee_demographics (id,mining_operation_id,employee_group) VALUES (1,1,'underrepresented'),(2,2,'not underrepresented'),(3,3,'underrepresented');
|
SELECT mining_type, COUNT(*) as num_underrepresented_employees FROM mining_operations JOIN employee_demographics ON mining_operations.id = employee_demographics.mining_operation_id WHERE country = 'Australia' AND operation_date >= DATEADD(month, -3, GETDATE()) AND employee_group = 'underrepresented' GROUP BY mining_type;
|
Find the difference in the number of players between 'Rocket League' and 'Overwatch'
|
CREATE TABLE PlayerDemographics (PlayerID INT,Game VARCHAR(20),Age INT); INSERT INTO PlayerDemographics (PlayerID,Game,Age) VALUES (1,'Rocket League',19),(2,'Overwatch',22),(3,'Minecraft',15),(4,'Rocket League',20),(5,'Overwatch',24);
|
SELECT COUNT(CASE WHEN Game = 'Rocket League' THEN 1 END) - COUNT(CASE WHEN Game = 'Overwatch' THEN 1 END) FROM PlayerDemographics
|
Find the average rainfall level in India in the last 60 days?
|
CREATE TABLE if NOT EXISTS rainfall_levels (id int,location varchar(50),rainfall float,timestamp datetime); INSERT INTO rainfall_levels (id,location,rainfall,timestamp) VALUES (1,'India',54.8,'2022-03-25 10:00:00');
|
SELECT AVG(rainfall) FROM rainfall_levels WHERE location = 'India' AND timestamp >= DATE_SUB(NOW(), INTERVAL 60 DAY);
|
Update the "disease_prevalence" table to include the latest data for the "heart_disease" column.
|
CREATE TABLE disease_prevalence (id INT,region VARCHAR(50),heart_disease INT,cancer INT,diabetes INT);
|
UPDATE disease_prevalence SET heart_disease = (SELECT latest_heart_disease_data FROM latest_data) WHERE region = 'Rural Appalachia';
|
What is the total revenue of fair labor practice brands in each region?
|
CREATE TABLE Brands (brand_id INT,brand_name VARCHAR(50),ethical BOOLEAN); CREATE TABLE Sales (sale_id INT,brand_id INT,revenue DECIMAL(10,2)); CREATE TABLE Regions (region_id INT,region VARCHAR(50)); CREATE TABLE BrandRegions (brand_id INT,region_id INT);
|
SELECT R.region, SUM(S.revenue) FROM Brands B INNER JOIN Sales S ON B.brand_id = S.brand_id INNER JOIN BrandRegions BR ON B.brand_id = BR.brand_id INNER JOIN Regions R ON BR.region_id = R.region_id WHERE B.ethical = TRUE GROUP BY R.region;
|
How many farmers are there in 'Asia' without any production records?
|
CREATE TABLE farmers_3 (id INT,name TEXT,country TEXT,certification TEXT); INSERT INTO farmers_3 (id,name,country,certification) VALUES (1,'Farmer A','India','organic'),(2,'Farmer B','China','conventional'),(3,'Farmer C','Japan','organic');
|
SELECT COUNT(*) FROM farmers_3 WHERE country = 'Asia' AND id NOT IN (SELECT farmer_id FROM crops);
|
List all cities with their respective counts of electric vehicles
|
CREATE TABLE public.vehicles (id INT,type VARCHAR(20),city VARCHAR(20)); INSERT INTO public.vehicles (id,type,city) VALUES (1,'electric_car','San Francisco'),(2,'conventional_car','San Francisco'),(3,'electric_bus','Los Angeles'),(4,'conventional_bus','Los Angeles'),(5,'electric_car','New York');
|
SELECT city, COUNT(*) FROM public.vehicles WHERE type LIKE 'electric%' GROUP BY city;
|
Display the average speed of buses with registration numbers starting with 'B' for the month of May 2022
|
CREATE TABLE bus_speed (id INT PRIMARY KEY,bus_id INT,speed INT,speed_time TIMESTAMP);
|
SELECT bus_id, AVG(speed) AS avg_speed FROM bus_speed WHERE bus_id LIKE 'B%' AND speed_time >= '2022-05-01 00:00:00' AND speed_time < '2022-06-01 00:00:00' GROUP BY bus_id;
|
How many military technologies were developed in each year, according to the military_technologies table?
|
CREATE TABLE military_technologies (id INT,name VARCHAR(100),branch VARCHAR(50),year_developed INT);
|
SELECT year_developed, COUNT(*) as technology_count FROM military_technologies GROUP BY year_developed;
|
List vessels with the highest cargo weight transported in Q1 2022
|
VESSEL(vessel_id,vessel_name); TRIP(voyage_id,trip_date,vessel_id,cargo_weight)
|
SELECT v.vessel_id, v.vessel_name, SUM(t.cargo_weight) AS total_cargo_weight FROM VESSEL v JOIN TRIP t ON v.vessel_id = t.vessel_id WHERE t.trip_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY v.vessel_id, v.vessel_name ORDER BY total_cargo_weight DESC LIMIT 10;
|
Calculate the average financial wellbeing score for each age group
|
CREATE TABLE age_groups (age_group_id INT,age_group VARCHAR(10),start_age INT,end_age INT);
|
CREATE TABLE financial_wellbeing_scores (score_id INT, score DECIMAL(18,2), age_group_id INT); SELECT age_group, AVG(score) FROM age_groups INNER JOIN financial_wellbeing_scores ON age_groups.age_group_id = financial_wellbeing_scores.age_group_id GROUP BY age_group;
|
What is the average donation amount for donors from the USA and Canada?
|
CREATE TABLE donations (id INT,donor_id INT,donation_amount DECIMAL,donation_date DATE,donor_country VARCHAR); INSERT INTO donations (id,donor_id,donation_amount,donation_date,donor_country) VALUES (1,101,'500','2021-01-01','USA'),(2,102,'300','2021-02-01','Canada'),(3,103,'800','2021-03-01','Mexico');
|
SELECT AVG(donation_amount) as avg_donation_amount FROM donations WHERE donor_country IN ('USA', 'Canada');
|
What is the minimum research grant amount awarded to a faculty member in the Physics department?
|
CREATE TABLE Faculty (FacultyID INT,Name VARCHAR(50),Department VARCHAR(50),Gender VARCHAR(10),Salary INT); INSERT INTO Faculty (FacultyID,Name,Department,Gender,Salary) VALUES (1,'Alice','Physics','Female',80000); INSERT INTO Faculty (FacultyID,Name,Department,Gender,Salary) VALUES (2,'Bob','Physics','Male',85000); CREATE TABLE ResearchGrants (GrantID INT,FacultyID INT,Amount INT); INSERT INTO ResearchGrants (GrantID,FacultyID,Amount) VALUES (1,1,90000); INSERT INTO ResearchGrants (GrantID,FacultyID,Amount) VALUES (2,2,95000);
|
SELECT MIN(Amount) FROM ResearchGrants rg INNER JOIN Faculty f ON rg.FacultyID = f.FacultyID WHERE f.Department = 'Physics';
|
Get the total CO2 emissions per quarter for the facilities located in California.
|
CREATE TABLE facility_location (facility_id INT,state VARCHAR(50),quarter INT,year INT,co2_emissions FLOAT); INSERT INTO facility_location (facility_id,state,quarter,year,co2_emissions) VALUES (1,'California',1,2021,1500),(1,'California',2,2021,1600),(1,'California',3,2021,1700),(1,'California',4,2021,1800),(2,'California',1,2021,1200),(2,'California',2,2021,1300),(2,'California',3,2021,1400),(2,'California',4,2021,1500);
|
SELECT state, quarter, year, SUM(co2_emissions) as total_co2_emissions FROM facility_location WHERE state = 'California' GROUP BY state, quarter, year;
|
Which textile suppliers have provided eco-friendly materials to the company?
|
CREATE TABLE TextileSuppliers (id INT,supplier_name TEXT,eco_friendly_material BOOLEAN); INSERT INTO TextileSuppliers (id,supplier_name,eco_friendly_material) VALUES (1,'GreenTextiles',true),(2,'BlueFabrics',false),(3,'EcoFiberCo',true);
|
SELECT supplier_name FROM TextileSuppliers WHERE eco_friendly_material = true;
|
Find the total number of animals in each habitat that were educated in a given year, excluding 'Habitat F'?
|
CREATE TABLE Habitats (id INT,name VARCHAR(20)); INSERT INTO Habitats (id,name) VALUES (1,'Habitat A'),(2,'Habitat B'),(3,'Habitat C'),(4,'Habitat D'),(5,'Habitat E'),(6,'Habitat F'); CREATE TABLE Animals (id INT,name VARCHAR(20),habitat_id INT); INSERT INTO Animals (id,name,habitat_id) VALUES (1,'Tiger',3),(2,'Elephant',3),(3,'Giraffe',1),(4,'Zebra',4),(5,'Kangaroo',5),(6,'Penguin',6); CREATE TABLE Education (animal_id INT,date DATE); INSERT INTO Education (animal_id,date) VALUES (1,'2022-01-01'),(2,'2022-01-02'),(3,'2022-03-01'),(4,'2022-03-02'),(5,'2022-04-01'),(6,'2022-04-02');
|
SELECT subquery.habitat_id, SUM(num_animals) FROM (SELECT habitat_id, COUNT(*) as num_animals FROM Animals INNER JOIN Education ON Animals.id = Education.animal_id WHERE habitat_id != 6 GROUP BY habitat_id, YEAR(Education.date)) AS subquery GROUP BY subquery.habitat_id
|
What is the average property size in sustainable neighborhoods in Tokyo?
|
CREATE TABLE Tokyo_Neighborhoods (Neighborhood_Name TEXT,Sustainability BOOLEAN); INSERT INTO Tokyo_Neighborhoods (Neighborhood_Name,Sustainability) VALUES ('Shinjuku',true),('Shibuya',false),('Ginza',true),('Tsukiji',false),('Asakusa',true); CREATE TABLE Tokyo_Properties (Neighborhood_Name TEXT,Property_Size INTEGER); INSERT INTO Tokyo_Properties (Neighborhood_Name,Property_Size) VALUES ('Shinjuku',800),('Shibuya',700),('Ginza',900),('Tsukiji',600),('Asakusa',850);
|
SELECT AVG(Tokyo_Properties.Property_Size) FROM Tokyo_Properties INNER JOIN Tokyo_Neighborhoods ON Tokyo_Properties.Neighborhood_Name = Tokyo_Neighborhoods.Neighborhood_Name WHERE Tokyo_Neighborhoods.Sustainability = true;
|
Which spacecraft have been launched by ISRO?
|
CREATE TABLE Spacecraft (id INT,name VARCHAR(255),manufacturer VARCHAR(255),type VARCHAR(255),launch_date DATE); INSERT INTO Spacecraft (id,name,manufacturer,type,launch_date) VALUES (1,'Chandrayaan-1','ISRO','Robotic','2008-10-22'); INSERT INTO Spacecraft (id,name,manufacturer,type,launch_date) VALUES (2,'Mars Orbiter Mission','ISRO','Robotic','2013-11-05');
|
SELECT name FROM Spacecraft WHERE manufacturer = 'ISRO';
|
Insert new records for the OnlineEngagement table for the 'Virtual Tour' event.
|
CREATE TABLE OnlineEngagement (EventID INT,EventName VARCHAR(50),TotalParticipants INT,AvgDuration FLOAT);
|
INSERT INTO OnlineEngagement (EventID, EventName, TotalParticipants, AvgDuration) VALUES (201, 'Virtual Tour', 120, 45.5);
|
Identify the mining operations with the highest water usage in South Africa.
|
CREATE TABLE MiningOperations (OperationID INT,MineName VARCHAR(100),OperationType VARCHAR(50),Country VARCHAR(50),StartDate DATE,EndDate DATE); INSERT INTO MiningOperations (OperationID,MineName,OperationType,Country,StartDate,EndDate) VALUES (1,'Golden Mine','Exploration','South Africa','2015-01-01','2015-12-31'),(2,'Silver Ridge','Extraction','USA','2016-01-01','2016-12-31'); CREATE TABLE EnvironmentalImpact (OperationID INT,CO2Emissions INT,WaterUsage INT,WasteGeneration INT); INSERT INTO EnvironmentalImpact (OperationID,CO2Emissions,WaterUsage,WasteGeneration) VALUES (1,5000,10000,2000),(2,7000,12000,2500);
|
SELECT mo.OperationID, mo.MineName, ei.WaterUsage FROM MiningOperations mo JOIN EnvironmentalImpact ei ON mo.OperationID = ei.OperationID WHERE mo.Country = 'South Africa' ORDER BY ei.WaterUsage DESC LIMIT 1;
|
Find the average budget of climate change projects
|
CREATE TABLE climate_projects (project_id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),budget FLOAT); INSERT INTO climate_projects (project_id,name,country,budget) VALUES (1,'Solar Power India','India',5000000); INSERT INTO climate_projects (project_id,name,country,budget) VALUES (2,'Wind Farms India','India',7000000);
|
SELECT AVG(budget) FROM climate_projects;
|
What is the total donation amount from volunteers in India, grouped by fiscal quarter?
|
CREATE TABLE donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,is_volunteer BOOLEAN); INSERT INTO donations (id,donor_name,donation_amount,donation_date,is_volunteer) VALUES (1,'Ravi Sharma',200.00,'2021-04-15',true),(2,'Priya Gupta',300.00,'2021-07-30',true),(3,'Akash Patel',150.00,'2021-10-05',false),(4,'Meera Singh',500.00,'2021-01-01',true);
|
SELECT DATE_FORMAT(donation_date, '%Y-%V') AS fiscal_quarter, SUM(donation_amount) FROM donations WHERE is_volunteer = true AND donor_country = 'India' GROUP BY fiscal_quarter;
|
What is the total number of ethical certifications for all brands?
|
CREATE TABLE Brands (brand_id INT PRIMARY KEY,name VARCHAR(50),ethical_certifications INT); INSERT INTO Brands (brand_id,name,ethical_certifications) VALUES (1,'Sustainable Fashion',3),(2,'Eco Friendly Wear',2);
|
SELECT SUM(ethical_certifications) FROM Brands;
|
How many employees have been hired in the past year, broken down by department?
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),HireDate DATE); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,HireDate) VALUES (1,'John','Doe','IT','2021-06-01'),(2,'Jane','Doe','HR','2022-02-15');
|
SELECT Department, COUNT(*) FROM Employees WHERE HireDate >= DATEADD(year, -1, GETDATE()) GROUP BY Department;
|
What is the maximum water conservation effort by any state in a month?
|
CREATE TABLE state_conservation_efforts (state TEXT,month INT,water_conserved FLOAT); INSERT INTO state_conservation_efforts (state,month,water_conserved) VALUES ('CA',1,100000),('CA',2,120000),('NY',1,150000),('NY',2,180000);
|
SELECT state, MAX(water_conserved) FROM state_conservation_efforts GROUP BY state;
|
Determine the maximum grant amount awarded to a faculty member in the Mathematics department.
|
CREATE TABLE grants (id INT,faculty_id INT,year INT,amount DECIMAL(10,2)); INSERT INTO grants (id,faculty_id,year,amount) VALUES (1,1,2020,85000); INSERT INTO grants (id,faculty_id,year,amount) VALUES (2,2,2019,35000); CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO faculty (id,name,department) VALUES (1,'Hannah','Mathematics'); INSERT INTO faculty (id,name,department) VALUES (2,'Ibrahim','Computer Science');
|
SELECT MAX(g.amount) FROM grants g JOIN faculty f ON g.faculty_id = f.id WHERE f.department = 'Mathematics';
|
What is the average donation amount per program in Canada?
|
CREATE TABLE donations (id INT,program TEXT,country TEXT,donation_amount DECIMAL(10,2)); INSERT INTO donations VALUES (1,'Education','Canada',200.00),(2,'Healthcare','Canada',300.00),(3,'Environment','Canada',400.00);
|
SELECT program, AVG(donation_amount) FROM donations WHERE country = 'Canada' GROUP BY program;
|
What is the average age of players from each country?
|
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (2,30,'Female','Canada'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (3,22,'Male','Mexico');
|
SELECT Country, AVG(Age) FROM Players GROUP BY Country;
|
Delete the record of the customer with the lowest assets value from 'Greater China' region.
|
CREATE TABLE customers (id INT,name VARCHAR(100),region VARCHAR(50),assets_value FLOAT); INSERT INTO customers (id,name,region,assets_value) VALUES (1,'Li Xiang','Greater China',350000.00);
|
DELETE FROM customers WHERE id = (SELECT id FROM customers WHERE region = 'Greater China' ORDER BY assets_value ASC LIMIT 1);
|
What is the average number of hospital beds per rural hospital in Canada and the United States?
|
CREATE TABLE RuralHospitals (Country VARCHAR(20),HospitalName VARCHAR(50),NumberOfBeds INT); INSERT INTO RuralHospitals (Country,HospitalName,NumberOfBeds) VALUES ('Canada','Hospital A',75),('Canada','Hospital B',100),('USA','Hospital C',50),('USA','Hospital D',75);
|
SELECT AVG(NumberOfBeds) FROM RuralHospitals WHERE Country IN ('Canada', 'USA') AND HospitalName IN ('Hospital A', 'Hospital B', 'Hospital C', 'Hospital D') GROUP BY Country;
|
What was the total amount spent on education in Afghanistan in 2015?
|
CREATE TABLE expenses (id INT,category TEXT,country TEXT,year INT,amount_spent DECIMAL(10,2)); INSERT INTO expenses
|
SELECT SUM(amount_spent) FROM expenses WHERE category = 'education' AND country = 'Afghanistan' AND year = 2015;
|
Find the total number of socially responsible loans issued in Canada in 2021.
|
CREATE TABLE socially_responsible_loans (id INT,year INT,country VARCHAR(255),loan_type VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO socially_responsible_loans (id,year,country,loan_type,amount) VALUES (1,2021,'Canada','Microloan',5000.00),(2,2021,'Canada','Education Loan',20000.00);
|
SELECT COUNT(*) FROM socially_responsible_loans WHERE year = 2021 AND country = 'Canada' AND loan_type = 'Microloan' OR loan_type = 'Education Loan';
|
What are the top 3 regions with the highest average investment sums?
|
CREATE TABLE investments (region VARCHAR(20),investment_sum NUMERIC(12,2)); INSERT INTO investments (region,investment_sum) VALUES ('Asia',50000),('Europe',75000),('Africa',35000),('North America',90000),('South America',45000),('Australia',60000);
|
SELECT region, AVG(investment_sum) as avg_investment FROM investments GROUP BY region ORDER BY avg_investment DESC LIMIT 3;
|
Get the status and count of shipments for each warehouse_id from the shipment table where the shipped_date is between '2021-01-01' and '2021-12-31' grouped by status and warehouse_id
|
CREATE TABLE shipment (shipment_id VARCHAR(10),status VARCHAR(20),warehouse_id VARCHAR(10),carrier_name VARCHAR(30),shipped_date DATE);
|
SELECT status, warehouse_id, COUNT(*) as count FROM shipment WHERE shipped_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY status, warehouse_id;
|
What is the average salary for employees who have completed diversity and inclusion training, by department?
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),CompletedDiversityTraining BOOLEAN,Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,CompletedDiversityTraining,Salary) VALUES (1,'John','Doe','IT',TRUE,80000.00),(2,'Jane','Doe','HR',FALSE,85000.00);
|
SELECT Department, AVG(Salary) FROM Employees WHERE CompletedDiversityTraining = TRUE GROUP BY Department;
|
How many marine research stations are in the Pacific Ocean?
|
CREATE TABLE research_stations (station_name VARCHAR(50),ocean VARCHAR(20)); INSERT INTO research_stations (station_name,ocean) VALUES ('Hawaii Ocean Observing System','Pacific'),('Monterey Bay Aquarium Research Institute','Pacific');
|
SELECT COUNT(*) FROM research_stations WHERE ocean = 'Pacific';
|
What is the total climate finance committed to renewable energy projects in Asia?
|
CREATE TABLE climate_finance (project_name VARCHAR(255),region VARCHAR(255),sector VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO climate_finance (project_name,region,sector,amount) VALUES ('Solar Power Plant','Asia','Renewable Energy',5000000.00); INSERT INTO climate_finance (project_name,region,sector,amount) VALUES ('Wind Turbine Project','Asia','Renewable Energy',7000000.00);
|
SELECT SUM(amount) FROM climate_finance WHERE region = 'Asia' AND sector = 'Renewable Energy';
|
Update the 'decentralized_applications' table to set the app_category to 'Lending' for all records where the app_name is 'Aave'
|
CREATE TABLE decentralized_applications (app_id INT PRIMARY KEY,app_name VARCHAR(100),app_category VARCHAR(50));
|
UPDATE decentralized_applications SET app_category = 'Lending' WHERE app_name = 'Aave';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.