instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
List the top 3 countries with the most players in Mobile games. | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20),FavoriteGame VARCHAR(10)); INSERT INTO Players (PlayerID,Age,Gender,Country,FavoriteGame) VALUES (1,25,'Male','USA','Mobile'); INSERT INTO Players (PlayerID,Age,Gender,Country,FavoriteGame) VALUES (2,30,'Female','Canada','Mobile'); INSERT INTO Players (PlayerID,Age,Gender,Country,FavoriteGame) VALUES (3,22,'Male','Mexico','Mobile'); | SELECT Country, COUNT(PlayerID) as NumberOfPlayers FROM Players WHERE FavoriteGame = 'Mobile' GROUP BY Country ORDER BY NumberOfPlayers DESC LIMIT 3; |
Show the youngest player from the 'PlayerData' table | CREATE TABLE PlayerData (PlayerID INT,Name VARCHAR(50),Age INT,Country VARCHAR(50)); INSERT INTO PlayerData (PlayerID,Name,Age,Country) VALUES ('1','John Doe','25','USA'),('2','Jane Smith','30','Canada'),('3','Mike Johnson','22','USA'),('4','Sarah Lee','28','Canada'),('5','Lucas Martinez','35','Mexico'); | SELECT * FROM PlayerData ORDER BY Age LIMIT 1; |
What is the average age of players who play multiplayer games? | CREATE TABLE players (id INT,age INT,multiplayer BOOLEAN); INSERT INTO players (id,age,multiplayer) VALUES (1,25,true),(2,30,false),(3,22,true),(4,35,true); | SELECT AVG(age) FROM players WHERE multiplayer = true; |
What is the minimum price per kilogram of Gadolinium imported by South Korea from all countries in the last 5 years? | CREATE TABLE Gadolinium_Imports (id INT PRIMARY KEY,year INT,importing_country VARCHAR(20),exporting_country VARCHAR(20),quantity INT,price PER_KG); INSERT INTO Gadolinium_Imports (id,year,importing_country,exporting_country,quantity,price) VALUES (1,2017,'South Korea','Australia',15,17),(2,2018,'South Korea','Australia',16,18),(3,2019,'South Korea','Australia',17,19),(4,2020,'South Korea','Australia',18,20),(5,2021,'South Korea','Australia',19,21),(6,2017,'South Korea','China',16,18),(7,2018,'South Korea','China',17,19),(8,2019,'South Korea','China',18,20),(9,2020,'South Korea','China',19,21),(10,2021,'South Korea','China',20,22); | SELECT MIN(price) FROM Gadolinium_Imports WHERE importing_country = 'South Korea' GROUP BY year ORDER BY year DESC LIMIT 5; |
Insert new inclusive housing policies in Boston. | CREATE TABLE policies(id INT,city TEXT,policy TEXT); INSERT INTO policies(id,city,policy) VALUES (1,'Boston','Policy 1'); | INSERT INTO policies(id, city, policy) VALUES (2, 'Boston', 'Policy 2'); |
List the number of affordable housing units in each neighborhood of San Francisco. | CREATE TABLE affordable_housing (id INT,neighborhood VARCHAR(30),num_units INT); INSERT INTO affordable_housing (id,neighborhood,num_units) VALUES (1,'Mission',100),(2,'SoMa',150),(3,'Haight-Ashbury',120),(4,'Richmond',80),(5,'Sunset',130),(6,'Tenderloin',140),(7,'Chinatown',90),(8,'Nob Hill',70),(9,'Pacific Heights',60),(10,'Marina',50); | SELECT neighborhood, num_units FROM affordable_housing; |
What is the total number of co-owned properties in each location type? | CREATE TABLE co_ownership_location_count (id INT PRIMARY KEY,location VARCHAR(255),count INT); INSERT INTO co_ownership_location_count (id,location,count) VALUES (1,'urban',30),(2,'rural',15),(3,'suburban',20); | SELECT location, SUM(count) FROM co_ownership_location_count WHERE location IN ('urban', 'rural') GROUP BY location; |
What is the total number of inclusive housing policies in each city? | CREATE TABLE inclusive_housing (id INT,city VARCHAR(20),policy VARCHAR(50),start_date DATE); INSERT INTO inclusive_housing (id,city,policy,start_date) VALUES (1,'Boston','Accessible Housing Regulations','2018-01-01'),(2,'Boston','Affordable Housing Requirements','2019-05-01'),(3,'Chicago','Fair Housing Ordinance','2017-12-15'); | SELECT city, COUNT(DISTINCT policy) as num_policies FROM inclusive_housing GROUP BY city; |
How many products in each category are available in the inventory? | CREATE TABLE products (product_id int,name varchar(255),category varchar(255),quantity int); INSERT INTO products (product_id,name,category,quantity) VALUES (1,'Organic Cotton T-Shirt','Clothing',100),(2,'Regular Cotton T-Shirt','Clothing',150),(3,'Reusable Water Bottle','Home',200),(4,'LED Light Bulb','Electronics',50); | SELECT category, COUNT(*) FROM products GROUP BY category; |
What is the total quantity of products manufactured using ethical labor practices in each country? | CREATE TABLE country_ethical_chains (country VARCHAR(255),product_id INT,quantity INT,ethical_labor BOOLEAN,FOREIGN KEY (product_id) REFERENCES products(id)); | SELECT country, SUM(quantity) FROM country_ethical_chains WHERE ethical_labor = TRUE GROUP BY country; |
Find the number of operational satellites in low Earth orbit. | CREATE TABLE Satellites (Satellite_ID INT,Name VARCHAR(100),Orbit VARCHAR(50),Operational BOOLEAN); INSERT INTO Satellites (Satellite_ID,Name,Orbit,Operational) VALUES (1,'Starlink-1','Low Earth Orbit',TRUE),(2,'Galaxy 1R','Geostationary Orbit',FALSE); | SELECT COUNT(*) FROM Satellites WHERE Orbit = 'Low Earth Orbit' AND Operational = TRUE; |
What is the average age of astronauts from Japan? | CREATE TABLE astronauts (astronaut_id INT,name VARCHAR(255),gender VARCHAR(255),age INT,country VARCHAR(255),missions INT); INSERT INTO astronauts (astronaut_id,name,gender,age,country,missions) VALUES (1,'Takao Doi','Male',71,'Japan',3); | SELECT AVG(age) as avg_age FROM astronauts WHERE country = 'Japan'; |
What is the total number of spacecraft sent to Mars by any space agency? | CREATE TABLE mars_missions (id INT,mission_name VARCHAR(255),agency VARCHAR(255)); INSERT INTO mars_missions (id,mission_name,agency) VALUES (1,'Viking 1','NASA'); INSERT INTO mars_missions (id,mission_name,agency) VALUES (2,'Mars 3','Roscosmos'); | SELECT COUNT(*) FROM mars_missions; |
Identify the number of unique ticket buyers from California who attended more than three games in the last season. | CREATE TABLE ticket_sales (ticket_id INT,buyer_name VARCHAR(50),state VARCHAR(2),game_count INT); | SELECT COUNT(DISTINCT buyer_name) FROM ticket_sales WHERE state = 'CA' AND game_count > 3; |
What is the percentage of security incidents that were phishing attacks in the last quarter? | CREATE TABLE incident_types (incident_type_id INT,incident_type VARCHAR(255)); INSERT INTO incident_types (incident_type_id,incident_type) VALUES (1,'Phishing'),(2,'Malware'),(3,'Ransomware'),(4,'DDoS'),(5,'Insider Threat'),(6,'Data Breach'); | SELECT (COUNT(*) FILTER (WHERE incident_type = 'Phishing') * 100.0 / COUNT(*)) as phishing_percentage FROM incidents WHERE incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH); |
List all machinery malfunctions that affected union members in Texas since 2018-01-01, ordered by severity. | CREATE TABLE WorkplaceSafety (id INT PRIMARY KEY,union_id INT,incident_date DATE,incident_type VARCHAR(20),severity INT); CREATE TABLE UnionMembers (id INT PRIMARY KEY,name VARCHAR(50),state VARCHAR(2),union_id INT,FOREIGN KEY (union_id) REFERENCES UnionNegotiations(union_id)); CREATE TABLE UnionNegotiations (id INT PRIMARY KEY,union_id INT); | SELECT w.incident_date, w.incident_type, w.severity FROM WorkplaceSafety w JOIN UnionNegotiations n ON w.union_id = n.union_id JOIN UnionMembers m ON n.union_id = m.union_id WHERE m.state = 'TX' AND w.incident_date >= '2018-01-01' AND w.incident_type = 'Machinery Malfunction' ORDER BY w.severity DESC; |
Compute the average safety rating for hybrid vehicles | CREATE TABLE safety_ratings (id INT,vehicle_type VARCHAR(20),safety_rating DECIMAL(3,2)); INSERT INTO safety_ratings (id,vehicle_type,safety_rating) VALUES (1,'EV',4.5),(2,'EV',4.7),(3,'Hybrid',4.3),(4,'Hybrid',4.6),(5,'Conventional',4.2); | SELECT AVG(safety_rating) FROM safety_ratings WHERE vehicle_type = 'Hybrid'; |
What is the total number of electric vehicles sold in each city in Canada? | CREATE TABLE if not exists EVSales (Id int,Vehicle varchar(100),City varchar(100),Quantity int); INSERT INTO EVSales (Id,Vehicle,City,Quantity) VALUES (1,'Tesla Model 3','Toronto',1000),(2,'Nissan Leaf','Vancouver',800),(3,'Chevrolet Bolt','Montreal',1200),(4,'Tesla Model X','Calgary',600),(5,'Tesla Model S','Ottawa',900); | SELECT City, SUM(Quantity) FROM EVSales WHERE Country = 'Canada' GROUP BY City; |
How many visitors attended the Modern Art exhibition from the United States? | CREATE TABLE exhibitions (exhibition_id INT,name VARCHAR(255)); INSERT INTO exhibitions (exhibition_id,name) VALUES (1,'Art of the Renaissance'),(2,'Modern Art'); CREATE TABLE visitors (visitor_id INT,exhibition_id INT,country VARCHAR(50)); INSERT INTO visitors (visitor_id,exhibition_id,country) VALUES (1,1,'USA'),(2,1,'Canada'),(3,2,'USA'),(4,2,'Mexico'),(5,2,'Canada'); | SELECT COUNT(visitor_id) as num_visitors FROM visitors WHERE exhibition_id = 2 AND country = 'USA'; |
find the total attendance for exhibits 1 and 2 | CREATE TABLE exhibition_statistics (exhibit_id INT,attendance INT); INSERT INTO exhibition_statistics (exhibit_id,attendance) VALUES (1,500),(2,750); | SELECT SUM(attendance) FROM exhibition_statistics WHERE exhibit_id IN (1, 2); |
Update wastewater treatment records from 'New York' to have a 5% higher water volume | CREATE TABLE wastewater_treatment (id INT PRIMARY KEY,location VARCHAR(255),treatment_date DATE,water_volume INT); | UPDATE wastewater_treatment SET water_volume = water_volume * 1.05 WHERE location = 'New York'; |
What is the average water usage in Florida in 2020? | CREATE TABLE water_usage(state VARCHAR(20),year INT,usage FLOAT); | SELECT AVG(usage) FROM water_usage WHERE state='Florida' AND year=2020; |
Show the total workout duration for each workout type, excluding the ones that have a duration less than 30 minutes. | CREATE TABLE workout_data_ext(id INT,member_id INT,workout_type VARCHAR(20),workout_duration INT,country VARCHAR(20),additional_data VARCHAR(20)); INSERT INTO workout_data_ext(id,member_id,workout_type,workout_duration,country,additional_data) VALUES (1,1,'Running',60,'USA','Trail'),(2,2,'Yoga',20,'Canada','Home'),(3,3,'Running',45,'USA','Track'); | SELECT workout_type, SUM(workout_duration) FROM workout_data_ext WHERE workout_duration >= 30 GROUP BY workout_type; |
List community development initiatives and their funding sources from the 'rural_development' database | CREATE TABLE community_development (id INT,initiative VARCHAR(50),description TEXT,lead_organization VARCHAR(50),funding_source VARCHAR(50)); INSERT INTO community_development (id,initiative,description,lead_organization,funding_source) VALUES (1,'Youth Center','A place for local youth to gather and learn','Local NGO','Government Grant'); INSERT INTO community_development (id,initiative,description,lead_organization,funding_source) VALUES (2,'Community Garden','A green space for residents to grow food','Municipal Government','Local Donations'); | SELECT initiative, lead_organization, funding_source FROM community_development; |
What is the total budget for all agricultural innovation projects in the 'rural_infrastructure' table? | CREATE TABLE rural_infrastructure (project_name VARCHAR(255),project_type VARCHAR(255),budget INT); INSERT INTO rural_infrastructure (project_name,project_type,budget) VALUES ('Greenhouse Project','Agricultural Innovation',50000),('Drip Irrigation System','Agricultural Innovation',30000); | SELECT SUM(budget) FROM rural_infrastructure WHERE project_type = 'Agricultural Innovation'; |
How many successful orbital launches did Russia have in 2021? | CREATE TABLE RussianLaunches (id INT,launch_date DATE,launch_result VARCHAR(10),launch_country VARCHAR(50)); | SELECT COUNT(*) FROM RussianLaunches WHERE launch_date BETWEEN '2021-01-01' AND '2021-12-31' AND launch_result = 'Success'; |
What is the average delivery time for satellites by manufacturer, considering only successful launches? | CREATE TABLE SatelliteLaunch (id INT,satellite_name VARCHAR(255),manufacturer VARCHAR(255),launch_outcome VARCHAR(255),launch_date DATE); INSERT INTO SatelliteLaunch (id,satellite_name,manufacturer,launch_outcome,launch_date) VALUES (1,'Sat1','SpaceTech Inc.','successful','2018-12-12'),(2,'Sat2','Galactic Systems','unsuccessful','2019-06-28'),(3,'Sat3','SpaceTech Inc.','successful','2021-03-02'); | SELECT manufacturer, AVG(DATEDIFF(launch_date, (SELECT MIN(launch_date) FROM SatelliteLaunch sl2 WHERE sl2.manufacturer = sl.manufacturer AND launch_outcome = 'successful'))) AS avg_delivery_time FROM SatelliteLaunch sl WHERE launch_outcome = 'successful' GROUP BY manufacturer; |
What is the total cost of aircraft orders for each manufacturer? | CREATE TABLE aircraft_orders (order_id INT,aircraft_id INT,manufacturer VARCHAR(50),cost DECIMAL(10,2)); CREATE TABLE aircraft (aircraft_id INT,manufacturer VARCHAR(50)); | SELECT manufacturer, SUM(cost) as total_cost FROM aircraft_orders JOIN aircraft ON aircraft_orders.aircraft_id = aircraft.aircraft_id GROUP BY manufacturer; |
How many animals of each type were in rehabilitation centers as of January 1, 2020? | CREATE TABLE AnimalRehabilitation (center_id INT,animal_type VARCHAR(20),num_animals INT,date DATE); INSERT INTO AnimalRehabilitation (center_id,animal_type,num_animals,date) VALUES (1,'Tiger',10,'2019-12-31'),(1,'Elephant',15,'2019-12-31'),(2,'Tiger',12,'2019-12-31'),(2,'Elephant',18,'2019-12-31'),(3,'Tiger',8,'2019-12-31'),(3,'Elephant',20,'2019-12-31'); | SELECT animal_type, num_animals FROM AnimalRehabilitation WHERE date = '2020-01-01'; |
How many music_concerts were held in Paris and Berlin? | CREATE TABLE music_concerts (id INT,concert_location VARCHAR(50)); INSERT INTO music_concerts (id,concert_location) VALUES (1,'Paris'),(2,'Berlin'),(3,'London'),(4,'New York'); | SELECT COUNT(*) FROM music_concerts WHERE concert_location IN ('Paris', 'Berlin'); |
What was the number of attendees for events in the 'Theater' category? | CREATE TABLE event_attendance (id INT,event_id INT,attendee_count INT); INSERT INTO event_attendance (id,event_id,attendee_count) VALUES (1,1,250),(2,2,320),(3,3,175); CREATE TABLE events (id INT,category VARCHAR(10)); INSERT INTO events (id,category) VALUES (1,'Dance'),(2,'Music'),(3,'Theater'); | SELECT SUM(attendee_count) FROM event_attendance JOIN events ON event_attendance.event_id = events.id WHERE events.category = 'Theater'; |
What was the total expenditure by each department in the last fiscal quarter? | CREATE TABLE Expenditures (ExpenseID INT,ExpenseDate DATE,ExpenseType VARCHAR(20),ExpenseAmount DECIMAL(10,2)); INSERT INTO Expenditures (ExpenseID,ExpenseDate,ExpenseType,ExpenseAmount) VALUES (1,'2022-04-01','Marketing',15000.00),(2,'2022-05-01','Operations',25000.00),(3,'2022-06-01','Marketing',18000.00); | SELECT ExpenseType, SUM(ExpenseAmount) FROM Expenditures WHERE ExpenseDate >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) AND ExpenseDate < LAST_DAY(CURDATE()) GROUP BY ExpenseType; |
Insert a new record for 'DrugG' sales in 'Q4 2021' with '7000' units sold. | CREATE TABLE sales (drug_name TEXT,quarter TEXT,year INTEGER,units_sold INTEGER); | INSERT INTO sales (drug_name, quarter, year, units_sold) VALUES ('DrugG', 'Q4', 2021, 7000); |
How many innovations have been made in the African region since 2016? | CREATE TABLE region (id INT,region VARCHAR(50)); INSERT INTO region (id,region) VALUES (1,'North America'); INSERT INTO region (id,region) VALUES (2,'Europe'); INSERT INTO region (id,region) VALUES (3,'Africa'); CREATE TABLE innovation_region (id INT,innovation_id INT,region_id INT); INSERT INTO innovation_region (id,innovation_id,region_id) VALUES (1,1,1); INSERT INTO innovation_region (id,innovation_id,region_id) VALUES (2,2,2); INSERT INTO innovation_region (id,innovation_id,region_id) VALUES (3,3,3); CREATE TABLE innovation (id INT,year INT); INSERT INTO innovation (id,year) VALUES (1,2015); INSERT INTO innovation (id,year) VALUES (2,2016); INSERT INTO innovation (id,year) VALUES (3,2017); | SELECT COUNT(*) FROM innovation i INNER JOIN innovation_region ir ON i.id = ir.innovation_id INNER JOIN region r ON ir.region_id = r.id WHERE r.region = 'Africa' AND i.year >= 2016; |
List funding amounts and corresponding diversity scores for companies founded in 2018 | CREATE TABLE companies (id INT,name VARCHAR(50),founding_year INT,diversity_score DECIMAL(3,2)); CREATE TABLE funds (id INT,company_id INT,funding_amount DECIMAL(10,2)); INSERT INTO companies VALUES (1,'Acme Corp',2018,0.85); INSERT INTO companies VALUES (2,'Beta Inc',2015,0.70); INSERT INTO funds VALUES (1,1,50000); INSERT INTO funds VALUES (2,2,75000); | SELECT companies.name, funds.funding_amount, companies.diversity_score FROM companies INNER JOIN funds ON companies.id = funds.company_id WHERE companies.founding_year = 2018; |
List the diversity metrics for startups founded in '2018'. | CREATE TABLE diversity_metrics (id INT,startup_name VARCHAR(50),founding_year INT,female_founders INT,underrepresented_teams INT); | SELECT startup_name, female_founders, underrepresented_teams FROM diversity_metrics WHERE founding_year = 2018; |
List all marine protected areas in the Pacific Ocean. | CREATE TABLE marine_protected_areas (area_id INTEGER,area_name TEXT,ocean_basin TEXT); | SELECT area_name FROM marine_protected_areas WHERE ocean_basin = 'Pacific Ocean'; |
Delete records in the species table where the common_name is 'White Oak' | CREATE TABLE species (id INT PRIMARY KEY,common_name TEXT,scientific_name TEXT,region TEXT); INSERT INTO species (id,common_name,scientific_name,region) VALUES (1,'White Oak','Quercus alba','North America'); | DELETE FROM species WHERE common_name = 'White Oak'; |
What is the average carbon sequestration rate for forests in tropical regions? | CREATE TABLE forests (id INT,name VARCHAR(50),region VARCHAR(50),carbon_sequestration_rate DECIMAL(5,2)); INSERT INTO forests (id,name,region,carbon_sequestration_rate) VALUES (1,'Forest 1','Tropical',2.50),(2,'Forest 2','Temperate',1.80),(3,'Forest 3','Tropical',3.20),(4,'Forest 4','Temperate',2.00); | SELECT AVG(f.carbon_sequestration_rate) FROM forests f WHERE f.region = 'Tropical'; |
What is the total area of all wildlife habitats, in hectares, for each type of habitat? | CREATE TABLE wildlife_habitat_2 (id INT,habitat_type VARCHAR(255),area FLOAT); INSERT INTO wildlife_habitat_2 (id,habitat_type,area) VALUES (1,'Forest',150000.0),(2,'Wetlands',120000.0),(3,'Forest',200000.0),(4,'Grasslands',180000.0),(5,'Desert',100000.0); | SELECT habitat_type, SUM(area) FROM wildlife_habitat_2 GROUP BY habitat_type; |
List the top 5 countries with the highest average foundation sales revenue in H2 2021. | CREATE TABLE cosmetics_sales(country VARCHAR(255),product_type VARCHAR(255),sales_quantity INT,sales_revenue DECIMAL(10,2)); | SELECT country, AVG(sales_revenue) as avg_rev FROM cosmetics_sales WHERE product_type = 'foundation' AND sales_date BETWEEN '2021-07-01' AND '2021-12-31' GROUP BY country ORDER BY avg_rev DESC LIMIT 5; |
Insert a new record into the 'FireDepartments' table with the following data: '890', 'Eastside Fire Department', 2000 | CREATE TABLE FireDepartments (DepartmentID INT PRIMARY KEY,DepartmentName VARCHAR(50),EstablishedYear INT); | INSERT INTO FireDepartments (DepartmentID, DepartmentName, EstablishedYear) VALUES (890, 'Eastside Fire Department', 2000); |
What is the maximum number of crimes reported in a single day in 'Harbor' district? | CREATE TABLE daily_crimes (date DATE,district VARCHAR(20),crimes_reported INT); INSERT INTO daily_crimes (date,district,crimes_reported) VALUES ('2022-01-01','Harbor',3),('2022-01-02','Harbor',5),('2022-01-03','Harbor',4),('2022-01-04','Harbor',2),('2022-01-05','Harbor',7); | SELECT MAX(crimes_reported) FROM daily_crimes WHERE district = 'Harbor'; |
Calculate the total ticket revenue for events in the 'events' table. | CREATE TABLE events (event_id INT,name VARCHAR(50),location VARCHAR(50),date DATE,type VARCHAR(50),ticket_price DECIMAL(5,2),attendance INT); | SELECT SUM(ticket_price * attendance) as total_revenue FROM events; |
How many veteran employment applications were submitted in California in 2018? | CREATE TABLE Veteran_Employment (ID INT,State VARCHAR(50),Year INT,Applications INT); INSERT INTO Veteran_Employment (ID,State,Year,Applications) VALUES (1,'California',2016,200),(2,'California',2018,300),(3,'New_York',2017,250); | SELECT Applications FROM Veteran_Employment WHERE State = 'California' AND Year = 2018; |
How many peacekeeping operations were led by the Association of Southeast Asian Nations (ASEAN) in the past decade? | CREATE SCHEMA if not exists peacekeeping;CREATE TABLE if not exists asean_operations (id INT,operation_name VARCHAR(255),operation_start_date DATE,operation_end_date DATE); INSERT INTO asean_operations (id,operation_name,operation_start_date,operation_end_date) VALUES (1,'ASEAN Peacekeeping Force','2011-05-15','2022-01-01'); | SELECT COUNT(*) FROM asean_operations WHERE operation_start_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 10 YEAR) AND CURRENT_DATE; |
What is the maximum number of peacekeeping troops deployed by any country in a single peacekeeping operation? | CREATE TABLE PeacekeepingTroops (TroopID INT,OperationID INT,Country VARCHAR(50),NumberOfTroops INT); | SELECT OperationID, MAX(NumberOfTroops) FROM PeacekeepingTroops GROUP BY OperationID; |
What is the total number of military innovation projects and military personnel for each country involved in defense diplomacy? | CREATE TABLE defense_diplomacy (id INT,country VARCHAR,military_personnel INT,project_count INT); | SELECT country, SUM(military_personnel) AS total_military_personnel, SUM(project_count) AS total_projects FROM defense_diplomacy GROUP BY country; |
How many high-risk accounts are in the Asia-Pacific region with a balance greater than $100,000? | CREATE TABLE accounts (id INT,region VARCHAR(20),risk_level VARCHAR(10),balance DECIMAL(15,2)); INSERT INTO accounts (id,region,risk_level,balance) VALUES (1,'Asia-Pacific','high',120000.00),(2,'Europe','medium',80000.00),(3,'North America','low',50000.00),(4,'Asia-Pacific','high',150000.00); | SELECT COUNT(*) FROM accounts WHERE region = 'Asia-Pacific' AND risk_level = 'high' AND balance > 100000.00; |
List all clients with their age and the total number of investments they made? | CREATE TABLE clients (client_id INT,name TEXT,age INT,gender TEXT); INSERT INTO clients VALUES (1,'John Doe',35,'Male'),(2,'Jane Smith',45,'Female'),(3,'Bob Johnson',50,'Male'); CREATE TABLE investments (client_id INT,investment_type TEXT); INSERT INTO investments VALUES (1,'Stocks'),(1,'Bonds'),(2,'Stocks'),(2,'Mutual Funds'),(3,'Mutual Funds'),(3,'Real Estate'); | SELECT c.age, COUNT(i.investment_type) AS num_investments FROM clients c LEFT JOIN investments i ON c.client_id = i.client_id GROUP BY c.client_id; |
Find the total unloaded cargo weight in the US for each flag. | CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT,unloaded_weight FLOAT,vessel_flag TEXT); INSERT INTO ports (port_id,port_name,country,unloaded_weight,vessel_flag) VALUES (1,'Los Angeles','USA',9876543.21,'Panama'),(2,'New York','USA',7654321.89,'Liberia'),(3,'Houston','USA',3218976.54,'Marshall Islands'); | SELECT vessel_flag, SUM(unloaded_weight) AS total_weight FROM ports WHERE country = 'USA' GROUP BY vessel_flag; |
List the ports that have been visited by vessels with a maximum cargo capacity of over 20000 tons in Q4 2020. | CREATE TABLE Port_Visits (id INT,vessel VARCHAR(255),capacity INT,port VARCHAR(255),time DATETIME); INSERT INTO Port_Visits (id,vessel,capacity,port,time) VALUES (1,'Arctic Explorer',25000,'Oslo','2020-12-01 10:00:00'),(2,'Sea Titan',18000,'Reykjavik','2020-11-15 15:30:00'); | SELECT DISTINCT port FROM Port_Visits PV JOIN (SELECT vessel, capacity FROM Vessels WHERE capacity > 20000) V ON PV.vessel = V.vessel WHERE MONTH(time) BETWEEN 10 AND 12 AND YEAR(time) = 2020; |
What is the total production output of factories in each country? | CREATE TABLE factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),country VARCHAR(100),production_output INT); INSERT INTO factories (factory_id,name,location,country,production_output) VALUES (1,'ABC Factory','New York','USA',5500),(2,'XYZ Factory','California','USA',4000),(3,'LMN Factory','Texas','USA',6000),(4,'PQR Factory','Toronto','Canada',7000); | SELECT country, SUM(production_output) FROM factories GROUP BY country; |
Determine the percentage change in national security budgets for the last 3 years, per region. | CREATE TABLE budgets (budget_year INT,region_id INT,budget_amount INT); INSERT INTO budgets (budget_year,region_id,budget_amount) VALUES (2019,1,500),(2020,1,600),(2021,1,700),(2019,2,400),(2020,2,450),(2021,2,500); | SELECT budget_year, region_id, budget_amount, (budget_amount - LAG(budget_amount, 1) OVER (PARTITION BY region_id ORDER BY budget_year)) * 100.0 / LAG(budget_amount, 1) OVER (PARTITION BY region_id ORDER BY budget_year) as percentage_change FROM budgets WHERE budget_year >= YEAR(CURRENT_DATE) - 3; |
List all cybersecurity incidents and their respective severity levels in the Asia-Pacific region since 2020. | CREATE TABLE cybersecurity_incidents (id INT PRIMARY KEY,incident_name VARCHAR(255),severity INT,date DATE); INSERT INTO cybersecurity_incidents (id,incident_name,severity,date) VALUES (1,'SolarWinds Hack',9,'2020-03-26'); | SELECT incident_name, severity FROM cybersecurity_incidents WHERE date >= '2020-01-01' AND location LIKE '%Asia-Pacific%'; |
Show all cybersecurity strategies along with their respective authors. | CREATE TABLE cybersecurity_strategies (id INT,strategy VARCHAR(50),author VARCHAR(30)); INSERT INTO cybersecurity_strategies (id,strategy,author) VALUES (1,'Zero Trust Architecture','John Smith'); INSERT INTO cybersecurity_strategies (id,strategy,author) VALUES (2,'Multi-Factor Authentication','Jane Doe'); | SELECT strategy, author FROM cybersecurity_strategies; |
What are the types and severities of cybersecurity incidents that occurred before '2021-03-01'? | CREATE TABLE Cyber_Incidents (incident_id INT,incident_date DATE,incident_type VARCHAR(50),incident_severity INT); INSERT INTO Cyber_Incidents (incident_id,incident_date,incident_type,incident_severity) VALUES (1,'2021-01-01','Phishing',3); INSERT INTO Cyber_Incidents (incident_id,incident_date,incident_type,incident_severity) VALUES (2,'2021-02-15','Malware',5); | SELECT incident_type, incident_severity FROM Cyber_Incidents WHERE incident_date < '2021-03-01'; |
What is the total number of military bases and their types in the Asia-Pacific region? | CREATE TABLE military_bases (id INT,name VARCHAR(255),type VARCHAR(255),region VARCHAR(255)); INSERT INTO military_bases (id,name,type,region) VALUES (1,'Base 1','Air Force','Asia-Pacific'),(2,'Base 2','Navy','Asia-Pacific'); | SELECT COUNT(*), type FROM military_bases WHERE region = 'Asia-Pacific' GROUP BY type; |
Which artists have the most followers on Instagram, by genre? | CREATE TABLE artists (artist_id INT,artist VARCHAR(100),genre VARCHAR(50),followers INT); CREATE VIEW followers_view AS SELECT artist_id,SUM(followers) AS total_followers FROM instagram_data GROUP BY artist_id; | SELECT g.genre, a.artist, f.total_followers FROM artists a JOIN genres g ON a.genre = g.genre JOIN followers_view f ON a.artist_id = f.artist_id ORDER BY total_followers DESC; |
How many games did each NBA team play in the 2021-2022 season? | CREATE TABLE nba_schedule (team TEXT,games INT); INSERT INTO nba_schedule (team,games) VALUES ('Warriors',82),('Celtics',82),('Bucks',82); | SELECT team, COUNT(*) as games FROM nba_schedule GROUP BY team; |
Update the names of athletes whose names start with 'J' to 'X' | CREATE TABLE athletes (athlete_id INT,name VARCHAR(50),sport VARCHAR(50),join_year INT); INSERT INTO athletes (athlete_id,name,sport,join_year) VALUES (1,'Jane Doe','Basketball',2021),(2,'John Smith','Soccer',2019); | UPDATE athletes SET name = REPLACE(name, 'J', 'X') WHERE name LIKE 'J%'; |
What is the total number of penalties awarded to football team 306? | CREATE TABLE penalties (penalty_id INT,player_id INT,match_id INT,team_id INT,penalties INT); INSERT INTO penalties (penalty_id,player_id,match_id,team_id,penalties) VALUES (1,10,11,306,2); | SELECT SUM(penalties) FROM penalties WHERE team_id = 306; |
Identify all the unique beneficiaries in Nepal who received support from the 'education' sector in 2021, the number of times they received support, and the total amount donated to each. | CREATE TABLE beneficiaries (id INT,name TEXT,country TEXT); INSERT INTO beneficiaries VALUES (1,'Sita','Nepal'); CREATE TABLE support (id INT,beneficiary_id INT,sector TEXT,support_date YEAR,amount INT); INSERT INTO support VALUES (1,1,'education',2021,200); | SELECT beneficiaries.name, COUNT(support.id), SUM(support.amount) FROM beneficiaries INNER JOIN support ON beneficiaries.id = support.beneficiary_id WHERE beneficiaries.country = 'Nepal' AND support.sector = 'education' AND support.support_date = 2021 GROUP BY beneficiaries.id; |
What is the average production cost of garments made from organic cotton, per country? | CREATE TABLE OrganicCottonGarments (id INT,country VARCHAR(50),production_cost DECIMAL(5,2)); | SELECT country, AVG(production_cost) as avg_cost FROM OrganicCottonGarments GROUP BY country; |
What is the total CO2 emissions of silk production in China? | CREATE TABLE SilkProduction (id INT,country VARCHAR,co2_emissions INT); | SELECT SUM(co2_emissions) FROM SilkProduction WHERE country = 'China'; |
Find the top 5 most active users in 'user_behavior' table in the last month? | CREATE TABLE user_behavior (user_id INT,post_date DATE,posts_per_day INT); | SELECT user_id, SUM(posts_per_day) FROM user_behavior WHERE post_date >= CURDATE() - INTERVAL 1 MONTH GROUP BY user_id ORDER BY SUM(posts_per_day) DESC LIMIT 5; |
Update the "status" column to 'active' for all users with more than 1000 followers in the "users" table | CREATE TABLE users (id INT,username VARCHAR(255),followers INT,status VARCHAR(255)); | UPDATE users SET status = 'active' WHERE followers > 1000; |
What is the total revenue generated from ads on Instagram in March 2021, for users in the 'brand' category who have posted more than 10 times? | CREATE TABLE ads (ad_id INT,user_id INT,platform VARCHAR(255),ad_revenue DECIMAL(10,2),post_count INT); INSERT INTO ads (ad_id,user_id,platform,ad_revenue,post_count) VALUES (1,1,'Instagram',150.50,12),(2,2,'Twitter',80.00,15),(3,3,'Instagram',120.75,8); | SELECT SUM(ad_revenue) FROM ads WHERE platform = 'Instagram' AND MONTH(ad_date) = 3 AND YEAR(ad_date) = 2021 AND user_id IN (SELECT user_id FROM users WHERE category = 'brand' AND post_count > 10); |
How many socially responsible loans were issued to customers in the South? | CREATE TABLE loans (loan_number INT,customer_name VARCHAR(50),issue_date DATE,is_socially_responsible BOOLEAN,region VARCHAR(20)); INSERT INTO loans (loan_number,customer_name,issue_date,is_socially_responsible,region) VALUES (1,'Ahmed','2021-01-01',true,'South'),(2,'Sara','2021-02-15',false,'North'),(3,'Mohammed','2021-03-03',true,'South'); | SELECT COUNT(*) FROM loans WHERE is_socially_responsible = true AND region = 'South'; |
What is the maximum socially responsible loan amount? | CREATE TABLE loans (id INT PRIMARY KEY,loan_id INT,amount INT,client_id INT,is_socially_responsible BOOLEAN); | SELECT MAX(loans.amount) as max_loan_amount FROM loans WHERE loans.is_socially_responsible = TRUE; |
What was the total amount of Shariah-compliant finance loans issued to micro businesses in 2021? | CREATE TABLE shariah_compliant_finance (id INT PRIMARY KEY,loan_amount DECIMAL(10,2),borrower_type TEXT,lending_date DATE); | SELECT SUM(loan_amount) FROM shariah_compliant_finance WHERE borrower_type = 'Micro Business' AND lending_date BETWEEN '2021-01-01' AND '2021-12-31'; |
What is the monthly donation trend for the last 12 months? | CREATE TABLE Donations (DonationID INT,DonationDate DATE,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonationDate,DonationAmount) VALUES (1,'2022-01-15',200.00),(2,'2022-02-20',250.00),(3,'2022-03-05',300.00); | SELECT EXTRACT(MONTH FROM DonationDate) as Month, ROUND(AVG(DonationAmount), 2) as AvgDonation FROM Donations WHERE DonationDate >= DATE_TRUNC('year', CURRENT_DATE - INTERVAL '1 year') AND DonationDate < DATE_TRUNC('year', CURRENT_DATE) GROUP BY Month ORDER BY Month; |
What was the total amount donated by individuals in the United States in Q1 2021? | CREATE TABLE donations (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (donor_id,donation_amount,donation_date) VALUES (1,50.00,'2021-01-05'),(2,100.00,'2021-03-15'); | SELECT SUM(donation_amount) FROM donations WHERE donation_date BETWEEN '2021-01-01' AND '2021-03-31' AND donor_id IN (SELECT donor_id FROM donors WHERE country = 'United States'); |
List all warehouse locations and their corresponding total inventory value. | CREATE TABLE warehouse (id INT,location VARCHAR(20),total_inventory DECIMAL(10,2)); INSERT INTO warehouse (id,location,total_inventory) VALUES (1,'Atlanta',2000.00),(2,'Dallas',3000.00); | SELECT location, total_inventory FROM warehouse; |
What is the total quantity of items in the 'inventory' table? | CREATE TABLE inventory (item_id INT,item_name VARCHAR(20),quantity INT); INSERT INTO inventory (item_id,item_name,quantity) VALUES (1,'apples',50),(2,'bananas',75),(3,'oranges',30); | SELECT SUM(quantity) FROM inventory; |
List biotech startups founded before 2010. | CREATE TABLE startups (id INT,name VARCHAR(50),location VARCHAR(50),industry VARCHAR(50),founding_date DATE); | SELECT name FROM startups WHERE industry = 'biotech' AND founding_date < '2010-01-01'; |
What is the total funding amount for all biotech startups? | CREATE TABLE biotech_startups (id INT,name TEXT,location TEXT,funding_amount INT); INSERT INTO biotech_startups (id,name,location,funding_amount) VALUES (1,'GenSolutions','California',12000000),(2,'BioInnovate','Texas',20000000),(3,'TechGen','Texas',15000000); | SELECT SUM(funding_amount) FROM biotech_startups; |
What is the total number of public transportation projects and their total budget for projects located in 'Rural' area, grouped by transportation type? | CREATE TABLE projects (project_id INT,project_name VARCHAR(50),budget DECIMAL(10,2),area VARCHAR(50),transportation_type VARCHAR(50)); INSERT INTO projects (project_id,project_name,budget,area,transportation_type) VALUES (4,'ProjectA',7000000.00,'Rural','Bus'),(5,'ProjectB',6000000.00,'Rural','Train'),(6,'ProjectC',8000000.00,'Rural','Bus'); | SELECT transportation_type, COUNT(*) AS total_projects, SUM(budget) AS total_budget FROM projects WHERE area = 'Rural' GROUP BY transportation_type; |
List Smart City initiatives and their corresponding countries. | CREATE TABLE Countries (id INT,name VARCHAR(50)); INSERT INTO Countries (id,name) VALUES (1,'CountryA'),(2,'CountryB'); CREATE TABLE SmartCities (id INT,country_id INT,initiative VARCHAR(50)); INSERT INTO SmartCities (id,country_id,initiative) VALUES (1,1,'InitiativeA'),(2,1,'InitiativeB'),(3,2,'InitiativeC'); | SELECT SmartCities.initiative, Countries.name FROM SmartCities INNER JOIN Countries ON SmartCities.country_id = Countries.id; |
List all renewable energy infrastructure projects in the African region and their respective costs. | CREATE TABLE renewable_energy_infrastructure (project_id INT,project_name VARCHAR(50),region VARCHAR(20),cost DECIMAL(10,2)); INSERT INTO renewable_energy_infrastructure (project_id,project_name,region,cost) VALUES (1,'Hydroelectric Dam','Africa',30000000.00),(2,'Biomass Plant','Europe',25000000.00),(3,'Wind Farm','Asia',18000000.00); | SELECT project_name, cost FROM renewable_energy_infrastructure WHERE region = 'Africa'; |
What is the total number of Green buildings in India certified by GRIHA? | CREATE TABLE green_buildings (id INT,project_name VARCHAR(100),certifier VARCHAR(50),country VARCHAR(50)); INSERT INTO green_buildings (id,project_name,certifier,country) VALUES (1,'Eco Tower','LEED','India'),(2,'Green Heights','BREEAM','UK'),(3,'Sustainable Plaza','GRIHA','India'); | SELECT COUNT(*) FROM green_buildings WHERE certifier = 'GRIHA' AND country = 'India'; |
Add a new sustainable practice to 'sustainable_practices' table | CREATE TABLE sustainable_practices (id INT PRIMARY KEY,name VARCHAR(255),description TEXT); | INSERT INTO sustainable_practices (id, name, description) VALUES (1, 'Refillable Water Bottles', 'Promote reusable water bottles to reduce plastic waste.'); |
What is the average number of eco-friendly tours offered per hotel in Paris? | CREATE TABLE hotels (id INT,city VARCHAR(20)); INSERT INTO hotels (id,city) VALUES (1,'Paris'),(2,'Berlin'); CREATE TABLE tours (id INT,hotel_id INT,eco_friendly BOOLEAN); INSERT INTO tours (id,hotel_id,eco_friendly) VALUES (1,1,true),(2,1,false),(3,2,true); | SELECT AVG(t.eco_friendly) FROM tours t JOIN hotels h ON t.hotel_id = h.id WHERE h.city = 'Paris' AND t.eco_friendly = true; |
What is the percentage of revenue generated from sustainable tourism in Europe? | CREATE TABLE tourism_revenue (revenue_id INT,revenue_type TEXT,region TEXT,amount FLOAT); INSERT INTO tourism_revenue (revenue_id,revenue_type,region,amount) VALUES (1,'Sustainable Tourism','Europe',500000.00),(2,'Traditional Tourism','Europe',1000000.00); | SELECT 100.0 * SUM(CASE WHEN revenue_type = 'Sustainable Tourism' THEN amount ELSE 0 END) / SUM(amount) as percentage FROM tourism_revenue WHERE region = 'Europe'; |
Which sites in New York City, USA have more than 100000 annual visitors and what are their preferred languages? | CREATE TABLE Cultural_Heritage_Sites (id INT,name VARCHAR(255),location VARCHAR(255),year_established INT,PRIMARY KEY(id)); INSERT INTO Cultural_Heritage_Sites (id,name,location,year_established) VALUES (1,'Statue of Liberty','New York City,USA',1886); CREATE TABLE User_Preferences (id INT,user_id INT,preferred_language VARCHAR(255),PRIMARY KEY(id),FOREIGN KEY (user_id) REFERENCES Users(id)); INSERT INTO User_Preferences (id,user_id,preferred_language) VALUES (1,1,'Spanish'),(2,1,'English'); | SELECT c.name, COUNT(u.id) as annual_visitors, p.preferred_language FROM Cultural_Heritage_Sites c JOIN User_Preferences p ON c.id = p.user_id GROUP BY c.name HAVING annual_visitors > 100000; |
List the booking dates and hotel names for all OTA bookings where the hotel has implemented at least one AI-powered solution. | CREATE TABLE otas (ota_id INT,booking_date DATE,hotel_id INT); CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,region TEXT); CREATE TABLE ai_solutions (solution_id INT,hotel_id INT,implemented_date DATE); INSERT INTO hotels (hotel_id,hotel_name,region) VALUES (1,'Beach Retreat','Americas'); INSERT INTO ai_solutions (solution_id,hotel_id,implemented_date) VALUES (1,1,'2021-02-01'); INSERT INTO otas (ota_id,booking_date,hotel_id) VALUES (1,'2021-04-01',1); | SELECT otas.booking_date, hotels.hotel_name FROM otas INNER JOIN hotels ON otas.hotel_id = hotels.hotel_id INNER JOIN ai_solutions ON hotels.hotel_id = ai_solutions.hotel_id GROUP BY otas.booking_date, hotels.hotel_name HAVING COUNT(DISTINCT ai_solutions.solution_id) >= 1; |
Display the names and founding years of art galleries established after 1950 that have hosted exhibitions featuring artists from Africa or the African Diaspora. | CREATE TABLE art_galleries (name TEXT,founding_year INTEGER); INSERT INTO art_galleries (name,founding_year) VALUES ('Tate Modern',2000),('MoMA',1929),('Guggenheim Museum',1939); CREATE TABLE exhibitions (gallery_name TEXT,artist_name TEXT,exhibition_year INTEGER); INSERT INTO exhibitions (gallery_name,artist_name,exhibition_year) VALUES ('Tate Modern','Chris Ofili',2005),('MoMA','Kehinde Wiley',2016),('Guggenheim Museum','Theaster Gates',2018); | SELECT ag.name, ag.founding_year FROM art_galleries ag INNER JOIN exhibitions e ON ag.name = e.gallery_name WHERE ag.founding_year > 1950 AND (e.artist_name LIKE 'African%' OR e.artist_name LIKE 'Diaspora%'); |
What are the names and languages of the heritages sites located in Africa? | CREATE TABLE Heritages (id INT,name TEXT,location TEXT); INSERT INTO Heritages (id,name,location) VALUES (1,'Giza Pyramids','Egypt'); CREATE TABLE Languages (id INT,site_id INT,language TEXT); INSERT INTO Languages (id,site_id,language) VALUES (1,1,'Egyptian Arabic'); | SELECT H.name, L.language FROM Heritages H INNER JOIN Languages L ON H.id = L.site_id WHERE H.location = 'Africa'; |
What is the average age of patients who received therapy in the state of California? | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,state) VALUES (1,35,'Female','California'); INSERT INTO patients (patient_id,age,gender,state) VALUES (2,42,'Male','Texas'); | SELECT AVG(age) FROM patients WHERE state = 'California' AND therapy_type IS NOT NULL; |
What is the maximum water depth for dams in Australia? | CREATE TABLE Dam (id INT,name TEXT,location TEXT,max_depth FLOAT,height FLOAT); INSERT INTO Dam (id,name,location,max_depth,height) VALUES (1,'Snowy Mountains Dam','NSW,Australia',120,160); | SELECT MAX(max_depth) FROM Dam WHERE location LIKE '%Australia%' AND type = 'Dam'; |
Find the average visitor count for natural attractions in Antarctica. | CREATE TABLE antarctica_attractions (id INT,name TEXT,visitors INT); INSERT INTO antarctica_attractions VALUES (1,'South Pole',10000),(2,'Ross Ice Shelf',5000),(3,'Lemaire Channel',8000); | SELECT AVG(visitors) FROM antarctica_attractions; |
What is the success rate of alternative dispute resolution methods, by type and resolution method? | CREATE TABLE disputes (dispute_id INT,type VARCHAR(20),resolution_method VARCHAR(20),success BOOLEAN); INSERT INTO disputes (dispute_id,type,resolution_method,success) VALUES (1,'Civil','Mediation',true),(2,'Criminal','Restorative Justice',false),(3,'Civil','Arbitration',true); | SELECT disputes.type, disputes.resolution_method, AVG(disputes.success) as success_rate FROM disputes GROUP BY disputes.type, disputes.resolution_method; |
Delete all invasive species records from the year 2020 in the 'MarineLife' table | CREATE TABLE MarineLife (id INT,species VARCHAR(50),population INT,last_sighting DATE); INSERT INTO MarineLife (id,species,population,last_sighting) VALUES (1,'Shark',500,'2019-01-01'),(2,'Starfish',3000,'2020-05-15'),(3,'Jellyfish',1500,'2018-12-27'),(4,'Lionfish',800,'2020-07-08'); | DELETE FROM MarineLife WHERE species = 'Lionfish' AND YEAR(last_sighting) = 2020; |
Which countries have the highest and lowest media representation scores in South America? | CREATE TABLE media_representation (id INT,user_id INT,country VARCHAR(50),region VARCHAR(50),score INT); INSERT INTO media_representation (id,user_id,country,region,score) VALUES (7,7,'Argentina','South America',82),(8,8,'Brazil','South America',78),(9,9,'Colombia','South America',74),(10,10,'Peru','South America',71),(11,11,'Chile','South America',69); | SELECT country, score FROM media_representation WHERE region = 'South America' ORDER BY score DESC LIMIT 1; SELECT country, score FROM media_representation WHERE region = 'South America' ORDER BY score ASC LIMIT 1; |
Who are the top 3 authors with the highest number of articles published in The Guardian? | CREATE TABLE authors (id INT,name VARCHAR(100),publisher VARCHAR(50)); CREATE TABLE articles_authors (article_id INT,author_id INT); INSERT INTO authors (id,name,publisher) VALUES (1,'Author1','The Guardian'),(2,'Author2','The Guardian'),(3,'Author3','The Guardian'); INSERT INTO articles_authors (article_id,author_id) VALUES (1,1),(2,2),(3,1),(3,2),(3,3); INSERT INTO articles (id,title,publication_date,publisher) VALUES (1,'Article1','2021-01-01','The Guardian'),(2,'Article2','2021-01-02','The Guardian'),(3,'Article3','2021-01-03','The Guardian'); | SELECT a.name, COUNT(aa.article_id) AS articles_count FROM authors a JOIN articles_authors aa ON a.id = aa.author_id JOIN articles ar ON aa.article_id = ar.id WHERE ar.publisher = 'The Guardian' GROUP BY a.name ORDER BY articles_count DESC LIMIT 3; |
What is the maximum number of servings of any vegetarian side dish? | CREATE TABLE side_dishes (id INT,side_name TEXT,max_servings INT,is_vegetarian BOOLEAN); | SELECT MAX(max_servings) FROM side_dishes WHERE is_vegetarian = TRUE; |
What's the percentage of coal resources depleted in each mine? | CREATE TABLE mines (id INT,name VARCHAR(50),resource VARCHAR(20),total_resources INT,depleted_resources INT); INSERT INTO mines (id,name,resource,total_resources,depleted_resources) VALUES (1,'Smith Mine','Coal',10000,2500); INSERT INTO mines (id,name,resource,total_resources,depleted_resources) VALUES (2,'Doe Mine','Coal',12000,4000); | SELECT name, (depleted_resources * 100.0 / total_resources) AS percentage_depleted FROM mines WHERE resource = 'Coal'; |
How many donations were made in each city? | CREATE TABLE donations_2 (id INT PRIMARY KEY,donor_id INT,city VARCHAR(50),state VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO donations_2 (id,donor_id,city,state,amount) VALUES (1,1,'Albany','NY',50.00),(2,2,'Buffalo','NY',75.00); | SELECT city, COUNT(*) as total_donations FROM donations_2 GROUP BY city; |
Update the game genre of a specific game to 'Action RPG' in the GameGenres table. | CREATE TABLE GameGenres (GameID INT,GameName VARCHAR(20),Genre VARCHAR(20)); INSERT INTO GameGenres (GameID,GameName,Genre) VALUES (1,'GameA','Action'),(2,'GameB','Puzzle'),(3,'GameC','Action'),(4,'GameD','Puzzle'); | UPDATE GameGenres SET Genre = 'Action RPG' WHERE GameID = 1; |
What is the average age of female players? | CREATE TABLE Players (PlayerID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (3,32,'Female','Mexico'); | SELECT AVG(Age) FROM Players WHERE Gender = 'Female'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.