instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many exhibitions have been held at 'Guggenheim Museum' since its opening?
CREATE TABLE museums (museum_id INT,name VARCHAR(50),city VARCHAR(50),opening_year INT); INSERT INTO museums (museum_id,name,city,opening_year) VALUES (1,'Guggenheim Museum','New York',1939); CREATE TABLE exhibitions (exhibition_id INT,title VARCHAR(50),year INT,museum_id INT); INSERT INTO exhibitions (exhibition_id,title,year,museum_id) VALUES (1,'First Exhibition',1940,1);
SELECT COUNT(*) FROM exhibitions e WHERE e.museum_id = (SELECT museum_id FROM museums m WHERE m.name = 'Guggenheim Museum');
What is the total amount of socially responsible loans issued to minority communities in 2021?
CREATE TABLE socially_responsible_lending (id INT PRIMARY KEY,loan_amount DECIMAL(10,2),community_type TEXT,lending_date DATE);
SELECT SUM(loan_amount) FROM socially_responsible_lending WHERE community_type IN ('Minority Community 1', 'Minority Community 2') AND lending_date BETWEEN '2021-01-01' AND '2021-12-31';
Who are the most influential artists in the 'Influential_Artists' table?
CREATE TABLE Influential_Artists (artist_id INT,artist_name VARCHAR(255),influence_score FLOAT);
SELECT artist_name FROM Influential_Artists ORDER BY influence_score DESC LIMIT 1;
What is the total revenue generated by each event type ('event_type' table) for the year 2020?
CREATE TABLE event (id INT,year INT,type_id INT,name VARCHAR(50),revenue INT);CREATE TABLE event_type (id INT,name VARCHAR(50));
SELECT et.name, SUM(e.revenue) FROM event e JOIN event_type et ON e.type_id = et.id WHERE e.year = 2020 GROUP BY et.name;
What is the average number of open data initiatives per country in the European region?
CREATE TABLE initiatives (id INT,country TEXT,region TEXT,initiative_count INT); INSERT INTO initiatives (id,country,region,initiative_count) VALUES (1,'France','European',10),(2,'Germany','European',12),(3,'Spain','European',8),(4,'United States','American',15);
SELECT AVG(initiative_count) FROM initiatives WHERE region = 'European';
Add new records to hotel_tech_adoption_table for hotels in the Americas region
CREATE TABLE hotel_tech_adoption (hotel_id INT,region VARCHAR(50),ai_integration VARCHAR(50));
INSERT INTO hotel_tech_adoption (hotel_id, region, ai_integration) VALUES (1001, 'Americas', 'Yes'), (1002, 'Americas', 'No'), (1003, 'Americas', 'Yes');
Who are the volunteers with no donation records?
CREATE TABLE Volunteers (id INT,name TEXT); CREATE TABLE VolunteerDonations (id INT,volunteer_id INT,amount FLOAT);
SELECT Volunteers.name FROM Volunteers LEFT JOIN VolunteerDonations ON Volunteers.id = VolunteerDonations.volunteer_id WHERE VolunteerDonations.id IS NULL;
List all cybersecurity incidents with their corresponding threat level in descending order by date.
CREATE TABLE CyberIncidents (IncidentID int,IncidentDate date,ThreatLevel varchar(50)); INSERT INTO CyberIncidents (IncidentID,IncidentDate,ThreatLevel) VALUES (1,'2021-08-01','High'),(2,'2021-07-01','Medium'),(3,'2021-06-01','Low');
SELECT * FROM CyberIncidents ORDER BY IncidentDate DESC, ThreatLevel DESC;
What is the total production of each crop?
CREATE TABLE crops (id INT,name VARCHAR(50),location VARCHAR(50),year INT,production INT); INSERT INTO crops (id,name,location,year,production) VALUES (1,'Corn','US',2020,5000),(2,'Wheat','US',2020,7000),(3,'Soybean','Canada',2020,3000),(4,'Barley','Canada',2020,4000),(5,'Corn','US',2019,6000),(6,'Wheat','US',2019,8000),(7,'Soybean','Canada',2019,4000),(8,'Barley','Canada',2019,5000);
SELECT name, SUM(production) as total_production FROM crops GROUP BY name;
What is the 5-year trend of sea surface temperature in the Pacific Ocean?
CREATE TABLE sea_surface_temperature (ocean VARCHAR(255),date DATE,temperature FLOAT); INSERT INTO sea_surface_temperature (ocean,date,temperature) VALUES ('Pacific','2017-01-01',26.5),('Pacific','2017-07-01',27.2),('Pacific','2018-01-01',26.8),('Pacific','2018-07-01',27.1),('Pacific','2019-01-01',26.7),('Pacific','2019-07-01',27.0),('Pacific','2020-01-01',26.6),('Pacific','2020-07-01',26.9),('Pacific','2021-01-01',26.5),('Pacific','2021-07-01',26.8);
SELECT date, temperature, ROW_NUMBER() OVER (ORDER BY date) as rn, AVG(temperature) OVER (ORDER BY date ROWS BETWEEN 4 PRECEDING AND CURRENT ROW) as moving_avg FROM sea_surface_temperature WHERE ocean = 'Pacific';
List unique safety_issues reported by country in descending order of count.
CREATE TABLE safety_issues (issue_id INTEGER,issue_description TEXT,reported_country TEXT);
SELECT reported_country, COUNT(*) as count FROM safety_issues GROUP BY reported_country ORDER BY count DESC;
What is the total production quantity (in metric tons) for rare earth elements in Africa for the year 2015?
CREATE TABLE african_production (id INT,year INT,quantity FLOAT); INSERT INTO african_production (id,year,quantity) VALUES (1,2014,4000),(2,2015,5000),(3,2016,6000);
SELECT SUM(quantity) FROM african_production WHERE year = 2015;
What is the number of pharmaceutical companies in each country of the world?
CREATE TABLE pharmaceuticals (country VARCHAR(50),num_pharmaceuticals INT); INSERT INTO pharmaceuticals (country,num_pharmaceuticals) VALUES ('USA',823),('Germany',405),('Japan',519);
SELECT country, COUNT(*) as num_pharmaceutical_companies FROM pharmaceuticals GROUP BY country;
What is the percentage of total donations made by top 10 donors?
CREATE TABLE Donor (DonorID INT,DonationAmount NUMERIC(15,2)); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE);
SELECT Percentage FROM (SELECT SUM(DonationAmount) as TotalDonations, ROW_NUMBER() OVER (ORDER BY SUM(DonationAmount) DESC) as Rank, SUM(DonationAmount)/SUM(DonationAmount) OVER () as Percentage FROM Donations INNER JOIN Donor ON Donations.DonorID = Donor.DonorID GROUP BY DonorID) WHERE Rank <= 10;
What is the mass of the smallest satellite of Jupiter?
CREATE TABLE jupiter_moons (id INT,name VARCHAR(50),mass FLOAT); INSERT INTO jupiter_moons (id,name,mass) VALUES (1,'Metis',1200); INSERT INTO jupiter_moons (id,name,mass) VALUES (2,'Adrastea',1800); INSERT INTO jupiter_moons (id,name,mass) VALUES (3,'Amalthea',7000);
SELECT MIN(mass) FROM jupiter_moons;
What is the total investment amount for each investor?
CREATE TABLE investors (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),investment_amount DECIMAL(10,2)); INSERT INTO investors (id,name,location,investment_amount) VALUES (1,'Alice','USA',5000.00),(2,'Bob','Canada',3000.00);
SELECT id, SUM(investment_amount) FROM investors GROUP BY id;
Find the average carbon sequestration value for tree species in the tree_carbon_sequestration table, grouped by tree type.
CREATE TABLE tree_carbon_sequestration (id INT,tree_type VARCHAR(255),carbon_sequestration INT);
SELECT tree_type, AVG(carbon_sequestration) FROM tree_carbon_sequestration GROUP BY tree_type;
What is the total number of military personnel, by rank, and the percentage of total personnel each rank represents, for the past year?
CREATE TABLE military_personnel(id INT,rank VARCHAR(255),status VARCHAR(255),date DATE);
SELECT rank, COUNT(*) as count, ROUND(100 * COUNT(*) / (SELECT COUNT(*) FROM military_personnel WHERE date > DATE_SUB(NOW(), INTERVAL 1 YEAR) AND status = 'active'), 2) as percent FROM military_personnel WHERE date > DATE_SUB(NOW(), INTERVAL 1 YEAR) AND status = 'active' GROUP BY rank;
What is the average energy rating for each city in the green buildings table?
CREATE TABLE green_buildings (id INT,city VARCHAR(50),country VARCHAR(50),energy_rating FLOAT); INSERT INTO green_buildings (id,city,country,energy_rating) VALUES (1,'Mumbai','India',85.0),(2,'Rio de Janeiro','Brazil',88.5),(3,'Johannesburg','South Africa',82.0);
SELECT city, AVG(energy_rating) as avg_energy_rating FROM green_buildings GROUP BY city;
What is the average billing amount for attorneys in the 'Personal Injury' practice area, partitioned by attorney's last name and ordered by the average billing amount in descending order?
CREATE TABLE Attorneys (AttorneyID INT,FirstName VARCHAR(50),LastName VARCHAR(50),PracticeArea VARCHAR(50),TotalBilling FLOAT); INSERT INTO Attorneys (AttorneyID,FirstName,LastName,PracticeArea,TotalBilling) VALUES (1,'Clara','Rivera','Personal Injury',8000.00),(2,'Jamal','Lee','Personal Injury',6000.00),(3,'Sophia','Gomez','Criminal Law',9000.00);
SELECT LastName, AVG(TotalBilling) OVER (PARTITION BY LastName) AS AvgBilling FROM Attorneys WHERE PracticeArea = 'Personal Injury' ORDER BY AvgBilling DESC;
How many exoplanets have been discovered by each space telescope?
CREATE TABLE ExoplanetDiscoveries (telescope TEXT,num_exoplanets INTEGER); INSERT INTO ExoplanetDiscoveries (telescope,num_exoplanets) VALUES ('Kepler',2300),('COROT',32),('CoRoT',31),('HATNet',90),('K2',400);
SELECT telescope, num_exoplanets FROM ExoplanetDiscoveries ORDER BY num_exoplanets DESC;
Update the safety_records table to set inspection_status as 'Passed' for vessels with vessel_id in (1, 3, 5)
CREATE TABLE safety_records (vessel_id INT,inspection_status VARCHAR(10));
UPDATE safety_records SET inspection_status = 'Passed' WHERE vessel_id IN (1, 3, 5);
What is the average budget allocated for endangered species conservation in 'Asia'?
CREATE TABLE Habitat_Preservation (PreservationID INT,Habitat VARCHAR(20),Budget DECIMAL(10,2),Species VARCHAR(20)); INSERT INTO Habitat_Preservation (PreservationID,Habitat,Budget,Species) VALUES (1,'Asia',25000.00,'Tiger'); INSERT INTO Habitat_Preservation (PreservationID,Habitat,Budget,Species) VALUES (2,'Asia',30000.00,'Panda'); INSERT INTO Habitat_Preservation (PreservationID,Habitat,Budget,Species) VALUES (3,'Africa',35000.00,'Elephant');
SELECT AVG(Budget) FROM Habitat_Preservation WHERE Habitat = 'Asia' AND Species IN (SELECT Species FROM Endangered_Species);
Determine the total workout duration for members with the 'Premium' subscription type.
CREATE TABLE Workout (MemberID INT,Duration INT,Subscription VARCHAR(50)); INSERT INTO Workout (MemberID,Duration,Subscription) VALUES (1,60,'Premium');
SELECT SUM(Duration) FROM Workout WHERE Subscription = 'Premium';
What is the average age of players in each position?
CREATE TABLE players (player_id INT,name VARCHAR(50),last_name VARCHAR(50),position VARCHAR(50),age INT); INSERT INTO players (player_id,name,last_name,position,age) VALUES (1,'John','Doe','Pitcher',30),(2,'Jane','Smith','Catcher',28);
SELECT position, AVG(age) as avg_age FROM players GROUP BY position;
What are the top 3 countries with the highest clinical trial completion rates in 2020?
CREATE TABLE clinical_trials (id INT,country VARCHAR(50),year INT,completion_rate DECIMAL(5,2)); INSERT INTO clinical_trials (id,country,year,completion_rate) VALUES (1,'USA',2020,0.85),(2,'Germany',2020,0.82),(3,'Canada',2020,0.78),(4,'USA',2020,0.90),(5,'Germany',2020,0.87),(6,'Canada',2020,0.73);
SELECT country, MAX(completion_rate) as max_completion_rate FROM clinical_trials WHERE year = 2020 GROUP BY country ORDER BY max_completion_rate DESC LIMIT 3;
What is the total waste generation in each country for the last 5 years?
CREATE TABLE waste_generation (country TEXT,year INT,waste_generation FLOAT); INSERT INTO waste_generation (country,year,waste_generation) VALUES ('Country A',2018,1200),('Country A',2019,1300),('Country A',2020,1400),('Country A',2021,1500),('Country B',2018,1500),('Country B',2019,1600),('Country B',2020,1700),('Country B',2021,1800);
SELECT country, SUM(waste_generation) FROM waste_generation WHERE year BETWEEN 2017 AND 2021 GROUP BY country;
What is the total value of investments for each investment type, excluding investments with a value less than 10000?
CREATE TABLE investments (investment_id INT,investment_type VARCHAR(20),value DECIMAL(10,2)); INSERT INTO investments (investment_id,investment_type,value) VALUES (1,'Stocks',30000.00),(2,'Bonds',20000.00),(3,'Mutual Funds',50000.00),(4,'Stocks',8000.00),(5,'Bonds',15000.00),(6,'Mutual Funds',20000.00);
SELECT investment_type, SUM(value) as total_value FROM investments WHERE value >= 10000 GROUP BY investment_type;
What is the average rating for organic skincare products by brand?
CREATE TABLE brands (brand_id INT,brand_name VARCHAR(255)); CREATE TABLE products (product_id INT,product_name VARCHAR(255),brand_id INT,rating INT); CREATE TABLE ingredients (ingredient_id INT,product_id INT,is_organic BOOLEAN);
SELECT b.brand_name, AVG(p.rating) as avg_rating FROM brands b INNER JOIN products p ON b.brand_id = p.brand_id INNER JOIN ingredients i ON p.product_id = i.product_id WHERE i.is_organic = TRUE GROUP BY b.brand_name;
Delete team 2
CREATE TABLE players (player_id INT,name VARCHAR(100),position VARCHAR(50),team_id INT); INSERT INTO players (player_id,name,position,team_id) VALUES (1,'John Doe','Forward',1),(2,'Jane Smith','Goalie',2); CREATE TABLE teams (team_id INT,name VARCHAR(100),city VARCHAR(100)); INSERT INTO teams (team_id,name,city) VALUES (1,'Boston Bruins','Boston'),(2,'New York Rangers','New York');
DELETE FROM teams WHERE team_id = 2;
Delete rows from the Local_Economic_Impact table where the Annual_Revenue is more than 10% below the average annual revenue across all rows in the table.
CREATE TABLE Local_Economic_Impact (City VARCHAR(50),Annual_Revenue INT,Job_Creation INT); INSERT INTO Local_Economic_Impact (City,Annual_Revenue,Job_Creation) VALUES ('Barcelona',28000000,65000),('Rome',25000000,70000),('Prague',12000000,30000),('Oslo',18000000,40000);
DELETE FROM Local_Economic_Impact WHERE Annual_Revenue < (SELECT AVG(Annual_Revenue) * 0.9 FROM Local_Economic_Impact);
What is the average number of likes on posts by users from the United States, having more than 500 followers, in the last month?
CREATE TABLE users (id INT,name TEXT,country TEXT,followers INT); INSERT INTO users (id,name,country,followers) VALUES (1,'Alice','USA',700),(2,'Bob','USA',600),(3,'Charlie','Canada',800); CREATE TABLE posts (id INT,user_id INT,likes INT,timestamp DATETIME); INSERT INTO posts (id,user_id,likes,timestamp) VALUES (1,1,20,'2022-01-01 12:00:00'),(2,1,30,'2022-01-05 13:00:00'),(3,2,10,'2022-01-03 11:00:00'),(4,3,40,'2022-01-04 14:00:00');
SELECT AVG(posts.likes) FROM posts JOIN users ON posts.user_id = users.id WHERE users.country = 'USA' AND users.followers > 500 AND posts.timestamp >= DATE_SUB(NOW(), INTERVAL 1 MONTH);
What is the total number of marine protected areas in the Pacific ocean that are deeper than 500 meters?
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(50),region VARCHAR(50),depth FLOAT); INSERT INTO marine_protected_areas (id,name,region,depth) VALUES (1,'MPA1','Pacific',500.0),(2,'MPA2','Pacific',700.0),(3,'MPA3','Pacific',300.0);
SELECT COUNT(*) FROM marine_protected_areas WHERE region = 'Pacific' AND depth > 500.0;
What was the total number of attendees for 'Culture Fest' who identified as 'Non-binary' or 'Prefer not to say'?
CREATE TABLE EventAttendance (event_name VARCHAR(255),attendee_age INT,attendee_gender VARCHAR(50)); INSERT INTO EventAttendance (event_name,attendee_age,attendee_gender) VALUES ('Culture Fest',30,'Male'),('Culture Fest',42,'Female'),('Culture Fest',35,'Non-binary'),('Culture Fest',50,'Prefer not to say');
SELECT COUNT(*) FROM EventAttendance WHERE event_name = 'Culture Fest' AND attendee_gender IN ('Non-binary', 'Prefer not to say');
What is the total amount donated in each country?
CREATE TABLE Donations (DonationID INT,DonorID INT,RecipientID INT,Amount DECIMAL(10,2),Country TEXT); INSERT INTO Donations (DonationID,DonorID,RecipientID,Amount,Country) VALUES (1,1,101,1000.00,'USA'),(2,1,102,2000.00,'Canada'),(3,2,101,500.00,'USA'),(4,3,103,3000.00,'Mexico');
SELECT Country, SUM(Amount) AS TotalDonated FROM Donations GROUP BY Country;
Show total salary expenses for each department in the "hr" schema
CREATE TABLE hr.employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(10,2)); INSERT INTO hr.employees (id,name,department,salary) VALUES (1,'John Doe','HR',50000.00); INSERT INTO hr.employees (id,name,department,salary) VALUES (2,'Jane Smith','IT',60000.00); INSERT INTO hr.employees (id,name,department,salary) VALUES (3,'Bob Brown','IT',65000.00); INSERT INTO hr.employees (id,name,department,salary) VALUES (4,'Alice Johnson','HR',55000.00);
SELECT department, SUM(salary) FROM hr.employees GROUP BY department;
Create a view that shows the percentage of electric vehicle sales out of total vehicle sales per year
CREATE TABLE transportation.yearly_vehicle_sales (year INT,total_vehicle_sales INT,electric_vehicle_sales INT);
CREATE VIEW transportation.yearly_electric_vehicle_sales_percentage AS SELECT year, (electric_vehicle_sales * 100.0 / total_vehicle_sales)::numeric(5,2) AS percentage FROM transportation.yearly_vehicle_sales;
What is the percentage of mobile customers who have used roaming services while in the country of Germany?
CREATE TABLE mobile_customers (customer_id INT,roaming BOOLEAN,country VARCHAR(20)); INSERT INTO mobile_customers (customer_id,roaming,country) VALUES (1,true,'Germany'),(2,false,'Germany'),(3,true,'Germany');
SELECT (COUNT(*) FILTER (WHERE roaming = true)) * 100.0 / COUNT(*) FROM mobile_customers WHERE country = 'Germany';
Find users who made more than 5 transactions in the last week?
CREATE TABLE users (user_id INT,username VARCHAR(20),region VARCHAR(20));CREATE TABLE transactions (transaction_id INT,user_id INT,amount DECIMAL(10,2),transaction_time TIMESTAMP);
SELECT user_id FROM transactions WHERE transaction_time > DATEADD(week, -1, GETDATE()) GROUP BY user_id HAVING COUNT(*) > 5;
What is the maximum mental health score for students who have not participated in open pedagogy activities?
CREATE TABLE students (student_id INT,mental_health_score INT,participated_in_open_pedagogy BOOLEAN); INSERT INTO students (student_id,mental_health_score,participated_in_open_pedagogy) VALUES (1,80,FALSE),(2,60,FALSE),(3,90,TRUE);
SELECT MAX(mental_health_score) FROM students WHERE participated_in_open_pedagogy = FALSE;
Find the vessel with the longest continuous journey
CREATE TABLE VesselPositions (vessel_id INT,timestamp TIMESTAMP,latitude DECIMAL(9,6),longitude DECIMAL(9,6));
SELECT t1.vessel_id, MAX(t2.timestamp) - MIN(t1.timestamp) AS duration FROM VesselPositions t1 JOIN VesselPositions t2 ON t1.vessel_id = t2.vessel_id AND t2.timestamp > t1.timestamp GROUP BY t1.vessel_id ORDER BY duration DESC LIMIT 1;
Show the number of unique users who have streamed songs by artists from different genres.
CREATE TABLE Users (UserID INT,UserName VARCHAR(255),Age INT); INSERT INTO Users (UserID,UserName,Age) VALUES (1,'UserA',25),(2,'UserB',35),(3,'UserC',45); CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(255),Genre VARCHAR(255)); INSERT INTO Artists (ArtistID,ArtistName,Genre) VALUES (1,'ArtistA','Pop'),(2,'ArtistB','Rock'),(3,'ArtistC','Jazz'); CREATE TABLE Streams (StreamID INT,UserID INT,ArtistID INT,StreamDate DATE); INSERT INTO Streams (StreamID,UserID,ArtistID,StreamDate) VALUES (1,1,1,'2022-01-01'),(2,2,2,'2022-01-02'),(3,3,3,'2022-01-03');
SELECT A.Genre, COUNT(DISTINCT S.UserID) as UniqueUsers FROM Artists A JOIN Streams S ON A.ArtistID = S.ArtistID GROUP BY A.Genre;
Create a table for open pedagogy data
CREATE TABLE open_pedagogy (course_id INT,open_pedagogy_score INT);
CREATE TABLE open_pedagogy (course_id INT, open_pedagogy_score INT);
What is the total amount donated in the 'Social Services' category?
CREATE TABLE Donations (DonationID INT,DonorID INT,Category TEXT,Amount DECIMAL); INSERT INTO Donations (DonationID,DonorID,Category,Amount) VALUES (1,1,'Social Services',100),(2,1,'Education',200),(3,2,'Social Services',150),(4,2,'Arts',50);
SELECT SUM(Amount) FROM Donations WHERE Category = 'Social Services';
What is the total number of articles published by 'CNN' in the politics and technology categories?
CREATE TABLE cnn (article_id INT,title TEXT,category TEXT,publisher TEXT); INSERT INTO cnn (article_id,title,category,publisher) VALUES (1,'Article 1','Technology','CNN'),(2,'Article 2','Politics','CNN'),(3,'Article 3','Business','CNN');
SELECT COUNT(*) FROM cnn WHERE category IN ('Politics', 'Technology');
What is the total amount donated by each country for a specific project in Q1 2022?
CREATE TABLE donations (donation_id INT,country VARCHAR(50),amount DECIMAL(10,2),project_id INT); INSERT INTO donations (donation_id,country,amount,project_id) VALUES (1,'USA',50.00,1),(2,'Canada',100.00,1),(3,'Mexico',200.00,1);
SELECT country, SUM(amount) AS total_donated FROM donations WHERE project_id = 1 AND QUARTER(donation_date) = 1 AND YEAR(donation_date) = 2022 GROUP BY country;
What is the wastewater treatment capacity in New York?
CREATE TABLE wastewater_treatment(state VARCHAR(20),treatment_capacity INT); INSERT INTO wastewater_treatment VALUES('New York',50000);
SELECT treatment_capacity FROM wastewater_treatment WHERE state = 'New York';
What is the number of fish caught for each species and year in the Pacific?
CREATE TABLE fish_catch_data (species VARCHAR(255),year INT,number_caught INT,region VARCHAR(255)); INSERT INTO fish_catch_data (species,year,number_caught,region) VALUES ('Salmon',2018,1000,'North Atlantic'),('Salmon',2019,1200,'North Atlantic'),('Salmon',2020,1500,'North Atlantic'),('Cod',2018,2000,'North Atlantic'),('Cod',2019,2200,'North Atlantic'),('Cod',2020,2500,'North Atlantic'),('Tuna',2018,3000,'Pacific'),('Tuna',2019,3200,'Pacific'),('Tuna',2020,3500,'Pacific');
SELECT species, year, SUM(number_caught) as total_caught FROM fish_catch_data WHERE region = 'Pacific' GROUP BY species, year ORDER BY species, year;
What is the clearance rate for crimes committed in a specific neighborhood, by type?
CREATE TABLE crimes (id INT,date DATE,neighborhood VARCHAR(50),type VARCHAR(50));CREATE TABLE arrests (id INT,crime_id INT,date DATE);
SELECT neighborhood, type, COUNT(arrests.id) / COUNT(crimes.id) as clearance_rate FROM crimes LEFT JOIN arrests ON crimes.id = arrests.crime_id WHERE neighborhood = 'Bronx' GROUP BY neighborhood, type;
Compare production figures of unconventional shale oil in the United States and Argentina.
CREATE TABLE production_figures(country VARCHAR(255),resource VARCHAR(255),year INT,production INT);INSERT INTO production_figures(country,resource,year,production) VALUES('United States','Shale Oil',2018,1000000),('United States','Shale Oil',2019,1100000),('United States','Shale Oil',2020,1200000),('Argentina','Shale Oil',2018,50000),('Argentina','Shale Oil',2019,60000),('Argentina','Shale Oil',2020,70000);
SELECT country, (production * 100 / (SELECT SUM(production) FROM production_figures WHERE country = pf.country AND resource = 'Shale Oil') ) AS production_percentage FROM production_figures pf WHERE country IN ('United States', 'Argentina') AND resource = 'Shale Oil' GROUP BY country, production;
Identify the EIA reports that have been reviewed and approved, and list the corresponding mine names and report_ids.
CREATE TABLE eia_reports (report_id INT,mine_id INT,report_status TEXT); INSERT INTO eia_reports (report_id,mine_id,report_status) VALUES (1,1,'In Progress'),(2,2,'Completed'),(3,3,'Approved'),(4,4,'Rejected'); CREATE TABLE mines (mine_id INT,mine_name TEXT); INSERT INTO mines (mine_id,mine_name) VALUES (1,'MineA'),(2,'MineB'),(3,'MineC'),(4,'MineD');
SELECT e.report_id, m.mine_name FROM eia_reports e JOIN mines m ON e.mine_id = m.mine_id WHERE e.report_status = 'Approved';
How many space missions has each country conducted, ordered by the most missions?
CREATE TABLE space_missions (id INT,mission_name VARCHAR(50),country VARCHAR(50),launch_date DATE); INSERT INTO space_missions (id,mission_name,country,launch_date) VALUES (1,'Mission 1','USA','2018-01-01'); INSERT INTO space_missions (id,mission_name,country,launch_date) VALUES (2,'Mission 2','China','2020-05-05'); INSERT INTO space_missions (id,mission_name,country,launch_date) VALUES (3,'Mission 3','USA','2021-01-01');
SELECT country, COUNT(*) as total_missions FROM space_missions GROUP BY country ORDER BY total_missions DESC;
Insert a new campaign record into the campaigns table.
CREATE TABLE campaigns (id INT PRIMARY KEY,campaign_name VARCHAR(50),start_date DATE,end_date DATE,budget DECIMAL(5,2),location VARCHAR(50));INSERT INTO campaigns (id,campaign_name,start_date,end_date,budget,location) VALUES (1,'End Stigma','2022-01-01','2022-02-28',10000.00,'New York');
INSERT INTO campaigns (id, campaign_name, start_date, end_date, budget, location) VALUES (2, 'Mental Health Awareness', '2022-03-01', '2022-03-31', 7500.00, 'Los Angeles');
Update the jersey number for athlete 'John Doe' to '12' in the 'Players' table.
CREATE TABLE Players (PlayerID INT,FirstName VARCHAR(255),LastName VARCHAR(255),JerseyNumber INT);
UPDATE Players SET JerseyNumber = 12 WHERE FirstName = 'John' AND LastName = 'Doe';
List the number of hours played by the top 10 players in 'World of Warcraft'
CREATE TABLE player_stats (player_id INT,game_id INT,hours_played INT,PRIMARY KEY (player_id,game_id)); INSERT INTO player_stats VALUES (1,1,100),(1,1,200),(2,1,300),(2,1,400),(3,1,500),(3,1,600),(4,1,700),(4,1,800),(5,1,900),(5,1,1000),(6,1,1100),(6,1,1200); CREATE TABLE game_titles (game_id INT,title VARCHAR(50),PRIMARY KEY (game_id)); INSERT INTO game_titles VALUES (1,'World of Warcraft');
SELECT player_id, SUM(hours_played) as total_hours_played FROM player_stats ps INNER JOIN game_titles gt ON ps.game_id = gt.game_id WHERE gt.title = 'World of Warcraft' GROUP BY player_id ORDER BY total_hours_played DESC LIMIT 10;
What's the total donation amount for each disaster type?
CREATE TABLE disaster_donations (disaster_type TEXT,donation_amount INTEGER); INSERT INTO disaster_donations (disaster_type,donation_amount) VALUES ('Flood',50000),('Earthquake',75000),('Fire',30000);
SELECT d.disaster_type, SUM(d.donation_amount) FROM disaster_donations d GROUP BY d.disaster_type;
How many aircraft accidents were there in Canada between 2015 and 2020?
CREATE TABLE accidents (id INT,year INT,country TEXT,incidents INT); INSERT INTO accidents (id,year,country,incidents) VALUES (1,2015,'Canada',3),(2,2016,'Canada',4),(3,2017,'Canada',5);
SELECT SUM(incidents) FROM accidents WHERE country = 'Canada' AND year BETWEEN 2015 AND 2020;
Insert a new funding record for company STU with funding amount 1000000 in the 'funding_records' table
CREATE TABLE funding_records (company_name VARCHAR(50),funding_amount INT);
INSERT INTO funding_records (company_name, funding_amount) VALUES ('STU', 1000000);
What is the percentage of circular economy initiatives in the city of Berlin, Germany?'
CREATE TABLE circular_economy_initiatives (city VARCHAR(20),initiative VARCHAR(20),is_circular BOOLEAN); INSERT INTO circular_economy_initiatives (city,initiative,is_circular) VALUES ('Berlin','Recycling program',true),('Berlin','Waste-to-energy plant',false);
SELECT ROUND(COUNT(is_circular) * 100.0 / (SELECT COUNT(*) FROM circular_economy_initiatives WHERE city = 'Berlin') , 2) as percentage_of_circular_economy_initiatives FROM circular_economy_initiatives WHERE city = 'Berlin' AND is_circular = true;
How many cases were resolved in favor of the defendant in the last quarter?
CREATE TABLE cases (case_id INT,case_status VARCHAR(10),resolved_date DATE); INSERT INTO cases (case_id,case_status,resolved_date) VALUES (1,'Defendant','2021-01-15'),(2,'Plaintiff','2021-02-20'),(3,'Defendant','2021-03-05');
SELECT COUNT(*) FROM cases WHERE case_status = 'Defendant' AND resolved_date >= '2021-01-01' AND resolved_date < '2021-04-01';
List the top 2 cities with the most autonomous buses in Asia.
CREATE TABLE asian_buses (city VARCHAR(20),num_buses INT); INSERT INTO asian_buses (city,num_buses) VALUES ('Singapore',400),('Seoul',350),('Tokyo',300),('Beijing',250),('Mumbai',200);
SELECT city, num_buses FROM (SELECT city, num_buses, ROW_NUMBER() OVER (ORDER BY num_buses DESC) rn FROM asian_buses WHERE city LIKE 'S%' OR city LIKE 'T%' OR city LIKE 'B%' OR city LIKE 'M%') tmp WHERE rn <= 2;
Create a table for employee diversity metrics and insert data on gender, race, and veteran status
CREATE TABLE diversity_metrics (id INT,employee_id INT,gender VARCHAR(50),race VARCHAR(50),veteran_status VARCHAR(50));
CREATE TABLE diversity_metrics (id INT, employee_id INT, gender VARCHAR(50), race VARCHAR(50), veteran_status VARCHAR(50)) AS SELECT * FROM (VALUES (1, 123, 'Female', 'Asian', 'No'), (2, 234, 'Male', 'Black', 'Yes'), (3, 345, 'Non-binary', 'White', 'No'), (4, 456, 'Female', 'Latinx', 'No')) AS t(id, employee_id, gender, race, veteran_status);
What is the total number of humanitarian assistance operations in Southeast Asia from 2015 to 2020?
CREATE TABLE humanitarian_assistance (operation_id INT,operation_name VARCHAR(255),region VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO humanitarian_assistance (operation_id,operation_name,region,start_date,end_date) VALUES (1,'Operation Aid','Southeast Asia','2015-01-01','2015-12-31'),(2,'Operation Hope','Southeast Asia','2016-01-01','2016-12-31'); CREATE TABLE operations (operation_id INT,operation_name VARCHAR(255));
SELECT COUNT(*) FROM humanitarian_assistance INNER JOIN operations ON humanitarian_assistance.operation_id = operations.operation_id WHERE region = 'Southeast Asia' AND YEAR(start_date) BETWEEN 2015 AND 2020;
What is the number of active validators on the Cosmos network?
CREATE TABLE cosmos_validators (validator_id INT,active BOOLEAN);
SELECT COUNT(validator_id) FROM cosmos_validators WHERE active = TRUE;
What is the transaction amount difference between the previous day and the current day for each customer?
CREATE TABLE transactions (customer_id INT,transaction_date DATE,amount DECIMAL(10,2)); INSERT INTO transactions (customer_id,transaction_date,amount) VALUES (1,'2022-01-01',100),(1,'2022-01-02',150),(2,'2022-01-01',50),(2,'2022-01-02',200);
SELECT customer_id, transaction_date, amount, LAG(amount) OVER (PARTITION BY customer_id ORDER BY transaction_date) AS previous_day_amount, amount - LAG(amount) OVER (PARTITION BY customer_id ORDER BY transaction_date) AS difference FROM transactions;
What is the total carbon sequestered by each forest type in 2020, ranked from highest to lowest?
CREATE TABLE forests (forest_id INT,forest_type VARCHAR(50),year INT,carbon_seq INT); INSERT INTO forests (forest_id,forest_type,year,carbon_seq) VALUES (1,'Tropical',2020,5000),(2,'Temperate',2020,4000),(3,'Boreal',2020,3000);
SELECT forest_type, SUM(carbon_seq) AS total_carbon_seq, RANK() OVER (ORDER BY SUM(carbon_seq) DESC) AS carbon_rank FROM forests WHERE year = 2020 GROUP BY forest_type ORDER BY carbon_rank ASC;
What are the traditional arts categories in Asia?
CREATE TABLE TraditionalArts (id INT,name VARCHAR(50),category VARCHAR(50),country VARCHAR(50)); INSERT INTO TraditionalArts (id,name,category,country) VALUES (1,'Ukiyo-e','Printmaking','Japan'); INSERT INTO TraditionalArts (id,name,category,country) VALUES (2,'Thangka','Painting','Nepal');
SELECT DISTINCT TraditionalArts.category FROM TraditionalArts WHERE TraditionalArts.country IN ('Afghanistan', 'Armenia', 'Azerbaijan', 'Bahrain', 'Bangladesh', 'Bhutan', 'Brunei', 'Cambodia', 'China', 'Cyprus', 'Georgia', 'India', 'Indonesia', 'Iran', 'Iraq', 'Israel', 'Japan', 'Jordan', 'Kazakhstan', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Lebanon', 'Malaysia', 'Maldives', 'Mongolia', 'Myanmar', 'Nepal', 'North Korea', 'Oman', 'Pakistan', 'Philippines', 'Qatar', 'Russia', 'Saudi Arabia', 'Singapore', 'South Korea', 'Sri Lanka', 'Syria', 'Tajikistan', 'Thailand', 'Turkey', 'Turkmenistan', 'United Arab Emirates', 'Uzbekistan', 'Vietnam', 'Yemen');
What are the total items in the warehouse in Australia and New Zealand combined?
CREATE TABLE Warehouse (id INT,country VARCHAR(255),items_quantity INT); INSERT INTO Warehouse (id,country,items_quantity) VALUES (1,'Australia',300),(2,'New Zealand',200),(3,'USA',400);
SELECT SUM(items_quantity) FROM Warehouse WHERE country = 'Australia' INTERSECT SELECT SUM(items_quantity) FROM Warehouse WHERE country = 'New Zealand';
What is the average response time for natural disasters in the 'Central' region?
CREATE TABLE regions (id INT,name VARCHAR(255)); CREATE TABLE natural_disasters (id INT,region_id INT,response_time INT); INSERT INTO regions (id,name) VALUES (1,'Central'); INSERT INTO natural_disasters (id,region_id,response_time) VALUES (1,1,10);
SELECT AVG(response_time) FROM natural_disasters WHERE region_id = (SELECT id FROM regions WHERE name = 'Central');
Identify the communication strategies used in climate change projects in Central America, along with the project type and the total budget.
CREATE TABLE climate_projects (project_id INT,project_type VARCHAR(50),location VARCHAR(50),budget FLOAT); CREATE TABLE communication_strategies (strategy_id INT,strategy_name VARCHAR(50),project_id INT); INSERT INTO climate_projects (project_id,project_type,location,budget) VALUES (1,'Climate Research','Central America',8000000); INSERT INTO climate_projects (project_id,project_type,location,budget) VALUES (2,'Climate Education','Central America',9000000); INSERT INTO communication_strategies (strategy_id,strategy_name,project_id) VALUES (1,'Social Media',1); INSERT INTO communication_strategies (strategy_id,strategy_name,project_id) VALUES (2,'Community Outreach',2);
SELECT cp.project_type, cs.strategy_name, SUM(cp.budget) as total_budget FROM climate_projects cp INNER JOIN communication_strategies cs ON cp.project_id = cs.project_id WHERE cp.location = 'Central America' GROUP BY cp.project_type, cs.strategy_name;
What are the top 5 countries with the longest average resolution times for security incidents in the 'global_incident_data' table?
CREATE TABLE global_incident_data (id INT,incident_category VARCHAR(50),country VARCHAR(50),resolution_time INT); INSERT INTO global_incident_data (id,incident_category,country,resolution_time) VALUES (1,'Malware','USA',480),(2,'Phishing','Canada',240),(3,'Malware','Mexico',720),(4,'Phishing','Brazil',360),(5,'DDoS','Argentina',1440),(6,'Malware','USA',360),(7,'Phishing','Canada',180),(8,'Malware','Mexico',600),(9,'Phishing','Brazil',480),(10,'DDoS','Argentina',1200);
SELECT country, AVG(resolution_time) as avg_resolution_time, COUNT(*) as count FROM global_incident_data GROUP BY country HAVING count > 4 ORDER BY avg_resolution_time DESC LIMIT 5;
What is the average food cost for gluten-free menu items in TX?
CREATE TABLE tx_menu_items (menu_item_id INT,restaurant_id INT,dish_type VARCHAR(255),food_cost DECIMAL(5,2)); INSERT INTO tx_menu_items (menu_item_id,restaurant_id,dish_type,food_cost) VALUES (1,1,'Gluten-free',3.50),(2,2,'Vegetarian',2.50),(3,3,'Gluten-free',1.50);
SELECT AVG(food_cost) FROM tx_menu_items WHERE dish_type = 'Gluten-free';
What is the total number of crimes committed in the "north" district, for the year 2020?
CREATE TABLE crimes (id INT,crime_date DATE,district VARCHAR(20),crime_count INT);
SELECT SUM(crime_count) FROM crimes WHERE district = 'north' AND EXTRACT(YEAR FROM crime_date) = 2020;
What is the total budget allocated for support programs in North America and Europe?
CREATE TABLE budget (id INT,category VARCHAR(255),region VARCHAR(255),amount INT); INSERT INTO budget (id,category,region,amount) VALUES (1,'Policy Advocacy','North America',100000),(2,'Policy Advocacy','Europe',120000),(3,'Support Programs','North America',150000),(4,'Support Programs','Europe',180000),(5,'Accommodations','Africa',110000),(6,'Accommodations','Asia',130000);
SELECT SUM(amount) as total_support_program_budget FROM budget WHERE category = 'Support Programs' AND region IN ('North America', 'Europe');
List all satellites launched by China in descending order by launch date.
CREATE TABLE satellites (id INT,country VARCHAR(255),launch_date DATE); INSERT INTO satellites (id,country,launch_date) VALUES (1,'USA','2000-01-01'),(2,'Russia','2005-01-01'),(3,'USA','2010-01-01'),(4,'Russia','2015-01-01'),(5,'China','2001-01-01'),(6,'China','2011-01-01'),(7,'China','2016-01-01');
SELECT * FROM satellites WHERE country = 'China' ORDER BY launch_date DESC;
What is the total number of users for accessibility devices in Australia and New Zealand?
CREATE TABLE assistive_tech (id INT,device VARCHAR(50),type VARCHAR(50),description TEXT,users INT,country VARCHAR(50)); INSERT INTO assistive_tech (id,device,type,description,users,country) VALUES (2,'Voice Assistant','Software','A software that provides voice assistance for disabled users.',30000,'Australia');
SELECT country, SUM(users) as total_users FROM assistive_tech WHERE country IN ('Australia', 'New Zealand') GROUP BY country;
Identify countries with less than 500 tigers
CREATE TABLE if not exists animal_population (id INT,animal VARCHAR(255),country VARCHAR(255),population INT); INSERT INTO animal_population (id,animal,country,population) VALUES (1,'Tiger','India',2500),(2,'Tiger','Bangladesh',150),(3,'Tiger','Nepal',300),(4,'Tiger','Bhutan',100);
SELECT country FROM animal_population WHERE animal = 'Tiger' GROUP BY country HAVING SUM(population) < 500;
What is the average insurance policy price for sculptures in the Tate Modern gallery?
CREATE TABLE ArtInsurance (PolicyID int,PolicyPrice int,ArtworkID int,ArtworkType varchar(50)); INSERT INTO ArtInsurance (PolicyID,PolicyPrice,ArtworkID,ArtworkType) VALUES (1,2500000,1,'Sculpture'); CREATE TABLE Artworks (ArtworkID int,ArtworkName varchar(100),ArtistID int,GalleryID int); INSERT INTO Artworks (ArtworkID,ArtworkName,ArtistID,GalleryID) VALUES (1,'The Thinker',2,2); CREATE TABLE Galleries (GalleryID int,GalleryName varchar(100),City varchar(100)); INSERT INTO Galleries (GalleryID,GalleryName,City) VALUES (2,'Tate Modern','London');
SELECT AVG(ArtInsurance.PolicyPrice) AS AveragePolicyPrice FROM ArtInsurance INNER JOIN Artworks ON ArtInsurance.ArtworkID = Artworks.ArtworkID INNER JOIN Galleries ON Artworks.GalleryID = Galleries.GalleryID WHERE Artworks.ArtworkType = 'Sculpture' AND Galleries.GalleryName = 'Tate Modern';
Get the number of articles published in the first quarter of each year by 'The New York Times'.
CREATE TABLE articles (id INT,title TEXT,publication_date DATE,publisher TEXT);
SELECT YEAR(publication_date) AS year, COUNT(*) AS count FROM articles WHERE publisher = 'The New York Times' AND MONTH(publication_date) <= 3 GROUP BY year;
Increase the speed of the vessel 'VesselI' by 2.5.
CREATE TABLE vessels (id INT,name TEXT,speed FLOAT,departed_port TEXT,departed_date DATE); INSERT INTO vessels (id,name,speed,departed_port,departed_date) VALUES (1,'VesselA',15.2,'Oakland','2020-01-01'); INSERT INTO vessels (id,name,speed,departed_port,departed_date) VALUES (2,'VesselB',17.8,'Oakland','2020-01-15'); INSERT INTO vessels (id,name,speed,departed_port,departed_date) VALUES (3,'VesselI',20.0,'Tokyo','2021-08-12');
UPDATE vessels SET speed = speed + 2.5 WHERE name = 'VesselI';
What is the average transaction value for accounts in the 'Standard' category?
CREATE TABLE transactions (transaction_id INT,account_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,account_id,amount) VALUES (1,1,1000.00); INSERT INTO transactions (transaction_id,account_id,amount) VALUES (2,2,500.00); INSERT INTO transactions (transaction_id,account_id,amount) VALUES (3,3,250.00);
SELECT AVG(amount) FROM transactions JOIN customer_accounts ON transactions.account_id = customer_accounts.account_id WHERE customer_accounts.account_type = 'Standard';
get the total quantity of sustainable fabrics used
CREATE TABLE fabric_usage (id INT,supplier VARCHAR(50),fabric_type VARCHAR(50),quantity INT,sustainability_rating INT); INSERT INTO fabric_usage (id,supplier,fabric_type,quantity,sustainability_rating) VALUES (1,'Supplier1','Cotton',500,80); INSERT INTO fabric_usage (id,supplier,fabric_type,quantity,sustainability_rating) VALUES (2,'Supplier2','Polyester',300,50); INSERT INTO fabric_usage (id,supplier,fabric_type,quantity,sustainability_rating) VALUES (3,'Supplier1','Hemp',700,90);
SELECT SUM(quantity) FROM fabric_usage WHERE sustainability_rating >= 80;
Compare the average water usage by industrial sectors in New York and Ontario in 2021.
CREATE TABLE industrial_water_usage_ny (state VARCHAR(20),year INT,sector VARCHAR(30),usage FLOAT); INSERT INTO industrial_water_usage_ny (state,year,sector,usage) VALUES ('New York',2021,'Agriculture',12345.6),('New York',2021,'Manufacturing',23456.7),('New York',2021,'Mining',34567.8); CREATE TABLE industrial_water_usage_ont (state VARCHAR(20),year INT,sector VARCHAR(30),usage FLOAT); INSERT INTO industrial_water_usage_ont (state,year,sector,usage) VALUES ('Ontario',2021,'Agriculture',23456.7),('Ontario',2021,'Manufacturing',34567.8),('Ontario',2021,'Oil and Gas',45678.9);
SELECT AVG(industrial_water_usage_ny.usage) FROM industrial_water_usage_ny WHERE state = 'New York' AND year = 2021; SELECT AVG(industrial_water_usage_ont.usage) FROM industrial_water_usage_ont WHERE state = 'Ontario' AND year = 2021;
What is the average number of likes on posts containing the hashtag "#sustainability" in the past month?
CREATE TABLE posts (id INT,user VARCHAR(50),content TEXT,likes INT,timestamp DATETIME);
SELECT AVG(likes) FROM posts WHERE content LIKE '%#sustainability%' AND timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW();
What is the percentage change in attendance for dance programs between Q1 and Q2 2022?
CREATE TABLE Events (EventID INT,EventDate DATE,TotalAttendees INT,Program VARCHAR(255)); INSERT INTO Events (EventID,EventDate,TotalAttendees,Program) VALUES (1,'2022-01-01',50,'Dance'),(2,'2022-04-01',75,'Dance');
SELECT ((Q2Attendance - Q1Attendance) * 100.0 / Q1Attendance) AS PercentageChange FROM (SELECT SUM(CASE WHEN QUARTER(EventDate) = 1 AND YEAR(EventDate) = 2022 THEN TotalAttendees ELSE 0 END) AS Q1Attendance, SUM(CASE WHEN QUARTER(EventDate) = 2 AND YEAR(EventDate) = 2022 THEN TotalAttendees ELSE 0 END) AS Q2Attendance FROM Events WHERE Program = 'Dance') AS EventTotals;
What is the average rating of eco-friendly hotels in Germany and Austria?
CREATE TABLE eco_hotels (hotel_id INT,name TEXT,rating FLOAT,country TEXT); INSERT INTO eco_hotels (hotel_id,name,rating,country) VALUES (1,'Eco Lodge',4.5,'Germany'),(2,'Green Hotel',4.2,'Germany'),(3,'Nachhaltiges Hotel',4.7,'Austria');
SELECT AVG(rating) FROM eco_hotels WHERE country IN ('Germany', 'Austria');
What is the average total value locked in smart contracts for each blockchain platform, for the last month?
CREATE TABLE SmartContract (ContractID INT,ContractValue FLOAT,ContractPlatform VARCHAR(50),ContractDate DATE); INSERT INTO SmartContract (ContractID,ContractValue,ContractPlatform,ContractDate) VALUES (1,5000,'Ethereum','2022-01-01'),(2,3000,'Solana','2022-01-02'),(3,7000,'Tezos','2022-01-03'); ALTER TABLE SmartContract ADD COLUMN ContractDate DATE;
SELECT ContractPlatform, AVG(ContractValue) as AverageValue FROM SmartContract WHERE ContractDate >= DATEADD(month, -1, GETDATE()) GROUP BY ContractPlatform;
What is the total billing amount for cases handled by attorneys who joined the firm in 2010?
CREATE TABLE attorneys (attorney_id INT,join_year INT); CREATE TABLE cases (case_id INT,attorney_id INT,billing_amount INT);
SELECT SUM(cases.billing_amount) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.join_year = 2010;
List the mental health parity status for each region, in alphabetical order.
CREATE TABLE Region (Region TEXT,ParityStatus TEXT); INSERT INTO Region (Region,ParityStatus) VALUES ('Northeast','Parity'); INSERT INTO Region (Region,ParityStatus) VALUES ('Midwest','Non-Parity'); INSERT INTO Region (Region,ParityStatus) VALUES ('South','Parity');
SELECT Region, ParityStatus FROM Region ORDER BY Region;
How many construction labor hours were spent on projects in Texas in the year 2020?
CREATE TABLE labor_hours (labor_hour_id INT,project_id INT,city VARCHAR(20),hours INT,year INT); INSERT INTO labor_hours (labor_hour_id,project_id,city,hours,year) VALUES (1,201,'Dallas',100,2020),(2,201,'Dallas',200,2019),(3,202,'Houston',150,2020);
SELECT SUM(hours) FROM labor_hours WHERE city IN ('Dallas', 'Houston') AND year = 2020;
Count of patients who received teletherapy in each country?
CREATE TABLE patients (id INT,country VARCHAR(255)); INSERT INTO patients (id,country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'); CREATE TABLE therapy (patient_id INT,therapy_type VARCHAR(255)); INSERT INTO therapy (patient_id,therapy_type) VALUES (1,'Teletherapy'),(2,'In-person'),(3,'Teletherapy');
SELECT country, COUNT(*) as teletherapy_count FROM patients JOIN therapy ON patients.id = therapy.patient_id WHERE therapy.therapy_type = 'Teletherapy' GROUP BY country;
Which model has the highest fairness score in the 'algorithmic_fairness' table?
CREATE TABLE algorithmic_fairness (model_name TEXT,fairness_score INTEGER); INSERT INTO algorithmic_fairness (model_name,fairness_score) VALUES ('modelX',87),('modelY',84),('modelZ',89);
SELECT model_name, fairness_score FROM algorithmic_fairness WHERE fairness_score = (SELECT MAX(fairness_score) FROM algorithmic_fairness);
What is the total construction revenue for each sector in the Southern region?
CREATE TABLE revenue (revenue_id INT,region VARCHAR(50),sector VARCHAR(50),revenue FLOAT); INSERT INTO revenue (revenue_id,region,sector,revenue) VALUES (1,'Southern','Residential',3000000);
SELECT sector, SUM(revenue) AS total_revenue FROM revenue WHERE region = 'Southern' GROUP BY sector;
Display the language preservation programs that have been active for more than 15 years, along with the year they were established.
CREATE TABLE Language_Preservation_Programs (id INT,program VARCHAR(100),establishment_year INT); INSERT INTO Language_Preservation_Programs (id,program,establishment_year) VALUES (1,'Breath of Life',1992),(2,'Rising Voices',2007),(3,'Living Tongues Institute',2006),(4,'Endangered Languages Project',2011);
SELECT program, establishment_year FROM Language_Preservation_Programs WHERE establishment_year <= YEAR(CURRENT_DATE) - 15;
What is the average salary of employees working in renewable energy companies?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,type TEXT,employees_count INT,avg_salary FLOAT); INSERT INTO companies (id,name,industry,type,employees_count,avg_salary) VALUES (1,'ABC Corp','Technology','Public',500,80000.00),(2,'XYZ Inc','Renewable Energy','Public',300,70000.00);
SELECT AVG(avg_salary) FROM companies WHERE industry = 'Renewable Energy';
What is the total number of customers who have purchased a specific product category in Michigan, grouped by product category and customer?
CREATE TABLE customers (customer_id INT,name TEXT,state TEXT); INSERT INTO customers (customer_id,name,state) VALUES (1,'Customer A','Michigan'),(2,'Customer B','Michigan'),(3,'Customer C','Michigan'); CREATE TABLE purchases (purchase_id INT,customer_id INT,product_category_id INT); INSERT INTO purchases (purchase_id,customer_id,product_category_id) VALUES (1,1,1),(2,1,2),(3,2,1);
SELECT p.product_category_id, c.name, COUNT(*) AS purchase_count FROM customers c JOIN purchases p ON c.customer_id = p.customer_id WHERE c.state = 'Michigan' GROUP BY p.product_category_id, c.name;
List all unique investment strategies in the 'Healthcare' sector with an ESG score above 85.
CREATE TABLE investment_strategies (investment_id INT,sector VARCHAR(20),strategy VARCHAR(50),esg_score FLOAT); INSERT INTO investment_strategies (investment_id,sector,strategy,esg_score) VALUES (1,'Healthcare','Microfinance',86.2),(2,'Finance','Sustainable Agriculture',72.3),(3,'Healthcare','Green Energy',89.5),(4,'Education','Affordable Housing',80.5);
SELECT DISTINCT strategy FROM investment_strategies WHERE sector = 'Healthcare' AND esg_score > 85;
What are the names of financial institutions that offer socially responsible loans in Indonesia?
CREATE TABLE financial_institutions (id INT,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255)); INSERT INTO financial_institutions (id,name,type,country) VALUES (1,'Bank Rakyat Indonesia','Shariah-compliant Bank','Indonesia'); CREATE TABLE loans (id INT,financial_institution_id INT,loan_type VARCHAR(255),is_socially_responsible BOOLEAN); INSERT INTO loans (id,financial_institution_id,loan_type,is_socially_responsible) VALUES (1,1,'Home Mortgage',true);
SELECT financial_institutions.name FROM financial_institutions INNER JOIN loans ON financial_institutions.id = loans.financial_institution_id WHERE loans.is_socially_responsible = true AND financial_institutions.country = 'Indonesia';
What is the average effective date of mental health parity regulations?
CREATE TABLE mental_health_parity (id INT,regulation VARCHAR(100),effective_date DATE); INSERT INTO mental_health_parity (id,regulation,effective_date) VALUES (1,'Regulation 1','2010-01-01'),(2,'Regulation 2','2015-01-01'),(3,'Regulation 3','2018-01-01');
SELECT AVG(effective_date) FROM mental_health_parity;
What is the average rating for each menu category?
CREATE TABLE ratings (item_name VARCHAR(50),category VARCHAR(50),rating NUMERIC(3,2)); INSERT INTO ratings (item_name,category,rating) VALUES ('Bruschetta','Appetizers',4.5),('Chicken Caesar Salad','Salads',3.5),('Veggie Burger','Entrees',4.0);
SELECT category, AVG(rating) AS avg_rating FROM ratings GROUP BY category;