instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Select the names, games, and scores of players who have a higher score than the player with the highest score in game A. | CREATE TABLE Players (PlayerID INT,Name VARCHAR(50),Game VARCHAR(50),Score INT); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (1,'John Doe','GameA',1000); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (2,'Jane Doe','GameB',2000); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (3,'Alice','GameA',1500); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (4,'Bob','GameA',1200); | SELECT Name, Game, Score FROM Players WHERE Game = 'GameA' AND Score > (SELECT MAX(Score) FROM Players WHERE Game = 'GameA'); |
What is the percentage of players who prefer FPS and action genres out of the total number of players? | CREATE TABLE TotalPlayers (PlayerID INT,Genre VARCHAR(10)); INSERT INTO TotalPlayers (PlayerID,Genre) VALUES (1,'FPS'),(2,'Action'),(3,'FPS'),(4,'Action'); | SELECT COUNT(*) * 100.0 / (SELECT COUNT(*) FROM TotalPlayers) FROM TotalPlayers WHERE Genre IN ('FPS', 'Action'); |
Calculate the average precipitation in the 'weather_data_2022' table for wheat fields in France. | CREATE TABLE weather_data_2022 (crop_type VARCHAR(50),location VARCHAR(50),precipitation FLOAT,reading_date DATE); INSERT INTO weather_data_2022 (crop_type,location,precipitation,reading_date) VALUES ('Wheat','France',12.6,'2022-06-01'); INSERT INTO weather_data_2022 (crop_type,location,precipitation,reading_date) VALUES ('Wheat','France',13.2,'2022-06-02'); | SELECT AVG(precipitation) FROM weather_data_2022 WHERE crop_type = 'Wheat' AND location = 'France'; |
What is the average temperature in each country for the month of June, sorted by the highest average temperature? | CREATE TABLE WeatherData (id INT,Country VARCHAR(255),Temperature INT,Timestamp DATETIME); INSERT INTO WeatherData (id,Country,Temperature,Timestamp) VALUES (1,'Mexico',30,'2022-06-01 12:00:00'),(2,'Canada',20,'2022-06-01 12:00:00'); | SELECT Country, AVG(Temperature) as AvgTemp FROM WeatherData WHERE Timestamp BETWEEN '2022-06-01 00:00:00' AND '2022-06-30 23:59:59' GROUP BY Country ORDER BY AvgTemp DESC; |
What was the average budget allocated to public services in District G and H in 2021? | CREATE TABLE Budget (District VARCHAR(10),Year INT,Amount INT); INSERT INTO Budget VALUES ('District G',2021,1500000),('District G',2021,1400000),('District H',2021,1300000),('District H',2021,1200000); | SELECT AVG(Amount) FROM Budget WHERE District IN ('District G', 'District H') AND Year = 2021; |
What is the maximum market price of Terbium in China for 2017? | CREATE TABLE Terbium_Market_Prices (id INT,year INT,country VARCHAR(255),market_price FLOAT); | SELECT MAX(market_price) FROM Terbium_Market_Prices WHERE year = 2017 AND country = 'China'; |
Get the total revenue from sustainable and non-sustainable sources | CREATE TABLE SustainableSourcing (sourcing_id INT,revenue_id INT,is_sustainable BOOLEAN); INSERT INTO SustainableSourcing (sourcing_id,revenue_id,is_sustainable) VALUES (1,1,TRUE); INSERT INTO SustainableSourcing (sourcing_id,revenue_id,is_sustainable) VALUES (2,2,FALSE); | SELECT SUM(CASE WHEN is_sustainable THEN revenue_amount ELSE 0 END) AS sustainable_revenue, SUM(CASE WHEN NOT is_sustainable THEN revenue_amount ELSE 0 END) AS non_sustainable_revenue FROM Revenue JOIN SustainableSourcing ON Revenue.revenue_id = SustainableSourcing.revenue_id; |
Identify the average food safety score for restaurants in the "urban" area. | CREATE TABLE inspections (restaurant_id INT,score INT,area VARCHAR(255));INSERT INTO inspections (restaurant_id,score,area) VALUES (1,95,'urban'),(2,85,'urban'),(3,90,'suburban'),(4,80,'rural'),(5,92,'urban'); | SELECT AVG(inspections.score) FROM inspections WHERE inspections.area = 'urban'; |
What is the maximum revenue generated in a single day from delivery orders? | CREATE TABLE Orders (id INT,order_channel VARCHAR(50),price DECIMAL(10,2),date DATE); CREATE VIEW Delivery_Orders AS SELECT price FROM Orders WHERE order_channel = 'delivery'; | SELECT MAX(SUM(price)) FROM Delivery_Orders GROUP BY date; |
What was the maximum daily revenue for each restaurant in 2022? | CREATE TABLE daily_revenue (restaurant_name TEXT,daily_revenue NUMERIC,date DATE); INSERT INTO daily_revenue (restaurant_name,daily_revenue,date) VALUES ('ABC Bistro',700,'2022-01-01'),('ABC Bistro',800,'2022-01-02'),('XYZ Café',400,'2022-01-01'),('XYZ Café',450,'2022-01-02'); | SELECT restaurant_name, MAX(daily_revenue) as max_daily_revenue FROM daily_revenue GROUP BY restaurant_name; |
What is the total mass of space debris in Medium Earth Orbit (MEO) that was launched before 2010? | CREATE TABLE space_debris(id INT,name VARCHAR(255),launch_date DATE,launch_site VARCHAR(255),orbit VARCHAR(255),mass FLOAT); INSERT INTO space_debris VALUES (1,'Metop-A','2006-10-19','Baikonur Cosmodrome','MEO',4000); INSERT INTO space_debris VALUES (2,'COSMOS 2486','2008-09-26','Plesetsk','MEO',1200); INSERT INTO space_debris VALUES (3,'Galileo IOV-1','2011-10-21','Centre Spatial Guyanais','MEO',670); | SELECT SUM(mass) FROM space_debris WHERE orbit = 'MEO' AND launch_date < '2010-01-01'; |
How many new fans have signed up for the fan club in the last 30 days, sorted by their sign-up date? | CREATE TABLE fan_club_members (id INT,sign_up_date DATE); | SELECT COUNT(*) FROM fan_club_members WHERE sign_up_date >= CURDATE() - INTERVAL 30 DAY ORDER BY sign_up_date; |
How many unique cities have hosted the Olympics in the 'olympics_history' table? | CREATE TABLE olympics_history (edition INT,year INT,city VARCHAR(50),country VARCHAR(50)); | SELECT COUNT(DISTINCT city) FROM olympics_history; |
What is the average ticket price for basketball games in New York? | CREATE TABLE stadiums (name VARCHAR(255),city VARCHAR(255),capacity INT,avg_ticket_price DECIMAL(5,2)); INSERT INTO stadiums (name,city,capacity,avg_ticket_price) VALUES ('Madison Square Garden','New York',20000,150.50); | SELECT avg(avg_ticket_price) FROM stadiums WHERE city = 'New York' AND sport = 'Basketball'; |
Which threat intelligence sources have provided the most false positives in the last quarter? | CREATE TABLE false_positives(id INT,source VARCHAR(50),category VARCHAR(50),date DATE); | SELECT source, COUNT(*) as total_false_positives FROM false_positives WHERE date > DATE(NOW()) - INTERVAL 90 DAY AND category = 'false positive' GROUP BY source; |
List all bike-share stations in New York with more than 20 bikes available. | CREATE TABLE bike_stations (station_id INT,city VARCHAR(20),bikes_available INT); INSERT INTO bike_stations (station_id,city,bikes_available) VALUES (1,'New York',25),(2,'New York',18),(3,'New York',32); | SELECT * FROM bike_stations WHERE city = 'New York' AND bikes_available > 20; |
What is the average speed of high-speed trains in Beijing, China? | CREATE TABLE high_speed_trains (train_id INT,trip_duration INT,start_time TIMESTAMP,end_time TIMESTAMP,start_station TEXT,end_station TEXT,city TEXT,line TEXT); | SELECT AVG(trip_duration / (end_time - start_time)) FROM high_speed_trains WHERE city = 'Beijing' AND line LIKE '%high-speed%'; |
What is the percentage of trips that are multimodal? | CREATE TABLE trips (user_id INT,trip_date DATE,trip_count INT,mode1 VARCHAR(50),mode2 VARCHAR(50)); | SELECT AVG(CASE WHEN mode1 <> mode2 THEN 1 ELSE 0 END) as avg_multimodal FROM trips; |
What is the total number of vehicles sold in 'sales_data' view that have a speed greater than or equal to 80 mph? | CREATE VIEW sales_data AS SELECT id,vehicle_type,avg_speed,sales FROM vehicle_sales WHERE sales > 20000; | SELECT SUM(sales) FROM sales_data WHERE avg_speed >= 80; |
Calculate the average retail sales revenue per 'Jeans' item in Mexico in 2021. | CREATE TABLE RetailSales (id INT,garment_type VARCHAR(20),country VARCHAR(20),revenue DECIMAL(10,2),year INT); INSERT INTO RetailSales (id,garment_type,country,revenue,year) VALUES (1,'Dress','Mexico',75.50,2021),(2,'Shirt','Mexico',120.00,2021),(3,'Pant','Mexico',100.00,2021),(4,'Jacket','Mexico',150.00,2021),(5,'Shirt','Mexico',50.00,2021),(6,'Dress','Mexico',60.00,2021),(7,'Jeans','Mexico',80.00,2021),(8,'Jeans','Mexico',90.00,2021),(9,'Jeans','Mexico',70.00,2021); | SELECT AVG(revenue) as avg_revenue_per_item FROM RetailSales WHERE garment_type = 'Jeans' AND country = 'Mexico' AND year = 2021; |
What was the average sustainability score for the 'Autumn 2021' collection? | CREATE TABLE garment_data_2 (garment_id INT,collection VARCHAR(20),sustainability_score FLOAT); INSERT INTO garment_data_2 (garment_id,collection,sustainability_score) VALUES (1,'Autumn 2019',7.5),(2,'Winter 2019',8.1),(3,'Autumn 2020',8.6),(4,'Winter 2020',8.3),(5,'Autumn 2021',9.1),(6,'Winter 2021',8.9),(7,'Autumn 2022',9.3); | SELECT AVG(sustainability_score) FROM garment_data_2 WHERE collection = 'Autumn 2021'; |
Display policy_id and sum_insured for policies where the sum insured is less than 60000 and policyholder gender is female | CREATE TABLE policy_info (policy_id INT,premium FLOAT,sum_insured INT); CREATE TABLE policyholder (policy_id INT,first_name VARCHAR(50),last_name VARCHAR(50),gender VARCHAR(50)); INSERT INTO policy_info (policy_id,premium,sum_insured) VALUES (1,1200.50,60000),(2,2500.00,70000),(3,1800.00,90000),(4,1500.00,40000),(5,1700.00,50000); INSERT INTO policyholder (policy_id,first_name,last_name,gender) VALUES (1,'Jane','Doe','Female'),(2,'John','Doe','Male'),(3,'Jim','Smith','Male'),(4,'Anna','Johnson','Female'),(5,'David','Lee','Male'); | SELECT policy_info.policy_id, policy_info.sum_insured FROM policy_info INNER JOIN policyholder ON policy_info.policy_id = policyholder.policy_id WHERE policy_info.sum_insured < 60000 AND policyholder.gender = 'Female'; |
Count the number of safety tests passed by vehicles in the 'safety_testing' table | CREATE TABLE safety_testing (id INT PRIMARY KEY,make VARCHAR(50),model VARCHAR(50),year INT,tests_passed INT); | SELECT COUNT(*) FROM safety_testing WHERE tests_passed IS NOT NULL; |
How many autonomous driving research papers were published in the year 2021 in the 'research_papers' table? | CREATE TABLE research_papers (paper_id INT,title VARCHAR(100),author VARCHAR(50),publication_date DATE); | SELECT COUNT(*) FROM research_papers WHERE YEAR(publication_date) = 2021 AND author = 'Wayve'; |
How many 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(*) FROM autonomous_testing WHERE test_result = 'successful'; |
List the vessels that have had safety incidents in the last 12 months, ordered by the number of incidents in descending order. | CREATE TABLE Vessels (vessel_id INT,vessel_name VARCHAR(30)); CREATE TABLE SafetyIncidents (incident_id INT,vessel_id INT,incident_date DATE); INSERT INTO Vessels (vessel_id,vessel_name) VALUES (1,'Ever Given'),(2,'Ever Summit'),(3,'Ever Leader'); INSERT INTO SafetyIncidents (incident_id,vessel_id,incident_date) VALUES (1,1,'2021-03-23'),(2,1,'2021-06-17'),(3,2,'2021-01-15'),(4,2,'2021-04-29'); | SELECT vessel_name, COUNT(*) as incidents FROM SafetyIncidents JOIN Vessels ON SafetyIncidents.vessel_id = Vessels.vessel_id WHERE incident_date >= DATEADD(year, -1, GETDATE()) GROUP BY vessel_name ORDER BY incidents DESC; |
What is the total cargo weight for vessels that arrived in the US between July 2021 and December 2021? | CREATE TABLE vessel_performance (id INT,name TEXT,speed DECIMAL(5,2),arrived_date DATE,country TEXT,cargo_weight INT); INSERT INTO vessel_performance (id,name,speed,arrived_date,country,cargo_weight) VALUES (1,'Vessel A',15.2,'2021-07-05','US',5000),(2,'Vessel B',17.8,'2021-08-10','US',6000),(3,'Vessel C',13.6,'2021-12-18','US',7000); | SELECT SUM(cargo_weight) FROM vessel_performance WHERE arrived_date BETWEEN '2021-07-01' AND '2021-12-31' AND country = 'US'; |
How many circular economy initiatives were implemented in the Latin America region in 2020? | CREATE TABLE circular_economy_initiatives (region VARCHAR(255),year INT,initiative_id INT); INSERT INTO circular_economy_initiatives (region,year,initiative_id) VALUES ('Latin America',2020,1),('Latin America',2020,2),('Latin America',2020,3); | SELECT COUNT(initiative_id) FROM circular_economy_initiatives WHERE region = 'Latin America' AND year = 2020; |
What is the combined landfill capacity for 'City A' and 'City B'? | CREATE TABLE landfill_capacity (city VARCHAR(255),capacity INT); INSERT INTO landfill_capacity (city,capacity) VALUES ('City A',500000),('City B',600000); | SELECT SUM(capacity) FROM (SELECT capacity FROM landfill_capacity WHERE city = 'City A' UNION ALL SELECT capacity FROM landfill_capacity WHERE city = 'City B') AS combined_capacity; |
Find the sensor with the maximum water level in the 'sensor_data' table | CREATE TABLE sensor_data (sensor_id INT,water_level FLOAT,timestamp TIMESTAMP); | SELECT sensor_id, MAX(water_level) as max_water_level FROM sensor_data; |
Find the number of AI ethics issues reported in South America, Central America, and the Caribbean, and provide a breakdown by issue category. | CREATE TABLE ethics_issues (issue_id INT,issue_date DATE,country VARCHAR(255),issue_category VARCHAR(255)); INSERT INTO ethics_issues (issue_id,issue_date,country,issue_category) VALUES (1,'2022-01-01','Colombia','Bias'),(2,'2022-02-01','Brazil','Explainability'),(3,'2022-03-01','Cuba','Transparency'); | SELECT issue_category, COUNT(*) as num_issues FROM ethics_issues WHERE country IN ('South America', 'Central America', 'Caribbean') GROUP BY issue_category; |
Who are the top 3 countries with the most creative AI algorithm explainability issues? | CREATE TABLE creative_ai_algorithm_explainability (issue_id INT PRIMARY KEY,ai_algorithm_id INT,issue_date DATE,country VARCHAR(255)); | SELECT country, COUNT(*) AS issue_count FROM creative_ai_algorithm_explainability GROUP BY country ORDER BY issue_count DESC LIMIT 3; |
What are the names and launch dates of satellites deployed by SpaceTech Inc.? | CREATE TABLE Satellites (satellite_id INT,name VARCHAR(50),launch_date DATE,manufacturer VARCHAR(50)); INSERT INTO Satellites (satellite_id,name,launch_date,manufacturer) VALUES (1,'Sat1','2020-01-01','SpaceTech Inc.'); | SELECT name, launch_date FROM Satellites WHERE manufacturer = 'SpaceTech Inc.'; |
What is the maximum habitat size for any animal in the 'animal_habitat' table? | CREATE TABLE animal_habitat (habitat_id INT,animal_name VARCHAR(50),habitat_size INT); INSERT INTO animal_habitat (habitat_id,animal_name,habitat_size) VALUES (1,'Polar Bear',15000),(2,'Elephant',1000),(3,'Lion',700); | SELECT MAX(habitat_size) FROM animal_habitat; |
What is the gender breakdown of attendees for the 'African Art' event? | CREATE TABLE Events (EventID INT PRIMARY KEY,EventName VARCHAR(255),Attendance INT); CREATE TABLE Audience (AudienceID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),Occupation VARCHAR(255),EventID INT,FOREIGN KEY (EventID) REFERENCES Events(EventID)); INSERT INTO Events (EventID,EventName,Attendance) VALUES (1,'African Art',850); INSERT INTO Audience (AudienceID,Age,Gender,Occupation,EventID) VALUES (1,33,'Female','Art Teacher',1),(2,42,'Male','Art Collector',1),(3,30,'Non-binary','Art Conservator',1),(4,45,'Female','African Art Specialist',1); | SELECT Audience.Gender, COUNT(*) AS Attendance FROM Audience INNER JOIN Events ON Audience.EventID = Events.EventID WHERE Events.EventName = 'African Art' GROUP BY Audience.Gender; |
How many times has music from the United States been streamed in Africa in the last 3 years? | CREATE TABLE music (id INT,title VARCHAR(100),artist_country VARCHAR(50),streams INT); INSERT INTO music (id,title,artist_country,streams) VALUES (1,'MusicA','United States',1000000); INSERT INTO music (id,title,artist_country,streams) VALUES (2,'MusicB','United States',1200000); | SELECT SUM(streams) FROM music WHERE artist_country = 'United States' AND (EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM date(substr(title, 7, 4)))) BETWEEN 1 AND 3; |
Identify the top 2 states with the highest average construction wages in 2020 | CREATE TABLE labor_statistics (state VARCHAR(255),year INTEGER,avg_wage DECIMAL(5,2)); INSERT INTO labor_statistics (state,year,avg_wage) VALUES ('Oregon',2020,26.50),('Oregon',2019,25.75),('Florida',2020,24.25),('Washington',2020,27.50),('California',2020,25.25); | SELECT state, AVG(avg_wage) FROM labor_statistics WHERE year = 2020 GROUP BY state ORDER BY AVG(avg_wage) DESC LIMIT 2; |
What is the average cost of commercial building permits in the state of California for the year 2019? | CREATE TABLE building_permits (permit_type TEXT,state TEXT,cost INTEGER,year INTEGER);INSERT INTO building_permits (permit_type,state,cost,year) VALUES ('Residential','California',200000,2019),('Commercial','California',800000,2019),('Industrial','California',500000,2019); | SELECT AVG(cost) FROM building_permits WHERE state = 'California' AND year = 2019 AND permit_type = 'Commercial'; |
Create a table to store client demographics | CREATE TABLE client_demographics (client_id INT PRIMARY KEY,client_name VARCHAR(255)); | CREATE TABLE client_demographics (client_id INT PRIMARY KEY, client_name VARCHAR(255)); |
Insert a new client named 'Alex Juarez' into the 'clients' table and assign them a unique client_id. | CREATE TABLE clients (client_id INT PRIMARY KEY AUTO_INCREMENT,client_name VARCHAR(255)); | INSERT INTO clients (client_name) VALUES ('Alex Juarez'); |
What is the total billable hours for attorney John Doe? | CREATE TABLE Attorneys (AttorneyID INT,Name VARCHAR(50),Title VARCHAR(50)); INSERT INTO Attorneys (AttorneyID,Name,Title) VALUES (1,'John Doe','Partner'); CREATE TABLE TimeEntries (EntryID INT,AttorneyID INT,Hours DECIMAL(10,2)); INSERT INTO TimeEntries (EntryID,AttorneyID,Hours) VALUES (1,1,5.00),(2,1,7.50); | SELECT SUM(Hours) FROM TimeEntries WHERE AttorneyID = (SELECT AttorneyID FROM Attorneys WHERE Name = 'John Doe'); |
How many healthcare facilities are there in total, by type, in the database? | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO hospitals (id,name,location,type) VALUES (1,'Hospital A','City A','General'); INSERT INTO hospitals (id,name,location,type) VALUES (2,'Hospital B','City B','Pediatric'); CREATE TABLE clinics (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO clinics (id,name,location,type) VALUES (1,'Clinic C','City C','Dental'); INSERT INTO clinics (id,name,location,type) VALUES (2,'Clinic D','City D','General'); CREATE TABLE long_term_care (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO long_term_care (id,name,location,type) VALUES (1,'LT Care A','City A','Nursing'); INSERT INTO long_term_care (id,name,location,type) VALUES (2,'LT Care B','City B','Assisted Living'); | SELECT type, COUNT(*) FROM hospitals GROUP BY type UNION SELECT type, COUNT(*) FROM clinics GROUP BY type UNION SELECT type, COUNT(*) FROM long_term_care GROUP BY type; |
What is the average age of patients who received a flu shot in 2020, grouped by their gender? | CREATE TABLE patients (id INT,gender VARCHAR(10),age INT,flu_shot BOOLEAN,shot_date DATE); INSERT INTO patients (id,gender,age,flu_shot,shot_date) VALUES (1,'Male',45,true,'2020-02-01'); INSERT INTO patients (id,gender,age,flu_shot,shot_date) VALUES (2,'Female',50,false,NULL); INSERT INTO patients (id,gender,age,flu_shot,shot_date) VALUES (3,'Non-binary',30,true,'2020-03-15'); | SELECT AVG(age) as avg_age, gender FROM patients WHERE flu_shot = true AND YEAR(shot_date) = 2020 GROUP BY gender; |
What is the number of cancer screenings performed, by gender? | CREATE TABLE cancer_screenings (gender VARCHAR(6),num_screenings INT); INSERT INTO cancer_screenings (gender,num_screenings) VALUES ('Male',120000),('Female',180000); | SELECT gender, SUM(num_screenings) as total_screenings FROM cancer_screenings GROUP BY gender; |
What is the total number of organic farms in the 'farm_data' table, grouped by country? | CREATE TABLE farm_data (farm_id INT,farm_name VARCHAR(255),country VARCHAR(255),is_organic BOOLEAN); INSERT INTO farm_data (farm_id,farm_name,country,is_organic) VALUES (1,'Farm1','CountryA',true),(2,'Farm2','CountryB',false),(3,'Farm3','CountryA',true),(4,'Farm4','CountryC',true); | SELECT country, COUNT(*) as total_organic_farms FROM farm_data WHERE is_organic = true GROUP BY country; |
What is the total production (in metric tons) of organic crops in Europe, broken down by crop type? | CREATE TABLE organic_crops (crop_id INT,crop_name TEXT,country TEXT,production_tons FLOAT); INSERT INTO organic_crops (crop_id,crop_name,country,production_tons) VALUES (1,'Wheat','France',1500.0),(2,'Barley','Germany',1200.0),(3,'Corn','Italy',2000.0); | SELECT crop_name, SUM(production_tons) FROM organic_crops WHERE country = 'Europe' GROUP BY crop_name; |
Which smart contracts have a transaction count greater than 1000 and were deployed in the last 30 days? | CREATE TABLE smart_contracts (contract_address VARCHAR(42),deployment_date DATE); INSERT INTO smart_contracts (contract_address,deployment_date) VALUES ('0x123','2022-01-01'),('0x456','2022-01-15'),('0x789','2022-02-01'); CREATE TABLE transactions (contract_address VARCHAR(42),transaction_date DATE); INSERT INTO transactions (contract_address,transaction_date) VALUES ('0x123','2022-01-01'),('0x123','2022-01-02'),('0x456','2022-01-16'),('0x456','2022-01-17'),('0x789','2022-02-01'),('0x789','2022-02-02'); | SELECT contract_address FROM smart_contracts s JOIN transactions t ON s.contract_address = t.contract_address WHERE s.deployment_date >= DATEADD(day, -30, CURRENT_DATE) GROUP BY contract_address HAVING COUNT(*) > 1000; |
Who is the top token holder for a specific digital asset? | CREATE TABLE token_holders (holder_id INT,address VARCHAR(42),asset_id INT,balance DECIMAL(20,2)); | SELECT ah.address, SUM(th.balance) FROM token_holders th JOIN digital_assets da ON th.asset_id = da.asset_id GROUP BY ah.address ORDER BY SUM(th.balance) DESC LIMIT 1; |
Calculate the total quantity of products sold and group by supplier name, for products in the "Haircare" category. | CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2)); CREATE TABLE sales (id INT PRIMARY KEY,product_id INT,supplier_id INT,quantity INT,date DATE); CREATE VIEW sales_per_product AS SELECT sales.product_id,products.name,products.category,SUM(sales.quantity) as quantity_sold FROM sales JOIN products ON sales.product_id = products.id GROUP BY sales.product_id,products.name,products.category,sales.supplier_id; | SELECT sales_per_product.category as product_category, supplier_id, SUM(quantity_sold) as total_quantity_sold FROM sales_per_product WHERE product_category = 'Haircare' GROUP BY product_category, supplier_id; |
List all products that are both vegan and cruelty-free, ordered by name in ascending order. | CREATE TABLE products (product_id INT,name VARCHAR(255),category VARCHAR(255),vegan BOOLEAN,cruelty_free BOOLEAN); | SELECT * FROM products WHERE vegan = TRUE AND cruelty_free = TRUE ORDER BY name ASC; |
Which countries produce cruelty-free skincare products and how many are there? | CREATE TABLE cruelty_free_products (country VARCHAR(255),cruelty_free BOOLEAN,product_count INTEGER); INSERT INTO cruelty_free_products (country,cruelty_free,product_count) VALUES ('France',true,2000),('USA',false,3000),('Canada',true,1000),('Australia',true,1500); | SELECT country, SUM(product_count) as total_products FROM cruelty_free_products WHERE cruelty_free = true GROUP BY country; |
How many emergency response vehicles are stationed in each borough? | CREATE TABLE borough (id INT,name TEXT); INSERT INTO borough (id,name) VALUES (1,'Brooklyn'); INSERT INTO borough (id,name) VALUES (2,'Queens'); CREATE TABLE stations (id INT,borough_id INT,num_vehicles INT); INSERT INTO stations (id,borough_id,num_vehicles) VALUES (1,1,12); INSERT INTO stations (id,borough_id,num_vehicles) VALUES (2,2,15); | SELECT b.name, s.num_vehicles FROM stations s JOIN borough b ON s.borough_id = b.id; |
What is the average response time for emergency calls in CityA, grouped by incident type? | CREATE TABLE EmergencyCalls (CallID INT,City VARCHAR(50),IncidentType VARCHAR(50),ResponseTime INT); INSERT INTO EmergencyCalls VALUES (1,'CityA','Fire',8),(2,'CityA','Medical',12); CREATE TABLE IncidentTypes (IncidentType VARCHAR(50),TypeDescription VARCHAR(50)); INSERT INTO IncidentTypes VALUES ('Fire','Building Fire'),('Medical','Medical Emergency'); | SELECT IncidentType, AVG(ResponseTime) FROM EmergencyCalls EC INNER JOIN IncidentTypes IT ON EC.IncidentType = IT.IncidentType WHERE City = 'CityA' GROUP BY IncidentType; |
What is the count of incidents for each type at each location, and what is the percentage of the total count for each location? | CREATE TABLE incidents(id INT,location VARCHAR(255),type VARCHAR(255),timestamp TIMESTAMP); | SELECT location, type, COUNT(*) as incident_count, incident_count * 100.0 / SUM(COUNT(*)) OVER (PARTITION BY location) as percentage FROM incidents GROUP BY location, type; |
What is the maximum and minimum response time for fire departments in each city in the state of Ohio? | CREATE TABLE fire_department_oh (id INT,city VARCHAR(255),response_time INT); | SELECT city, MIN(response_time) as min_response_time, MAX(response_time) as max_response_time FROM fire_department_oh GROUP BY city; |
Which defense agency has the highest total contract value in Texas? | CREATE TABLE Agency_Contracts (Agency VARCHAR(255),Contract_Value INT,State VARCHAR(255)); INSERT INTO Agency_Contracts (Agency,Contract_Value,State) VALUES ('DOD',1000000,'Texas'),('DOJ',1500000,'Texas'),('DOD',1200000,'California'),('CIA',800000,'Texas'); | SELECT Agency, SUM(Contract_Value) as Total_Contract_Value FROM Agency_Contracts WHERE State = 'Texas' GROUP BY Agency ORDER BY Total_Contract_Value DESC; |
Delete all records in the 'equipment' table where the 'type' is 'ground' | CREATE TABLE equipment (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(20)); INSERT INTO equipment (id,name,type) VALUES (1,'M1 Abrams','ground'),(2,'F-15 Eagle','air'),(3,'Los Angeles','sea'); | DELETE FROM equipment WHERE type = 'ground'; |
List all transactions involving customers from the US in February 2022. | CREATE TABLE customers (customer_id INT,customer_name TEXT,country TEXT); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_date DATE); | SELECT t.transaction_id, c.customer_name, c.country, t.transaction_date FROM transactions t JOIN customers c ON t.customer_id = c.customer_id WHERE c.country = 'US' AND t.transaction_date BETWEEN '2022-02-01' AND '2022-02-28'; |
Which customers have made a transaction over 500 in the "risk_management" category? | CREATE TABLE customers (id INT,name VARCHAR(50),category VARCHAR(50)); INSERT INTO customers (id,name,category) VALUES (1,'John Doe','risk_management'); INSERT INTO customers (id,name,category) VALUES (2,'Jane Smith','compliance'); INSERT INTO customers (id,name,category) VALUES (3,'Jim Brown','risk_management'); CREATE TABLE transactions (id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (id,customer_id,amount) VALUES (1,1,500.00); INSERT INTO transactions (id,customer_id,amount) VALUES (2,1,200.00); INSERT INTO transactions (id,customer_id,amount) VALUES (3,2,100.00); INSERT INTO transactions (id,customer_id,amount) VALUES (4,3,750.00); | SELECT c.name FROM customers c INNER JOIN transactions t ON c.id = t.customer_id WHERE c.category = 'risk_management' AND t.amount > 500; |
Update the max_capacity of a vessel | fleet(vessel_id,vessel_name,max_capacity,build_year,type,flag) | UPDATE fleet SET max_capacity = 13000 WHERE vessel_id = 3002; |
What is the average salary for workers in the renewable energy sector in the US and Canada? | CREATE TABLE worker_salaries (employee_id INT,country VARCHAR(50),sector VARCHAR(50),salary FLOAT); | SELECT AVG(salary) FROM worker_salaries WHERE country IN ('USA', 'Canada') AND sector = 'Renewable Energy'; |
Which excavation sites have more than 10 artifacts? | CREATE TABLE ExcavationSite (SiteID INT,SiteName VARCHAR(50)); INSERT INTO ExcavationSite (SiteID,SiteName) VALUES (1,'Site A'),(2,'Site B'),(3,'Site C'); CREATE TABLE Artifact (ArtifactID INT,SiteID INT,ObjectType VARCHAR(50)); INSERT INTO Artifact (ArtifactID,SiteID,ObjectType) VALUES (1,1,'Pottery'),(2,1,'Tool'),(3,2,'Statue'),(4,2,'Bead'),(5,3,'Bead'),(6,3,'Bead'),(7,3,'Bead'),(8,3,'Bead'),(9,3,'Bead'),(10,3,'Bead'),(11,3,'Bead'); | SELECT e.SiteName FROM ExcavationSite e JOIN Artifact a ON e.SiteID = a.SiteID GROUP BY e.SiteName HAVING COUNT(a.ArtifactID) > 10; |
What is the total revenue of rural hospitals that have a trauma center? | CREATE TABLE hospitals (id INT,location VARCHAR(20),trauma_center BOOLEAN,revenue INT); INSERT INTO hospitals (id,location,trauma_center,revenue) VALUES (1,'rural',TRUE,1000000); | SELECT SUM(revenue) FROM hospitals WHERE location = 'rural' AND trauma_center = TRUE; |
List the intelligence operations and their corresponding threat levels, and rank them based on their threat level and budget. | CREATE TABLE intel_ops_threat (id INT,operation VARCHAR,threat VARCHAR,budget INT); INSERT INTO intel_ops_threat (id,operation,threat,budget) VALUES (1,'Operation Red Folder','High',5000000),(2,'Operation Black Vault','Medium',7000000),(3,'Operation Blue Sail','Low',6000000); | SELECT operation, threat, budget, ROW_NUMBER() OVER (PARTITION BY threat ORDER BY budget DESC) as rank FROM intel_ops_threat; |
What is the diversity ratio (percentage of non-male employees) in each department? | CREATE TABLE Employees (EmployeeID int,Department varchar(20),Gender varchar(10)); INSERT INTO Employees (EmployeeID,Department,Gender) VALUES (1,'Marketing','Male'); INSERT INTO Employees (EmployeeID,Department,Gender) VALUES (2,'Marketing','Female'); INSERT INTO Employees (EmployeeID,Department,Gender) VALUES (3,'IT','Male'); INSERT INTO Employees (EmployeeID,Department,Gender) VALUES (4,'IT','Non-binary'); | SELECT Department, (COUNT(CASE WHEN Gender <> 'Male' THEN 1 END) / COUNT(*)) * 100 AS DiversityRatio FROM Employees GROUP BY Department; |
Find the number of energy efficiency policies in countries with more than 20 GW of solar capacity | CREATE TABLE energy_efficiency (id INT,name TEXT,country TEXT); INSERT INTO energy_efficiency (id,name,country) VALUES (1,'Energy Efficiency Standard','Germany'); INSERT INTO energy_efficiency (id,name,country) VALUES (2,'Energy Conservation Act','India'); INSERT INTO energy_efficiency (id,name,country) VALUES (3,'Energy Efficiency Resource Standard','US'); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (4,'Solar','India',30); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (5,'Solar','US',60); | SELECT COUNT(*) FROM energy_efficiency WHERE country IN (SELECT country FROM renewable_sources WHERE name = 'Solar' AND capacity > 20); |
What is the total installed capacity of hydroelectric power plants in Brazil and Canada? | CREATE TABLE hydroelectric_power (country TEXT,capacity INTEGER); INSERT INTO hydroelectric_power (country,capacity) VALUES ('Brazil',104000),('Canada',78000),('China',350000),('United States',100000),('Russia',45000); | (SELECT capacity FROM hydroelectric_power WHERE country = 'Brazil') UNION (SELECT capacity FROM hydroelectric_power WHERE country = 'Canada'); |
What is the total number of points scored by each team in the NBA this season? | CREATE TABLE nba_teams (team_name TEXT,points_scored INT); INSERT INTO nba_teams (team_name,points_scored) VALUES ('Cavaliers',8000),('Warriors',8500),('Celtics',7500); | SELECT team_name, SUM(points_scored) FROM nba_teams GROUP BY team_name; |
What is the average amount of donations given by donors from the United States, per transaction, for the year 2020? | CREATE TABLE donors (donor_id INT,donor_name VARCHAR(50),donor_country VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (donor_id,donor_name,donor_country,donation_amount,donation_date) VALUES (1,'John Doe','USA',50.00,'2020-01-01'); | SELECT AVG(donation_amount) FROM donors WHERE donor_country = 'USA' AND YEAR(donation_date) = 2020; |
Which organizations focus on ethical AI in each continent? | CREATE TABLE ethics_by_continent (continent VARCHAR(50),name VARCHAR(50),focus VARCHAR(50)); INSERT INTO ethics_by_continent (continent,name,focus) VALUES ('Asia','Ethics Asia','Ethical AI'),('Africa','AI for Good','Ethical AI'); | SELECT continent, name FROM ethics_by_continent WHERE focus = 'Ethical AI'; |
Find the daily ridership for a specific train line | CREATE TABLE train_trip (trip_id INT,trip_date DATE,line_name VARCHAR(50),num_passengers INT); | SELECT trip_date, SUM(num_passengers) AS daily_ridership FROM train_trip WHERE line_name = 'Red Line' GROUP BY trip_date; |
What is the average distance and frequency for routes with a distance greater than 7 km and a frequency of at least 120? | CREATE TABLE route (route_id INT,start_station VARCHAR(255),end_station VARCHAR(255),distance FLOAT,frequency INT); INSERT INTO route (route_id,start_station,end_station,distance,frequency) VALUES (3,'Station C','Station D',7.2,120); INSERT INTO route (route_id,start_station,end_station,distance,frequency) VALUES (4,'Station D','Station E',6.5,100); | SELECT route_id, AVG(distance) as avg_distance, AVG(frequency) as avg_frequency FROM route WHERE distance > 7 AND frequency >= 120 GROUP BY route_id; |
Update the 'GOTS' status of all manufacturers in the 'Africa' region to 'Yes'. | CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50),Region VARCHAR(50),GOTS VARCHAR(5)); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName,Region,GOTS) VALUES (1,'EcoFriendlyFabrics','Europe','No'),(2,'GreenYarns','Asia','No'),(3,'SustainableTextiles','Africa','No'),(4,'EcoWeaves','Europe','Yes'); | UPDATE Manufacturers SET GOTS = 'Yes' WHERE Region = 'Africa'; |
What is the total quantity of materials used by each producer in the 'ethical_materials' table? | CREATE TABLE ethical_materials (id INT,producer VARCHAR(20),material VARCHAR(20),quantity INT); INSERT INTO ethical_materials (id,producer,material,quantity) VALUES (1,'EcoFabrics','cotton',8000),(2,'GreenYarn','wool',5000),(3,'EcoFabrics','polyester',3000),(4,'GreenYarn','cotton',6000),(5,'SustainaFiber','silk',9000); | SELECT producer, SUM(quantity) AS total_quantity FROM ethical_materials GROUP BY producer; |
What is the minimum sustainability score for each textile material? | CREATE TABLE TextileSources (SourceID INT,Country VARCHAR(255),Material VARCHAR(255),SustainabilityScore INT); INSERT INTO TextileSources (SourceID,Country,Material,SustainabilityScore) VALUES (1,'India','Cotton',85),(2,'Brazil','Rayon',70),(3,'USA','Hemp',90),(4,'China','Polyester',60); | SELECT Material, MIN(SustainabilityScore) AS MinSustainabilityScore FROM TextileSources GROUP BY Material; |
How many clients have taken out socially responsible loans in each country? | CREATE TABLE socially_responsible_loans(client_id INT,country VARCHAR(25));INSERT INTO socially_responsible_loans(client_id,country) VALUES (1,'Malaysia'),(2,'UAE'),(3,'Indonesia'),(4,'Saudi Arabia'),(5,'Malaysia'),(6,'UAE'); | SELECT country, COUNT(DISTINCT client_id) as num_clients FROM socially_responsible_loans GROUP BY country; |
What is the total amount of Shariah-compliant loans issued by each financial institution in Oceania? | CREATE TABLE financial_institutions (institution_id INT,institution_name TEXT); INSERT INTO financial_institutions (institution_id,institution_name) VALUES (1,'Islamic Bank Oceania'),(2,'Al Baraka Bank Oceania'),(3,'Islamic Finance House Oceania'); CREATE TABLE loans (loan_id INT,institution_id INT,loan_type TEXT,amount FLOAT); INSERT INTO loans (loan_id,institution_id,loan_type,amount) VALUES (1,1,'Shariah-compliant',5000),(2,1,'conventional',7000),(3,2,'Shariah-compliant',4000),(4,2,'Shariah-compliant',6000),(5,3,'conventional',8000); | SELECT institution_id, SUM(amount) FROM loans WHERE loan_type = 'Shariah-compliant' AND institution_id IN (SELECT institution_id FROM financial_institutions WHERE institution_name LIKE '%Oceania%') GROUP BY institution_id; |
What is the total income of clients in Canada who are socially responsible investors? | CREATE TABLE clients (client_id INT,name VARCHAR(100),age INT,country VARCHAR(50),income DECIMAL(10,2),is_socially_responsible_investor BOOLEAN); INSERT INTO clients (client_id,name,age,country,income,is_socially_responsible_investor) VALUES (12,'Emily Chen',40,'Canada',80000,true); | SELECT SUM(income) FROM clients WHERE country = 'Canada' AND is_socially_responsible_investor = true; |
Find the number of donations made by first-time donors in the last quarter. | CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationType TEXT,DonationAmount FLOAT); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationType,DonationAmount) VALUES (1,1,'2021-01-01','Individual',100),(2,2,'2021-02-01','Corporate',5000); | SELECT COUNT(*) FROM (SELECT DonationID FROM Donations WHERE DonationType = 'Individual' AND DonationDate >= DATEADD(quarter, -1, CURRENT_DATE) EXCEPT SELECT DonationID FROM PreviousDonations) AS FirstTimeDonors; |
How many volunteers helped in the education programs in 2021? | CREATE TABLE volunteers (id INT,name TEXT,program TEXT,hours FLOAT,volunteer_date DATE); INSERT INTO volunteers (id,name,program,hours,volunteer_date) VALUES (1,'Jim Brown','Education',5,'2021-02-03'); INSERT INTO volunteers (id,name,program,hours,volunteer_date) VALUES (2,'Karen Green','Health',3,'2021-06-15'); | SELECT COUNT(*) FROM volunteers WHERE program = 'Education' AND volunteer_date BETWEEN '2021-01-01' AND '2021-12-31'; |
What is the total donation amount by each program in Q1 2022? | CREATE TABLE program (pid INT,pname VARCHAR(255)); INSERT INTO program (pid,pname) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donation (did INT,pid INT,donation_date DATE,amount DECIMAL(10,2)); INSERT INTO donation (did,pid,donation_date,amount) VALUES (1,1,'2022-01-05',500),(2,2,'2022-01-10',750),(3,3,'2022-03-20',600); | SELECT p.pname, SUM(d.amount) as total_donation FROM donation d JOIN program p ON d.pid = p.pid WHERE d.donation_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY p.pname; |
Which programs have the highest and lowest average donation amounts? | CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,DonationAmount DECIMAL(10,2)); INSERT INTO Programs (ProgramID,ProgramName,DonationAmount) VALUES (1,'Education',500.00),(2,'Healthcare',250.00); | SELECT ProgramName, AVG(DonationAmount) AS AvgDonation FROM Programs GROUP BY ProgramName ORDER BY AvgDonation DESC, ProgramName ASC; |
Delete all records with a best-before date earlier than tomorrow from the FoodSafetyRecords.PerishableGoods table. | CREATE TABLE FoodSafetyRecords.PerishableGoods (itemName TEXT,bestBeforeDate DATE); | DELETE FROM FoodSafetyRecords.PerishableGoods WHERE bestBeforeDate < DATEADD(day, 1, CURDATE()); |
Insert new food safety records for locations "A123", "B456", and "C789" | CREATE TABLE food_safety_records (id INT,location VARCHAR(255),inspection_date DATE,violation_count INT); | INSERT INTO food_safety_records (location, inspection_date, violation_count) VALUES ('A123', '2022-03-01', 0), ('B456', '2022-03-05', 2), ('C789', '2022-03-10', 1); |
What is the percentage of meals that meet the daily recommended nutrient intake for customers in Indonesia? | CREATE TABLE meals (id INT,customer_id INT,calories INT,daily_recommended_intake INT); INSERT INTO meals (id,customer_id,calories,daily_recommended_intake) VALUES (1,1,1000,2200),(2,1,700,2200),(3,2,800,2300); CREATE TABLE customers (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO customers (id,name,country) VALUES (1,'Budi Santosa','Indonesia'),(2,'Dewi Sartika','Indonesia'); | SELECT (COUNT(*) FILTER (WHERE meals.calories >= (meals.daily_recommended_intake * 0.8))) * 100.0 / COUNT(*) AS percentage FROM meals JOIN customers ON meals.customer_id = customers.id WHERE customers.country = 'Indonesia'; |
How many shipments were handled by each warehouse in the first quarter of 2021? | CREATE TABLE Warehouse (id INT,country VARCHAR(255),city VARCHAR(255),opened_date DATE); INSERT INTO Warehouse (id,country,city,opened_date) VALUES (1,'Germany','Frankfurt','2019-01-01'),(2,'France','Lyon','2020-01-01'); CREATE TABLE Shipments (id INT,warehouse_id INT,shipped_date DATE); | SELECT w.country, w.city, COUNT(s.id) AS shipment_count FROM Warehouse w JOIN Shipments s ON w.id = s.warehouse_id WHERE s.shipped_date >= '2021-01-01' AND s.shipped_date < '2021-04-01' GROUP BY w.id; |
What is the average delivery time for ground freight from 'Toronto' to 'Montreal'? | CREATE TABLE ground_freight_routes (route_id INT,origin VARCHAR(255),destination VARCHAR(255),transit_time INT); INSERT INTO ground_freight_routes (route_id,origin,destination,transit_time) VALUES (1,'Toronto','Montreal',7),(2,'Toronto','New York',12),(3,'Montreal','Boston',8); | SELECT AVG(transit_time) FROM ground_freight_routes WHERE origin = 'Toronto' AND destination = 'Montreal'; |
How many biosensors have been developed in each country? | CREATE TABLE biosensors(id INT,name VARCHAR(50),country VARCHAR(50),development_date DATE);INSERT INTO biosensors (id,name,country,development_date) VALUES (1,'BioSensorA','USA','2021-03-01');INSERT INTO biosensors (id,name,country,development_date) VALUES (2,'BioSensorB','Canada','2020-12-10');INSERT INTO biosensors (id,name,country,development_date) VALUES (3,'BioSensorC','USA','2019-09-25'); | SELECT country, COUNT(*) AS biosensors_per_country FROM biosensors GROUP BY country ORDER BY biosensors_per_country DESC; |
Insert a new record in the 'Research_Grants' table with the following details: Grant_ID = 30, Grant_Title = 'Artificial Intelligence for Healthcare', Start_Date = '2023-01-01', End_Date = '2025-12-31', Grant_Amount = 1200000, Grant_Status = 'Active | CREATE TABLE Research_Grants (Grant_ID INT,Grant_Title VARCHAR(100),Start_Date DATE,End_Date DATE,Grant_Amount DECIMAL(10,2),Grant_Status VARCHAR(20)); | INSERT INTO Research_Grants (Grant_ID, Grant_Title, Start_Date, End_Date, Grant_Amount, Grant_Status) VALUES (30, 'Artificial Intelligence for Healthcare', '2023-01-01', '2025-12-31', 1200000, 'Active'); |
What is the number of smart city initiatives implemented in each country? | CREATE TABLE smart_city_initiatives (initiative_id INT,country VARCHAR(50),city VARCHAR(100),status VARCHAR(50)); INSERT INTO smart_city_initiatives (initiative_id,country,city,status) VALUES (1,'France','Paris','Implemented'); | SELECT country, COUNT(*) as implemented_initiatives FROM smart_city_initiatives WHERE status = 'Implemented' GROUP BY country; |
What is the average rating of historical sites in Egypt? | CREATE TABLE site_ratings(site_id INT,rating FLOAT); INSERT INTO site_ratings (site_id,rating) VALUES (1,4.5),(2,4.7); CREATE TABLE site_info(site_id INT,name TEXT,country TEXT); INSERT INTO site_info (site_id,name,country) VALUES (1,'Historic Site','Egypt'),(2,'Modern Building','Egypt'); | SELECT AVG(rating) FROM site_info si INNER JOIN site_ratings sr ON si.site_id = sr.site_id WHERE si.country = 'Egypt' AND sr.rating IS NOT NULL; |
What is the engagement rate of virtual tours in European hotels? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT); INSERT INTO hotels (hotel_id,hotel_name,country) VALUES (1,'Hotel A','France'),(2,'Hotel B','Germany'),(3,'Hotel C','Italy'),(4,'Hotel D','Spain'); CREATE TABLE virtual_tours (hotel_id INT,tour_name TEXT,views INT); INSERT INTO virtual_tours (hotel_id,tour_name,views) VALUES (1,'Tour A',100),(2,'Tour B',200),(3,'Tour C',300),(4,'Tour D',400),(5,'Tour E',500); | SELECT country, AVG(views / (SELECT SUM(views) FROM virtual_tours WHERE hotel_id = hotels.hotel_id) * 100) as engagement_rate FROM hotels INNER JOIN virtual_tours ON hotels.hotel_id = virtual_tours.hotel_id GROUP BY country; |
Count the number of French Impressionist paintings in the collection. | CREATE TABLE art_collection (id INT,art_name VARCHAR(50),artist_name VARCHAR(50),style VARCHAR(50)); | SELECT COUNT(*) as impressionist_count FROM art_collection WHERE artist_name = 'French' AND style = 'Impressionism'; |
What is the average price of paintings from African artists in our collection? | CREATE TABLE Artworks (id INT,title VARCHAR(50),price DECIMAL(10,2),medium VARCHAR(50),artist_nationality VARCHAR(50)); CREATE TABLE Collections (id INT,name VARCHAR(50),continent VARCHAR(50)); | SELECT AVG(Artworks.price) FROM Artworks INNER JOIN Collections ON Artworks.artist_nationality = Collections.continent WHERE Artworks.medium = 'Painting' AND Collections.continent = 'Africa'; |
What is the total value of surrealist art pieces? | CREATE TABLE ArtPieces (id INT,title VARCHAR(50),galleryId INT,year INT,value INT,style VARCHAR(20)); INSERT INTO ArtPieces (id,title,galleryId,year,value,style) VALUES (1,'Piece 1',1,2000,10000,'Impressionism'),(2,'Piece 2',1,2010,15000,'Surrealism'),(3,'Piece 3',2,2020,20000,'Cubism'),(4,'Piece 4',3,1990,5000,'Surrealism'),(5,'Piece 5',NULL,1874,25000,'Impressionism'); | SELECT SUM(value) FROM ArtPieces WHERE style = 'Surrealism'; |
Calculate the average number of bridges constructed per year in the Pacific Northwest, and the total bridge construction cost for each year since 2000. | CREATE TABLE bridge_projects (id INT,project_name VARCHAR(255),location VARCHAR(255),construction_year INT,length FLOAT,cost INT); INSERT INTO bridge_projects (id,project_name,location,construction_year,length,cost) VALUES (1,'I-5 Bridge Replacement','Pacific Northwest',2002,2.5,12000000),(2,'Highway 101 Bridge Construction','Pacific Northwest',2005,1.8,8000000),(3,'I-405 Bridge Rehabilitation','Pacific Northwest',2010,3.2,15000000); | SELECT construction_year, AVG(length) AS avg_bridges_per_year, SUM(cost) AS total_cost FROM bridge_projects WHERE location = 'Pacific Northwest' AND construction_year >= 2000 GROUP BY construction_year; |
What are the names and types of bridges in California? | CREATE TABLE Bridges (Name VARCHAR(255),Type VARCHAR(255),State VARCHAR(255)); INSERT INTO Bridges (Name,Type,State) VALUES ('Golden Gate','Suspension','California'); | SELECT Name, Type FROM Bridges WHERE State = 'California'; |
What is the average budget for all projects in the infrastructure development database? | CREATE TABLE if not exists Projects (id INT,name VARCHAR(50),type VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO Projects (id,name,type,budget) VALUES (1,'Seawall','Resilience',5000000.00),(2,'Floodgate','Resilience',3000000.00),(3,'Bridge','Transportation',8000000.00),(4,'Highway','Transportation',12000000.00); | SELECT AVG(budget) FROM Projects; |
How many sustainable tourism initiatives are there in total and how many are there in each continent? | CREATE TABLE Sustainable_Initiatives_Global (id INT,name VARCHAR(50),location VARCHAR(50),continent VARCHAR(50)); INSERT INTO Sustainable_Initiatives_Global (id,name,location,continent) VALUES (1,'Green Safari','Africa','Africa'),(2,'Eco-Lodge Project','Africa','Africa'),(3,'Sustainable Beach Resort','Americas','Americas'),(4,'Community-Based Tourism','Asia','Asia'),(5,'Island Conservation Project','Australia','Australia'),(6,'Glacier Preservation Initiative','Antarctica','Antarctica'); | SELECT continent, COUNT(*) as num_initiatives FROM Sustainable_Initiatives_Global GROUP BY continent; SELECT COUNT(*) as total_initiatives FROM Sustainable_Initiatives_Global; |
What is the percentage change in the number of tourists visiting Japan from India between March and April? | CREATE TABLE tourism (date DATE,host_country VARCHAR(50),visitor_country VARCHAR(50),number_of_tourists INT); INSERT INTO tourism (date,host_country,visitor_country,number_of_tourists) VALUES ('2022-03-01','Japan','India',10000),('2022-04-01','Japan','India',12000); | SELECT (SUM(number_of_tourists) - LAG(SUM(number_of_tourists)) OVER (PARTITION BY visitor_country ORDER BY date)) / LAG(SUM(number_of_tourists)) OVER (PARTITION BY visitor_country ORDER BY date) * 100.0 as percentage_change FROM tourism WHERE host_country = 'Japan' AND visitor_country = 'India'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.