instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
How many wells were drilled in the Gulf of Mexico in 2022?
|
CREATE TABLE DrillingPlatforms (PlatformID int,PlatformName varchar(50),Location varchar(50),PlatformType varchar(50),NumberOfWells int); INSERT INTO DrillingPlatforms (PlatformID,PlatformName,Location,PlatformType,NumberOfWells) VALUES (1,'A01','North Sea','Offshore',10),(2,'B02','Gulf of Mexico','Offshore',15),(3,'C03','Texas','Onshore',6),(4,'D04','Texas','Onshore',20); CREATE TABLE DrillingLogs (DrillingLogID int,PlatformID int,WellID int,DrillingDate date); INSERT INTO DrillingLogs (DrillingLogID,PlatformID,WellID,DrillingDate) VALUES (1,2,101,'2022-01-01'),(2,2,102,'2022-01-02'),(3,5,201,'2022-01-03'),(4,5,202,'2022-01-04');
|
SELECT COUNT(*) FROM DrillingLogs JOIN DrillingPlatforms ON DrillingLogs.PlatformID = DrillingPlatforms.PlatformID WHERE DrillingPlatforms.Location = 'Gulf of Mexico' AND YEAR(DrillingLogs.DrillingDate) = 2022;
|
What is the total number of paintings and sculptures in Paris and Berlin museums?
|
CREATE TABLE paris_art(id INT,museum VARCHAR(20),art_type VARCHAR(20),count INT); INSERT INTO paris_art VALUES (1,'Louvre','Painting',500); INSERT INTO paris_art VALUES (2,'Louvre','Sculpture',300); CREATE TABLE berlin_art(id INT,museum VARCHAR(20),art_type VARCHAR(20),count INT); INSERT INTO berlin_art VALUES (1,'Pergamon','Painting',400); INSERT INTO berlin_art VALUES (2,'Pergamon','Sculpture',600);
|
SELECT SUM(count) FROM (SELECT count FROM paris_art WHERE museum = 'Louvre' UNION ALL SELECT count FROM berlin_art WHERE museum = 'Pergamon') AS combined_museums;
|
Identify the top 2 continents with the highest water consumption in the last 6 months.
|
CREATE TABLE water_consumption (continent VARCHAR(255),consumption FLOAT,date DATE); INSERT INTO water_consumption (continent,consumption,date) VALUES ('South America',120000,'2022-01-01'); INSERT INTO water_consumption (continent,consumption,date) VALUES ('Europe',150000,'2022-01-01');
|
SELECT continent, SUM(consumption) FROM (SELECT continent, consumption, ROW_NUMBER() OVER (PARTITION BY continent ORDER BY consumption DESC) as rank FROM water_consumption WHERE date >= '2021-07-01' GROUP BY continent, consumption) subquery WHERE rank <= 2 GROUP BY continent;
|
What is the minimum population of a facility in the 'health_facilities' table?
|
CREATE TABLE health_facilities (facility_id INT,name VARCHAR(50),type VARCHAR(50),population INT,city VARCHAR(50),state VARCHAR(50));
|
SELECT MIN(population) FROM health_facilities;
|
Insert new records into the 'creative_ai' table for 'Diffusion Models' in 'China'
|
CREATE TABLE creative_ai (id INT,tool VARCHAR(20),application VARCHAR(50),country VARCHAR(20));
|
INSERT INTO creative_ai (id, tool, application, country) VALUES (3, 'Diffusion Models', 'Image Generation', 'China');
|
What is the total number of fans who have attended a tennis match and are under the age of 25?
|
CREATE TABLE fans (id INT,name VARCHAR(50),age INT,last_game_date DATE); INSERT INTO fans (id,name,age,last_game_date) VALUES (1,'Emily Davis',22,'2021-01-01'); INSERT INTO fans (id,name,age,last_game_date) VALUES (2,'Michael Chen',30,'2020-01-01');
|
SELECT COUNT(*) FROM fans WHERE age < 25 AND last_game_date IS NOT NULL;
|
Add a new "Eyeshadow" product to the cosmetics table with an id of 11, a price of $12.50, and a vegan status of true.
|
CREATE TABLE cosmetics (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),is_vegan BOOLEAN); CREATE TABLE sales (id INT PRIMARY KEY,product_id INT,supplier_id INT,quantity INT,date DATE);
|
INSERT INTO cosmetics (id, name, category, price, is_vegan) VALUES (11, 'Eyeshadow', 'Eye', 12.50, true);
|
What was the total fare collected by bus number on the first week of March 2021?
|
CREATE SCHEMA trans schemas.trans; CREATE TABLE bus_fares (bus_number INT,fare FLOAT,fare_date DATE); INSERT INTO bus_fares (bus_number,fare,fare_date) VALUES (1201,1.75,'2021-03-01'),(1201,1.75,'2021-03-02'),(1201,1.75,'2021-03-03'),(1201,1.75,'2021-03-04'),(1201,1.75,'2021-03-05'),(1202,2.25,'2021-03-01'),(1202,2.25,'2021-03-02'),(1202,2.25,'2021-03-03'),(1202,2.25,'2021-03-04'),(1202,2.25,'2021-03-05');
|
SELECT bus_number, SUM(fare) OVER (PARTITION BY bus_number) FROM bus_fares WHERE fare_date BETWEEN '2021-03-01' AND '2021-03-05';
|
Insert a new record into the 'community_education' table
|
CREATE TABLE community_education (id INT PRIMARY KEY,program_name VARCHAR(255),description TEXT,target_audience VARCHAR(255));
|
INSERT INTO community_education (id, program_name, description, target_audience) VALUES (1, 'Wildlife Warriors', 'A program to teach children about wildlife conservation.', 'Children');
|
List the art pieces that are present in both the Metropolitan Museum and the Guggenheim Museum.
|
CREATE TABLE MetropolitanMuseum(id INT,type VARCHAR(20),artist VARCHAR(30)); CREATE TABLE GuggenheimMuseum(id INT,type VARCHAR(20),artist VARCHAR(30)); INSERT INTO MetropolitanMuseum(id,type,artist) VALUES (1,'Painting','Rembrandt'),(2,'Sculpture','Rodin'),(3,'Painting','Van Gogh'); INSERT INTO GuggenheimMuseum(id,type,artist) VALUES (1,'Painting','Picasso'),(2,'Sculpture','Brancusi'),(3,'Painting','Rembrandt');
|
SELECT type, artist FROM MetropolitanMuseum WHERE (type, artist) IN (SELECT type, artist FROM GuggenheimMuseum);
|
What is the maximum number of AI patents filed by companies based in the USA?
|
CREATE TABLE ai_patents (patent_id INT,company_name VARCHAR(30),country VARCHAR(20)); INSERT INTO ai_patents (patent_id,company_name,country) VALUES (1,'IBM','USA'),(2,'Microsoft','USA'),(3,'TCS','India');
|
SELECT MAX(patent_id) FROM ai_patents WHERE country = 'USA';
|
Identify the customer with the highest investment in stock 'MSFT'
|
CREATE TABLE customers (customer_id INT,total_assets DECIMAL(10,2)); INSERT INTO customers (customer_id,total_assets) VALUES (1,50000),(2,75000),(3,30000); CREATE TABLE investments (customer_id INT,stock_symbol VARCHAR(5),investment_amount DECIMAL(10,2)); INSERT INTO investments (customer_id,stock_symbol,investment_amount) VALUES (1,'AAPL',25000),(2,'GOOG',50000),(3,'MSFT',15000),(4,'MSFT',20000);
|
SELECT investments.customer_id, MAX(investments.investment_amount) FROM investments WHERE investments.stock_symbol = 'MSFT' GROUP BY investments.customer_id;
|
What is the maximum number of hours spent on a single project by students in each campus?
|
CREATE TABLE students (id INT,campus TEXT,hours INT,project_id INT);
|
SELECT campus, MAX(hours) FROM students GROUP BY campus;
|
How much climate finance has been provided by multilateral development banks in the last 5 years?
|
CREATE TABLE climate_finance (id INT PRIMARY KEY,source VARCHAR(255),recipient VARCHAR(255),amount FLOAT,date DATE); INSERT INTO climate_finance (id,source,recipient,amount,date) VALUES (1,'World Bank','Brazil',5000000,'2018-01-01'),(2,'Asian Development Bank','India',7000000,'2020-01-01');
|
SELECT SUM(amount) FROM climate_finance WHERE source LIKE '%Multilateral Development Bank%' AND YEAR(date) >= 2017;
|
What is the change in median property price between 2020 and 2021 in each neighborhood?
|
CREATE TABLE properties (id INT,neighborhood VARCHAR(20),year INT,price INT); INSERT INTO properties (id,neighborhood,year,price) VALUES (1,'Neighborhood X',2020,200000),(2,'Neighborhood Y',2020,150000),(3,'Neighborhood X',2021,250000),(4,'Neighborhood Y',2021,180000);
|
SELECT neighborhood, (LEAD(price) OVER (PARTITION BY neighborhood ORDER BY year)) - price AS price_change FROM properties WHERE year IN (2020, 2021);
|
What is the maximum carbon sequestration achieved in a single year in temperate forests, and which forest was it?
|
CREATE TABLE temperate_forests (id INT,name VARCHAR(255),country VARCHAR(255),sequestration INT); INSERT INTO temperate_forests (id,name,country,sequestration) VALUES (1,'Temperate Forest 1','USA',12000),(2,'Temperate Forest 2','USA',15000),(3,'Temperate Forest 3','USA',18000);
|
SELECT name, MAX(sequestration) FROM temperate_forests WHERE country = 'USA';
|
What is the total sales revenue per country, ranked by sales revenue?
|
CREATE TABLE DrugSales (SalesCountry varchar(50),DrugName varchar(50),SalesDate date,TotalSalesRev decimal(18,2)); INSERT INTO DrugSales (SalesCountry,DrugName,SalesDate,TotalSalesRev) VALUES ('USA','DrugAF','2021-03-15',55000.00),('Canada','DrugAG','2021-02-01',60000.00),('Mexico','DrugAH','2021-01-25',80000.00),('Brazil','DrugAI','2021-04-02',90000.00);
|
SELECT SalesCountry, SUM(TotalSalesRev) as TotalSales, ROW_NUMBER() OVER (ORDER BY SUM(TotalSalesRev) DESC) as SalesRank FROM DrugSales GROUP BY SalesCountry;
|
What is the total number of multimodal transportation users in Australia?
|
CREATE TABLE australia_users (transport_type VARCHAR(20),users INT);
|
SELECT SUM(users) AS total_multimodal_users FROM australia_users;
|
What is the maximum ESG score for companies in the 'finance' sector?
|
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_score FLOAT); INSERT INTO companies (id,sector,ESG_score) VALUES (1,'technology',78.3),(2,'finance',65.2),(3,'technology',74.5);
|
SELECT MAX(ESG_score) FROM companies WHERE sector = 'finance';
|
What was the landfill capacity in cubic meters for the 'Central' region in 2020?
|
CREATE TABLE landfill_capacity (region VARCHAR(20),year INT,capacity INT); INSERT INTO landfill_capacity (region,year,capacity) VALUES ('Central',2019,500000),('Central',2020,550000),('Central',2021,600000);
|
SELECT capacity FROM landfill_capacity WHERE region = 'Central' AND year = 2020;
|
What is the minimum investment made in the climate change sector?
|
CREATE TABLE investments (id INT,sector VARCHAR(20),amount DECIMAL(10,2)); INSERT INTO investments (id,sector,amount) VALUES (1,'climate change',10000.00),(2,'climate change',12000.00),(3,'education',22000.00);
|
SELECT MIN(amount) FROM investments WHERE sector = 'climate change';
|
How many ethical products were sold in the EU in Q2 2021?
|
CREATE TABLE orders (order_id INT,order_date DATE,product_id INT,revenue FLOAT); CREATE TABLE products (product_id INT,product_name VARCHAR(50),revenue FLOAT,labor_practices VARCHAR(20),country VARCHAR(50)); INSERT INTO products (product_id,product_name,revenue,labor_practices,country) VALUES (1,'T-Shirt',25.5,'Ethical','Germany'),(2,'Jeans',30,'Unethical','USA'),(3,'Shirt',15,'Ethical','France'); INSERT INTO orders (order_id,order_date,product_id,revenue) VALUES (1,'2021-04-01',1,25.5),(2,'2021-04-02',2,30),(3,'2021-07-03',3,15);
|
SELECT COUNT(*) FROM orders JOIN products ON orders.product_id = products.product_id WHERE products.labor_practices = 'Ethical' AND EXTRACT(MONTH FROM order_date) BETWEEN 4 AND 6 AND EXTRACT(YEAR FROM order_date) = 2021 AND products.country IN ('Germany', 'France', 'Italy', 'Spain', 'Portugal', 'Belgium', 'Netherlands', 'Luxembourg', 'Ireland', 'Austria', 'Finland', 'Sweden', 'Denmark');
|
Which miner has the highest labor force in Asia?
|
CREATE TABLE labor_force (miner_name VARCHAR(50),country VARCHAR(50),worker_count INT,PRIMARY KEY (miner_name,country));INSERT INTO labor_force (miner_name,country,worker_count) VALUES ('Li Wong','China',500),('Han Lee','South Korea',400),('Kim Park','Japan',600);CREATE VIEW miner_country_worker_count AS SELECT miner_name,country,worker_count,ROW_NUMBER() OVER(PARTITION BY miner_name ORDER BY worker_count DESC) as rank FROM labor_force;
|
SELECT context.miner_name, context.country, sql.worker_count, sql.rank FROM labor_force sql JOIN miner_country_worker_count context ON sql.miner_name = context.miner_name WHERE context.rank = 1 AND sql.country = 'Asia'
|
How many donors are there from Japan with a donation amount greater than 500?
|
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL(10,2),Country TEXT);
|
SELECT COUNT(*) FROM Donors WHERE Country = 'Japan' AND DonationAmount > 500;
|
Which country had the highest production increase from 2019 to 2020?
|
CREATE TABLE production (country VARCHAR(255),year INT,amount INT); INSERT INTO production (country,year,amount) VALUES ('China',2019,120000),('China',2020,140000),('USA',2019,36000),('USA',2020,38000),('Australia',2019,18000),('Australia',2020,20000),('India',2019,4000),('India',2020,5000);
|
SELECT country, MAX(amount - LAG(amount, 1) OVER (PARTITION BY country ORDER BY year)) AS production_increase FROM production GROUP BY country;
|
What is the total revenue and number of subscribers for each product category, sales region, and mobile network operator?
|
CREATE TABLE product_sales (product_category VARCHAR(50),region VARCHAR(50),operator VARCHAR(50),revenue FLOAT,subscribers INT); INSERT INTO product_sales VALUES ('Category A','Region A','Operator A',2000,100); INSERT INTO product_sales VALUES ('Category B','Region A','Operator A',3000,200); INSERT INTO product_sales VALUES ('Category A','Region B','Operator B',4000,300); INSERT INTO product_sales VALUES ('Category C','Region C','Operator C',5000,400);
|
SELECT region, operator, product_category, AVG(revenue) as avg_revenue, SUM(subscribers) as total_subscribers FROM product_sales GROUP BY region, operator, product_category;
|
Which country has the most players in the FPS genre?
|
CREATE TABLE Players (PlayerID INT,Age INT,Country VARCHAR(20),GamePreference VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Country,GamePreference) VALUES (1,25,'USA','FPS');
|
SELECT Country, COUNT(*) FROM Players WHERE GamePreference = 'FPS' GROUP BY Country ORDER BY COUNT(*) DESC LIMIT 1;
|
Identify the top 3 countries with the largest coral reef area.
|
CREATE TABLE countries (country_name TEXT,coral_reef_area FLOAT);
|
SELECT country_name, coral_reef_area FROM countries ORDER BY coral_reef_area DESC LIMIT 3;
|
Which countries have launched the most spacecraft?
|
CREATE TABLE spacecraft (id INT,name VARCHAR(255),launch_country VARCHAR(255),launch_date DATE,max_speed FLOAT);
|
SELECT launch_country, COUNT(*) as num_spacecraft FROM spacecraft GROUP BY launch_country ORDER BY num_spacecraft DESC;
|
How many 'vegan' products are offered by each manufacturer?
|
CREATE TABLE manufacturers (manufacturer_id INT,name VARCHAR(50)); INSERT INTO manufacturers (manufacturer_id,name) VALUES (1,'ManufacturerA'),(2,'ManufacturerB'),(3,'ManufacturerC'); CREATE TABLE products (product_id INT,manufacturer_id INT,vegan CHAR(1)); INSERT INTO products (product_id,manufacturer_id,vegan) VALUES (1,1,'Y'),(2,1,'N'),(3,2,'Y'),(4,2,'Y'),(5,3,'N'),(6,3,'Y');
|
SELECT manufacturers.name, COUNT(products.product_id) AS vegan_products_count FROM manufacturers JOIN products ON manufacturers.manufacturer_id = products.manufacturer_id WHERE products.vegan = 'Y' GROUP BY manufacturers.name;
|
What is the percentage of successful passes by each team in the 2022 FIFA World Cup knockout stage?
|
CREATE TABLE fifa_teams (team_id INT,team_name VARCHAR(255)); INSERT INTO fifa_teams VALUES (1,'TeamA'),(2,'TeamB'),(3,'TeamC'),(4,'TeamD'); CREATE TABLE fifa_knockout_stage_stats (game_id INT,team_id INT,passes_attempted INT,passes_successful INT); INSERT INTO fifa_knockout_stage_stats VALUES (1,1,450,400),(1,2,400,350),(2,1,500,450),(2,3,480,420),(3,2,420,380),(3,4,520,480);
|
SELECT t.team_name, (SUM(s.passes_successful) * 100.0 / SUM(s.passes_attempted)) AS pass_success_percentage FROM fifa_teams t JOIN fifa_knockout_stage_stats s ON t.team_id = s.team_id GROUP BY t.team_id;
|
How many attendees were there at the "Jazz" event from the "Events" table?
|
CREATE TABLE Events (EventID INT,EventName TEXT,Attendance INT); INSERT INTO Events (EventID,EventName,Attendance) VALUES (1,'Jazz',50),(2,'Rock',100);
|
SELECT Attendance FROM Events WHERE EventName = 'Jazz';
|
What is the average price of products that contain natural ingredients and are certified vegan?
|
CREATE TABLE products (product_id INT,natural_ingredients BOOLEAN,certified_vegan BOOLEAN,price DECIMAL(5,2)); INSERT INTO products VALUES (1,true,true,25.99),(2,false,false,10.99),(3,true,false,15.49),(4,true,true,22.50),(5,false,true,30.00),(6,true,false,9.99),(7,true,false,12.35),(8,true,true,14.55),(9,false,false,18.99),(10,true,true,25.00);
|
SELECT AVG(p.price) FROM products p WHERE p.natural_ingredients = true AND p.certified_vegan = true;
|
List the total number of wildlife species and the number of forests for each country with wildlife sanctuaries, grouped by country, and sorted by the number of forests in descending order.
|
CREATE TABLE country (country_id INT,country_name TEXT,PRIMARY KEY (country_id)); CREATE TABLE wildlife (wildlife_id INT,country_id INT,species_count INT,PRIMARY KEY (wildlife_id),FOREIGN KEY (country_id) REFERENCES country(country_id)); CREATE TABLE forest (forest_id INT,country_id INT,forest_count INT,PRIMARY KEY (forest_id),FOREIGN KEY (country_id) REFERENCES country(country_id));
|
SELECT c.country_name, COUNT(w.species_count) AS total_wildlife_species, COUNT(f.forest_count) AS total_forests FROM country c INNER JOIN wildlife w ON c.country_id = w.country_id INNER JOIN forest f ON c.country_id = f.country_id GROUP BY c.country_name HAVING COUNT(w.species_count) > 0 ORDER BY total_forests DESC;
|
How many advertisements were served to users in the past week, grouped by the day of the week?
|
CREATE TABLE ads (id INT,user_id INT,ad_date DATE); CREATE TABLE users (id INT);
|
SELECT DATE_TRUNC('day', ad_date) ad_date, COUNT(*) FROM ads JOIN users ON ads.user_id = users.id WHERE ad_date >= CURRENT_DATE - INTERVAL '7 days' GROUP BY 1 ORDER BY 1;
|
How many new hires were made in the 'HR' and 'Finance' departments in the first half of 2021?
|
CREATE TABLE Talent_Acquisition (Applicant_ID INT,Job_Title VARCHAR(50),Department VARCHAR(50),Gender VARCHAR(10),Hire_Date DATE); INSERT INTO Talent_Acquisition (Applicant_ID,Job_Title,Department,Gender,Hire_Date) VALUES (1001,'Software Engineer','IT','Male','2021-06-01'),(1002,'HR Coordinator','HR','Female','2021-07-15'),(1003,'Finance Analyst','Finance','Non-binary','2021-04-20'),(1004,'HR Coordinator','HR','Male','2021-01-10'),(1005,'Finance Analyst','Finance','Female','2021-02-28');
|
SELECT Department, COUNT(*) FROM Talent_Acquisition WHERE Hire_Date >= '2021-01-01' AND Hire_Date < '2021-07-01' AND Department IN ('HR', 'Finance') GROUP BY Department;
|
What is the total revenue for movies by genre?
|
CREATE TABLE movie_revenue (id INT,movie TEXT,genre TEXT,revenue INT); INSERT INTO movie_revenue (id,movie,genre,revenue) VALUES (1,'Movie1','Action',5000000); INSERT INTO movie_revenue (id,movie,genre,revenue) VALUES (2,'Movie2','Comedy',4000000); INSERT INTO movie_revenue (id,movie,genre,revenue) VALUES (3,'Movie3','Action',6000000);
|
SELECT genre, SUM(revenue) as total_revenue FROM movie_revenue GROUP BY genre;
|
What is the average number of animals in habitats located in North America?
|
CREATE TABLE habitat (id INT,location TEXT,size FLOAT); CREATE TABLE animal_population (id INT,habitat_id INT,animal_count INT);
|
SELECT AVG(ap.animal_count) FROM animal_population ap INNER JOIN habitat h ON ap.habitat_id = h.id WHERE h.location = 'North America';
|
What is the average funding amount for companies founded by Latinx entrepreneurs in the last 7 years?
|
CREATE TABLE CompanyFunding(id INT,name TEXT,founding_year INT,funding_amount INT,racial_ethnicity TEXT); INSERT INTO CompanyFunding VALUES (1,'TechCo',2016,6000000,'Latinx'),(2,'GreenTech',2014,8000000,'Caucasian'),(3,'AIStudio',2021,4000000,'African'),(4,'RenewableEnergy',2018,9000000,'Latinx'),(5,'CloudServices',2020,5000000,'Asian'),(6,'SmartCity',2017,7000000,'Latinx'),(7,'DataAnalytics',2019,3000000,'Latinx');
|
SELECT AVG(funding_amount) FROM CompanyFunding WHERE racial_ethnicity = 'Latinx' AND founding_year >= YEAR(CURRENT_DATE) - 7;
|
Find the top 5 cities with the highest revenue from concert ticket sales for artists from the Pop genre.
|
CREATE TABLE Concerts (id INT,city VARCHAR(255),revenue DECIMAL(10,2)); CREATE TABLE Artists (id INT,genre VARCHAR(255));
|
SELECT city, SUM(revenue) as total_revenue FROM Concerts INNER JOIN Artists ON Concerts.id = Artists.id WHERE genre = 'Pop' GROUP BY city ORDER BY total_revenue DESC LIMIT 5;
|
Who are the top 3 volunteers by total hours served?
|
CREATE TABLE Volunteers (Id INT,Name TEXT,Hours DECIMAL(10,2)); INSERT INTO Volunteers VALUES (1,'Charlie',50.00),(2,'David',30.00),(3,'Eve',40.00);
|
SELECT Name, RANK() OVER (ORDER BY Hours DESC) as Rank FROM Volunteers WHERE Rank <= 3;
|
What is the total number of workplaces with successful collective bargaining in 2021?
|
CREATE TABLE workplaces (id INT,name TEXT,location TEXT,sector TEXT,total_employees INT,union_members INT,successful_cb BOOLEAN,cb_year INT);
|
SELECT SUM(successful_cb) FROM workplaces WHERE cb_year = 2021 AND successful_cb = TRUE;
|
What is the average ticket price for each concert in the 'music_festivals' table?
|
CREATE TABLE music_festivals (festival_name VARCHAR(255),location VARCHAR(255),date DATE,tier_1_price INT,tier_2_price INT);
|
SELECT festival_name, (tier_1_price + tier_2_price)/2 as avg_ticket_price FROM music_festivals;
|
What is the total population of lions and zebras in all sanctuaries?
|
CREATE TABLE sanctuary_g (animal_id INT,animal_name VARCHAR(50),population INT,sanctuary_name VARCHAR(50)); INSERT INTO sanctuary_g VALUES (1,'lion',60,'sanctuary_1'); INSERT INTO sanctuary_g VALUES (2,'zebra',45,'sanctuary_1'); INSERT INTO sanctuary_g VALUES (3,'lion',50,'sanctuary_2'); INSERT INTO sanctuary_g VALUES (4,'zebra',35,'sanctuary_2');
|
SELECT SUM(population) FROM sanctuary_g WHERE animal_name IN ('lion', 'zebra');
|
What is the number of hospitals and clinics in urban areas, broken down by state?
|
CREATE TABLE hospitals (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO hospitals (id,name,location,type) VALUES (1,'Hospital A','City A,State A','Hospital'); INSERT INTO hospitals (id,name,location,type) VALUES (2,'Clinic A','City B,State A','Clinic'); CREATE TABLE clinics (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO clinics (id,name,location,type) VALUES (1,'Clinic B','City A,State B','Clinic');
|
SELECT h.state, COUNT(h.id) as hospital_count, COUNT(c.id) as clinic_count FROM hospitals h INNER JOIN clinics c ON h.state = c.state WHERE h.location LIKE '%urban%' GROUP BY h.state;
|
What is the total quantity of each strain type sold in Arizona dispensaries in May 2022?
|
CREATE TABLE sales (id INT,strain_id INT,quantity INT,date DATE); INSERT INTO sales (id,strain_id,quantity,date) VALUES (1,5,10,'2022-05-01'),(2,6,15,'2022-05-02');
|
SELECT strain_id, type, SUM(quantity) as total_quantity FROM sales s JOIN strains st ON s.strain_id = st.id WHERE st.state = 'Arizona' AND date BETWEEN '2022-05-01' AND '2022-05-31' GROUP BY strain_id, type;
|
List the names of all indigenous food systems in Mexico and Guatemala, with their respective establishment years.
|
CREATE TABLE indigenous_food_systems (system_id INT,system_name TEXT,country TEXT,establishment_year INT); INSERT INTO indigenous_food_systems (system_id,system_name,country,establishment_year) VALUES (1,'Milpa System','Mexico',2000),(2,'Maya System','Guatemala',1500);
|
SELECT system_name, establishment_year FROM indigenous_food_systems WHERE country IN ('Mexico', 'Guatemala');
|
What is the average number of natural disasters reported in each region per year?
|
CREATE TABLE disasters (id INT,type TEXT,location TEXT,year INT); INSERT INTO disasters (id,type,location,year) VALUES (1,'Flood','South America',2020),(2,'Earthquake','Asia',2019),(3,'Tornado','North America',2020);
|
SELECT AVG(total_disasters) FROM (SELECT location, COUNT(*) AS total_disasters FROM disasters GROUP BY location, year) AS disaster_counts GROUP BY location;
|
What is the total number of mental health parity regulations?
|
CREATE TABLE MentalHealthParity (ID INT,Regulation VARCHAR(50),State VARCHAR(50)); INSERT INTO MentalHealthParity (ID,Regulation,State) VALUES (1,'Regulation 1','New York'); INSERT INTO MentalHealthParity (ID,Regulation,State) VALUES (2,'Regulation 2','California');
|
SELECT COUNT(*) FROM MentalHealthParity;
|
What is the earliest launch date of a mission for 'GalacticExplorers'?
|
CREATE TABLE Missions (id INT,name VARCHAR(50),company VARCHAR(50),launch_date DATE); INSERT INTO Missions (id,name,company,launch_date) VALUES (1,'Pegasus 1','GalacticExplorers','2025-04-10'),(2,'Pegasus 2','GalacticExplorers','2027-07-04'),(3,'Pegasus 3','GalacticExplorers','2029-10-31');
|
SELECT MIN(launch_date) FROM Missions WHERE company = 'GalacticExplorers';
|
What is the total number of peacekeeping operations conducted by Indonesia in 2017 and 2018?
|
CREATE TABLE peacekeeping_operations (country VARCHAR(50),year INT,operation_count INT); INSERT INTO peacekeeping_operations (country,year,operation_count) VALUES ('Indonesia',2017,3),('Indonesia',2017,4),('Indonesia',2018,5),('Indonesia',2018,6);
|
SELECT SUM(operation_count) FROM peacekeeping_operations WHERE country = 'Indonesia' AND year IN (2017, 2018);
|
Find countries with no sustainable seafood certifications for Salmon.
|
CREATE TABLE seafood_certifications (id INT,country VARCHAR(50),certification VARCHAR(50),species VARCHAR(50)); INSERT INTO seafood_certifications (id,country,certification,species) VALUES (1,'Norway','MSC','Salmon'),(2,'Norway','ASC','Salmon'),(3,'Canada','MSC','Salmon');
|
SELECT country FROM seafood_certifications WHERE species = 'Salmon' GROUP BY country HAVING COUNT(DISTINCT certification) = 0;
|
Identify the top 2 dishes with the highest carbohydrate content in Chinese cuisine restaurants in New York City, considering the month of June 2022.
|
CREATE TABLE dishes (restaurant_name TEXT,cuisine TEXT,dish TEXT,carbohydrates INTEGER,dish_date DATE); INSERT INTO dishes (restaurant_name,cuisine,dish,carbohydrates,dish_date) VALUES ('New York Wok','Chinese','Kung Pao Chicken',45,'2022-06-01');
|
SELECT dish, carbohydrates FROM (SELECT dish, carbohydrates, ROW_NUMBER() OVER (PARTITION BY dish_date ORDER BY carbohydrates DESC) as rn FROM dishes WHERE restaurant_name LIKE 'New York%' AND cuisine = 'Chinese' AND dish_date >= '2022-06-01' AND dish_date < '2022-07-01') t WHERE rn <= 2;
|
Which country has the highest sum of military equipment sales?
|
CREATE TABLE CountrySales (id INT PRIMARY KEY,country VARCHAR(50),sale_price DECIMAL(10,2));
|
SELECT country, SUM(sale_price) FROM CountrySales GROUP BY country ORDER BY SUM(sale_price) DESC LIMIT 1;
|
What is the average depth of all trenches in the Pacific Ocean, excluding trenches with an average depth of over 8000 meters?
|
CREATE TABLE ocean_trenches (trench_name TEXT,ocean TEXT,avg_depth FLOAT);
|
SELECT AVG(avg_depth) FROM ocean_trenches WHERE ocean = 'Pacific' HAVING AVG(avg_depth) < 8000;
|
What is the average water conservation initiative score for Western states?
|
CREATE TABLE western_states (state VARCHAR(20),score INT); INSERT INTO western_states (state,score) VALUES ('California',85),('Washington',82),('Oregon',88),('Nevada',78),('Colorado',75);
|
SELECT AVG(score) FROM western_states WHERE state IN ('California', 'Washington', 'Oregon', 'Nevada', 'Colorado')
|
Get the top 2 'carrier_names' with the highest 'carrier_id' from the 'freight_forwarding' table
|
CREATE TABLE freight_forwarding (carrier_id INT,carrier_name VARCHAR(50)); INSERT INTO freight_forwarding (carrier_id,carrier_name) VALUES (1,'FedEx'),(2,'UPS'),(3,'USPS');
|
SELECT carrier_name FROM freight_forwarding ORDER BY carrier_id DESC LIMIT 2;
|
How many farmers in Indonesia and Malaysia adopted sustainable agricultural practices in 2018?
|
CREATE TABLE Farmers (Farmer_ID INT,Farmer_Name TEXT,Location TEXT,Sustainable_Practices_Adopted INT,Year INT); INSERT INTO Farmers (Farmer_ID,Farmer_Name,Location,Sustainable_Practices_Adopted,Year) VALUES (1,'Siti','Indonesia',1,2018),(2,'Lee','Malaysia',1,2018);
|
SELECT SUM(Sustainable_Practices_Adopted) FROM Farmers WHERE Year = 2018 AND Location IN ('Indonesia', 'Malaysia');
|
What is the total account balance for customers in Mumbai?
|
CREATE TABLE customer (id INT,name VARCHAR(255),address VARCHAR(255),account_balance DECIMAL(10,2)); INSERT INTO customer (id,name,address,account_balance) VALUES (1,'Ravi Patel','Mumbai',3000.00),(2,'Priya Gupta','Mumbai',4000.00);
|
SELECT SUM(account_balance) FROM customer WHERE address = 'Mumbai';
|
How many carbon offset programs were implemented in 'country_codes' table in the year 2020?
|
CREATE TABLE country_codes (country_code CHAR(2),country_name VARCHAR(100),offset_program_start_year INT); INSERT INTO country_codes (country_code,country_name,offset_program_start_year) VALUES ('US','United States',2010),('CA','Canada',2015),('MX','Mexico',2018);
|
SELECT COUNT(*) FROM country_codes WHERE offset_program_start_year = 2020;
|
What is the average age of readers who prefer print news in the United States?
|
CREATE TABLE readers (id INT,name VARCHAR(50),age INT,country VARCHAR(50)); INSERT INTO readers (id,name,age,country) VALUES (1,'John Doe',45,'USA'),(2,'Jane Smith',35,'USA'); CREATE TABLE news_preferences (id INT,reader_id INT,preference VARCHAR(50)); INSERT INTO news_preferences (id,reader_id,preference) VALUES (1,1,'print'),(2,2,'digital');
|
SELECT AVG(readers.age) FROM readers INNER JOIN news_preferences ON readers.id = news_preferences.reader_id WHERE readers.country = 'USA' AND news_preferences.preference = 'print';
|
What is the total amount of Shariah-compliant loans issued by financial institutions located in Asia?
|
CREATE TABLE financial_institutions (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO financial_institutions (id,name,type,location) VALUES (1,'ABC Bank','Islamic','India'); INSERT INTO financial_institutions (id,name,type,location) VALUES (2,'Islamic Bank','Islamic','UAE'); CREATE TABLE loans (id INT,institution_id INT,type VARCHAR(255),amount DECIMAL(10,2),date DATE); INSERT INTO loans (id,institution_id,type,amount,date) VALUES (1,1,'Islamic',5000.00,'2022-01-01'); INSERT INTO loans (id,institution_id,type,amount,date) VALUES (2,2,'Islamic',6000.00,'2022-01-02');
|
SELECT SUM(amount) FROM loans WHERE type = 'Islamic' AND institution_id IN (SELECT id FROM financial_institutions WHERE location = 'Asia');
|
Which programs had the highest volunteer hours in Q1 2022?
|
CREATE TABLE VolunteerHours (Program VARCHAR(30),VolunteerHours INT,VolunteerDate DATE); INSERT INTO VolunteerHours (Program,VolunteerHours,VolunteerDate) VALUES ('Education',150,'2022-01-05'),('Health',200,'2022-01-10'),('Education',120,'2022-02-03');
|
SELECT Program, SUM(VolunteerHours) FROM VolunteerHours WHERE VolunteerDate BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY Program ORDER BY SUM(VolunteerHours) DESC;
|
How many people in Africa have access to healthcare?
|
CREATE TABLE Regions (Region TEXT,PeopleWithHealthcare INTEGER); INSERT INTO Regions (Region,PeopleWithHealthcare) VALUES ('Africa',600000000),('Asia',2000000000),('Europe',700000000);
|
SELECT PeopleWithHealthcare FROM Regions WHERE Region = 'Africa';
|
How many 'medical relief supplies' were sent to 'Africa' in the year 2022?
|
CREATE TABLE continent (continent_id INT,name VARCHAR(50)); INSERT INTO continent (continent_id,name) VALUES (1,'Asia'),(2,'Africa'); CREATE TABLE year (year_id INT,year INT); INSERT INTO year (year_id,year) VALUES (1,2022),(2,2021); CREATE TABLE supplies (supply_id INT,type VARCHAR(50),continent_id INT,year_id INT,quantity INT); INSERT INTO supplies (supply_id,type,continent_id,year_id,quantity) VALUES (1,'Food',2,1,800),(2,'Water',2,1,600),(3,'Medical',1,1,1000);
|
SELECT SUM(quantity) FROM supplies WHERE type = 'Medical' AND continent_id = 2 AND year_id = 1;
|
What is the total number of autonomous driving research studies conducted in Germany?
|
CREATE TABLE AutonomousDrivingStudies (Country VARCHAR(50),Studies INT); INSERT INTO AutonomousDrivingStudies (Country,Studies) VALUES ('Germany',30),('USA',50),('China',45);
|
SELECT SUM(Studies) FROM AutonomousDrivingStudies WHERE Country = 'Germany';
|
How many unique attendees visited art exhibitions in the 'Modern Art' genre?
|
CREATE TABLE attendees (id INT,event_id INT,name VARCHAR(255)); CREATE TABLE events (id INT,name VARCHAR(255),genre VARCHAR(255)); INSERT INTO attendees (id,event_id,name) VALUES (1,1,'John Doe'); INSERT INTO attendees (id,event_id,name) VALUES (2,1,'Jane Doe'); INSERT INTO events (id,name,genre) VALUES (1,'Modern Art Exhibit','Modern Art');
|
SELECT COUNT(DISTINCT a.name) FROM attendees a JOIN events e ON a.event_id = e.id WHERE e.genre = 'Modern Art';
|
Select the Name, Rank, and EntryYear of the top 2 soldiers with the earliest EntryYear.
|
CREATE TABLE Soldiers (SoldierID INT,Name VARCHAR(50),Rank VARCHAR(20),EntryYear INT); INSERT INTO Soldiers (SoldierID,Name,Rank,EntryYear) VALUES (1,'John Doe','Captain',1995),(2,'Jane Smith','Lieutenant',2002),(3,'Mary Johnson','Lieutenant',2000);
|
SELECT Name, Rank, EntryYear FROM (SELECT Name, Rank, EntryYear, ROW_NUMBER() OVER (ORDER BY EntryYear) as RowNum FROM Soldiers) AS SoldiersRanked WHERE RowNum <= 2;
|
How many customers are there in each network type?
|
CREATE TABLE subscribers (id INT,name VARCHAR(50),network VARCHAR(20)); INSERT INTO subscribers (id,name,network) VALUES (1,'Jane Doe','4G'),(2,'Mike Smith','5G'),(3,'Sara Connor','4G');
|
SELECT network, COUNT(*) FROM subscribers GROUP BY network;
|
Which reporters are based in African countries?
|
CREATE TABLE reporters (id INT,name VARCHAR(255),gender VARCHAR(10),age INT,country VARCHAR(100)); INSERT INTO reporters (id,name,gender,age,country) VALUES (4,'Aisha Okeke','Female',38,'Nigeria'); INSERT INTO reporters (id,name,gender,age,country) VALUES (5,'Kwame Boateng','Male',45,'Ghana');
|
SELECT * FROM reporters WHERE country IN ('Nigeria', 'Ghana', 'Kenya', 'Egypt', 'South Africa');
|
What is the total number of offenders in the justice_data schema's juvenile_offenders table who have been referred to restorative justice programs, broken down by race?
|
CREATE TABLE justice_data.juvenile_offenders (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),race VARCHAR(50),restorative_justice_program BOOLEAN);
|
SELECT race, COUNT(*) FROM justice_data.juvenile_offenders WHERE restorative_justice_program = TRUE GROUP BY race;
|
Which campaigns received the most donations in H1 2022?
|
CREATE TABLE Donations (id INT,campaign VARCHAR(50),amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,campaign,amount,donation_date) VALUES (1,'Spring Campaign',5000,'2022-04-01'),(2,'Summer Campaign',6000,'2022-06-01'),(3,'Fall Campaign',7000,'2022-08-01'),(4,'Winter Campaign',8000,'2022-10-01');
|
SELECT campaign, SUM(amount) as total_donations FROM Donations WHERE donation_date >= '2022-01-01' AND donation_date <= '2022-06-30' GROUP BY campaign ORDER BY total_donations DESC;
|
Show the construction labor statistics for the last quarter, for the Eastern region, and rank the statistics by their wage increases in descending order.
|
CREATE TABLE LaborStatsByQuarter (StatID int,Region varchar(20),Quarter int,WageIncrease decimal(10,2)); INSERT INTO LaborStatsByQuarter (StatID,Region,Quarter,WageIncrease) VALUES (1,'Eastern',3,0.04),(2,'Eastern',4,0.05),(3,'Eastern',4,0.03);
|
SELECT Region, WageIncrease, ROW_NUMBER() OVER (PARTITION BY Region ORDER BY WageIncrease DESC) as rn FROM LaborStatsByQuarter WHERE Region = 'Eastern' AND Quarter IN (3, 4);
|
Identify the number of climate communication projects funded by private sectors in Asia.
|
CREATE TABLE climate_communication_projects (project_id INT,sector TEXT,investor_type TEXT,region TEXT); INSERT INTO climate_communication_projects (project_id,sector,investor_type,region) VALUES (1,'Climate Communication','Private','Asia'); INSERT INTO climate_communication_projects (project_id,sector,investor_type,region) VALUES (2,'Climate Communication','Public','Asia');
|
SELECT COUNT(*) FROM climate_communication_projects WHERE sector = 'Climate Communication' AND investor_type = 'Private';
|
What is the average response time for emergencies in the 'South' district in the last year?
|
CREATE TABLE districts (district_id INT,district_name TEXT);CREATE TABLE emergencies (emergency_id INT,district_id INT,response_time INT,emergency_date DATE);
|
SELECT AVG(response_time) FROM emergencies WHERE district_id = (SELECT district_id FROM districts WHERE district_name = 'South') AND emergency_date >= DATEADD(year, -1, GETDATE());
|
What is the total weight of recycled materials used in the production of garments in the 'Vintage_Styles' category?
|
CREATE TABLE Production(garment_id INT,category VARCHAR(20),recycled_material_weight INT); INSERT INTO Production(garment_id,category,recycled_material_weight) VALUES (1,'Vintage_Styles',5),(2,'Vintage_Styles',3);
|
SELECT SUM(recycled_material_weight) FROM Production WHERE category = 'Vintage_Styles';
|
Show the total number of ad impressions and clicks for users aged between 25 and 34 in the last week, along with the click-through rate (CTR).
|
CREATE TABLE if not exists user_profile (user_id int,age int,gender varchar(10),signup_date date);CREATE TABLE if not exists ad_impressions (impression_id int,user_id int,ad_id int,impression_date date);CREATE TABLE if not exists ad_clicks (click_id int,user_id int,ad_id int,click_date date);
|
SELECT u.age_range, COUNT(i.impression_id) as total_impressions, COUNT(c.click_id) as total_clicks, (COUNT(c.click_id) * 100.0 / COUNT(i.impression_id)) as ctr FROM (SELECT user_id, CASE WHEN age BETWEEN 25 AND 34 THEN '25-34' END as age_range FROM user_profile WHERE signup_date <= DATEADD(day, -7, GETDATE())) u INNER JOIN ad_impressions i ON u.user_id = i.user_id INNER JOIN ad_clicks c ON u.user_id = c.user_id WHERE i.impression_date = c.click_date AND u.age_range IS NOT NULL GROUP BY u.age_range;
|
Identify the customers who returned the most items in reverse logistics in Q4 2020, with at least 3 returns.
|
CREATE TABLE customer_returns (return_id INT,customer_id INT,return_date DATE);
|
SELECT customer_id, COUNT(*) as num_returns FROM customer_returns WHERE EXTRACT(MONTH FROM return_date) BETWEEN 10 AND 12 GROUP BY customer_id HAVING num_returns >= 3;
|
What is the total number of marine protected areas in the Pacific region that were established in the last decade?"
|
CREATE TABLE marine_protected_areas (area_name TEXT,region TEXT,establishment_date DATE); CREATE TABLE pacific_region (region_name TEXT,region_description TEXT);
|
SELECT COUNT(mpa.area_name) FROM marine_protected_areas mpa INNER JOIN pacific_region pr ON mpa.region = pr.region_name AND mpa.establishment_date >= (CURRENT_DATE - INTERVAL '10 years');
|
List the community development initiatives with their respective funding sources in 2019, ordered by the amount of funds received?
|
CREATE TABLE community_development (id INT,initiative_name VARCHAR(100),initiative_type VARCHAR(50),funding_source VARCHAR(50),funds_received FLOAT,start_date DATE,end_date DATE);
|
SELECT initiative_name, funding_source, funds_received FROM community_development WHERE YEAR(start_date) = 2019 ORDER BY funds_received DESC;
|
What is the minimum and maximum water temperature for each tank in the 'fish_tanks' table?
|
CREATE TABLE fish_tanks (tank_id INT,species VARCHAR(255),water_temperature DECIMAL(5,2)); INSERT INTO fish_tanks (tank_id,species,water_temperature) VALUES (1,'Tilapia',26.5),(2,'Salmon',12.0),(3,'Tilapia',27.3),(4,'Catfish',24.6),(5,'Salmon',12.5);
|
SELECT tank_id, MIN(water_temperature) as min_temp, MAX(water_temperature) as max_temp FROM fish_tanks GROUP BY tank_id;
|
What is the average number of points scored by basketball players in the last 5 games they have played?
|
CREATE TABLE games (id INT,team_id INT,player_id INT,points INT,sport VARCHAR(50)); INSERT INTO games (id,team_id,player_id,points,sport) VALUES (1,101,1,25,'Basketball'); INSERT INTO games (id,team_id,player_id,points,sport) VALUES (2,102,2,30,'Basketball');
|
SELECT AVG(points) FROM games WHERE sport = 'Basketball' AND id IN (SELECT game_id FROM last_5_games);
|
What is the total number of green buildings in the state of Texas that were constructed before 2015?
|
CREATE TABLE green_buildings (id INT,state VARCHAR(20),construction_year INT); INSERT INTO green_buildings (id,state,construction_year) VALUES (1,'Texas',2012),(2,'Texas',2005),(3,'California',2018),(4,'Texas',2014);
|
SELECT COUNT(*) FROM green_buildings WHERE state = 'Texas' AND construction_year < 2015;
|
Find the total number of tickets sold by each salesperson, grouped by team.
|
CREATE TABLE salesperson (id INT,name VARCHAR(50),team VARCHAR(50)); CREATE TABLE tickets (id INT,salesperson_id INT,quantity INT,city VARCHAR(50)); INSERT INTO salesperson (id,name,team) VALUES (1,'John Doe','Knicks'),(2,'Jane Smith','Giants'),(3,'Mia Rodriguez','Lakers'),(4,'Mason Green','United'); INSERT INTO tickets (id,salesperson_id,quantity,city) VALUES (1,1,50,'New York'),(2,1,75,'New York'),(3,2,30,'Los Angeles'),(4,2,40,'Los Angeles'),(5,3,25,'Chicago'),(6,3,50,'Chicago'),(7,4,10,'London');
|
SELECT s.team, s.name, SUM(t.quantity) as total_quantity FROM salesperson s JOIN tickets t ON s.id = t.salesperson_id GROUP BY s.team, s.name;
|
What is the total amount of electronic waste generated in the world, and how does that compare to the amount of electronic waste generated in Europe?
|
CREATE TABLE ElectronicWaste (Region VARCHAR(50),WasteQuantity INT); INSERT INTO ElectronicWaste (Region,WasteQuantity) VALUES ('World',50000000),('Europe',5000000),('North America',15000000),('Asia',25000000);
|
SELECT Region, WasteQuantity FROM ElectronicWaste WHERE Region IN ('World', 'Europe');
|
What is the total cost of dairy ingredients?
|
CREATE TABLE inventory (ingredient_id INT,ingredient_name VARCHAR(50),ingredient_category VARCHAR(50),quantity INT,cost DECIMAL(5,2)); INSERT INTO inventory VALUES (1,'Quinoa','Grain',50,2.99),(2,'Milk','Dairy',30,1.49),(3,'Tofu','Protein',40,1.99),(4,'Cheese','Dairy',20,3.99);
|
SELECT SUM(quantity * cost) FROM inventory WHERE ingredient_category = 'Dairy';
|
List the number of unique patients who have completed each type of treatment.
|
CREATE TABLE treatments (treatment_id INT,treatment VARCHAR(10),patient_id INT); INSERT INTO treatments (treatment_id,treatment,patient_id) VALUES (1,'CBT',1),(2,'DBT',2),(3,'CBT',3),(4,'Group Therapy',1),(5,'CBT',2);
|
SELECT treatment, COUNT(DISTINCT patient_id) FROM treatments GROUP BY treatment;
|
What is the minimum surface salinity recorded in the Pacific Ocean?
|
CREATE TABLE ocean_salinity (location VARCHAR(255),salinity FLOAT,date DATE);
|
SELECT MIN(salinity) FROM ocean_salinity WHERE location = 'Pacific Ocean';
|
What is the maximum number of species observed in the 'arctic_species' table, grouped by year?
|
CREATE TABLE arctic_species (year INT,species_count INT);
|
SELECT year, MAX(species_count) FROM arctic_species GROUP BY year;
|
What is the total number of games won by each team in the last season?
|
CREATE TABLE teams (team_name VARCHAR(50),team_city VARCHAR(50),games_won INT); INSERT INTO teams (team_name,team_city,games_won) VALUES ('Red Sox','Boston',93),('Yankees','New York',92);
|
SELECT team_name, SUM(games_won) as total_games_won FROM teams WHERE game_date >= DATEADD(year, -1, GETDATE()) GROUP BY team_name;
|
What is the total number of digital assets issued by each country?
|
CREATE TABLE country (id INT,name VARCHAR(255)); INSERT INTO country (id,name) VALUES (1,'USA'),(2,'China'),(3,'Japan'); CREATE TABLE digital_assets (id INT,country_id INT,name VARCHAR(255),quantity INT); INSERT INTO digital_assets (id,country_id,name,quantity) VALUES (1,1,'AssetA',500),(2,1,'AssetB',300),(3,2,'AssetC',200),(4,3,'AssetD',400);
|
SELECT country.name AS Country, SUM(digital_assets.quantity) AS Total_Assets FROM country JOIN digital_assets ON country.id = digital_assets.country_id GROUP BY country.name;
|
How many fish species are there in the 'fish_stock' table?
|
CREATE TABLE fish_stock (fish_id INT PRIMARY KEY,species VARCHAR(50),location VARCHAR(50),biomass FLOAT); INSERT INTO fish_stock (fish_id,species,location,biomass) VALUES (1,'tuna','tropical',250.5),(2,'salmon','arctic',180.3),(3,'cod','temperate',120.0);
|
SELECT COUNT(DISTINCT species) FROM fish_stock;
|
How many indigenous communities exist in the Arctic with a population greater than 500?
|
CREATE TABLE indigenous_communities (id INT PRIMARY KEY,name VARCHAR(255),population INT,region VARCHAR(255),language VARCHAR(255)); INSERT INTO indigenous_communities (id,name,population,region,language) VALUES (1,'Community A',500,'Arctic','Language A'); INSERT INTO indigenous_communities (id,name,population,region,language) VALUES (2,'Community B',700,'Arctic','Language B');
|
SELECT COUNT(*) FROM indigenous_communities WHERE region = 'Arctic' AND population > 500;
|
What is the percentage of the budget allocated to education, healthcare, and infrastructure in CityE?
|
CREATE TABLE City_Budget (City VARCHAR(20),Department VARCHAR(20),Budget INT); INSERT INTO City_Budget (City,Department,Budget) VALUES ('CityE','Education',4000000); INSERT INTO City_Budget (City,Department,Budget) VALUES ('CityE','Healthcare',3000000); INSERT INTO City_Budget (City,Department,Budget) VALUES ('CityE','Infrastructure',5000000);
|
SELECT City, ROUND(SUM(CASE WHEN Department = 'Education' THEN Budget ELSE 0 END) / SUM(Budget) * 100, 2) AS 'Education Budget %', ROUND(SUM(CASE WHEN Department = 'Healthcare' THEN Budget ELSE 0 END) / SUM(Budget) * 100, 2) AS 'Healthcare Budget %', ROUND(SUM(CASE WHEN Department = 'Infrastructure' THEN Budget ELSE 0 END) / SUM(Budget) * 100, 2) AS 'Infrastructure Budget %' FROM City_Budget WHERE City = 'CityE' GROUP BY City;
|
What is the most frequently purchased halal certified skincare product in India?
|
CREATE TABLE skincare_purchases (purchase_id INT,product_id INT,purchase_quantity INT,is_halal_certified BOOLEAN,purchase_date DATE,country VARCHAR(20)); INSERT INTO skincare_purchases VALUES (1,40,5,true,'2021-07-22','India'); INSERT INTO skincare_purchases VALUES (2,41,2,true,'2021-07-22','India');
|
SELECT product_id, MAX(purchase_quantity) FROM skincare_purchases WHERE is_halal_certified = true AND country = 'India' GROUP BY product_id;
|
List the number of military equipment maintenance requests in Canada, in ascending order.
|
CREATE TABLE military_equipment_maintenance (request_id INT,equipment_type TEXT,country TEXT,maintenance_date DATE); INSERT INTO military_equipment_maintenance (request_id,equipment_type,country,maintenance_date) VALUES (1,'M1 Abrams','Canada','2022-02-14');
|
SELECT COUNT(*) FROM military_equipment_maintenance WHERE country = 'Canada' ORDER BY COUNT(*) ASC;
|
List the names of astronauts who participated in missions with duration greater than 300 days
|
CREATE TABLE Space_Missions(mission_name VARCHAR(30),duration INT,astronaut_id INT); CREATE TABLE Astronauts(astronaut_id INT,astronaut_name VARCHAR(30)); INSERT INTO Space_Missions(mission_name,duration,astronaut_id) VALUES ('Apollo 11',240,1),('Apollo 11',240,2),('Ares 1',315,3),('Ares 1',315,4),('Gemini 12',198,5),('Gemini 12',198,6); INSERT INTO Astronauts(astronaut_id,astronaut_name) VALUES (1,'Neil Armstrong'),(2,'Buzz Aldrin'),(3,'John Williams'),(4,'Mary Jackson'),(5,'Ellen Johnson'),(6,'Mark Robinson');
|
SELECT Astronauts.astronaut_name FROM Space_Missions INNER JOIN Astronauts ON Space_Missions.astronaut_id = Astronauts.astronaut_id WHERE Space_Missions.duration > 300;
|
List all the customers who have taken out a loan in the last month and have a financial wellbeing workshop coming up in the next month
|
CREATE TABLE Customers (CustomerID INT,Name VARCHAR(255)); INSERT INTO Customers (CustomerID,Name) VALUES (1,'John Doe'); INSERT INTO Customers (CustomerID,Name) VALUES (2,'Jane Doe'); CREATE TABLE Loans (LoanID INT,CustomerID INT,Date DATE); INSERT INTO Loans (LoanID,CustomerID,Date) VALUES (1,1,'2022-05-01'); INSERT INTO Loans (LoanID,CustomerID,Date) VALUES (2,1,'2022-04-01'); INSERT INTO Loans (LoanID,CustomerID,Date) VALUES (3,2,'2022-05-01'); CREATE TABLE Workshops (WorkshopID INT,CustomerID INT,Date DATE); INSERT INTO Workshops (WorkshopID,CustomerID,Date) VALUES (1,1,'2022-06-01');
|
SELECT L.CustomerID, C.Name FROM Loans L INNER JOIN Customers C ON L.CustomerID = C.CustomerID WHERE L.Date >= DATEADD(month, -1, GETDATE()) AND C.CustomerID IN (SELECT W.CustomerID FROM Workshops W WHERE W.Date >= DATEADD(month, 1, GETDATE()));
|
What is the total irrigated area in South America for the past year from satellite imagery analysis?
|
CREATE TABLE if not exists satellite_analysis (id INT,location VARCHAR(255),irrigated_area INT,image_date DATETIME); INSERT INTO satellite_analysis (id,location,irrigated_area,image_date) VALUES (1,'Brazil',50000,'2022-01-01 00:00:00'),(2,'Argentina',40000,'2022-01-01 00:00:00');
|
SELECT SUM(irrigated_area) FROM satellite_analysis WHERE location LIKE 'South%' AND image_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 YEAR) AND NOW();
|
What is the ratio of male to female employees in the Engineering department?
|
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Gender,Department) VALUES (1,'Female','HR'),(2,'Male','IT'),(3,'Female','HR'),(4,'Male','IT'),(5,'Female','Engineering'),(6,'Male','Engineering');
|
SELECT COUNT(*) * 1.0 / SUM(CASE WHEN Gender = 'Female' THEN 1 ELSE 0 END) FROM Employees WHERE Department = 'Engineering';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.