instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
How many TV shows are there for each genre?
|
CREATE TABLE tv_show (tv_show_id INT,title VARCHAR(50),genre VARCHAR(50)); INSERT INTO tv_show (tv_show_id,title,genre) VALUES (1,'Show 1','Comedy'),(2,'Show 2','Drama'),(3,'Show 3','Comedy');
|
SELECT genre, COUNT(title) FROM tv_show GROUP BY genre;
|
What is the maximum inference time for models that use explainable AI techniques?
|
CREATE TABLE ai_models (id INT,name VARCHAR(50),explainability_technique VARCHAR(50),inference_time FLOAT); INSERT INTO ai_models (id,name,explainability_technique,inference_time) VALUES (1,'ModelA','SHAP',0.7),(2,'ModelB','LIME',0.6),(3,'ModelC','TreeExplainer',0.9);
|
SELECT MAX(inference_time) FROM ai_models WHERE explainability_technique IS NOT NULL;
|
What is the total CO2 emissions reduction (in metric tons) from green building projects, grouped by city and building type, where the reduction is greater than 5000 metric tons?
|
CREATE TABLE green_buildings (building_id INT,city VARCHAR(50),building_type VARCHAR(50),co2_reduction_tons INT);
|
SELECT city, building_type, SUM(co2_reduction_tons) FROM green_buildings GROUP BY city, building_type HAVING SUM(co2_reduction_tons) > 5000;
|
List all marine research studies in the Pacific region.
|
CREATE TABLE marine_research (id INT,study_name VARCHAR(255),region VARCHAR(255));
|
SELECT study_name FROM marine_research WHERE region = 'Pacific';
|
What is the name of the country with the most eco-friendly accommodations?
|
CREATE TABLE accommodations (id INT,name TEXT,country TEXT,rating FLOAT,is_eco_friendly BOOLEAN); INSERT INTO accommodations (id,name,country,rating,is_eco_friendly) VALUES (1,'Hotel Laguna','Costa Rica',4.5,true),(2,'Hotel Tropical','Mexico',4.2,false);
|
SELECT country FROM accommodations WHERE is_eco_friendly = true GROUP BY country ORDER BY COUNT(*) DESC LIMIT 1;
|
What is the waste generation trend in the city of Sydney between 2015 and 2020?
|
CREATE TABLE waste_trends (city varchar(255),year int,generation int); INSERT INTO waste_trends (city,year,generation) VALUES ('Sydney',2015,120000),('Sydney',2016,125000),('Sydney',2017,130000),('Sydney',2018,135000),('Sydney',2019,140000),('Sydney',2020,145000);
|
SELECT year, generation FROM waste_trends WHERE city = 'Sydney' AND year BETWEEN 2015 AND 2020;
|
Update the 'vehicle_make' column for the 'id' 10 in the 'vehicle_sales' table to 'Nissan'
|
CREATE TABLE vehicle_sales (id INT PRIMARY KEY,vehicle_make VARCHAR(255),sales_count INT);
|
UPDATE vehicle_sales SET vehicle_make = 'Nissan' WHERE id = 10;
|
What are the names and dates of birth of policyholders who have both a home and auto insurance policy with us?
|
CREATE TABLE HomeInsurance (PolicyholderName VARCHAR(50),DOB DATE); INSERT INTO HomeInsurance VALUES ('John Doe','1980-05-05'); INSERT INTO HomeInsurance VALUES ('Jane Smith','1990-12-31'); CREATE TABLE AutoInsurance (PolicyholderName VARCHAR(50),DOB DATE); INSERT INTO AutoInsurance VALUES ('John Doe','1980-05-05'); INSERT INTO AutoInsurance VALUES ('Jim Brown','1975-08-11');
|
SELECT HomeInsurance.PolicyholderName, HomeInsurance.DOB FROM HomeInsurance INNER JOIN AutoInsurance ON HomeInsurance.PolicyholderName = AutoInsurance.PolicyholderName;
|
What is the total duration of 'strength' workouts for each member in January 2022?
|
CREATE TABLE workouts (id INT,workout_date DATE,activity_type VARCHAR(50),duration INT); INSERT INTO workouts (id,workout_date,activity_type,duration) VALUES (1,'2022-01-01','strength',60),(2,'2022-01-02','cardio',45),(3,'2022-01-03','strength',75),(4,'2022-02-04','yoga',60),(5,'2022-01-05','strength',90),(6,'2022-03-06','cardio',45);
|
SELECT DATE_FORMAT(workout_date, '%Y-%m') AS month, members.member_name, SUM(duration) AS total_duration FROM workouts JOIN members ON workouts.id = members.member_id WHERE activity_type = 'strength' AND month = '2022-01' GROUP BY month, members.member_name;
|
What is the average volume of warehouses in Canada?
|
CREATE TABLE canada_warehouses (id INT,volume FLOAT); INSERT INTO canada_warehouses (id,volume) VALUES (1,1600),(2,1900);
|
SELECT AVG(volume) FROM canada_warehouses;
|
Determine the number of distinct stock symbols invested by customer with ID 2
|
CREATE TABLE customers (customer_id INT,total_assets DECIMAL(10,2)); INSERT INTO customers (customer_id,total_assets) VALUES (1,50000),(2,75000),(3,30000),(4,60000),(5,80000); CREATE TABLE investments (customer_id INT,stock_symbol VARCHAR(5),investment_amount DECIMAL(10,2)); INSERT INTO investments (customer_id,stock_symbol,investment_amount) VALUES (1,'AAPL',25000),(2,'GOOG',50000),(2,'MSFT',10000),(3,'MSFT',15000),(4,'GOOG',10000),(4,'AMZN',40000),(5,'AMZN',50000),(5,'TSLA',60000);
|
SELECT COUNT(DISTINCT investments.stock_symbol) FROM investments WHERE investments.customer_id = 2;
|
What is the total mass of space debris in orbit around the Earth?
|
CREATE TABLE space_debris (id INT,debris_name VARCHAR(50),mass FLOAT,orbit VARCHAR(50)); INSERT INTO space_debris (id,debris_name,mass,orbit) VALUES (1,'ENVISAT',8212,'LEO'); INSERT INTO space_debris (id,debris_name,mass,orbit) VALUES (2,'FENYERS 3/4',1520,'LEO');
|
SELECT SUM(mass) FROM space_debris WHERE orbit = 'LEO';
|
Show unique genres for players who have played more than 700 games
|
CREATE TABLE player_games (player_id INT,genre VARCHAR(10),game VARCHAR(20)); INSERT INTO player_games (player_id,genre,game) VALUES (1,'RPG','Game1'); INSERT INTO player_games (player_id,genre,game) VALUES (1,'RPG','Game2'); INSERT INTO player_games (player_id,genre,game) VALUES (2,'Strategy','Game3'); INSERT INTO player_games (player_id,genre,game) VALUES (3,'Action','Game4');
|
SELECT DISTINCT genre FROM player_games WHERE player_id IN (SELECT player_id FROM player_games GROUP BY player_id HAVING COUNT(*) > 700);
|
How many mobile subscribers have exceeded their data limit in Canada?
|
CREATE TABLE mobile_subscriber_limits (subscriber_id INT,data_limit FLOAT,data_usage FLOAT,country VARCHAR(20)); INSERT INTO mobile_subscriber_limits (subscriber_id,data_limit,data_usage,country) VALUES (1,50,60,'Canada'); INSERT INTO mobile_subscriber_limits (subscriber_id,data_limit,data_usage,country) VALUES (2,75,68,'Canada');
|
SELECT COUNT(*) FROM mobile_subscriber_limits WHERE data_usage > data_limit AND country = 'Canada';
|
Find the average age of members who have done a 'Yoga' workout.
|
CREATE TABLE Members (MemberID INT,Name VARCHAR(50),Age INT); INSERT INTO Members (MemberID,Name,Age) VALUES (1,'John Doe',30); INSERT INTO Members (MemberID,Name,Age) VALUES (2,'Jane Smith',45); INSERT INTO Members (MemberID,Name,Age) VALUES (3,'Alice Johnson',28); CREATE TABLE Workout (WorkoutID INT,MemberID INT,WorkoutType VARCHAR(30)); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType) VALUES (1,1,'Running'); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType) VALUES (2,1,'Cycling'); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType) VALUES (3,2,'Yoga'); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType) VALUES (4,2,'Cycling'); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType) VALUES (5,3,'Running');
|
SELECT AVG(Age) FROM Members m INNER JOIN Workout w ON m.MemberID = w.MemberID WHERE w.WorkoutType = 'Yoga';
|
What is the earliest donation date for each cause_category in the 'philanthropy.causes' table?
|
CREATE TABLE philanthropy.donation_frequency (donation_id INT,donor_id INT,cause_id INT,donation_date DATE,donation_frequency INT);
|
SELECT c.cause_category, MIN(df.donation_date) FROM philanthropy.causes c JOIN philanthropy.donation_frequency df ON c.cause_id = df.cause_id GROUP BY c.cause_category;
|
What is the total number of accommodations provided to students who have completed a support program?
|
CREATE TABLE accommodation_requests (student_id INT,accommodation_type VARCHAR(50),completed_support_program BOOLEAN); INSERT INTO accommodation_requests (student_id,accommodation_type,completed_support_program) VALUES (1,'Note Taker',TRUE),(2,'Wheelchair Access',FALSE);
|
SELECT COUNT(*) FROM accommodation_requests WHERE completed_support_program = TRUE;
|
List all members who joined the 'labor_rights' union in 2020.
|
CREATE TABLE labor_rights (member_id INT,name VARCHAR(50),union_joined_date DATE); INSERT INTO labor_rights (member_id,name,union_joined_date) VALUES (9,'Gabriel White','2020-04-02'),(10,'Heidi Lewis','2020-12-30'),(11,'Ivan Thompson','2019-08-08'),(12,'Jasmine Nguyen','2018-01-23');
|
SELECT * FROM labor_rights WHERE YEAR(union_joined_date) = 2020;
|
What is the average game rating for 'Virtual Reality' games in the 'game_reviews' table?
|
CREATE TABLE games (game_id INT,game_name VARCHAR(50)); INSERT INTO games VALUES (1,'GameA'); INSERT INTO games VALUES (2,'GameB'); INSERT INTO games VALUES (3,'Virtual Reality Game'); CREATE TABLE game_reviews (review_id INT,game_id INT,rating INT); INSERT INTO game_reviews VALUES (1,1,8); INSERT INTO game_reviews VALUES (2,1,9); INSERT INTO game_reviews VALUES (3,2,7); INSERT INTO game_reviews VALUES (4,2,6); INSERT INTO game_reviews VALUES (5,3,10); INSERT INTO game_reviews VALUES (6,3,9);
|
SELECT AVG(gr.rating) FROM game_reviews gr JOIN games g ON gr.game_id = g.game_id WHERE g.game_name = 'Virtual Reality Game';
|
Find the policy type with the highest claim amount.
|
CREATE TABLE HighestClaim (PolicyID INT,PolicyType VARCHAR(20),ClaimAmount DECIMAL(10,2)); INSERT INTO HighestClaim (PolicyID,PolicyType,ClaimAmount) VALUES (1,'Auto',500.00),(2,'Home',1000.00),(3,'Auto',750.00);
|
SELECT PolicyType, MAX(ClaimAmount) FROM HighestClaim GROUP BY PolicyType;
|
What is the total number of exhibitions in each city?
|
CREATE TABLE Exhibitions (id INT,city VARCHAR(20),visitors INT); INSERT INTO Exhibitions (id,city,visitors) VALUES (1,'Paris',3000),(2,'London',4000),(3,'New York',5000),(4,'Paris',2000),(5,'London',1000),(6,'New York',3000),(7,'Tokyo',4000),(8,'Berlin',5000),(9,'Rome',2000),(10,'Tokyo',3000);
|
SELECT city, COUNT(id) FROM Exhibitions GROUP BY city;
|
What is the total amount donated by organizations based in South America?
|
CREATE TABLE organizations (id INT,name TEXT,region TEXT,donation_amount DECIMAL); INSERT INTO organizations (id,name,region,donation_amount) VALUES (1,'ABC Corp','South America',300.00);
|
SELECT SUM(donation_amount) FROM organizations WHERE region = 'South America';
|
How many policy advocacy initiatives were implemented in the North American region in 2019?
|
CREATE TABLE policy_advocacy_2 (id INT,initiative TEXT,region TEXT,year INT); INSERT INTO policy_advocacy_2 (id,initiative,region,year) VALUES (1,'Inclusion Program','North America',2019),(2,'Accessible Education','North America',2020);
|
SELECT COUNT(*) FROM policy_advocacy_2 WHERE region = 'North America' AND year = 2019;
|
List the top 3 countries with the most excavation sites in the last decade, by total count.
|
CREATE TABLE excavation_sites (site_name TEXT,location TEXT,start_date DATE,end_date DATE); INSERT INTO excavation_sites (site_name,location,start_date,end_date) VALUES ('Site C','Mexico','2010-01-01','2012-12-31'); INSERT INTO excavation_sites (site_name,location,start_date,end_date) VALUES ('Site D','Peru','2011-01-01','2013-12-31'); INSERT INTO excavation_sites (site_name,location,start_date,end_date) VALUES ('Site E','Brazil','2012-01-01','2014-12-31'); INSERT INTO excavation_sites (site_name,location,start_date,end_date) VALUES ('Site F','Colombia','2013-01-01','2015-12-31'); INSERT INTO excavation_sites (site_name,location,start_date,end_date) VALUES ('Site G','Argentina','2014-01-01','2016-12-31'); INSERT INTO excavation_sites (site_name,location,start_date,end_date) VALUES ('Site H','Chile','2015-01-01','2017-12-31');
|
SELECT location, COUNT(location) AS site_count FROM excavation_sites WHERE start_date >= '2010-01-01' GROUP BY location ORDER BY site_count DESC LIMIT 3;
|
Identify if there's a bias in the AI fairness dataset
|
CREATE TABLE ai_fairness_dataset (algorithm VARCHAR(255),gender VARCHAR(10),passed_test BOOLEAN);
|
SELECT algorithm, AVG(passed_test) AS pass_rate FROM ai_fairness_dataset GROUP BY algorithm HAVING pass_rate < 0.5 OR pass_rate > 0.8;
|
Identify the number of unique visitors and their respective continents who have engaged with museum digital content, ranked in descending order.
|
CREATE TABLE Continent (Id INT,Continent VARCHAR(50)); CREATE TABLE Visitor (Id INT,Age INT,ContinentId INT,DigitalContent INT);
|
SELECT ContinentId, Continent, COUNT(DISTINCT VisitorId) as UniqueVisitors, RANK() OVER (ORDER BY COUNT(DISTINCT VisitorId) DESC) as Ranking FROM Continent c JOIN Visitor v ON c.Id = v.ContinentId WHERE DigitalContent = 1 GROUP BY ContinentId, Continent ORDER BY Ranking;
|
What is the average number of shares for articles published in each category, in the last year?
|
CREATE TABLE ArticleShares (ShareID INT,ArticleID INT,Shares INT); CREATE TABLE Articles (ArticleID INT,Title VARCHAR(100),AuthorID INT,Category VARCHAR(50),WordCount INT,PublishedDate DATE);
|
SELECT AVG(Shares) FROM ArticleShares INNER JOIN Articles ON ArticleShares.ArticleID = Articles.ArticleID WHERE PublishedDate >= DATEADD(year, -1, GETDATE()) GROUP BY Articles.Category;
|
What is the total number of visitors by month for each continent?
|
CREATE TABLE if not exists visitor_stats (visitor_id INT,arrival_date DATE); INSERT INTO visitor_stats (visitor_id,arrival_date) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2022-03-01'),(4,'2022-04-01'),(5,'2022-05-01');
|
SELECT EXTRACT(MONTH FROM arrival_date) as month, continent, COUNT(*) as num_visitors FROM visitor_stats CROSS JOIN (VALUES ('Europe'), ('Asia'), ('Americas'), ('Africa'), ('Australia')) AS regions(continent) GROUP BY month, continent;
|
What is the transaction volume for each digital asset in the 'emerging_markets' schema?
|
CREATE SCHEMA emerging_markets; CREATE TABLE emerging_markets.digital_assets (asset_name VARCHAR(10),daily_transaction_volume BIGINT); INSERT INTO emerging_markets.digital_assets (asset_name,daily_transaction_volume) VALUES ('AssetX',8000000),('AssetY',7000000),('AssetZ',6000000),('AssetW',5000000),('AssetV',4000000);
|
SELECT asset_name, SUM(daily_transaction_volume) FROM emerging_markets.digital_assets GROUP BY asset_name;
|
Which climate communication campaigns have been implemented in the Asia-Pacific region?
|
CREATE TABLE climate_communication(campaign_id INT,campaign_name TEXT,location TEXT);
|
SELECT campaign_name FROM climate_communication WHERE location LIKE '%Asia-Pacific%';
|
Identify the hotel_id and hotel_name with the highest unique visitors to virtual tours in June, 2021?
|
CREATE TABLE virtual_tours (hotel_id INT,tour_date DATE,unique_visitors INT); INSERT INTO virtual_tours (hotel_id,tour_date,unique_visitors) VALUES (1,'2021-06-01',100),(2,'2021-06-01',150),(1,'2021-06-02',120),(4,'2021-06-03',200),(5,'2021-06-03',250); CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(50)); INSERT INTO hotels (hotel_id,hotel_name) VALUES (1,'Hotel A'),(2,'Hotel B'),(3,'Hotel C'),(4,'Hotel D'),(5,'Hotel E');
|
SELECT h.hotel_id, h.hotel_name, SUM(vt.unique_visitors) as total_visitors FROM virtual_tours vt JOIN hotels h ON vt.hotel_id = h.hotel_id WHERE vt.tour_date BETWEEN '2021-06-01' AND '2021-06-30' GROUP BY h.hotel_id, h.hotel_name ORDER BY total_visitors DESC LIMIT 1;
|
What is the most popular makeup product category among Gen Z consumers?
|
CREATE TABLE ConsumerPreferences (customer_id INT,age INT,favorite_category VARCHAR(20)); INSERT INTO ConsumerPreferences (customer_id,age,favorite_category) VALUES (1,23,'lipstick'),(2,25,'eyeshadow'),(3,19,'lipstick'),(4,21,'mascara');
|
SELECT favorite_category, COUNT(*) as preference_count FROM ConsumerPreferences WHERE age BETWEEN 18 AND 24 GROUP BY favorite_category ORDER BY preference_count DESC LIMIT 1;
|
What organizations are focused on climate finance in Spain?
|
CREATE TABLE organizations (id INT PRIMARY KEY,name VARCHAR(50),country VARCHAR(50),focus VARCHAR(20)); INSERT INTO organizations (id,name,country,focus) VALUES (1,'Green Bank','Spain','Finance'); INSERT INTO organizations (id,name,country,focus) VALUES (2,'Climate Action Fund','UK','Adaptation');
|
SELECT name FROM organizations WHERE focus = 'Finance' AND country = 'Spain';
|
Identify the types of crops grown in urban areas, along with their respective planting dates, from the 'urban_agriculture' schema?
|
CREATE SCHEMA urban_agriculture;CREATE TABLE urban_crops (id INT,type VARCHAR(50),planting_date DATE);INSERT INTO urban_agriculture.urban_crops (id,type,planting_date) VALUES (1,'Crop A','2022-03-01'),(2,'Crop B','2022-04-15'),(3,'Crop C','2022-05-05');
|
SELECT type, planting_date FROM urban_agriculture.urban_crops;
|
What is the maximum fare collected in a single day for trains in London?
|
CREATE TABLE train_routes (route_id INT,vehicle_type VARCHAR(10),fare DECIMAL(5,2)); CREATE TABLE train_fares (fare_id INT,route_id INT,fare_amount DECIMAL(5,2),fare_collection_date DATE); INSERT INTO train_routes VALUES (1,'Train',5.00),(2,'Train',7.00); INSERT INTO train_fares VALUES (1,1,5.00,'2022-01-01'),(2,1,5.00,'2022-01-02'),(3,2,7.00,'2022-01-03');
|
SELECT MAX(f.fare_amount) FROM train_fares f JOIN train_routes br ON f.route_id = br.route_id WHERE f.fare_collection_date = (SELECT MAX(fare_collection_date) FROM train_fares);
|
What is the average playtime of players who joined tournaments in the last 30 days?
|
CREATE TABLE players (player_id INT,join_date DATE); INSERT INTO players (player_id,join_date) VALUES (1,'2021-01-01'),(2,'2021-02-15'),(3,'2021-03-27'); CREATE TABLE tournaments (tournament_id INT,start_date DATE,end_date DATE); INSERT INTO tournaments (tournament_id,start_date,end_date) VALUES (1,'2021-03-01','2021-03-05'),(2,'2021-04-01','2021-04-05'),(3,'2021-04-15','2021-04-18'); CREATE TABLE player_tournaments (player_id INT,tournament_id INT,playtime INT); INSERT INTO player_tournaments (player_id,tournament_id,playtime) VALUES (1,1,20),(1,2,30),(2,2,25),(2,3,35),(3,3,40);
|
SELECT AVG(playtime) FROM player_tournaments WHERE player_id IN (SELECT player_id FROM players WHERE join_date >= DATE(NOW()) - INTERVAL 30 DAY) AND tournament_id IN (SELECT tournament_id FROM tournaments WHERE start_date <= DATE(NOW()) AND end_date >= DATE(NOW()));
|
Which spacecraft have had repairs costing more than $100,000, ordered by repair cost?
|
CREATE TABLE Spacecraft_Repairs (id INT,spacecraft_id INT,repair_date DATE,description VARCHAR(100),cost DECIMAL(10,2)); CREATE TABLE Spacecraft (id INT,name VARCHAR(50),type VARCHAR(50),manufacturer VARCHAR(50),launch_date DATE);
|
SELECT s.name, s.type, r.cost FROM Spacecraft_Repairs r JOIN Spacecraft s ON r.spacecraft_id = s.id WHERE r.cost > 100000.00 ORDER BY r.cost DESC;
|
What is the average CO2 emission for products sold in the UK?
|
CREATE TABLE vendors (vendor_id INT,vendor_name TEXT,country TEXT);CREATE TABLE products (product_id INT,product_name TEXT,price DECIMAL,CO2_emission INT,vendor_id INT); INSERT INTO vendors (vendor_id,vendor_name,country) VALUES (1,'VendorA','UK'),(2,'VendorB','USA'); INSERT INTO products (product_id,product_name,price,CO2_emission,vendor_id) VALUES (1,'ProductX',15.99,500,1),(2,'ProductY',12.49,300,1),(3,'ProductZ',9.99,800,2);
|
SELECT AVG(CO2_emission) FROM products JOIN vendors ON products.vendor_id = vendors.vendor_id WHERE country = 'UK';
|
Delete all records from the donors table where the total donation is less than 250.00.
|
CREATE TABLE donors (id INT,name VARCHAR(50),total_donation FLOAT); INSERT INTO donors (id,name,total_donation) VALUES (1,'John Doe',500.00),(2,'Jane Smith',350.00),(3,'Mike Johnson',200.00);
|
DELETE FROM donors WHERE total_donation < 250.00;
|
Which defense contractors have the highest average maintenance request processing time per contractor, and what is that average time?
|
CREATE TABLE contractor_maintenance(contractor_id INT,request_date DATE,request_type VARCHAR(20),processing_time INT); INSERT INTO contractor_maintenance(contractor_id,request_date,request_type,processing_time) VALUES (1,'2021-01-01','equipment_inspection',30),(2,'2021-01-05','parts_replacement',45),(1,'2021-01-10','equipment_repair',60);
|
SELECT contractor_id, AVG(processing_time) as avg_processing_time FROM contractor_maintenance GROUP BY contractor_id ORDER BY avg_processing_time DESC LIMIT 1;
|
What is the average number of digital exhibits visited per visitor from the LGBTQ+ community in 2020?
|
CREATE TABLE CommunityTypes (id INT,community_type VARCHAR(30)); INSERT INTO CommunityTypes (id,community_type) VALUES (1,'Indigenous'),(2,'Settler'),(3,'Immigrant'),(4,'Asian'),(5,'Latinx'),(6,'LGBTQ+'); CREATE TABLE DigitalVisits (id INT,visitor_id INT,community_id INT,year INT,exhibit_count INT); INSERT INTO DigitalVisits (id,visitor_id,community_id,year,exhibit_count) VALUES (1,201,6,2020,2),(2,202,6,2020,1),(3,203,3,2019,3);
|
SELECT AVG(DigitalVisits.exhibit_count) FROM DigitalVisits INNER JOIN CommunityTypes ON DigitalVisits.community_id = CommunityTypes.id WHERE CommunityTypes.community_type = 'LGBTQ+' AND DigitalVisits.year = 2020;
|
Who are the artists that performed at Lollapalooza in 2022?
|
CREATE TABLE FestivalArtists (id INT,festival VARCHAR(20),year INT,artist VARCHAR(50)); INSERT INTO FestivalArtists (id,festival,year,artist) VALUES (1,'Lollapalooza',2022,'Dua Lipa'),(2,'Lollapalooza',2022,'Machine Gun Kelly');
|
SELECT DISTINCT artist FROM FestivalArtists WHERE festival = 'Lollapalooza' AND year = 2022;
|
What is the minimum carbon offset of programs in the 'carbon_offset' schema?
|
CREATE SCHEMA carbon_offset; CREATE TABLE carbon_offset_programs (id INT,name VARCHAR(100),carbon_offset FLOAT); INSERT INTO carbon_offset_programs (id,name,carbon_offset) VALUES (1,'Program U',16.5),(2,'Program V',17.5);
|
SELECT MIN(carbon_offset) FROM carbon_offset.carbon_offset_programs;
|
How many climate adaptation initiatives were implemented in African countries?
|
CREATE TABLE climate_initiatives (id INT,country VARCHAR(50),category VARCHAR(50),year INT); INSERT INTO climate_initiatives (id,country,category,year) VALUES (1,'Kenya','Climate Adaptation',2010); INSERT INTO climate_initiatives (id,country,category,year) VALUES (2,'Nigeria','Climate Mitigation',2015); INSERT INTO climate_initiatives (id,country,category,year) VALUES (3,'South Africa','Climate Adaptation',2020);
|
SELECT COUNT(*) FROM climate_initiatives WHERE category = 'Climate Adaptation' AND country IN ('Kenya', 'Nigeria', 'South Africa', 'Egypt', 'Algeria', 'Morocco');
|
Delete transactions related to NFT dapps that have an amount less than $50.
|
CREATE TABLE if not exists transactions (id INT PRIMARY KEY,dapp_id INT,amount DECIMAL); CREATE TABLE if not exists dapps (id INT PRIMARY KEY,name TEXT,category TEXT,platform TEXT); INSERT INTO transactions (id,dapp_id,amount) VALUES (1,1,700),(2,3,40),(4,4,200); INSERT INTO dapps (id,name,category,platform) VALUES (1,'CryptoPunks','NFT','Ethereum'),(2,'Decentraland','Virtual World','Ethereum'),(3,'Aavegotchi','NFT','Ethereum'),(4,'UniswapV3','Exchange','Ethereum');
|
DELETE FROM transactions WHERE dapp_id IN (SELECT id FROM dapps WHERE category = 'NFT') AND amount < 50;
|
Find the names of all government agencies that have a budget lower than the average budget for all agencies in the 'Federal' schema.
|
CREATE TABLE Federal.agencies (name VARCHAR(50),budget INT); INSERT INTO Federal.agencies (name,budget) VALUES ('Department of Defense',7000000000),('Department of Education',70000000),('Department of Health and Human Services',1200000000),('Department of State',50000000),('Department of Transportation',80000000);
|
SELECT name FROM Federal.agencies WHERE budget < (SELECT AVG(budget) FROM Federal.agencies);
|
What is the explainability score for each AI model, partitioned by model type, ordered by score in ascending order?
|
CREATE TABLE ai_models_explainability (model_id INT,model_type VARCHAR(50),explainability_score DECIMAL(5,2)); INSERT INTO ai_models_explainability (model_id,model_type,explainability_score) VALUES (1,'Random Forest',0.87),(2,'Support Vector Machine',0.75),(3,'Convolutional Neural Network',0.93),(4,'Long Short-Term Memory',0.82);
|
SELECT model_type, AVG(explainability_score) as avg_explainability_score FROM ai_models_explainability GROUP BY model_type ORDER BY avg_explainability_score ASC;
|
List all players who have played games for more than 100 hours
|
CREATE TABLE Players (PlayerID INT,HoursPlayed INT); INSERT INTO Players (PlayerID,HoursPlayed) VALUES (1,150); INSERT INTO Players (PlayerID,HoursPlayed) VALUES (2,50);
|
SELECT * FROM Players WHERE HoursPlayed > 100;
|
List all 'Stone' artifacts from site 'Teotihuacan' with their age.
|
CREATE TABLE artifact_teotihuacan (artifact_id INTEGER,site_name TEXT,artifact_type TEXT,age INTEGER); INSERT INTO artifact_teotihuacan (artifact_id,site_name,artifact_type,age) VALUES (1,'Teotihuacan','Stone',1200),(2,'Teotihuacan','Stone',1100),(3,'Teotihuacan','Pottery',1300),(4,'Teotihuacan','Bone',1000),(5,'Teotihuacan','Stone',1400);
|
SELECT * FROM artifact_teotihuacan WHERE site_name = 'Teotihuacan' AND artifact_type = 'Stone';
|
Delete all genetic research projects that have a budget over 2 million.
|
CREATE TABLE research_projects (id INT,name VARCHAR(50),budget FLOAT); INSERT INTO research_projects VALUES (1,'ProjectG',1500000); INSERT INTO research_projects VALUES (2,'ProjectH',1000000); INSERT INTO research_projects VALUES (3,'ProjectI',2500000);
|
DELETE FROM research_projects WHERE budget > 2000000;
|
Insert new recycling data for 'Contributor B' in the 'recycling_data' table.
|
CREATE TABLE recycling_data (contributor VARCHAR(20),recycling_rate FLOAT); INSERT INTO recycling_data (contributor,recycling_rate) VALUES ('Contributor A',0.35),('Contributor B',0);
|
INSERT INTO recycling_data (contributor, recycling_rate) VALUES ('Contributor B', 0.27);
|
What is the average number of flights per day for each aircraft model?
|
CREATE TABLE aircraft_flights (flight_id INT,model_id INT,date DATE);
|
SELECT model_id, AVG(DATEDIFF('day', MIN(date), MAX(date))) as avg_flights_per_day FROM aircraft_flights GROUP BY model_id;
|
What is the distribution of articles by category and author in 'news_articles' table?
|
CREATE TABLE news_articles (id INT,title VARCHAR(100),publication_date DATE,category VARCHAR(50),author VARCHAR(50)); INSERT INTO news_articles (id,title,publication_date,category,author) VALUES (1,'Article 1','2022-01-01','Politics','John Doe'),(2,'Article 2','2022-01-02','Sports','Jane Smith');
|
SELECT category, author, COUNT(*) as num_articles, ROW_NUMBER() OVER (PARTITION BY category ORDER BY COUNT(*) DESC) as rank FROM news_articles GROUP BY category, author;
|
What is the total revenue for each product line in the 'finance' schema?
|
CREATE TABLE finance.revenue (product_line VARCHAR(50),month INT,year INT,revenue DECIMAL(10,2)); INSERT INTO finance.revenue (product_line,month,year,revenue) VALUES ('Product Line A',1,2022,12000.00),('Product Line A',2,2022,24000.00),('Product Line B',1,2022,18000.00),('Product Line B',2,2022,30000.00);
|
SELECT product_line, SUM(revenue) as total_revenue FROM finance.revenue GROUP BY product_line;
|
What is the average age of players who have participated in esports events, and the number of events they have participated in?
|
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10));CREATE TABLE EsportsEvents (EventID INT,PlayerID INT,EventType VARCHAR(20));
|
SELECT AVG(Players.Age), COUNT(EsportsEvents.EventID) FROM Players INNER JOIN EsportsEvents ON Players.PlayerID = EsportsEvents.PlayerID;
|
What was the total revenue generated by all artists in 2018?
|
CREATE TABLE ArtistRevenue (id INT,artist_name VARCHAR(50),revenue DECIMAL(10,2),year INT); INSERT INTO ArtistRevenue (id,artist_name,revenue,year) VALUES (1,'Picasso',15000,2018),(2,'Van Gogh',12000,2018),(3,'Dali',18000,2018),(4,'Matisse',16000,2018),(5,'Monet',17000,2018);
|
SELECT SUM(revenue) FROM ArtistRevenue WHERE year = 2018;
|
How many users have a membership type starting with 'E' or 'P'?
|
CREATE TABLE memberships (id INT,member_type VARCHAR(20)); INSERT INTO memberships (id,member_type) VALUES (1,'Basic'),(2,'Premium'),(3,'Elite'),(4,'Platinum'),(5,'Essential');
|
SELECT COUNT(*) as num_users FROM memberships WHERE member_type LIKE 'E%' OR member_type LIKE 'P%';
|
How many users have posted more than 50 times in the entertainment category from Canada?
|
CREATE TABLE users (id INT,country VARCHAR(255),category VARCHAR(255)); INSERT INTO users (id,country,category) VALUES (1,'Canada','entertainment'); CREATE TABLE posts (id INT,user_id INT,times INT);
|
SELECT COUNT(DISTINCT users.id) FROM users INNER JOIN posts ON users.id = posts.user_id WHERE users.country = 'Canada' AND posts.times > 50 AND users.category = 'entertainment';
|
How many agroecology initiatives have been implemented in North America, and what is the total area of land in square kilometers used for these initiatives?
|
CREATE TABLE agroecology_initiatives (id INT,name VARCHAR(255),area FLOAT,continent VARCHAR(255)); INSERT INTO agroecology_initiatives (id,name,area,continent) VALUES (1,'Initiative A',12345.6,'North America'),(2,'Initiative B',23456.7,'Europe'),(3,'Initiative C',34567.8,'Asia');
|
SELECT COUNT(*), SUM(area * 0.0001) as total_area_sq_km FROM agroecology_initiatives WHERE continent = 'North America';
|
What is the percentage of disability accommodations requested and approved by month?
|
CREATE TABLE Accommodation_Data (Request_ID INT,Request_Date DATE,Accommodation_Type VARCHAR(50),Request_Status VARCHAR(10));
|
SELECT DATE_PART('month', Request_Date) as Month, PERCENTAGE(COUNT(*) FILTER (WHERE Request_Status = 'Approved')) as Percentage_Approved FROM Accommodation_Data GROUP BY Month;
|
Find players who joined after the player with the earliest join date in 'gaming_players' table
|
CREATE TABLE gaming_players (player_id INT,name VARCHAR(50),join_date DATE);
|
SELECT * FROM gaming_players WHERE join_date > (SELECT MIN(join_date) FROM gaming_players);
|
List all cybersecurity incidents reported in the African region in 2019, including the name of the country and the incident type.
|
CREATE TABLE country (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE region (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE incident (id INT PRIMARY KEY,country_id INT,region_id INT,reported_date DATE,type VARCHAR(255)); INSERT INTO country (id,name) VALUES (1,'Nigeria'),(2,'South Africa'),(3,'Egypt'); INSERT INTO region (id,name) VALUES (1,'Africa'); INSERT INTO incident (id,country_id,region_id,reported_date,type) VALUES (1,1,1,'2019-01-01','Phishing'),(2,2,1,'2019-02-01','Malware'),(3,3,1,'2019-03-01','Data Breach');
|
SELECT c.name as country_name, i.type as incident_type FROM country c INNER JOIN incident i ON c.id = i.country_id INNER JOIN region r ON i.region_id = r.id WHERE r.name = 'Africa' AND YEAR(i.reported_date) = 2019;
|
What is the name and IP address of the threat with the lowest threat level in the 'threat_intelligence_v2' table?
|
CREATE TABLE threat_intelligence_v2 (id INT,name VARCHAR(255),ip_address VARCHAR(50),threat_level VARCHAR(10)); INSERT INTO threat_intelligence_v2 (id,name,ip_address,threat_level) VALUES (4,'APT35','172.20.0.1','Low'),(5,'APT36','10.1.1.1','High'),(6,'APT37','192.168.2.1','Medium');
|
SELECT name, ip_address FROM threat_intelligence_v2 WHERE threat_level = (SELECT MIN(threat_level) FROM threat_intelligence_v2);
|
Get the number of employees who left in each month of 2020 from the "employee_records" table
|
CREATE TABLE employee_records (employee_id INT PRIMARY KEY,name TEXT,position TEXT,leaving_date DATE); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (1,'John Doe','CTO','2018-01-01'); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (2,'Jane Smith','COO','2019-05-15'); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (3,'Alice Johnson','Data Analyst','2020-03-20'); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (4,'Bella Williams','Data Scientist','2020-04-30'); INSERT INTO employee_records (employee_id,name,position,leaving_date) VALUES (5,'Carlos Brown','Software Engineer','2020-12-15');
|
SELECT EXTRACT(MONTH FROM leaving_date) AS month, COUNT(*) AS count FROM employee_records WHERE leaving_date >= '2020-01-01' AND leaving_date < '2021-01-01' GROUP BY month ORDER BY month;
|
Insert a new record into the cargo table with the following data: cargo_id 302, vessel_id 201, cargo_type 'Containers', weight 5000
|
CREATE TABLE cargo (cargo_id INT,vessel_id INT,cargo_type VARCHAR(20),weight INT);
|
INSERT INTO cargo (cargo_id, vessel_id, cargo_type, weight) VALUES (302, 201, 'Containers', 5000);
|
What is the total waste generated by each facility, partitioned by quarter and ordered by total waste?
|
CREATE TABLE facilities (facility_id INT,facility_name VARCHAR(255),waste_generated INT,waste_collection_date DATE); INSERT INTO facilities (facility_id,facility_name,waste_generated,waste_collection_date) VALUES (1,'Facility A',100,'2022-01-01'),(2,'Facility B',200,'2022-01-15');
|
SELECT facility_name, DATE_TRUNC('quarter', waste_collection_date) AS quarter, SUM(waste_generated) AS total_waste, RANK() OVER (ORDER BY SUM(waste_generated) DESC) AS ranking FROM facilities GROUP BY facility_name, quarter ORDER BY total_waste DESC;
|
Create a view to show the average sustainability score of suppliers from each country
|
CREATE TABLE supplier_ethics (supplier_id INT,country VARCHAR(50),labor_practices VARCHAR(50),sustainability_score INT); CREATE VIEW supplier_sustainability_scores AS SELECT country,AVG(sustainability_score) as avg_sustainability_score FROM supplier_ethics GROUP BY country;
|
CREATE VIEW supplier_sustainability_scores AS SELECT country, AVG(sustainability_score) as avg_sustainability_score FROM supplier_ethics GROUP BY country;
|
What is the maximum timeline for a sustainable construction project in Utah?
|
CREATE TABLE Sustainable_Projects_UT (project_id INT,project_name VARCHAR(50),state VARCHAR(2),timeline INT,is_sustainable BOOLEAN); INSERT INTO Sustainable_Projects_UT VALUES (2,'SaltLakeCityGreenTower','UT',36,true);
|
SELECT MAX(timeline) FROM Sustainable_Projects_UT WHERE state = 'UT' AND is_sustainable = true;
|
How many times has 'contaminated' appeared in the 'food_safety_inspections' table?
|
CREATE TABLE food_safety_inspections (inspection_id INT,report TEXT); INSERT INTO food_safety_inspections (inspection_id,report) VALUES (1,'The food was contaminated with bacteria.'),(2,'The food was safe for consumption.'),(3,'The food was not contaminated.');
|
SELECT COUNT(*) as contamination_count FROM food_safety_inspections WHERE report LIKE '%contaminated%';
|
Which facilities are not hospitals?
|
CREATE TABLE facilities (id INT,name TEXT,type TEXT); INSERT INTO facilities (id,name,type) VALUES (1,'Rural Clinic','Primary Care'),(2,'Urgent Care','Urgent Care'),(3,'General Hospital','Hospital');
|
SELECT name FROM facilities WHERE type != 'Hospital';
|
What is the total tonnage of all cargos carried by vessels that have carried cargos from the African continent?
|
CREATE TABLE Cargo (Id INT,VesselId INT,Tonnage INT,Continent VARCHAR(50)); INSERT INTO Cargo (Id,VesselId,Tonnage,Continent) VALUES (1,1,5000,'Africa'),(2,1,7000,'Asia'),(3,3,8000,'Africa'),(4,2,6000,'Europe');
|
SELECT SUM(Tonnage) FROM Cargo WHERE Continent = 'Africa';
|
List safety incidents for VESSEL009
|
CREATE TABLE vessels (id VARCHAR(20),name VARCHAR(20)); INSERT INTO vessels (id,name) VALUES ('VES009','VESSEL009'),('VES010','VESSEL010'); CREATE TABLE safety_incidents (vessel_id VARCHAR(20),incident_type VARCHAR(50)); INSERT INTO safety_incidents (vessel_id,incident_type) VALUES ('VES009','Collision'),('VES009','Fire'),('VES010','Grounding');
|
SELECT incident_type FROM safety_incidents WHERE vessel_id = 'VES009';
|
List the organizations that have not had any AI safety incidents, in alphabetical order.
|
CREATE TABLE ai_safety (incident_id INT,incident_date DATE,organization_name TEXT,incident_description TEXT); INSERT INTO ai_safety (incident_id,incident_date,organization_name,incident_description) VALUES (1,'2021-01-01','TechCo','AI system caused harm to a user'); INSERT INTO ai_safety (incident_id,incident_date,organization_name,incident_description) VALUES (2,'2021-02-01','AI Lab','AI system made a biased decision');
|
SELECT DISTINCT organization_name FROM ai_safety WHERE organization_name NOT IN (SELECT organization_name FROM ai_safety GROUP BY organization_name HAVING COUNT(*) > 0) ORDER BY organization_name;
|
What is the average score for players who joined on the same day as the player with the highest score in the game 'Quantum Quests'?
|
CREATE TABLE Quantum_Quests (player_id INT,player_name VARCHAR(50),score INT,join_date DATE); INSERT INTO Quantum_Quests (player_id,player_name,score,join_date) VALUES (1,'Lucas Chen',2000,'2020-08-08'),(2,'Mia Lee',1500,'2020-08-08'),(3,'Jordan Park',1800,'2020-08-08');
|
SELECT AVG(score) FROM Quantum_Quests WHERE join_date = (SELECT join_date FROM Quantum_Quests WHERE score = (SELECT MAX(score) FROM Quantum_Quests));
|
How many unique donors supported each cause in H1 2022?
|
CREATE TABLE causes (id INT,name VARCHAR(255)); INSERT INTO causes (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donors (id INT,cause_id INT); INSERT INTO donors (id,cause_id) VALUES (1,1),(2,2),(3,1),(4,3),(5,2),(6,1),(7,3),(8,2),(9,1),(10,3);
|
SELECT cause_id, COUNT(DISTINCT id) as unique_donors FROM donors WHERE id IN (SELECT id FROM donors WHERE donation_date BETWEEN '2022-01-01' AND '2022-06-30') GROUP BY cause_id;
|
What is the average number of containers handled daily by each port agent in 'Casablanca'?
|
CREATE TABLE port (port_id INT,name TEXT);CREATE TABLE port_agent (port_agent_id INT,port_id INT,name TEXT);CREATE TABLE container (container_id INT,port_agent_id INT,handled_at DATETIME);INSERT INTO port VALUES (12,'Casablanca');
|
SELECT port_agent.name, AVG(COUNT(container.container_id)) FROM port_agent JOIN port ON port_agent.port_id = port.port_id JOIN container ON port_agent.port_agent_id = container.port_agent_id WHERE port.name = 'Casablanca' GROUP BY port_agent.name, DATE(container.handled_at);
|
What is the maximum rating of tours in Japan with a duration of at least 7 days?
|
CREATE TABLE tours (tour_id INT,name TEXT,country TEXT,rating DECIMAL,duration INT); INSERT INTO tours (tour_id,name,country,rating,duration) VALUES (1,'Japan Odyssey','Japan',5.0,10),(2,'Quick Japan Tour','Japan',4.5,5);
|
SELECT MAX(rating) FROM tours WHERE country = 'Japan' AND duration >= 7;
|
List the farms and their soil moisture levels, if available.
|
CREATE TABLE farm (id INT,name VARCHAR(50),size FLOAT,PRIMARY KEY(id)); INSERT INTO farm (id,name,size) VALUES (1,'Farm A',50.3); INSERT INTO farm (id,name,size) VALUES (2,'Farm B',75.8); CREATE TABLE soil_moisture (id INT,farm_id INT,moisture FLOAT,PRIMARY KEY(id)); INSERT INTO soil_moisture (id,farm_id,moisture) VALUES (1,1,45.6);
|
SELECT f.name, s.moisture FROM farm f LEFT JOIN soil_moisture s ON f.id = s.farm_id;
|
Find the percentage of patients treated for depression
|
CREATE TABLE patients (patient_id INT,condition VARCHAR(20)); INSERT INTO patients (patient_id,condition) VALUES (1,'depression'),(2,'anxiety');
|
SELECT (COUNT(CASE WHEN condition = 'depression' THEN 1 END) * 100.0 / COUNT(*)) AS depression_percentage FROM patients;
|
How many community engagement programs are there for each heritage site in Europe?
|
CREATE TABLE heritage_sites (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),PRIMARY KEY(id)); INSERT INTO heritage_sites (id,name,location,type) VALUES (1,'Colosseum','Italy,Europe','Ancient Roman'),(2,'Acropolis','Greece,Europe','Ancient Greek'),(3,'Alhambra','Spain,Europe','Islamic'); CREATE TABLE community_programs (id INT,heritage_site_id INT,program_name VARCHAR(50),PRIMARY KEY(id)); INSERT INTO community_programs (id,heritage_site_id,program_name) VALUES (1,1,'Guided Tours'),(2,1,'Educational Workshops'),(3,2,'Cultural Festivals'),(4,3,'Restoration Projects');
|
SELECT hs.name, hs.location, hs.type, COUNT(cp.id) AS program_count FROM heritage_sites hs JOIN community_programs cp ON hs.id = cp.heritage_site_id GROUP BY hs.name, hs.location, hs.type;
|
Identify the most profitable menu item for each restaurant
|
CREATE TABLE RestaurantSales (sale_id INT,restaurant_id INT,menu_item_id INT,revenue DECIMAL(10,2)); INSERT INTO RestaurantSales (sale_id,restaurant_id,menu_item_id,revenue) VALUES (1,1,1,100),(2,1,1,200),(3,1,2,150),(4,2,1,250),(5,2,3,300);
|
SELECT r.restaurant_name, m.menu_item_name, MAX(rs.revenue) as max_revenue FROM Restaurants r INNER JOIN RestaurantMenu rm ON r.restaurant_id = rm.restaurant_id INNER JOIN RestaurantSales rs ON rm.menu_item_id = rs.menu_item_id INNER JOIN MenuItems m ON rs.menu_item_id = m.menu_item_id GROUP BY r.restaurant_name, m.menu_item_name;
|
Insert new record into "safety_inspections" table
|
CREATE TABLE safety_inspections (id INT,union_name VARCHAR(50),inspection_date DATE,passed BOOLEAN);
|
INSERT INTO safety_inspections (id, union_name, inspection_date, passed) VALUES (1, 'United Auto Workers', '2022-06-01', true);
|
Insert new records of public schools and their student enrollment data for the city of New York.
|
CREATE TABLE schools(id INT,name VARCHAR(100),city VARCHAR(50));CREATE TABLE enrollment(id INT,school_id INT,enrollment_count INT);
|
INSERT INTO schools (name, city) VALUES ('School 1', 'New York'), ('School 2', 'New York');INSERT INTO enrollment (school_id, enrollment_count) VALUES (1, 500), (2, 800);
|
Rank peacekeeping missions in Afghanistan by duration, in descending order?
|
CREATE TABLE peacekeeping_ops (id INT,mission VARCHAR,country VARCHAR,start_date DATE,end_date DATE,PRIMARY KEY (id)); INSERT INTO peacekeeping_ops (id,mission,country,start_date,end_date) VALUES (1,'ISAF','Afghanistan','2001-09-12','2014-12-31');
|
SELECT mission, country, DATEDIFF(day, start_date, end_date) as mission_duration, RANK() OVER (ORDER BY DATEDIFF(day, start_date, end_date) DESC) as mission_rank FROM peacekeeping_ops WHERE country = 'Afghanistan';
|
What is the total number of packages received at each warehouse in Canada?
|
CREATE TABLE Warehouse (id INT,country VARCHAR(255),city VARCHAR(255),number_of_packages INT); INSERT INTO Warehouse (id,country,city,number_of_packages) VALUES (1,'Canada','Toronto',500),(2,'Canada','Vancouver',300),(3,'Canada','Montreal',200);
|
SELECT country, city, SUM(number_of_packages) FROM Warehouse WHERE country = 'Canada' GROUP BY country, city
|
How many Tb dysprosium were produced in China in total?
|
CREATE TABLE Dysprosium_Production (id INT,year INT,country VARCHAR(20),production_volume INT);
|
SELECT SUM(production_volume) FROM Dysprosium_Production WHERE country = 'China' AND element = 'Tb';
|
How many security incidents were associated with each type of attack in the last year?
|
CREATE TABLE incident_attack_type (id INT,incident_count INT,attack_type VARCHAR(50),incident_date DATE); INSERT INTO incident_attack_type (id,incident_count,attack_type,incident_date) VALUES (1,20,'Malware','2022-02-01'),(2,15,'Phishing','2022-02-02'),(3,30,'SQL Injection','2022-02-03');
|
SELECT attack_type, SUM(incident_count) as total_incidents FROM incident_attack_type WHERE incident_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY attack_type;
|
Find the number of asteroids discovered by each observatory in descending order?
|
CREATE TABLE asteroids (id INT,asteroid_name VARCHAR(50),discovery_date DATE,observatory VARCHAR(50));
|
SELECT observatory, COUNT(*) AS num_asteroids, RANK() OVER (ORDER BY COUNT(*) DESC) AS observatory_rank FROM asteroids GROUP BY observatory;
|
List all national security operations and their types from the 'National_Security' table.
|
CREATE TABLE National_Security (id INT,name VARCHAR(50),location VARCHAR(20),type VARCHAR(20),budget INT); INSERT INTO National_Security (id,name,location,type,budget) VALUES (1,'Operation Iron Wall','Middle East','Security',4000000);
|
SELECT * FROM National_Security;
|
What is the distribution of audience demographics for news in France and Germany?
|
CREATE TABLE audience (id INT,country VARCHAR(50),age INT,gender VARCHAR(10),topic VARCHAR(50)); INSERT INTO audience (id,country,age,gender,topic) VALUES (1,'France',35,'Male','News'); INSERT INTO audience (id,country,age,gender,topic) VALUES (2,'Germany',42,'Female','News');
|
SELECT country, COUNT(*), age, gender FROM audience WHERE topic = 'News' AND (country = 'France' OR country = 'Germany') GROUP BY country, age, gender;
|
What is the average energy efficiency rating for buildings in Germany in 2019?
|
CREATE TABLE EnergyEfficiency (id INT,building_id INT,year INT,energy_star_rating INT,primary key (id)); INSERT INTO EnergyEfficiency (id,building_id,year,energy_star_rating) VALUES (1,8001,2019,85);
|
SELECT AVG(energy_star_rating) FROM EnergyEfficiency WHERE country = 'Germany' AND year = 2019;
|
What is the average number of posts per day for users in the social_media schema?
|
CREATE TABLE users (id INT,name VARCHAR(50),posts_count INT,registration_date DATE); CREATE TABLE posts (id INT,user_id INT,post_text VARCHAR(255),post_date DATE);
|
SELECT AVG(DATEDIFF(post_date, registration_date) / posts_count) FROM users JOIN posts ON users.id = posts.user_id;
|
What is the minimum production quantity (in metric tons) of Terbium for the year 2017?
|
CREATE TABLE production (id INT,mine_id INT,year INT,element TEXT,production_quantity INT); INSERT INTO production (id,mine_id,year,element,production_quantity) VALUES (1,1,2017,'Terbium',40),(2,2,2017,'Terbium',60),(3,3,2017,'Terbium',80),(4,1,2017,'Dysprosium',100),(5,2,2017,'Dysprosium',120),(6,3,2017,'Dysprosium',140);
|
SELECT MIN(production_quantity) FROM production WHERE year = 2017 AND element = 'Terbium';
|
Update the rating of the brand 'EcoFriendlyBrand' to 4.5?
|
CREATE TABLE clothing_brands (brand_id INT PRIMARY KEY,brand_name VARCHAR(100),sustainability_rating FLOAT); INSERT INTO clothing_brands (brand_id,brand_name,sustainability_rating) VALUES (1,'EcoFriendlyBrand',4.2),(2,'GreenFashion',4.6),(3,'SustainableTextiles',4.5);
|
UPDATE clothing_brands SET sustainability_rating = 4.5 WHERE brand_name = 'EcoFriendlyBrand';
|
What is the average plastic waste generation per capita in the European Union?
|
CREATE TABLE PlasticWaste (country VARCHAR(50),population INT,plastic_waste_kg FLOAT); INSERT INTO PlasticWaste (country,population,plastic_waste_kg) VALUES ('Germany',83019234,17.36),('France',66990156,15.2),('Italy',60317014,13.9),('Spain',47351247,10.5),('United Kingdom',67886011,12.5);
|
SELECT AVG(plastic_waste_kg/population) FROM PlasticWaste WHERE country IN ('Germany', 'France', 'Italy', 'Spain', 'United Kingdom');
|
What is the average number of electric vehicles per city in the 'transportation' schema?
|
CREATE TABLE city_electric_vehicles (city_name VARCHAR(255),num_electric_vehicles INT); INSERT INTO city_electric_vehicles (city_name,num_electric_vehicles) VALUES ('San Francisco',15000),('Los Angeles',20000),('New York',30000);
|
SELECT AVG(num_electric_vehicles) FROM city_electric_vehicles;
|
What is the current landfill capacity in Beijing and the projected capacity in 2040?
|
CREATE TABLE landfill_capacity (location VARCHAR(50),current_capacity INT,projected_capacity INT,year INT); INSERT INTO landfill_capacity (location,current_capacity,projected_capacity,year) VALUES ('Beijing',60000,70000,2040);
|
SELECT location, current_capacity, projected_capacity FROM landfill_capacity WHERE location = 'Beijing' AND year = 2040;
|
What are the total salaries of players in each position for the hockey_players table?
|
CREATE TABLE hockey_players (player_id INT,name VARCHAR(50),position VARCHAR(20),team VARCHAR(50),salary DECIMAL(10,2)); INSERT INTO hockey_players (player_id,name,position,team,salary) VALUES (1,'Alex Ovechkin','Left Wing','Washington Capitals',10000000.00); INSERT INTO hockey_players (player_id,name,position,team,salary) VALUES (2,'Sidney Crosby','Center','Pittsburgh Penguins',11000000.00);
|
SELECT position, SUM(salary) FROM hockey_players GROUP BY position;
|
What is the total revenue for restaurants that source at least 50% of their ingredients locally?
|
CREATE TABLE restaurant_revenue(restaurant_id INT,cuisine_type TEXT,revenue FLOAT),local_sourcing(restaurant_id INT,local_source BOOLEAN); INSERT INTO restaurant_revenue(restaurant_id,cuisine_type,revenue) VALUES (1,'Italian',5000.00),(2,'Mexican',6000.00),(3,'Italian',4000.00); INSERT INTO local_sourcing(restaurant_id,local_source) VALUES (1,TRUE),(2,FALSE),(3,TRUE);
|
SELECT SUM(revenue) FROM restaurant_revenue WHERE restaurant_id IN (SELECT restaurant_id FROM local_sourcing WHERE local_source = TRUE) AND cuisine_type IN (SELECT cuisine_type FROM local_sourcing WHERE local_source = TRUE) GROUP BY cuisine_type;
|
How many marine research stations are located in the Arctic and Antarctic Oceans?
|
CREATE TABLE Research_Station (station_name VARCHAR(50),latitude NUMERIC(8,2),longitude NUMERIC(8,2),ocean_name VARCHAR(50)); INSERT INTO Research_Station (station_name,latitude,longitude,ocean_name) VALUES ('Station A',90.0000,-135.0000,'Arctic'),('Station B',90.0000,135.0000,'Antarctic'),('Station C',60.0000,-90.0000,'Arctic');
|
SELECT COUNT(*) FROM Research_Station WHERE ocean_name IN ('Arctic', 'Antarctic');
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.