instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Insert a new record in the 'authors' table | CREATE TABLE authors (author_id INT,name VARCHAR(255),nationality VARCHAR(100)); | INSERT INTO authors (author_id, name, nationality) VALUES (1, 'Chimamanda Ngozi Adichie', 'Nigerian'); |
What is the number of COVID-19 cases per 100,000 population for each county in the covid_cases table? | CREATE TABLE covid_cases (county TEXT,population INT,cases INT); INSERT INTO covid_cases (county,population,cases) VALUES ('County A',500000,5000),('County B',750000,8000),('County C',600000,6500),('County D',450000,4000); | SELECT county, (cases * 100000) / population AS cases_per_100k FROM covid_cases; |
Which regions have the highest volunteer hours? | CREATE TABLE volunteers (id INT,region VARCHAR(50),hours INT); INSERT INTO volunteers (id,region,hours) VALUES (1,'Northeast',500),(2,'Southeast',700),(3,'Midwest',600),(4,'West',800); | SELECT region, MAX(hours) as max_hours FROM volunteers GROUP BY region; |
What is the average funding amount for startups founded by people from historically marginalized gender identities? | CREATE TABLE startups (id INT,name TEXT,location TEXT,founder_gender TEXT,funding_amount INT); INSERT INTO startups (id,name,location,founder_gender,funding_amount) VALUES (1,'Startup A','USA','female',3000000); INSERT INTO startups (id,name,location,founder_gender,funding_amount) VALUES (2,'Startup B','Canada','non-bi... | SELECT AVG(funding_amount) FROM startups WHERE founder_gender IN ('female', 'non-binary'); |
What is the average salary of non-binary and transgender employees, partitioned by department? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(20),Department VARCHAR(30),Salary INT); INSERT INTO Employees (EmployeeID,Gender,Department,Salary) VALUES (1,'Non-binary','IT',60000),(2,'Transgender','HR',65000),(3,'Non-binary','Finance',70000),(4,'Transgender','Marketing',62000); | SELECT Department, AVG(CASE WHEN Gender = 'Non-binary' THEN Salary ELSE NULL END) AS Avg_Nonbinary_Salary, AVG(CASE WHEN Gender = 'Transgender' THEN Salary ELSE NULL END) AS Avg_Transgender_Salary FROM Employees GROUP BY Department; |
What is the average length of songs in the jazz genre released in the 2000s? | CREATE TABLE songs (song_id INT,genre VARCHAR(20),album VARCHAR(30),artist VARCHAR(30),length FLOAT,release_year INT); CREATE TABLE genres (genre VARCHAR(20)); INSERT INTO genres (genre) VALUES ('pop'),('rock'),('jazz'),('hip-hop'); ALTER TABLE songs ADD CONSTRAINT fk_genre FOREIGN KEY (genre) REFERENCES genres(genre); | SELECT AVG(length) as avg_length FROM songs WHERE genre = (SELECT genre FROM genres WHERE genre = 'jazz') AND release_year BETWEEN 2000 AND 2009; |
What is the total transaction value for each hour of the day for the month of March 2021? | CREATE TABLE transactions (transaction_id INT,transaction_date DATE,transaction_category VARCHAR(255),transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,transaction_category,transaction_value) VALUES (1,'2021-03-02','Food',50.00),(2,'2021-03-05','Electronics',300.00),(3,'2021-03... | SELECT HOUR(transaction_date) as hour_of_day, SUM(transaction_value) as total_value FROM transactions WHERE transaction_date BETWEEN '2021-03-01' AND '2021-03-31' GROUP BY hour_of_day; |
Count the number of spacecraft manufactured by SpaceX before 2015 | CREATE TABLE spacecraft (id INT,name VARCHAR(50),manufacturer VARCHAR(50),launch_year INT);INSERT INTO spacecraft (id,name,manufacturer,launch_year) VALUES (1,'Dragon','SpaceX',2010),(2,'Falcon','SpaceX',2006),(3,'Crew','SpaceX',2020); | SELECT COUNT(*) FROM spacecraft WHERE manufacturer = 'SpaceX' AND launch_year < 2015; |
Find the top 3 most expensive road projects | CREATE TABLE Road_Projects (project_id int,project_name varchar(255),location varchar(255),cost decimal(10,2)); | SELECT project_id, project_name, location, cost FROM Road_Projects ORDER BY cost DESC LIMIT 3; |
Find the number of articles published by each author in the 'news_articles' table | CREATE TABLE news_articles (article_id INT,author_name VARCHAR(50),title VARCHAR(100),published_date DATE); | SELECT author_name, COUNT(article_id) as article_count FROM news_articles GROUP BY author_name; |
What is the maximum depth of any marine protected area in the Indian region? | CREATE TABLE marine_protected_areas (name VARCHAR(255),location VARCHAR(255),depth FLOAT); INSERT INTO marine_protected_areas (name,location,depth) VALUES ('MPA 1','Indian',150.7); INSERT INTO marine_protected_areas (name,location,depth) VALUES ('MPA 2','Atlantic',200.3); | SELECT MAX(depth) FROM marine_protected_areas WHERE location = 'Indian'; |
List the top 3 countries with the most user engagement on posts related to "sports" in 2021. | CREATE TABLE posts (id INT,content TEXT,likes INT,created_at TIMESTAMP,user_location VARCHAR(255)); CREATE VIEW user_country AS SELECT user_location,COUNT(DISTINCT id) AS num_users FROM users GROUP BY user_location; | SELECT user_country.user_location, SUM(posts.likes) AS total_likes FROM posts JOIN user_country ON posts.user_location = user_country.user_location WHERE posts.content LIKE '%sports%' AND YEAR(posts.created_at) = 2021 GROUP BY user_country.user_location ORDER BY total_likes DESC LIMIT 3; |
What is the earliest offense date and corresponding crime type for each offender? | CREATE TABLE offenses (offender_id INT,offense_date DATE,crime VARCHAR(20)); INSERT INTO offenses (offender_id,offense_date,crime) VALUES (1,'2018-01-01','Murder'),(1,'2019-01-01','Robbery'),(2,'2017-01-01','Assault'); | SELECT offender_id, MIN(offense_date) OVER (PARTITION BY offender_id) AS min_offense_date, FIRST_VALUE(crime) OVER (PARTITION BY offender_id ORDER BY offense_date) AS first_crime FROM offenses; |
Report the number of public meetings in the 'Urban Development' department in the first half of 2022, grouped by the week they were held. | CREATE TABLE meetings (id INT,dept VARCHAR(255),meeting_date DATE); INSERT INTO meetings (id,dept,meeting_date) VALUES (1,'Urban Development','2022-03-01'),(2,'Urban Development','2022-05-15'),(3,'Transportation','2022-03-04'); | SELECT WEEKOFYEAR(meeting_date) AS week, COUNT(*) AS num_meetings FROM meetings WHERE dept = 'Urban Development' AND meeting_date BETWEEN '2022-01-01' AND '2022-06-30' GROUP BY week |
What is the average donation amount from donors in each country? | CREATE TABLE Donors (DonorID int,DonorName varchar(50),Country varchar(50)); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE Donations (DonationID int,DonorID int,DonationAmount decimal(10,2)); INSERT INTO Donations (DonationID,DonorID,DonationAmount) V... | SELECT Country, AVG(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID GROUP BY Country; |
Delete smart contracts from the 'SmartContracts' table that have not been updated in the past year from the current date. | CREATE TABLE SmartContracts (ContractID INT,LastUpdate DATETIME); | DELETE FROM SmartContracts WHERE LastUpdate < DATEADD(year, -1, GETDATE()); |
List all the timber_production data for a specific year, such as 2020? | CREATE TABLE timber_production (production_id INT,year INT,volume FLOAT); | SELECT * FROM timber_production WHERE year = 2020; |
How many defense projects did Raytheon undertake in the Asia-Pacific region between 2018 and 2020? | CREATE TABLE DefenseProjects (ProjectID INT,Contractor VARCHAR(50),Region VARCHAR(50),StartDate DATE,EndDate DATE); INSERT INTO DefenseProjects (ProjectID,Contractor,Region,StartDate,EndDate) VALUES (1,'Raytheon','Asia-Pacific','2018-04-01','2019-03-31'),(2,'Boeing','Europe','2019-01-01','2020-12-31'),(3,'Raytheon','As... | SELECT COUNT(*) FROM DefenseProjects WHERE Contractor = 'Raytheon' AND Region = 'Asia-Pacific' AND StartDate <= '2020-12-31' AND EndDate >= '2018-01-01'; |
Which vessels in the 'vessel_performance' table have an average speed below 10 knots? | CREATE TABLE vessel_performance (id INT,vessel_name VARCHAR(50),average_speed DECIMAL(5,2)); | SELECT vessel_name FROM vessel_performance WHERE average_speed < 10; |
How many virtual reality (VR) games have been released in 2022 and 2023 from the 'VR_Games' table? | CREATE TABLE VR_Games (Game_ID INT,Release_Year INT,Game_Category VARCHAR(20)); INSERT INTO VR_Games (Game_ID,Release_Year,Game_Category) VALUES (1,2022,'VR'); | SELECT COUNT(*) FROM VR_Games WHERE Release_Year IN (2022, 2023) AND Game_Category = 'VR'; |
List energy efficiency programs and their corresponding energy savings per household from the Programs and Households tables | CREATE TABLE Programs (id INT,name VARCHAR(50),sector VARCHAR(10));CREATE TABLE Households (id INT,program_id INT,energy_savings FLOAT,household_size INT); | SELECT p.name, AVG(h.energy_savings / h.household_size) as savings_per_household FROM Programs p INNER JOIN Households h ON p.id = h.program_id WHERE p.sector = 'efficiency' GROUP BY p.id; |
What is the average climate finance commitment per climate adaptation project in Europe? | CREATE TABLE climate_finance (finance_id INT,finance_amount DECIMAL(10,2),finance_type TEXT,project_id INT,commitment_date DATE); | SELECT AVG(cf.finance_amount) FROM climate_finance cf JOIN climate_adaptation_projects cap ON cf.project_id = cap.project_id WHERE cap.location LIKE '%Europe%' AND cf.finance_type = 'climate_adaptation'; |
Which community development initiatives in the 'rural_infrastructure' schema were completed in 2018? | CREATE TABLE community_initiatives (id INT,name VARCHAR(50),completion_date DATE); INSERT INTO community_initiatives (id,name,completion_date) VALUES (1,'Clean Energy Project','2018-12-31'); | SELECT name FROM rural_infrastructure.community_initiatives WHERE completion_date = '2018-01-01' OR completion_date = '2018-02-01' OR completion_date = '2018-03-01' OR completion_date = '2018-04-01' OR completion_date = '2018-05-01' OR completion_date = '2018-06-01' OR completion_date = '2018-07-01' OR completion_date ... |
Add a record to the ArtWorks table for an artwork titled 'Sunset', by 'Van Gogh', from year 1888 | CREATE TABLE ArtWorks (ID INT PRIMARY KEY,Title TEXT,Artist TEXT,Year INT); | INSERT INTO ArtWorks (Title, Artist, Year) VALUES ('Sunset', 'Van Gogh', 1888); |
What is the average production of Neodymium by mine location? | CREATE TABLE mines (id INT,location VARCHAR(50),neodymium_production FLOAT); INSERT INTO mines (id,location,neodymium_production) VALUES (1,'Bayan Obo',12000),(2,'Mount Weld',3500); | SELECT location, AVG(neodymium_production) as avg_production FROM mines GROUP BY location; |
Which dish has the highest calorie count in the vegan category? | CREATE TABLE nutrition (id INT,dish TEXT,vegan BOOLEAN,calories INT); INSERT INTO nutrition (id,dish,vegan,calories) VALUES (1,'Tofu Stir Fry',true,600),(2,'Chicken Shawarma',false,900),(3,'Vegan Nachos',true,700),(4,'Beef Burrito',false,1200); | SELECT dish, calories FROM nutrition WHERE vegan = true ORDER BY calories DESC LIMIT 1; |
What is the total number of mental health parity violations for each healthcare provider? | CREATE TABLE mental_health_parity (violation_id INT,provider_id INT,violation_count INT); INSERT INTO mental_health_parity (violation_id,provider_id,violation_count) VALUES (1,1,5),(2,1,3),(3,2,2),(4,3,1); CREATE TABLE healthcare_providers (provider_id INT,name VARCHAR(50)); INSERT INTO healthcare_providers (provider_i... | SELECT hp.name, SUM(mhp.violation_count) FROM healthcare_providers hp INNER JOIN mental_health_parity mhp ON hp.provider_id = mhp.provider_id GROUP BY hp.name; |
Display the total budget allocated for public parks in 2021 | CREATE TABLE Budget_Allocation(allocation_id INT PRIMARY KEY,category VARCHAR(255),amount FLOAT,fiscal_year INT,FOREIGN KEY (category) REFERENCES Parks(name)); INSERT INTO Budget_Allocation (allocation_id,category,amount,fiscal_year) VALUES (1,'Central Park',15000000.00,2021),(2,'Prospect Park',12000000.00,2021),(3,'G... | SELECT SUM(amount) FROM Budget_Allocation WHERE fiscal_year = 2021 AND category IN (SELECT name FROM Parks); |
Update the total of the order with order_id 1 to $60.00 | CREATE TABLE orders (order_id INT,customer_id INT,order_date DATE,total DECIMAL(5,2)); | UPDATE orders SET total = 60.00 WHERE order_id = 1; |
What is the minimum production cost for garments made from organic cotton in the last 6 months? | CREATE TABLE OrganicCottonGarments (garment_id INT,production_cost DECIMAL(5,2),production_date DATE); INSERT INTO OrganicCottonGarments (garment_id,production_cost,production_date) VALUES (1,25.00,'2022-01-01'),(2,28.00,'2022-02-01'),(3,26.50,'2022-03-01'),(4,23.50,'2022-04-01'),(5,29.00,'2022-05-01'),(6,27.00,'2022-0... | SELECT MIN(production_cost) FROM OrganicCottonGarments WHERE production_date BETWEEN DATEADD(month, -6, GETDATE()) AND GETDATE(); |
What is the daily minimum temperature for the last 60 days, with a running total of the number of days below 15 degrees Celsius? | CREATE TABLE WeatherData (id INT,Temperature INT,Timestamp DATETIME); INSERT INTO WeatherData (id,Temperature,Timestamp) VALUES (1,12,'2022-04-15 12:00:00'),(2,18,'2022-04-16 12:00:00'); | SELECT Temperature, Timestamp, SUM(CASE WHEN Temperature < 15 THEN 1 ELSE 0 END) OVER (ORDER BY Timestamp) as RunningTotal FROM WeatherData WHERE Timestamp BETWEEN DATEADD(day, -60, GETDATE()) AND GETDATE(); |
List all the public transportation projects in the city of New York and Chicago, including their start and end dates, that have an estimated budget over 50 million. | CREATE TABLE TransitProjects (project VARCHAR(50),city VARCHAR(20),start_date DATE,end_date DATE,budget INT); INSERT INTO TransitProjects (project,city,start_date,end_date,budget) VALUES ('ProjectA','New York','2020-01-01','2022-12-31',60000000),('ProjectB','Chicago','2019-01-01','2021-12-31',55000000); | SELECT project, city, start_date, end_date FROM TransitProjects WHERE city IN ('New York', 'Chicago') AND budget > 50000000; |
What is the total water consumption by each industry sector in the city of Sacramento in 2020? | CREATE TABLE industry_water_usage (industry_sector VARCHAR(50),city VARCHAR(50),year INT,water_consumption FLOAT); INSERT INTO industry_water_usage (industry_sector,city,year,water_consumption) VALUES ('Agriculture','Sacramento',2020,12345.6),('Manufacturing','Sacramento',2020,23456.7),('Residential','Sacramento',2020,... | SELECT industry_sector, SUM(water_consumption) as total_water_consumption FROM industry_water_usage WHERE city = 'Sacramento' AND year = 2020 GROUP BY industry_sector; |
What is the number of cases and win rate for female attorneys in the West region? | CREATE TABLE Cases (CaseID INT,AttorneyID INT,CaseOutcome VARCHAR(50)); INSERT INTO Cases (CaseID,AttorneyID,CaseOutcome) VALUES (1,1,'Won'),(2,1,'Lost'),(3,2,'Won'),(4,2,'Won'),(5,3,'Lost'),(6,3,'Lost'),(7,4,'Won'),(8,4,'Lost'),(9,5,'Lost'),(10,5,'Won'); CREATE TABLE Attorneys (AttorneyID INT,AttorneyName VARCHAR(50... | SELECT a.AttorneyName, a.Gender, COUNT(c.CaseID) AS TotalCases, COUNT(c.CaseID) * 100.0 / SUM(COUNT(c.CaseID)) OVER (PARTITION BY a.Gender) AS WinRate FROM Attorneys a JOIN Cases c ON a.AttorneyID = c.AttorneyID WHERE a.Gender = 'Female' AND a.Region = 'West' GROUP BY a.AttorneyName, a.Gender; |
Add new category 'Vegan' in the menu_categories table | CREATE TABLE menu_categories (category_id INT,category_name TEXT); | INSERT INTO menu_categories (category_name) VALUES ('Vegan'); |
How many socially responsible loans were granted to customers in the last month? | CREATE TABLE socially_responsible_loans (id INT PRIMARY KEY,customer_id INT,amount DECIMAL(10,2),date DATE); CREATE VIEW last_month_loans AS SELECT * FROM socially_responsible_loans WHERE date >= DATE_SUB(CURRENT_DATE,INTERVAL 1 MONTH); | SELECT COUNT(*) FROM last_month_loans; |
What is the total length of all roads in the state of New York? | CREATE TABLE Roads (RoadID INT,Name TEXT,Length INT,State TEXT); INSERT INTO Roads (RoadID,Name,Length,State) VALUES (1,'Road1',50,'New York'); INSERT INTO Roads (RoadID,Name,Length,State) VALUES (2,'Road2',75,'New York'); INSERT INTO Roads (RoadID,Name,Length,State) VALUES (3,'Road3',100,'New Jersey'); | SELECT SUM(Length) FROM Roads WHERE State = 'New York'; |
What is the maximum budget for road projects in New York? | CREATE TABLE road_projects (id INT,name TEXT,state TEXT,budget FLOAT); INSERT INTO road_projects (id,name,state,budget) VALUES (1,'NY-1 Expressway Reconstruction','NY',20000000); | SELECT MAX(budget) FROM road_projects WHERE state = 'NY'; |
What are the names and budget allocations for all agricultural innovation projects in the 'agriculture_innovation_2' table? | CREATE TABLE agriculture_innovation_2 (id INT,project_name VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO agriculture_innovation_2 (id,project_name,budget) VALUES (1,'Precision Agriculture',75000.00),(2,'Vertical Farming',125000.00),(3,'Biological Pest Control',95000.00); | SELECT project_name, budget FROM agriculture_innovation_2; |
What is the total number of posts in the 'social_media' table? | CREATE TABLE social_media (user_id INT,posts_count INT); | SELECT SUM(posts_count) FROM social_media; |
What is the average carbon sequestration, in metric tons, for each country in the Europe region for the year 2020? | CREATE TABLE carbon_sequestration (id INT,country VARCHAR(255),region VARCHAR(255),year INT,metric_tons FLOAT); INSERT INTO carbon_sequestration (id,country,region,year,metric_tons) VALUES (1,'Germany','Europe',2020,123456.12),(2,'France','Europe',2020,234567.12),(3,'Spain','Europe',2020,345678.12); | SELECT country, AVG(metric_tons) FROM carbon_sequestration WHERE region = 'Europe' AND year = 2020 GROUP BY country; |
What is the average caloric intake per serving for organic dishes? | CREATE TABLE dishes (id INT,name VARCHAR(255),is_organic BOOLEAN,serving_size INT,calories INT); INSERT INTO dishes (id,name,is_organic,serving_size,calories) VALUES (1,'Quinoa Salad',true,1,400),(2,'Spaghetti Bolognese',false,2,600),(3,'Veggie Tacos',true,1,350); | SELECT AVG(calories / serving_size) as avg_caloric_intake FROM dishes WHERE is_organic = true; |
What is the average number of cases handled by attorneys per year? | CREATE TABLE AttorneyStartYear (AttorneyID INT,StartYear INT); INSERT INTO AttorneyStartYear (AttorneyID,StartYear) VALUES (1,2018),(2,2019),(3,2015); | SELECT AVG(DATEDIFF(YEAR, StartYear, GETDATE())) FROM AttorneyStartYear; |
What is the total revenue for each product category in Q2 2022? | CREATE TABLE sales (product_id INT,product_category TEXT,sale_date DATE,revenue FLOAT); | SELECT product_category, SUM(revenue) FROM sales WHERE sale_date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY product_category; |
What is the minimum co-ownership price for properties in each city, grouped by category? | CREATE TABLE city (id INT,name VARCHAR(255)); INSERT INTO city (id,name) VALUES (1,'CityA'),(2,'CityB'); CREATE TABLE property (id INT,co_ownership_price DECIMAL(10,2),city_id INT,category VARCHAR(255)); INSERT INTO property (id,co_ownership_price,city_id,category) VALUES (1,500000,1,'sustainable urbanism'),(2,600000,1... | SELECT c.name AS city, p.category AS category, MIN(p.co_ownership_price) AS min_price FROM property p JOIN city c ON p.city_id = c.id GROUP BY c.name, p.category; |
What is the total number of military aircraft by manufacturer, sorted by the count in descending order? | CREATE TABLE Manufacturer (MID INT PRIMARY KEY,Name VARCHAR(50)); INSERT INTO Manufacturer (MID,Name) VALUES (1,'Boeing'),(2,'Lockheed Martin'),(3,'Northrop Grumman'); CREATE TABLE Aircraft (AID INT PRIMARY KEY,Model VARCHAR(50),ManufacturerID INT,FOREIGN KEY (ManufacturerID) REFERENCES Manufacturer(MID)); INSERT INTO ... | SELECT m.Name, COUNT(a.AID) AS Total FROM Manufacturer m JOIN Aircraft a ON m.MID = a.ManufacturerID GROUP BY m.Name ORDER BY Total DESC; |
How many AI safety incidents were reported in Africa in the last 6 months? | CREATE TABLE safety_incidents (incident_id INT,location TEXT,incident_date DATE); INSERT INTO safety_incidents (incident_id,location,incident_date) VALUES (1,'Nigeria','2022-02-12'),(2,'South Africa','2021-10-18'),(3,'Egypt','2022-04-05'),(4,'Kenya','2021-08-07'); | SELECT COUNT(*) FROM safety_incidents WHERE location LIKE 'Africa%' AND incident_date >= DATEADD(month, -6, GETDATE()); |
What is the minimum media literacy score for articles published in the 'articles' table? | CREATE TABLE articles (title VARCHAR(255),media_literacy_score INT); | SELECT MIN(media_literacy_score) AS min_score FROM articles; |
What are the energy efficiency stats for residential buildings in the city of Seattle? | CREATE TABLE ResidentialEfficiency (city VARCHAR(20),building_type VARCHAR(20),energy_efficiency FLOAT); INSERT INTO ResidentialEfficiency (city,building_type,energy_efficiency) VALUES ('Seattle','Residential',85.0); | SELECT energy_efficiency FROM ResidentialEfficiency WHERE city = 'Seattle' AND building_type = 'Residential'; |
How many building permits were issued in Texas in Q1 of 2021? | CREATE TABLE BuildingPermits (id INT,permitNumber TEXT,state TEXT,quarter INT,year INT); | SELECT COUNT(*) FROM BuildingPermits WHERE state = 'Texas' AND quarter = 1 AND year = 2021; |
What is the number of climate-related policy documents published by each government in Oceania, ranked by the most recent year? | CREATE TABLE PolicyDocuments (Country VARCHAR(50),Year INT,Documents INT); INSERT INTO PolicyDocuments (Country,Year,Documents) VALUES ('Australia',2010,20),('Australia',2015,25),('Australia',2020,30),('New Zealand',2010,15),('New Zealand',2015,20),('New Zealand',2020,25); | SELECT Country, MAX(Year) AS RecentYear, SUM(Documents) AS TotalDocuments FROM PolicyDocuments GROUP BY Country ORDER BY RecentYear DESC; |
What is the total playtime for each game by players in Europe? | CREATE TABLE Players (PlayerID INT,PlayerName TEXT,Country TEXT); INSERT INTO Players (PlayerID,PlayerName,Country) VALUES (1,'John Doe','France'),(2,'Jane Smith','Germany'); CREATE TABLE GameSessions (SessionID INT,PlayerID INT,GameID INT,StartTime TIMESTAMP,EndTime TIMESTAMP); INSERT INTO GameSessions (SessionID,Play... | SELECT Players.Country, SUM(TIMESTAMPDIFF(MINUTE, GameSessions.StartTime, GameSessions.EndTime)) as TotalPlaytime FROM Players JOIN GameSessions ON Players.PlayerID = GameSessions.PlayerID WHERE Players.Country IN ('France', 'Germany') GROUP BY Players.Country; |
What is the average engagement rate for posts containing hashtags related to 'music' in the past day? | CREATE TABLE posts (id INT,hashtags TEXT,engagement_rate DECIMAL(5,2),timestamp TIMESTAMP); INSERT INTO posts (id,hashtags,engagement_rate,timestamp) VALUES (1,'#music,#song',6.15,'2022-07-17 10:00:00'); | SELECT AVG(engagement_rate) FROM posts WHERE hashtags LIKE '%#music%' AND timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY); |
What is the minimum number of hospital beds in rural areas of India? | CREATE TABLE HospitalBeds (HospitalID int,Beds int,Rural bool); INSERT INTO HospitalBeds (HospitalID,Beds,Rural) VALUES (1,50,true); | SELECT MIN(Beds) FROM HospitalBeds WHERE Rural = true; |
Update the address of the 'Rural Community Hospital' in 'RuralHealthFacilities' table. | CREATE TABLE RuralHealthFacilities (FacilityID INT,Name VARCHAR(50),Address VARCHAR(100),TotalBeds INT); INSERT INTO RuralHealthFacilities (FacilityID,Name,Address,TotalBeds) VALUES (1,'Rural Community Hospital','1234 Rural Rd',50); | UPDATE RuralHealthFacilities SET Address = '5678 Rural Ave' WHERE Name = 'Rural Community Hospital'; |
Insert a new record into the volunteers table with the following information: id = 4, name = 'Olivia Thompson', hours_served = 25.00. | CREATE TABLE volunteers (id INT,name VARCHAR(50),hours_served FLOAT); | INSERT INTO volunteers (id, name, hours_served) VALUES (4, 'Olivia Thompson', 25.00); |
What is the total number of female and male editors in the 'editors' table? | CREATE TABLE editors (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,experience INT); INSERT INTO editors (id,name,gender,age,experience) VALUES (1,'John Doe','Male',55,15); INSERT INTO editors (id,name,gender,age,experience) VALUES (2,'Jim Brown','Male',50,12); INSERT INTO editors (id,name,gender,age,experience) V... | SELECT SUM(CASE WHEN gender = 'Female' THEN 1 ELSE 0 END) AS female_editors, SUM(CASE WHEN gender = 'Male' THEN 1 ELSE 0 END) AS male_editors FROM editors; |
What is the total sales volume for organic cosmetic products in the US market? | CREATE TABLE cosmetic_sales (product_id INT,sale_volume INT,market VARCHAR(10)); INSERT INTO cosmetic_sales (product_id,sale_volume,market) VALUES (1,200,'US'),(2,300,'CA'),(3,400,'US'); CREATE TABLE product_info (product_id INT,is_organic BOOLEAN); INSERT INTO product_info (product_id,is_organic) VALUES (1,true),(2,fa... | SELECT SUM(cs.sale_volume) FROM cosmetic_sales cs JOIN product_info pi ON cs.product_id = pi.product_id WHERE pi.is_organic = true AND cs.market = 'US'; |
Show the names and ages of clients who invested in mutual funds but not in stocks and bonds? | 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'),(4,'Alice Lee',40,'Female'); CREATE TABLE investments (client_id INT,investment_type TEXT); INSERT INTO investments VALUES (1,'Stocks'),(1,'Bon... | SELECT c.name, c.age FROM clients c INNER JOIN investments i ON c.client_id = i.client_id WHERE i.investment_type = 'Mutual Funds' AND c.client_id NOT IN (SELECT client_id FROM investments WHERE investment_type IN ('Stocks', 'Bonds')); |
What is the minimum salary of AI researchers in the "ai_ethics" department of the "research_lab" company in 2022? | CREATE TABLE ai_researchers (id INT,name VARCHAR(50),salary FLOAT,department VARCHAR(50),year INT); INSERT INTO ai_researchers (id,name,salary,department,year) VALUES (1,'Jack',100000,'ai_ethics',2022),(2,'Jill',105000,'ai_ethics',2022),(3,'John',95000,'ai_ethics',2022),(4,'Jane',90000,'ai_ethics',2022); | SELECT MIN(salary) FROM ai_researchers WHERE department = 'ai_ethics' AND year = 2022; |
Insert a new player from Brazil with the name 'Marcos Oliveira', age 35 | CREATE TABLE players (id INT PRIMARY KEY,name VARCHAR(50),age INT,country VARCHAR(50)); | INSERT INTO players (name, age, country) VALUES ('Marcos Oliveira', 35, 'Brazil'); |
What is the number of hospitals per 1000 people in European countries in 2020? | CREATE TABLE Hospitals (Country VARCHAR(50),Continent VARCHAR(50),HospitalsPer1000 FLOAT,Year INT); INSERT INTO Hospitals (Country,Continent,HospitalsPer1000,Year) VALUES ('France','Europe',3.5,2020),('Germany','Europe',4.0,2020),('Italy','Europe',3.7,2020); | SELECT Country, Continent, HospitalsPer1000 FROM Hospitals WHERE Continent = 'Europe' AND Year = 2020; |
What is the total number of articles published by each author in the 'authors' table? | CREATE TABLE authors (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,total_articles INT); INSERT INTO authors (id,name,gender,age,total_articles) VALUES (1,'Jane Smith','Female',35,5); INSERT INTO authors (id,name,gender,age,total_articles) VALUES (2,'Alice Johnson','Female',40,10); INSERT INTO authors (id,name,gen... | SELECT name, SUM(total_articles) FROM authors GROUP BY name; |
List cities with more than 2000 trips on shared electric vehicles | CREATE TABLE shared_vehicles (id INT,vehicle_type VARCHAR(20),trip_count INT); INSERT INTO shared_vehicles (id,vehicle_type,trip_count) VALUES (1,'ebike',1200),(2,'escooter',800),(3,'car',1500); CREATE TABLE city_data (city VARCHAR(20),shared_ebikes BOOLEAN,shared_escooters BOOLEAN,shared_cars BOOLEAN); INSERT INTO cit... | SELECT city FROM city_data WHERE (shared_ebikes = true OR shared_escooters = true OR shared_cars = true) AND city IN (SELECT city FROM (SELECT city, SUM(trip_count) AS total_trips FROM shared_vehicles WHERE (vehicle_type = 'ebike' OR vehicle_type = 'escooter' OR vehicle_type = 'car') GROUP BY city) AS shared_vehicles W... |
What is the total cost of sustainable seafood products in each store? | CREATE TABLE Stores (store_id INT,store_name VARCHAR(255)); CREATE TABLE Products (product_id INT,product_name VARCHAR(255),is_sustainable BOOLEAN,cost INT); CREATE TABLE Inventory (store_id INT,product_id INT,quantity INT); | SELECT s.store_name, p.product_name, SUM(i.quantity * p.cost) as total_cost FROM Inventory i JOIN Stores s ON i.store_id = s.store_id JOIN Products p ON i.product_id = p.product_id WHERE p.is_sustainable = TRUE GROUP BY s.store_name, p.product_name; |
What are the top 3 construction materials used by project in Utah? | CREATE TABLE projects (id INT,name TEXT,state TEXT); CREATE TABLE project_materials (id INT,project_id INT,material TEXT); INSERT INTO projects (id,name,state) VALUES (1,'Green Project 1','Utah'); INSERT INTO projects (id,name,state) VALUES (2,'Eco Project 2','Utah'); INSERT INTO project_materials (id,project_id,materi... | SELECT projects.name, project_materials.material, COUNT(project_materials.id) as material_count FROM projects JOIN project_materials ON projects.id = project_materials.project_id WHERE projects.state = 'Utah' GROUP BY projects.name, project_materials.material ORDER BY material_count DESC LIMIT 3; |
List all case IDs and billing amounts for cases with a precedent set by Judge 'Anderson' that had a verdict of 'Not Guilty' or 'Mistrial'. | CREATE TABLE cases (id INT,judge_name VARCHAR(20),verdict VARCHAR(20),billing_amount DECIMAL(10,2)); INSERT INTO cases (id,judge_name,verdict,billing_amount) VALUES (1,'Anderson','Not Guilty',5000.00),(2,'Brown','Guilty',4000.00),(3,'Anderson','Mistrial',6000.00),(4,'Green','Not Guilty',7000.00); | SELECT id, billing_amount FROM cases WHERE judge_name = 'Anderson' AND (verdict = 'Not Guilty' OR verdict = 'Mistrial'); |
Count the number of articles published in the 'culture' section with a word count greater than 1000. | CREATE TABLE articles (id INT,title VARCHAR(255),section VARCHAR(64),word_count INT); INSERT INTO articles (id,title,section,word_count) VALUES (1,'ArticleA','culture',1200),(2,'ArticleB','politics',800),(3,'ArticleC','culture',1500); | SELECT COUNT(*) FROM articles WHERE section = 'culture' AND word_count > 1000; |
What is the average clinic capacity per province, excluding the top 25% of clinics? | CREATE TABLE ClinicCapacity (ProvinceName VARCHAR(50),ClinicName VARCHAR(50),Capacity INT); INSERT INTO ClinicCapacity (ProvinceName,ClinicName,Capacity) VALUES ('Ontario','ClinicA',200),('Ontario','ClinicB',250),('Quebec','ClinicX',150),('British Columbia','ClinicY',200),('British Columbia','ClinicZ',175); | SELECT ProvinceName, AVG(Capacity) AS AvgCapacity FROM (SELECT ProvinceName, Capacity, NTILE(4) OVER (ORDER BY Capacity DESC) AS Quartile FROM ClinicCapacity) AS Subquery WHERE Quartile < 4 GROUP BY ProvinceName |
How many research stations are in each region without any species? | CREATE TABLE ResearchStations (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(100),region VARCHAR(50)); INSERT INTO ResearchStations (id,name,location,region) VALUES (2,'Station B','Greenland','Arctic'),(3,'Station C','Svalbard','Arctic'); | SELECT ResearchStations.region, COUNT(DISTINCT ResearchStations.name) FROM ResearchStations LEFT JOIN Species ON ResearchStations.region = Species.region WHERE Species.id IS NULL GROUP BY ResearchStations.region; |
Create a view for the number of visits by age group | CREATE VIEW visit_age_group AS SELECT age,COUNT(*) AS count FROM visitor_demographics GROUP BY age; | SELECT * FROM visit_age_group; |
Find transactions conducted by customers with ages greater than 30, assuming we have a 'customers' table with 'birth_date'. | CREATE TABLE customers (id INT,birth_date DATE); INSERT INTO customers (id,birth_date) VALUES (1,'1985-01-01'),(2,'1990-01-01'),(3,'1975-01-01'),(4,'2000-01-01'); CREATE TABLE transactions (id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (id,customer_id,amount) VALUES (1,1,500.00),(2,2,350.00),(3... | SELECT t.id, t.customer_id, t.amount FROM transactions t INNER JOIN customers c ON t.customer_id = c.id WHERE DATEDIFF(YEAR, c.birth_date, GETDATE()) > 30; |
Which languages have the most preservation initiatives? | CREATE TABLE language_preservation (id INT,language VARCHAR(255),initiative VARCHAR(255),country VARCHAR(255)); INSERT INTO language_preservation (id,language,initiative,country) VALUES (1,'Quechua','Quechua Education','Peru'),(2,'Gaelic','Gaelic Language Revitalization','Scotland'); | SELECT language, COUNT(*) as initiatives_count FROM language_preservation GROUP BY language; |
What is the total billing amount for cases handled by lawyers specialized in Immigration Law? | CREATE TABLE Cases (CaseID INT PRIMARY KEY,CaseName VARCHAR(50),CaseType VARCHAR(50),LawyerID INT,ClientID INT); INSERT INTO Cases (CaseID,CaseName,CaseType,LawyerID,ClientID) VALUES (1,'Sample Case','Immigration',1,1); CREATE TABLE Lawyers (LawyerID INT PRIMARY KEY,Name VARCHAR(50),SpecializedIn VARCHAR(50)); INSERT I... | SELECT SUM(Billing.BillAmount) FROM Cases INNER JOIN Lawyers ON Cases.LawyerID = Lawyers.LawyerID INNER JOIN Billing ON Cases.CaseID = Billing.CaseID WHERE Lawyers.SpecializedIn = 'Immigration'; |
What is the percentage of patients who improved after teletherapy? | CREATE TABLE outcomes (id INT,patient_id INT,improvement VARCHAR(10),therapy_type VARCHAR(10)); INSERT INTO outcomes (id,patient_id,improvement,therapy_type) VALUES (1,1,'improved','teletherapy'),(2,2,'did not improve','in-person'),(3,3,'improved','teletherapy'),(4,4,'did not improve','in-person'),(5,5,'improved','tele... | SELECT (COUNT(*) FILTER (WHERE improvement = 'improved' AND therapy_type = 'teletherapy')) * 100.0 / COUNT(*) AS percentage FROM outcomes; |
What is the average number of volunteers per cause? | CREATE TABLE cause (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE volunteer (id INT PRIMARY KEY,cause_id INT,organization_id INT); | SELECT c.name, AVG(COUNT(v.id)) AS avg_volunteers FROM cause c JOIN volunteer v ON c.id = v.cause_id GROUP BY c.id; |
What is the average life expectancy for men and women in each country? | CREATE TABLE LifeExpectancyData (Country VARCHAR(50),Gender VARCHAR(6),LifeExpectancy DECIMAL(3,1)); INSERT INTO LifeExpectancyData (Country,Gender,LifeExpectancy) VALUES ('Canada','Men',80.1),('Canada','Women',84.3),('USA','Men',76.2),('USA','Women',81.6); | SELECT Country, Gender, AVG(LifeExpectancy) AS AvgLifeExp FROM LifeExpectancyData GROUP BY Country, Gender; |
What is the minimum budget of climate finance projects in South America? | CREATE TABLE climate_finance (id INT,project_name TEXT,budget INT,location TEXT); INSERT INTO climate_finance (id,project_name,budget,location) VALUES (1,'Coral Reef Restoration',25000,'South America'); INSERT INTO climate_finance (id,project_name,budget,location) VALUES (2,'Mangrove Planting',30000,'Asia'); | SELECT MIN(budget) FROM climate_finance WHERE location = 'South America'; |
What is the total revenue of organic products sold by vendors with a high ethical labor score? | CREATE TABLE vendors (vendor_id INT,ethical_score INT); INSERT INTO vendors (vendor_id,ethical_score) VALUES (1,90),(2,75),(3,85); CREATE TABLE products (product_id INT,organic BOOLEAN); INSERT INTO products (product_id,organic) VALUES (101,TRUE),(102,FALSE),(103,TRUE); CREATE TABLE sales (sale_id INT,vendor_id INT,pro... | SELECT SUM(sales.revenue) FROM sales JOIN vendors ON sales.vendor_id = vendors.vendor_id JOIN products ON sales.product_id = products.product_id WHERE products.organic = TRUE AND vendors.ethical_score >= 80; |
Calculate the percentage of emergency incidents in each district that occurred at night (between 8 PM and 6 AM) during the last month. | CREATE TABLE IncidentTimes (id INT,incident_id INT,incident_time TIME); CREATE TABLE EmergencyIncidents (id INT,district_id INT,incident_date DATE); INSERT INTO IncidentTimes (id,incident_id,incident_time) VALUES (1,1,'12:00:00'),(2,2,'21:00:00'),(3,3,'06:00:00'),(4,4,'18:00:00'); INSERT INTO EmergencyIncidents (id,dis... | SELECT district_id, COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (PARTITION BY district_id) as pct_night_incidents FROM EmergencyIncidents e JOIN IncidentTimes i ON e.id = i.incident_id WHERE incident_time BETWEEN '20:00:00' AND '06:00:00' AND incident_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GRO... |
What is the percentage of security incidents resolved within the SLA for each department in the last month? | CREATE TABLE security_incidents (id INT,department VARCHAR(255),resolution_time INT,timestamp DATETIME,SLA_time INT); | SELECT department, 100.0 * COUNT(*) / (SELECT COUNT(*) FROM security_incidents WHERE department = security_incidents.department AND timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH)) as percentage_SLA FROM security_incidents WHERE resolution_time <= SLA_time AND timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH)... |
What is the total quantity of gluten-free ingredients? | CREATE TABLE ingredients (ingredient_id INT,ingredient_name VARCHAR(50),is_gluten_free BOOLEAN,quantity INT); INSERT INTO ingredients (ingredient_id,ingredient_name,is_gluten_free,quantity) VALUES (1,'Quinoa',TRUE,50),(2,'Tomatoes',TRUE,200),(3,'Chickpeas',FALSE,100),(4,'Beef',FALSE,30),(5,'Vegan Cheese',TRUE,80),(6,'W... | SELECT SUM(quantity) FROM ingredients WHERE is_gluten_free = TRUE; |
List the organizations with a social impact score below 70, along with their respective scores. | CREATE TABLE Social_Impact_Scores (id INT,organization_name TEXT,social_impact_score INT); INSERT INTO Social_Impact_Scores (id,organization_name,social_impact_score) VALUES (1,'Save the Children',65),(2,'World Wildlife Fund',80),(3,'Oxfam',68); | SELECT organization_name, social_impact_score FROM Social_Impact_Scores WHERE social_impact_score < 70; |
What was the total cost of the Mars Exploration Program in 2025? | CREATE TABLE space_projects (project_name VARCHAR(255),start_year INT,end_year INT,total_cost FLOAT); INSERT INTO space_projects (project_name,start_year,end_year,total_cost) VALUES ('Mars Exploration Program',2020,2030,2500000000.00); | SELECT total_cost FROM space_projects WHERE project_name = 'Mars Exploration Program' AND YEAR(2025 BETWEEN start_year AND end_year); |
What are the total quantities of chemicals produced by each manufacturer, grouped by month? | CREATE TABLE Manufacturer(Id INT,Name VARCHAR(50),Location VARCHAR(50)); CREATE TABLE Chemical(Id INT,Name VARCHAR(50),ManufacturerId INT,QuantityProduced INT,ProductionDate DATE); | SELECT m.Name, DATE_FORMAT(c.ProductionDate, '%Y-%m') AS Month, SUM(c.QuantityProduced) AS TotalQuantity FROM Chemical c JOIN Manufacturer m ON c.ManufacturerId = m.Id GROUP BY m.Name, Month; |
Which authors have published more than one book in the 'Fiction' category? | CREATE TABLE authors (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO authors (id,name) VALUES (1,'Stephen King'); INSERT INTO authors (id,name) VALUES (2,'J.R.R. Tolkien'); CREATE TABLE books (id INT PRIMARY KEY,title VARCHAR(255),author_id INT,publication_year INT,category VARCHAR(255)); INSERT INTO books (id,titl... | SELECT a.name FROM authors a INNER JOIN books b ON a.id = b.author_id INNER JOIN categories c ON b.category = c.category WHERE a.id = b.author_id AND c.category = 'Fiction' GROUP BY a.name HAVING COUNT(b.id) > 1; |
List the ports where both import and export activities are present. | CREATE TABLE ports (id INT,name VARCHAR(50)); CREATE TABLE import_activities (port_id INT,port_name VARCHAR(50),cargo_type VARCHAR(50)); CREATE TABLE export_activities (port_id INT,port_name VARCHAR(50),cargo_type VARCHAR(50)); | SELECT DISTINCT p.name FROM ports p INNER JOIN import_activities ia ON p.name = ia.port_name INNER JOIN export_activities ea ON p.name = ea.port_name; |
Find the total number of packages shipped to each destination in the last 5 days of September 2021 | CREATE TABLE Shipments (id INT,destination VARCHAR(50),packages INT,timestamp DATE); INSERT INTO Shipments (id,destination,packages,timestamp) VALUES (1,'Jakarta',50,'2021-09-26'),(2,'Bandung',30,'2021-09-27'),(3,'Surabaya',40,'2021-09-28'),(4,'Bali',55,'2021-09-29'),(5,'Yogyakarta',60,'2021-09-30'); | SELECT destination, SUM(packages) FROM Shipments WHERE timestamp BETWEEN '2021-09-26' AND '2021-09-30' GROUP BY destination; |
What is the average monthly food distribution per person in Kenya and Tanzania? | CREATE TABLE food_distributions (id INT,country VARCHAR(20),person_id INT,distribution_date DATE,quantity INT); | SELECT country, AVG(quantity) as avg_monthly_distribution FROM (SELECT country, person_id, DATE_TRUNC('month', distribution_date) as distribution_month, SUM(quantity) as quantity FROM food_distributions GROUP BY country, person_id, distribution_month) as subquery GROUP BY country; |
How can I update the price of all size 2XL clothing items in the 'Sales' table to $60, for sales made in the last month? | CREATE TABLE Sales (id INT,product_id INT,size VARCHAR(10),price DECIMAL(5,2),sale_date DATE); INSERT INTO Sales (id,product_id,size,price,sale_date) VALUES (1,1,'2XL',50.00,'2022-04-01'),(2,2,'XS',30.00,'2022-05-15'); | UPDATE Sales SET price = 60.00 WHERE size = '2XL' AND sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the number of animals in protected habitats for each species and region? | CREATE TABLE ProtectedHabitats (id INT,animal_id INT,species VARCHAR(255),size FLOAT,region VARCHAR(255)); INSERT INTO ProtectedHabitats (id,animal_id,species,size,region) VALUES (1,1,'Lion',5.6,'Africa'),(2,2,'Elephant',3.2,'Asia'),(3,3,'Tiger',7.8,'Africa'); | SELECT species, region, COUNT(animal_id) FROM ProtectedHabitats GROUP BY species, region; |
Which countries are responsible for the most space debris? | CREATE TABLE space_debris (id INTEGER,country TEXT,debris_count INTEGER); INSERT INTO space_debris (id,country,debris_count) VALUES (1,'USA',3000),(2,'Russia',2500),(3,'China',2000),(4,'India',1000),(5,'Japan',800); | SELECT country, debris_count FROM space_debris ORDER BY debris_count DESC; |
What is the total budget for all economic diversification efforts in Indonesia that were not successfully implemented? | CREATE TABLE economic_diversification_efforts (id INT,country VARCHAR(50),effort_name VARCHAR(100),start_date DATE,end_date DATE,budget DECIMAL(10,2),success_status VARCHAR(50)); | SELECT SUM(budget) FROM economic_diversification_efforts WHERE country = 'Indonesia' AND success_status != 'Successfully Implemented'; |
What is the total water consumption per mining site, grouped by mine ownership in the 'mining_sites' table? | CREATE TABLE mining_sites (site_id INT,site_ownership VARCHAR(50),year INT,water_consumption INT); INSERT INTO mining_sites (site_id,site_ownership,year,water_consumption) VALUES (1,'Company C',2020,12000); INSERT INTO mining_sites (site_id,site_ownership,year,water_consumption) VALUES (2,'Company D',2020,15000); INSER... | SELECT site_ownership, SUM(water_consumption) FROM mining_sites GROUP BY site_ownership; |
Which artifacts were found in the 'Classic' era? | CREATE TABLE Artifacts (Artifact_ID INT,Name TEXT,Era TEXT); INSERT INTO Artifacts (Artifact_ID,Name,Era) VALUES (1,'Jade Figurine','Preclassic'),(2,'Ceramic Pot','Classic'); | SELECT Name FROM Artifacts WHERE Era='Classic'; |
Identify the number of tunnels in the city of London that have been built in the last 5 years and their respective construction companies. | CREATE TABLE tunnel (id INT,name TEXT,city TEXT,construction_date DATE,construction_company TEXT); INSERT INTO tunnel (id,name,city,construction_date,construction_company) VALUES (1,'Tunnel A','London','2020-01-01','Company A'); INSERT INTO tunnel (id,name,city,construction_date,construction_company) VALUES (2,'Tunnel ... | SELECT COUNT(*), construction_company FROM tunnel WHERE city = 'London' AND construction_date >= '2016-01-01' GROUP BY construction_company; |
What is the sequence of case events for each defendant, ordered by their timestamp? | CREATE TABLE defendant_events (id INT,defendant_id INT,event_type VARCHAR(255),timestamp TIMESTAMP); INSERT INTO defendant_events (id,defendant_id,event_type,timestamp) VALUES (1,1,'Arrest','2022-01-01 10:00:00'); INSERT INTO defendant_events (id,defendant_id,event_type,timestamp) VALUES (2,1,'Arraignment','2022-01-02 ... | SELECT defendant_id, event_type, timestamp, ROW_NUMBER() OVER(PARTITION BY defendant_id ORDER BY timestamp) as sequence FROM defendant_events; |
What is the total number of accidents for each mine in the last year? | CREATE TABLE mine (id INT,name TEXT,location TEXT); INSERT INTO mine (id,name,location) VALUES (1,'Mine I','Country R'),(2,'Mine J','Country Q'); CREATE TABLE accident_report (mine_id INT,timestamp TIMESTAMP); INSERT INTO accident_report (mine_id,timestamp) VALUES (1,'2022-01-01 00:00:00'),(2,'2022-02-01 00:00:00'); | SELECT mine_id, COUNT(*) as num_accidents FROM accident_report WHERE timestamp >= DATEADD(year, -1, CURRENT_TIMESTAMP) GROUP BY mine_id; |
Which countries have published the most creative AI applications? | CREATE TABLE application (name VARCHAR(255),country VARCHAR(255),publications INTEGER); INSERT INTO application (name,country,publications) VALUES ('Japan','Japan',300),('Germany','Germany',250),('Canada','Canada',200),('Australia','Australia',180),('Brazil','Brazil',150); | SELECT country, SUM(publications) as total_publications FROM application GROUP BY country ORDER BY total_publications DESC; |
What is the average rating of hotels in the APAC region that have more than 150 reviews? | CREATE TABLE hotels (id INT,name TEXT,region TEXT,rating FLOAT,reviews INT); INSERT INTO hotels (id,name,region,rating,reviews) VALUES (1,'Hotel Asia','APAC',4.2,180),(2,'Hotel Europe','EMEA',4.5,220),(3,'Hotel Americas','Americas',4.7,250),(4,'Hotel APAC','APAC',4.1,120); | SELECT AVG(rating) FROM hotels WHERE region = 'APAC' AND reviews > 150; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.