instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average rating of hotels in the 'boutique' category? | CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),category VARCHAR(20),rating DECIMAL(2,1)); INSERT INTO hotels (hotel_id,name,category,rating) VALUES (1,'The Urban Chic','boutique',4.5),(2,'The Artistic Boutique','boutique',4.7),(3,'The Cozy Inn','budget',4.2); | SELECT AVG(rating) FROM hotels WHERE category = 'boutique'; |
What is the total mass of spacecraft manufactured by Galactic Inc, grouped by the continent of their origin? | CREATE TABLE SpacecraftManufacturing (Manufacturer VARCHAR(255),Country VARCHAR(255),SpacecraftModel VARCHAR(255),SpacecraftMass INT); INSERT INTO SpacecraftManufacturing (Manufacturer,Country,SpacecraftModel,SpacecraftMass) VALUES ('SpaceTech Corp','USA','SpaceshipX',10000),('SpaceTech Corp','USA','SpaceshipY',12000),('Galactic Inc','Canada','SpaceshipA',8000); | SELECT SUM(SpacecraftMass) AS Total_Spacecraft_Mass, CONCAT(SUBSTRING(Country, 1, 2), '%') AS Continent FROM SpacecraftManufacturing WHERE Manufacturer = 'Galactic Inc' GROUP BY Continent; |
List all the unique departments that have submitted petitions, along with the number of petitions submitted by each department. | CREATE TABLE departments (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE petitions (id INT PRIMARY KEY,department_id INT,title VARCHAR(255)); | SELECT d.name, COUNT(p.id) FROM departments d JOIN petitions p ON d.id = p.department_id GROUP BY d.name; |
What is the average dissolved oxygen level in farms located in the Baltic Sea and the North Sea? | CREATE TABLE dissolved_oxygen_data (farm_id INT,location VARCHAR(20),dissolved_oxygen FLOAT); INSERT INTO dissolved_oxygen_data (farm_id,location,dissolved_oxygen) VALUES (1,'Baltic Sea',8.5),(2,'North Sea',7.2),(3,'Baltic Sea',8.8),(4,'North Sea',7.5); | SELECT AVG(dissolved_oxygen) FROM dissolved_oxygen_data WHERE location IN ('Baltic Sea', 'North Sea'); |
Identify the number of unique clients associated with suspicious activities. | CREATE TABLE clients (id INT PRIMARY KEY,name VARCHAR(255),age INT,city VARCHAR(255)); INSERT INTO clients (id,name,age,city) VALUES (1001,'Jacob Smith',34,'New York'),(1002,'Sophia Johnson',45,'Los Angeles'),(1003,'Ethan Williams',29,'Chicago'),(1005,'Aaliyah Brown',31,'Houston'),(1006,'Mateo Davis',42,'Miami'); CREATE TABLE suspicious_activity (id INT PRIMARY KEY,account_id INT,activity VARCHAR(255),date DATE,client_id INT); INSERT INTO suspicious_activity (id,account_id,activity,date,client_id) VALUES (1,1,'Multiple Logins','2021-01-05',1001),(2,3,'Large Withdrawal','2021-02-15',1002),(3,5,'Account Hacking','2021-03-31',1005),(4,6,'Phishing Attempt','2021-04-10',1006),(5,1,'Suspicious Transactions','2021-05-15',1001); | SELECT COUNT(DISTINCT c.id) FROM clients c INNER JOIN suspicious_activity sa ON c.id = sa.client_id; |
What is the average water pressure by city and location, per day? | CREATE TABLE water_pressure_2 (id INT,city VARCHAR(255),location VARCHAR(255),pressure FLOAT,pressure_date DATE); INSERT INTO water_pressure_2 (id,city,location,pressure,pressure_date) VALUES (1,'Miami','Downtown',55,'2022-03-01'); INSERT INTO water_pressure_2 (id,city,location,pressure,pressure_date) VALUES (2,'Chicago','Loop',60,'2022-03-02'); | SELECT city, location, AVG(pressure) FROM water_pressure_2 GROUP BY city, location, DATE(pressure_date); |
What is the total premium for each gender? | See context | SELECT * FROM total_premium_by_gender; |
Update the contact information for the 'Code for Change' organization. | CREATE TABLE organizations (id INT,name TEXT,contact_name TEXT,contact_email TEXT,contact_phone TEXT); INSERT INTO organizations (id,name,contact_name,contact_email,contact_phone) VALUES (1,'Doctors Without Borders','John Smith','john.smith@dwb.org','555-123-4567'),(2,'Code for Change','Jane Doe','jane.doe@codeforchange.org','555-987-6543'); | UPDATE organizations SET contact_name = 'James Lee', contact_email = 'james.lee@codeforchange.org', contact_phone = '555-444-3333' WHERE name = 'Code for Change'; |
What was the average energy consumption per capita in Australia in Q2 2022? | CREATE TABLE per_capita_consumption (quarter VARCHAR(6),country VARCHAR(255),consumption FLOAT); INSERT INTO per_capita_consumption (quarter,country,consumption) VALUES ('Q2 2022','Australia',12.5),('Q2 2022','Canada',11.2),('Q3 2022','Australia',13.0); | SELECT AVG(consumption) FROM per_capita_consumption WHERE quarter = 'Q2 2022' AND country = 'Australia' |
List all astronauts who have been on a spacewalk. | CREATE TABLE spacewalks (spacewalk_id INT,astronaut_id INT,duration INT); CREATE TABLE astronauts (astronaut_id INT,name VARCHAR(50),age INT,nationality VARCHAR(50)); | SELECT a.name FROM astronauts a JOIN spacewalks s ON a.astronaut_id = s.astronaut_id; |
What is the distribution of view times for content related to climate change, segmented by age group? | CREATE TABLE user_age_groups (user_id INT,user_age_group VARCHAR(20)); CREATE TABLE content_topics (content_id INT,content_topic VARCHAR(50),content_length INT); CREATE TABLE user_content_views (view_id INT,user_id INT,content_id INT,view_date DATE); | SELECT user_age_group, AVG(content_length / 60) as avg_view_time FROM user_content_views JOIN user_age_groups ON user_content_views.user_id = user_age_groups.user_id JOIN content_topics ON user_content_views.content_id = content_topics.content_id WHERE content_topics.content_topic = 'climate change' GROUP BY user_age_group; |
What is the total recycled content of products in the 'Eco-friendly' category? | CREATE TABLE products (product_id int,product_name varchar(255),product_category varchar(255),recycled_content float); INSERT INTO products (product_id,product_name,product_category,recycled_content) VALUES (1,'Product A','Eco-friendly',0.8),(2,'Product B','Standard',0.2),(3,'Product C','Eco-friendly',0.9); | SELECT product_category, SUM(recycled_content) FROM products WHERE product_category = 'Eco-friendly' GROUP BY product_category; |
Update the temperature values to Fahrenheit in the temperature_data table | CREATE TABLE temperature_data (id INT,farm_id INT,temperature FLOAT,measurement_date DATE); | UPDATE temperature_data SET temperature = temperature * 9/5 + 32; |
What is the average maintenance cost for the top five equipment types with the most maintenance costs? | CREATE TABLE Equipment_Maintenance (Equipment_ID INT,Equipment_Type VARCHAR(50),Maintenance_Date DATE,Maintenance_Cost FLOAT,Maintenance_Company VARCHAR(50)); CREATE VIEW Most_Expensive_Equipment_Maintenance AS SELECT Equipment_Type,SUM(Maintenance_Cost) as Total_Maintenance_Cost FROM Equipment_Maintenance GROUP BY Equipment_Type ORDER BY Total_Maintenance_Cost DESC; | SELECT Equipment_Type, AVG(Maintenance_Cost) as Average_Maintenance_Cost FROM Equipment_Maintenance WHERE Equipment_Type IN (SELECT Equipment_Type FROM Most_Expensive_Equipment_Maintenance WHERE ROWNUM <= 5) GROUP BY Equipment_Type; |
What is the average size of the largest order for each salesperson? | CREATE TABLE salesperson (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO salesperson (id,name,region) VALUES (1,'John Doe','North'),(2,'Jane Smith','South'); CREATE TABLE orders (id INT,salesperson_id INT,size INT); INSERT INTO orders (id,salesperson_id,size) VALUES (1,1,10),(2,1,15),(3,2,20),(4,2,25); | SELECT salesperson_id, AVG(size) as avg_max_order_size FROM (SELECT salesperson_id, MAX(size) as size FROM orders GROUP BY salesperson_id) subquery GROUP BY salesperson_id; |
How many satellites were launched by each country in the satellites table? | CREATE TABLE satellites (id INT,name VARCHAR(50),launch_country VARCHAR(50),launch_date DATE); INSERT INTO satellites VALUES (1,'Sputnik 1','USSR','1957-10-04'); INSERT INTO satellites VALUES (2,'Explorer 1','USA','1958-01-31'); | SELECT launch_country, COUNT(*) OVER (PARTITION BY launch_country) FROM satellites; |
What is the average plastic recycling rate in 2019 for Oceania and Australia? | CREATE TABLE RecyclingRates (year INT,region VARCHAR(50),material VARCHAR(50),recycling_rate FLOAT); INSERT INTO RecyclingRates (year,region,material,recycling_rate) VALUES (2019,'North America','Plastic',0.25),(2019,'Europe','Plastic',0.3),(2019,'Asia','Plastic',0.4),(2019,'Oceania','Plastic',0.2),(2019,'Australia','Plastic',0.15); | SELECT AVG(recycling_rate) FROM RecyclingRates WHERE year = 2019 AND material = 'Plastic' AND region IN ('Oceania', 'Australia'); |
How many lifelong learning programs were offered in each country in 2022? | CREATE TABLE lifelong_learning_programs (program_id INT,country VARCHAR(50),year INT); INSERT INTO lifelong_learning_programs (program_id,country,year) VALUES (1,'USA',2022),(2,'Canada',2021),(3,'Mexico',2022),(4,'Brazil',2021),(5,'USA',2022),(6,'UK',2022),(7,'Germany',2021),(8,'France',2022),(9,'Japan',2022),(10,'China',2021); | SELECT country, COUNT(*) as program_count FROM lifelong_learning_programs WHERE year = 2022 GROUP BY country; |
What is the maximum age of trees in the 'Temperate' region? | CREATE TABLE trees (id INT,age FLOAT,species TEXT,region TEXT); INSERT INTO trees (id,age,species,region) VALUES (1,23.4,'Oak','Temperate'),(2,56.7,'Maple','Temperate'),(3,98.2,'Birch','Temperate'); | SELECT MAX(age) FROM trees WHERE region = 'Temperate'; |
What is the maximum capacity of green building certifications awarded in New York City? | CREATE TABLE certifications (id INT,city VARCHAR(20),certification_name VARCHAR(20),capacity INT); INSERT INTO certifications (id,city,certification_name,capacity) VALUES (1,'New York City','LEED',100),(2,'New York City','BREEAM',120),(3,'New York City','WELL',150),(4,'New York City','Green Star',130); | SELECT MAX(capacity) FROM certifications WHERE city = 'New York City'; |
What is the number of patents related to climate change mitigation filed by Indian companies? | CREATE TABLE Patents (ID INT,Company VARCHAR(255),Country VARCHAR(255),Category VARCHAR(255)); INSERT INTO Patents (ID,Company,Country,Category) VALUES (1,'Company 1','India','Climate Change Mitigation'),(2,'Company 2','China','Climate Change Adaptation'),(3,'Company 3','India','Climate Change Mitigation'),(4,'Company 4','US','Climate Change Finance'),(5,'Company 5','India','Climate Change Communication'); | SELECT COUNT(*) FROM Patents WHERE Country = 'India' AND Category = 'Climate Change Mitigation'; |
Show the number of followers for users who have posted about vegan food in the past week, filtered by gender (male, female, non-binary). | CREATE TABLE users (user_id INT,user_name VARCHAR(50),join_date DATE,follower_count INT,gender VARCHAR(10));CREATE TABLE posts (post_id INT,user_id INT,post_content TEXT,post_date DATE);INSERT INTO users (user_id,user_name,join_date,follower_count,gender) VALUES (1,'user1','2021-01-01',15000,'female'),(2,'user2','2021-02-01',12000,'male'),(3,'user3','2021-03-01',5000,'non-binary'),(4,'user4','2021-03-01',8000,'non-binary'); | SELECT u.gender, COUNT(u.user_id) as follower_count FROM users u JOIN posts p ON u.user_id = p.user_id WHERE p.post_content LIKE '%vegan food%' AND p.post_date >= DATEADD(week, -1, GETDATE()) GROUP BY u.gender; |
How many marine species have been observed in the Mediterranean Sea? | CREATE TABLE marine_species_observations (species_name VARCHAR(255),location VARCHAR(255),num_observations INT); INSERT INTO marine_species_observations (species_name,location,num_observations) VALUES ('Dolphins','Mediterranean Sea',500),('Tuna','Mediterranean Sea',1200),('Jellyfish','Mediterranean Sea',800); | SELECT COUNT(DISTINCT species_name) FROM marine_species_observations WHERE location = 'Mediterranean Sea'; |
What is the percentage of social good technology initiatives in Latin America? | CREATE TABLE social_good_technology (id INT,initiative VARCHAR,region VARCHAR,is_social_good BOOLEAN); | SELECT region, COUNT(*) as total_initiatives, COUNT(*) FILTER (WHERE is_social_good = TRUE) as social_good_initiatives, (COUNT(*) FILTER (WHERE is_social_good = TRUE) * 100.0 / COUNT(*)) as percentage FROM social_good_technology WHERE region = 'Latin America' GROUP BY region; |
Which countries have sales of products with natural preservatives? | CREATE TABLE natural_preservatives (product_id INT,preservative_id INT,preservative_name TEXT); CREATE TABLE sales_countries_with_natural_preservatives AS SELECT sales_countries.*,natural_preservatives.preservative_id,natural_preservatives.preservative_name FROM sales_countries JOIN natural_preservatives ON sales_countries.product_id = natural_preservatives.product_id; INSERT INTO natural_preservatives VALUES (1,1,'PreservativeA'),(2,2,'PreservativeB'),(3,3,'PreservativeC'),(4,4,'PreservativeD'),(5,1,'PreservativeA'),(6,5,'PreservativeE'); | SELECT sales_countries_with_natural_preservatives.country_name FROM sales_countries_with_natural_preservatives JOIN natural_preservatives ON sales_countries_with_natural_preservatives.preservative_id = natural_preservatives.preservative_id WHERE natural_preservatives.preservative_name LIKE 'Preservative%' GROUP BY sales_countries_with_natural_preservatives.country_name HAVING COUNT(DISTINCT natural_preservatives.preservative_id) > 1 |
Which biotech startups from Canada or Japan have filed for biosensor patents in the last 3 years? | CREATE TABLE biosensor_patents (patent_name VARCHAR(255),filing_date DATE,startup_country VARCHAR(255)); INSERT INTO biosensor_patents (patent_name,filing_date,startup_country) VALUES ('BioPatent2','2022-01-01','Canada'); | SELECT DISTINCT startup_country FROM biosensor_patents WHERE filing_date BETWEEN DATEADD(YEAR, -3, GETDATE()) AND GETDATE() AND startup_country IN ('Canada', 'Japan'); |
Identify the top 3 menu items with the highest inventory turnover ratio in the last 6 months. | CREATE TABLE inventory (inventory_id INT,menu_item_id INT,quantity INT,reorder_date DATE); INSERT INTO inventory VALUES (1,1,50,'2022-01-01'),(2,2,75,'2022-02-01'),(3,3,60,'2022-03-01'),(4,1,100,'2022-04-01'); CREATE TABLE sales (sale_id INT,menu_item_id INT,sale_amount DECIMAL(10,2),sale_date DATE); INSERT INTO sales VALUES (1,1,50.00,'2022-02-01'),(2,2,75.00,'2022-03-01'),(3,3,60.00,'2022-04-01'),(4,1,100.00,'2022-05-01'); CREATE TABLE menu_items (menu_item_id INT,menu_item_name VARCHAR(255),category VARCHAR(255)); INSERT INTO menu_items VALUES (1,'Veggie Burger','Entrees'),(2,'Tomato Soup','Soups'),(3,'Caesar Salad','Salads'); | SELECT i1.menu_item_id, m1.menu_item_name, c1.category, AVG(i1.quantity / (DATEDIFF(day, i1.reorder_date, s1.sale_date) * AVG(i1.quantity))) AS inventory_turnover_ratio FROM inventory i1 INNER JOIN menu_items m1 ON i1.menu_item_id = m1.menu_item_id INNER JOIN (SELECT menu_item_id, category FROM menu_items EXCEPT SELECT menu_item_id, category FROM menu_items WHERE menu_item_id NOT IN (SELECT menu_item_id FROM sales)) c1 ON m1.menu_item_id = c1.menu_item_id INNER JOIN sales s1 ON i1.menu_item_id = s1.menu_item_id WHERE s1.sale_date > DATEADD(month, -6, GETDATE()) GROUP BY i1.menu_item_id, m1.menu_item_name, c1.category ORDER BY inventory_turnover_ratio DESC LIMIT 3; |
Add a new record for a supplier 'Supplier F' from the 'Renewable Energy' industry. | CREATE TABLE suppliers (id INT,name TEXT,industry TEXT); INSERT INTO suppliers (id,name,industry) VALUES (1,'Supplier A','Manufacturing'),(2,'Supplier B','Electronics'),(3,'Supplier C','Manufacturing'),(4,'Supplier D','Electronics'),(5,'Supplier E','Manufacturing'); | INSERT INTO suppliers (id, name, industry) VALUES (6, 'Supplier F', 'Renewable Energy'); |
How many autonomous cars were sold in San Francisco in 2021? | CREATE TABLE cars (id INT PRIMARY KEY,type VARCHAR(20),sales_year INT,city VARCHAR(20),quantity INT); | SELECT SUM(quantity) FROM cars WHERE type = 'Autonomous' AND city = 'San Francisco' AND sales_year = 2021; |
What is the previous day's closing price for each stock? | CREATE TABLE stocks (stock_symbol TEXT,date DATE,open_price FLOAT,close_price FLOAT); INSERT INTO stocks (stock_symbol,date,open_price,close_price) VALUES ('AAPL','2022-01-01',150.00,155.00),('AAPL','2022-01-02',155.00,160.00); | SELECT stock_symbol, date, close_price, LAG(close_price) OVER (PARTITION BY stock_symbol ORDER BY date) as previous_day_close FROM stocks; |
Show the top 3 countries with the most players in the 'Players' table, ordered by the number of players in descending order. | CREATE TABLE Players (PlayerID INT,Name VARCHAR(100),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Name,Country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'),(3,'James Brown','England'),(4,'Sophia Johnson','Germany'),(5,'Emma White','USA'),(6,'Oliver Black','Canada'),(7,'Lucas Green','Brazil'),(8,'Ava Blue','Australia'); | SELECT Country, COUNT(*) AS PlayerCount FROM Players GROUP BY Country ORDER BY PlayerCount DESC LIMIT 3; |
Insert new player records for the "RPG Quest" game | CREATE TABLE players (player_id INT,name VARCHAR(255),country VARCHAR(255),date_registered DATE); CREATE TABLE player_scores (player_id INT,game_name VARCHAR(255),score INT,date DATE); | INSERT INTO players (player_id, name, country, date_registered) VALUES (1, 'Sophia Lee', 'South Korea', '2022-01-03'), (2, 'Pedro Martinez', 'Brazil', '2022-01-04'); INSERT INTO player_scores (player_id, game_name, score, date) VALUES (1, 'RPG Quest', 1200, '2022-01-03'), (2, 'RPG Quest', 1300, '2022-01-04'); |
What's the number of viewers for each TV show genre in Spain? | CREATE TABLE tv_show (tv_show_id INT,title VARCHAR(50),genre VARCHAR(50),viewers INT,country VARCHAR(50)); INSERT INTO tv_show (tv_show_id,title,genre,viewers,country) VALUES (1,'Show 1','Comedy',1000,'Spain'),(2,'Show 2','Drama',2000,'France'),(3,'Show 3','Comedy',1500,'Spain'); | SELECT genre, SUM(viewers) FROM tv_show WHERE country = 'Spain' GROUP BY genre; |
What is the total cargo handled by each port in 2021? | CREATE TABLE if not exists ports_traffic (id INT PRIMARY KEY,port_id INT,year INT,total_cargo INT); INSERT INTO ports_traffic (id,port_id,year,total_cargo) VALUES (1,1,2021,6000000); | SELECT p.name, total_cargo FROM ports p JOIN ports_traffic t ON p.id = t.port_id WHERE t.year = 2021; |
What is the total revenue generated by each manufacturer in the oncology category? | CREATE TABLE drugs (id INT PRIMARY KEY,name VARCHAR(255),manufacturer VARCHAR(255),category VARCHAR(255)); INSERT INTO drugs (id,name,manufacturer,category) VALUES (1,'DrugC','Manufacturer2','Oncology'); CREATE TABLE sales (id INT PRIMARY KEY,drug_id INT,quantity INT,revenue FLOAT,date DATE,FOREIGN KEY (drug_id) REFERENCES drugs(id)); INSERT INTO sales (id,drug_id,quantity,revenue,date) VALUES (3,1,150,15000.00,'2020-01-01'); | SELECT manufacturer, SUM(revenue) FROM drugs INNER JOIN sales ON drugs.id = sales.drug_id WHERE category = 'Oncology' GROUP BY manufacturer; |
What is the total number of volunteers who signed up in each quarter of the last two years? | CREATE TABLE Volunteers (VolunteerID INT,SignUpDate DATE); INSERT INTO Volunteers (VolunteerID,SignUpDate) VALUES (1,'2022-01-15'),(2,'2022-02-20'),(3,'2022-03-05'),(4,'2021-12-31'),(5,'2021-06-01'); | SELECT EXTRACT(QUARTER FROM SignUpDate) as Quarter, COUNT(*) as NumVolunteers FROM Volunteers WHERE SignUpDate >= DATE_TRUNC('year', CURRENT_DATE - INTERVAL '2 years') AND SignUpDate < DATE_TRUNC('year', CURRENT_DATE) GROUP BY Quarter ORDER BY Quarter; |
What is the total labor cost for construction projects in California? | CREATE TABLE projects (id INT,name TEXT,state TEXT,labor_cost DECIMAL(10,2)); INSERT INTO projects (id,name,state,labor_cost) VALUES (1,'Eco Project 1','California',50000.00); INSERT INTO projects (id,name,state,labor_cost) VALUES (2,'Green Project 2','California',75000.00); INSERT INTO projects (id,name,state,labor_cost) VALUES (3,'Solar Project 3','Nevada',60000.00); | SELECT SUM(labor_cost) as total_labor_cost FROM projects WHERE state = 'California'; |
Insert a new teacher with ID 3, name 'David Jones', subject 'English', and years of experience 8. | CREATE TABLE teachers (id INT,name VARCHAR(50),subject VARCHAR(50),years_experience INT); INSERT INTO teachers (id,name,subject,years_experience) VALUES (1,'Alice Brown','Math',10); INSERT INTO teachers (id,name,subject,years_experience) VALUES (2,'Bob Johnson','Science',15); | INSERT INTO teachers (id, name, subject, years_experience) VALUES (3, 'David Jones', 'English', 8); |
What is the total number of vessels in the Global Fishing Watch database? | CREATE TABLE global_fishing_watch (mmsi INTEGER,vessel_name TEXT,status TEXT); INSERT INTO global_fishing_watch (mmsi,vessel_name,status) VALUES (123456,'Fishing Vessel A','Active'),(789012,'Fishing Vessel B','Inactive'),(345678,'Fishing Vessel C','Active'); | SELECT COUNT(*) FROM global_fishing_watch WHERE status = 'Active'; |
Update the country of the satellite 'Sentinel-1A' to 'Europe' | CREATE TABLE satellite_deployment (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),launch_date DATE); INSERT INTO satellite_deployment (id,name,country,launch_date) VALUES (1,'Sentinel-1A','European Union','2014-04-03'),(2,'TechSat','United States','2022-09-01'); | UPDATE satellite_deployment SET country = 'Europe' WHERE name = 'Sentinel-1A'; |
What was the total carbon emissions in the United States and Canada in 2018 and 2020? | CREATE TABLE carbon_emissions (country VARCHAR(255),year INT,emissions FLOAT); INSERT INTO carbon_emissions (country,year,emissions) VALUES ('United States',2018,5500),('United States',2018,5300),('United States',2020,5000),('United States',2020,5200),('Canada',2018,600),('Canada',2018,650),('Canada',2020,550),('Canada',2020,600); | SELECT country, SUM(emissions) as total_emissions, year FROM carbon_emissions GROUP BY country, year; |
What is the total number of online travel agency bookings for hotels in Mumbai, India in the month of July 2022? | CREATE TABLE online_travel_agencies (id INT,hotel_id INT,revenue INT,booking_date DATE); CREATE TABLE hotels (id INT,name TEXT,city TEXT,country TEXT); | SELECT SUM(1) FROM online_travel_agencies ota INNER JOIN hotels h ON ota.hotel_id = h.id WHERE h.city = 'Mumbai' AND h.country = 'India' AND booking_date BETWEEN '2022-07-01' AND '2022-07-31'; |
What is the total number of comments on posts in the 'beauty' category on Instagram? | CREATE TABLE post_data (post_id INT,category VARCHAR(50),platform VARCHAR(20)); INSERT INTO post_data (post_id,category,platform) VALUES (1,'beauty','Instagram'),(2,'fashion','Instagram'); CREATE TABLE post_comments (comment_id INT,post_id INT,platform VARCHAR(20)); INSERT INTO post_comments (comment_id,post_id,platform) VALUES (1,1,'Instagram'),(2,1,'Instagram'),(3,2,'Instagram'); | SELECT SUM(comment_id) FROM post_comments INNER JOIN post_data ON post_comments.post_id = post_data.post_id WHERE post_data.category = 'beauty' AND post_data.platform = 'Instagram'; |
What is the maximum budget for a single infrastructure project in the 'rural_infrastructure' table? | CREATE TABLE rural_infrastructure (project_id INT,project_name TEXT,start_date DATE,end_date DATE,budget INT); INSERT INTO rural_infrastructure (project_id,project_name,start_date,end_date,budget) VALUES (1,'Water Supply','2021-01-01','2021-12-31',100000),(2,'Road Construction','2020-04-01','2020-12-31',150000); | SELECT MAX(budget) FROM rural_infrastructure; |
Update the capacity of the Mumbai landfill | CREATE TABLE landfill_capacity (id INT PRIMARY KEY,location VARCHAR(50),capacity INT); | UPDATE landfill_capacity SET capacity = 500000 WHERE location = 'Mumbai'; |
What was the outcome of cases in which clients were billed over $1000? | CREATE TABLE clients (id INT,name TEXT,state TEXT); INSERT INTO clients (id,name,state) VALUES (1,'Alan Shore','New York'); CREATE TABLE billing (id INT,client_id INT,amount INT); INSERT INTO billing (id,client_id,amount) VALUES (1,1,1500); CREATE TABLE cases (id INT,client_id INT,result TEXT); INSERT INTO cases (id,client_id,result) VALUES (1,1,'won'); | SELECT cases.result FROM cases INNER JOIN billing ON cases.client_id = billing.client_id WHERE billing.amount > 1000; |
What is the average depth of all stations owned by the Oceanographers United? | CREATE TABLE DiverseStations (id INT,owner TEXT,name TEXT,latitude REAL,longitude REAL,depth REAL); INSERT INTO DiverseStations (id,owner,name,latitude,longitude,depth) VALUES (1,'Oceanographers United','Station 1',32.9648,-117.2254,1200); INSERT INTO DiverseStations (id,owner,name,latitude,longitude,depth) VALUES (2,'Oceanographers United','Station 2',55.3781,-3.4359,800); | SELECT AVG(depth) FROM DiverseStations WHERE owner = 'Oceanographers United'; |
What is the total quantity of organic fruits in stock? | CREATE TABLE Inventory (item_id INT,name VARCHAR(50),is_organic BOOLEAN,is_fruit BOOLEAN,quantity INT); INSERT INTO Inventory (item_id,name,is_organic,is_fruit,quantity) VALUES (1,'Apples',true,true,50),(2,'Potatoes',false,false,30); | SELECT SUM(quantity) FROM Inventory WHERE is_organic = true AND is_fruit = true; |
What is the total installed capacity (in MW) of wind projects in the state of 'California'? | CREATE TABLE wind_projects (project_id INT,project_name VARCHAR(50),state VARCHAR(50),installed_capacity INT); INSERT INTO wind_projects (project_id,project_name,state,installed_capacity) VALUES (1,'Wind Farm 1','California',50),(2,'Wind Farm 2','Texas',100); | SELECT SUM(installed_capacity) FROM wind_projects WHERE state = 'California'; |
What is the total number of research grants awarded to the Department of Computer Science and the Department of Mathematics? | CREATE TABLE Department (id INT,name VARCHAR(255),college VARCHAR(255)); INSERT INTO Department (id,name,college) VALUES (1,'Biology','College of Science'),(2,'Chemistry','College of Science'),(3,'Physics','College of Science'),(4,'Computer Science','College of Engineering'),(5,'Mathematics','College of Engineering'); CREATE TABLE ResearchGrants (id INT,department_id INT,num_grants INT); INSERT INTO ResearchGrants (id,department_id,num_grants) VALUES (1,1,5),(2,1,3),(3,2,7),(4,3,2),(5,4,4),(6,4,6),(7,5,3); | SELECT SUM(rg.num_grants) FROM ResearchGrants rg JOIN Department d ON rg.department_id = d.id WHERE d.name IN ('Computer Science', 'Mathematics'); |
What was the average delivery time for ground shipments in Canada? | CREATE TABLE shipments (shipment_id INT,shipment_date DATE,shipping_mode VARCHAR(20),delivery_time INT,delivery_country VARCHAR(20)); INSERT INTO shipments (shipment_id,shipment_date,shipping_mode,delivery_time,delivery_country) VALUES (1,'2022-04-01','Ground',5,'Canada'),(2,'2022-06-15','Air',3,'USA'),(3,'2022-05-03','Ground',7,'Canada'); | SELECT AVG(delivery_time) FROM shipments WHERE shipping_mode = 'Ground' AND delivery_country = 'Canada'; |
What is the percentage of products in each category that are part of the circular supply chain? | CREATE TABLE products (product_id INT,product_category VARCHAR(50),is_circular_supply BOOLEAN); INSERT INTO products (product_id,product_category,is_circular_supply) VALUES (1,'Electronics',TRUE),(2,'Clothing',FALSE),(3,'Furniture',TRUE),(4,'Electronics',FALSE),(5,'Clothing',TRUE); | SELECT product_category, (COUNT(*) FILTER (WHERE is_circular_supply = TRUE)::DECIMAL / COUNT(*)) * 100 AS percentage FROM products GROUP BY product_category; |
Decrease the soil moisture readings by 5% for parcel_id 9 | CREATE TABLE soil_moisture_data (parcel_id INT,moisture FLOAT,timestamp TIMESTAMP); INSERT INTO soil_moisture_data (parcel_id,moisture,timestamp) VALUES (8,32.1,'2021-01-01 10:00:00'),(9,40.5,'2021-01-01 10:00:00'),(10,45.3,'2021-01-01 10:00:00'); | WITH updated_data AS (UPDATE soil_moisture_data SET moisture = moisture - 5 WHERE parcel_id = 9 RETURNING *) SELECT * FROM updated_data; |
What is the average age of artists who performed at festivals in 2021? | CREATE TABLE artists (id INT,name VARCHAR(255),age INT),festivals (id INT,artist_id INT,year INT); INSERT INTO artists (id,name,age) VALUES (1,'ArtistA',30),(2,'ArtistB',35),(3,'ArtistC',28); INSERT INTO festivals (id,artist_id,year) VALUES (1,1,2021),(2,2,2021),(3,3,2021); | SELECT AVG(age) AS avg_age FROM artists JOIN festivals ON artists.id = festivals.artist_id WHERE festivals.year = 2021; |
List all military innovation projects with a budget over '1000000' dollars | CREATE TABLE military_innovation (project_name VARCHAR(50),budget DECIMAL(10,2)); | SELECT project_name FROM military_innovation WHERE budget > 1000000; |
How many flu vaccinations were administered in Canada in 2019? | CREATE TABLE flu_vaccinations (id INT,country VARCHAR(20),year INT,vaccinations INT); INSERT INTO flu_vaccinations (id,country,year,vaccinations) VALUES (1,'Canada',2018,5000000),(2,'Canada',2019,6000000),(3,'Mexico',2019,4000000); | SELECT SUM(vaccinations) FROM flu_vaccinations WHERE country = 'Canada' AND year = 2019; |
List the VictimAdvocateID and total cases handled by Victim Advocates who have handled more than 15 cases in the RestorativeJusticeProgram table. | CREATE TABLE VictimAdvocates (VictimAdvocateID INT,Name VARCHAR(30)); CREATE TABLE RestorativeJusticeProgram (CaseID INT,VictimAdvocateID INT,Date DATE); INSERT INTO VictimAdvocates (VictimAdvocateID,Name) VALUES (1,'Judy Hopps'),(2,'Nick Wilde'),(3,'Chief Bogo'); INSERT INTO RestorativeJusticeProgram (CaseID,VictimAdvocateID,Date) VALUES (1,1,'2021-09-01'),(2,1,'2021-09-15'),(3,2,'2021-09-25'),(4,3,'2021-10-01'),(5,1,'2021-10-05'),(6,2,'2021-10-10'); | SELECT VictimAdvocateID, COUNT(*) as TotalCases FROM RestorativeJusticeProgram WHERE VictimAdvocateID IN (SELECT VictimAdvocateID FROM RestorativeJusticeProgram GROUP BY VictimAdvocateID HAVING COUNT(*) > 15) GROUP BY VictimAdvocateID; |
What is the budget for projects in Africa? | CREATE TABLE if not exists countries (id INT PRIMARY KEY,name VARCHAR(50),continent VARCHAR(50)); INSERT INTO countries (id,name,continent) VALUES (1,'Afghanistan','Asia'); INSERT INTO countries (id,name,continent) VALUES (2,'Algeria','Africa'); CREATE TABLE if not exists projects (id INT PRIMARY KEY,name VARCHAR(50),country_id INT,budget DECIMAL(10,2)); INSERT INTO projects (id,name,country_id,budget) VALUES (1,'Disaster Response',2,60000.00); INSERT INTO projects (id,name,country_id,budget) VALUES (2,'Community Development',2,80000.00); | SELECT p.budget FROM projects p JOIN countries c ON p.country_id = c.id WHERE c.continent = 'Africa'; |
What are the production figures for wells in the Gulf of Mexico? | CREATE TABLE wells (well_id INT,well_name VARCHAR(50),location VARCHAR(50),production FLOAT); INSERT INTO wells (well_id,well_name,location,production) VALUES (9,'Well I','Gulf of Mexico',450.6),(10,'Well J','Sahara',501.7),(11,'Well K','North Sea',420.4); | SELECT location, production FROM wells WHERE location = 'Gulf of Mexico'; |
Delete all records in the creative_ai table where the application is 'audio generation' and the output_quality is not 'excellent' | CREATE TABLE creative_ai (id INTEGER,application TEXT,output_quality TEXT,last_updated TIMESTAMP); | DELETE FROM creative_ai WHERE application = 'audio generation' AND output_quality != 'excellent'; |
Update the name of the hotel in Spain with ID 5 to 'Hotel Renamed'. | CREATE TABLE hotels(id INT,name TEXT,country TEXT); INSERT INTO hotels(id,name,country) VALUES (5,'Hotel Original','Spain'),(6,'Hotel Another','Portugal'); | UPDATE hotels SET name = 'Hotel Renamed' WHERE id = 5 AND country = 'Spain'; |
How many employees were hired in 2020? | CREATE TABLE Hiring (HireID INT,HireDate DATE); INSERT INTO Hiring (HireID,HireDate) VALUES (1,'2020-01-01'),(2,'2019-12-31'),(3,'2020-06-15'),(4,'2018-09-01'); | SELECT COUNT(*) FROM Hiring WHERE YEAR(HireDate) = 2020; |
Create a table to store information about teachers' professional development | CREATE TABLE TeachersProfessionalDevelopment (TeacherID INT PRIMARY KEY,DevelopmentType VARCHAR(50),StartDate DATE,EndDate DATE); | CREATE TABLE TeachersProfessionalDevelopment (TeacherID INT PRIMARY KEY, DevelopmentType VARCHAR(50), StartDate DATE, EndDate DATE); |
What is the average age of players who have played a VR game? | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),HasPlayedVR BOOLEAN); INSERT INTO Players (PlayerID,Age,Gender,HasPlayedVR) VALUES (1,25,'Male',TRUE),(2,30,'Female',FALSE),(3,22,'Male',TRUE); | SELECT AVG(Age) FROM Players WHERE HasPlayedVR = TRUE; |
What percentage of autonomous vehicle crash tests were successful in the 'autonomous_testing' view? | CREATE VIEW autonomous_testing AS SELECT vehicle_make VARCHAR(50),test_result VARCHAR(10) FROM safety_testing WHERE test_type = 'autonomous'; | SELECT (COUNT(*) FILTER (WHERE test_result = 'successful')) * 100.0 / COUNT(*) FROM autonomous_testing; |
What is the total billing amount for each attorney, sorted by the total amount? | CREATE TABLE Attorneys (AttorneyID INT,Name VARCHAR(50),TotalBilling DECIMAL(10,2)); INSERT INTO Attorneys (AttorneyID,Name,TotalBilling) VALUES (1,'John Doe',5000.00),(2,'Jane Smith',7000.00); | SELECT Name, SUM(TotalBilling) AS TotalBilling FROM Attorneys GROUP BY Name ORDER BY TotalBilling DESC; |
What is the total military equipment sales revenue for each year? | CREATE TABLE military_equipment_sales(id INT,year INT,equipment_type VARCHAR(20),quantity INT,sale_price FLOAT); | SELECT year, SUM(quantity * sale_price) FROM military_equipment_sales GROUP BY year; |
What is the number of vessels of type 'tanker' that are in the fleet? | CREATE TABLE vessel_types (vessel_type VARCHAR(50),quantity INT); CREATE TABLE vessels (vessel_id INT,vessel_type VARCHAR(50)); | SELECT quantity FROM vessel_types WHERE vessel_type = 'tanker'; |
How many cargo handling operations were performed in the 'Pacific' region in 2020? | CREATE TABLE regions (id INT PRIMARY KEY,name TEXT); INSERT INTO regions (id,name) VALUES (1,'Pacific'),(2,'Atlantic'); CREATE TABLE operations (id INT PRIMARY KEY,region_id INT,year INT,FOREIGN KEY (region_id) REFERENCES regions(id)); | SELECT COUNT(*) FROM operations WHERE region_id = (SELECT id FROM regions WHERE name = 'Pacific') AND year = 2020; |
Count of creative AI applications submitted from underrepresented communities in 2020. | CREATE TABLE creative_ai (application_id TEXT,community_type TEXT,submission_date DATE); INSERT INTO creative_ai (application_id,community_type,submission_date) VALUES ('App1','Underrepresented','2020-02-12'),('App2','Represented','2019-06-15'),('App3','Underrepresented','2020-11-05'); | SELECT COUNT(*) FROM creative_ai WHERE community_type = 'Underrepresented' AND submission_date >= '2020-01-01' AND submission_date < '2021-01-01'; |
List all flood control projects in the Midwest that were constructed between 1990 and 2000, along with their construction cost and the number of people served, and rank them by the construction cost in ascending order. | CREATE TABLE flood_control_projects (id INT,project_name VARCHAR(255),location VARCHAR(255),construction_cost INT,people_served INT); INSERT INTO flood_control_projects (id,project_name,location,construction_cost,people_served) VALUES (1,'Levee System','Midwest',25000000,50000),(2,'Floodplain Restoration','Midwest',18000000,30000),(3,'Detention Basin','Midwest',22000000,40000); | SELECT project_name, construction_cost, people_served, ROW_NUMBER() OVER (ORDER BY construction_cost ASC) as rank FROM flood_control_projects WHERE location = 'Midwest' AND construction_cost BETWEEN 1990 AND 2000 GROUP BY project_name, construction_cost, people_served; |
What is the count of impact investments in South Asia with a value greater than 10000? | CREATE TABLE impact_investments (id INT,value INT,location VARCHAR(50)); INSERT INTO impact_investments (id,value,location) VALUES (1,12000,'South Asia'),(2,7000,'East Asia'),(3,15000,'South Asia'); | SELECT COUNT(*) FROM impact_investments WHERE location = 'South Asia' AND value > 10000; |
How many unique elements were produced in each country in 2020? | CREATE TABLE production (country VARCHAR(255),year INT,element VARCHAR(10),quantity INT); INSERT INTO production (country,year,element,quantity) VALUES ('China',2020,'Nd',120000),('Australia',2020,'Nd',8000),('China',2020,'Pr',130000),('China',2020,'Dy',140000); | SELECT country, COUNT(DISTINCT element) FROM production WHERE year = 2020 GROUP BY country; |
What is the minimum mental health score by community health worker certification level? | CREATE TABLE CertificationLevels (LevelID INT,Level VARCHAR(50)); CREATE TABLE MentalHealthScores (MH_ID INT,LevelID INT,MentalHealthScore INT); INSERT INTO CertificationLevels (LevelID,Level) VALUES (1,'Basic'),(2,'Intermediate'),(3,'Advanced'); INSERT INTO MentalHealthScores (MH_ID,LevelID,MentalHealthScore) VALUES (1,1,70),(2,1,75),(3,2,80),(4,2,85),(5,3,90),(6,3,95); | SELECT c.Level, MIN(mhs.MentalHealthScore) as Min_Score FROM MentalHealthScores mhs JOIN CertificationLevels c ON mhs.LevelID = c.LevelID GROUP BY c.Level; |
What is the minimum amount of funding received by a refugee support organization in the Middle East? | CREATE TABLE funding (id INT,organization VARCHAR(255),region VARCHAR(255),amount DECIMAL(10,2)); | SELECT MIN(amount) FROM funding WHERE region = 'Middle East' AND organization LIKE '%refugee support%'; |
What is the total number of unique countries that have made donations in 2021? | CREATE TABLE Donors (id INT,name TEXT,country TEXT,donation FLOAT,quarter TEXT,year INT); INSERT INTO Donors (id,name,country,donation,quarter,year) VALUES (1,'Charlie','USA',100.0,'Q2',2021),(2,'David','Mexico',150.0,'Q2',2021),(3,'Eve','Canada',75.0,'Q2',2021),(4,'Frank','USA',200.0,'Q3',2021),(5,'Greg','India',50.0,'Q1',2021); | SELECT COUNT(DISTINCT country) FROM Donors WHERE year = 2021; |
What is the average age of patients who have been diagnosed with influenza in the past year, grouped by their ethnicity? | CREATE TABLE Patients (PatientID INT,Age INT,Ethnicity VARCHAR(255),Diagnosis VARCHAR(255)); INSERT INTO Patients (PatientID,Age,Ethnicity,Diagnosis) VALUES (1,35,'Hispanic','Influenza'); CREATE TABLE DiagnosisHistory (PatientID INT,Diagnosis VARCHAR(255),DiagnosisDate DATE); INSERT INTO DiagnosisHistory (PatientID,Diagnosis,DiagnosisDate) VALUES (1,'Influenza','2021-03-15'); | SELECT Ethnicity, AVG(Age) FROM Patients p JOIN DiagnosisHistory dh ON p.PatientID = dh.PatientID WHERE dh.Diagnosis = 'Influenza' AND dh.DiagnosisDate >= DATEADD(year, -1, GETDATE()) GROUP BY Ethnicity; |
Create a view to display state and parity status | CREATE TABLE MentalHealthParity (ID INT PRIMARY KEY,State VARCHAR(2),ParityStatus VARCHAR(10)); CREATE TABLE CulturalCompetency (ID INT PRIMARY KEY,State VARCHAR(2),CompetencyStatus VARCHAR(10)); | CREATE VIEW ParityView AS SELECT State, ParityStatus FROM MentalHealthParity; |
What are the total investment amounts and the associated risk levels for the Water and Sanitation sector investments in African countries? | CREATE TABLE risk_assessments (id INT,investment_id INT,risk_level VARCHAR(255),assessment_date DATE); INSERT INTO risk_assessments (id,investment_id,risk_level,assessment_date) VALUES (1,1,'Low','2022-01-15'),(2,2,'Medium','2022-02-15'); CREATE TABLE impact_investments (id INT,sector VARCHAR(255),project VARCHAR(255),location VARCHAR(255),amount FLOAT); INSERT INTO impact_investments (id,sector,project,location,amount) VALUES (1,'Water and Sanitation','Water Purification Plant','Kenya',2000000.00),(2,'Renewable Energy','Wind Farm Project','Egypt',5000000.00); | SELECT i.sector, SUM(i.amount) as total_amount, r.risk_level FROM impact_investments i INNER JOIN risk_assessments r ON i.id = r.investment_id WHERE i.sector = 'Water and Sanitation' AND i.location LIKE 'Africa%' GROUP BY i.sector, r.risk_level; |
What is the total calorie intake by state? | CREATE TABLE nutrition_data (state VARCHAR(20),calories INT); INSERT INTO nutrition_data (state,calories) VALUES ('California',2000),('Texas',2500),('New York',1800); | SELECT state, SUM(calories) FROM nutrition_data GROUP BY state; |
What is the total healthcare spending in rural Montana? | CREATE TABLE spending (id INT,location VARCHAR(20),amount FLOAT); INSERT INTO spending (id,location,amount) VALUES (1,'rural Montana',5000000); | SELECT SUM(amount) FROM spending WHERE location = 'rural Montana'; |
Insert new records into the Departments table | CREATE TABLE Departments (DepartmentID INT PRIMARY KEY,DepartmentName VARCHAR(50),EmployeesCount INT); | INSERT INTO Departments (DepartmentID, DepartmentName, EmployeesCount) VALUES (1, 'HR', 100), (2, 'IT', 200), (3, 'Finance', 50), (4, 'Marketing', 75), (5, 'Legal', 150), (6, 'Sales', 125), (7, 'Diversity and Inclusion', 5); |
How many autonomous vehicle patents were filed in the last 3 years? | CREATE TABLE patents (patent_id INT,patent_number INT,filing_date DATE,vehicle_id INT); CREATE TABLE vehicles (vehicle_id INT,manufacture VARCHAR(20),has_autonomous_features BOOLEAN); | SELECT COUNT(*) FROM patents p JOIN vehicles v ON p.vehicle_id = v.vehicle_id WHERE has_autonomous_features = TRUE AND p.filing_date >= DATEADD(year, -3, GETDATE()); |
Insert new users and their posts. | CREATE TABLE users (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,content TEXT,created_at TIMESTAMP); CREATE VIEW latest_post AS SELECT posts.user_id,MAX(posts.created_at) AS latest_post FROM posts GROUP BY posts.user_id; | INSERT INTO users (id, name, country) VALUES (1, 'Alice', 'Australia'), (2, 'Bob', 'Canada'); INSERT INTO posts (id, user_id, content, created_at) SELECT NULL, users.id, 'Hello World!', NOW() FROM users WHERE users.id NOT IN (SELECT latest_post.user_id FROM latest_post); |
What is the total number of accessible technology products by company? | CREATE TABLE Accessible_Tech (company VARCHAR(50),product VARCHAR(50)); INSERT INTO Accessible_Tech (company,product) VALUES ('Google','Screen Reader'),('Microsoft','Adaptive Keyboard'),('Apple','Voice Control'),('IBM','Accessibility Checker'); | SELECT company, COUNT(product) FROM Accessible_Tech GROUP BY company; |
What is the average water consumption for producing the top 2 sustainable materials? | CREATE TABLE water_consumption(material VARCHAR(20),water_consumption DECIMAL(5,2)); INSERT INTO water_consumption(material,water_consumption) VALUES('organic cotton',20.00),('recycled polyester',15.00),('hemp',10.00); | SELECT AVG(water_consumption) FROM water_consumption WHERE material IN (SELECT material FROM water_consumption ORDER BY water_consumption LIMIT 2); |
Which cities have adopted electric vehicle charging stations? | CREATE TABLE cities (id INT,name VARCHAR(50)); CREATE TABLE charging_stations (id INT,city_id INT,station_count INT); INSERT INTO cities (id,name) VALUES (1,'San Francisco'),(2,'Los Angeles'),(3,'New York'); INSERT INTO charging_stations (id,city_id,station_count) VALUES (1,1,500),(2,2,700),(3,3,800); | SELECT DISTINCT c.name FROM cities c JOIN charging_stations cs ON c.id = cs.city_id; |
How many confirmed COVID-19 cases were reported in Chicago? | CREATE TABLE covid_cases (id INT,location TEXT,confirmed INT); INSERT INTO covid_cases (id,location,confirmed) VALUES (1,'New York City',500); INSERT INTO covid_cases (id,location,confirmed) VALUES (2,'Chicago',400); | SELECT SUM(confirmed) FROM covid_cases WHERE location = 'Chicago'; |
What is the average flight time for each aircraft type? | CREATE TABLE flights (flight_id INT,aircraft_type VARCHAR(50),flight_time INT); | SELECT aircraft_type, AVG(flight_time) as avg_flight_time FROM flights GROUP BY aircraft_type; |
What is the total number of articles published in each month of the year in the 'investigative_reports' table? | CREATE TABLE investigative_reports (id INT,title VARCHAR(255),author VARCHAR(255),publication_date DATE); | SELECT EXTRACT(MONTH FROM publication_date) as month, COUNT(*) as total_articles FROM investigative_reports GROUP BY month; |
What's the average ESG score for all investments in the Healthcare sector? | CREATE TABLE investments (id INT,sector VARCHAR(20),esg_score FLOAT); INSERT INTO investments (id,sector,esg_score) VALUES (1,'Healthcare',80.5),(2,'Finance',72.3),(3,'Healthcare',84.2); | SELECT AVG(esg_score) FROM investments WHERE sector = 'Healthcare'; |
Delete a research grant record from the "grants" table | CREATE TABLE grants (id INT PRIMARY KEY,title VARCHAR(100),principal_investigator VARCHAR(50),amount NUMERIC,start_date DATE,end_date DATE); | WITH deleted_grant AS (DELETE FROM grants WHERE id = 3 RETURNING *) SELECT * FROM deleted_grant; |
Insert a new record into the "regulations" table with "country" as "Australia", "regulation_name" as "Australian Securities and Investments Commission Act 2001" | CREATE TABLE regulations (country VARCHAR(2),regulation_name VARCHAR(100)); | INSERT INTO regulations (country, regulation_name) VALUES ('AU', 'Australian Securities and Investments Commission Act 2001'); |
How many supplies were received by each facility, tiered by quantity? | CREATE TABLE facility_supplies (id INT,facility_id INT,supply_id INT,supply_quantity INT,received_date DATE); INSERT INTO facility_supplies (id,facility_id,supply_id,supply_quantity,received_date) VALUES (1,1,1,50,'2021-02-03'); INSERT INTO facility_supplies (id,facility_id,supply_id,supply_quantity,received_date) VALUES (2,2,2,75,'2021-02-04'); | SELECT facility_id, NTILE(2) OVER (ORDER BY SUM(supply_quantity) DESC) as tier, SUM(supply_quantity) as total_quantity FROM facility_supplies GROUP BY facility_id; |
Which roads in the 'infrastructure' schema intersect with the road named 'Main Street'? | CREATE TABLE roads (name VARCHAR(255),intersects VARCHAR(255)); INSERT INTO roads (name,intersects) VALUES ('Road1','Main Street'),('Road2','Second Street'),('Road3','Main Street'); | SELECT name FROM roads WHERE intersects = 'Main Street'; |
What is the total amount of funds spent on infrastructure projects in 'StateX' in Q1 and Q2 of 2022? | CREATE TABLE StateX_Infrastructure (Quarter INT,Year INT,Amount FLOAT); INSERT INTO StateX_Infrastructure (Quarter,Year,Amount) VALUES (1,2022,2500000),(2,2022,3000000); | SELECT SUM(Amount) FROM StateX_Infrastructure WHERE Year = 2022 AND Quarter <= 2; |
What is the maximum number of visitors for a museum in Spain? | CREATE TABLE museums (id INT,name TEXT,country TEXT,visitors INT); INSERT INTO museums (id,name,country,visitors) VALUES (1,'Museum A','Spain',25000),(2,'Museum B','Spain',30000),(3,'Museum C','France',22000); | SELECT MAX(visitors) FROM museums WHERE country = 'Spain'; |
_What is the average number of streams for songs in the Pop genre on Spotify, for artists with more than 5 million total streams across all platforms?_ | CREATE TABLE streams (song_id INT,artist_id INT,platform VARCHAR(50),stream_count INT); INSERT INTO streams (song_id,artist_id,platform,stream_count) VALUES (1,1,'Spotify',1000000),(2,2,'Apple Music',2000000); | SELECT AVG(s.stream_count) FROM streams s JOIN artists a ON s.artist_id = a.id WHERE s.platform = 'Spotify' AND a.genre = 'Pop' AND a.total_streams > 5000000; |
What was the minimum carbon price in the US and Mexico in 2019? | CREATE TABLE carbon_prices (id INT,country VARCHAR(255),year INT,carbon_price DECIMAL(5,2)); INSERT INTO carbon_prices (id,country,year,carbon_price) VALUES (1,'US',2019,15.0),(2,'Mexico',2019,10.0); | SELECT MIN(carbon_price) FROM carbon_prices WHERE country IN ('US', 'Mexico') AND year = 2019; |
How many volunteers signed up in each program? | CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,Program TEXT); | SELECT Program, COUNT(*) FROM Volunteers GROUP BY Program; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.