instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many employees work in the Mining department compared to the HR department?
CREATE TABLE Employees (id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT); INSERT INTO Employees (id,name,department,salary) VALUES (1,'John Doe','Mining',75000.00),(2,'Jane Smith','HR',60000.00),(3,'Mike Johnson','Mining',80000.00),(4,'Sara Davis','HR',65000.00);
SELECT department, COUNT(*) FROM Employees GROUP BY department;
List all policies with a coverage type of 'Premium' and their corresponding policyholders' ages.
CREATE TABLE Policyholders (PolicyholderID INT,Age INT,Region VARCHAR(10)); CREATE TABLE Policies (PolicyID INT,PolicyholderID INT,Coverage VARCHAR(20),Region VARCHAR(10)); INSERT INTO Policyholders (PolicyholderID,Age,Region) VALUES (1,35,'West'); INSERT INTO Policyholders (PolicyholderID,Age,Region) VALUES (2,45,'Eas...
SELECT Policies.Coverage, Policyholders.Age FROM Policies INNER JOIN Policyholders ON Policies.PolicyholderID = Policyholders.PolicyholderID WHERE Policies.Coverage = 'Premium';
What is the minimum dissolved oxygen level (dissolved_oxygen) for each depth (depth) in the 'ocean_health_v2' table, where the water temperature (temp) is above 25 degrees Celsius?
CREATE TABLE ocean_health_v2 (depth INT,temp FLOAT,dissolved_oxygen FLOAT); INSERT INTO ocean_health_v2 (depth,temp,dissolved_oxygen) VALUES (10,26.5,5.0),(15,28.0,4.5),(20,24.5,6.0),(25,23.0,7.0),(30,27.5,5.5);
SELECT depth, MIN(dissolved_oxygen) FROM ocean_health_v2 WHERE temp > 25 GROUP BY depth;
What is the total fish weight for each country per year?
CREATE TABLE Country_Year (Country TEXT,Year INT,Fish_Weight FLOAT); INSERT INTO Country_Year (Country,Year,Fish_Weight) VALUES ('China',2019,1200000),('Indonesia',2019,800000),('India',2019,600000),('China',2020,1400000),('Indonesia',2020,900000),('India',2020,700000);
SELECT Country, Year, SUM(Fish_Weight) OVER (PARTITION BY Country) AS Total_Fish_Weight FROM Country_Year;
Which regions are facing severe water scarcity in 'WaterScarcity' table?
CREATE TABLE WaterScarcity (region VARCHAR(20),scarcity_level VARCHAR(20)); INSERT INTO WaterScarcity (region,scarcity_level) VALUES ('RegionA','Moderate'),('RegionB','Severe'),('RegionC','Critical');
SELECT region FROM WaterScarcity WHERE scarcity_level = 'Severe';
How many collective bargaining agreements were signed in California in the year 2020?
CREATE TABLE cb_agreements (id INT,state VARCHAR(255),city VARCHAR(255),year INT,num_employees INT); INSERT INTO cb_agreements (id,state,city,year,num_employees) VALUES (1,'California','San Francisco',2020,500),(2,'California','Los Angeles',2019,700),(3,'Texas','Dallas',2020,800);
SELECT COUNT(*) FROM cb_agreements WHERE state = 'California' AND year = 2020;
Insert a new donation from a donor to a nonprofit
CREATE TABLE donations (id INT PRIMARY KEY,donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,nonprofit_id INT); CREATE TABLE donors (id INT PRIMARY KEY,name VARCHAR(100),city VARCHAR(50)); CREATE TABLE nonprofits (id INT PRIMARY KEY,name VARCHAR(100),city VARCHAR(50),mission VARCHAR(200)); INSERT INTO donor...
INSERT INTO donations (id, donor_id, donation_amount, donation_date, nonprofit_id) VALUES (1, 1, 250, '2023-01-01', 1);
What is the average price of skincare products that contain only organic ingredients?
CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2)); INSERT INTO products (product_id,product_name,category,price) VALUES (1,'Liquid Eyeliner','Cosmetics',19.99),(2,'Organic Moisturizer','Skincare',35.00),(3,'Concealer','Cosmetics',12.50),(4,'Aloe Vera Gel','Skincar...
SELECT AVG(price) FROM products JOIN ingredients ON products.product_id = ingredients.product_id WHERE category = 'Skincare' AND is_organic = true GROUP BY category;
What is the maximum fare for buses in Tokyo?
CREATE TABLE if not exists bus_fares (id INT,city VARCHAR(20),max_fare DECIMAL(3,2)); INSERT INTO bus_fares (id,city,max_fare) VALUES (1,'Tokyo',3.50),(2,'Seoul',2.80);
SELECT max_fare FROM bus_fares WHERE city = 'Tokyo';
Find the number of wells drilled in each country, ordered by the most wells drilled
CREATE TABLE wells (well_id INT,country VARCHAR(50)); INSERT INTO wells (well_id,country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico');
SELECT country, COUNT(well_id) as total_wells FROM wells GROUP BY country ORDER BY total_wells DESC;
What is the total water usage in manufacturing, grouped by month and material type?
CREATE TABLE Manufacturing (manufacturing_id INT,material VARCHAR(20),water_usage FLOAT,manufacturing_date DATE); INSERT INTO Manufacturing (manufacturing_id,material,water_usage,manufacturing_date) VALUES (1,'Organic Cotton',1500.0,'2022-01-01');
SELECT DATE_FORMAT(manufacturing_date, '%Y-%m') as month, material, SUM(water_usage) as total_water_usage FROM Manufacturing GROUP BY month, material;
What is the total number of articles and blogs published by women authors from underrepresented communities in the last 6 months?
CREATE TABLE authors (id INT,name VARCHAR(50),gender VARCHAR(10),community VARCHAR(30));CREATE TABLE posts (id INT,title VARCHAR(50),author_id INT,post_type VARCHAR(10),publish_date DATE);
SELECT COUNT(*) FROM posts p JOIN authors a ON p.author_id = a.id WHERE a.gender = 'female' AND a.community IN ('LGBTQ+', 'Minority Races', 'Indigenous') AND p.publish_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE;
Which underrepresented communities were studied in AI safety research in 2020?
CREATE TABLE Underrepresented_Communities (community TEXT,year INT); CREATE TABLE AI_Safety_Research (research_name TEXT,year INT,domain TEXT); INSERT INTO Underrepresented_Communities VALUES ('Community-A',2020),('Community-B',2020); INSERT INTO AI_Safety_Research VALUES ('AI and Community-A',2020,'Safety');
SELECT Underrepresented_Communities.community FROM Underrepresented_Communities INNER JOIN AI_Safety_Research ON Underrepresented_Communities.community = AI_Safety_Research.community WHERE AI_Safety_Research.domain = 'Safety' AND Underrepresented_Communities.year = 2020;
What is the name and crop of all farmers who grow crops in 'Sandy' soil?
CREATE TABLE soil (id INT PRIMARY KEY,type VARCHAR(50),nutrients VARCHAR(50),location VARCHAR(50)); INSERT INTO soil (id,type,nutrients,location) VALUES (1,'Sandy','Nitrogen,Phosphorus,Potassium','Farmfield');
SELECT farmers.name, farmers.crop FROM farmers INNER JOIN soil ON farmers.location = soil.location WHERE soil.type = 'Sandy';
What is the total number of visitors to the museum's website from Canada and Germany in 2022?'
CREATE TABLE Website_Visitors (id INT,country VARCHAR(20),visit_year INT,num_visits INT); INSERT INTO Website_Visitors (id,country,visit_year,num_visits) VALUES (1,'Canada',2022,2500),(2,'Canada',2022,3000),(3,'Germany',2022,4000);
SELECT SUM(num_visits) FROM Website_Visitors WHERE country IN ('Canada', 'Germany') AND visit_year = 2022;
What is the average amount of waste produced by coal and gold mines?
CREATE TABLE WasteByMine (WasteID INT,MineType VARCHAR(10),Waste INT); INSERT INTO WasteByMine (WasteID,MineType,Waste) VALUES (1,'Coal',1000),(2,'Coal',1500),(3,'Gold',500);
SELECT MineType, AVG(Waste) FROM WasteByMine WHERE MineType IN ('Coal', 'Gold') GROUP BY MineType;
Find all users who have accessed the network from multiple countries within the past month.
CREATE TABLE user_activity (id INT,user_id INT,country VARCHAR(255),activity_date DATE);
SELECT user_id FROM (SELECT user_id, country, COUNT(*) as activity_count FROM user_activity WHERE activity_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY user_id, country) subquery GROUP BY user_id HAVING COUNT(*) > 1;
Update contract details for 'North America' defense projects with timelines > 2025
CREATE TABLE defense_projects (proj_id INT,proj_name VARCHAR(50),region VARCHAR(50),start_date DATE,end_date DATE); CREATE TABLE defense_contracts (cont_id INT,cont_name VARCHAR(50),proj_id INT,cont_status VARCHAR(50),cont_end_date DATE);
UPDATE defense_contracts dc SET cont_status = 'Active' FROM defense_projects dp WHERE dc.proj_id = dp.proj_id AND dp.region = 'North America' AND dp.start_date < '2026-01-01' AND dp.end_date > '2026-12-31';
What are the names and account balances of customers who have accounts in the High-Risk division and are also flagged for potential fraud?
CREATE TABLE High_Risk_Accounts (customer_id INT,name VARCHAR(50),division VARCHAR(20),account_balance DECIMAL(10,2),fraud_flag BOOLEAN); INSERT INTO High_Risk_Accounts (customer_id,name,division,account_balance,fraud_flag) VALUES (4,'Bob Brown','High-Risk',6000.00,true),(5,'Charlie Davis','High-Risk',8000.00,false);
SELECT hra.name, hra.account_balance FROM High_Risk_Accounts hra WHERE hra.division = 'High-Risk' AND hra.fraud_flag = true;
What is the total area of urban gardens in the 'urban_gardens' table?
CREATE TABLE urban_gardens (id INT,name VARCHAR(20),location VARCHAR(30),area DECIMAL(5,2));
SELECT SUM(area) FROM urban_gardens;
List all drug approval dates for the drug 'Curely' in North America.
CREATE TABLE drug_approval_2 (drug_name TEXT,approval_date DATE,region TEXT); INSERT INTO drug_approval_2 (drug_name,approval_date,region) VALUES ('Drexo','2020-02-01','Canada'),('Curely','2018-12-12','United States');
SELECT approval_date FROM drug_approval_2 WHERE drug_name = 'Curely' AND region = 'North America';
List all the mining sites, their locations and the total amount of coal mined annually, in descending order of coal mined
CREATE TABLE MiningSites (SiteID INT,SiteName VARCHAR(50),Location VARCHAR(50),AnnualCoalMined INT); INSERT INTO MiningSites (SiteID,SiteName,Location,AnnualCoalMined) VALUES (1,'Site A','New York',5000),(2,'Site B','Ohio',7000);
SELECT SiteName, Location, AnnualCoalMined FROM MiningSites ORDER BY AnnualCoalMined DESC;
Which animal species have been admitted to the rehabilitation center more than once?
CREATE TABLE rehabilitation_center (animal_id INT,species_id INT,admission_date DATE); INSERT INTO rehabilitation_center (animal_id,species_id,admission_date) VALUES (1,1,'2021-01-05'),(2,2,'2021-01-12'),(3,3,'2021-02-18'),(4,1,'2021-01-15');
SELECT species_id, COUNT(*) FROM rehabilitation_center GROUP BY species_id HAVING COUNT(*) > 1;
Insert new VR device 'Valve Index' into 'VRDevices' table.
CREATE TABLE VRDevices (DeviceID INT,DeviceName VARCHAR(20));
INSERT INTO VRDevices (DeviceID, DeviceName) VALUES (4, 'Valve Index');
What is the total revenue generated by hotels in the Middle East region that have adopted AI-powered concierge systems?
CREATE TABLE revenue (revenue_id INT,hotel_id INT,revenue_date DATE,revenue_channel TEXT,amount FLOAT); INSERT INTO revenue (revenue_id,hotel_id,revenue_date,revenue_channel,amount) VALUES (1,1,'2022-07-01','Direct',800),(2,2,'2022-08-15','OTA',700),(3,1,'2022-09-30','Direct',900); CREATE TABLE hotels (hotel_id INT,reg...
SELECT region, SUM(amount) FROM revenue r JOIN hotels h ON r.hotel_id = h.hotel_id WHERE ai_concierge = true GROUP BY region;
Delete all records in the 'HealthEquityMetrics' table where the metric value is below the median.
CREATE TABLE HealthEquityMetrics (MetricID INT,MetricType VARCHAR(255),MetricValue INT);
DELETE FROM HealthEquityMetrics WHERE MetricValue < (SELECT AVG(MetricValue) FROM HealthEquityMetrics) - (SELECT STDDEV(MetricValue) FROM HealthEquityMetrics);
What is the total value of donations by currency in the last 6 months?
CREATE TABLE currencies (id INT,name VARCHAR(255),exchange_rate DECIMAL(10,2)); CREATE TABLE donations (id INT,donor_id INT,donation_date DATE,amount DECIMAL(10,2),currency_id INT);
SELECT currencies.name, SUM(donations.amount * currencies.exchange_rate) FROM donations JOIN currencies ON donations.currency_id = currencies.id WHERE donations.donation_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE GROUP BY donations.currency_id;
What is the total production of wells in the Arabian Sea?
CREATE TABLE wells (well_id INT,name VARCHAR(50),location VARCHAR(50),production FLOAT); INSERT INTO wells (well_id,name,location,production) VALUES (1,'F1','Arabian Sea',4000),(2,'F2','Arabian Sea',3000),(3,'F3','Arabian Sea',5000);
SELECT SUM(production) FROM wells WHERE location = 'Arabian Sea';
Which ocean floor mapping projects have a budget over 25 million?
CREATE TABLE ocean_floor_mapping_projects (project_name TEXT,budget FLOAT); INSERT INTO ocean_floor_mapping_projects (project_name,budget) VALUES ('Atlantic Deep Sea Exploration',30000000.0),('Pacific Ocean Mapping Project',20000000.0),('Arctic Sea Floor Survey',22000000.0);
SELECT project_name FROM ocean_floor_mapping_projects WHERE budget > 25000000.0;
What is the total number of hours flown by all pilots in the Air Force?
CREATE TABLE PilotHours (PilotID INT,Name VARCHAR(100),Service VARCHAR(50),TotalHours FLOAT);
SELECT SUM(TotalHours) FROM PilotHours WHERE Service = 'Air Force';
Identify the suppliers that sell both organic and non-organic products?
CREATE TABLE Suppliers (SupplierID INT,SupplierName VARCHAR(50),Location VARCHAR(50)); INSERT INTO Suppliers (SupplierID,SupplierName,Location) VALUES (1,'Supplier A','Northeast'),(2,'Supplier B','Southeast'); CREATE TABLE Products (ProductID INT,ProductName VARCHAR(50),SupplierID INT,IsOrganic BOOLEAN); INSERT INTO Pr...
SELECT SupplierID FROM Products GROUP BY SupplierID HAVING COUNT(DISTINCT IsOrganic) = 2;
What is the average duration of successful restorative justice sessions in the justice_schemas.restorative_sessions table, grouped by type of session?
CREATE TABLE justice_schemas.restorative_sessions (id INT PRIMARY KEY,session_type TEXT,duration_minutes INT,was_successful BOOLEAN);
SELECT session_type, AVG(duration_minutes) FROM justice_schemas.restorative_sessions WHERE was_successful = TRUE GROUP BY session_type;
What is the total number of sculptures in the 'Renaissance' gallery?
CREATE TABLE Artworks (artwork_id INT,artwork_name VARCHAR(50),artwork_type VARCHAR(50),gallery_name VARCHAR(50)); INSERT INTO Artworks (artwork_id,artwork_name,artwork_type,gallery_name) VALUES (1,'David','Sculpture','Renaissance'),(2,'Mona Lisa','Painting','Renaissance');
SELECT COUNT(*) FROM Artworks WHERE artwork_type = 'Sculpture' AND gallery_name = 'Renaissance';
What is the average population of species in the 'biodiversity' table for those with a population less than 10000?
CREATE TABLE biodiversity (id INT,species VARCHAR(255),population INT); INSERT INTO biodiversity (id,species,population) VALUES (1,'Polar Bear',5000),(2,'Arctic Fox',10000),(3,'Caribou',20000);
SELECT AVG(population) FROM biodiversity WHERE population < 10000;
What is the average horsepower of luxury cars produced by BMW?
CREATE TABLE LuxuryCars (Id INT,Make VARCHAR(50),Model VARCHAR(50),Horsepower FLOAT); INSERT INTO LuxuryCars (Id,Make,Model,Horsepower) VALUES (1,'BMW','7 Series',340),(2,'BMW','8 Series',440),(3,'BMW','X5',300),(4,'BMW','X6',400);
SELECT AVG(Horsepower) FROM LuxuryCars WHERE Make = 'BMW' AND Model LIKE '%Luxury%';
What is the total revenue of virtual tours for a museum in Italy?
CREATE TABLE museums (museum_id INT,museum_name TEXT,country TEXT); CREATE TABLE virtual_tours (tour_id INT,museum_id INT,revenue INT); INSERT INTO museums (museum_id,museum_name,country) VALUES (1,'Museum A','Italy'),(2,'Museum B','Italy'); INSERT INTO virtual_tours (tour_id,museum_id,revenue) VALUES (1,1,1000),(2,1,1...
SELECT SUM(revenue) FROM virtual_tours INNER JOIN museums ON virtual_tours.museum_id = museums.museum_id WHERE museum_name = 'Museum A' AND country = 'Italy';
What was the total military equipment sales value to Oceania countries in 2021?
CREATE TABLE military_sales (id INT,country VARCHAR(50),year INT,value FLOAT); INSERT INTO military_sales (id,country,year,value) VALUES (1,'Australia',2021,1000000); INSERT INTO military_sales (id,country,year,value) VALUES (2,'New Zealand',2021,2000000);
SELECT SUM(value) FROM military_sales WHERE YEAR(FROM_UNIXTIME(timestamp)) = 2021 AND country IN ('Australia', 'New Zealand');
What is the total number of military equipment units that have not been maintained for over a year, and what is the total maintenance cost for those units?
CREATE TABLE military_equipment (equipment_id INT,equipment_type VARCHAR(255),last_maintenance_date DATE,next_maintenance_date DATE,unit_id INT,maintenance_cost FLOAT);
SELECT COUNT(*) AS num_equipment, SUM(maintenance_cost) AS total_cost FROM military_equipment WHERE DATEDIFF(next_maintenance_date, last_maintenance_date) > 365;
What is the average loan amount for socially responsible lending institutions in the United States?
CREATE TABLE SociallyResponsibleLending (id INT,institution_name VARCHAR(50),country VARCHAR(50),loan_amount FLOAT); INSERT INTO SociallyResponsibleLending (id,institution_name,country,loan_amount) VALUES (1,'ACME Socially Responsible Lending','USA',5000),(2,'XYZ Socially Responsible Lending','USA',7000),(3,'Community ...
SELECT AVG(loan_amount) as avg_loan_amount FROM SociallyResponsibleLending WHERE country = 'USA';
What is the minimum number of co-owners for properties in urban areas?
CREATE TABLE properties (id INT,location VARCHAR(20),coowners INT); INSERT INTO properties (id,location,coowners) VALUES (1,'urban',2),(2,'rural',1);
SELECT MIN(coowners) FROM properties WHERE location = 'urban';
What is the average heart rate for users who identify as female and have completed more than 20 runs?
CREATE TABLE users (id INT,gender VARCHAR(10)); INSERT INTO users (id,gender) VALUES (1,'Male'); INSERT INTO users (id,gender) VALUES (2,'Female'); CREATE TABLE runs (id INT,user_id INT,hr INT); INSERT INTO runs (id,user_id,hr) VALUES (1,1,145); INSERT INTO runs (id,user_id,hr) VALUES (2,2,135); INSERT INTO runs (id,...
SELECT AVG(hr) FROM runs JOIN users ON runs.user_id = users.id WHERE gender = 'Female' AND id IN (SELECT user_id FROM runs GROUP BY user_id HAVING COUNT(*) > 20);
What is the percentage of students who have taken a course on open pedagogy?
CREATE TABLE Students (StudentID INT,Age INT,Gender VARCHAR(10),CoursesTaken VARCHAR(20)); INSERT INTO Students (StudentID,Age,Gender,CoursesTaken) VALUES (1,22,'Male','Lifelong Learning'); INSERT INTO Students (StudentID,Age,Gender,CoursesTaken) VALUES (2,20,'Female','Open Pedagogy'); INSERT INTO Students (StudentID,A...
SELECT (COUNT(*) FILTER (WHERE CoursesTaken = 'Open Pedagogy')) * 100.0 / COUNT(*) FROM Students;
What is the maximum age of male residents in 'CityData' table?
CREATE TABLE CityData (resident_id INT,age INT,gender VARCHAR(10));
SELECT MAX(age) FROM CityData WHERE gender = 'Male';
What is the highest score in the 'basketball_games' table?
CREATE TABLE basketball_games (game_id INT,home_team INT,away_team INT,home_team_score INT,away_team_score INT); INSERT INTO basketball_games (game_id,home_team,away_team,home_team_score,away_team_score) VALUES (1,1,2,100,90),(2,2,1,95,105);
SELECT GREATEST(home_team_score, away_team_score) AS highest_score FROM basketball_games;
How many dance events were held in the last year?
CREATE TABLE events (event_id INT,event_type VARCHAR(50),event_date DATE); INSERT INTO events (event_id,event_type,event_date) VALUES (1,'Dance','2022-01-10'),(2,'Theater','2022-01-15'),(3,'Music','2022-02-01'),(4,'Dance','2021-12-25');
SELECT COUNT(*) FROM events WHERE event_type = 'Dance' AND event_date >= DATEADD(year, -1, CURRENT_TIMESTAMP);
How many graduate students are enrolled in each program by gender?
CREATE TABLE graduate_students (id INT,program_id INT,gender VARCHAR(10)); INSERT INTO graduate_students (id,program_id,gender) VALUES (1,1,'Female'),(2,1,'Male'),(3,2,'Female'),(4,2,'Non-binary'),(5,3,'Male'),(6,3,'Female'); CREATE TABLE graduate_programs (id INT,name VARCHAR(255)); INSERT INTO graduate_programs (id,n...
SELECT gp.name, g.gender, COUNT(g.id) FROM graduate_students g JOIN graduate_programs gp ON g.program_id = gp.id GROUP BY gp.name, g.gender;
What is the average transaction value for users who identify as LGBTQ+, per device type, for the first quarter of 2020?
CREATE TABLE users (user_id INT,user_group VARCHAR(30)); CREATE TABLE transactions (transaction_id INT,user_id INT,transaction_value FLOAT,transaction_date DATE); INSERT INTO users (user_id,user_group) VALUES (1,'LGBTQ+'); INSERT INTO transactions (transaction_id,user_id,transaction_value,transaction_date) VALUES (1,1,...
SELECT device_type, AVG(transaction_value) FROM transactions INNER JOIN users ON transactions.user_id = users.user_id WHERE EXTRACT(MONTH FROM transaction_date) BETWEEN 1 AND 3 AND user_group = 'LGBTQ+' GROUP BY device_type;
How many circular economy initiatives were launched in Osaka in 2020?
CREATE TABLE circular_economy_initiatives(location VARCHAR(20),launch_date DATE); INSERT INTO circular_economy_initiatives VALUES('Osaka','2020-01-01'),('Osaka','2020-03-15'),('Tokyo','2019-12-31');
SELECT COUNT(*) as initiatives FROM circular_economy_initiatives WHERE location = 'Osaka' AND YEAR(launch_date) = 2020;
What is the maximum ESG rating for companies in the 'finance' sector?
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_rating FLOAT); INSERT INTO companies (id,sector,ESG_rating) VALUES (1,'technology',7.5),(2,'finance',8.2),(3,'technology',7.8);
SELECT MAX(ESG_rating) FROM companies WHERE sector = 'finance';
Insert a new record into the 'products' table with the following data: 'Product 100', 'Ethical Jeans', 'Eco-Friendly', 65.99
CREATE TABLE products (product_id INT,product_name VARCHAR(50),brand VARCHAR(20),price DECIMAL(5,2));
INSERT INTO products (product_id, product_name, brand, price) VALUES (100, 'Ethical Jeans', 'Eco-Friendly', 65.99);
Identify REE market trends by year, price, and the number of companies active in REE production.
CREATE TABLE market_trends (year INT,ree_price FLOAT); INSERT INTO market_trends (year,ree_price) VALUES (2019,25.5),(2020,30.2),(2021,35.1),(2022,40.5),(2023,45.6),(2024,50.4); CREATE TABLE company_activity (year INT,active BOOLEAN); INSERT INTO company_activity (year,active) VALUES (2019,true),(2020,true),(2021,true)...
SELECT market_trends.year, market_trends.ree_price, COUNT(DISTINCT company_activity.year) as active_companies FROM market_trends INNER JOIN company_activity ON market_trends.year = company_activity.year GROUP BY market_trends.year;
List the organizations that have received donations from donors located in 'New York', but have not received donations from donors located in 'Texas' or 'Florida'.
CREATE TABLE donors (id INT,name TEXT,state TEXT); INSERT INTO donors (id,name,state) VALUES (1,'Emily Smith','New York'); CREATE TABLE donations (id INT,donor_id INT,org_id INT,donation_amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,org_id,donation_amount) VALUES (1,1,1,100.00);
SELECT organizations.name FROM organizations WHERE organizations.id IN (SELECT donations.org_id FROM donations JOIN donors ON donations.donor_id = donors.id WHERE donors.state = 'New York') AND organizations.id NOT IN (SELECT donations.org_id FROM donations JOIN donors ON donations.donor_id = donors.id WHERE donors.sta...
What is the average age of players who play VR games, grouped by the genre of the game?
CREATE TABLE Players (PlayerID int,Age int,Gender varchar(10),GameGenre varchar(20)); INSERT INTO Players (PlayerID,Age,Gender,GameGenre) VALUES (1,30,'Male','VirtualReality');
SELECT GameGenre, AVG(Age) FROM Players WHERE GameGenre = 'VirtualReality' GROUP BY GameGenre;
What is the total weight of packages shipped to California from warehouse 1?
CREATE TABLE warehouses (warehouse_id INT,warehouse_state VARCHAR(50)); INSERT INTO warehouses (warehouse_id,warehouse_state) VALUES (1,'New York'); CREATE TABLE packages (package_id INT,package_weight INT,warehouse_id INT,recipient_state VARCHAR(50)); INSERT INTO packages (package_id,package_weight,warehouse_id,recipi...
SELECT SUM(package_weight) FROM packages WHERE warehouse_id = 1 AND recipient_state = 'California';
List all clients who have not been billed in the last 6 months.
CREATE TABLE clients (client_id INT,client_name VARCHAR(255),last_contact_date DATE); INSERT INTO clients (client_id,client_name,last_contact_date) VALUES (1,'John Smith','2022-01-01'),(2,'Jane Doe','2022-02-15'),(3,'Bob Johnson','2022-06-30'); CREATE TABLE billing (bill_id INT,client_id INT,bill_date DATE); INSERT INT...
SELECT c.client_name FROM clients c LEFT OUTER JOIN billing b ON c.client_id = b.client_id WHERE b.bill_date IS NULL OR b.bill_date < DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
What is the average donation amount for each program, excluding anonymous donations, in the year 2020?
CREATE TABLE donations (id INT,donation_amount DECIMAL(10,2),donation_date DATE,program_name VARCHAR(50)); INSERT INTO donations (id,donation_amount,donation_date,program_name) VALUES (1,50.00,'2020-01-05','Program A'),(2,100.00,'2020-03-15','Program B'),(3,75.00,'2020-01-20','Program A'),(4,150.00,'2020-02-01','Progra...
SELECT p.program_name, AVG(d.donation_amount) AS avg_donation FROM donations d JOIN programs p ON d.program_name = p.program_name WHERE d.donor_name != 'Anonymous' AND YEAR(d.donation_date) = 2020 GROUP BY p.program_name;
What is the average donation amount per capita for each state in the US?
CREATE TABLE donations (donation_id INT,donor_state VARCHAR(2));CREATE TABLE states (state_id INT,state_name VARCHAR(50),state_population INT); INSERT INTO donations (donation_id,donor_state) VALUES (1,'NY'),(2,'CA'),(3,'IL'),(4,'TX'),(5,'AZ'); INSERT INTO states (state_id,state_name,state_population) VALUES (1,'New Yo...
SELECT s.state_name, AVG(d.donation_amount/s.state_population) as avg_donation_per_capita FROM donations d RIGHT JOIN states s ON d.donor_state = s.state_name GROUP BY s.state_name;
Count the unique materials at 'Museum X'?
CREATE TABLE Museum_X (Artifact_ID INT,Material VARCHAR(255)); INSERT INTO Museum_X (Artifact_ID,Material) VALUES (1,'Clay');
SELECT COUNT(DISTINCT Material) FROM Museum_X;
How many local vendors registered in the virtual marketplace are based in Tokyo and Seoul?
CREATE TABLE local_vendors (vendor_id INT,name VARCHAR(255),city VARCHAR(255)); INSERT INTO local_vendors (vendor_id,name,city) VALUES (1,'Tokyo Crafts','Tokyo'),(2,'Seoul Souvenirs','Seoul');
SELECT COUNT(*) FROM local_vendors WHERE city IN ('Tokyo', 'Seoul');
What's the average age of players who play sports games in South America?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Location VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (1,22,'Female','Brazil'); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (2,35,'Male','Argentina'); CREATE TABLE Games (GameID INT,GameName VARCHAR(20),Genre VARCHAR(...
SELECT AVG(Players.Age) FROM Players INNER JOIN Games ON Players.Location = Games.GameName WHERE Games.Genre = 'Sports' AND Players.Location IN ('Brazil', 'Argentina');
What are the total costs of support programs for 'Mentorship Program' and 'Tutoring Program' from the 'SupportPrograms' table?
CREATE TABLE SupportPrograms (program_id INT,program_name VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO SupportPrograms (program_id,program_name,cost) VALUES (2001,'Buddy Program',1500.00),(2002,'Mentorship Program',2500.00),(2003,'Tutoring Program',3500.00),(2004,'Counseling Program',4500.00);
SELECT SUM(cost) FROM SupportPrograms WHERE program_name IN ('Mentorship Program', 'Tutoring Program');
What is the maximum safety record for flights 'BB123' and 'BB456'?
CREATE TABLE FlightSafety(flight_number VARCHAR(10),safety_record INT); INSERT INTO FlightSafety VALUES('BB123',99),('BB456',97);
SELECT MAX(safety_record) FROM FlightSafety WHERE flight_number IN ('BB123', 'BB456');
How many employees work at the 'Bronze Basin' mine?'
CREATE TABLE mines (id INT,name TEXT,location TEXT,production_volume INT,product TEXT,num_employees INT); INSERT INTO mines (id,name,location,production_volume,product,num_employees) VALUES (1,'Bronze Basin','Australia',8000,'Bronze',400);
SELECT num_employees FROM mines WHERE name = 'Bronze Basin';
How many mobile subscribers are there in Texas with a data plan that is not unlimited?
CREATE TABLE mobile_subscribers (id INT,name VARCHAR(50),data_plan VARCHAR(20),state VARCHAR(50)); INSERT INTO mobile_subscribers (id,name,data_plan,state) VALUES (15,'Jasmine Smith','Limited','TX'); INSERT INTO mobile_subscribers (id,name,data_plan,state) VALUES (16,'Kevin Lewis','Limited','TX');
SELECT COUNT(*) FROM mobile_subscribers WHERE data_plan != 'Unlimited' AND state = 'TX';
List all smart city initiatives in 'City B' with their respective start dates.
CREATE TABLE SmartCities (CityID INT,CityName VARCHAR(255),InitiativeName VARCHAR(255),StartDate DATE); INSERT INTO SmartCities (CityID,CityName,InitiativeName,StartDate) VALUES (1,'City B','Smart Grid Initiative','2020-01-01');
SELECT CityName, InitiativeName, StartDate FROM SmartCities WHERE CityName = 'City B';
How many patients have not received a flu shot in Illinois as of December 2020?
CREATE TABLE flu_shots (patient_id INT,shot_date DATE,state VARCHAR(2)); INSERT INTO flu_shots (patient_id,shot_date,state) VALUES (1,'2020-11-05','IL'),(2,'2020-12-10','IL');
SELECT COUNT(*) - (SELECT COUNT(*) FROM flu_shots WHERE state = 'IL' AND MONTH(shot_date) <= 12 AND YEAR(shot_date) = 2020) AS num_no_flu_shot FROM flu_shots WHERE state = 'IL';
How many customers have a Shariah-compliant mortgage?
CREATE TABLE shariah_compliant_mortgages (mortgage_id INT,customer_id INT); INSERT INTO shariah_compliant_mortgages (mortgage_id,customer_id) VALUES (1,4),(2,5),(3,6);
SELECT COUNT(DISTINCT customer_id) FROM shariah_compliant_mortgages;
How many farmers in the 'urban' area are growing crops in the 'dry' season?
CREATE TABLE farmers (id INT,name VARCHAR(30),location VARCHAR(10),growing_season VARCHAR(10));
SELECT COUNT(*) FROM farmers WHERE location = 'urban' AND growing_season = 'dry';
What is the maximum risk score of Brown Investment Group's portfolio in the agriculture sector?
CREATE TABLE Brown_Investment_Group (id INT,sector VARCHAR(20),risk_score INT); INSERT INTO Brown_Investment_Group (id,sector,risk_score) VALUES (1,'Agriculture',50),(2,'Manufacturing',40);
SELECT MAX(risk_score) FROM Brown_Investment_Group WHERE sector = 'Agriculture';
Delete all access to justice grants awarded to organizations in Washington D.C. in 2020.
CREATE TABLE access_to_justice_grants (id INT,organization_name TEXT,city TEXT,state TEXT,award_year INT,grant_amount INT);
DELETE FROM access_to_justice_grants WHERE state = 'District of Columbia' AND city = 'Washington' AND award_year = 2020;
What is the average speed of vessels with Canadian flag in the Pacific Ocean?
CREATE TABLE Flag (flag_id INT PRIMARY KEY,flag_country VARCHAR(255)); INSERT INTO Flag (flag_id,flag_country) VALUES (2,'Canada'); CREATE TABLE Vessel (vessel_id INT PRIMARY KEY,vessel_name VARCHAR(255),flag_id INT,average_speed DECIMAL(5,2)); CREATE TABLE Region (region_id INT PRIMARY KEY,region_name VARCHAR(255));
SELECT AVG(V.average_speed) FROM Vessel V JOIN Flag F ON V.flag_id = F.flag_id JOIN Region R ON V.region_id = R.region_id WHERE F.flag_country = 'Canada' AND R.region_name = 'Pacific Ocean';
What is the total CO2 emissions for the garment manufacturing process in the 'Spring 2022' collection?
CREATE TABLE emissions (collection VARCHAR(20),co2_emissions INT); INSERT INTO emissions (collection,co2_emissions) VALUES ('Spring 2022',15000);
SELECT co2_emissions FROM emissions WHERE collection = 'Spring 2022';
Who are the top 3 contractors with the highest number of contracts?
CREATE TABLE Contracts (ID INT,Contractor VARCHAR(255),ContractValue FLOAT); INSERT INTO Contracts VALUES (1,'ABC Company',2000000),(2,'XYZ Corporation',2500000),(3,'DEF Industries',3000000),(4,'ABC Company',1800000),(5,'GHI Services',1500000);
SELECT Contractor, COUNT(*) OVER (PARTITION BY Contractor) AS ContractCount, RANK() OVER (PARTITION BY NULL ORDER BY COUNT(*) DESC) AS ContractRank FROM Contracts WHERE ContractValue > 1000000 GROUP BY Contractor HAVING ContractCount = (SELECT MAX(ContractCount) FROM Contracts WHERE Contractor = Contracts.Contractor) F...
Delete the wastewater_treatment record with the lowest treatment_cost value.
CREATE TABLE wastewater_treatment (treatment_id INT,treatment_cost FLOAT,treatment_date DATE); INSERT INTO wastewater_treatment (treatment_id,treatment_cost,treatment_date) VALUES (1,50.2,'2022-01-01'),(2,60.3,'2022-01-02'),(3,70.4,'2022-01-03');
DELETE FROM wastewater_treatment WHERE treatment_cost = (SELECT MIN(treatment_cost) FROM wastewater_treatment);
List the names and IDs of students who have received accommodations in both the academic and residential departments.
CREATE TABLE student_info (student_id INT,name VARCHAR(255)); INSERT INTO student_info (student_id,name) VALUES (1,'Jane Doe'); INSERT INTO student_info (student_id,name) VALUES (2,'Jim Smith'); CREATE TABLE student_accommodations (student_id INT,department VARCHAR(255),date DATE); INSERT INTO student_accommodations (s...
SELECT s.student_id, s.name FROM student_info s JOIN student_accommodations sa1 ON s.student_id = sa1.student_id JOIN student_accommodations sa2 ON s.student_id = sa2.student_id WHERE sa1.department <> sa2.department AND sa1.department IN ('Academic', 'Residential') GROUP BY s.student_id, s.name HAVING COUNT(DISTINCT s...
What is the total number of agricultural innovation projects and their budgets for each South American country?
CREATE TABLE projects (id INT,country VARCHAR(50),type VARCHAR(50),budget INT); INSERT INTO projects (id,country,type,budget) VALUES (1,'Argentina','Precision Agriculture',50000),(2,'Brazil','Drip Irrigation',75000);
SELECT country, COUNT(*), SUM(budget) FROM projects WHERE country IN ('Argentina', 'Brazil', 'Chile', 'Colombia', 'Peru') GROUP BY country;
Which indigenous food systems have the most community-based organizations in the 'indigenous_food_systems' table?
CREATE TABLE indigenous_food_systems (id INT,system VARCHAR(255),organizations INT); INSERT INTO indigenous_food_systems (id,system,organizations) VALUES (1,'Navajo',30),(2,'Cherokee',40),(3,'Maya',50),(4,'Maori',60);
SELECT system, organizations FROM indigenous_food_systems ORDER BY organizations DESC;
What is the highest selling product category in Q1 2022 for the Southeast region?
CREATE TABLE sales (id INT,product_category VARCHAR(50),sale_date DATE,region VARCHAR(50),revenue DECIMAL(10,2)); INSERT INTO sales (id,product_category,sale_date,region,revenue) VALUES (1,'Electronics','2022-01-05','Southeast',5000.00),(2,'Fashion','2022-03-10','Southeast',6000.00);
SELECT product_category, MAX(revenue) FROM sales WHERE sale_date BETWEEN '2022-01-01' AND '2022-03-31' AND region = 'Southeast' GROUP BY product_category;
What is the total number of concerts held at Symphony Hall in 2019?
CREATE TABLE Events (EventID int,EventName varchar(100),EventDate date,VenueName varchar(100)); INSERT INTO Events (EventID,EventName,EventDate,VenueName) VALUES (1,'Concert A','2019-01-01','Symphony Hall'),(2,'Concert B','2019-12-31','Symphony Hall'),(3,'Play X','2018-12-31','Symphony Hall');
SELECT COUNT(*) FROM Events WHERE VenueName = 'Symphony Hall' AND YEAR(EventDate) = 2019 AND EventName LIKE 'Concert%';
What is the name and efficiency of the solar panel with the highest efficiency in Japan?
CREATE TABLE solar_panels (id INT,name VARCHAR(255),efficiency FLOAT); INSERT INTO solar_panels (id,name,efficiency) VALUES (1,'SolarPanel A',18.5),(2,'SolarPanel B',20.3),(3,'SolarPanel C',21.0),(4,'SolarPanel D',19.1);
SELECT name, MAX(efficiency) FROM solar_panels WHERE country = 'Japan';
Delete all the records in the table of government employees who have not been active for the past 5 years.
CREATE TABLE employees (id INT,name VARCHAR(255),last_active DATE); INSERT INTO employees (id,name,last_active) VALUES (1,'John Doe','2016-01-01'),(2,'Jane Smith','2021-02-01'),(3,'Bob Johnson','2018-05-01');
DELETE FROM employees WHERE last_active < NOW() - INTERVAL '5 years';
What is the average number of tickets sold for basketball matches per season?
CREATE TABLE basketball_matches (match_id INT,season INT,tickets_sold INT); INSERT INTO basketball_matches (match_id,season,tickets_sold) VALUES (1,2018,35000),(2,2018,38000),(3,2019,42000);
SELECT AVG(tickets_sold) FROM basketball_matches GROUP BY season;
What is the total assets under management for a specific investment strategy?
CREATE TABLE investment_strategies (strategy_id INT,strategy_name VARCHAR(50),customer_id INT); INSERT INTO investment_strategies (strategy_id,strategy_name,customer_id) VALUES (1,'Conservative',1),(2,'Aggressive',2); CREATE TABLE investment_accounts (account_id INT,customer_id INT,balance DECIMAL(10,2)); INSERT INTO i...
SELECT SUM(investment_accounts.balance) FROM investment_accounts JOIN investment_strategies ON investment_accounts.customer_id = investment_strategies.customer_id WHERE investment_strategies.strategy_name = 'Conservative';
Show the number of spicy menu items sold in the East region.
CREATE TABLE orders (order_id INT,order_date DATE,region VARCHAR(50)); CREATE TABLE order_details (order_id INT,menu_id INT,quantity_sold INT); CREATE TABLE menu (menu_id INT,menu_name VARCHAR(255),is_spicy BOOLEAN,price DECIMAL(5,2)); INSERT INTO orders (order_id,order_date,region) VALUES (1,'2022-01-01','East'),(2,'2...
SELECT SUM(quantity_sold) as total_sold FROM order_details od JOIN menu m ON od.menu_id = m.menu_id WHERE is_spicy = TRUE AND region = 'East';
What is the difference in temperature between the hottest and coldest Mars Rovers?
CREATE TABLE mars_rovers_temperatures (rover_name TEXT,temperature FLOAT); INSERT INTO mars_rovers_temperatures (rover_name,temperature) VALUES ('Spirit',20.5),('Opportunity',15.2),('Curiosity',10.1);
SELECT MAX(temperature) - MIN(temperature) as temperature_difference FROM mars_rovers_temperatures;
What is the minimum mental health score for students in the lifelong learning program?
CREATE TABLE mental_health (id INT,student_id INT,program VARCHAR(50),score INT); INSERT INTO mental_health (id,student_id,program,score) VALUES (1,1001,'Lifelong Learning',70),(2,1002,'Lifelong Learning',75),(3,1003,'Lifelong Learning',60),(4,1004,'Traditional Program',80);
SELECT MIN(score) as min_score FROM mental_health WHERE program = 'Lifelong Learning';
What is the average funding amount for companies with at least 3 female executives?
CREATE TABLE Companies(id INT,name TEXT,funding_amount INT); CREATE TABLE Executives(id INT,company_id INT,gender TEXT); INSERT INTO Companies VALUES (1,'TechCo',5000000),(2,'GreenTech',7000000); INSERT INTO Executives VALUES (1,1,'Female'),(2,1,'Female'),(3,1,'Male'),(4,2,'Female'),(5,2,'Female'),(6,2,'Female');
SELECT AVG(Companies.funding_amount) FROM Companies INNER JOIN (SELECT company_id FROM Executives WHERE gender = 'Female' GROUP BY company_id HAVING COUNT(*) >= 3) AS FemaleExecs ON Companies.id = FemaleExecs.company_id;
What is the percentage of employees in each department who are female?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT,employment_status VARCHAR(50),gender VARCHAR(10)); INSERT INTO employees (id,name,department,salary,employment_status,gender) VALUES (1,'John Doe','IT',75000.0,'Full-time','Male'),(2,'Jane Smith','IT',80000.0,'Part-time','Female'),(3,'A...
SELECT departments.name, (COUNT(CASE WHEN employees.gender = 'Female' THEN 1 END) * 100.0 / COUNT(employees.id)) AS percentage FROM departments INNER JOIN employees ON departments.name = employees.department GROUP BY departments.name;
How many unique subscribers have both mobile and broadband plans?
CREATE TABLE mobile_subscribers (subscriber_id INT,plan_name TEXT); CREATE TABLE broadband_subscribers (subscriber_id INT,plan_name TEXT);
SELECT COUNT(DISTINCT mobile_subscribers.subscriber_id) FROM mobile_subscribers INNER JOIN broadband_subscribers ON mobile_subscribers.subscriber_id = broadband_subscribers.subscriber_id;
Find the number of green-certified buildings in each city.
CREATE TABLE cities (id INT,name VARCHAR(30)); CREATE TABLE properties (id INT,city VARCHAR(20),green_certified BOOLEAN); INSERT INTO cities (id,name) VALUES (1,'Seattle'),(2,'Portland'),(3,'Vancouver'); INSERT INTO properties (id,city,green_certified) VALUES (101,'Seattle',true),(102,'Seattle',false),(103,'Portland',t...
SELECT cities.name, COUNT(properties.id) FROM cities INNER JOIN properties ON cities.name = properties.city WHERE properties.green_certified = true GROUP BY cities.name;
What is the life expectancy in each country in the Asian region?
CREATE TABLE countries (id INT,name TEXT,region TEXT,life_expectancy INT); INSERT INTO countries (id,name,region,life_expectancy) VALUES (1,'Japan','Asia',85); INSERT INTO countries (id,name,region,life_expectancy) VALUES (2,'India','Asia',69);
SELECT name, region, life_expectancy FROM countries WHERE region = 'Asia';
What is the average environmental impact score for chemical B?
CREATE TABLE environmental_impact (chemical VARCHAR(20),score INT); INSERT INTO environmental_impact (chemical,score) VALUES ('chemical B',60); INSERT INTO environmental_impact (chemical,score) VALUES ('chemical B',70);
SELECT avg(score) as avg_score FROM environmental_impact WHERE chemical = 'chemical B';
What is the inventory level for each organic ingredient used in the menu?
CREATE TABLE inventory (ingredient VARCHAR(255),quantity INT,organic BOOLEAN); INSERT INTO inventory (ingredient,quantity,organic) VALUES ('Flour',1000,FALSE),('Tomatoes',2000,TRUE),('Cheese',3000,FALSE);
SELECT ingredient, quantity FROM inventory WHERE organic = TRUE;
How many public housing units were constructed in each ward for the last 2 years?
CREATE TABLE PublicHousing (Ward text,ConstructionDate date); INSERT INTO PublicHousing (Ward,ConstructionDate) VALUES ('Ward1','2020-01-01'),('Ward2','2021-01-01');
SELECT Ward, COUNT(*) as Units, DATE_TRUNC('year', ConstructionDate) as Year FROM PublicHousing WHERE ConstructionDate >= DATEADD(year, -2, CURRENT_DATE) GROUP BY Ward, Year;
Update an existing patient record in the patients table.
CREATE TABLE patients (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),race VARCHAR(20),ethnicity VARCHAR(30)); INSERT INTO patients (id,name,age,gender,race,ethnicity) VALUES (1,'John Doe',35,'Male','Caucasian','Non-Hispanic');
UPDATE patients SET age = 36 WHERE id = 1;
What is the average energy efficiency rating for renewable energy projects implemented in the last two years by country?
CREATE TABLE projects (project_id INT,name TEXT,rating FLOAT,country TEXT,implementation_date DATE); INSERT INTO projects (project_id,name,rating,country,implementation_date) VALUES (1,'Solar Farm',1.8,'Germany','2020-01-01'),(2,'Wind Turbine',2.2,'France','2019-01-01'),(3,'Geothermal Plant',2.0,'Germany','2021-01-01')...
SELECT country, AVG(rating) FROM projects WHERE implementation_date >= DATEADD(year, -2, GETDATE()) GROUP BY country;
How many tourists visited Spain in the last year, broken down by month?
CREATE TABLE tourist_visits (id INT,country TEXT,visit_date DATE); INSERT INTO tourist_visits (id,country,visit_date) VALUES (1,'Spain','2022-01-01');
SELECT DATE_TRUNC('month', visit_date) AS month, COUNT(*) FROM tourist_visits WHERE country = 'Spain' AND visit_date >= DATEADD(year, -1, CURRENT_DATE) GROUP BY month;
What is the total weight of cannabis flower sold by dispensaries in Washington in Q2 2022?
CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT);CREATE TABLE Sales (id INT,dispensary_id INT,weight DECIMAL,sale_date DATE,product_type TEXT); INSERT INTO Dispensaries (id,name,state) VALUES (1,'Dispensary A','Washington'); INSERT INTO Sales (id,dispensary_id,weight,sale_date,product_type) VALUES (1,1,100,'2022...
SELECT SUM(s.weight) FROM Dispensaries d INNER JOIN Sales s ON d.id = s.dispensary_id WHERE d.state = 'Washington' AND s.product_type = 'flower' AND s.sale_date BETWEEN '2022-04-01' AND '2022-06-30';
How many threat intelligence records were created in the last week?
CREATE TABLE Threat_Intelligence (id INT,threat_type VARCHAR(30),created_date DATE); INSERT INTO Threat_Intelligence (id,threat_type,created_date) VALUES (1,'Cyber Threat','2022-01-01'),(2,'Physical Threat','2022-02-01'),(3,'Cyber Threat','2022-05-01');
SELECT COUNT(*) FROM Threat_Intelligence WHERE created_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND CURRENT_DATE;
What is the total playtime (in minutes) for each game in the "PCGamingCommunity"?
CREATE TABLE Games (GameID INT PRIMARY KEY,GameName VARCHAR(50),GamingCommunity VARCHAR(50)); CREATE TABLE GameSessions (SessionID INT PRIMARY KEY,GameName VARCHAR(50),Playtime MINUTE,FOREIGN KEY (GameName) REFERENCES Games(GameName)); INSERT INTO Games (GameID,GameName,GamingCommunity) VALUES (1,'WorldOfWarcraft','PCG...
SELECT GameName, SUM(Playtime) FROM GameSessions JOIN Games ON GameSessions.GameName = Games.GameName WHERE Games.GamingCommunity = 'PCGamingCommunity' GROUP BY GameName;