instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Which teams have the highest and lowest game attendance?
|
CREATE TABLE TeamStats (GameID INT,TeamID INT,HomeTeam VARCHAR(255),AwayTeam VARCHAR(255),HomeAttendance INT,AwayAttendance INT); INSERT INTO TeamStats (GameID,TeamID,HomeTeam,AwayTeam,HomeAttendance,AwayAttendance) VALUES (1,1,'Lakers','Celtics',15000,12000),(2,2,'Celtics','Bulls',18000,10000);
|
SELECT HomeTeam, AVG(HomeAttendance) as Avg_Home_Attendance, AwayTeam, AVG(AwayAttendance) as Avg_Away_Attendance FROM TeamStats GROUP BY HomeTeam, AwayTeam ORDER BY Avg_Home_Attendance DESC, Avg_Away_Attendance DESC;
|
What is the total revenue generated from all art classes in the past month?
|
CREATE TABLE ArtClasses (classID INT,classDate DATE,classFee DECIMAL(10,2)); INSERT INTO ArtClasses (classID,classDate,classFee) VALUES (16,'2022-04-05',100.00),(17,'2022-04-12',120.00),(18,'2022-04-26',150.00);
|
SELECT SUM(classFee) FROM ArtClasses WHERE classDate >= '2022-04-01' AND classDate <= '2022-04-30';
|
Calculate the average attendance for dance performances in the last 3 months in Paris, France.
|
CREATE TABLE events (id INT,event_name VARCHAR(255),attendance INT,event_date DATE); INSERT INTO events (id,event_name,attendance,event_date) VALUES (1,'Ballet',200,'2022-03-01'),(2,'Modern Dance',150,'2022-06-01');
|
SELECT AVG(attendance) FROM events WHERE event_name = 'Dance' AND event_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND city = 'Paris';
|
How many citizens provided feedback in District R and S in Q4 of 2021 and Q1 of 2022?
|
CREATE TABLE CitizenFeedback (District VARCHAR(10),Quarter INT,Year INT,FeedbackCount INT); INSERT INTO CitizenFeedback VALUES ('District R',4,2021,500),('District R',1,2022,600),('District S',4,2021,400),('District S',1,2022,500);
|
SELECT SUM(FeedbackCount) FROM CitizenFeedback WHERE District IN ('District R', 'District S') AND (Quarter = 4 AND Year = 2021 OR Quarter = 1 AND Year = 2022);
|
What are the budget allocations for the top 3 most expensive parks in the city of Chicago?
|
CREATE TABLE parks (name TEXT,city TEXT,budget_allocation INT); INSERT INTO parks (name,city,budget_allocation) VALUES ('Park A','Chicago',500000),('Park B','Chicago',450000),('Park C','Chicago',400000),('Park D','Chicago',350000);
|
SELECT name, budget_allocation FROM parks WHERE city = 'Chicago' ORDER BY budget_allocation DESC LIMIT 3;
|
How many climate change adaptation projects were implemented in India before 2010?
|
CREATE TABLE climate_change_projects (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255),start_year INT,end_year INT,funding_amount DECIMAL(10,2));
|
SELECT COUNT(*) FROM climate_change_projects WHERE type = 'climate change adaptation' AND location = 'India' AND start_year < 2010;
|
What is the total amount of loans issued by each lender in the last month?
|
CREATE TABLE lenders (lender_id INT,name VARCHAR(255),address VARCHAR(255)); CREATE TABLE loans (loan_id INT,lender_id INT,date DATE,amount DECIMAL(10,2));
|
SELECT lenders.name, SUM(loans.amount) FROM lenders INNER JOIN loans ON lenders.lender_id = loans.lender_id WHERE loans.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GROUP BY lenders.name;
|
Determine the total funding received by startups founded by Latinx individuals in the social media industry
|
CREATE TABLE founders (id INT,company_id INT,ethnicity VARCHAR(255)); CREATE TABLE companies (id INT,industry VARCHAR(255),funding_amount INT); INSERT INTO founders SELECT 1,1,'Latinx'; INSERT INTO founders SELECT 2,2,'Asian'; INSERT INTO founders SELECT 3,3,'Latinx'; INSERT INTO companies (id,industry,funding_amount) SELECT 2,'Education',3000000; INSERT INTO companies (id,industry,funding_amount) SELECT 3,'Social Media',5000000; INSERT INTO companies (id,industry,funding_amount) SELECT 4,'Retail',8000000;
|
SELECT SUM(companies.funding_amount) FROM founders JOIN companies ON founders.company_id = companies.id WHERE companies.industry = 'Social Media' AND founders.ethnicity = 'Latinx';
|
List the top 3 countries with the highest CO2 emissions in garment manufacturing.
|
CREATE TABLE co2_emissions (id INT,country VARCHAR(50),co2_emissions INT); INSERT INTO co2_emissions (id,country,co2_emissions) VALUES (1,'China',1000); INSERT INTO co2_emissions (id,country,co2_emissions) VALUES (2,'India',800); INSERT INTO co2_emissions (id,country,co2_emissions) VALUES (3,'Bangladesh',600); INSERT INTO co2_emissions (id,country,co2_emissions) VALUES (4,'Vietnam',400);
|
SELECT country, co2_emissions FROM co2_emissions ORDER BY co2_emissions DESC LIMIT 3;
|
What is the ratio of electric scooters to autonomous buses in Singapore?
|
CREATE TABLE singapore_escooters(id INT,count INT); INSERT INTO singapore_escooters VALUES (1,800),(2,850),(3,900); CREATE TABLE singapore_abuses(id INT,count INT); INSERT INTO singapore_abuses VALUES (1,500),(2,550),(3,600);
|
SELECT COUNT(*) * 1.0 / (SELECT COUNT(*) FROM singapore_abuses) FROM singapore_escooters;
|
What is the average duration of military operations in 'Africa' for the 'MilitaryOperations' schema?
|
CREATE SCHEMA IF NOT EXISTS MilitaryOperations; CREATE TABLE IF NOT EXISTS MilitaryOperations.Operations (operation_id INT,operation_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO MilitaryOperations.Operations (operation_id,operation_name,location,start_date,end_date) VALUES (1,'Operation Enduring Freedom','Afghanistan','2001-10-07','2014-12-28'),(2,'Operation Iraqi Freedom','Iraq','2003-03-19','2011-12-15'),(3,'Operation Flintlock','Africa','2005-02-22','2005-03-14');
|
SELECT AVG(DATEDIFF(end_date, start_date)) FROM MilitaryOperations.Operations WHERE location = 'Africa';
|
What is the total sales of all drugs in Japan?
|
CREATE TABLE sales (drug_id VARCHAR(10),country VARCHAR(10),sales_amount NUMERIC(12,2));
|
SELECT SUM(sales_amount) FROM sales WHERE country = 'Japan';
|
What is the minimum age of users who have created at least one post in the 'social_media' database?
|
CREATE TABLE users (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,location VARCHAR(50)); CREATE TABLE posts (id INT,user_id INT,content TEXT,timestamp TIMESTAMP);
|
SELECT MIN(users.age) AS min_age FROM users JOIN posts ON users.id = posts.user_id;
|
What is the number of students who have never taken a professional development course?
|
CREATE TABLE students (student_id INT,course_id INT); CREATE TABLE courses (course_id INT); INSERT INTO students (student_id,course_id) VALUES (1,101),(2,102),(3,103),(4,104); INSERT INTO courses (course_id) VALUES (101),(102),(103),(104),(105);
|
SELECT COUNT(s.student_id) as num_students FROM students s RIGHT JOIN courses c ON s.course_id = c.course_id WHERE s.student_id IS NULL;
|
How many public transportation trips were taken in April and May 2021?
|
CREATE SCHEMA gov_service;CREATE TABLE gov_service.transportation_data (month INT,trips_taken INT); INSERT INTO gov_service.transportation_data (month,trips_taken) VALUES (4,15000),(5,18000);
|
SELECT SUM(trips_taken) FROM gov_service.transportation_data WHERE month IN (4, 5);
|
List the top 5 warehouses with the highest total shipment count in Africa?
|
CREATE TABLE Warehouse (id INT,country VARCHAR(255),city VARCHAR(255),opened_date DATE); CREATE TABLE Shipments (id INT,warehouse_id INT,shipped_date DATE);
|
SELECT w.country, w.city, SUM(1) as total_shipments FROM Warehouse w JOIN Shipments s ON w.id = s.warehouse_id WHERE w.country = 'Africa' GROUP BY w.id, w.country, w.city ORDER BY total_shipments DESC LIMIT 5;
|
Delete military equipment records acquired before 2005
|
CREATE TABLE military_equipment (equipment_id INT,equipment_type VARCHAR(20),year_acquired INT);
|
DELETE FROM military_equipment WHERE year_acquired < 2005;
|
What is the maximum heart rate recorded for users?
|
CREATE TABLE workout (user_id INT,heart_rate INT); INSERT INTO workout (user_id,heart_rate) VALUES (1,120),(2,150),(3,180),(4,200);
|
SELECT MAX(heart_rate) FROM workout;
|
How many climate finance records were inserted for the year 2021?
|
CREATE TABLE climate_finance (record_id INT,project_name TEXT,funding_year INT,amount FLOAT); INSERT INTO climate_finance (record_id,project_name,funding_year,amount) VALUES (1,'Energy Efficiency 1',2021,3000000.00),(2,'Public Transport 2',2021,4000000.00),(3,'Green Buildings 3',2022,5000000.00);
|
SELECT COUNT(*) FROM climate_finance WHERE funding_year = 2021;
|
Generate a list of departments with their respective faculty members' average salaries.
|
CREATE TABLE Departments (DepartmentID INT,DepartmentName VARCHAR(50)); INSERT INTO Departments (DepartmentID,DepartmentName) VALUES (1,'Computer Science'); INSERT INTO Departments (DepartmentID,DepartmentName) VALUES (2,'Mathematics'); CREATE TABLE Faculty (FacultyID INT,FacultyName VARCHAR(50),DepartmentID INT,Salary DECIMAL(10,2)); INSERT INTO Faculty (FacultyID,FacultyName,DepartmentID,Salary) VALUES (1,'John Doe',1,80000); INSERT INTO Faculty (FacultyID,FacultyName,DepartmentID,Salary) VALUES (2,'Jane Smith',1,85000); INSERT INTO Faculty (FacultyID,FacultyName,DepartmentID,Salary) VALUES (3,'Alice Johnson',2,90000);
|
SELECT d.DepartmentName, AVG(f.Salary) as AvgSalary FROM Departments d JOIN Faculty f ON d.DepartmentID = f.DepartmentID GROUP BY d.DepartmentName;
|
What is the change in emissions for India from 2018 to 2020?
|
CREATE TABLE emissions_india (year INT,total_emissions INT); INSERT INTO emissions_india (year,total_emissions) VALUES (2018,3000),(2019,3200),(2020,3000);
|
SELECT (total_emissions::DECIMAL(10,2)-LAG(total_emissions) OVER ())/LAG(total_emissions) OVER ()*100 AS emission_change FROM emissions_india WHERE year IN (2019, 2020);
|
What is the average severity level of vulnerabilities for each country in the last year?
|
CREATE TABLE vulnerabilities (id INT,country VARCHAR(255),severity VARCHAR(255),timestamp TIMESTAMP);
|
SELECT country, AVG(severity = 'high') + AVG(severity = 'medium') * 0.5 + AVG(severity = 'low') * 0.25 AS avg_severity FROM vulnerabilities WHERE timestamp >= NOW() - INTERVAL 1 YEAR GROUP BY country;
|
Generate a view 'veteran_employment_trends' to display the number of employed and unemployed veterans by year
|
CREATE TABLE veteran_employment (id INT PRIMARY KEY,year INT,state VARCHAR(2),total_veterans INT,employed_veterans INT,unemployed_veterans INT);INSERT INTO veteran_employment (id,year,state,total_veterans,employed_veterans,unemployed_veterans) VALUES (1,2018,'CA',10000,8000,2000),(2,2018,'NY',8000,6500,1500),(3,2019,'CA',11000,9000,2000),(4,2019,'NY',9000,7500,1500);
|
CREATE VIEW veteran_employment_trends AS SELECT year, SUM(employed_veterans) as employed, SUM(unemployed_veterans) as unemployed FROM veteran_employment GROUP BY year;
|
Which countries have a marine research station in the Pacific Ocean and the Atlantic Ocean?
|
CREATE TABLE countries_oceans (country_name VARCHAR(50),pacific_station BOOLEAN,atlantic_station BOOLEAN); INSERT INTO countries_oceans (country_name,pacific_station,atlantic_station) VALUES ('USA',true,true),('Mexico',false,false);
|
SELECT country_name FROM countries_oceans WHERE pacific_station = true AND atlantic_station = true;
|
What is the total quantity of products sold in each country in the past year, ordered by total quantity in descending order?
|
CREATE TABLE orders (id INT PRIMARY KEY,product_id INT,quantity INT,order_date DATETIME,country VARCHAR(255),FOREIGN KEY (product_id) REFERENCES products(id)); INSERT INTO orders (id,product_id,quantity,order_date,country) VALUES (1,1,10,'2022-01-01 10:00:00','USA'),(2,2,20,'2022-01-02 15:00:00','Canada'),(3,3,30,'2022-01-03 09:00:00','Mexico');
|
SELECT o.country, SUM(o.quantity) as total_quantity FROM orders o WHERE YEAR(o.order_date) = YEAR(CURRENT_DATE - INTERVAL 1 YEAR) GROUP BY o.country ORDER BY total_quantity DESC;
|
What is the total grant amount awarded to each department in the College of Engineering?
|
CREATE TABLE grants (id INT,department VARCHAR(50),grant_amount DECIMAL(10,2)); INSERT INTO grants (id,department,grant_amount) VALUES (1,'Civil Engineering',500000.00); CREATE VIEW engineering_departments AS SELECT DISTINCT department FROM grants WHERE department LIKE 'Engineering%';
|
SELECT department, SUM(grant_amount) FROM grants JOIN engineering_departments ON grants.department = engineering_departments.department GROUP BY department;
|
Update the status of satellites that have been in orbit for more than 5 years
|
CREATE TABLE Satellites (ID INT,Name VARCHAR(50),LaunchDate DATE,Status VARCHAR(50)); INSERT INTO Satellites (ID,Name,LaunchDate,Status) VALUES (1,'Sat1','2018-01-01','Active'),(2,'Sat2','2020-05-15','Active'),(3,'Sat3','2019-09-01','Inactive'),(4,'Sat4','2016-03-01','Active'),(5,'Sat5','2017-12-25','Active');
|
UPDATE Satellites SET Status = 'Inactive' WHERE ID IN (SELECT ID FROM (SELECT ID, DATEDIFF(year, LaunchDate, GETDATE()) as YearsInOrbit FROM Satellites) as Satellites WHERE YearsInOrbit > 5);
|
How many virtual tours were conducted in the 'Americas' region in the last quarter?
|
CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,region VARCHAR(20),tour_date DATE);
|
SELECT COUNT(*) FROM virtual_tours WHERE region = 'Americas' AND tour_date >= DATE(NOW()) - INTERVAL 3 MONTH;
|
What is the total number of NFT transactions in the 'binance' network?
|
CREATE TABLE blockchain (id INT,network VARCHAR(20),tx_type VARCHAR(20),tx_count INT); INSERT INTO blockchain (id,network,tx_type,tx_count) VALUES (1,'binance','NFT',1000);
|
SELECT SUM(tx_count) FROM blockchain WHERE network = 'binance' AND tx_type = 'NFT';
|
How many mobile and broadband subscribers does each network type have in Canada?
|
CREATE TABLE subscriber_data (subscriber_id INT,network_type VARCHAR(10),subscriber_type VARCHAR(10)); INSERT INTO subscriber_data (subscriber_id,network_type,subscriber_type) VALUES (1,'4G','mobile'),(2,'5G','mobile'),(3,'Fiber','broadband');
|
SELECT network_type, COUNT(*) as total_subscribers FROM subscriber_data WHERE subscriber_type IN ('mobile', 'broadband') GROUP BY network_type;
|
Which directors have directed movies with a runtime greater than the average runtime?
|
CREATE TABLE movies (id INT,title TEXT,director TEXT,runtime INT);
|
SELECT director FROM movies WHERE runtime > (SELECT AVG(runtime) FROM movies) GROUP BY director;
|
Delete all donations made in March 2022.
|
CREATE TABLE Donors (DonorID int,Name varchar(50),TotalDonation money); CREATE TABLE Donations (DonationID int,DonorID int,Amount money,DonationDate date); INSERT INTO Donors (DonorID,Name,TotalDonation) VALUES (1,'John Doe',5000),(2,'Jane Smith',7000); INSERT INTO Donations (DonationID,DonorID,Amount,DonationDate) VALUES (5,1,1000,'2022-02-14'),(6,1,1500,'2022-03-01'),(7,2,2000,'2022-03-15'),(8,2,4000,'2022-04-20');
|
DELETE D FROM Donations D WHERE MONTH(D.DonationDate) = 3 AND YEAR(D.DonationDate) = 2022;
|
List all suppliers and their average price of 'Chicken' in 'Farm2Table' and 'HealthyHarvest'.
|
CREATE TABLE Farm2Table (supplier_id INT,product_id INT); CREATE TABLE Suppliers (supplier_id INT,supplier_name VARCHAR(50)); CREATE TABLE Products (product_id INT,product_name VARCHAR(50),price FLOAT); CREATE TABLE HealthyHarvest (supplier_id INT,product_id INT,price FLOAT); INSERT INTO Suppliers (supplier_id,supplier_name) VALUES (1,'Local Farm'),(2,'Small Dairy'),(3,'Free Range Ranch'),(4,'Green Valley'); INSERT INTO Products (product_id,product_name,price) VALUES (1,'Eggs',4.0),(2,'Milk',3.5),(3,'Chicken',6.5),(4,'Beef',12.0); INSERT INTO Farm2Table (supplier_id,product_id) VALUES (1,1),(1,3),(2,2),(2,4),(3,3),(4,2); INSERT INTO HealthyHarvest (supplier_id,product_id,price) VALUES (1,3,7.0),(2,2,4.0),(3,3,6.0),(4,2,3.5);
|
SELECT s.supplier_name, AVG(h.price) as avg_price FROM Suppliers s INNER JOIN Farm2Table ft ON s.supplier_id = ft.supplier_id INNER JOIN Products p ON ft.product_id = p.product_id INNER JOIN HealthyHarvest h ON s.supplier_id = h.supplier_id WHERE p.product_name = 'Chicken' GROUP BY s.supplier_id;
|
What is the average number of subway delays in 'suburbia' per month?
|
CREATE TABLE subway_delays (station VARCHAR(20),delay_time INT,delay_date DATE); INSERT INTO subway_delays (station,delay_time,delay_date) VALUES ('suburbia',8,'2022-02-01'),('downtown',4,'2022-02-02'),('suburbia',12,'2022-02-03');
|
SELECT AVG(delay_time) FROM subway_delays WHERE station = 'suburbia' GROUP BY EXTRACT(MONTH FROM delay_date);
|
How many soil moisture sensors have a temperature above 25 degrees in 'Field003'?
|
CREATE TABLE soil_moisture_sensors (id INT,field_id VARCHAR(10),sensor_id VARCHAR(10),temperature FLOAT); INSERT INTO soil_moisture_sensors (id,field_id,sensor_id,temperature) VALUES (1,'Field003','SM003',26.1),(2,'Field003','SM004',24.9);
|
SELECT COUNT(*) FROM soil_moisture_sensors WHERE field_id = 'Field003' AND temperature > 25;
|
Find the total transaction value for social impact investments in the 'Climate Action' category in Asia.
|
CREATE TABLE social_impact_investments (id INT,region VARCHAR(50),category VARCHAR(50),transaction_value FLOAT); INSERT INTO social_impact_investments (id,region,category,transaction_value) VALUES (1,'Asia','Climate Action',8000.0),(2,'Europe','Gender Equality',6000.0),(3,'Africa','Climate Action',10000.0),(4,'North America','Renewable Energy',5000.0);
|
SELECT SUM(transaction_value) FROM social_impact_investments WHERE region = 'Asia' AND category = 'Climate Action';
|
What is the average arrival time of flights from Tokyo to Sydney?
|
CREATE TABLE Flights (FlightID INT,DepartureCity VARCHAR(20),ArrivalCity VARCHAR(20),DepartureTime TIMESTAMP); INSERT INTO Flights (FlightID,DepartureCity,ArrivalCity,DepartureTime) VALUES (1,'Tokyo','Sydney','2022-01-01 10:30:00'),(2,'Tokyo','Sydney','2022-01-02 11:15:00');
|
SELECT AVG(EXTRACT(HOUR FROM DepartureTime)) AS AvgDepartureHour FROM Flights WHERE DepartureCity = 'Tokyo' AND ArrivalCity = 'Sydney';
|
How many mining operations were conducted in the year 2020 and what was the total cost?
|
CREATE TABLE Mining_Operations (id INT,operation_name VARCHAR(50),location VARCHAR(50),cost FLOAT,year INT); INSERT INTO Mining_Operations (id,operation_name,location,cost,year) VALUES (1,'Operation A','USA',100000.00,2020),(2,'Operation B','Canada',120000.00,2019),(3,'Operation C','Mexico',90000.00,2020),(4,'Operation D','USA',80000.00,2019);
|
SELECT COUNT(*), SUM(cost) FROM Mining_Operations WHERE year = 2020;
|
Insert a new record into the 'veteran_employment' table for a veteran hired as a 'data analyst' on 2022-02-20 with a salary of $70,000
|
CREATE TABLE veteran_employment (veteran_id INT,job_title VARCHAR(30),hire_date DATE,salary FLOAT);
|
INSERT INTO veteran_employment (veteran_id, job_title, hire_date, salary) VALUES (2, 'data analyst', '2022-02-20', 70000);
|
Count the number of female students who have enrolled in the 'OpenCourses' platform from 'California' after 2018-01-01
|
CREATE TABLE Students (StudentID INT,Gender VARCHAR(10),EnrollmentDate DATE); INSERT INTO Students (StudentID,Gender,EnrollmentDate) VALUES (1,'Female','2019-01-02');
|
SELECT COUNT(*) FROM Students WHERE Gender = 'Female' AND EnrollmentDate >= '2018-01-01' AND State = 'California' AND Platform = 'OpenCourses';
|
List the top 3 organic items with the lowest inventory value?
|
CREATE TABLE organic_inventory (item_id INT,item_name VARCHAR(255),category VARCHAR(255),quantity INT,unit_price DECIMAL(5,2)); INSERT INTO organic_inventory (item_id,item_name,category,quantity,unit_price) VALUES (1,'Apples','Fruits',100,0.99),(2,'Bananas','Fruits',150,0.69),(3,'Carrots','Vegetables',75,1.49),(4,'Quinoa','Grains',50,3.99),(5,'Almonds','Nuts',30,8.99);
|
SELECT item_name, quantity * unit_price as total_value FROM organic_inventory ORDER BY total_value LIMIT 3;
|
What is the total number of mining accidents in each province in Canada?
|
CREATE TABLE accidents (id INT,province VARCHAR(50),industry VARCHAR(50),num_accidents INT); INSERT INTO accidents (id,province,industry,num_accidents) VALUES (1,'Ontario','mining',50); INSERT INTO accidents (id,province,industry,num_accidents) VALUES (2,'Quebec','mining',30); INSERT INTO accidents (id,province,industry,num_accidents) VALUES (3,'Alberta','oil',20);
|
SELECT province, SUM(num_accidents) FROM accidents WHERE industry = 'mining' GROUP BY province;
|
What is the total quantity of 'vegan leather' products sold by each supplier?
|
CREATE TABLE suppliers(supplier_id INT,supplier_name TEXT); INSERT INTO suppliers(supplier_id,supplier_name) VALUES (1,'Plant-Based Leather Inc'),(2,'Eco-Friendly Leathers Ltd'); CREATE TABLE products(product_id INT,product_name TEXT,supplier_id INT,price DECIMAL,quantity INT); INSERT INTO products(product_id,product_name,supplier_id,price,quantity) VALUES (1,'Vegan Leather Jacket',1,129.99,25),(2,'Vegan Leather Bag',1,69.99,75),(3,'Eco-Leather Jacket',2,119.99,30); CREATE TABLE sales(sale_id INT,product_id INT); INSERT INTO sales(sale_id,product_id) VALUES (1,1),(2,2),(3,3);
|
SELECT suppliers.supplier_name, SUM(products.quantity) FROM suppliers JOIN products ON suppliers.supplier_id = products.supplier_id JOIN sales ON products.product_id = sales.product_id WHERE products.product_name LIKE '%vegan leather%' GROUP BY suppliers.supplier_name;
|
How many sustainable building projects were completed in New York in 2020?
|
CREATE TABLE SustainableBuildings (id INT,project_start DATE,project_end DATE,city VARCHAR(20)); INSERT INTO SustainableBuildings (id,project_start,project_end,city) VALUES (1,'2020-01-01','2020-04-01','New York'),(2,'2019-06-15','2019-11-30','Los Angeles');
|
SELECT COUNT(*) FROM SustainableBuildings WHERE city = 'New York' AND YEAR(project_start) = 2020 AND YEAR(project_end) = 2020;
|
Display the total grant amount awarded to each department.
|
CREATE TABLE DepartmentGrants (Department VARCHAR(50),GrantID INT,GrantAmount DECIMAL(10,2)); INSERT INTO DepartmentGrants (Department,GrantID,GrantAmount) VALUES ('Chemistry',1,50000); INSERT INTO DepartmentGrants (Department,GrantID,GrantAmount) VALUES ('Biology',2,75000); INSERT INTO DepartmentGrants (Department,GrantID,GrantAmount) VALUES ('Physics',3,100000);
|
SELECT Department, SUM(GrantAmount) as TotalGrantAmount FROM DepartmentGrants GROUP BY Department;
|
What is the average age of all rock artists in the database?
|
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,ArtistName VARCHAR(100),Age INT,Genre VARCHAR(50)); INSERT INTO Artists (ArtistID,ArtistName,Age,Genre) VALUES (1,'Artist A',35,'Rock'),(2,'Artist B',45,'Jazz'),(3,'Artist C',28,'Rock');
|
SELECT AVG(Age) FROM Artists WHERE Genre = 'Rock';
|
What is the distribution of content by region?
|
CREATE TABLE content (id INT,title VARCHAR(255),region VARCHAR(255)); INSERT INTO content (id,title,region) VALUES (1,'Content1','North America'),(2,'Content2','Europe'),(3,'Content3','Asia'),(4,'Content4','Africa'),(5,'Content5','South America');
|
SELECT region, COUNT(*) as count FROM content GROUP BY region;
|
Show the monthly revenue trend for the top 2 revenue-generating menu items?
|
CREATE TABLE sales (sale_id INT,menu_item VARCHAR(255),revenue INT,sale_date DATE); INSERT INTO sales (sale_id,menu_item,revenue,sale_date) VALUES (1,'Impossible Burger',500,'2022-01-01'),(2,'Beyond Sausage',700,'2022-01-02'),(3,'Local Greens Salad',600,'2022-02-01'),(4,'Tofu Stir Fry',800,'2022-02-02'),(5,'Chicken Caesar Salad',900,'2022-03-01');
|
SELECT DATE_FORMAT(s.sale_date, '%Y-%m') AS month, m.menu_item, SUM(s.revenue) AS monthly_revenue FROM sales s JOIN (SELECT menu_item, MAX(revenue) AS max_revenue FROM sales GROUP BY menu_item LIMIT 2) ms ON s.menu_item = ms.menu_item JOIN menu m ON s.menu_item = m.menu_item GROUP BY m.menu_item, month ORDER BY monthly_revenue DESC;
|
List of cities in the USA with population over 500,000 in descending order by population size.
|
CREATE TABLE cities (id INT,name VARCHAR(50),population INT,country VARCHAR(50)); INSERT INTO cities (id,name,population,country) VALUES (1,'New York',8500000,'USA'),(2,'Los Angeles',4000000,'USA'),(3,'Chicago',2700000,'USA'),(4,'Houston',2300000,'USA'),(5,'Phoenix',1700000,'USA');
|
SELECT name FROM cities WHERE country = 'USA' AND population > 500000 ORDER BY population DESC;
|
List games from 'game_design' table with ratings higher than the average rating
|
CREATE TABLE game_design (game_id INT,game_name VARCHAR(50),genre VARCHAR(50),rating FLOAT);
|
SELECT * FROM game_design WHERE rating > (SELECT AVG(rating) FROM game_design);
|
Delete permit 2022-005 from the database
|
CREATE TABLE building_permits (permit_number TEXT,contractor TEXT); INSERT INTO building_permits (permit_number,contractor) VALUES ('2022-005','Contractor C');
|
WITH cte AS (DELETE FROM building_permits WHERE permit_number = '2022-005') SELECT * FROM cte;
|
What is the total biomass of fish in each aquaculture farm?
|
CREATE TABLE FarmStocks (FarmID INT,Species VARCHAR(20),Biomass FLOAT); CREATE TABLE Farms (FarmID INT,FarmName VARCHAR(50)); INSERT INTO Farms (FarmID,FarmName) VALUES (1,'Farm A'),(2,'Farm B'); INSERT INTO FarmStocks (FarmID,Species,Biomass) VALUES (1,'Tilapia',1500),(1,'Salmon',2000),(2,'Trout',2500),(2,'Tilapia',1200);
|
SELECT FarmName, SUM(Biomass) FROM FarmStocks JOIN Farms ON FarmStocks.FarmID = Farms.FarmID GROUP BY FarmName;
|
What is the total installed capacity of geothermal plants in Indonesia?
|
CREATE TABLE geothermal_plants (id INT,name VARCHAR(255),location VARCHAR(255),capacity FLOAT); INSERT INTO geothermal_plants (id,name,location,capacity) VALUES (1,'Sinabung Geothermal Power Plant','Indonesia',190.0); INSERT INTO geothermal_plants (id,name,location,capacity) VALUES (2,'Darajat Geothermal Power Plant','Indonesia',230.0);
|
SELECT SUM(capacity) FROM geothermal_plants WHERE location = 'Indonesia';
|
Delete the record for 'Sign Language Interpreter' from the support_program table.
|
CREATE TABLE support_program (program_id INT,program_name TEXT,org_id INT); INSERT INTO support_program (program_id,program_name,org_id) VALUES (1,'Adaptive Sports',1); INSERT INTO support_program (program_id,program_name,org_id) VALUES (2,'Assistive Technology',2); INSERT INTO support_program (program_id,program_name,org_id) VALUES (3,'Sign Language Interpreter',1);
|
DELETE FROM support_program WHERE program_name = 'Sign Language Interpreter';
|
What is the percentage of patients by ethnicity and gender?
|
CREATE TABLE patients (id INT,name VARCHAR(50),ethnicity VARCHAR(50),gender VARCHAR(10)); INSERT INTO patients (id,name,ethnicity,gender) VALUES (1,'John Doe','Caucasian','Male'),(2,'Jane Smith','African American','Female'),(3,'Alice Johnson','Hispanic','Female');
|
SELECT ethnicity, gender, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM patients) AS percentage FROM patients GROUP BY ethnicity, gender;
|
Find the total number of bike-share trips taken in Paris during rush hour (7-10 AM and 4-7 PM) on weekdays.
|
CREATE TABLE paris_bikeshare (id INT,ride_time TIME,is_weekday BOOLEAN,trip_duration INT); INSERT INTO paris_bikeshare (id,ride_time,is_weekday,trip_duration) VALUES (1,'07:30:00',TRUE,30),(2,'18:45:00',TRUE,45);
|
SELECT COUNT(*) FROM paris_bikeshare WHERE is_weekday = TRUE AND (ride_time BETWEEN '07:00:00' AND '10:00:00' OR ride_time BETWEEN '16:00:00' AND '19:00:00');
|
What is the number of community health workers who have received cultural competency training in the last year?
|
CREATE TABLE CommunityHealthWorker (WorkerID INT,TrainingDate DATE); INSERT INTO CommunityHealthWorker (WorkerID,TrainingDate) VALUES (1,'2022-02-01'),(2,'2022-03-15'),(3,'2021-12-20'),(4,'2022-01-05'),(5,'2021-11-08'),(6,'2022-04-10'),(7,'2022-03-22'),(8,'2022-02-28'),(9,'2021-12-12'),(10,'2022-01-18');
|
SELECT COUNT(*) as Total FROM CommunityHealthWorker WHERE TrainingDate >= DATEADD(year, -1, GETDATE());
|
Who are the policy advocates for policies related to cognitive disabilities?
|
CREATE TABLE Policies (PolicyID INT,PolicyName VARCHAR(50),PolicyType VARCHAR(50)); INSERT INTO Policies VALUES (1,'Assistive Technology','Academic'); CREATE TABLE PolicyAdvocates (AdvocateID INT,AdvocateName VARCHAR(50),PolicyID INT); INSERT INTO PolicyAdvocates VALUES (1,'Jamie Rodriguez',1); CREATE TABLE PolicyDetails (PolicyID INT,DisabilityType VARCHAR(50)); INSERT INTO PolicyDetails VALUES (1,'Cognitive Disability');
|
SELECT pa.AdvocateName FROM Policies p INNER JOIN PolicyDetails pd ON p.PolicyID = pd.PolicyID INNER JOIN PolicyAdvocates pa ON p.PolicyID = pa.PolicyID WHERE pd.DisabilityType = 'Cognitive Disability';
|
What is the total quantity of sustainable material A used in products manufactured in Italy and Spain?
|
CREATE TABLE materials (product_id INT,material_type VARCHAR(50),material_quantity INT); CREATE TABLE products (product_id INT,country VARCHAR(50),material_A_used INT); INSERT INTO materials (product_id,material_type,material_quantity) VALUES (1,'sustainable material A',100),(2,'sustainable material B',50),(3,'sustainable material A',150); INSERT INTO products (product_id,country,material_A_used) VALUES (1,'Italy',75),(2,'Spain',100),(3,'Italy',125);
|
SELECT SUM(materials.material_quantity) FROM materials INNER JOIN products ON materials.product_id = products.product_id WHERE products.country IN ('Italy', 'Spain') AND materials.material_type = 'sustainable material A';
|
Which dams in Texas are over 100 feet tall?
|
CREATE TABLE Dams (Name VARCHAR(255),Height_feet INT,State VARCHAR(255)); INSERT INTO Dams (Name,Height_feet,State) VALUES ('Amistad Dam',246,'Texas');
|
SELECT Name FROM Dams WHERE Height_feet > 100 AND State = 'Texas';
|
What is the average time to resolve security incidents for each category in the 'incident_response' table?
|
CREATE TABLE incident_response (id INT,incident_category VARCHAR(50),resolution_time INT); INSERT INTO incident_response (id,incident_category,resolution_time) VALUES (1,'Malware',480),(2,'Phishing',240),(3,'Malware',720),(4,'Phishing',360),(5,'DDoS',1440);
|
SELECT incident_category, AVG(resolution_time) FROM incident_response GROUP BY incident_category;
|
Insert a new record for a farm with farm ID 2 and species ID 2
|
CREATE TABLE Aquatic_Farm (Farm_ID INT,Farm_Name VARCHAR(100),Species_ID INT,Stock_Quantity INT); INSERT INTO Aquatic_Farm (Farm_ID,Farm_Name,Species_ID,Stock_Quantity) VALUES (1,'North Sea Fishery',1,25000);
|
INSERT INTO Aquatic_Farm (Farm_ID, Farm_Name, Species_ID, Stock_Quantity) VALUES (2, 'Pacific Fishery', 2, 15000);
|
Find the number of unique users who streamed a given artist's music in a given year.
|
CREATE TABLE Artists (id INT,name VARCHAR(100)); CREATE TABLE Users (id INT,name VARCHAR(100)); CREATE TABLE Streams (id INT,user_id INT,artist_id INT,minutes DECIMAL(10,2),year INT);
|
SELECT artist_id, COUNT(DISTINCT user_id) AS unique_users FROM Streams WHERE year = 2021 GROUP BY artist_id;
|
What is the total amount of funds spent on disaster response projects in Asia?
|
CREATE TABLE Projects (project_id INT,project_location VARCHAR(50),project_type VARCHAR(50),project_funding DECIMAL(10,2)); INSERT INTO Projects (project_id,project_location,project_type,project_funding) VALUES (1,'India','Disaster Response',200000.00),(2,'Canada','Education',50000.00),(3,'China','Disaster Response',300000.00);
|
SELECT SUM(project_funding) FROM Projects WHERE project_type = 'Disaster Response' AND project_location LIKE 'Asia%';
|
What is the average weight of all satellites in the satellites table?
|
CREATE TABLE satellites (name TEXT,country TEXT,weight FLOAT); INSERT INTO satellites (name,country,weight) VALUES ('Sentinel-1A','European Union',2300.0);
|
SELECT AVG(weight) FROM satellites;
|
What is the maximum explainability score for each AI technique in the 'tech_explainability' table?
|
CREATE TABLE tech_explainability (technique_name TEXT,explainability_score FLOAT); INSERT INTO tech_explainability (technique_name,explainability_score) VALUES ('TechniqueX',0.75),('TechniqueY',0.90),('TechniqueZ',0.85);
|
SELECT technique_name, MAX(explainability_score) OVER (PARTITION BY technique_name) AS max_explainability_score FROM tech_explainability;
|
Delete the 'military_weapon_system' with 'system_id' 1 from the 'military_weapon_systems' table
|
CREATE TABLE military_weapon_systems (system_id INT PRIMARY KEY,system_name VARCHAR(100),system_type VARCHAR(50),manufacturer VARCHAR(100)); INSERT INTO military_weapon_systems (system_id,system_name,system_type,manufacturer) VALUES (1,'Patriot Missile System','Air Defense Missile System','Raytheon'),(2,'Tomahawk Cruise Missile','Missile','Raytheon'),(3,'Aegis Ballistic Missile Defense System','Shipboard Missile Defense System','Lockheed Martin');
|
DELETE FROM military_weapon_systems WHERE system_id = 1;
|
Delete the 'DEF' warehouse and all associated shipments
|
CREATE TABLE warehouse (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO warehouse (id,name) VALUES (1,'ABC'),(2,'DEF'); CREATE TABLE shipments (id INT PRIMARY KEY,warehouse_id INT,FOREIGN KEY (warehouse_id) REFERENCES warehouse(id)); INSERT INTO shipments (id,warehouse_id) VALUES (1,1),(2,2);
|
WITH w AS (DELETE FROM warehouse WHERE name = 'DEF' RETURNING id) DELETE FROM shipments WHERE warehouse_id IN (SELECT id FROM w);
|
Insert a new record into the "player_demographics" table with player_id 5, age 30, and gender "Transgender Male"
|
CREATE TABLE player_demographics (player_id INT,age INT,gender VARCHAR(50)); INSERT INTO player_demographics (player_id,age,gender) VALUES (1,25,'Male'),(2,35,'Female'),(3,17,'Female'),(4,22,'Non-binary');
|
INSERT INTO player_demographics (player_id, age, gender) VALUES (5, 30, 'Transgender Male');
|
What is the average age of healthcare workers in California?
|
CREATE TABLE healthcare_workers (id INT,name TEXT,age INT,state TEXT); INSERT INTO healthcare_workers (id,name,age,state) VALUES (1,'John Doe',35,'California'); INSERT INTO healthcare_workers (id,name,age,state) VALUES (2,'Jane Smith',40,'California');
|
SELECT AVG(age) FROM healthcare_workers WHERE state = 'California';
|
What is the average capacity of cargo ships that have visited the Port of Oakland?
|
CREATE SCHEMA if not exists ocean_shipping;CREATE TABLE if not exists ocean_shipping.ships (id INT PRIMARY KEY,name VARCHAR(100),capacity INT);CREATE TABLE if not exists ocean_shipping.trips (id INT PRIMARY KEY,ship_id INT,port VARCHAR(100));INSERT INTO ocean_shipping.ships (id,name,capacity) VALUES (1,'SS Oakland 1',4000),(2,'SS Oakland 2',6000);INSERT INTO ocean_shipping.trips (id,ship_id,port) VALUES (1,1,'Port of Oakland'),(2,2,'Port of Oakland');
|
SELECT AVG(capacity) FROM ocean_shipping.ships INNER JOIN ocean_shipping.trips ON ships.id = trips.ship_id WHERE trips.port = 'Port of Oakland';
|
List all artists who have never performed a concert in the United States.
|
CREATE TABLE concerts (concert_id INT,artist_name VARCHAR(100),concert_location VARCHAR(100)); INSERT INTO concerts (concert_id,artist_name,concert_location) VALUES (1,'Taylor Swift','New York,USA'); INSERT INTO concerts (concert_id,artist_name,concert_location) VALUES (2,'BTS','Seoul,South Korea'); INSERT INTO concerts (concert_id,artist_name,concert_location) VALUES (3,'Dua Lipa','London,UK');
|
SELECT artist_name FROM concerts WHERE concert_location NOT LIKE '%USA%' GROUP BY artist_name HAVING COUNT(*) = 1;
|
What is the distribution of user ratings for movies released in the US in 2016?
|
CREATE TABLE movie_reviews (id INT,user_id INT,movie_id INT,rating INT); CREATE VIEW movie_summary AS SELECT m.id,m.title,m.release_year,m.country,AVG(mr.rating) as avg_rating FROM movies m JOIN movie_reviews mr ON m.id = mr.movie_id GROUP BY m.id;
|
SELECT avg_rating, COUNT(*) as num_movies FROM movie_summary WHERE release_year = 2016 AND country = 'USA' GROUP BY avg_rating;
|
What is the total number of songs and the average length of songs in the "pop" genre, produced by female artists from the United States, released in the last 5 years?
|
CREATE TABLE Songs(id INT,title VARCHAR(30),genre VARCHAR(10),artist VARCHAR(20),country VARCHAR(20),release_date DATE,length FLOAT);
|
SELECT 'total songs' AS metric, COUNT(*) FROM Songs WHERE genre = 'pop' AND artist GLOB '*female*' AND country = 'United States' AND release_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) AND length IS NOT NULL; SELECT 'average song length' AS metric, AVG(length) FROM Songs WHERE genre = 'pop' AND artist GLOB '*female*' AND country = 'United States' AND release_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) AND length IS NOT NULL;
|
What is the total budget (in USD) for agroforestry projects in Central America and how many of them are using permaculture techniques?
|
CREATE TABLE AgroforestryProject (id INT,region VARCHAR(50),budget DECIMAL(10,2),permaculture BOOLEAN); INSERT INTO AgroforestryProject (id,region,budget,permaculture) VALUES (1,'Central America',15000.0,true); INSERT INTO AgroforestryProject (id,region,budget,permaculture) VALUES (2,'Central America',20000.0,false);
|
SELECT SUM(budget), SUM(permaculture) FROM AgroforestryProject WHERE region = 'Central America';
|
What is the sum of funding for all biotech startups based in Canada?
|
CREATE SCHEMA if not exists biotech; USE biotech; CREATE TABLE if not exists startups (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),funding DECIMAL(10,2)); INSERT INTO startups (id,name,location,funding) VALUES (1,'StartupA','USA',15000000.50),(2,'StartupB','USA',22000000.25),(3,'StartupC','Canada',5000000.00),(4,'StartupD','Canada',7000000.00);
|
SELECT SUM(funding) FROM biotech.startups WHERE location = 'Canada';
|
What is the minimum yield of 'corn' for each state?
|
CREATE TABLE states (id INT PRIMARY KEY,name TEXT,region TEXT); INSERT INTO states (id,name,region) VALUES (1,'Alabama','South'); CREATE TABLE crops (id INT PRIMARY KEY,state_id INT,crop TEXT,yield REAL); INSERT INTO crops (id,state_id,crop,yield) VALUES (1,1,'corn',2.5);
|
SELECT state_id, MIN(yield) FROM crops WHERE crop = 'corn' GROUP BY state_id;
|
How many packages arrived at the 'NY' warehouse from 'Mexico' in the last week, and how many of those were damaged?
|
CREATE TABLE warehouse (id INT PRIMARY KEY,name VARCHAR(50),city VARCHAR(50));CREATE TABLE carrier (id INT PRIMARY KEY,name VARCHAR(50));CREATE TABLE shipment (id INT PRIMARY KEY,warehouse_id INT,carrier_id INT,package_count INT,damaged_count INT,shipped_date DATE);
|
SELECT SUM(shipment.package_count), SUM(shipment.damaged_count) FROM shipment WHERE shipment.warehouse_id = (SELECT id FROM warehouse WHERE city = 'NY') AND shipment.shipped_date BETWEEN (CURRENT_DATE - INTERVAL '7 days') AND CURRENT_DATE AND (SELECT name FROM carrier WHERE id = shipment.carrier_id) = 'Mexico';
|
Count the number of bridges in Japan
|
CREATE TABLE infrastructure_projects (id INT,name TEXT,type TEXT,location TEXT); INSERT INTO infrastructure_projects (id,name,type,location) VALUES (1,'Brooklyn Bridge','Bridge','USA'); INSERT INTO infrastructure_projects (id,name,type,location) VALUES (2,'Chunnel','Tunnel','UK'); INSERT INTO infrastructure_projects (id,name,type,location) VALUES (3,'Tokyo Tower','Tower','Japan'); INSERT INTO infrastructure_projects (id,name,type,location) VALUES (4,'Golden Gate Bridge','Bridge','USA');
|
SELECT COUNT(*) FROM infrastructure_projects WHERE type = 'Bridge' AND location = 'Japan';
|
Which sustainable tourism initiatives have been implemented in Costa Rica?
|
CREATE TABLE sustainable_tourism (id INT,country VARCHAR(50),initiative VARCHAR(100)); INSERT INTO sustainable_tourism (id,country,initiative) VALUES (1,'Costa Rica','Carbon neutral by 2050'),(2,'Costa Rica','Banned single-use plastics');
|
SELECT initiative FROM sustainable_tourism WHERE country = 'Costa Rica';
|
What is the number of students who received accommodations by gender?
|
CREATE TABLE disability_accommodations (student_id INT,disability_type VARCHAR(50),gender VARCHAR(50)); INSERT INTO disability_accommodations (student_id,disability_type,gender) VALUES (1,'Physical','Female');
|
SELECT gender, COUNT(*) as total_students FROM disability_accommodations GROUP BY gender;
|
Which policies have been modified in the last week?
|
CREATE TABLE policies (id INT,policy_name VARCHAR(50),last_modified DATE);
|
SELECT policy_name FROM policies WHERE last_modified >= DATEADD(week, -1, GETDATE());
|
Which sustainable building projects in Australia started between 2019 and 2021?
|
CREATE TABLE project_australia (project_id INT,country VARCHAR(50),project_type VARCHAR(50),start_date DATE); INSERT INTO project_australia (project_id,country,project_type,start_date) VALUES (1,'Australia','Sustainable','2019-05-01');
|
SELECT * FROM project_australia WHERE country = 'Australia' AND project_type = 'Sustainable' AND start_date BETWEEN '2019-01-01' AND '2021-12-31';
|
What is the percentage of sustainable building projects in OR?
|
CREATE TABLE SustainableProjects (ProjectID int,State varchar(25),Sustainable bit); INSERT INTO SustainableProjects (ProjectID,State,Sustainable) VALUES (1,'OR',1),(2,'OR',0),(3,'OR',1);
|
SELECT State, (COUNT(*) FILTER (WHERE Sustainable = 1) * 100.0 / COUNT(*)) AS Percentage FROM SustainableProjects WHERE State = 'OR' GROUP BY State;
|
What is the average budget for agricultural innovation initiatives in South America, broken down by initiative type and contributing organization?
|
CREATE TABLE agricultural_innovation (id INT,country VARCHAR(50),initiative VARCHAR(50),budget INT,contributor VARCHAR(50)); INSERT INTO agricultural_innovation (id,country,initiative,budget,contributor) VALUES (1,'Brazil','Precision Agriculture',2000000,'Government'),(2,'Argentina','Sustainable Agriculture',3000000,'Private'),(3,'Colombia','Agroforestry',4000000,'NGO');
|
SELECT initiative, contributor, AVG(budget) as avg_budget FROM agricultural_innovation WHERE country IN ('Brazil', 'Argentina', 'Colombia') GROUP BY initiative, contributor;
|
How many virtual tours were engaged with in the Americas in the past month?
|
CREATE TABLE virtual_tours (id INT,location TEXT,date DATE,engagement INT); INSERT INTO virtual_tours (id,location,date,engagement) VALUES (1,'Hotel 1','2022-01-01',50),(2,'Hotel 2','2022-01-05',75),(3,'Hotel 3','2022-02-01',100),(4,'Hotel 4','2022-02-10',125),(5,'Hotel 5','2022-03-01',150),(6,'Hotel 6','2022-03-15',175);
|
SELECT COUNT(*) FROM virtual_tours WHERE location LIKE '%Americas%' AND date >= DATEADD(month, -1, GETDATE());
|
Which excavation sites have more than 50 artifacts?
|
CREATE TABLE Sites (site_id INT,site_name TEXT,num_artifacts INT); INSERT INTO Sites (site_id,site_name,num_artifacts) VALUES (1,'SiteA',60),(2,'SiteB',40),(3,'SiteC',30);
|
SELECT site_name FROM Sites WHERE num_artifacts > 50;
|
Insert new record into impact_investments table
|
CREATE TABLE impact_investments (id INT PRIMARY KEY,name VARCHAR(100),amount INT,sector VARCHAR(20));
|
INSERT INTO impact_investments (id, name, amount, sector) VALUES (5, 'Investment in Clean Energy', 500000, 'Clean Energy');
|
What are the waiting times for cargo handling at port 'SFO'?
|
CREATE TABLE ports (port_code CHAR(3),port_name VARCHAR(20)); INSERT INTO ports (port_code,port_name) VALUES ('LA','Los Angeles'),('NY','New York'),('MIA','Miami'),('HOU','Houston'),('SFO','San Francisco'); CREATE TABLE cargo_handling (port_code CHAR(3),waiting_time INT); INSERT INTO cargo_handling (port_code,waiting_time) VALUES ('LA',2),('LA',3),('NY',1),('NY',2),('NY',3),('SFO',4),('SFO',5),('SFO',6);
|
SELECT cargo_handling.waiting_time FROM cargo_handling WHERE cargo_handling.port_code = 'SFO';
|
Calculate the average production volume for wells in the South China Sea in 2022.
|
CREATE TABLE wells (id INT,location VARCHAR(20),volume INT,date DATE); INSERT INTO wells (id,location,volume,date) VALUES (1,'South China Sea',800,'2022-01-01'); INSERT INTO wells (id,location,volume,date) VALUES (2,'South China Sea',1800,'2022-02-01'); INSERT INTO wells (id,location,volume,date) VALUES (3,'South China Sea',2800,'2022-03-01');
|
SELECT AVG(volume) FROM wells WHERE location = 'South China Sea' AND YEAR(date) = 2022;
|
What is the total number of students who received accommodations by disability type?
|
CREATE TABLE disability_accommodations (student_id INT,disability_type VARCHAR(50)); INSERT INTO disability_accommodations (student_id,disability_type) VALUES (1,'Physical');
|
SELECT disability_type, COUNT(*) as total_students FROM disability_accommodations GROUP BY disability_type;
|
List all the eSports events that have taken place in Africa or South America, along with the number of attendees?
|
CREATE TABLE events (id INT,name VARCHAR(20),location VARCHAR(20),attendees INT); INSERT INTO events (id,name,location,attendees) VALUES (1,'Rio Games','Brazil',50000),(2,'Casablanca Cup','Morocco',30000),(3,'Johannesburg Jam','South Africa',40000),(4,'Lima League','Peru',25000),(5,'Cairo Clash','Egypt',35000);
|
SELECT events.name, events.location, events.attendees FROM events WHERE events.location IN ('Africa', 'South America');
|
What is the total amount donated by each donor in 'donations' table?
|
CREATE TABLE donors (id INT,name TEXT,total_donations DECIMAL(10,2)); CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (id,name,total_donations) VALUES (1,'John Doe',500.00),(2,'Jane Smith',300.00); INSERT INTO donations (id,donor_id,amount,donation_date) VALUES (1,1,100.00,'2022-01-01'),(2,1,200.00,'2022-01-02'),(3,2,300.00,'2022-01-01');
|
SELECT donor_id, SUM(amount) as total_donations FROM donations GROUP BY donor_id;
|
What is the average depth of all marine life research stations in the Southern hemisphere?
|
CREATE TABLE marine_life_research_stations (id INT,name TEXT,location TEXT,depth FLOAT); INSERT INTO marine_life_research_stations (id,name,location,depth) VALUES (1,'Station A','Pacific',2500.5); INSERT INTO marine_life_research_stations (id,name,location,depth) VALUES (2,'Station B','Atlantic',3000.2);
|
SELECT AVG(depth) FROM marine_life_research_stations WHERE location LIKE 'S%';
|
What is the maximum cargo capacity in TEUs for vessels owned by companies based in Asia with the word 'Ocean' in their name?
|
CREATE TABLE companies (company_id INT,company_name TEXT,country TEXT); INSERT INTO companies VALUES (1,'Pacific Ocean Shipping','China'),(2,'Asian Coastal Lines','Japan'),(3,'Indian Ocean Maritime','India'); CREATE TABLE vessels (vessel_id INT,company_id INT,capacity INT); INSERT INTO vessels VALUES (1,1,15000),(2,1,18000),(3,3,12000),(4,2,9000);
|
SELECT MAX(vessels.capacity) FROM vessels JOIN companies ON vessels.company_id = companies.company_id WHERE companies.country = 'Asia' AND companies.company_name LIKE '%Ocean%';
|
Which cultural events in Asia had the highest attendance?
|
CREATE TABLE CulturalEvents (EventID INT,Name TEXT,Location TEXT,Attendance INT); INSERT INTO CulturalEvents (EventID,Name,Location,Attendance) VALUES (1,'Chinese New Year','China',10000000); INSERT INTO CulturalEvents (EventID,Name,Location,Attendance) VALUES (2,'Diwali','India',8000000); INSERT INTO CulturalEvents (EventID,Name,Location,Attendance) VALUES (3,'Songkran','Thailand',6000000); INSERT INTO CulturalEvents (EventID,Name,Location,Attendance) VALUES (4,'Obon','Japan',5000000);
|
SELECT Name FROM CulturalEvents WHERE Location = 'Asia' GROUP BY Name ORDER BY Attendance DESC LIMIT 1;
|
What is the average carbon offset by smart city initiatives in each region?
|
CREATE TABLE carbon_offset (id INT,initiative_name VARCHAR(50),region VARCHAR(50),offset_amount INT); INSERT INTO carbon_offset (id,initiative_name,region,offset_amount) VALUES (1,'GreenCities EU','Europe',25000),(2,'CleanAir NA','North America',18000),(3,'SmartGrid AP','Asia Pacific',22000),(4,'EcoRail EU','Europe',30000),(5,'SolarCity AP','Asia Pacific',20000),(6,'WindCities NA','North America',28000);
|
SELECT region, AVG(offset_amount) FROM carbon_offset GROUP BY region;
|
What are the names and locations of traditional art forms in Brazil?
|
CREATE TABLE ArtForms (ArtFormID INT,Name TEXT,Location TEXT); INSERT INTO ArtForms (ArtFormID,Name,Location) VALUES (1,'Capoeira','Brazil'); INSERT INTO ArtForms (ArtFormID,Name,Location) VALUES (2,'Samba','Brazil');
|
SELECT Name, Location FROM ArtForms WHERE Location = 'Brazil';
|
What is the total calorie count for gluten-free products in the NutritionData table, grouped by product type?
|
CREATE TABLE NutritionData(product_id INT,product_type VARCHAR(50),is_gluten_free BOOLEAN,calorie_count INT);
|
SELECT product_type, SUM(calorie_count) FROM NutritionData WHERE is_gluten_free = TRUE GROUP BY product_type;
|
Find the number of packages shipped to each destination in March 2021
|
CREATE TABLE Shipments (id INT,destination VARCHAR(50),packages INT,timestamp DATE); INSERT INTO Shipments (id,destination,packages,timestamp) VALUES (1,'Paris',50,'2021-03-01'),(2,'Berlin',30,'2021-03-02'),(3,'London',40,'2021-03-03'),(4,'Rome',55,'2021-03-04'),(5,'Paris',60,'2021-03-05');
|
SELECT destination, SUM(packages) FROM Shipments WHERE timestamp BETWEEN '2021-03-01' AND '2021-03-31' GROUP BY destination;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.