instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Calculate the average premium for each policy type, ordered from highest to lowest.
|
CREATE TABLE policy_4 (policy_id INT,policy_type VARCHAR(20),premium FLOAT); INSERT INTO policy_4 (policy_id,policy_type,premium) VALUES (5,'Home',1400.00),(6,'Auto',850.00),(7,'Life',650.00),(8,'Rent',1450.00),(9,'Travel',900.00);
|
SELECT policy_type, AVG(premium) AS avg_premium, RANK() OVER (ORDER BY AVG(premium) DESC) AS policy_rank FROM policy_4 GROUP BY policy_type ORDER BY policy_rank;
|
Which adaptation measures have the highest success rate in Africa?
|
CREATE TABLE adaptation_measures (measure VARCHAR(50),location VARCHAR(50),success_rate NUMERIC); INSERT INTO adaptation_measures (measure,location,success_rate) VALUES ('Building sea walls','Africa',0.9),('Planting mangroves','Africa',0.85),('Constructing flood barriers','Africa',0.75);
|
SELECT measure, MAX(success_rate) as highest_success_rate FROM adaptation_measures WHERE location = 'Africa' GROUP BY measure;
|
List all feed additives with their manufacturers' names and countries.
|
CREATE TABLE feed_additives_manufacturers (id INT,feed_additive_id INT,manufacturer_name VARCHAR(255),manufacturer_country VARCHAR(255)); INSERT INTO feed_additives_manufacturers (id,feed_additive_id,manufacturer_name,manufacturer_country) VALUES (1,1,'Skretting','Netherlands'),(2,2,'Cargill Aqua Nutrition','USA'),(3,3,'BioMar','Denmark'),(4,4,'Skretting','Norway'),(5,5,'Cargill Aqua Nutrition','Canada');
|
SELECT feed_additives.name, manufacturers.name, manufacturers.country FROM feed_additives JOIN feed_additives_manufacturers ON feed_additives.id = feed_additive_id JOIN feed_manufacturers AS manufacturers ON feed_additives_manufacturers.manufacturer_country = manufacturers.country;
|
Which country has the least sustainable cosmetics brands?
|
CREATE TABLE Brands (brand_id INT,brand_name VARCHAR(50),country VARCHAR(50),sustainability_score INT); INSERT INTO Brands (brand_id,brand_name,country,sustainability_score) VALUES (1,'Lush','UK',90),(2,'The Body Shop','UK',85),(3,'Sephora','France',70),(4,'Chanel','France',60),(5,'Shiseido','Japan',75);
|
SELECT country FROM Brands ORDER BY sustainability_score LIMIT 1;
|
What are the top 3 genres by total revenue?
|
CREATE TABLE Genres (genre_id INT,genre_name VARCHAR(255)); INSERT INTO Genres (genre_id,genre_name) VALUES (1,'Pop'),(2,'Rock'),(3,'Hip Hop'); CREATE TABLE Sales (song_id INT,genre_id INT,revenue DECIMAL(10,2)); INSERT INTO Sales (song_id,genre_id,revenue) VALUES (1,1,10000),(2,2,15000),(3,3,20000);
|
SELECT Genres.genre_name, SUM(Sales.revenue) AS total_revenue FROM Genres INNER JOIN Sales ON Genres.genre_id = Sales.genre_id GROUP BY Genres.genre_name ORDER BY total_revenue DESC LIMIT 3;
|
What is the distribution of fan demographics (age and gender) for each team's athlete wellbeing program?
|
CREATE TABLE fan_demographics (fan_id INT,team_id INT,age INT,gender VARCHAR(10)); CREATE TABLE teams (team_id INT,team_name VARCHAR(255),sport_id INT); INSERT INTO fan_demographics VALUES (1,101,25,'Male'),(2,101,35,'Female'),(3,102,45,'Male'),(4,102,19,'Other'),(5,103,32,'Female'),(6,103,40,'Male'); INSERT INTO teams VALUES (101,'TeamA',1),(102,'TeamB',2),(103,'TeamC',1);
|
SELECT t.team_name, f.gender, f.age, COUNT(f.fan_id) as fan_count FROM fan_demographics f JOIN teams t ON f.team_id = t.team_id GROUP BY t.team_name, f.gender, f.age ORDER BY t.team_name, f.gender, f.age;
|
What is the total amount of donations made by donors from Palestine in the year 2019?
|
CREATE TABLE donations (id INT,donor_id INT,donor_country TEXT,donation_date DATE,donation_amount DECIMAL); INSERT INTO donations (id,donor_id,donor_country,donation_date,donation_amount) VALUES (1,1,'Palestine','2019-01-01',50.00),(2,2,'Palestine','2019-06-01',100.00),(3,3,'Palestine','2019-12-31',25.00);
|
SELECT SUM(donation_amount) FROM donations WHERE donor_country = 'Palestine' AND YEAR(donation_date) = 2019;
|
Which genre has the most streams in 2019?
|
CREATE TABLE music_streams (stream_id INT,genre VARCHAR(10),year INT,streams INT); INSERT INTO music_streams (stream_id,genre,year,streams) VALUES (1,'Classical',2019,1000000),(2,'Jazz',2020,1500000),(3,'Classical',2020,1200000),(4,'Pop',2019,1800000); CREATE VIEW genre_streams AS SELECT genre,SUM(streams) as total_streams FROM music_streams GROUP BY genre;
|
SELECT genre, total_streams FROM genre_streams WHERE year = 2019 ORDER BY total_streams DESC LIMIT 1;
|
List the names and funding amounts of startups in the 'midwest' region that were founded before 2018
|
CREATE TABLE companies (id INT,name TEXT,region TEXT,founding_year INT,funding FLOAT); INSERT INTO companies (id,name,region,founding_year,funding) VALUES (1,'Startup A','west_coast',2016,5000000),(2,'Startup B','east_coast',2017,3000000),(3,'Startup C','west_coast',2018,7000000),(4,'Startup D','east_coast',2019,8000000),(5,'Startup E','south',2020,6000000),(6,'Startup F','midwest',2015,9000000);
|
SELECT name, funding FROM companies WHERE region = 'midwest' AND founding_year < 2018;
|
What is the minimum price of organic products, grouped by subcategory?
|
CREATE TABLE products (product_id INT,subcategory VARCHAR(255),price DECIMAL(5,2),is_organic BOOLEAN); INSERT INTO products (product_id,subcategory,price,is_organic) VALUES (1,'Fruits',3.99,true);
|
SELECT subcategory, MIN(price) AS min_price FROM products WHERE is_organic = true GROUP BY subcategory;
|
What is the average price per pound of organic produce sold in farmers markets, grouped by state?
|
CREATE TABLE FarmersMarketData (MarketID int,State varchar(50),Product varchar(50),PricePerPound decimal(5,2));
|
SELECT State, AVG(PricePerPound) FROM FarmersMarketData WHERE Product LIKE '%organic produce%' GROUP BY State;
|
What are the names and subscription types of all broadband subscribers in Canada?
|
CREATE TABLE broadband_subscribers (subscriber_id INT,country VARCHAR(50),subscription_type VARCHAR(50)); INSERT INTO broadband_subscribers (subscriber_id,country,subscription_type) VALUES (1,'Canada','Residential'),(2,'USA','Business');
|
SELECT name, subscription_type FROM broadband_subscribers WHERE country = 'Canada';
|
What is the total number of open data initiatives in Asian countries?
|
CREATE TABLE Country (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO Country (id,name,region) VALUES (1,'China','Asia'); INSERT INTO Country (id,name,region) VALUES (2,'Japan','Asia'); INSERT INTO Country (id,name,region) VALUES (3,'India','Asia'); CREATE TABLE OpenData (id INT,country_id INT,initiative VARCHAR(255)); INSERT INTO OpenData (id,country_id,initiative) VALUES (1,1,'Open Data China'); INSERT INTO OpenData (id,country_id,initiative) VALUES (2,2,'Open Data Japan'); INSERT INTO OpenData (id,country_id,initiative) VALUES (3,3,'Open Data India');
|
SELECT COUNT(*) FROM OpenData JOIN Country ON OpenData.country_id = Country.id WHERE Country.region = 'Asia' AND OpenData.initiative IS NOT NULL;
|
What is the average rainfall in fieldA for the month of May?
|
CREATE TABLE fieldA (rainfall FLOAT,date DATE); INSERT INTO fieldA (rainfall,date) VALUES (12.5,'2021-05-01'),(15.3,'2021-05-02');
|
SELECT AVG(rainfall) FROM fieldA WHERE EXTRACT(MONTH FROM date) = 5 AND fieldA.date BETWEEN '2021-05-01' AND '2021-05-31';
|
List all the aquaculture farms in the Pacific region with fish species and quantity.
|
CREATE TABLE AquacultureFarms (FarmID int,FarmName varchar(50),FarmLocation varchar(50),FishSpecies varchar(50),Quantity int); INSERT INTO AquacultureFarms (FarmID,FarmName,FarmLocation,FishSpecies,Quantity) VALUES (1,'Farm A','Pacific','Salmon',5000),(2,'Farm B','Atlantic','Tuna',8000),(3,'Farm C','Pacific','Cod',3000);
|
SELECT FarmName, FishSpecies, Quantity FROM AquacultureFarms WHERE FarmLocation = 'Pacific';
|
Which countries have the highest and lowest average streams per user for Hip Hop songs on Spotify?
|
CREATE TABLE UserStreamingData (UserID INT,Country VARCHAR(50),Platform VARCHAR(50),Genre VARCHAR(50),Streams INT); INSERT INTO UserStreamingData (UserID,Country,Platform,Genre,Streams) VALUES (1,'USA','Spotify','Hip Hop',100000),(2,'Canada','Spotify','Hip Hop',120000);
|
SELECT Country, AVG(Streams) as AvgStreams FROM UserStreamingData WHERE Platform = 'Spotify' AND Genre = 'Hip Hop' GROUP BY Country ORDER BY AvgStreams DESC LIMIT 1; SELECT Country, AVG(Streams) as AvgStreams FROM UserStreamingData WHERE Platform = 'Spotify' AND Genre = 'Hip Hop' GROUP BY Country ORDER BY AvgStreams ASC LIMIT 1;
|
Add a new vendor to the "vendors" table with ID 121314, name "ABC Company", and address "123 Main St"
|
CREATE TABLE vendors (id INT PRIMARY KEY,name VARCHAR(50),address VARCHAR(100));
|
INSERT INTO vendors (id, name, address) VALUES (121314, 'ABC Company', '123 Main St');
|
How many users from each country participated in virtual workouts in the last week?
|
CREATE TABLE Users (user_id INT,country VARCHAR(50),last_login DATE); CREATE VIEW Virtual_Workouts AS SELECT user_id,date FROM Virtual_Workout_Data WHERE workout_type = 'virtual';
|
SELECT country, COUNT(DISTINCT user_id) FROM Users JOIN Virtual_Workouts ON Users.user_id = Virtual_Workouts.user_id WHERE last_login >= DATEADD(day, -7, GETDATE()) GROUP BY country;
|
What is the total sales amount of cosmetics sold in Germany in Q3 2022, grouped by week?
|
CREATE TABLE sales (id INT,brand VARCHAR(255),country VARCHAR(255),sales_amount DECIMAL(10,2),sale_date DATE);
|
SELECT DATE_TRUNC('week', sale_date) as week, SUM(sales_amount) FROM sales WHERE country = 'Germany' AND sale_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY week;
|
What is the minimum citizen feedback score for public transportation and education services?
|
CREATE TABLE ServiceFeedback (Service TEXT,Score INTEGER); INSERT INTO ServiceFeedback (Service,Score) VALUES ('Public Transportation',8),('Education',9),('Healthcare',7);
|
SELECT Service, MIN(Score) FROM ServiceFeedback WHERE Service IN ('Public Transportation', 'Education') GROUP BY Service;
|
How many matches in the MLS have had a result of a 1-1 draw?
|
CREATE TABLE MLS_Matches (MatchID INT,HomeTeam VARCHAR(50),AwayTeam VARCHAR(50),HomeTeamScore INT,AwayTeamScore INT); INSERT INTO MLS_Matches (MatchID,HomeTeam,AwayTeam,HomeTeamScore,AwayTeamScore) VALUES (1,'New York City FC','Atlanta United',1,1);
|
SELECT COUNT(*) FROM MLS_Matches WHERE HomeTeamScore = 1 AND AwayTeamScore = 1;
|
What was the recycling rate for the 'Metals' category in the 'Northeast' region in 2021?
|
CREATE TABLE recycling_rates (category VARCHAR(20),region VARCHAR(20),year INT,rate DECIMAL(3,2)); INSERT INTO recycling_rates (category,region,year,rate) VALUES ('Paper','Northeast',2020,0.45),('Paper','Northeast',2021,0.47),('Metals','Northeast',2020,0.38),('Metals','Northeast',2021,0.41);
|
SELECT rate FROM recycling_rates WHERE category = 'Metals' AND region = 'Northeast' AND year = 2021;
|
What are the top 5 countries with the most sustainable tourism certifications?
|
CREATE TABLE countries (id INT PRIMARY KEY,name VARCHAR(255),certification_count INT);CREATE VIEW top_countries AS SELECT name,certification_count,ROW_NUMBER() OVER (ORDER BY certification_count DESC) as rank FROM countries;
|
SELECT name FROM top_countries WHERE rank <= 5;
|
Update the result of a specific intelligence operation in the "intelligence_ops" table
|
CREATE TABLE intelligence_ops (id INT,year INT,location VARCHAR(255),type VARCHAR(255),result VARCHAR(255)); INSERT INTO intelligence_ops (id,year,location,type,result) VALUES (1,2015,'Russia','Surveillance','Success');
|
UPDATE intelligence_ops SET result = 'Failure' WHERE id = 1;
|
What is the maximum number of patients diagnosed with COVID-19 per week in each state?
|
CREATE TABLE Patients (ID INT,Disease VARCHAR(20),DiagnosisDate DATE,State VARCHAR(20)); INSERT INTO Patients (ID,Disease,DiagnosisDate,State) VALUES (1,'COVID-19','2022-01-01','California'),(2,'COVID-19','2022-01-05','California');
|
SELECT State, MAX(CountPerWeek) AS MaxCountPerWeek FROM (SELECT State, DATEPART(WEEK, DiagnosisDate) AS WeekNumber, COUNT(*) AS CountPerWeek FROM Patients WHERE Disease = 'COVID-19' GROUP BY State, WeekNumber) AS Subquery GROUP BY State;
|
What is the total number of players who have adopted VR technology?
|
CREATE TABLE players (id INT,has_vr BOOLEAN); INSERT INTO players (id,has_vr) VALUES (1,TRUE),(2,FALSE),(3,TRUE),(4,FALSE),(5,TRUE);
|
SELECT COUNT(*) FROM players WHERE has_vr = TRUE;
|
What is the total data usage, in GB, for each customer in the last 3 months, partitioned by region, and ordered by the most data usage?
|
CREATE TABLE customers (customer_id INT,name VARCHAR(50),data_usage FLOAT,region VARCHAR(50),usage_date DATE); INSERT INTO customers (customer_id,name,data_usage,region,usage_date) VALUES (1,'John Doe',45.6,'North','2022-01-01'),(2,'Jane Smith',30.9,'South','2022-02-01'),(3,'Mike Johnson',60.7,'East','2022-03-01'); CREATE TABLE regions (region_id INT,region_name VARCHAR(50)); INSERT INTO regions (region_id,region_name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West');
|
SELECT customer_id, region, SUM(data_usage) as total_data_usage, DENSE_RANK() OVER (ORDER BY SUM(data_usage) DESC) as data_usage_rank FROM customers c JOIN regions r ON c.region = r.region_name WHERE usage_date >= DATEADD(month, -3, GETDATE()) GROUP BY customer_id, region ORDER BY total_data_usage DESC;
|
What is the most popular dish in each category?
|
CREATE TABLE ratings (rating_id INT,menu_id INT,customer_id INT,rating FLOAT,review VARCHAR(255));
|
SELECT menu_id, category, MAX(rating) as max_rating FROM menus JOIN ratings ON menus.menu_id = ratings.menu_id GROUP BY category;
|
What is the maximum duration of astronaut medical records in days?
|
CREATE TABLE MedicalRecords (id INT,astronaut_id INT,start_date DATE,end_date DATE); INSERT INTO MedicalRecords (id,astronaut_id,start_date,end_date) VALUES (1,1,'2010-01-01','2010-01-10'),(2,2,'2012-05-01','2012-06-01');
|
SELECT MAX(DATEDIFF(end_date, start_date)) FROM MedicalRecords;
|
What is the total production volume of Terbium for 2020 and 2021?
|
CREATE TABLE terbium_production (year INT,production_volume FLOAT);
|
SELECT SUM(production_volume) FROM terbium_production WHERE year IN (2020, 2021);
|
What is the number of hospitals and clinics in each state, ordered by the number of hospitals, descending?
|
CREATE TABLE hospitals (id INT,name TEXT,state TEXT,location TEXT,type TEXT,num_beds INT); INSERT INTO hospitals (id,name,state,location,type,num_beds) VALUES (1,'Hospital A','State A','Urban','Teaching',200),(2,'Hospital B','State B','Rural','Community',150),(3,'Hospital C','State A','Urban','Specialty',100); CREATE TABLE clinics (id INT,name TEXT,state TEXT,location TEXT,type TEXT,num_providers INT); INSERT INTO clinics (id,name,state,location,type,num_providers) VALUES (1,'Clinic X','State A','Urban','Specialty Care',10),(2,'Clinic Y','State B','Rural','Urgent Care',8),(3,'Clinic Z','State A','Urban','Primary Care',12);
|
SELECT h.state, COUNT(h.id) as num_hospitals, COUNT(c.id) as num_clinics FROM hospitals h FULL OUTER JOIN clinics c ON h.state = c.state GROUP BY h.state ORDER BY num_hospitals DESC;
|
Delete all projects in Australia
|
CREATE TABLE infrastructure_projects (id INT,name TEXT,location TEXT); INSERT INTO infrastructure_projects (id,name,location) VALUES (1,'Brooklyn Bridge','USA'); INSERT INTO infrastructure_projects (id,name,location) VALUES (2,'Chunnel','UK'); INSERT INTO infrastructure_projects (id,name,location) VALUES (3,'Tokyo Tower','Japan'); INSERT INTO infrastructure_projects (id,name,location) VALUES (4,'Sydney Opera House','Australia');
|
DELETE FROM infrastructure_projects WHERE location = 'Australia';
|
What are the total training costs for the Sales department for each quarter in 2021?
|
CREATE TABLE Employees (EmployeeID int,Name varchar(50),Department varchar(50)); CREATE TABLE Training (TrainingID int,EmployeeID int,TrainingName varchar(50),TrainingCost decimal(10,2),TrainingDate date); INSERT INTO Employees (EmployeeID,Name,Department) VALUES (1,'John Doe','Sales'); INSERT INTO Training (TrainingID,EmployeeID,TrainingName,TrainingCost,TrainingDate) VALUES (1,1,'Sales Training',500.00,'2021-01-10'); INSERT INTO Training (TrainingID,EmployeeID,TrainingName,TrainingCost,TrainingDate) VALUES (2,1,'Sales Training',500.00,'2021-04-15');
|
SELECT DATE_FORMAT(TrainingDate, '%Y-%m') AS Quarter, Department, SUM(TrainingCost) AS TotalCost FROM Training t JOIN Employees e ON t.EmployeeID = e.EmployeeID WHERE YEAR(TrainingDate) = 2021 AND Department = 'Sales' GROUP BY Quarter;
|
How many patients with a mental health condition have been treated in each state in the past year?
|
CREATE TABLE PatientDemographics (PatientID INT,Age INT,Gender VARCHAR(10),Condition VARCHAR(50),TreatmentDate DATE,State VARCHAR(20));
|
SELECT State, COUNT(*) FROM PatientDemographics WHERE TreatmentDate >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY State;
|
How many workplace safety incidents have been reported in the 'transportation' industry by month in 2021?
|
CREATE TABLE safety_incidents (incident_id INT,industry TEXT,incident_date DATE); INSERT INTO safety_incidents (incident_id,industry,incident_date) VALUES (1,'transportation','2021-01-05'),(2,'transportation','2021-02-12'),(3,'retail','2021-03-20');
|
SELECT industry, MONTH(incident_date) AS month, COUNT(*) OVER (PARTITION BY industry, MONTH(incident_date)) FROM safety_incidents WHERE industry = 'transportation' AND YEAR(incident_date) = 2021;
|
What is the percentage of female union members in the agriculture sector?
|
CREATE TABLE agriculture (id INT,gender TEXT,union_member BOOLEAN); INSERT INTO agriculture (id,gender,union_member) VALUES (1,'Female',TRUE),(2,'Male',FALSE),(3,'Female',TRUE),(4,'Male',TRUE);
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM agriculture WHERE union_member = TRUE)) FROM agriculture WHERE gender = 'Female';
|
What is the total value of assets for all customers in the 'High Net Worth' category?
|
CREATE TABLE customers (id INT,name VARCHAR(50),age INT,account_balance DECIMAL(10,2),assets DECIMAL(10,2)); INSERT INTO customers (id,name,age,account_balance,assets) VALUES (1,'Jane Smith',50,10000.00,50000.00); CREATE TABLE categories (id INT,customer_id INT,category VARCHAR(20)); INSERT INTO categories (id,customer_id,category) VALUES (1,1,'High Net Worth');
|
SELECT SUM(assets) FROM customers JOIN categories ON customers.id = categories.customer_id WHERE category = 'High Net Worth';
|
What is the total revenue generated by the hotels table for each country?
|
CREATE TABLE hotels (id INT,hotel_name VARCHAR(50),country VARCHAR(50),revenue INT);
|
SELECT country, SUM(revenue) FROM hotels GROUP BY country;
|
List the top 3 countries with the highest number of social good technology initiatives.
|
CREATE TABLE initiatives (id INT,name VARCHAR(255),country VARCHAR(255),type VARCHAR(255)); INSERT INTO initiatives (id,name,country,type) VALUES (1,'Project A','Brazil','Social Good'),(2,'Project B','India','Social Good'),(3,'Project C','Brazil','Social Good'),(4,'Project D','South Africa','Social Good'),(5,'Project E','United States','Social Good');
|
SELECT country, COUNT(*) as initiative_count FROM initiatives WHERE type = 'Social Good' GROUP BY country ORDER BY initiative_count DESC LIMIT 3;
|
What is the total conservation cost for each art category?
|
CREATE TABLE ArtConservation (art_category VARCHAR(255),conservation_date DATE,cost DECIMAL(10,2)); INSERT INTO ArtConservation (art_category,conservation_date,cost) VALUES ('Painting','2022-01-02',1000.00),('Sculpture','2022-01-03',1500.00),('Painting','2022-03-05',1200.00),('Sculpture','2022-02-10',1800.00);
|
SELECT art_category, SUM(cost) as Total_Conservation_Cost FROM ArtConservation GROUP BY art_category;
|
What is the average age of all female authors in the "journalists" table?
|
CREATE TABLE journalists (id INT,name VARCHAR(50),age INT,gender VARCHAR(10));
|
SELECT AVG(age) FROM journalists WHERE gender = 'female';
|
What is the total fare collected and the number of unique passengers for routes with a fare amount greater than $30?
|
CREATE TABLE fare (fare_id INT,route_id INT,passenger_count INT,fare_amount FLOAT,payment_method VARCHAR(255)); INSERT INTO fare (fare_id,route_id,passenger_count,fare_amount,payment_method) VALUES (3,5,3,32.0,'Credit Card'); INSERT INTO fare (fare_id,route_id,passenger_count,fare_amount,payment_method) VALUES (4,6,1,15.00,'Cash');
|
SELECT route_id, SUM(fare_amount) as total_fare, COUNT(DISTINCT passenger_count) as unique_passengers FROM fare WHERE fare_amount > 30 GROUP BY route_id;
|
What is the total quantity of organic cotton used by brands in 2021?
|
CREATE TABLE organic_cotton (brand VARCHAR(50),quantity INT,year INT); INSERT INTO organic_cotton (brand,quantity,year) VALUES ('BrandA',12000,2021),('BrandB',18000,2021),('BrandC',9000,2021);
|
SELECT SUM(quantity) FROM organic_cotton WHERE year = 2021;
|
Delete records from the "digital_assets" table where "asset_type" is "Security Token" and "country" is "Canada"
|
CREATE TABLE digital_assets (asset_id VARCHAR(42),asset_type VARCHAR(20),country VARCHAR(2)); INSERT INTO digital_assets (asset_id,asset_type,country) VALUES ('0x1234567890123456789012345678901234567890','Security Token','CA');
|
DELETE FROM digital_assets WHERE asset_type = 'Security Token' AND country = 'CA';
|
Add a new record to the 'Customer' table for 'Alicia' from 'USA' who prefers 'Plus Size'
|
CREATE TABLE Customer (id INT PRIMARY KEY,name VARCHAR(50),country VARCHAR(50),size VARCHAR(50));
|
INSERT INTO Customer (id, name, country, size) VALUES (100, 'Alicia', 'USA', 'Plus Size');
|
Show the total funding amount for companies with female founders in the technology industry
|
CREATE TABLE company_founding (company_name VARCHAR(255),founder_gender VARCHAR(10),founder_race VARCHAR(50)); INSERT INTO company_founding (company_name,founder_gender,founder_race) VALUES ('Delta Enterprises','Female','African American'),('Echo Startups','Male','Asian'),('Foxtrot LLC','Female','Hispanic'),('Golf Inc','Male','Caucasian'); CREATE TABLE company_industry (company_name VARCHAR(255),industry VARCHAR(50)); INSERT INTO company_industry (company_name,industry) VALUES ('Delta Enterprises','Technology'),('Delta Enterprises','Retail'),('Echo Startups','Technology'),('Foxtrot LLC','Retail'),('Foxtrot LLC','Technology'),('Golf Inc','Sports'); CREATE TABLE funding (company_name VARCHAR(255),funding_amount INT); INSERT INTO funding (company_name,funding_amount) VALUES ('Delta Enterprises',600000),('Delta Enterprises',400000),('Echo Startups',750000),('Foxtrot LLC',500000),('Golf Inc',800000);
|
SELECT SUM(funding_amount) FROM funding WHERE company_name IN (SELECT company_name FROM company_founding f JOIN company_industry i ON f.company_name = i.company_name WHERE f.founder_gender = 'Female' AND i.industry = 'Technology');
|
How many transport infrastructure projects were completed in 2021 for each division?
|
CREATE TABLE TransportInfrastructure (id INT,division VARCHAR(20),year INT,completed INT); INSERT INTO TransportInfrastructure (id,division,year,completed) VALUES (1,'East',2021,1),(2,'West',2020,1),(3,'North',2021,1);
|
SELECT division, COUNT(*) as num_projects FROM TransportInfrastructure WHERE year = 2021 GROUP BY division;
|
List the top 5 states with the highest number of labor rights violation incidents in the last 12 months.
|
CREATE TABLE states (id INT,name VARCHAR(255)); INSERT INTO states (id,name) VALUES (1,'Alabama'),(2,'Alaska'); CREATE TABLE incidents (id INT,state_id INT,incident_date DATE,incident_type VARCHAR(255)); INSERT INTO incidents (id,state_id,incident_date,incident_type) VALUES (1,1,'2021-08-15','Child Labor'),(2,1,'2021-05-03','Unfair Pay');
|
SELECT s.name, COUNT(*) as total_incidents FROM incidents i JOIN states s ON i.state_id = s.id WHERE i.incident_date >= DATE(NOW()) - INTERVAL 12 MONTH GROUP BY s.name ORDER BY total_incidents DESC LIMIT 5;
|
What is the total funding for biotech startups by industry segment?
|
CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.startups (id INT,name VARCHAR(100),industry_segment VARCHAR(50),funding DECIMAL(10,2));INSERT INTO biotech.startups (id,name,industry_segment,funding) VALUES (1,'StartupA','Pharmaceuticals',5000000.00),(2,'StartupB','Bioinformatics',7000000.00),(3,'StartupC','Biosensors',3000000.00);
|
SELECT industry_segment, SUM(funding) as total_funding FROM biotech.startups GROUP BY industry_segment;
|
What is the total production volume in Canada?
|
CREATE TABLE production (id INT,location VARCHAR(20),volume INT); INSERT INTO production (id,location,volume) VALUES (1,'Canada',55000); INSERT INTO production (id,location,volume) VALUES (2,'Canada',65000); INSERT INTO production (id,location,volume) VALUES (3,'Brazil',45000);
|
SELECT SUM(volume) FROM production WHERE location = 'Canada';
|
What was the median fare for each vehicle type in the first quarter of 2021?
|
CREATE TABLE fare_collection (id INT,vehicle_type VARCHAR(20),fare_date DATE,fare FLOAT); INSERT INTO fare_collection (id,vehicle_type,fare_date,fare) VALUES (1,'Bus','2021-01-01',2.0),(2,'Tram','2021-01-03',2.5),(3,'Train','2021-01-05',3.0),(4,'Bus','2021-01-07',2.2),(5,'Tram','2021-01-09',2.8),(6,'Train','2021-01-11',3.2);
|
SELECT vehicle_type, AVG(fare) as median_fare FROM (SELECT vehicle_type, fare, ROW_NUMBER() OVER (PARTITION BY vehicle_type ORDER BY fare) as rn, COUNT(*) OVER (PARTITION BY vehicle_type) as cnt FROM fare_collection WHERE fare_date BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY vehicle_type, fare) x WHERE rn IN (cnt/2 + 1, cnt/2 + 2) GROUP BY vehicle_type;
|
What is the total number of guests who have taken virtual tours in Spain?
|
CREATE TABLE tours (id INT,type TEXT,country TEXT,guests INT); INSERT INTO tours (id,type,country,guests) VALUES (1,'Virtual Tour of the Alhambra','Spain',500),(2,'In-person Tour of the Prado Museum','Spain',300),(3,'Virtual Tour of the Guggenheim Museum','Spain',400);
|
SELECT SUM(guests) FROM tours WHERE type = 'Virtual Tour' AND country = 'Spain';
|
What is the average quantity of items in stock per product category?
|
CREATE TABLE Inventory (WarehouseId INT,Product VARCHAR(50),Quantity INT,Category VARCHAR(50)); INSERT INTO Inventory (WarehouseId,Product,Quantity,Category) VALUES (1,'Laptop',100,'Electronics'); INSERT INTO Inventory (WarehouseId,Product,Quantity,Category) VALUES (1,'Monitor',200,'Electronics'); INSERT INTO Inventory (WarehouseId,Product,Quantity,Category) VALUES (2,'Keyboard',300,'Electronics'); INSERT INTO Inventory (WarehouseId,Product,Quantity,Category) VALUES (2,'Chair',50,'Furniture');
|
SELECT Category, AVG(Quantity) AS AvgQuantity FROM Inventory GROUP BY Category;
|
What is the maximum salary for employees in the management department?
|
CREATE TABLE Employees (EmployeeID int,Department varchar(20),Salary numeric(10,2)); INSERT INTO Employees (EmployeeID,Department,Salary) VALUES (1,'IT',75000.00),(2,'Management',90000.00),(3,'HR',60000.00);
|
SELECT MAX(Salary) FROM Employees WHERE Department = 'Management';
|
What is the 2nd highest rent in the greenest buildings in Berlin?
|
CREATE TABLE buildings (building_id INT,city VARCHAR(20),green_rating INT,rent INT); INSERT INTO buildings (building_id,city,green_rating,rent) VALUES (1,'Berlin',5,1500),(2,'Berlin',4,1400),(3,'Paris',5,2000);
|
SELECT LEAD(rent) OVER (ORDER BY green_rating DESC, rent DESC) as second_highest_rent FROM buildings WHERE city = 'Berlin' AND green_rating = (SELECT MAX(green_rating) FROM buildings WHERE city = 'Berlin');
|
Identify users who made transactions in both the US and Canada?
|
CREATE TABLE users (user_id INT,username VARCHAR(20),region VARCHAR(20));CREATE TABLE transactions (transaction_id INT,user_id INT,amount DECIMAL(10,2),transaction_time TIMESTAMP,region VARCHAR(20));
|
SELECT DISTINCT user_id FROM transactions t1 JOIN transactions t2 ON t1.user_id = t2.user_id WHERE t1.region = 'US' AND t2.region = 'Canada';
|
Find the total number of court_cases in the criminal_justice table, grouped by court_type, but exclude the records for 'NY' and 'TX' locations.
|
CREATE TABLE criminal_justice (court_case_id INT,court_type VARCHAR(20),location VARCHAR(20),case_status VARCHAR(20)); INSERT INTO criminal_justice (court_case_id,court_type,location,case_status) VALUES (1,'Supreme_Court','NY','Open'),(2,'District_Court','NY','Closed'),(3,'Supreme_Court','CA','Open'),(4,'District_Court','CA','Closed'),(5,'Supreme_Court','TX','Open'),(6,'District_Court','TX','Closed'),(7,'Court_of_Appeals','IL','Open'),(8,'District_Court','IL','Closed'),(9,'Supreme_Court','IL','Open'),(10,'District_Court','IL','Closed');
|
SELECT court_type, COUNT(*) FROM criminal_justice WHERE location NOT IN ('NY', 'TX') GROUP BY court_type;
|
How many military personnel are currently assigned to intelligence operations in the Asia-Pacific region?
|
CREATE TABLE military_personnel(personnel_id INT,assignment VARCHAR(255),region VARCHAR(255)); INSERT INTO military_personnel(personnel_id,assignment,region) VALUES (1,'Intelligence','Asia-Pacific'),(2,'Cybersecurity','Europe'),(3,'Logistics','North America');
|
SELECT COUNT(*) FROM military_personnel WHERE assignment = 'Intelligence' AND region = 'Asia-Pacific';
|
How many dispensaries are there in each state that sell strains with a THC content greater than 20%?
|
CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT); INSERT INTO Dispensaries (id,name,state) VALUES (1,'Dispensary A','California'),(2,'Dispensary B','Oregon'),(3,'Dispensary C','Washington'); CREATE TABLE Strains (id INT,strain TEXT,thc_content REAL,dispensary_id INT); INSERT INTO Strains (id,strain,thc_content,dispensary_id) VALUES (1,'Strain A',25.5,1),(2,'Strain B',18.3,2),(3,'Strain C',22.7,3),(4,'Strain D',21.5,1),(5,'Strain E',19.3,2),(6,'Strain F',23.7,3);
|
SELECT s.state, COUNT(DISTINCT d.id) AS num_dispensaries FROM Strains s INNER JOIN Dispensaries d ON s.dispensary_id = d.id WHERE s.thc_content > 20 GROUP BY s.state;
|
What is the total number of flight accidents per year?
|
CREATE TABLE Flight_Safety (ID INT,Year INT,Number_Of_Accidents INT); INSERT INTO Flight_Safety (ID,Year,Number_Of_Accidents) VALUES (1,2015,10),(2,2016,12),(3,2017,15),(4,2018,18),(5,2019,20);
|
SELECT Year, SUM(Number_Of_Accidents) FROM Flight_Safety GROUP BY Year;
|
Identify the top 3 states with the highest water consumption.
|
CREATE TABLE StateWaterUsage (State VARCHAR(20),Usage FLOAT); INSERT INTO StateWaterUsage (State,Usage) VALUES ('California',25000),('Texas',22000),('Florida',20000),('New York',18000);
|
SELECT State, Usage FROM (SELECT State, Usage, ROW_NUMBER() OVER (ORDER BY Usage DESC) as rank FROM StateWaterUsage) AS subquery WHERE rank <= 3;
|
What is the average risk score for policyholders aged 50-60 who have made at least one claim in the last 12 months?
|
CREATE TABLE policyholders (id INT,dob DATE,risk_score INT); INSERT INTO policyholders (id,dob,risk_score) VALUES (1,'1962-05-01',45); CREATE TABLE claims (id INT,policyholder_id INT,claim_date DATE); INSERT INTO claims (id,policyholder_id,claim_date) VALUES (1,1,'2021-11-15');
|
SELECT AVG(policyholders.risk_score) FROM policyholders JOIN claims ON policyholders.id = claims.policyholder_id WHERE policyholders.dob BETWEEN '1961-01-01' AND '1972-01-01' AND claims.claim_date BETWEEN '2021-11-01' AND '2022-10-31';
|
What is the average temperature recorded in the 'arctic_weather' table for the month of January, for all years?
|
CREATE TABLE arctic_weather (station_id INT,record_date DATE,temperature DECIMAL(5,2));
|
SELECT AVG(temperature) FROM arctic_weather WHERE EXTRACT(MONTH FROM record_date) = 1;
|
List the top 3 teams with the highest average explainability score for their models.
|
CREATE TABLE ModelExplainabilityScores (ModelID INT,TeamID INT,ExplainabilityScore INT); CREATE TABLE TeamNames (TeamID INT,TeamName VARCHAR(50));
|
SELECT TeamNames.TeamName, AVG(ModelExplainabilityScores.ExplainabilityScore) AS AverageExplainabilityScore FROM ModelExplainabilityScores INNER JOIN TeamNames ON ModelExplainabilityScores.TeamID = TeamNames.TeamID GROUP BY TeamNames.TeamName ORDER BY AverageExplainabilityScore DESC LIMIT 3;
|
Find the average temperature and humidity for the month of July for all crops in the 'SouthEast' region.
|
CREATE TABLE Weather (date DATE,crop VARCHAR(20),temperature FLOAT,humidity FLOAT); CREATE TABLE Region (region VARCHAR(20),crop VARCHAR(20),PRIMARY KEY (region,crop));
|
SELECT AVG(temperature), AVG(humidity) FROM Weather JOIN Region ON Weather.crop = Region.crop WHERE Region.region = 'SouthEast' AND EXTRACT(MONTH FROM Weather.date) = 7;
|
How many IoT devices were added in 'Field009' in the past week?
|
CREATE TABLE iot_devices (id INT,field_id VARCHAR(10),device_type VARCHAR(20),added_date TIMESTAMP); INSERT INTO iot_devices (id,field_id,device_type,added_date) VALUES (1,'Field009','humidity_sensor','2022-03-03 10:00:00'),(2,'Field009','temperature_sensor','2022-03-01 10:00:00');
|
SELECT COUNT(*) FROM iot_devices WHERE field_id = 'Field009' AND added_date BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 7 DAY) AND CURRENT_TIMESTAMP;
|
What is the water usage for customers in 'City E'?
|
CREATE TABLE Water_Meters (id INT,customer_id INT,meter_reading FLOAT,read_date DATE); INSERT INTO Water_Meters (id,customer_id,meter_reading,read_date) VALUES (1,2001,80,'2021-01-01'),(2,2002,90,'2021-01-01'),(3,2003,70,'2021-01-01');
|
SELECT SUM(meter_reading) FROM Water_Meters WHERE customer_id IN (SELECT id FROM Customers WHERE city = 'City E');
|
Update the endangered_species table to add 10 to the population of each animal
|
CREATE TABLE endangered_species (species VARCHAR(50),population INT); INSERT INTO endangered_species (species,population) VALUES ('Tiger',300),('Giant Panda',600),('Elephant',400);
|
UPDATE endangered_species SET population = population + 10;
|
What is the percentage of customers in the 'suburban' region who only have a mobile subscription?
|
CREATE TABLE customers (id INT,region VARCHAR(10),mobile_subscription VARCHAR(10),broadband_subscription VARCHAR(10)); INSERT INTO customers (id,region,mobile_subscription,broadband_subscription) VALUES (1,'suburban','yes','no'),(2,'urban','yes','yes'),(3,'rural','no','yes'),(4,'suburban','no','no'),(5,'urban','yes','no');
|
SELECT (COUNT(*) FILTER (WHERE region = 'suburban' AND mobile_subscription = 'yes' AND broadband_subscription = 'no')) * 100.0 / (SELECT COUNT(*) FROM customers WHERE region = 'suburban') FROM customers;
|
What is the percentage of organic facial creams sold in Canada in Q2 2021?
|
CREATE TABLE facial_cream_sales (sale_id INT,product_id INT,sale_quantity INT,is_organic BOOLEAN,sale_date DATE,country VARCHAR(20)); INSERT INTO facial_cream_sales VALUES (1,30,4,true,'2021-04-23','Canada'); INSERT INTO facial_cream_sales VALUES (2,31,2,false,'2021-04-23','Canada');
|
SELECT ROUND((SUM(CASE WHEN is_organic = true THEN sale_quantity ELSE 0 END) / SUM(sale_quantity)) * 100, 2) FROM facial_cream_sales WHERE sale_date BETWEEN '2021-04-01' AND '2021-06-30' AND country = 'Canada';
|
What is the total revenue of companies that have a circular economy model?
|
CREATE TABLE Companies (company_id INT,company_name TEXT,has_circular_economy BOOLEAN,total_revenue DECIMAL(10,2));
|
SELECT SUM(total_revenue) FROM Companies WHERE has_circular_economy = TRUE;
|
What is the minimum age of players who have won in an FPS esports event?
|
CREATE TABLE PlayerWins (PlayerID INT,Age INT,EventID INT); INSERT INTO PlayerWins (PlayerID,Age,EventID) VALUES (1,22,1); CREATE TABLE EsportsEvents (EventID INT,Game VARCHAR(10)); INSERT INTO EsportsEvents (EventID,Game) VALUES (1,'CS:GO');
|
SELECT MIN(Age) FROM PlayerWins PW JOIN EsportsEvents EE ON PW.EventID = EE.EventID WHERE EE.Game LIKE '%FPS%';
|
Update all records with the occupation 'Engineer' to 'Senior Engineer' in the 'union_contracts' table
|
CREATE TABLE union_contracts (id INT,worker_id INT,occupation VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO union_contracts (id,worker_id,occupation,start_date,end_date) VALUES (1,1,'Engineer','2022-01-01','2023-12-31'),(2,2,'Engineer','2021-06-15','2022-06-14'),(3,3,'Clerk','2022-01-01','2023-12-31'),(4,4,'Clerk','2021-06-15','2022-06-14');
|
UPDATE union_contracts SET occupation = 'Senior Engineer' WHERE occupation = 'Engineer';
|
Update the focus of the 'National Security Strategy' for the North American region to 'Cyber Defense'.
|
CREATE TABLE region (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE strategy (id INT PRIMARY KEY,name VARCHAR(255),region_id INT,focus VARCHAR(255)); INSERT INTO region (id,name) VALUES (1,'North America'); INSERT INTO strategy (id,name,region_id,focus) VALUES (1,'National Security Strategy',1,'Counter-Terrorism');
|
UPDATE strategy SET focus = 'Cyber Defense' WHERE name = 'National Security Strategy' AND region_id = (SELECT id FROM region WHERE name = 'North America');
|
Calculate the average seafood consumption per capita in each province in Canada.
|
CREATE TABLE seafood_consumption (id INT,province VARCHAR(255),consumption FLOAT); INSERT INTO seafood_consumption (id,province,consumption) VALUES (1,'British Columbia',35.0),(2,'Ontario',30.0),(3,'Quebec',28.0),(4,'Nova Scotia',25.0);
|
SELECT province, AVG(consumption) FROM seafood_consumption GROUP BY province;
|
What is the total revenue generated by virtual tours for each month?
|
CREATE TABLE Virtual_Tour (month TEXT,revenue NUMERIC); INSERT INTO Virtual_Tour (month,revenue) VALUES ('January',5000),('February',7000),('March',8000);
|
SELECT month, SUM(revenue) FROM Virtual_Tour GROUP BY month;
|
List all news articles related to 'environment' from the 'articles' table.
|
CREATE TABLE articles (id INT,title VARCHAR(100),content TEXT,category VARCHAR(50),publication_date DATE); INSERT INTO articles (id,title,content,category,publication_date) VALUES (1,'Climate Change...','...','environment','2022-01-01');
|
SELECT * FROM articles WHERE category = 'environment';
|
What is the average streaming minutes per user for a given artist?
|
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));
|
SELECT artist_id, AVG(minutes/COUNT(*)) AS avg_minutes_per_user FROM Streams GROUP BY artist_id;
|
What is the total number of visitors who are artists or musicians from Asia?
|
CREATE TABLE visitors (id INT,name VARCHAR(100),country VARCHAR(50),occupation VARCHAR(50)); INSERT INTO visitors (id,name,country,occupation) VALUES (1,'Leila Zhang','China','Artist'),(2,'Alex Brown','Japan','Musician');
|
SELECT SUM(occupation IN ('Artist', 'Musician') AND country LIKE 'Asia%') FROM visitors;
|
What is the percentage of community health workers who have completed cultural competency training in each state?
|
CREATE TABLE community_health_workers (worker_id INT,name VARCHAR(50),state VARCHAR(2),completed_training BOOLEAN);
|
SELECT state, AVG(completed_training::INT) FROM community_health_workers GROUP BY state;
|
Show the transaction history for smart contract address 0x123, including the transaction date and the digital asset associated with each transaction.
|
CREATE TABLE transactions (address TEXT,tx_date DATE,asset TEXT); INSERT INTO transactions (address,tx_date,asset) VALUES ('0x123','2021-01-01','Securitize'),('0x123','2021-01-02','Polymath');
|
SELECT * FROM transactions WHERE address = '0x123' ORDER BY tx_date;
|
Delete records of users who have not interacted with the system in the past 6 months
|
CREATE TABLE users (id INT,last_interaction TIMESTAMP); INSERT INTO users (id,last_interaction) VALUES (1,'2021-01-01 10:00:00'),(2,'2021-06-15 14:30:00'),(3,'2020-12-25 09:15:00');
|
DELETE FROM users WHERE last_interaction < NOW() - INTERVAL 6 MONTH;
|
What is the total number of mental health parity complaints by county in the last 3 years?
|
CREATE TABLE MentalHealthParityComplaints (ComplaintID INT,County VARCHAR(50),ComplaintDate DATE); INSERT INTO MentalHealthParityComplaints (ComplaintID,County,ComplaintDate) VALUES (1,'Los Angeles','2020-01-01'),(2,'Harris','2019-12-15'),(3,'New York','2021-02-03');
|
SELECT County, COUNT(*) OVER (PARTITION BY County) AS TotalComplaints FROM MentalHealthParityComplaints WHERE ComplaintDate >= DATEADD(year, -3, GETDATE());
|
What is the average rating of movies directed by 'Director2'?
|
CREATE TABLE movies (id INT,title VARCHAR(255),rating FLOAT,director VARCHAR(255)); INSERT INTO movies (id,title,rating,director) VALUES (1,'Movie1',4.5,'Director1'),(2,'Movie2',3.2,'Director2'),(3,'Movie3',4.7,'Director2'),(4,'Movie4',2.9,'Director3');
|
SELECT AVG(rating) FROM movies WHERE director = 'Director2';
|
Delete policyholders and their insurance policies from the database who have not filed a claim in the past 2 years.
|
CREATE TABLE Policyholders (PolicyholderID INT,LastClaimDate DATE); INSERT INTO Policyholders VALUES (1,'2020-01-01'); INSERT INTO Policyholders VALUES (2,'2021-05-05'); INSERT INTO Policyholders VALUES (3,'2019-12-31');
|
DELETE FROM Policyholders WHERE LastClaimDate < NOW() - INTERVAL '2 years'; DELETE FROM HomeInsurance WHERE PolicyholderID IN (SELECT PolicyholderID FROM Policyholders WHERE LastClaimDate < NOW() - INTERVAL '2 years'); DELETE FROM AutoInsurance WHERE PolicyholderID IN (SELECT PolicyholderID FROM Policyholders WHERE LastClaimDate < NOW() - INTERVAL '2 years');
|
Insert new record into the Species table.
|
CREATE TABLE Species (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50)); INSERT INTO Species (id,name,type) VALUES (1,'Tuna','Fish'); INSERT INTO Species (id,name,type) VALUES (2,'Krill','Crustacean');
|
INSERT INTO Species (id, name, type) VALUES (3, 'Coral', 'Cnidarian');
|
What is the total water usage in 'WaterUsage' table for the state of California?
|
CREATE TABLE WaterUsage (id INT,location TEXT,water_usage INT);
|
SELECT SUM(water_usage) FROM WaterUsage WHERE location = 'California';
|
What is the average ticket price for events in Paris?
|
CREATE TABLE Events (id INT,city VARCHAR(20),price DECIMAL(5,2)); INSERT INTO Events (id,city,price) VALUES (1,'Paris',20.99),(2,'London',15.49),(3,'Paris',25.00);
|
SELECT AVG(price) FROM Events WHERE city = 'Paris';
|
How much water was consumed in the province of British Columbia in 2018?
|
CREATE TABLE water_usage(province VARCHAR(20),year INT,consumption INT); INSERT INTO water_usage(province,year,consumption) VALUES ('British Columbia',2015,10000),('British Columbia',2016,11000),('British Columbia',2017,12000),('British Columbia',2018,13000),('British Columbia',2019,14000);
|
SELECT consumption FROM water_usage WHERE province = 'British Columbia' AND year = 2018;
|
List all art-related exhibitions with more than 1500 visitors.
|
CREATE TABLE exhibitions (id INT,name VARCHAR(100),type VARCHAR(50),visitors INT); INSERT INTO exhibitions (id,name,type,visitors) VALUES (1,'Impressionism','Art',2000),(2,'Classical Music','Music',1200);
|
SELECT name FROM exhibitions WHERE type LIKE '%Art%' AND visitors > 1500;
|
Which crops were planted before June 1, 2021 and harvested after September 1, 2021?
|
CREATE TABLE Crops (id INT PRIMARY KEY,name VARCHAR(50),planting_date DATE,harvest_date DATE,yield INT); INSERT INTO Crops (id,name,planting_date,harvest_date,yield) VALUES (1,'Corn','2021-04-15','2021-08-30',80); INSERT INTO Crops (id,name,planting_date,harvest_date,yield) VALUES (2,'Soybeans','2021-05-01','2021-10-15',70);
|
SELECT name FROM Crops WHERE planting_date < '2021-06-01' AND harvest_date > '2021-09-01';
|
How many military equipment maintenance requests were submitted in Ontario in 2021?
|
CREATE TABLE Maintenance_Requests (request_id INT,equipment_type TEXT,province TEXT,request_date DATE); INSERT INTO Maintenance_Requests (request_id,equipment_type,province,request_date) VALUES (1,'Helicopter','Ontario','2021-01-01'),(2,'Tank','Ontario','2021-06-01');
|
SELECT COUNT(*) FROM Maintenance_Requests WHERE province = 'Ontario' AND YEAR(request_date) = 2021;
|
Calculate the total waste generation for the year 2020 from the 'waste_generation' table
|
CREATE TABLE waste_generation (id INT,country VARCHAR(50),year INT,total_waste_gen FLOAT);
|
SELECT SUM(total_waste_gen) FROM waste_generation WHERE year = 2020;
|
What is the maximum temperature recorded in the Arctic in the past year?
|
CREATE TABLE TemperatureReadings (Year INT,Temperature DECIMAL(5,2)); INSERT INTO TemperatureReadings (Year,Temperature) VALUES (2021,-14.5),(2021,-13.8),(2021,-16.2),(2022,-12.9),(2022,-15.1),(2022,-13.4);
|
SELECT MAX(Temperature) FROM TemperatureReadings WHERE Year = 2022;
|
What is the average donation amount per zip code?
|
CREATE TABLE Donors (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,zip VARCHAR(10)); INSERT INTO Donors (id,donor_name,donation_amount,donation_date,zip) VALUES (1,'Alex Brown',200.00,'2021-01-01','10001');
|
SELECT zip, AVG(donation_amount) as avg_donation_amount FROM Donors GROUP BY zip;
|
Create a table named 'waste_generation_metrics'
|
CREATE TABLE waste_generation_metrics (country VARCHAR(50),year INT,generation_metric INT);
|
CREATE TABLE waste_generation_metrics ( country VARCHAR(50), year INT, generation_metric INT);
|
What is the total number of subscribers who have been in compliance with regulatory requirements for each quarter?
|
CREATE TABLE regulatory_compliance (compliance_date DATE,subscriber_id INT); INSERT INTO regulatory_compliance (compliance_date,subscriber_id) VALUES ('2022-01-01',1),('2022-02-01',2);
|
SELECT DATE_FORMAT(compliance_date, '%Y-%q') AS quarter, COUNT(DISTINCT subscriber_id) FROM regulatory_compliance GROUP BY quarter;
|
How many artworks were sold by each art movement in 2022?
|
CREATE TABLE MovementSales (Movement VARCHAR(255),ArtWork VARCHAR(255),Year INT,QuantitySold INT); INSERT INTO MovementSales (Movement,ArtWork,Year,QuantitySold) VALUES ('Post-Impressionism','Artwork 1',2022,2),('Post-Impressionism','Artwork 2',2022,3),('Pop Art','Artwork 3',2022,1),('Pop Art','Artwork 4',2022,4);
|
SELECT Movement, SUM(QuantitySold) as TotalQuantitySold FROM MovementSales WHERE Year = 2022 GROUP BY Movement;
|
List all warehouses with available capacity over 10000 square meters.
|
CREATE TABLE Warehouses (warehouse_id INT,location VARCHAR(50),capacity FLOAT); INSERT INTO Warehouses (warehouse_id,location,capacity) VALUES (1,'Los Angeles',12000); INSERT INTO Warehouses (warehouse_id,location,capacity) VALUES (2,'New York',8000);
|
SELECT * FROM Warehouses WHERE capacity > 10000;
|
Who is the largest donor in each country?
|
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL(10,2),DonationCountry VARCHAR(50)); CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),DonationType VARCHAR(50));
|
SELECT d.DonorName, d.DonationCountry, SUM(d.DonationAmount) FROM Donations d JOIN Donors don ON d.DonorID = don.DonorID GROUP BY d.DonorName, d.DonationCountry HAVING SUM(d.DonationAmount) = (SELECT MAX(SUM(DonationAmount)) FROM Donations d2 JOIN Donors don2 ON d2.DonorID = don2.DonorID WHERE d2.DonationCountry = d.DonationCountry) ORDER BY SUM(d.DonationAmount) DESC;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.