instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total donation amount by funding source and age group, for visual arts events held in the past two years, broken down by quarter? | CREATE TABLE Events (id INT,date DATE,funding_source VARCHAR(50),event_type VARCHAR(50)); INSERT INTO Events (id,date,funding_source,event_type) VALUES (1,'2019-01-01','Foundation','Visual Arts'),(2,'2020-02-01','Individual','Visual Arts'); CREATE TABLE Donations (id INT,event_id INT,age_group VARCHAR(20),donation_amou... | SELECT DATE_FORMAT(e.date, '%Y-%m-%q') AS quarter, e.funding_source, d.age_group, SUM(d.donation_amount) AS total_donation FROM Events e INNER JOIN Donations d ON e.id = d.event_id WHERE e.date >= DATE_SUB(CURRENT_DATE, INTERVAL 2 YEAR) AND e.event_type = 'Visual Arts' GROUP BY quarter, e.funding_source, d.age_group; |
What is the number of new membership signups per month, comparing 2021 and 2022? | CREATE TABLE Memberships (MembershipID INT,UserID INT,SignUpDate DATE); INSERT INTO Memberships (MembershipID,UserID,SignUpDate) VALUES (1,1,'2021-01-01'),(2,2,'2021-02-01'),(3,3,'2022-01-01'); | SELECT EXTRACT(YEAR FROM SignUpDate) as Year, EXTRACT(MONTH FROM SignUpDate) as Month, COUNT(*) as Count FROM Memberships GROUP BY Year, Month ORDER BY Year, Month; |
What is the maximum number of intelligence operations conducted by the United States in a single year? | CREATE TABLE intelligence_operations (country VARCHAR(255),year INT,num_operations INT); INSERT INTO intelligence_operations (country,year,num_operations) VALUES ('United States',2015,5000),('United States',2016,6000),('United Kingdom',2015,3000),('United Kingdom',2016,3500); | SELECT MAX(num_operations) FROM intelligence_operations WHERE country = 'United States'; |
What is the price of the most expensive garment in the 'Fall 2022' collection? | CREATE TABLE garment_prices (collection VARCHAR(20),garment_name VARCHAR(30),price INT); INSERT INTO garment_prices (collection,garment_name,price) VALUES ('Fall 2022','Cashmere Sweater',300); | SELECT collection, MAX(price) FROM garment_prices GROUP BY collection; |
What is the total waste generation by material type in the city of Seattle for the year 2020?' | CREATE TABLE waste_generation (city VARCHAR(20),year INT,material VARCHAR(20),weight FLOAT); INSERT INTO waste_generation (city,year,material,weight) VALUES ('Seattle',2020,'Plastic',1200),('Seattle',2020,'Paper',2000),('Seattle',2020,'Glass',1500); | SELECT material, SUM(weight) as total_weight FROM waste_generation WHERE city = 'Seattle' AND year = 2020 GROUP BY material; |
What is the total number of heritage sites in Europe that have been restored by each restorer, and who has restored the most heritage sites? | CREATE TABLE HeritageSites(SiteID INT,SiteName VARCHAR(100),Country VARCHAR(50),RestorationDate DATE,RestorerID INT); CREATE TABLE Restorers(RestorerID INT,RestorerName VARCHAR(100)); | SELECT r.RestorerName, COUNT(*) as NumberOfSitesRestored FROM HeritageSites h INNER JOIN Restorers r ON h.RestorerID = r.RestorerID GROUP BY r.RestorerName; SELECT RestorerName, NumberOfSitesRestored FROM (SELECT r.RestorerName, COUNT(*) as NumberOfSitesRestored FROM HeritageSites h INNER JOIN Restorers r ON h.Restor... |
What is the total number of patients with chronic conditions in African American communities in Florida? | CREATE TABLE chronic_conditions (patient_id INT,community VARCHAR(20),condition VARCHAR(20)); INSERT INTO chronic_conditions (patient_id,community,condition) VALUES (1,'African American','Diabetes'); INSERT INTO chronic_conditions (patient_id,community,condition) VALUES (2,'Caucasian','Heart Disease'); | SELECT COUNT(*) FROM chronic_conditions WHERE community = 'African American'; |
List all records from the 'PlayerData' table where 'Country' is 'USA' | CREATE TABLE PlayerData (PlayerID INT,Name VARCHAR(50),Age INT,Country VARCHAR(50)); INSERT INTO PlayerData (PlayerID,Name,Age,Country) VALUES ('1','John Doe','25','USA'),('2','Jane Smith','30','Canada'),('3','Mike Johnson','22','USA'),('4','Sarah Lee','28','Canada'),('5','Lucas Martinez','35','Mexico'); | SELECT * FROM PlayerData WHERE Country = 'USA'; |
How many AI safety incidents were reported by each organization in the last year? | CREATE TABLE incidents (id INT,date DATE,organization TEXT,type TEXT); | SELECT organization, COUNT(*) as num_incidents FROM incidents WHERE date >= (CURRENT_DATE - INTERVAL '1 year') GROUP BY organization ORDER BY num_incidents DESC; |
List all journalists who have not published any articles in the last 6 months | CREATE TABLE journalists (id INT PRIMARY KEY,name TEXT NOT NULL); CREATE TABLE articles (id INT PRIMARY KEY,title TEXT NOT NULL,author_id INT,published_at DATE); | SELECT journalists.name FROM journalists LEFT JOIN articles ON journalists.id = articles.author_id WHERE articles.id IS NULL OR published_at < DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
What is the name, location, and height of all dams in the United States with a height greater than 300 feet? | CREATE TABLE Dams (DamID INT,Name TEXT,Height FLOAT,Location TEXT,Country TEXT); INSERT INTO Dams (DamID,Name,Height,Location,Country) VALUES (1,'Hoover Dam',726.3,'Black Canyon,Nevada','USA'); | SELECT Dams.Name, Dams.Location, Dams.Height FROM Dams WHERE Dams.Height > 300.0 AND Dams.Country = 'USA' |
What is the number of new members by month for the last two years? | CREATE SCHEMA members; CREATE TABLE members (member_id INT,member_since DATE); INSERT INTO members (member_id,member_since) VALUES (1,'2021-01-01'),(2,'2021-03-12'),(3,'2022-02-15'); | SELECT DATEPART(year, member_since) as year, DATEPART(month, member_since) as month, COUNT(*) as new_members FROM members WHERE member_since >= DATEADD(year, -2, GETDATE()) GROUP BY DATEPART(year, member_since), DATEPART(month, member_since); |
What is the total revenue for each route segment in the 'transit_routes' table? | CREATE TABLE transit_routes (route_id INT,segment_name VARCHAR(255),start_station VARCHAR(255),end_station VARCHAR(255),fare FLOAT); | SELECT segment_name, SUM(fare) as total_revenue FROM transit_routes GROUP BY segment_name; |
What is the name and launch date of satellites launched by JAXA? | CREATE TABLE Satellites (id INT PRIMARY KEY,name TEXT,launch_date DATE,type TEXT,agency TEXT); INSERT INTO Satellites (id,name,launch_date,type,agency) VALUES (3,'Hayabusa','2003-05-09','Asteroid Explorer','JAXA'); INSERT INTO Satellites (id,name,launch_date,type,agency) VALUES (4,'Akatsuki','2010-05-20','Venus Climate... | SELECT Satellites.name, Satellites.launch_date FROM Satellites WHERE Satellites.agency = 'JAXA' ORDER BY Satellites.launch_date DESC; |
What is the maximum carbon price (in USD/tonne) in the European Union Emissions Trading System (EU ETS) for the year 2021? | CREATE TABLE carbon_prices (id INT,date DATE,price_usd_tonne FLOAT,market TEXT); INSERT INTO carbon_prices (id,date,price_usd_tonne,market) VALUES (1,'2021-01-01',30.0,'EU ETS'),(2,'2021-02-01',32.0,'EU ETS'),(3,'2021-03-01',35.0,'EU ETS'); | SELECT MAX(price_usd_tonne) FROM carbon_prices WHERE market = 'EU ETS' AND date BETWEEN '2021-01-01' AND '2021-12-31'; |
Who are the top 3 most followed users in the 'Asia-Pacific' region who made posts with the hashtag '#technology' in the last 30 days? | CREATE TABLE posts (post_id INT,user_id INT,post_date DATE,hashtags VARCHAR(255)); CREATE TABLE users (user_id INT,name VARCHAR(255),followers INT,region VARCHAR(255)); INSERT INTO posts (post_id,user_id,post_date,hashtags) VALUES (1,1,'2021-08-01','#technology'); INSERT INTO users (user_id,name,followers,region) VALUE... | SELECT users.name, users.followers FROM posts JOIN users ON posts.user_id = users.user_id WHERE hashtags LIKE '%#technology%' AND users.region = 'Asia-Pacific' AND post_date >= NOW() - INTERVAL 30 DAY GROUP BY users.name ORDER BY users.followers DESC LIMIT 3; |
Update the environmental impact of 'Isopropyl Alcohol' to 3.0 in the environmental_impact_table | CREATE TABLE environmental_impact_table (record_id INT,chemical_id INT,environmental_impact_float); | UPDATE environmental_impact_table SET environmental_impact_float = 3.0 WHERE chemical_id = (SELECT chemical_id FROM chemical_table WHERE chemical_name = 'Isopropyl Alcohol'); |
Display the total number of troops for each branch in the 'Troops' table | CREATE TABLE Troops (id INT,branch VARCHAR(255),troop_count INT); | SELECT branch, SUM(troop_count) as total_troops FROM Troops GROUP BY branch; |
Get the number of articles published each month by 'BBC' in 2022. | CREATE TABLE articles (id INT,title TEXT,publication_date DATE,publisher TEXT); | SELECT MONTH(publication_date) AS month, COUNT(*) AS count FROM articles WHERE publisher = 'BBC' AND YEAR(publication_date) = 2022 GROUP BY month; |
Delete the record in the 'appointments' table for an appointment scheduled on 2022-08-15 with a provider based in Los Angeles, CA | CREATE TABLE appointments (appointment_id INT,appointment_date DATE,provider_id INT); CREATE TABLE providers (provider_id INT,first_name VARCHAR(50),last_name VARCHAR(50),specialty VARCHAR(50),city VARCHAR(50),state VARCHAR(2)); | DELETE FROM appointments WHERE appointment_date = '2022-08-15' AND provider_id IN (SELECT provider_id FROM providers WHERE city = 'Los Angeles' AND state = 'CA'); |
What is the total funding raised by startups with a Black CEO? | CREATE TABLE company (id INT,name TEXT,CEO_gender TEXT,CEO_ethnicity TEXT); INSERT INTO company (id,name,CEO_gender,CEO_ethnicity) VALUES (1,'ElevateHer','female','Black'); INSERT INTO company (id,name,CEO_gender,CEO_ethnicity) VALUES (2,'GreenSpectrum','male','Black'); CREATE TABLE funding_round (company_id INT,round_... | SELECT SUM(funding_round.round_amount) FROM company JOIN funding_round ON company.id = funding_round.company_id WHERE company.CEO_ethnicity = 'Black'; |
What is the average yield for 'Rice' and 'Wheat' crops? | CREATE TABLE AgriculturalProductivity (id INT,farmer_id INT,crop_name VARCHAR(50),yield INT,year INT); INSERT INTO AgriculturalProductivity (id,farmer_id,crop_name,yield,year) VALUES (1,1,'Corn',80,2020); INSERT INTO AgriculturalProductivity (id,farmer_id,crop_name,yield,year) VALUES (2,2,'Soybeans',60,2021); INSERT IN... | SELECT crop_name, AVG(yield) FROM AgriculturalProductivity WHERE crop_name IN ('Rice', 'Wheat') GROUP BY crop_name; |
Calculate the monthly water savings due to conservation initiatives in the state of New South Wales, Australia | CREATE TABLE states (id INT,name VARCHAR(255)); INSERT INTO states (id,name) VALUES (1,'New South Wales'); CREATE TABLE water_meter_readings (id INT,state_id INT,consumption FLOAT,reading_date DATE); INSERT INTO water_meter_readings (id,state_id,consumption,reading_date) VALUES (1,1,100,'2022-01-01'); CREATE TABLE cons... | SELECT EXTRACT(MONTH FROM water_meter_readings.reading_date) as month, SUM(conservation_initiatives.savings) as monthly_savings FROM water_meter_readings JOIN states ON water_meter_readings.state_id = states.id JOIN conservation_initiatives ON states.id = conservation_initiatives.state_id WHERE states.name = 'New South... |
Identify the number of construction workers in Oregon in 2020 | CREATE TABLE workforce_statistics (state VARCHAR(255),year INTEGER,num_workers INTEGER); INSERT INTO workforce_statistics (state,year,num_workers) VALUES ('Oregon',2020,15000),('Oregon',2019,14000),('Washington',2020,16000); | SELECT SUM(num_workers) FROM workforce_statistics WHERE state = 'Oregon' AND year = 2020; |
What was the total budget for each program in FY2022? | CREATE TABLE Programs (program_id INT,program_name VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO Programs (program_id,program_name,budget) VALUES (1001,'Education',25000.00),(1002,'Health',30000.00),(1003,'Environment',20000.00); | SELECT program_id, budget as total_budget FROM Programs WHERE program_id IN (1001, 1002, 1003); |
What is the average time to resolution for security incidents in the finance department, and how does it compare to the average for the entire organization? | CREATE TABLE incidents (incident_id INT,incident_date DATE,resolution_date DATE,department VARCHAR(50)); | SELECT AVG(DATEDIFF(resolution_date, incident_date)) as avg_resolution_time_finance FROM incidents WHERE department = 'finance'; SELECT AVG(DATEDIFF(resolution_date, incident_date)) as avg_resolution_time_org FROM incidents; |
Find the number of bridges built before 2010 | CREATE TABLE Bridges (id INT,name TEXT,built_year INT,location TEXT); INSERT INTO Bridges (id,name,built_year,location) VALUES (1,'Golden Gate',1937,'San Francisco'); INSERT INTO Bridges (id,name,built_year,location) VALUES (2,'Sydney Harbour Bridge',1932,'Sydney'); | SELECT COUNT(*) FROM Bridges WHERE built_year < 2010; |
What are the total revenue and number of menu items sold for each day at the 'Healthy Habits' restaurant in the past week? | CREATE TABLE revenue (restaurant_id INT,date DATE,menu_item VARCHAR(50),revenue INT); INSERT INTO revenue (restaurant_id,date,menu_item,revenue) VALUES (5,'2022-06-01','Quinoa Salad',500),(5,'2022-06-01','Tofu Wrap',700),(5,'2022-06-02','Quinoa Salad',600),(5,'2022-06-02','Tofu Wrap',800); | SELECT date, SUM(revenue) as total_revenue, COUNT(DISTINCT menu_item) as menu_items_sold FROM revenue WHERE restaurant_id = 5 AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY date; |
What is the total number of publications by graduate students in the Humanities department in 2022? | CREATE TABLE GraduateStudents (StudentID INT,FirstName VARCHAR(30),LastName VARCHAR(30),Department VARCHAR(30)); CREATE TABLE Publications (PublicationID INT,StudentID INT,PublicationYear INT,Title TEXT); INSERT INTO GraduateStudents (StudentID,FirstName,LastName,Department) VALUES (1,'Liam','Williams','Humanities'),(2... | SELECT COUNT(*) FROM GraduateStudents g JOIN Publications p ON g.StudentID = p.StudentID WHERE g.Department = 'Humanities' AND p.PublicationYear = 2022; |
What is the total CO2 emission of hemp production in Germany? | CREATE TABLE co2_emissions_hemp (country VARCHAR(255),production_type VARCHAR(255),co2_emission INT); INSERT INTO co2_emissions_hemp (country,production_type,co2_emission) VALUES ('Germany','farming',3500); INSERT INTO co2_emissions_hemp (country,production_type,co2_emission) VALUES ('Germany','processing',5000); | SELECT SUM(co2_emission) FROM co2_emissions_hemp WHERE country = 'Germany'; |
Display the number of accessible vehicles in the 'Purple Line' fleet | CREATE TABLE accessible_fleet (vehicle_type VARCHAR(50),fleet_name VARCHAR(50),is_accessible BOOLEAN); INSERT INTO accessible_fleet (vehicle_type,fleet_name,is_accessible) VALUES ('Purple Line','Bus',true),('Purple Line','Train',false),('Orange Line','Bus',true); | SELECT COUNT(*) FROM accessible_fleet WHERE fleet_name = 'Purple Line' AND is_accessible = true; |
What is the average price of vegan skincare products in Singapore? | CREATE TABLE SkincareProducts (productID INT,productName VARCHAR(50),category VARCHAR(50),country VARCHAR(50),isVegan BOOLEAN,price DECIMAL(5,2)); INSERT INTO SkincareProducts (productID,productName,category,country,isVegan,price) VALUES (1,'Vitamin C Serum','Skincare','Singapore',TRUE,30.99); | SELECT AVG(price) FROM SkincareProducts WHERE category = 'Skincare' AND country = 'Singapore' AND isVegan = TRUE; |
List the names of organizations and their respective website URLs from the 'Organizations' table, limited to the top 10 organizations with the highest total donations? | CREATE TABLE Organizations (OrgID INT,Name VARCHAR(50),Website VARCHAR(50),TotalDonations DECIMAL(10,2)); | SELECT Name, Website FROM (SELECT Name, Website, TotalDonations, ROW_NUMBER() OVER (ORDER BY TotalDonations DESC) AS Rank FROM Organizations) AS Subquery WHERE Rank <= 10; |
What are the top 5 artists with the most exhibitions in the US? | CREATE TABLE Artworks (ArtworkID INT,Name VARCHAR(100),Artist VARCHAR(100),Year INT); | SELECT Artworks.Artist, COUNT(DISTINCT Exhibitions.ExhibitionID) AS ExhibitionCount FROM Artworks INNER JOIN Exhibitions ON Artworks.ArtworkID = Exhibitions.ArtworkID WHERE Exhibitions.Country = 'US' GROUP BY Artworks.Artist ORDER BY ExhibitionCount DESC LIMIT 5; |
List the unique devices used in the month of February 2023 for users from Germany.' | CREATE SCHEMA device_usage; CREATE TABLE device_data (user_id INT,country VARCHAR(50),device VARCHAR(50),usage_date DATE); INSERT INTO device_data VALUES (1,'Germany','Smartwatch','2023-02-01'),(2,'France','Fitness Tracker','2023-02-02'),(3,'Germany','Heart Rate Monitor','2023-02-03'); | SELECT DISTINCT device FROM device_usage.device_data WHERE country = 'Germany' AND usage_date >= '2023-02-01' AND usage_date <= '2023-02-28'; |
Identify the number of unique mental health services provided by each mental health facility, partitioned by the facility type. | CREATE TABLE mental_health_facilities (facility_id INT,name VARCHAR(255),location VARCHAR(255),type VARCHAR(255),capacity INT); INSERT INTO mental_health_facilities (facility_id,name,location,type,capacity) VALUES (1,'Serenity House','New York,NY','Inpatient',50),(2,'Harmony House','New York,NY','Inpatient',80),(3,'Tra... | SELECT f.facility_id, f.type, COUNT(DISTINCT s.service) as unique_services FROM mental_health_facilities f JOIN mental_health_services s ON f.facility_id = s.facility_id GROUP BY f.facility_id, f.type; |
Show the number of active volunteers for each program | CREATE TABLE volunteers (id INT,program_id INT,is_active BOOLEAN); | SELECT p.name, COUNT(v.id) as active_volunteers FROM programs p JOIN volunteers v ON p.id = v.program_id WHERE v.is_active = TRUE GROUP BY p.id; |
What is the average number of likes on posts by users from the United States, for each month in 2021? | CREATE TABLE users (id INT,country VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,likes INT,post_date DATE); INSERT INTO users (id,country) VALUES (1,'United States'); INSERT INTO posts (id,user_id,likes,post_date) VALUES (1,1,10,'2021-01-01'); | SELECT EXTRACT(MONTH FROM post_date) AS month, AVG(likes) AS avg_likes FROM posts JOIN users ON posts.user_id = users.id WHERE users.country = 'United States' AND post_date >= '2021-01-01' AND post_date < '2022-01-01' GROUP BY EXTRACT(MONTH FROM post_date); |
What is the oldest certification date in the 'green_buildings' table? | CREATE TABLE green_buildings (building_id INT,building_name VARCHAR(100),location VARCHAR(100),certification_date DATE); INSERT INTO green_buildings (building_id,building_name,location,certification_date) VALUES (1,'Green Building 1','Canada','2018-01-01'),(2,'Green Building 2','Brazil','2020-05-15'); | SELECT MIN(certification_date) FROM green_buildings; |
Identify teachers who have not attended any professional development in the last 12 months. | CREATE TABLE Teachers (id INT,name VARCHAR(20)); INSERT INTO Teachers (id,name) VALUES (1,'Jane Doe'),(2,'Robert Smith'),(3,'Alice Johnson'); CREATE TABLE ProfessionalDevelopment (teacher_id INT,attended_date DATE); INSERT INTO ProfessionalDevelopment (teacher_id,attended_date) VALUES (1,'2022-01-01'),(2,'2022-02-15'),... | SELECT t.name FROM Teachers t LEFT JOIN ProfessionalDevelopment pd ON t.id = pd.teacher_id WHERE pd.teacher_id IS NULL OR pd.attended_date < DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH); |
What is the total number of electric vehicle charging stations in 'London', 'Madrid', and 'Rome' combined? | CREATE TABLE charging_stations (id INT,city TEXT,count INT); INSERT INTO charging_stations (id,city,count) VALUES (1,'London',100),(2,'Madrid',75),(3,'Rome',125); | SELECT SUM(count) FROM charging_stations WHERE city IN ('London', 'Madrid', 'Rome'); |
What is the average dissolved oxygen level for marine aquaculture sites in the US? | CREATE TABLE aquaculture_sites (site_id INT,site_name TEXT,country TEXT,latitude DECIMAL(9,6),longitude DECIMAL(9,6),dissolved_oxygen FLOAT); INSERT INTO aquaculture_sites (site_id,site_name,country,latitude,longitude,dissolved_oxygen) VALUES (1,'Site A','USA',38.534154,-120.740540,7.2),(2,'Site B','USA',41.383140,-100... | SELECT AVG(dissolved_oxygen) FROM aquaculture_sites WHERE country = 'USA'; |
How many ingredients in the 'lip_balm' product are not organic? | CREATE TABLE product_ingredients (product_id INT,ingredient VARCHAR(255),percentage FLOAT,PRIMARY KEY (product_id,ingredient)); | SELECT COUNT(ingredient) FROM product_ingredients WHERE product_id = (SELECT product_id FROM products WHERE product_name = 'lip_balm') AND ingredient NOT LIKE 'organic%'; |
What is the total installed capacity of wind power projects in the renewable_energy schema? | CREATE SCHEMA IF NOT EXISTS renewable_energy; CREATE TABLE IF NOT EXISTS renewable_energy.wind_power (project_id INT NOT NULL,location VARCHAR(255) NOT NULL,installed_capacity FLOAT NOT NULL,PRIMARY KEY (project_id)); | SELECT SUM(installed_capacity) FROM renewable_energy.wind_power; |
What is the total number of volunteers and their average hours of service, grouped by their occupation? | CREATE TABLE Volunteers (VolunteerID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),Occupation VARCHAR(20),VolunteerHours INT); INSERT INTO Volunteers (VolunteerID,Age,Gender,Occupation,VolunteerHours) VALUES (1,22,'Male','Software Engineer',50); | SELECT Occupation, COUNT(*), AVG(VolunteerHours) FROM Volunteers GROUP BY Occupation; |
What is the maximum cargo weight transported by a vessel on a single trip in the Baltic Sea? | CREATE TABLE Vessels (VesselID INT,Name TEXT,Type TEXT,MaxCapacity INT); CREATE TABLE Trips (TripID INT,VesselID INT,Date DATE,CargoWeight INT,Region TEXT); INSERT INTO Vessels VALUES (1,'Vessel 1','Cargo',50000); INSERT INTO Trips VALUES (1,1,'2022-01-01',40000,'Baltic Sea'); | SELECT MAX(Trips.CargoWeight) FROM Trips INNER JOIN Vessels ON Trips.VesselID = Vessels.VesselID WHERE Trips.Region = 'Baltic Sea'; |
What is the total amount of water consumed by each mining operation in 2019? | CREATE TABLE water_consumption (operation_id INT,operation_name TEXT,year INT,water_consumed INT); | SELECT operation_name, SUM(water_consumed) AS total_water_consumed FROM water_consumption WHERE year = 2019 GROUP BY operation_name; |
What is the total carbon footprint for each ingredient category? | CREATE TABLE IngredientCategories (id INT,name VARCHAR(255),carbon_footprint INT); | SELECT name, SUM(carbon_footprint) FROM IngredientCategories GROUP BY name; |
Display the bottom 25% of textile sourcing by production volume, partitioned by textile type. | CREATE TABLE production_volumes (id INT,textile_type VARCHAR(255),production_country VARCHAR(255),volume INT); INSERT INTO production_volumes (id,textile_type,production_country,volume) VALUES (1,'cotton','India',5000); | SELECT textile_type, production_country, volume, NTILE(4) OVER (PARTITION BY textile_type ORDER BY volume) as tier FROM production_volumes; |
What are the projects and budgets of resource management initiatives in Russia or Norway, with a budget greater than 600,000, that started before 2021? | CREATE TABLE Resource_Management (id INT,project VARCHAR(100),location VARCHAR(100),budget FLOAT,start_date DATE); INSERT INTO Resource_Management (id,project,location,budget,start_date) VALUES (1,'Arctic Drilling','Russia',800000,'2019-01-01'); INSERT INTO Resource_Management (id,project,location,budget,start_date) VA... | SELECT project, budget FROM Resource_Management WHERE (location = 'Russia' OR location = 'Norway') AND budget > 600000 AND start_date < '2021-01-01' |
What are the details of the teachers who have not undergone professional development in the last year? | CREATE TABLE teachers (id INT,name VARCHAR(255),last_workshop_date DATE); INSERT INTO teachers (id,name,last_workshop_date) VALUES (1,'Teacher A','2021-06-01'),(2,'Teacher B','2020-12-15'),(3,'Teacher C',NULL); | SELECT id, name, last_workshop_date FROM teachers WHERE last_workshop_date < DATEADD(year, -1, GETDATE()); |
What is the average donation amount for each cause across all regions? | CREATE TABLE Donations (DonationID INT,Cause VARCHAR(50),Amount DECIMAL(10,2),Region VARCHAR(50)); INSERT INTO Donations (DonationID,Cause,Amount,Region) VALUES (1,'Education',2000,'Africa'),(2,'Health',3000,'Asia'),(3,'Education',1000,'Africa'),(4,'Environment',4000,'Europe'); | SELECT Cause, AVG(Amount) as AverageDonation FROM Donations GROUP BY Cause; |
List the names of suppliers providing eco-friendly packaging materials in California. | CREATE TABLE Supplier (id INT,name VARCHAR(50),state VARCHAR(50)); INSERT INTO Supplier (id,name,state) VALUES (1,'Eco-Friendly Packaging','California'); INSERT INTO Supplier (id,name,state) VALUES (2,'Green Solutions','Texas'); CREATE TABLE Product (id INT,supplier_id INT,name VARCHAR(50),is_eco_friendly BOOLEAN); INS... | SELECT s.name FROM Supplier s JOIN Product p ON s.id = p.supplier_id WHERE s.state = 'California' AND p.is_eco_friendly = TRUE; |
How many investments were made in startups founded by underrepresented minorities in the last 3 years? | CREATE TABLE company (id INT,name TEXT,founding_year INT,founder_race TEXT); INSERT INTO company (id,name,founding_year,founder_race) VALUES (1,'Acme Corp',2010,'White'),(2,'Beta Inc',2012,'Black'); CREATE TABLE investment (id INT,company_id INT,funding_amount INT,investment_year INT); INSERT INTO investment (id,compan... | SELECT COUNT(*) FROM investment JOIN company ON investment.company_id = company.id WHERE investment_year >= (SELECT YEAR(CURRENT_DATE) - 3) AND founder_race IN ('Black', 'Hispanic', 'Indigenous', 'Asian Pacific Islander', 'Native Hawaiian'); |
What is the total funding raised by startups founded by underrepresented minorities in the technology sector? | CREATE TABLE company (id INT,name TEXT,industry TEXT,founder_race TEXT); INSERT INTO company (id,name,industry,founder_race) VALUES (1,'TechBoost','Technology','African American'); INSERT INTO company (id,name,industry,founder_race) VALUES (2,'Shopify','E-commerce','Asian'); CREATE TABLE funding_round (company_id INT,r... | SELECT SUM(funding_round.round_size) FROM company INNER JOIN funding_round ON company.id = funding_round.company_id WHERE company.founder_race IS NOT NULL; |
Calculate the average 'health_score' of 'Tilapia' and 'Cod' in the 'FishHealth' table, grouped by week | CREATE TABLE FishHealth (id INT,fish_id INT,health_score INT,date_entered TIMESTAMP); | SELECT DATE_PART('week', date_entered) AS week, AVG(health_score) FROM FishHealth WHERE species IN ('Tilapia', 'Cod') GROUP BY week; |
What is the total budget allocated for each department in the current fiscal year? | CREATE TABLE Budget (BudgetID INT,Department TEXT,Allocation INT,FiscalYear INT); INSERT INTO Budget (BudgetID,Department,Allocation,FiscalYear) VALUES (1,'Education',50000,2022),(2,'Healthcare',75000,2022); | SELECT Department, SUM(Allocation) FROM Budget WHERE FiscalYear = 2022 GROUP BY Department; |
How many suppliers in India have been certified with 'GOTS' (Global Organic Textile Standard)? | CREATE TABLE certifications(certification_id INT,certification_name TEXT); INSERT INTO certifications(certification_id,certification_name) VALUES (1,'GOTS'),(2,'Fair Trade'),(3,'SA8000'); CREATE TABLE suppliers(supplier_id INT,supplier_name TEXT,country TEXT); INSERT INTO suppliers(supplier_id,supplier_name,country) VA... | SELECT COUNT(DISTINCT suppliers.supplier_id) FROM suppliers JOIN supplier_certifications ON suppliers.supplier_id = supplier_certifications.supplier_id JOIN certifications ON supplier_certifications.certification_id = certifications.certification_id WHERE suppliers.country = 'India' AND certifications.certification_nam... |
Which Tanker vessels have a max speed greater than 16? | CREATE TABLE Vessels (vessel_id VARCHAR(10),name VARCHAR(20),type VARCHAR(20),max_speed FLOAT); INSERT INTO Vessels (vessel_id,name,type,max_speed) VALUES ('1','Vessel A','Cargo',20.5),('2','Vessel B','Tanker',15.2),('3','Vessel C','Tanker',19.1),('4','Vessel D','Cargo',12.6),('5','Vessel E','Cargo',16.2),('6','Vessel ... | SELECT vessel_id, name FROM Vessels WHERE type = 'Tanker' AND max_speed > 16; |
What is the total score of players who have played a game in the last 30 days? | CREATE TABLE GameSessions (GameSessionID INT,PlayerID INT,GameDate DATE); INSERT INTO GameSessions (GameSessionID,PlayerID,GameDate) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-02'),(3,3,'2022-01-03'),(4,4,'2022-01-04'),(5,5,'2022-01-05'); CREATE TABLE PlayerScores (PlayerID INT,Score INT); INSERT INTO PlayerScores (Player... | SELECT SUM(Score) FROM Players, GameSessions, PlayerScores WHERE Players.PlayerID = PlayerScores.PlayerID AND GameSessions.PlayerID = Players.PlayerID AND GameDate >= CURDATE() - INTERVAL 30 DAY; |
Which departments have the highest percentage of female employees? | CREATE TABLE departments (id INT,department_name VARCHAR(50),gender VARCHAR(10)); | SELECT department_name, (SUM(CASE WHEN gender = 'female' THEN 1 ELSE 0 END) / COUNT(*)) * 100 AS percentage FROM departments GROUP BY department_name ORDER BY percentage DESC; |
Find the dispensary with the lowest total sales revenue in the second quarter of 2021. | CREATE TABLE DispensarySales (dispensary_id INT,sale_revenue DECIMAL(10,2),sale_date DATE); | SELECT dispensary_id, SUM(sale_revenue) as total_revenue FROM DispensarySales WHERE sale_date >= '2021-04-01' AND sale_date <= '2021-06-30' GROUP BY dispensary_id ORDER BY total_revenue ASC LIMIT 1; |
What was the waste generation by material type for the residential sector in 2020? | CREATE TABLE waste_generation_by_material(year INT,sector VARCHAR(255),material VARCHAR(255),amount INT); INSERT INTO waste_generation_by_material VALUES (2018,'Residential','Paper',400),(2018,'Residential','Plastic',200),(2018,'Residential','Glass',300),(2019,'Residential','Paper',420),(2019,'Residential','Plastic',21... | SELECT material, SUM(amount) FROM waste_generation_by_material WHERE year = 2020 AND sector = 'Residential' GROUP BY material; |
Which creative AI applications have an explainability score that is at least 10 points higher than the average explainability score for all creative AI applications? | CREATE TABLE Creative_AI (app_name TEXT,explainability_score INT); INSERT INTO Creative_AI (app_name,explainability_score) VALUES ('AI Painter',80),('AI Poet',85),('AI Music Composer',70); | SELECT app_name FROM Creative_AI WHERE explainability_score >= (SELECT AVG(explainability_score) FROM Creative_AI) + 10; |
What is the total carbon emission for each city in the Arctic region in the last year? | CREATE TABLE CarbonEmission (City VARCHAR(100),Emission FLOAT,Region VARCHAR(100)); INSERT INTO CarbonEmission (City,Emission,Region) VALUES ('Tromso',6000,'Arctic'); INSERT INTO CarbonEmission (City,Emission,Region) VALUES ('Murmansk',8000,'Arctic'); | SELECT City, SUM(Emission) OVER (PARTITION BY City ORDER BY City DESC) AS TotalEmission FROM CarbonEmission WHERE Region = 'Arctic' AND YEAR(CurrentDate) - YEAR(DateInstalled) BETWEEN 1 AND 12; |
What is the count of patients with mental health disorders by their race/ethnicity? | CREATE TABLE patients (id INT,has_mental_health_disorder BOOLEAN,race_ethnicity VARCHAR(50)); INSERT INTO patients (id,has_mental_health_disorder,race_ethnicity) VALUES (1,true,'Asian'),(2,false,'White'),(3,true,'Hispanic'),(4,true,'Black'); | SELECT race_ethnicity, COUNT(*) as count FROM patients WHERE has_mental_health_disorder = true GROUP BY race_ethnicity; |
List all biotech startup funding events greater than $5M in Texas since 2020-01-01. | CREATE TABLE funding_events (id INT,startup_name VARCHAR(100),state VARCHAR(100),amount FLOAT,date DATE); | SELECT startup_name, amount FROM funding_events WHERE state = 'Texas' AND amount > 5000000 AND date >= '2020-01-01'; |
What is the NTILE ranking of each project based on their budget? | CREATE TABLE projects (id INT PRIMARY KEY,name VARCHAR(50),budget INT,department VARCHAR(50)); INSERT INTO projects (id,name,budget,department) VALUES (1,'Project X',100000,'Education'); INSERT INTO projects (id,name,budget,department) VALUES (2,'Project Y',150000,'Education'); INSERT INTO projects (id,name,budget,depa... | SELECT name, budget, NTILE(4) OVER (ORDER BY budget DESC) AS quartile FROM projects; |
Find the difference in energy efficiency scores between consecutive months for each state in the "MonthlyEnergyEfficiency" table. | CREATE TABLE MonthlyEnergyEfficiency (State VARCHAR(2),Month INT,EnergyEfficiencyScore FLOAT); | SELECT State, EnergyEfficiencyScore, LAG(EnergyEfficiencyScore) OVER (PARTITION BY State ORDER BY Month) AS PreviousEnergyEfficiencyScore, EnergyEfficiencyScore - LAG(EnergyEfficiencyScore) OVER (PARTITION BY State ORDER BY Month) AS Difference FROM MonthlyEnergyEfficiency; |
What is the standard deviation of the amount of Shariah-compliant financing provided to small businesses by industry in the last quarter? | CREATE TABLE shariah_financing (financing_id INT,financing_date DATE,financing_amount INT,business_size TEXT,industry TEXT); CREATE TABLE shariah_small_businesses (business_id INT,financing_id INT); | SELECT STDEV(sf.financing_amount) FROM shariah_financing sf JOIN shariah_small_businesses ssb ON sf.financing_id = ssb.financing_id WHERE sf.financing_date >= DATEADD(quarter, -1, CURRENT_DATE()) GROUP BY sf.industry; |
How many circular economy initiatives are present in the APAC region? | CREATE TABLE CircularEconomy (id INT,country VARCHAR(50),region VARCHAR(50),initiative_count INT); INSERT INTO CircularEconomy (id,country,region,initiative_count) VALUES (1,'China','APAC',12),(2,'Japan','APAC',7),(3,'India','APAC',9); | SELECT SUM(initiative_count) FROM CircularEconomy WHERE region = 'APAC'; |
What is the total capacity of energy storage facilities in the 'energy_storage' schema? | CREATE TABLE energy_storage.energy_storage_facilities (facility_id int,name varchar(50),capacity int); INSERT INTO energy_storage.energy_storage_facilities (facility_id,name,capacity) VALUES (1,'Facility M',800),(2,'Facility N',700),(3,'Facility O',900); | SELECT SUM(capacity) FROM energy_storage.energy_storage_facilities; |
Which countries have the highest and lowest average song duration in the 'Metal' genre? | CREATE TABLE songs (song_id INT,song VARCHAR(50),genre VARCHAR(10),duration FLOAT,country VARCHAR(50)); INSERT INTO songs VALUES (1,'Master Of Puppets','Metal',512.3,'USA'),(2,'Battery','Metal',456.7,'USA'),(3,'Symptom Of The Universe','Metal',400.5,'UK'); | SELECT s.country, AVG(s.duration) as avg_duration FROM songs s WHERE s.genre = 'Metal' GROUP BY s.country ORDER BY avg_duration DESC, s.country; |
Delete companies with ESG rating above 85. | CREATE TABLE companies (id INT,sector TEXT,ESG_rating FLOAT); INSERT INTO companies (id,sector,ESG_rating) VALUES (1,'technology',78.2),(2,'finance',82.5),(3,'technology',84.6); | DELETE FROM companies WHERE ESG_rating > 85; |
What was the total value of military equipment sales to India in H1 2021? | CREATE TABLE military_sales (id INT,region VARCHAR,sale_value DECIMAL,sale_date DATE); INSERT INTO military_sales (id,region,sale_value,sale_date) VALUES (1,'India',20000,'2021-02-12'); INSERT INTO military_sales (id,region,sale_value,sale_date) VALUES (2,'India',18000,'2021-04-28'); INSERT INTO military_sales (id,regi... | SELECT SUM(sale_value) FROM military_sales WHERE region = 'India' AND sale_date BETWEEN '2021-01-01' AND '2021-06-30'; |
List all the wells in the 'Permian' basin that were completed after 2018. | CREATE TABLE permian_wells (well text,completion_year integer); INSERT INTO permian_wells VALUES ('Well1',2016),('Well2',2017),('Well3',2019),('Well4',2018),('Well5',2020); | SELECT well FROM permian_wells WHERE completion_year > 2018; |
What is the total amount donated by each donor in the last quarter? | CREATE TABLE Donations (DonorID INT,DonationDate DATE,Amount DECIMAL(10,2)); | SELECT DonorID, SUM(Amount) as TotalDonated FROM Donations WHERE DonationDate >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY DonorID; |
What is the total number of schools in the state of California, grouped by school district? | CREATE TABLE schools (id INT,name TEXT,state TEXT,district TEXT,num_students INT); INSERT INTO schools (id,name,state,district,num_students) VALUES (1,'Elementary School','California','Los Angeles Unified',500),(2,'Middle School','California','Los Angeles Unified',700),(3,'High School','California','San Francisco Unifi... | SELECT district, COUNT(*) as total FROM schools WHERE state = 'California' GROUP BY district; |
What percentage of patients diagnosed with PTSD received medication? | CREATE TABLE diagnoses (patient_id INT,condition VARCHAR(20),medication BOOLEAN); INSERT INTO diagnoses (patient_id,condition,medication) VALUES (1,'PTSD',TRUE),(2,'anxiety',FALSE),(3,'PTSD',TRUE),(4,'depression',FALSE); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM diagnoses WHERE condition = 'PTSD')) AS percentage FROM diagnoses WHERE medication = TRUE AND condition = 'PTSD'; |
Show the top 2 most frequently ordered dishes in each category. | CREATE TABLE orders(order_id INT,dish VARCHAR(255),category VARCHAR(255),quantity INT); INSERT INTO orders(order_id,dish,category,quantity) VALUES (1,'Tofu Stir Fry','Starter',3),(2,'Lentil Soup','Starter',5),(3,'Chickpea Curry','Main',2),(4,'Tofu Curry','Main',4),(5,'Quinoa Salad','Side',6); | SELECT category, dish, quantity FROM (SELECT category, dish, quantity, ROW_NUMBER() OVER(PARTITION BY category ORDER BY quantity DESC) as row_num FROM orders) as ranked_orders WHERE row_num <= 2; |
Update the depth of all marine species in the 'marine_species' table that belong to the 'Actinopterygii' class to 100 meters. | CREATE TABLE marine_species (id INT,name VARCHAR(255),class VARCHAR(255),depth FLOAT); INSERT INTO marine_species (id,name,class,depth) VALUES (1,'Pacific salmon','Actinopterygii',50.0),(2,'Blue whale','Mammalia',500.0),(3,'Sea anemone','Anthozoa',0.01); | UPDATE marine_species SET depth = 100 WHERE class = 'Actinopterygii'; |
Calculate the average weight of packages shipped from China to Beijing in the last month. | CREATE TABLE shipments (id INT,source_country VARCHAR(20),destination_city VARCHAR(20),package_weight FLOAT,shipment_date DATE); INSERT INTO shipments (id,source_country,destination_city,package_weight,shipment_date) VALUES (1,'China','Beijing',25.3,'2022-06-05'),(2,'China','Beijing',27.8,'2022-06-20'); | SELECT AVG(package_weight) FROM shipments WHERE source_country = 'China' AND destination_city = 'Beijing' AND shipment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the maximum serving size for vegan drinks? | CREATE TABLE Servings (id INT,is_vegan BOOLEAN,category VARCHAR(20),serving_size INT); INSERT INTO Servings (id,is_vegan,category,serving_size) VALUES (1,true,'drink',16),(2,false,'drink',24),(3,true,'shake',20); | SELECT MAX(serving_size) FROM Servings WHERE is_vegan = true; |
What are the details of all vulnerabilities with a severity level of 'high'? | CREATE TABLE vulnerabilities (vulnerability_id INT,vulnerability_name VARCHAR(255),severity VARCHAR(255)); INSERT INTO vulnerabilities (vulnerability_id,vulnerability_name,severity) VALUES (1,'Vulnerability A','High'); INSERT INTO vulnerabilities (vulnerability_id,vulnerability_name,severity) VALUES (2,'Vulnerability B... | SELECT * FROM vulnerabilities WHERE severity = 'High'; |
What is the average monthly data usage for customers in the city of Los Angeles who have been active for more than 3 months? | CREATE TABLE customer_activity (customer_id INT,start_date DATE,end_date DATE); CREATE TABLE customers (customer_id INT,data_usage FLOAT); | SELECT AVG(data_usage) FROM customers INNER JOIN customer_activity ON customers.customer_id = customer_activity.customer_id WHERE customers.data_usage IS NOT NULL AND customer_activity.start_date <= CURDATE() - INTERVAL 3 MONTH AND (customer_activity.end_date IS NULL OR customer_activity.end_date >= CURDATE() - INTERVA... |
Find the total number of bookings for each hotel in the "Paris" city | CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(50),city VARCHAR(50)); CREATE TABLE bookings (booking_id INT,hotel_id INT,guest_name VARCHAR(50),checkin_date DATE,checkout_date DATE,price DECIMAL(10,2)); | SELECT h.hotel_id, h.hotel_name, COUNT(b.booking_id) AS booking_count FROM hotels h INNER JOIN bookings b ON h.hotel_id = b.hotel_id WHERE h.city = 'Paris' GROUP BY h.hotel_id, h.hotel_name; |
What is the total revenue generated from size-inclusive garments in the last quarter? | CREATE TABLE RevenueData (RevenueID INT,ProductID INT,Revenue FLOAT,SizeInclusive BOOLEAN); INSERT INTO RevenueData (RevenueID,ProductID,Revenue,SizeInclusive) VALUES (1,1001,500,true),(2,1002,600,false),(3,1003,400,true); | SELECT SUM(Revenue) FROM RevenueData WHERE SizeInclusive = true AND RevenueDate >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH); |
What is the total weight of ingredients sourced from the US, for each product category? | CREATE TABLE product_ingredients (ingredient_id INT,product_id INT,ingredient VARCHAR(255),source_country VARCHAR(255)); CREATE TABLE products (product_id INT,product VARCHAR(255),category VARCHAR(255)); INSERT INTO product_ingredients (ingredient_id,product_id,ingredient,source_country) VALUES (1,1,'Vitamin C','US'),(... | SELECT p.category, SUM(pi.ingredient_id) as total_us_weight FROM product_ingredients pi JOIN products p ON pi.product_id = p.product_id WHERE pi.source_country = 'US' GROUP BY p.category; |
Retrieve the number of patients by ethnicity 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'),(2,'Jane Smith',40,'Female','African American','African American'),(3,'Maria Garcia',45,'... | SELECT ethnicity, COUNT(*) as count FROM patients GROUP BY ethnicity; |
How many startups were founded in the food industry in the last 3 years? | CREATE TABLE startups(id INT,name TEXT,industry TEXT,founding_date DATE); INSERT INTO startups(id,name,industry,founding_date) VALUES (1,'FoodieStart','Food','2021-01-01'); | SELECT COUNT(*) FROM startups WHERE industry = 'Food' AND founding_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR); |
How many organizations work on AI for social good in each country? | CREATE TABLE organizations (id INT,name VARCHAR(50),country VARCHAR(50),ai_social_good BOOLEAN);INSERT INTO organizations (id,name,country,ai_social_good) VALUES (1,'AI for Earth','USA',true),(2,'AI for Accessibility','Canada',true),(3,'AI for Humanitarian Action','UK',true); | SELECT country, COUNT(*) as org_count FROM organizations WHERE ai_social_good = true GROUP BY country; |
How many traffic violations were issued in the borough of Manhattan in 2021 and what was the total fine amount? | CREATE TABLE traffic_violations (borough VARCHAR(255),year INT,violation_count INT,fine_amount FLOAT); INSERT INTO traffic_violations (borough,year,violation_count,fine_amount) VALUES ('Manhattan',2021,15000,1500000.00); | SELECT violation_count, SUM(fine_amount) AS total_fine_amount FROM traffic_violations WHERE borough = 'Manhattan' AND year = 2021; |
What is the average landfill capacity in Oceania in 2021?' | CREATE TABLE landfills (country VARCHAR(50),capacity INT,year INT); INSERT INTO landfills (country,capacity,year) VALUES ('Australia',25000,2021),('New Zealand',20000,2021); | SELECT AVG(capacity) as avg_capacity FROM landfills WHERE year = 2021 AND country IN ('Australia', 'New Zealand'); |
List all military equipment maintenance activities performed on naval vessels in the Caribbean region since 2019. | CREATE TABLE equipment_maintenance (maintenance_id INT,maintenance_date DATE,equipment_type VARCHAR(255),region VARCHAR(255)); INSERT INTO equipment_maintenance (maintenance_id,maintenance_date,equipment_type,region) VALUES (7,'2019-12-31','naval_vessel','Caribbean'),(8,'2020-04-04','tank','Europe'),(9,'2021-06-15','ai... | SELECT * FROM equipment_maintenance WHERE equipment_type = 'naval_vessel' AND region = 'Caribbean' AND maintenance_date >= '2019-01-01'; |
What is the total assets value for all clients who have invested in Tech Stocks? | CREATE TABLE ClientStockInvestments (ClientID INT,StockSymbol VARCHAR(10)); INSERT INTO ClientStockInvestments (ClientID,StockSymbol) VALUES (1,'AAPL'),(2,'GOOG'),(3,'MSFT'),(4,'TSLA'); CREATE TABLE Stocks (Symbol VARCHAR(10),AssetValue FLOAT); INSERT INTO Stocks (Symbol,AssetValue) VALUES ('AAPL',200.5),('GOOG',300.2)... | SELECT S.AssetValue FROM ClientStockInvestments CSI JOIN Stocks S ON CSI.StockSymbol = S.Symbol WHERE CSI.ClientID IN (SELECT ClientID FROM ClientTechStocks); |
What is the total cost of labor for laborers working on projects with permit numbers 'P001' and 'P002' in the 'building_permit' and 'construction_labor' tables? | CREATE TABLE building_permit (permit_id INT,permit_date DATE,project_id INT,location VARCHAR(50)); CREATE TABLE construction_labor (laborer_id INT,laborer_name VARCHAR(50),project_id INT,material VARCHAR(50),cost DECIMAL(10,2)); | SELECT SUM(cost) FROM construction_labor WHERE project_id IN (SELECT project_id FROM building_permit WHERE permit_id IN ('P001', 'P002')); |
What is the average treatment cost for patients with anxiety disorder who have not completed a treatment program? | CREATE TABLE PatientTreatmentCosts (PatientID INT,Condition VARCHAR(50),TreatmentCost DECIMAL(10,2),CompletedProgram BOOLEAN); | SELECT AVG(TreatmentCost) FROM PatientTreatmentCosts WHERE Condition = 'anxiety disorder' AND CompletedProgram = FALSE; |
What is the total area (in hectares) of all organic farms in the 'agroecology' schema? | CREATE SCHEMA if not exists agroecology; use agroecology; CREATE TABLE organic_farms (id INT,name TEXT,size_ha FLOAT,location TEXT); INSERT INTO organic_farms (id,name,size_ha,location) VALUES (1,'Farm 1',50.0,'City A'),(2,'Farm 2',75.0,'City B'); | SELECT SUM(size_ha) FROM agroecology.organic_farms; |
What is the total number of conservation efforts for marine mammals? | CREATE TABLE marine_species (id INT,species VARCHAR(50),type VARCHAR(50),population INT); INSERT INTO marine_species (id,species,type,population) VALUES (1,'Dolphin','Mammal',600000); INSERT INTO marine_species (id,species,type,population) VALUES (2,'Sea Otter','Mammal',15000); | SELECT SUM(population) FROM marine_species WHERE type = 'Mammal' AND species IN ('Dolphin', 'Sea Otter'); |
What was the total amount donated by the top 5 donors in the last quarter? | CREATE TABLE Donors (DonorID INT,Name TEXT,DonationAmount DECIMAL(10,2),DonationDate DATE); INSERT INTO Donors (DonorID,Name,DonationAmount,DonationDate) VALUES (1,'John Doe',5000.00,'2021-01-01'),(2,'Jane Smith',3500.00,'2021-02-15'),(3,'Mike Johnson',7000.00,'2021-03-30'); | SELECT SUM(DonationAmount) FROM (SELECT DonationAmount FROM Donors WHERE DonationDate >= DATEADD(quarter, -1, GETDATE()) ORDER BY DonationAmount DESC LIMIT 5) AS TopDonors |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.