instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the count of community policing events for each type at each location, and what is the percentage of the total count for each location? | CREATE TABLE community_policing(id INT,location VARCHAR(255),event_type VARCHAR(255),timestamp TIMESTAMP); | SELECT location, event_type, COUNT(*) as event_count, event_count * 100.0 / SUM(COUNT(*)) OVER (PARTITION BY location) as percentage FROM community_policing GROUP BY location, event_type; |
What is the average number of streams per day for 'WAP' by Cardi B and Megan Thee Stallion? | CREATE TABLE SongStreams (id INT,song VARCHAR(50),streams INT,date DATE); INSERT INTO SongStreams (id,song,streams,date) VALUES (1,'WAP',150000,'2022-01-01'),(2,'WAP',160000,'2022-01-02'); | SELECT AVG(streams/2) FROM SongStreams WHERE song = 'WAP'; |
Find the difference in average CO2 emission per capita between 2019 and 2020 for each continent. | CREATE TABLE EmissionsData (Continent VARCHAR(50),Year INT,CO2Emission DECIMAL(5,2),Population INT); INSERT INTO EmissionsData (Continent,Year,CO2Emission,Population) VALUES ('Asia',2020,5.3,4600000000),('Asia',2019,4.6,4580000000),('Africa',2020,2.1,1300000000),('Africa',2019,1.8,1280000000); | SELECT Continent, AVG(CO2Emission/Population) - LAG(AVG(CO2Emission/Population)) OVER (PARTITION BY Continent ORDER BY Year) as CO2PerCapitaDifference FROM EmissionsData GROUP BY Continent, Year; |
Insert a new record for a mine | mines(mine_id,mine_name,location,extraction_type) | INSERT INTO mines (mine_id, mine_name, location, extraction_type) VALUES (5, 'New Mine', 'New Location', 'Surface'); |
What is the average heart rate for each user, partitioned by gender? | CREATE TABLE user_data (id INT,user_name TEXT,country TEXT,gender TEXT,heart_rate INT); INSERT INTO user_data (id,user_name,country,gender,heart_rate) VALUES (1,'John Doe','USA','Male',75),(2,'Jane Smith','USA','Female',80),(3,'Alice Johnson','Canada','Female',85); | SELECT user_id, gender, AVG(heart_rate) as avg_heart_rate FROM user_data GROUP BY user_id, gender; |
What's the total number of shelters and hospitals in each country? | CREATE TABLE Facilities (FacilityID INT,FacilityCountry TEXT,FacilityType TEXT,FacilityCount INT); INSERT INTO Facilities (FacilityID,FacilityCountry,FacilityType,FacilityCount) VALUES (1,'Haiti','Shelters',5),(2,'Haiti','Hospitals',3),(3,'Dominican Republic','Shelters',7),(4,'Dominican Republic','Hospitals',4); | SELECT FacilityCountry, SUM(FacilityCount) FROM Facilities WHERE FacilityType IN ('Shelters', 'Hospitals') GROUP BY FacilityCountry; |
What is the difference in average depth between expeditions in the Pacific and Atlantic Oceans? | CREATE TABLE Expeditions(ExpeditionID INT,Location VARCHAR(20),AvgDepth DECIMAL(5,2)); INSERT INTO Expeditions(ExpeditionID,Location,AvgDepth) VALUES (1,'Pacific',3500.50),(2,'Atlantic',4200.30),(3,'Indian',2100.75),(4,'Pacific',5100.90),(5,'Atlantic',2900.40); | SELECT AVG(CASE WHEN Location = 'Pacific' THEN AvgDepth ELSE NULL END) - AVG(CASE WHEN Location = 'Atlantic' THEN AvgDepth ELSE NULL END) FROM Expeditions; |
What was the minimum response time for fire incidents in the Downtown district in 2021? | CREATE TABLE districts (id INT,name TEXT); INSERT INTO districts (id,name) VALUES (1,'Downtown'),(2,'Uptown'),(3,'Midtown'); CREATE TABLE fire_incidents (id INT,district_id INT,response_time INT,incident_date DATE); INSERT INTO fire_incidents (id,district_id,response_time,incident_date) VALUES (1,1,5,'2021-01-01'),(2,1... | SELECT MIN(response_time) FROM fire_incidents WHERE district_id = 1 AND YEAR(incident_date) = 2021; |
List all menu items that contain 'chicken' in their name from the 'Menu' table. | CREATE TABLE Menu (id INT,name VARCHAR(255),price DECIMAL(5,2),vegetarian BOOLEAN); INSERT INTO Menu (id,name,price,vegetarian) VALUES (1,'Chicken Burger',7.99,FALSE),(2,'Veggie Wrap',6.49,TRUE),(3,'Chicken Caesar Salad',9.99,FALSE); | SELECT name FROM Menu WHERE name LIKE '%chicken%'; |
What are the names and types of rovers that landed on Mars before 2010? | CREATE TABLE Mars_Rovers (Rover_ID INT PRIMARY KEY,Name VARCHAR(100),Type VARCHAR(50),Landing_Date DATE,Agency VARCHAR(50)); INSERT INTO Mars_Rovers (Rover_ID,Name,Type,Landing_Date,Agency) VALUES (1,'Sojourner','Micro rover','1997-07-04','NASA'),(2,'Spirit','Mars Exploration Rover','2004-01-04','NASA'),(3,'Opportunity... | SELECT Name, Type FROM Mars_Rovers WHERE Landing_Date < '2010-01-01'; |
How many infectious disease cases were reported in each age group? | CREATE TABLE age_groups (age_group_id INT,age_group VARCHAR(20)); CREATE TABLE disease_cases (case_id INT,age_group_id INT,disease_name VARCHAR(50),cases_count INT); | SELECT ag.age_group, SUM(dc.cases_count) AS total_cases FROM age_groups ag JOIN disease_cases dc ON ag.age_group_id = dc.age_group_id GROUP BY ag.age_group; |
What engineering design standards were used in projects located in Argentina? | CREATE TABLE projects_arg (id INT,country VARCHAR(50),standard VARCHAR(50)); INSERT INTO projects_arg (id,country,standard) VALUES (1,'Argentina','IRAM 11605'),(2,'Argentina','IRAM 11606'); | SELECT DISTINCT standard FROM projects_arg WHERE country = 'Argentina'; |
What are the names and descriptions of biosensor technology projects in India and China? | CREATE TABLE biosensor_technology (id INT,project_name VARCHAR(50),description TEXT,location VARCHAR(50)); INSERT INTO biosensor_technology (id,project_name,description,location) VALUES (1,'Project1','Biosensor for glucose detection','India'); INSERT INTO biosensor_technology (id,project_name,description,location) VALU... | SELECT project_name, description FROM biosensor_technology WHERE location IN ('India', 'China'); |
What is the total mass of space debris in LEO orbit? | CREATE TABLE Space_Debris (Debris_ID INT,Debris_Name VARCHAR(50),Mass FLOAT,Orbit VARCHAR(50),PRIMARY KEY (Debris_ID)); INSERT INTO Space_Debris (Debris_ID,Debris_Name,Mass,Orbit) VALUES (1,'Envisat',8212,'LEO'),(2,'Tiangong-1',8500,'GEO'),(3,'Fengyun-1C',3500,'GEO'),(4,'Cosmos 2251',900,'LEO'); | SELECT SUM(Mass) FROM Space_Debris WHERE Orbit = 'LEO'; |
What was the total cost of 'Waste Management' projects in 2019, grouped by their status? | CREATE TABLE Projects (id INT,name VARCHAR(50),category VARCHAR(50),cost FLOAT,year_started INT,year_completed INT,status VARCHAR(20)); INSERT INTO Projects (id,name,category,cost,year_started,year_completed,status) VALUES (1,'Dam Reconstruction','Water Supply',500000,2017,2019,'Completed'),(2,'Wastewater Treatment','W... | SELECT status, SUM(cost) FROM Projects WHERE category = 'Waste Management' AND year_completed = 2019 GROUP BY status; |
Who are the volunteers for the 'disaster_relief' program and when did they last volunteer? | CREATE TABLE program (id INT,name VARCHAR(255)); CREATE TABLE volunteer (id INT,program_id INT,name VARCHAR(255),last_volunteered DATE); INSERT INTO program (id,name) VALUES (1,'youth_mentoring'),(2,'disaster_relief'); INSERT INTO volunteer (id,program_id,name,last_volunteered) VALUES (1,1,'Alice','2022-01-01'),(2,2,'B... | SELECT * FROM volunteer WHERE program_id = (SELECT id FROM program WHERE name = 'disaster_relief'); |
Delete biosensors with accuracy below 0.95 and no startup funding. | CREATE TABLE biosensors (id INT,name VARCHAR(50),type VARCHAR(50),accuracy FLOAT); CREATE TABLE startup_funding (id INT,biosensor_id INT,funding_amount FLOAT); INSERT INTO biosensors (id,name,type,accuracy) VALUES (1,'BioSen1','Optical',0.96),(2,'BioSen2','Electrochemical',0.94); INSERT INTO startup_funding (id,biosens... | DELETE bs FROM biosensors bs LEFT JOIN startup_funding sf ON bs.id = sf.biosensor_id WHERE bs.accuracy < 0.95 AND sf.biosensor_id IS NULL; |
What is the difference in average time spent on the platform, per player, between players who made a purchase in the last month and those who did not, for each platform? | CREATE TABLE PlayerPurchaseTime (PlayerID INT,Platform VARCHAR(10),AvgTime FLOAT,Purchase DATE); INSERT INTO PlayerPurchaseTime (PlayerID,Platform,AvgTime,Purchase) VALUES (1,'PC',150.5,'2022-01-01'); | SELECT a.Platform, AVG(a.AvgTime - b.AvgTime) as AvgTimeDifference FROM PlayerPurchaseTime a, PlayerPurchaseTime b WHERE a.Platform = b.Platform AND a.Purchase >= CURRENT_DATE - INTERVAL 1 MONTH AND b.Purchase < CURRENT_DATE - INTERVAL 1 MONTH GROUP BY a.Platform; |
What is the average distance of Mars' moons from the planet? | CREATE TABLE mars_moons (moon_id INT,name VARCHAR(100),distance_from_mars FLOAT); | SELECT AVG(distance_from_mars) FROM mars_moons; |
What is the total funds allocated for rural healthcare in the "resource_allocation" table for each region? | CREATE TABLE resource_allocation (id INT,year INT,funds_allocated INT,region VARCHAR(50)); | SELECT region, SUM(funds_allocated) FROM resource_allocation GROUP BY region; |
List all socially responsible lending institutions in the African continent | CREATE TABLE african_srl_institutions (id INT PRIMARY KEY,institution_name VARCHAR(100),continent VARCHAR(50)); INSERT INTO african_srl_institutions (id,institution_name,continent) VALUES (1,'Institution A','Africa'),(2,'Institution B','Europe'),(3,'Institution C','Africa'); | SELECT institution_name FROM african_srl_institutions WHERE continent = 'Africa'; |
How many drought impacts have been recorded in Beijing and Tokyo? | CREATE TABLE DroughtImpact (Location VARCHAR(100),Impact INT,Date DATE); INSERT INTO DroughtImpact (Location,Impact,Date) VALUES ('Beijing',3,'2022-01-01'),('Tokyo',2,'2022-01-02'); | SELECT Location, COUNT(*) FROM DroughtImpact GROUP BY Location; |
List all factories that use renewable energy sources | CREATE TABLE factories (id INT,name VARCHAR(50),location VARCHAR(50),energy_source VARCHAR(50)); INSERT INTO factories (id,name,location,energy_source) VALUES (1,'Factory A','New York','solar'),(2,'Factory B','California','wind'),(3,'Factory C','Texas','fossil_fuels'); | SELECT name FROM factories WHERE energy_source IN ('solar', 'wind'); |
What is the number of financially capable customers by region, ordered by region and number of customers? | CREATE TABLE financially_capable_customers (customer_id INT,customer_name TEXT,region TEXT,financially_capable BOOLEAN); INSERT INTO financially_capable_customers VALUES (1,'John Doe','North',TRUE),(2,'Jane Smith','North',TRUE),(3,'Ahmed Ali','South',FALSE),(4,'Aisha Khan','East',TRUE); | SELECT region, COUNT(*) as num_customers, ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC, region) as rank FROM financially_capable_customers WHERE financially_capable = TRUE GROUP BY region ORDER BY num_customers DESC, region; |
Retrieve all sites from the Cultural_Heritage table that were established after 1600. | CREATE TABLE Cultural_Heritage (Site VARCHAR(50),Year_Established INT,Historical_Significance TEXT); INSERT INTO Cultural_Heritage (Site,Year_Established,Historical_Significance) VALUES ('Machu Picchu',1450,'An Incan citadel set high in the Andes Mountains,above the Sacred Valley. It is renowned for its sophisticated d... | SELECT Site FROM Cultural_Heritage WHERE Year_Established > 1600; |
How many female biotech entrepreneurs in Brazil have successfully raised series A funding? | CREATE TABLE entrepreneurs (id INT,name TEXT,gender TEXT,industry TEXT,funding_round TEXT,country TEXT); INSERT INTO entrepreneurs (id,name,gender,industry,funding_round,country) VALUES (1,'Ana','Female','Biotech','Series A','Brazil'); | SELECT COUNT(*) FROM entrepreneurs WHERE gender = 'Female' AND industry = 'Biotech' AND country = 'Brazil' AND funding_round = 'Series A'; |
What is the average rating of skincare products supplied by the USA? | CREATE TABLE CosmeticsProducts (ProductID INT,ProductName VARCHAR(50),Category VARCHAR(50)); INSERT INTO CosmeticsProducts (ProductID,ProductName,Category) VALUES (1,'Product A','Skin Care'),(2,'Product B','Skin Care'),(3,'Product C','Makeup'); | SELECT AVG(pr.Rating) as AverageRating FROM ProductReviews pr JOIN Inventory i ON pr.ProductID = i.ProductID JOIN Suppliers s ON i.ProductID = s.ProductID JOIN CosmeticsProducts p ON i.ProductID = p.ProductID WHERE p.Category = 'Skin Care' AND s.Country = 'USA'; |
What is the total amount of funding received by programs located in the 'Asia Pacific' region, in the 'Visual Arts' category? | CREATE TABLE Programs (program_id INT,program_category VARCHAR(50),program_location VARCHAR(50)); INSERT INTO Programs (program_id,program_category,program_location) VALUES (1,'Visual Arts','Asia Pacific'),(2,'Dance','North America'),(3,'Visual Arts','Europe'); CREATE TABLE Funding (funding_id INT,program_id INT,fundin... | SELECT p.program_category, p.program_location, SUM(f.funding_amount) AS total_funding FROM Programs p JOIN Funding f ON p.program_id = f.program_id WHERE p.program_category = 'Visual Arts' AND p.program_location = 'Asia Pacific' GROUP BY p.program_category, p.program_location; |
Find the names and production quantities of the top 3 producing wells in the 'SouthEastAsia' region. | CREATE TABLE WellProduction (well_id INT,well_name TEXT,region TEXT,production_qty REAL); INSERT INTO WellProduction (well_id,well_name,region,production_qty) VALUES (1,'Delta','SouthEastAsia',2000),(2,'Echo','SouthEastAsia',2200),(3,'Foxtrot','SouthEastAsia',2500); | SELECT well_name, production_qty FROM WellProduction WHERE region = 'SouthEastAsia' ORDER BY production_qty DESC LIMIT 3 |
What is the total quantity of Fair Trade textiles sold in Ghana? | CREATE TABLE sales (sale_id int,product_id int,vendor_id int,quantity int,sale_date date); CREATE TABLE products (product_id int,product_name varchar(255),is_fair_trade boolean,product_category varchar(50),country varchar(50)); INSERT INTO sales (sale_id,product_id,vendor_id,quantity,sale_date) VALUES (1,1,101,20,'2022... | SELECT SUM(quantity) AS total_quantity FROM sales JOIN products ON sales.product_id = products.product_id WHERE is_fair_trade = true AND product_category = 'Textiles' AND country = 'Ghana'; |
What is the total number of community health workers who identify as Native American or Alaska Native? | CREATE TABLE community_health_workers (worker_id INT,ethnicity VARCHAR(255)); INSERT INTO community_health_workers (worker_id,ethnicity) VALUES (1,'Hispanic'),(2,'African American'),(3,'Asian'),(4,'Caucasian'),(5,'Native American'),(6,'Alaska Native'); | SELECT COUNT(*) as total FROM community_health_workers WHERE ethnicity IN ('Native American', 'Alaska Native'); |
What is the total fare collected from passengers with disabilities for train route 201? | CREATE TABLE routes (route_id INT,route_name TEXT); INSERT INTO routes (route_id,route_name) VALUES (101,'Bus Route 101'),(201,'Train Route 201'); CREATE TABLE fare_collection (collection_id INT,passenger_type TEXT,route_id INT,fare DECIMAL); INSERT INTO fare_collection (collection_id,passenger_type,route_id) VALUES (1... | SELECT SUM(fare) FROM fare_collection JOIN routes ON fare_collection.route_id = routes.route_id WHERE passenger_type = 'Wheelchair' AND routes.route_name = 'Train Route 201'; |
What is the total sale price of artworks by female artists from the United States? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name VARCHAR(255),Gender VARCHAR(255),Nationality VARCHAR(255)); CREATE TABLE Artworks (ArtworkID INT PRIMARY KEY,Title VARCHAR(255),ArtistID INT,Year INT,SalePrice DECIMAL(10,2)); CREATE TABLE Sales (SaleID INT PRIMARY KEY,SaleDate DATE); | SELECT SUM(Artworks.SalePrice) AS TotalSalePrice FROM Artists INNER JOIN Artworks ON Artists.ArtistID = Artworks.ArtistID INNER JOIN Sales ON Artworks.ArtworkID = Sales.ArtworkID WHERE Artists.Gender = 'Female' AND Artists.Nationality = 'American'; |
How many electric scooter charging stations are there in Sao Paulo, Brazil? | CREATE TABLE electric_scooter_charging_stations (station_id INT,station_name TEXT,city TEXT,charging_stations INT); | SELECT SUM(charging_stations) FROM electric_scooter_charging_stations WHERE city = 'Sao Paulo'; |
What is the maximum number of satellites launched by a country in a year? | CREATE TABLE country_satellite_launches (country_id INT,launch_year INT,number_of_satellites INT); CREATE TABLE countries (id INT,name VARCHAR(50)); | SELECT c.name, MAX(cs.number_of_satellites) FROM countries c JOIN country_satellite_launches cs ON c.id = cs.country_id GROUP BY c.name; |
For the sustainable_tech table, return the product_name, manufacturing_location, and carbon_footprint for the rows with the 10th, 50th, and 90th percentile carbon_footprint values, in ascending order. | CREATE TABLE sustainable_tech (product_name VARCHAR(255),manufacturing_location VARCHAR(255),carbon_footprint FLOAT); | SELECT product_name, manufacturing_location, carbon_footprint FROM (SELECT product_name, manufacturing_location, carbon_footprint, NTILE(10) OVER (ORDER BY carbon_footprint) as percentile FROM sustainable_tech) tmp WHERE percentile IN (1, 5, 9) ORDER BY carbon_footprint ASC; |
How many sustainable tourism activities are available in New York? | CREATE TABLE TourismActivities (id INT,name TEXT,location TEXT,sustainable BOOLEAN); INSERT INTO TourismActivities (id,name,location,sustainable) VALUES (1,'Central Park Bike Tour','New York',true),(2,'New York City Bus Tour','New York',false); | SELECT COUNT(*) FROM TourismActivities WHERE location = 'New York' AND sustainable = true; |
How many trams are there in the 'east' region with fare greater than 2? | CREATE TABLE tram_data (region VARCHAR(10),fare DECIMAL(5,2)) ; INSERT INTO tram_data (region,fare) VALUES ('north',1.50),('south',2.25),('east',2.75),('west',1.75); | SELECT COUNT(*) FROM tram_data WHERE region = 'east' AND fare > 2; |
What is the total number of volunteers for each program and their average donation amount? | CREATE TABLE programs (id INT,name VARCHAR(255)); INSERT INTO programs (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE volunteers (id INT,name VARCHAR(255),program_id INT,total_donations DECIMAL(10,2)); | SELECT p.name, COUNT(*) as total_volunteers, AVG(v.total_donations) as avg_donation_amount FROM programs p JOIN volunteers v ON p.id = v.program_id GROUP BY p.id; |
Identify the chemical with the highest emission levels in Oregon. | CREATE TABLE chemical (chemical_id INT,name TEXT); INSERT INTO chemical (chemical_id,name) VALUES (1,'ChemicalA'),(2,'ChemicalB'),(3,'ChemicalC'); CREATE TABLE emission_log (log_id INT,chemical_id INT,emission_amount INT,emission_date DATE); INSERT INTO emission_log (log_id,chemical_id,emission_amount,emission_date) VA... | SELECT chemical.name, MAX(emission_log.emission_amount) FROM chemical JOIN emission_log ON chemical.chemical_id = emission_log.chemical_id WHERE chemical.name IN (SELECT name FROM chemical WHERE state = 'Oregon') GROUP BY chemical.name; |
How many green certified buildings are there in each city in Canada? | CREATE TABLE GreenCertified (id INT,city VARCHAR(50),building_count INT); INSERT INTO GreenCertified (id,city,building_count) VALUES (1,'Toronto',150),(2,'Vancouver',120),(3,'Montreal',180),(4,'Calgary',100); | SELECT city, building_count FROM GreenCertified WHERE country = 'Canada' GROUP BY city; |
What is the average cost of treatment for each unique treatment_approach in the 'treatment_costs' schema? | CREATE TABLE treatment_costs (cost_id INT,treatment_approach VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO treatment_costs (cost_id,treatment_approach,cost) VALUES (1,'CBT',150.00),(2,'DBT',200.00),(3,'EMDR',250.00),(4,'Medication',50.00),(5,'Lithium',75.00),(6,'Antipsychotics',100.00); | SELECT treatment_approach, AVG(cost) AS avg_cost FROM treatment_costs GROUP BY treatment_approach; |
List all sculptures with their sale prices in descending order. | CREATE TABLE Artwork (ArtworkID INT,Title VARCHAR(100),Type VARCHAR(50),Price FLOAT); INSERT INTO Artwork VALUES (1,'Guernica','Painting',2000000); INSERT INTO Artwork VALUES (2,'Venus de Milo','Sculpture',1200000); | SELECT Title, Price FROM Artwork WHERE Type = 'Sculpture' ORDER BY Price DESC; |
Count the number of records in the 'mammals_view' view | CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(100),species VARCHAR(50),population INT); INSERT INTO animals (id,name,species,population) VALUES (1,'Giraffe','Mammal',30000),(2,'Elephant','Mammal',5000); CREATE VIEW mammals_view AS SELECT * FROM animals WHERE species = 'Mammal'; | SELECT COUNT(*) FROM mammals_view; |
What is the average orbital altitude of satellites launched by each country? | CREATE TABLE satellites (satellite_id INT,country VARCHAR(50),orbital_altitude INT); INSERT INTO satellites (satellite_id,country,orbital_altitude) VALUES (1,'USA',700),(2,'USA',800),(3,'China',600),(4,'Russia',900),(5,'India',1000),(6,'Japan',1100); | SELECT country, AVG(orbital_altitude) as average_altitude FROM satellites GROUP BY country; |
Identify the top 3 countries with the highest average order value. | CREATE TABLE Orders (order_id INT,order_date DATE,order_value FLOAT,country VARCHAR(50)); INSERT INTO Orders (order_id,order_date,order_value,country) VALUES (1,'2021-01-01',150.00,'USA'),(2,'2021-01-02',200.00,'Canada'),(3,'2021-01-03',120.00,'USA'),(4,'2021-01-04',50.00,'Mexico'),(5,'2021-01-05',300.00,'Australia'); | SELECT country, AVG(order_value) AS avg_order_value FROM Orders GROUP BY country ORDER BY avg_order_value DESC LIMIT 3; |
What is the average network latency in the state of Texas for the last month? | CREATE TABLE network_latency (latency_id INT,state VARCHAR(50),latency FLOAT,measurement_date DATE); INSERT INTO network_latency (latency_id,state,latency,measurement_date) VALUES (1,'Texas',20,'2022-01-01'); INSERT INTO network_latency (latency_id,state,latency,measurement_date) VALUES (2,'Texas',25,'2022-01-02'); | SELECT AVG(latency) FROM network_latency WHERE state = 'Texas' AND measurement_date >= DATEADD(month, -1, GETDATE()); |
What is the total duration of Yoga classes attended by members in their 30s? | CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),MembershipType VARCHAR(20)); INSERT INTO Members (MemberID,Age,Gender,MembershipType) VALUES (1,35,'Female','Premium'),(2,45,'Male','Basic'),(3,28,'Female','Premium'); CREATE TABLE ClassAttendance (MemberID INT,Class VARCHAR(20),Duration INT,Date DATE); INSE... | SELECT SUM(Duration) FROM Members JOIN ClassAttendance ON Members.MemberID = ClassAttendance.MemberID WHERE Members.Age BETWEEN 30 AND 39 AND ClassAttendance.Class = 'Yoga'; |
Insert new records of farmed trout in Iceland in 2023 with production quantities of 500, 750, and 1000. | CREATE TABLE Farming(country VARCHAR(255),year INT,species VARCHAR(255),production FLOAT); | INSERT INTO Farming (country, year, species, production) VALUES ('Iceland', 2023, 'Trout', 500), ('Iceland', 2023, 'Trout', 750), ('Iceland', 2023, 'Trout', 1000); |
What is the percentage of properties in each city that have sustainable features? | CREATE TABLE cities (city_id INT,city_name VARCHAR(255));CREATE TABLE properties (property_id INT,city_id INT,has_sustainable_features BOOLEAN); INSERT INTO cities (city_id,city_name) VALUES (1,'CityA'),(2,'CityB'); INSERT INTO properties (property_id,city_id,has_sustainable_features) VALUES (1,1,TRUE),(2,1,FALSE),(3,2... | SELECT city_id, 100.0 * AVG(has_sustainable_features::INT) as percentage_sustainable FROM properties GROUP BY city_id; |
What is the total budget allocated for public safety and environmental protection services in the state of California in 2021? | CREATE TABLE budget_allocation (year INT,state VARCHAR(20),service VARCHAR(20),amount INT); INSERT INTO budget_allocation VALUES (2021,'California','Public Safety',3000000),(2021,'California','Environmental Protection',4000000); | SELECT SUM(amount) FROM budget_allocation WHERE state = 'California' AND (service = 'Public Safety' OR service = 'Environmental Protection') AND year = 2021; |
What percentage of concert ticket sales are from Asia? | CREATE TABLE concert_sales (sale_id INT,sale_country VARCHAR(50),tickets_sold INT); INSERT INTO concert_sales (sale_id,sale_country,tickets_sold) VALUES (1,'Japan',500),(2,'China',800),(3,'Canada',1500); | SELECT (SUM(CASE WHEN sale_country = 'Asia' THEN tickets_sold ELSE 0 END) / SUM(tickets_sold)) * 100 AS percentage FROM concert_sales; |
What is the total number of unique wallet addresses that have interacted with decentralized applications on the Polkadot network, and what is the average number of interactions per address? | CREATE TABLE polkadot_dapps (wallet_address VARCHAR(255),interaction_count INT); | SELECT COUNT(DISTINCT wallet_address) as total_wallets, AVG(interaction_count) as avg_interactions FROM polkadot_dapps; |
What are the names of attorneys who have a 100% success rate? | CREATE TABLE cases (case_id INT,attorney_name VARCHAR(50),case_outcome VARCHAR(10)); INSERT INTO cases (case_id,attorney_name,case_outcome) VALUES (1,'Jane Jones','Won'),(2,'Robert Smith','Lost'),(3,'Jane Jones','Won'); | SELECT attorney_name FROM cases WHERE case_outcome = 'Won' GROUP BY attorney_name HAVING COUNT(*) = (SELECT COUNT(*) FROM cases WHERE attorney_name = cases.attorney_name AND case_outcome = 'Won'); |
What is the maximum number of employees for startups founded by minorities? | CREATE TABLE startup (id INT,name TEXT,founder_race TEXT,num_employees INT); INSERT INTO startup (id,name,founder_race,num_employees) VALUES (1,'MinorityStart','Minority',500); INSERT INTO startup (id,name,founder_race,num_employees) VALUES (2,'TechStart','White',100); | SELECT MAX(num_employees) FROM startup WHERE founder_race = 'Minority'; |
What is the total number of fair trade and organic certified items in the inventory? | CREATE TABLE inventory (id INT,item_name VARCHAR(255),category VARCHAR(255),is_fair_trade BOOLEAN,is_organic BOOLEAN); INSERT INTO inventory (id,item_name,category,is_fair_trade,is_organic) VALUES (1,'T-Shirt','Tops',true,true),(2,'Jeans','Bottoms',true,false),(3,'Hoodie','Tops',false,true); | SELECT COUNT(*) FROM inventory WHERE is_fair_trade = true OR is_organic = true; |
List all clinical trials that have been conducted in 'CountryA' or 'CountryB'. | CREATE TABLE clinical_trials (trial_id INTEGER,country TEXT); INSERT INTO clinical_trials (trial_id,country) VALUES (1,'CountryA'),(2,'CountryB'),(3,'CountryC'); | SELECT DISTINCT trial_id FROM clinical_trials WHERE country IN ('CountryA', 'CountryB'); |
List the names of all female players who have played strategy games. | CREATE TABLE players (player_id int,age int,gender varchar(10),country varchar(20)); INSERT INTO players (player_id,age,gender,country) VALUES (1,25,'Male','USA'),(2,30,'Female','Canada'),(3,22,'Male','Mexico'),(4,35,'Female','USA'); CREATE TABLE game_sessions (session_id int,player_id int,game_name varchar(20),game_ty... | SELECT DISTINCT players.player_id, players.gender, game_sessions.game_name FROM players INNER JOIN game_sessions ON players.player_id = game_sessions.player_id INNER JOIN game_catalog ON game_sessions.game_name = game_catalog.game_name WHERE players.gender = 'Female' AND game_catalog.game_type = 'Strategy'; |
What is the total number of women-owned businesses in each province of South Africa? | CREATE TABLE businesses (id INT,owner VARCHAR(10),province VARCHAR(20),women_owned BOOLEAN); INSERT INTO businesses (id,owner,province,women_owned) VALUES (1,'Owner 1','Province 1',true); INSERT INTO businesses (id,owner,province,women_owned) VALUES (2,'Owner 2','Province 2',false); | SELECT province, COUNT(*) FROM businesses WHERE women_owned = true GROUP BY province; |
Which countries have the highest sales revenue for organic hair care products? | CREATE TABLE CountrySales (country VARCHAR(50),product_id INT,revenue DECIMAL(10,2),is_organic BOOLEAN); | SELECT country, SUM(revenue) FROM CountrySales WHERE is_organic = TRUE GROUP BY country ORDER BY SUM(revenue) DESC LIMIT 3; |
What is the total number of research expeditions to the Arctic by organization? | CREATE TABLE ResearchExpeditions(expedition_id INT,organization VARCHAR(255)); | SELECT organization, COUNT(*) FROM ResearchExpeditions GROUP BY organization; |
What is the total budget of all climate mitigation projects in the US? | CREATE TABLE projects (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),type VARCHAR(20),budget FLOAT); INSERT INTO projects (id,name,location,type,budget) VALUES (1,'Carbon Capture','US','Mitigation',7000000.0); INSERT INTO projects (id,name,location,type,budget) VALUES (2,'Green Roofs','New York','Adaptation'... | SELECT SUM(budget) FROM projects WHERE location = 'US' AND type = 'Mitigation'; |
What is the total revenue generated by music festivals in Europe in 2022? | CREATE TABLE Festivals (id INT,name VARCHAR(50),country VARCHAR(50),year INT,revenue INT); INSERT INTO Festivals (id,name,country,year,revenue) VALUES (1,'Glastonbury','UK',2022,5000000),(2,'Tomorrowland','Belgium',2022,7000000),(3,'Roskilde','Denmark',2021,6000000); | SELECT SUM(revenue) FROM Festivals WHERE country IN ('UK', 'Belgium', 'Denmark') AND year = 2022; |
How many games are designed by women in Canada and Germany? | CREATE TABLE GameDesigners (DesignerID INT,DesignerName VARCHAR(50),Gender VARCHAR(10),Country VARCHAR(20),GameID INT); | SELECT COUNT(DISTINCT GameID) FROM GameDesigners WHERE Country IN ('Canada', 'Germany') AND Gender = 'Female'; |
How many energy efficiency policies were implemented in the EU between 2015 and 2020, inclusive? | CREATE TABLE energy_efficiency_policies (policy_name VARCHAR(255),policy_date DATE); | SELECT COUNT(*) FROM energy_efficiency_policies WHERE policy_date BETWEEN '2015-01-01' AND '2020-12-31'; |
What is the average temperature in 'Miami' for January? | CREATE TABLE weather (city VARCHAR(255),temperature FLOAT,date DATE); INSERT INTO weather (city,temperature,date) VALUES ('Miami',75,'2022-01-01'),('Miami',72,'2022-01-02'),('Miami',78,'2022-01-03'); | SELECT AVG(temperature) FROM weather WHERE city = 'Miami' AND date BETWEEN '2022-01-01' AND '2022-01-31'; |
How many unique offenders were there in the 'criminal_database' table without specifying their ethnicity in the 'offender_demographics' table? | CREATE TABLE criminal_database (offender_id INT,offense VARCHAR(255)); CREATE TABLE offender_demographics (offender_id INT,ethnicity VARCHAR(255)); | SELECT COUNT(DISTINCT offender_id) FROM criminal_database WHERE offender_id NOT IN (SELECT offender_id FROM offender_demographics); |
How many vehicles were serviced in each region last month? | CREATE TABLE Regions (RegionID int,RegionName varchar(50)); INSERT INTO Regions VALUES (1,'North'); INSERT INTO Regions VALUES (2,'South'); CREATE TABLE VehicleMaintenance (MaintenanceID int,VehicleID int,MaintenanceDate date,RegionID int); INSERT INTO VehicleMaintenance VALUES (1,1,'2022-02-10',1); INSERT INTO Vehicle... | SELECT Regions.RegionName, COUNT(VehicleMaintenance.VehicleID) as VehiclesServiced FROM Regions INNER JOIN VehicleMaintenance ON Regions.RegionID = VehicleMaintenance.RegionID WHERE VehicleMaintenance.MaintenanceDate BETWEEN DATE_SUB(LAST_DAY(CURDATE()), INTERVAL 2 MONTH) AND LAST_DAY(CURDATE()) GROUP BY Regions.Region... |
What is the total value of veteran employment initiatives in Texas since 2018? | CREATE TABLE employment_initiatives (initiative_id INT,state VARCHAR(2),start_year INT,end_year INT,initiative_value DECIMAL(10,2)); INSERT INTO employment_initiatives (initiative_id,state,start_year,end_year,initiative_value) VALUES (1,'Texas',2018,2022,1500000.00),(2,'California',2019,2023,1200000.00); | SELECT SUM(initiative_value) FROM employment_initiatives WHERE state = 'Texas' AND start_year <= 2018 AND end_year >= 2018; |
What is the average energy production of wind farms in Denmark? | CREATE TABLE Wind_Farms (Farm_Name VARCHAR(30),Country VARCHAR(20),Production INT); INSERT INTO Wind_Farms VALUES ('Horns Rev','Denmark',250),('Rødsand','Denmark',300),('Nysted','Denmark',350),('Anholt','Denmark',400); | SELECT AVG(Production) AS Avg_Production FROM Wind_Farms WHERE Country = 'Denmark'; |
What is the average rating for movies belonging to the 'Action' genre? | CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(50),rating DECIMAL(3,2)); INSERT INTO movies (id,title,genre,rating) VALUES (1,'MovieA','Action',7.2); INSERT INTO movies (id,title,genre,rating) VALUES (2,'MovieB','Comedy',8.5); INSERT INTO movies (id,title,genre,rating) VALUES (3,'MovieC','Action',6.8); | SELECT AVG(rating) FROM movies WHERE genre = 'Action'; |
What is the total size of protected habitats for each type of habitat? | CREATE TABLE habitats (id INT,name TEXT,habitat_type TEXT,size_km2 FLOAT); INSERT INTO habitats (id,name,habitat_type,size_km2) VALUES (1,'Habitat1','Forest',50.3),(2,'Habitat2','Savannah',32.1),(3,'Habitat3','Savannah',87.6),(4,'Habitat4','Wetlands',22.5),(5,'Habitat5','Forest',75.8); | SELECT habitat_type, SUM(size_km2) as total_size FROM habitats GROUP BY habitat_type; |
What is the average price of products made from organic cotton, sold in the European market? | CREATE TABLE products (product_id INT,material VARCHAR(20),price DECIMAL(5,2),market VARCHAR(20)); INSERT INTO products (product_id,material,price,market) VALUES (1,'organic cotton',50.00,'Europe'),(2,'polyester',30.00,'Europe'),(3,'organic cotton',60.00,'Asia'); | SELECT AVG(price) FROM products WHERE material = 'organic cotton' AND market = 'Europe'; |
How many fans attended each event category? | CREATE TABLE Events (event_id INT,category VARCHAR(255),price DECIMAL(5,2)); INSERT INTO Events (event_id,category,price) VALUES (1,'Concert',50.99),(2,'Sports',30.50),(3,'Theater',75.00); CREATE TABLE Fans (fan_id INT,age INT,event_id INT); INSERT INTO Fans (fan_id,age,event_id) VALUES (1,25,1),(2,30,1),(3,18,2),(4,45... | SELECT e.category, COUNT(f.fan_id) FROM Events e LEFT JOIN Fans f ON e.event_id = f.event_id GROUP BY e.category; |
List the number of rural healthcare facilities in each state that offer mental health services. | CREATE TABLE facilities (facility_id INT,name VARCHAR(50),state VARCHAR(20),mental_health_services BOOLEAN); | SELECT state, COUNT(*) FROM facilities WHERE mental_health_services = true GROUP BY state; |
What is the total billing amount for cases lost by the top 2 attorneys? | CREATE TABLE attorneys (id INT,name VARCHAR(50),total_billing_amount DECIMAL(10,2)); CREATE TABLE cases (id INT,attorney_id INT,case_outcome VARCHAR(10)); | SELECT SUM(total_billing_amount) FROM (SELECT attorney_id, SUM(billing_amount) AS total_billing_amount FROM cases JOIN attorneys ON cases.attorney_id = attorneys.id WHERE case_outcome = 'lost' GROUP BY attorney_id ORDER BY total_billing_amount DESC LIMIT 2); |
What is the minimum price of Ytterbium produced in South Africa for the last 3 years? | CREATE TABLE ytterbium_prices (year INT,country TEXT,price FLOAT); INSERT INTO ytterbium_prices (year,country,price) VALUES (2019,'South Africa',220.0),(2020,'South Africa',230.0),(2021,'South Africa',240.0); | SELECT MIN(price) FROM ytterbium_prices WHERE country = 'South Africa' AND year >= 2019; |
Identify the graduate students in the College of Engineering who have not been assigned any advisors. | CREATE TABLE students (id INT,name VARCHAR(50),department VARCHAR(50)); CREATE TABLE advisors (id INT,student_id INT); INSERT INTO students VALUES (1,'Aarav','Engineering'),(2,'Bella','Engineering'),(3,'Chris','Engineering'); INSERT INTO advisors VALUES (1,1),(2,2); | SELECT DISTINCT students.id, students.name FROM students LEFT JOIN advisors ON students.id = advisors.student_id WHERE advisors.id IS NULL; |
What is the average mental health score of students in the 'Spring 2022' semester? | CREATE TABLE student_mental_health (student_id INT,mental_health_score INT,semester VARCHAR(20)); | SELECT AVG(mental_health_score) FROM student_mental_health WHERE semester = 'Spring 2022'; |
What is the total weight of plastic packaging used in cosmetics sold in France? | CREATE TABLE cosmetics_sales(product_name TEXT,weight FLOAT,sale_country TEXT); INSERT INTO cosmetics_sales(product_name,weight,sale_country) VALUES ('Mascara',12.5,'France'); | SELECT SUM(weight) FROM cosmetics_sales WHERE sale_country = 'France' AND packaging_material = 'plastic'; |
What is the change in funding for each visual arts program type from 2021 to 2022? | CREATE TABLE visual_arts_funding (id INT,program_type VARCHAR(255),funding_year INT,amount DECIMAL(10,2)); | SELECT program_type, (fy2022.amount - fy2021.amount) AS funding_change FROM visual_arts_funding fy2021, visual_arts_funding fy2022 WHERE fy2021.program_type = fy2022.program_type AND fy2021.funding_year = 2021 AND fy2022.funding_year = 2022 AND fy2021.program_type LIKE '%visual%arts%'; |
List the names and total contributions of organizations that have donated to technology for social good initiatives in the United States and Canada. | CREATE TABLE organizations (organization_id INT,name VARCHAR(50),donations_social_good FLOAT,country VARCHAR(50)); INSERT INTO organizations (organization_id,name,donations_social_good,country) VALUES (1,'OrgA',100000.0,'USA'),(2,'OrgB',150000.0,'Canada'),(3,'OrgC',75000.0,'USA'),(4,'OrgD',200000.0,'Canada'); | SELECT name, SUM(donations_social_good) FROM organizations WHERE country IN ('USA', 'Canada') GROUP BY name; |
Which countries have launched the most space missions in the last 10 years? | CREATE TABLE space_missions (id INT,mission_name VARCHAR(50),launch_date DATE,launch_country VARCHAR(50)); INSERT INTO space_missions (id,mission_name,launch_date,launch_country) VALUES (1,'STS-31','1990-04-24','USA'); INSERT INTO space_missions (id,mission_name,launch_date,launch_country) VALUES (2,'Soyuz TMA-20','201... | SELECT launch_country, COUNT(*) FROM space_missions WHERE YEAR(launch_date) >= YEAR(CURRENT_DATE) - 10 GROUP BY launch_country ORDER BY COUNT(*) DESC; |
Get the average mass of spacecraft per type. | CREATE TABLE spacecraft_mass (spacecraft_name VARCHAR(50),type VARCHAR(50),mass FLOAT); | SELECT type, AVG(mass) as avg_mass FROM spacecraft_mass GROUP BY type; |
How many autonomous driving research studies were conducted in North America? | CREATE TABLE AutonomousDrivingResearch (StudyID INT,StudyLocation VARCHAR(20)); INSERT INTO AutonomousDrivingResearch (StudyID,StudyLocation) VALUES (1,'North America'),(2,'Europe'); | SELECT COUNT(*) FROM AutonomousDrivingResearch WHERE StudyLocation = 'North America'; |
What is the percentage of repeat visitors for the "Photography Exhibit" program? | CREATE TABLE PhotographyExhibit(id INT,age INT,gender VARCHAR(10),visit_date DATE,is_repeat BOOLEAN); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM PhotographyExhibit WHERE is_repeat = FALSE) FROM PhotographyExhibit WHERE is_repeat = TRUE; |
Show the top 3 cities with the most green building certifications in the United States. | CREATE TABLE us_city_certifications (city VARCHAR(20),certifications INT); INSERT INTO us_city_certifications (city,certifications) VALUES ('New York',500),('Los Angeles',300),('Chicago',400),('Houston',200); | SELECT city, certifications FROM (SELECT city, certifications, RANK() OVER (ORDER BY certifications DESC) as rank FROM us_city_certifications WHERE country = 'United States') AS subquery WHERE rank <= 3; |
What is the average data usage difference between the highest and lowest data usage customers in each city? | CREATE TABLE city_customer_data (customer_id INT,city VARCHAR(50),data_usage_gb FLOAT); INSERT INTO city_customer_data (customer_id,city,data_usage_gb) VALUES (1,'Delhi',25.6),(2,'Delhi',30.9),(3,'Mumbai',45.2),(4,'Mumbai',52.1),(5,'Bangalore',15.6),(6,'Bangalore',18.9); | SELECT city, AVG(MAX(data_usage_gb) - MIN(data_usage_gb)) as avg_data_usage_diff FROM city_customer_data GROUP BY city; |
What is the average age of employees who identify as a racial or ethnic minority? | CREATE TABLE employees (id INT,age INT,gender VARCHAR(10),racial_ethnic_minority BOOLEAN); | SELECT AVG(age) FROM employees WHERE racial_ethnic_minority = TRUE; |
What is the minimum age of patients in Australia who have been diagnosed with anxiety disorders? | CREATE TABLE patients (id INT,age INT,gender TEXT,country TEXT); CREATE TABLE diagnoses (id INT,patient_id INT,disorder_name TEXT); INSERT INTO diagnoses (id,patient_id,disorder_name) VALUES (1,101,'Anxiety Disorder'); | SELECT MIN(patients.age) FROM patients JOIN diagnoses ON patients.id = diagnoses.patient_id WHERE diagnoses.disorder_name = 'Anxiety Disorder' AND patients.country = 'Australia'; |
What is the total number of cases heard in each court type in each state? | CREATE TABLE court_types (court_type_id INT,court_type_name VARCHAR(20),court_state VARCHAR(2)); INSERT INTO court_types VALUES (1,'Community','NY'),(2,'Juvenile','CA'),(3,'Traffic','IL'),(4,'Civil','TX'); CREATE TABLE court_cases (case_id INT,case_state VARCHAR(2),court_type_id INT,days_to_resolve INT); INSERT INTO co... | SELECT ct.court_type_name, cc.case_state, COUNT(cc.case_id) FROM court_types ct INNER JOIN court_cases cc ON ct.court_type_id = cc.court_type_id GROUP BY ct.court_type_name, cc.case_state; |
What is the average number of green buildings per state in the 'green_buildings' table? | CREATE TABLE green_buildings (state VARCHAR(255),building_type VARCHAR(255)); | SELECT state, AVG(cnt) FROM (SELECT state, COUNT(*) AS cnt FROM green_buildings GROUP BY state) AS state_building_counts; |
What is the revenue trend for dishes that are both vegetarian and gluten-free in the last month? | CREATE TABLE dishes (dish_id INT,dish VARCHAR(50),created_at TIMESTAMP,is_vegetarian BOOLEAN,is_gluten_free BOOLEAN);CREATE TABLE orders (order_id INT,dish_id INT,price DECIMAL(5,2)); | SELECT DATE_TRUNC('day', d.created_at) as day, SUM(o.price) as revenue FROM dishes d JOIN orders o ON d.dish_id = o.dish_id WHERE d.is_vegetarian = TRUE AND d.is_gluten_free = TRUE AND d.created_at >= NOW() - INTERVAL '1 month' GROUP BY day ORDER BY day; |
Count the number of aquaculture sites in Thailand with a water depth greater than 10 meters? | CREATE TABLE thailand_aquaculture_sites (site_id INT,site_name TEXT,water_depth FLOAT,country TEXT); INSERT INTO thailand_aquaculture_sites (site_id,site_name,water_depth,country) VALUES (1,'Site O',12.5,'Thailand'),(2,'Site P',8.2,'Thailand'),(3,'Site Q',15.0,'Thailand'); | SELECT COUNT(*) FROM thailand_aquaculture_sites WHERE water_depth > 10.0; |
Who are the top 3 artists by total revenue from streaming platforms in 2020? | CREATE TABLE artists (artist_id INT,artist_name VARCHAR(30)); INSERT INTO artists (artist_id,artist_name) VALUES (1,'Ariana Grande'),(2,'BTS'),(3,'Drake'),(4,'Ed Sheeran'),(5,'Taylor Swift'); CREATE TABLE streams (stream_id INT,artist_id INT,revenue DECIMAL(10,2),stream_date DATE); INSERT INTO streams (stream_id,artist... | SELECT artists.artist_name, SUM(streams.revenue) AS total_revenue FROM artists INNER JOIN streams ON artists.artist_id = streams.artist_id WHERE streams.stream_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY artists.artist_name ORDER BY total_revenue DESC LIMIT 3; |
What are the names and types of local businesses in Paris with more than 10 seats? | CREATE TABLE local_business (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255),seats INT); INSERT INTO local_business (id,name,type,location,seats) VALUES (1,'Bistrot La Fontaine','French','Paris',15); | SELECT l.name, l.type, l.location FROM local_business l WHERE l.location = 'Paris' AND l.seats > 10; |
What is the maximum number of games played by a team in a single season? | CREATE TABLE team_schedule (team_id INT,played INT); INSERT INTO team_schedule (team_id,played) VALUES (1,25),(2,28),(3,30),(4,26); | SELECT MAX(played) FROM team_schedule; |
What is the total number of eco-friendly tours offered in Spain and Germany? | CREATE TABLE tours_sp_de (id INT,country VARCHAR(50),type VARCHAR(50)); INSERT INTO tours_sp_de (id,country,type) VALUES (1,'Spain','Eco-friendly'),(2,'Spain','Regular'),(3,'Germany','Eco-friendly'); | SELECT SUM(CASE WHEN type = 'Eco-friendly' THEN 1 ELSE 0 END) FROM tours_sp_de WHERE country IN ('Spain', 'Germany'); |
What is the total number of articles published on investigative journalism in the last year? | CREATE TABLE articles (id INT,title VARCHAR(50),topic VARCHAR(50),publish_date DATE); INSERT INTO articles (id,title,topic,publish_date) VALUES (1,'Investigation on Corruption','investigative journalism','2022-02-10'); | SELECT COUNT(*) FROM articles WHERE topic = 'investigative journalism' AND publish_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
How many unique passengers have traveled on each route, ordered by the number of passengers? | CREATE TABLE passenger (passenger_id INT,route_id INT,boarding_time TIMESTAMP,alighting_time TIMESTAMP); INSERT INTO passenger (passenger_id,route_id,boarding_time,alighting_time) VALUES (1,1,'2021-01-01 08:10:00','2021-01-01 08:20:00'),(2,1,'2021-01-01 08:30:00','2021-01-01 08:40:00'),(3,2,'2021-01-01 09:00:00','2021-... | SELECT route_id, COUNT(DISTINCT passenger_id) AS unique_passengers FROM passenger GROUP BY route_id ORDER BY unique_passengers DESC; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.