instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total number of employees in technology unions with a salary greater than $80,000?
|
CREATE TABLE technology_unions (id INT,employee_name TEXT,union_id INT,salary REAL); INSERT INTO technology_unions (id,employee_name,union_id,salary) VALUES (1,'Alex Nguyen',1001,85000.00),(2,'Bella Chen',1002,90000.00),(3,'Charlie Patel',1003,95000.00);
|
SELECT COUNT(*) FROM technology_unions WHERE salary > 80000;
|
Determine the current landfill capacity for the 'North America' region from the 'landfill_capacity' table
|
CREATE TABLE landfill_capacity (region VARCHAR(50),current_capacity INT);
|
SELECT current_capacity FROM landfill_capacity WHERE region = 'North America';
|
What is the minimum landfill capacity in cubic meters for each country in the European Union?
|
CREATE TABLE LandfillCapacity (country VARCHAR(255),region VARCHAR(255),landfill_capacity FLOAT); INSERT INTO LandfillCapacity (country,region,landfill_capacity) VALUES ('Germany','European Union',1500000),('France','European Union',1200000),('Italy','European Union',1800000);
|
SELECT country, MIN(landfill_capacity) FROM LandfillCapacity WHERE region = 'European Union' GROUP BY country;
|
What is the waste generation in kg per capita for each city in the year 2020?
|
CREATE TABLE CityPopulation (city VARCHAR(50),year INT,population INT); INSERT INTO CityPopulation (city,year,population) VALUES ('CityA',2018,100000),('CityA',2019,105000),('CityA',2020,110000),('CityB',2018,200000),('CityB',2019,210000),('CityB',2020,220000);
|
SELECT wg.city, (SUM(wg.amount) / cp.population) FROM WasteGeneration wg INNER JOIN CityPopulation cp ON wg.city = cp.city AND wg.year = cp.year WHERE wg.year = 2020 GROUP BY wg.city;
|
How many customers were impacted by droughts in 2019 and 2020?
|
CREATE TABLE drought_impact (customer_id INT,year INT,impact_level TEXT); INSERT INTO drought_impact (customer_id,year,impact_level) VALUES (1,2019,'severe'),(1,2020,'moderate'),(2,2019,'none'),(3,2020,'severe'),(3,2019,'moderate');
|
SELECT COUNT(DISTINCT customer_id) as num_impacted_customers FROM drought_impact WHERE year IN (2019, 2020) AND impact_level <> 'none';
|
Identify the unique water conservation initiatives for each region.
|
CREATE TABLE conservation_initiatives(initiative_id INT,initiative_name TEXT,region TEXT); INSERT INTO conservation_initiatives(initiative_id,initiative_name,region) VALUES (1,'Rainwater harvesting','X'),(2,'Greywater recycling','X'),(3,'Smart irrigation','Y'),(4,'Drip irrigation','Z'),(5,'Permeable pavement','X');
|
SELECT DISTINCT region, initiative_name FROM conservation_initiatives;
|
What is the minimum duration of workouts for members who joined in 2019, grouped by gender?
|
CREATE TABLE Workout (WorkoutID INT PRIMARY KEY,MemberID INT,Duration INT,Date DATE); CREATE TABLE Member (MemberID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),MembershipStart DATE);
|
SELECT Member.Gender, MIN(Workout.Duration) FROM Workout INNER JOIN Member ON Workout.MemberID = Member.MemberID WHERE Member.MembershipStart BETWEEN '2019-01-01' AND '2019-12-31' GROUP BY Member.Gender;
|
What is the number of male and female members who joined in each month?
|
CREATE TABLE Members (MemberID INT,JoinDate DATE,Gender VARCHAR(10)); INSERT INTO Members (MemberID,JoinDate,Gender) VALUES (1,'2022-01-01','Male'),(2,'2022-02-01','Female'),(3,'2022-03-01','Male');
|
SELECT MONTH(JoinDate), Gender, COUNT(*) FROM Members GROUP BY MONTH(JoinDate), Gender;
|
What is the total revenue generated from each type of workout?
|
CREATE TABLE workout_fees (id INT,workout_type VARCHAR(50),fee DECIMAL(5,2)); INSERT INTO workout_fees (id,workout_type,fee) VALUES (1,'Running',10.00),(2,'Cycling',15.00);
|
SELECT workouts.workout_type, SUM(workout_fees.fee) AS total_revenue FROM workouts INNER JOIN workout_fees ON workouts.workout_type = workout_fees.workout_type GROUP BY workouts.workout_type;
|
List the number of flights operated by each airline in the last month?
|
CREATE TABLE FlightOperations (id INT,flight_number VARCHAR(50),airline VARCHAR(50),operated_date DATE);
|
SELECT airline, COUNT(*) FROM FlightOperations WHERE operated_date >= DATEADD(month, -1, GETDATE()) GROUP BY airline;
|
What is the total number of satellites deployed by each country?
|
CREATE SCHEMA if not exists aerospace;CREATE TABLE if not exists aerospace.satellites (id INT PRIMARY KEY,country VARCHAR(50),name VARCHAR(50),launch_date DATE); INSERT INTO aerospace.satellites (id,country,name,launch_date) VALUES (1,'USA','Sat1','2000-01-01'),(2,'USA','Sat2','2001-01-01'),(3,'China','Sat3','2002-01-01');
|
SELECT country, COUNT(*) as total_satellites FROM aerospace.satellites GROUP BY country;
|
What is the total number of animals in each sanctuary, sorted by the number of animals in descending order?
|
CREATE TABLE animal_sanctuary (sanctuary_id INT,sanctuary_name VARCHAR(255),animal_type VARCHAR(255),animal_count INT); INSERT INTO animal_sanctuary (sanctuary_id,sanctuary_name,animal_type,animal_count) VALUES (1,'Sanctuary A','Tiger',25),(2,'Sanctuary A','Elephant',30),(3,'Sanctuary B','Tiger',35),(4,'Sanctuary B','Elephant',20),(5,'Sanctuary C','Tiger',15),(6,'Sanctuary C','Elephant',40);
|
SELECT sanctuary_name, animal_type, SUM(animal_count) AS total_animals FROM animal_sanctuary GROUP BY sanctuary_name, animal_type WITH ROLLUP ORDER BY total_animals DESC;
|
How many tons of seafood were exported by the United States to China in 2020?
|
CREATE TABLE seafood_exports_v2 (id INT,export_date DATE,export_country VARCHAR(50),import_country VARCHAR(50),quantity INT,unit_type VARCHAR(10)); INSERT INTO seafood_exports_v2 (id,export_date,export_country,import_country,quantity,unit_type) VALUES (1,'2020-01-01','US','China',700,'ton'),(2,'2020-01-02','Canada','Mexico',400,'ton'),(3,'2021-01-01','US','China',800,'ton');
|
SELECT SUM(quantity) FROM seafood_exports_v2 WHERE export_country = 'US' AND import_country = 'China' AND EXTRACT(YEAR FROM export_date) = 2020;
|
Insert a new record into the "audience" table for a visitor named "Alex" from the USA
|
CREATE TABLE audience (visitor_id INT PRIMARY KEY,name VARCHAR(100),country VARCHAR(50),visit_date DATE);
|
INSERT INTO audience (visitor_id, name, country, visit_date) VALUES ((SELECT MAX(visitor_id) FROM audience) + 1, 'Alex', 'USA', CURDATE());
|
What is the average project timeline in weeks for construction in urban areas?
|
CREATE TABLE Projects (id INT,area_type VARCHAR(255),project_timeline_weeks FLOAT); INSERT INTO Projects (id,area_type,project_timeline_weeks) VALUES (1,'urban',12.5),(2,'rural',15.0),(3,'urban',13.0);
|
SELECT AVG(project_timeline_weeks) FROM Projects WHERE area_type = 'urban';
|
Insert a new record into the 'cannabis_production' table for strain 'Gelato' with a yield of 500 grams
|
CREATE TABLE cannabis_production (id INT,strain VARCHAR(50),yield INT); INSERT INTO cannabis_production (id,strain,yield) VALUES (1,'Blue Dream',400);
|
INSERT INTO cannabis_production (strain, yield) VALUES ('Gelato', 500);
|
Which chemical plants have exceeded the maximum allowed emission limit in the last year?
|
CREATE TABLE plants (plant_id INT,plant_name VARCHAR(50)); CREATE TABLE emissions (plant_id INT,emission_level INT,emission_date DATE); INSERT INTO plants (plant_id,plant_name) VALUES (1,'Plant A'),(2,'Plant B'); INSERT INTO emissions (plant_id,emission_level,emission_date) VALUES (1,500,'2022-01-01'),(2,450,'2022-01-01');
|
SELECT plants.plant_name FROM plants INNER JOIN emissions ON plants.plant_id = emissions.plant_id WHERE emissions.emission_level > (SELECT MAX(emission_limit) FROM allowed_emissions) AND emissions.emission_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
|
What is the percentage of the population with health insurance in the United States?
|
CREATE TABLE Health_Insurance (ID INT,Country VARCHAR(50),Percentage FLOAT); INSERT INTO Health_Insurance (ID,Country,Percentage) VALUES (1,'United States',91.2);
|
SELECT Percentage FROM Health_Insurance WHERE Country = 'United States';
|
How many startups in the transportation sector were founded by people from underrepresented communities?
|
CREATE TABLE startups(id INT,name TEXT,industry TEXT,founder_community TEXT); INSERT INTO startups (id,name,industry,founder_community) VALUES (1,'GreenRide','Transportation','Underrepresented');
|
SELECT COUNT(*) FROM startups WHERE industry = 'Transportation' AND founder_community = 'Underrepresented';
|
List all smart contracts created by developers located in the European Union?
|
CREATE TABLE smart_contracts (id INT,name VARCHAR(255),developer_country VARCHAR(50)); INSERT INTO smart_contracts (id,name,developer_country) VALUES (1,'Contract1','Germany'),(2,'Contract2','France'),(3,'Contract3','USA');
|
SELECT name FROM smart_contracts WHERE developer_country IN ('Germany', 'France', 'Italy', 'Spain', 'Poland');
|
What are the top 5 digital assets with the highest trading volume in the European region?
|
CREATE TABLE digital_assets (asset_id INT,asset_name VARCHAR(50),region VARCHAR(50),trading_volume DECIMAL(18,2)); INSERT INTO digital_assets (asset_id,asset_name,region,trading_volume) VALUES (1,'Bitcoin','Europe',15000000);
|
SELECT d.asset_name, SUM(d.trading_volume) as total_volume FROM digital_assets d WHERE d.region = 'Europe' GROUP BY d.asset_name ORDER BY total_volume DESC LIMIT 5;
|
What is the total number of transactions for each digital asset in the 'decentralized_exchanges' table, and their corresponding trading volume?
|
CREATE TABLE decentralized_exchanges (exchange_name VARCHAR(255),digital_asset VARCHAR(255),transaction_count INT,trading_volume DECIMAL(10,2));
|
SELECT d.digital_asset, SUM(d.transaction_count) as total_transactions, SUM(d.trading_volume) as total_volume FROM decentralized_exchanges d GROUP BY d.digital_asset;
|
Insert new records for timber production in the "Southeast" region for the years 2018, 2019, and 2020, with the following volumes: 1200, 1500, and 1800.
|
CREATE TABLE timber_production (id INT PRIMARY KEY,region VARCHAR(50),year INT,volume INT);
|
INSERT INTO timber_production (region, year, volume) VALUES ('Southeast', 2018, 1200), ('Southeast', 2019, 1500), ('Southeast', 2020, 1800);
|
List all the trees in the forest_management table that are older than 50 years?
|
CREATE TABLE forest_management (tree_id INT,species VARCHAR(50),age INT);
|
SELECT * FROM forest_management WHERE age > 50;
|
Show consumer preference data for foundations, excluding products from the USA.
|
CREATE TABLE cosmetics (product_id INT,product_name VARCHAR(100),product_type VARCHAR(50),is_cruelty_free BOOLEAN,consumer_preference_score INT); INSERT INTO cosmetics (product_id,product_name,product_type,is_cruelty_free,consumer_preference_score) VALUES (1,'Lipstick A','Lipstick',TRUE,80),(2,'Foundation B','Foundation',FALSE,90),(3,'Mascara C','Mascara',TRUE,85),(4,'Eyeshadow D','Eyeshadow',TRUE,70),(5,'Blush E','Blush',FALSE,95); CREATE TABLE ingredient_sourcing (ingredient_id INT,ingredient_name VARCHAR(100),sourcing_country VARCHAR(50),is_organic BOOLEAN); INSERT INTO ingredient_sourcing (ingredient_id,ingredient_name,sourcing_country,is_organic) VALUES (1,'Rosehip Oil','Chile',TRUE),(2,'Shea Butter','Ghana',TRUE),(3,'Jojoba Oil','India',TRUE),(4,'Coconut Oil','Philippines',FALSE),(5,'Aloe Vera','USA',TRUE);
|
SELECT * FROM cosmetics WHERE product_type = 'Foundation' AND product_id NOT IN (SELECT cosmetics.product_id FROM cosmetics INNER JOIN ingredient_sourcing ON cosmetics.product_id = ingredient_sourcing.ingredient_id WHERE ingredient_sourcing.sourcing_country = 'USA');
|
Which ingredients are sourced from countries with high biodiversity?
|
CREATE TABLE ingredients (ingredient_id INT,name VARCHAR(255),sourcing_country VARCHAR(255)); INSERT INTO ingredients (ingredient_id,name,sourcing_country) VALUES (1,'Argan Oil','Morocco'),(2,'Shea Butter','Ghana'),(3,'Jojoba Oil','Argentina'); CREATE TABLE country_biodiversity (country VARCHAR(255),biodiversity_index INT); INSERT INTO country_biodiversity (country,biodiversity_index) VALUES ('Morocco',80),('Ghana',90),('Argentina',70);
|
SELECT i.name, i.sourcing_country FROM ingredients i JOIN country_biodiversity cb ON i.sourcing_country = cb.country WHERE cb.biodiversity_index > 70;
|
What is the average threat intelligence metric score for the past month in the Pacific region?
|
CREATE TABLE threat_intelligence (threat_id INT,threat_score INT,threat_region VARCHAR(255),threat_date DATE); INSERT INTO threat_intelligence (threat_id,threat_score,threat_region,threat_date) VALUES (1,7,'Pacific','2021-01-01'); INSERT INTO threat_intelligence (threat_id,threat_score,threat_region,threat_date) VALUES (2,8,'Atlantic','2021-02-01');
|
SELECT AVG(threat_score) as avg_threat_score FROM threat_intelligence WHERE threat_region = 'Pacific' AND threat_date >= DATEADD(month, -1, GETDATE());
|
Which defense contractors have signed the most contracts in the last 12 months?
|
CREATE TABLE contract_timeline (contractor VARCHAR(255),contract_date DATE); INSERT INTO contract_timeline (contractor,contract_date) VALUES ('Contractor A','2022-01-01'),('Contractor B','2022-02-15'),('Contractor C','2022-03-01'),('Contractor A','2022-04-01');
|
SELECT contractor, COUNT(*) FROM contract_timeline WHERE contract_date >= DATEADD(year, -1, CURRENT_DATE) GROUP BY contractor;
|
What is the total defense spending by countries in Oceania in 2018?
|
CREATE TABLE defense_spending (country VARCHAR(50),continent VARCHAR(50),year INT,amount FLOAT); INSERT INTO defense_spending (country,continent,year,amount) VALUES ('Australia','Oceania',2018,750.3),('New Zealand','Oceania',2018,23.4),('Papua New Guinea','Oceania',2018,6.7);
|
SELECT SUM(amount) FROM defense_spending WHERE continent = 'Oceania' AND year = 2018;
|
What is the average daily transaction amount for each customer in the past quarter?
|
CREATE TABLE transactions (transaction_date DATE,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_date,customer_id,amount) VALUES ('2022-01-01',1,100),('2022-01-05',1,200),('2022-01-02',2,150),('2022-01-03',2,50),('2022-04-04',3,300),('2022-04-05',3,250),('2022-04-10',1,50),('2022-04-15',2,350),('2022-04-20',4,400);
|
SELECT customer_id, AVG(amount) AS avg_daily_amount FROM transactions WHERE transaction_date >= CURRENT_DATE - INTERVAL '3 months' GROUP BY customer_id, EXTRACT(DAY FROM transaction_date), EXTRACT(MONTH FROM transaction_date), EXTRACT(YEAR FROM transaction_date) ORDER BY customer_id;
|
List the unique destinations for cargos in the cargo_handling table that are also present in the regulatory_compliance table, and display the count of such destinations.
|
CREATE TABLE cargo_handling(cargo_id INT,cargo_type VARCHAR(50),weight FLOAT,destination VARCHAR(50)); CREATE TABLE regulatory_compliance(cargo_id INT,cargo_type VARCHAR(50),destination VARCHAR(50));
|
SELECT destination, COUNT(DISTINCT destination) AS dest_count FROM cargo_handling CH JOIN regulatory_compliance RC ON CH.cargo_id = RC.cargo_id GROUP BY destination HAVING COUNT(DISTINCT destination) > 1;
|
How many factories in the pharmaceutical industry are compliant with ethical manufacturing practices in South America?
|
CREATE TABLE factories (id INT,industry VARCHAR(50),region VARCHAR(50),ethical_manufacturing BOOLEAN);
|
SELECT COUNT(*) FROM factories WHERE industry = 'pharmaceutical' AND region = 'South America' AND ethical_manufacturing = TRUE;
|
Show the total number of employees and their average salary for each factory in workforce development programs.
|
CREATE TABLE factories (factory_id INT,employees INT,total_salary INT); CREATE TABLE workforce_development (factory_id INT,program TEXT);
|
SELECT factories.factory_id, COUNT(factories.employees) AS total_employees, AVG(factories.total_salary) AS avg_salary FROM factories INNER JOIN workforce_development ON factories.factory_id = workforce_development.factory_id GROUP BY factories.factory_id;
|
What is the total waste produced by the electronics industry in Africa?
|
CREATE TABLE waste (factory_id INT,industry VARCHAR(50),region VARCHAR(50),waste_generated INT);
|
SELECT SUM(waste_generated) FROM waste WHERE industry = 'electronics' AND region = 'Africa';
|
Delete any excavation sites with less than 10 artifacts.
|
CREATE TABLE ExcavationSite (SiteID INT,SiteName TEXT,Country TEXT,NumArtifacts INT); INSERT INTO ExcavationSite (SiteID,SiteName,Country,NumArtifacts) VALUES (1,'Pompeii','Italy',52),(2,'Tutankhamun','Egypt',35),(3,'Machu Picchu','Peru',42),(4,'Tikal','Guatemala',80),(5,'Angkor Wat','Cambodia',5);
|
DELETE FROM ExcavationSite WHERE NumArtifacts < 10;
|
Update the "hospitals" table to correct the address of "Rural Hospital A" from '123 Main St' to '456 Elm St' where the hospital ID is '123'
|
CREATE TABLE hospitals (id INT PRIMARY KEY,name VARCHAR(50),address VARCHAR(100)); INSERT INTO hospitals (id,name,address) VALUES ('123','Rural Hospital A','123 Main St');
|
UPDATE hospitals SET address = '456 Elm St' WHERE id = '123';
|
What is the total healthcare expenditure by rural county in 2022?
|
CREATE TABLE rural_counties (county_id INT,county_name VARCHAR(50),state VARCHAR(2),healthcare_expenditure DECIMAL(10,2)); INSERT INTO rural_counties (county_id,county_name,state,healthcare_expenditure) VALUES (1,'Rural County A','TX',100000),(2,'Rural County B','TX',150000),(3,'Rural County C','CA',120000),(4,'Rural County D','CA',180000);
|
SELECT county_name, SUM(healthcare_expenditure) as total_expenditure FROM rural_counties WHERE state IN ('TX', 'CA') AND YEAR(visit_date) = 2022 GROUP BY county_name;
|
List all investments in the 'renewable_energy' sector and their risk scores, ordered by risk score.
|
CREATE TABLE investments (id INT,name TEXT,sector TEXT,risk_score FLOAT); INSERT INTO investments (id,name,sector,risk_score) VALUES (1,'SolarFarm','renewable_energy',2.1),(2,'WindTurbine','renewable_energy',1.9),(3,'GeoThermal','renewable_energy',2.5);
|
SELECT * FROM investments WHERE sector = 'renewable_energy' ORDER BY risk_score;
|
What are the details of the military technologies that were developed in a specific year, say 2020, from the 'military_tech' table?
|
CREATE TABLE military_tech (id INT,tech_name VARCHAR(255),country VARCHAR(255),tech_date DATE);
|
SELECT * FROM military_tech WHERE YEAR(tech_date) = 2020;
|
List the top 5 albums with the highest number of streams in the "jazz" genre, including the album name and the total number of streams.
|
CREATE TABLE AlbumStreaming(id INT,album VARCHAR(30),genre VARCHAR(10),streams INT);
|
SELECT album, SUM(streams) AS total_streams FROM AlbumStreaming WHERE genre = 'jazz' GROUP BY album ORDER BY total_streams DESC LIMIT 5;
|
Find the top 5 donors by total donation amount in the last 30 days?
|
CREATE TABLE Donations (DonationID int,DonorID int,Program varchar(50),DonationAmount numeric(10,2),DonationDate date); INSERT INTO Donations (DonationID,DonorID,Program,DonationAmount,DonationDate) VALUES (1,1,'ProgramA',500.00,'2022-01-01'),(2,2,'ProgramB',350.00,'2022-02-01'),(3,1,'ProgramA',750.00,'2022-03-01');
|
SELECT DonorID, SUM(DonationAmount) AS TotalDonated FROM Donations WHERE DonationDate >= CURRENT_DATE - INTERVAL '30 days' GROUP BY DonorID ORDER BY TotalDonated DESC LIMIT 5;
|
What is the maximum donation amount received by each program?
|
CREATE TABLE programs (id INT,name VARCHAR(255)); INSERT INTO programs (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donations (id INT,program_id INT,amount DECIMAL(10,2)); INSERT INTO donations (id,program_id,amount) VALUES (1,1,500),(2,1,300),(3,2,800),(4,3,400);
|
SELECT program_id, MAX(amount) OVER (PARTITION BY program_id) AS max_donation_amount FROM donations;
|
What is the total donation amount made in the 'Education' program?
|
CREATE TABLE Programs (ProgramID int,Name varchar(50),Budget money); CREATE TABLE Donations (DonationID int,DonorID int,Amount money,DonationDate date,ProgramID int); INSERT INTO Programs (ProgramID,Name,Budget) VALUES (1,'Education',10000),(2,'Healthcare',15000); INSERT INTO Donations (DonationID,DonorID,Amount,DonationDate,ProgramID) VALUES (5,1,1000,'2022-02-14',1),(6,1,1500,'2022-03-01',1),(7,2,2000,'2022-03-15',2),(8,2,4000,'2022-04-20',2);
|
SELECT SUM(D.Amount) as TotalDonation FROM Donations D WHERE D.ProgramID = (SELECT P.ProgramID FROM Programs P WHERE P.Name = 'Education');
|
Create a view named 'TopTeachers' that selects 'Name' and 'Subject' from 'Teachers' table where 'Subject' is 'Science'
|
CREATE TABLE Teachers (TeacherID INT,Name VARCHAR(100),Subject VARCHAR(50));
|
CREATE VIEW TopTeachers AS SELECT Name, Subject FROM Teachers WHERE Subject = 'Science';
|
Delete all employee records with a salary greater than 80000.
|
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Department,Salary) VALUES (1,'IT',70000.00),(2,'Marketing',55000.00),(3,'Marketing',58000.00),(4,'HR',60000.00),(5,'HR',62000.00),(6,'Diversity & Inclusion',75000.00);
|
DELETE FROM Employees WHERE Salary > 80000;
|
List all the unique countries where we have active oil rigs
|
CREATE TABLE oil_rigs (rig_id INT,country VARCHAR(50),status VARCHAR(50)); INSERT INTO oil_rigs VALUES (1,'USA','active'),(2,'Canada','inactive'),(3,'Mexico','active'),(4,'Brazil','active'),(5,'Norway','active');
|
SELECT DISTINCT country FROM oil_rigs WHERE status = 'active';
|
List all soccer stadiums with a capacity greater than 70,000 and their respective capacities.
|
CREATE TABLE stadiums (stadium_name VARCHAR(100),capacity INT); INSERT INTO stadiums VALUES ('Camp Nou',99354),('Estadio Azteca',87000),('FNB Stadium',94736),('Wembley Stadium',90000),('Santiago Bernabéu',81044);
|
SELECT stadium_name, capacity FROM stadiums WHERE capacity > 70000;
|
Who had the most assists for the Heat in the 2017-2018 season?
|
CREATE TABLE teams (team_name VARCHAR(255),season_start_year INT,season_end_year INT); INSERT INTO teams (team_name,season_start_year,season_end_year) VALUES ('Heat',2017,2018); CREATE TABLE players (player_name VARCHAR(255),team_name VARCHAR(255),assists INT);
|
SELECT player_name, MAX(assists) FROM players WHERE team_name = 'Heat' AND season_start_year = 2017 AND season_end_year = 2018 GROUP BY player_name;
|
What are the names and countries of social enterprises that have been granted funding for technology projects addressing the digital divide in the last 3 years?
|
CREATE TABLE social_enterprises (id INT,name VARCHAR(255),country VARCHAR(255),focus VARCHAR(255)); CREATE TABLE grants (id INT,social_enterprises_id INT,grant_amount FLOAT,grant_date DATE);
|
SELECT social_enterprises.name, social_enterprises.country FROM social_enterprises INNER JOIN grants ON social_enterprises.id = grants.social_enterprises_id WHERE grants.grant_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 3 YEAR) AND social_enterprises.focus = 'Digital Divide';
|
Which cities have hosted conferences on ethical AI?
|
CREATE TABLE conferences (id INT PRIMARY KEY,name VARCHAR(255),city VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO conferences (id,name,city,start_date,end_date) VALUES (1,'Ethical AI Summit','San Francisco','2022-06-01','2022-06-03'); INSERT INTO conferences (id,name,city,start_date,end_date) VALUES (2,'Climate Change Tech Conference','Vancouver','2022-07-01','2022-07-02'); INSERT INTO conferences (id,name,city,start_date,end_date) VALUES (3,'Accessibility in Tech Conference','Toronto','2022-08-01','2022-08-03'); INSERT INTO conferences (id,name,city,start_date,end_date) VALUES (4,'Ethical AI Conference','New York','2022-09-01','2022-09-03'); INSERT INTO conferences (id,name,city,start_date,end_date) VALUES (5,'AI for Social Good Summit','London','2022-10-01','2022-10-03'); CREATE TABLE ethical_ai_topics (id INT PRIMARY KEY,conference_id INT,title VARCHAR(255)); INSERT INTO ethical_ai_topics (id,conference_id,title) VALUES (1,1,'Ethical AI in Healthcare'); INSERT INTO ethical_ai_topics (id,conference_id,title) VALUES (2,4,'Ethical AI for Climate Change'); INSERT INTO ethical_ai_topics (id,conference_id,title) VALUES (3,5,'Ethical AI in Education');
|
SELECT DISTINCT city FROM conferences JOIN ethical_ai_topics ON conferences.id = ethical_ai_topics.conference_id;
|
How many orders were placed by new and returning customers in each month of the year 2021?'
|
CREATE TABLE customer (id INT,first_order_date DATE,last_order_date DATE);
|
INSERT INTO customer (id, first_order_date, last_order_date) SELECT customer_id, MIN(order_date) AS first_order_date, MAX(order_date) AS last_order_date FROM orders GROUP BY customer_id; SELECT YEAR(order_date) AS year, MONTH(order_date) AS month, CASE WHEN DATEDIFF(last_order_date, first_order_date) > 30 THEN 'returning' ELSE 'new' END AS customer_type, COUNT(DISTINCT id) AS num_orders FROM orders JOIN customer ON orders.customer_id = customer.id WHERE YEAR(order_date) = 2021 GROUP BY year, month, customer_type;
|
What is the percentage of factories in each continent that use renewable energy?
|
CREATE TABLE factories (factory_id INT,factory_name VARCHAR(255),continent VARCHAR(255),uses_renewable_energy BOOLEAN);
|
SELECT continent, 100.0 * AVG(CASE WHEN uses_renewable_energy THEN 1.0 ELSE 0.0 END) AS percentage FROM factories GROUP BY continent;
|
Determine the top 3 most discussed topics related to environmental conservation in the social_media schema.
|
CREATE TABLE categories (id INT,name VARCHAR(50)); INSERT INTO categories (id,name) VALUES (1,'climate change'),(2,'renewable energy'),(3,'carbon footprint'),(4,'sustainable development'),(5,'environmental conservation'),(6,'green technology'); CREATE TABLE user_posts (user_id INT,post_id INT,category_id INT);
|
SELECT c.name AS topic, COUNT(up.post_id) AS posts_about_topic FROM user_posts up JOIN categories c ON up.category_id = c.id WHERE c.name LIKE '%environmental conservation%' GROUP BY up.category_id ORDER BY posts_about_topic DESC LIMIT 3;
|
Calculate the average Shariah-compliant loan amount in the Middle East and Africa.
|
CREATE TABLE shariah_compliant_loans (id INT,region VARCHAR(20),amount DECIMAL(10,2)); INSERT INTO shariah_compliant_loans (id,region,amount) VALUES (1,'Middle East',8000.00),(2,'Africa',9000.00),(3,'Europe',7000.00);
|
SELECT AVG(amount) FROM shariah_compliant_loans WHERE region IN ('Middle East', 'Africa');
|
Count the number of Shariah-compliant financial institutions in the Middle East and North Africa.
|
CREATE TABLE if not exists financial_institutions (id INT,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255),is_shariah_compliant BOOLEAN); INSERT INTO financial_institutions (id,name,type,country,is_shariah_compliant) VALUES (1,'Institution A','Bank','UAE',true),(2,'Institution B','Insurance','Egypt',false);
|
SELECT COUNT(*) FROM financial_institutions WHERE is_shariah_compliant = true AND (country = 'Middle East' OR country = 'North Africa');
|
List all programs with a budget over $50,000 and their corresponding program managers.
|
CREATE TABLE programs (id INT,name TEXT,budget FLOAT,manager TEXT); INSERT INTO programs (id,name,budget,manager) VALUES (1,'Education',60000.00,'Alice Johnson'),(2,'Health',40000.00,'Bob Brown');
|
SELECT * FROM programs WHERE budget > 50000;
|
What is the total donation amount by city for the last 6 months?
|
CREATE TABLE Donations (DonationID INT,DonationAmount NUMERIC,City TEXT,DonationDate DATE);
|
SELECT City, SUM(DonationAmount) FROM Donations WHERE DonationDate >= NOW() - INTERVAL '6 months' GROUP BY City;
|
What is the maximum quantity of a single organic product delivered in the DELIVERY_RECORDS table?
|
CREATE TABLE DELIVERY_RECORDS (id INT,supplier_id INT,product_id INT,is_organic BOOLEAN,quantity INT); INSERT INTO DELIVERY_RECORDS (id,supplier_id,product_id,is_organic,quantity) VALUES (1,1,1,true,50),(2,2,2,true,30);
|
SELECT MAX(quantity) FROM DELIVERY_RECORDS WHERE is_organic = true;
|
What is the total amount of funding received by each government department in 2021?
|
CREATE TABLE funding (id INT,department VARCHAR(50),year INT,amount FLOAT); INSERT INTO funding (id,department,year,amount) VALUES (1,'Department A',2021,1000000),(2,'Department B',2021,2000000),(3,'Department A',2022,1500000);
|
SELECT department, SUM(amount) as total_funding FROM funding WHERE year = 2021 GROUP BY department;
|
Update mental health diagnosis records with cultural competency training completion date.
|
CREATE TABLE patient_demographics (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),race VARCHAR(30),ethnicity VARCHAR(30)); INSERT INTO patient_demographics (id,name,age,gender,race,ethnicity) VALUES (1,'John Doe',45,'Male','Caucasian','Non-Hispanic'); CREATE TABLE mental_health_diagnosis (patient_id INT,diagnosis_date DATE,diagnosis VARCHAR(50),prescriber_id INT,training_completion_date DATE); INSERT INTO mental_health_diagnosis (patient_id,diagnosis_date,diagnosis,prescriber_id,training_completion_date) VALUES (1,'2022-01-01','Depression',101,NULL); CREATE TABLE cultural_competency_training (id INT,patient_id INT,training_date DATE); INSERT INTO cultural_competency_training (id,patient_id,training_date) VALUES (1001,1,'2022-03-15');
|
UPDATE mental_health_diagnosis M SET training_completion_date = (SELECT training_date FROM cultural_competency_training C WHERE C.patient_id = M.patient_id LIMIT 1);
|
Find the average revenue per sustainable hotel.
|
CREATE TABLE revenues(hotel_id INT,is_sustainable BOOLEAN,revenue FLOAT); INSERT INTO revenues(hotel_id,is_sustainable,revenue) VALUES (1,true,12000.0),(2,false,10000.0),(3,true,15000.0);
|
SELECT AVG(revenue) FROM revenues WHERE is_sustainable = true;
|
What is the total CO2 emissions in Canada per year?
|
CREATE TABLE CO2Emissions (country VARCHAR(255),year INT,emissions FLOAT); INSERT INTO CO2Emissions (country,year,emissions) VALUES ('Canada',2015,550.0),('Canada',2016,570.0),('Canada',2017,590.0),('Canada',2018,610.0),('Canada',2019,630.0);
|
SELECT year, SUM(emissions) FROM CO2Emissions WHERE country = 'Canada' GROUP BY year;
|
What are the names and languages of all heritage sites?
|
CREATE TABLE heritage_sites (id INT,name VARCHAR(50),country VARCHAR(50),language VARCHAR(50)); INSERT INTO heritage_sites (id,name,country,language) VALUES (1,'Mesa Verde','USA','Navajo'); INSERT INTO heritage_sites (id,name,country,language) VALUES (2,'Galapagos Islands','Ecuador','Spanish');
|
SELECT name, language FROM heritage_sites;
|
Add a record for a depression patient
|
CREATE TABLE patients (id INT PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(50)); CREATE TABLE patient_demographics (id INT PRIMARY KEY,patient_id INT,race VARCHAR(50),ethnicity VARCHAR(50),zip_code VARCHAR(10));
|
INSERT INTO patients (id, name, age, gender) VALUES (1, 'Jane Doe', 35, 'Female'); INSERT INTO patient_demographics (id, patient_id, race, ethnicity, zip_code) VALUES (1, 1, 'White', 'Not Hispanic or Latino', '12345');
|
How many unique patients were treated in Spain in 2020?
|
CREATE SCHEMA mental_health; USE mental_health; CREATE TABLE patients (patient_id INT,diagnosis VARCHAR(50),age INT,country VARCHAR(50)); CREATE TABLE treatments (treatment_id INT,patient_id INT,treatment_type VARCHAR(50),treatment_date DATE,country VARCHAR(50)); INSERT INTO treatments VALUES (5,6,'medication','2020-02-02','Spain');
|
SELECT COUNT(DISTINCT patient_id) FROM treatments JOIN patients ON treatments.patient_id = patients.patient_id WHERE patients.country = 'Spain' AND treatment_date LIKE '2020%';
|
List all dams located in the province of Quebec that have exceeded their maximum design capacity at any point in time.
|
CREATE TABLE dam (id INT,name TEXT,province TEXT,design_capacity FLOAT,max_exceeded INT); INSERT INTO dam (id,name,province,design_capacity,max_exceeded) VALUES (1,'Dam A','Quebec',5000000,1); INSERT INTO dam (id,name,province,design_capacity,max_exceeded) VALUES (2,'Dam B','Quebec',6000000,0);
|
SELECT name FROM dam WHERE province = 'Quebec' AND max_exceeded = 1;
|
How many tourist attractions are there in Japan that have a wheelchair accessibility rating above 4?
|
CREATE TABLE attractions (id INT,name TEXT,country TEXT,wheelchair_accessibility FLOAT); INSERT INTO attractions (id,name,country,wheelchair_accessibility) VALUES (1,'Mt. Fuji','Japan',3.5),(2,'Tokyo Disneyland','Japan',4.7);
|
SELECT COUNT(*) FROM attractions WHERE country = 'Japan' AND wheelchair_accessibility > 4;
|
How many alternative dispute resolution (ADR) programs have been implemented in each justice district from 2010 to 2020?
|
CREATE TABLE ADRPrograms (ID INT,ProgramID VARCHAR(20),District VARCHAR(20),YearEstablished INT,ProgramName VARCHAR(50)); INSERT INTO ADRPrograms (ID,ProgramID,District,YearEstablished,ProgramName) VALUES (1,'ADR001','East River',2012,'ADR for Juveniles'),(2,'ADR002','North Valley',2016,'Community Mediation'),(3,'ADR003','South Peak',2011,'Victim-Offender Dialogue');
|
SELECT District, COUNT(*) FROM ADRPrograms WHERE YearEstablished >= 2010 AND YearEstablished <= 2020 GROUP BY District;
|
Display the maximum legal speed for ships in the Bering Sea.
|
CREATE TABLE maritime_laws (id INT,law VARCHAR(50),region VARCHAR(50),speed_limit INT); INSERT INTO maritime_laws (id,law,region,speed_limit) VALUES (1,'Shipping Speed Regulations','Bering Sea',25);
|
SELECT speed_limit FROM maritime_laws WHERE region = 'Bering Sea';
|
Find the maximum depth of any ocean floor mapping project
|
CREATE TABLE ocean_floor_mapping (project_name VARCHAR(255),max_depth DECIMAL(5,2)); INSERT INTO ocean_floor_mapping (project_name,max_depth) VALUES ('Project A',8000.0),('Project B',7000.0),('Project C',9000.0);
|
SELECT MAX(max_depth) FROM ocean_floor_mapping;
|
How many countries are non-compliant with maritime law in the Caribbean region?
|
CREATE TABLE maritime_law_compliance(country VARCHAR(255),region VARCHAR(255),compliant BOOLEAN);INSERT INTO maritime_law_compliance(country,region,compliant) VALUES ('Cuba','Caribbean',FALSE),('Jamaica','Caribbean',FALSE),('Haiti','Caribbean',TRUE);
|
SELECT COUNT(*) FROM maritime_law_compliance WHERE region = 'Caribbean' AND compliant = FALSE;
|
How many pollution incidents have been recorded in the Atlantic Ocean since 2010?
|
CREATE TABLE Pollution_Incidents (incident_id INTEGER,location TEXT,year INTEGER); INSERT INTO Pollution_Incidents (incident_id,location,year) VALUES (1,'Atlantic Ocean',2012),(2,'Atlantic Ocean',2015);
|
SELECT COUNT(*) FROM Pollution_Incidents WHERE location = 'Atlantic Ocean' AND year >= 2010;
|
How many words are spoken by female and male characters in a movie?
|
CREATE TABLE lines (id INT,movie_id INT,character_id INT,character_gender VARCHAR(10),lines INT);
|
SELECT character_gender, SUM(lines) as total_lines FROM lines WHERE movie_id = 1 GROUP BY character_gender;
|
Which defense projects were not completed in 2021?
|
CREATE TABLE DefenseProjects (id INT PRIMARY KEY,project_name VARCHAR(50),start_date DATE,end_date DATE);
|
SELECT project_name FROM DefenseProjects WHERE end_date > '2021-12-31';
|
Find the number of mines in each location with extraction rates above the overall average.
|
CREATE TABLE mining_sites (id INT,name VARCHAR(50),location VARCHAR(50),extraction_rate DECIMAL(5,2)); INSERT INTO mining_sites (id,name,location,extraction_rate) VALUES (1,'Gold Mine','Colorado',12.5),(2,'Silver Mine','Nevada',15.2),(3,'Copper Mine','Arizona',18.9),(4,'Iron Mine','Minnesota',21.1);
|
SELECT location, COUNT(*) as mine_count FROM mining_sites WHERE extraction_rate > (SELECT AVG(extraction_rate) FROM mining_sites) GROUP BY location;
|
Update the total number of employees in the mining industry who identify as Native Hawaiian or Pacific Islander to 350 in California.
|
CREATE TABLE MiningEmployees (State VARCHAR(50),EmployeeEthnicity VARCHAR(50),EmployeeCount INT); INSERT INTO MiningEmployees(State,EmployeeEthnicity,EmployeeCount) VALUES ('Texas','Native American or Alaska Native',200),('Texas','Hispanic',500),('Texas','Black',300),('California','Native American or Alaska Native',100),('California','Hispanic',700),('California','Black',600);
|
UPDATE MiningEmployees SET EmployeeCount = 350 WHERE State = 'California' AND EmployeeEthnicity = 'Native Hawaiian or Pacific Islander';
|
What is the maximum and minimum number of employees in mining operations in each province of Canada?
|
CREATE TABLE mining_operations (id INT,province VARCHAR(255),num_employees INT); INSERT INTO mining_operations (id,province,num_employees) VALUES (1,'Ontario',500),(2,'Ontario',300),(3,'Quebec',400),(4,'Quebec',600),(5,'British Columbia',700),(6,'British Columbia',800);
|
SELECT province, MAX(num_employees) AS max_employees, MIN(num_employees) AS min_employees FROM mining_operations GROUP BY province;
|
List the total number of subscribers for each technology type in the "subscribers" and "infrastructure" tables.
|
CREATE TABLE subscribers (id INT PRIMARY KEY,name VARCHAR(50),technology VARCHAR(20)); CREATE TABLE infrastructure (tech_type VARCHAR(20) PRIMARY KEY,num_towers INT); INSERT INTO subscribers (id,name,technology) VALUES (1,'Alice','Mobile'),(2,'Bob','Broadband'),(3,'Charlie','Mobile'); INSERT INTO infrastructure (tech_type,num_towers) VALUES ('Mobile',20),('Broadband',15);
|
SELECT i.tech_type, COUNT(s.id) AS num_subscribers FROM subscribers s RIGHT JOIN infrastructure i ON s.technology = i.tech_type GROUP BY i.tech_type;
|
What is the average data usage for mobile subscribers in each region?
|
CREATE TABLE mobile_subscribers (subscriber_id INT,region VARCHAR(50),data_usage INT); INSERT INTO mobile_subscribers (subscriber_id,region,data_usage) VALUES (1,'North',100),(2,'South',150),(3,'East',200),(4,'West',250),(5,'North',50),(6,'South',75),(7,'East',125),(8,'West',175);
|
SELECT region, AVG(data_usage) AS avg_data_usage FROM mobile_subscribers GROUP BY region;
|
What is the average monthly data usage for each mobile network operator?
|
CREATE TABLE mobile_operators (operator_id INT,operator_name VARCHAR(50)); CREATE TABLE mobile_plans (plan_id INT,plan_name VARCHAR(50),operator_id INT,data_limit INT); CREATE TABLE usage (usage_id INT,subscriber_id INT,plan_id INT,usage_amount INT,usage_date DATE);
|
SELECT o.operator_name, AVG(u.usage_amount) AS avg_monthly_data_usage FROM mobile_operators o INNER JOIN mobile_plans p ON o.operator_id = p.operator_id INNER JOIN usage u ON p.plan_id = u.plan_id WHERE u.usage_date >= DATEADD(month, -1, GETDATE()) GROUP BY o.operator_name;
|
What is the monthly spending for a specific broadband customer?
|
CREATE TABLE broadband_customers (customer_id INT,monthly_spending FLOAT); INSERT INTO broadband_customers (customer_id,monthly_spending) VALUES (1,60),(2,70),(3,80); CREATE TABLE customer_data (customer_id INT,customer_name VARCHAR(50)); INSERT INTO customer_data (customer_id,customer_name) VALUES (1,'Rajesh Patel'),(2,'Sophia Garcia'),(3,'Ali Ahmed');
|
SELECT monthly_spending FROM broadband_customers WHERE customer_id = 2;
|
What is the total number of streams for Afrobeats music in Nigeria in Q1 2022?
|
CREATE TABLE UserStreams (StreamID INT,UserID INT,SongID INT,StreamDate DATE); CREATE TABLE Songs (SongID INT,Genre VARCHAR(50),Title VARCHAR(100)); CREATE TABLE UserLocation (UserID INT,Country VARCHAR(100),State VARCHAR(100));
|
SELECT SUM(US.StreamCount) FROM UserStreams US INNER JOIN Songs S ON US.SongID = S.SongID INNER JOIN UserLocation UL ON US.UserID = UL.UserID WHERE S.Genre = 'Afrobeats' AND UL.Country = 'Nigeria' AND QUARTER(US.StreamDate) = 1 AND YEAR(US.StreamDate) = 2022;
|
Insert new records for 3 additional volunteers for the 'Doctors Without Borders' organization.
|
CREATE TABLE organizations (id INT,name TEXT); INSERT INTO organizations (id,name) VALUES (1,'Doctors Without Borders'); CREATE TABLE volunteers (id INT,organization_id INT,name TEXT);
|
INSERT INTO volunteers (id, organization_id, name) VALUES (5, 1, 'Mohammed Ali'), (6, 1, 'Sara Ahmed'), (7, 1, 'Pablo Rodriguez');
|
Which ocean has the maximum number of underwater volcanoes?
|
CREATE TABLE oceans (name TEXT,underwater_volcanoes INT); INSERT INTO oceans (name,underwater_volcanoes) VALUES ('Atlantic',123),('Pacific',456),('Indian',789);
|
SELECT name FROM oceans WHERE underwater_volcanoes = (SELECT MAX(underwater_volcanoes) FROM oceans);
|
What is the total number of hours played in the "Cryptic Explorers" game by players who joined in 2022?
|
CREATE TABLE PlayerJoinDates (PlayerID INT,GameName VARCHAR(20),Playtime FLOAT,JoinDate DATE); INSERT INTO PlayerJoinDates (PlayerID,GameName,Playtime,JoinDate) VALUES (7001,'Cryptic Explorers',150.6,'2022-01-01'),(7002,'Cryptic Explorers',210.8,'2021-12-31'),(7003,'Cryptic Explorers',180.4,'2022-02-15');
|
SELECT SUM(Playtime) FROM PlayerJoinDates WHERE GameName = 'Cryptic Explorers' AND YEAR(JoinDate) = 2022;
|
Show the average soil moisture level for each field in the past week
|
CREATE TABLE field (id INT,name VARCHAR(255),farm_id INT);CREATE TABLE soil_moisture (id INT,field_id INT,measurement DATE,level INT);
|
SELECT field_id, AVG(level) FROM soil_moisture WHERE measurement >= DATEADD(day, -7, GETDATE()) GROUP BY field_id;
|
What is the minimum temperature recorded in 'Greenhouse7' for the month of September?
|
CREATE TABLE Greenhouse7 (date DATE,temperature FLOAT);
|
SELECT MIN(temperature) FROM Greenhouse7 WHERE EXTRACT(MONTH FROM date) = 9;
|
Find the number of Lutetium transactions with prices over 70 dollars in European countries.
|
CREATE TABLE lutetium_transactions (country VARCHAR(20),element VARCHAR(20),price DECIMAL(5,2),transaction_date DATE); INSERT INTO lutetium_transactions (country,element,price,transaction_date) VALUES ('France','Lutetium',80,'2020-01-01'),('Germany','Lutetium',65,'2020-02-01'),('France','Lutetium',75,'2020-03-01');
|
SELECT COUNT(*) FROM lutetium_transactions WHERE country IN ('France', 'Germany') AND element = 'Lutetium' AND price > 70;
|
What is the average carbon footprint of products manufactured in each region?
|
CREATE TABLE regions (id INT,name TEXT); CREATE TABLE manufacturers (id INT,name TEXT,region_id INT,carbon_footprint INT); INSERT INTO regions (id,name) VALUES (1,'Region 1'),(2,'Region 2'),(3,'Region 3'); INSERT INTO manufacturers (id,name,region_id,carbon_footprint) VALUES (1,'Manufacturer 1',1,50),(2,'Manufacturer 2',2,70),(3,'Manufacturer 3',3,30),(4,'Manufacturer 4',1,60),(5,'Manufacturer 5',2,40);
|
SELECT regions.name, AVG(manufacturers.carbon_footprint) FROM regions INNER JOIN manufacturers ON regions.id = manufacturers.region_id GROUP BY regions.name;
|
What is the minimum price of items in the 'Grocery' category sold by stores in 'New York'?
|
CREATE TABLE Stores (StoreID int,StoreName varchar(50),Address varchar(100),Country varchar(50),State varchar(50)); INSERT INTO Stores VALUES (1,'Store1','123 Main St,New York','USA','New York'); INSERT INTO Stores VALUES (2,'Store2','456 Oak St,California','USA','California'); INSERT INTO Stores VALUES (3,'Store3','789 Elm St,Texas','USA','Texas'); CREATE TABLE Products (ProductID int,ProductName varchar(50),StoreID int,Category varchar(50),Price int); INSERT INTO Products VALUES (1,'Product1',1,'Grocery',50); INSERT INTO Products VALUES (2,'Product2',1,'Fashion',100); INSERT INTO Products VALUES (3,'Product3',2,'Grocery',70); INSERT INTO Products VALUES (4,'Product4',2,'Electronics',150); INSERT INTO Products VALUES (5,'Product5',3,'Grocery',40); INSERT INTO Products VALUES (6,'Product6',3,'Fashion',80);
|
SELECT MIN(Products.Price) FROM Products INNER JOIN Stores ON Products.StoreID = Stores.StoreID WHERE Products.Category = 'Grocery' AND Stores.State = 'New York';
|
What is the total quantity of products sold by small businesses?
|
CREATE TABLE sales (sale_id INT,business_size VARCHAR(20),quantity INT); INSERT INTO sales (sale_id,business_size,quantity) VALUES (1,'small',100),(2,'medium',200),(3,'small',150),(4,'large',300);
|
SELECT SUM(quantity) FROM sales WHERE business_size = 'small';
|
How many countries have space agencies?
|
CREATE TABLE space_agencies (id INT,country TEXT); INSERT INTO space_agencies (id,country) VALUES (1,'USA'),(2,'China'),(3,'Russia'),(4,'India'),(5,'Japan'),(6,'Germany'),(7,'Italy'),(8,'France'),(9,'Canada'),(10,'UK'),(11,'Brazil'),(12,'South Korea'),(13,'Australia'),(14,'Spain'),(15,'Israel');
|
SELECT COUNT(*) FROM space_agencies;
|
What are the names and launch dates of all space missions launched by Russia?
|
CREATE TABLE missions (id INT,mission_name VARCHAR(50),launch_date DATE,country VARCHAR(50)); INSERT INTO missions (id,mission_name,launch_date,country) VALUES (2,'Sputnik 1','1957-10-04','Russia');
|
SELECT mission_name, launch_date FROM missions WHERE country = 'Russia';
|
What is the total number of space missions conducted by each country in the SpaceMissions table?
|
CREATE TABLE SpaceMissions (id INT,mission VARCHAR(50),year INT,country VARCHAR(50)); INSERT INTO SpaceMissions (id,mission,year,country) VALUES (1,'Apollo 11',1969,'USA'),(2,'Apollo 13',1970,'USA'),(3,'STS-1',1981,'USA'),(4,'Shenzhou 5',2003,'China');
|
SELECT country, COUNT(*) AS num_missions FROM SpaceMissions GROUP BY country;
|
How many space missions have been carried out by NASA?
|
CREATE TABLE Missions (agency VARCHAR(20),name VARCHAR(30)); INSERT INTO Missions (agency,name) VALUES ('NASA','Apollo 11'),('NASA','Apollo 13');
|
SELECT COUNT(*) FROM Missions WHERE agency = 'NASA';
|
Insert new fan records from the 'new_fans' staging table into the 'fans' table
|
CREATE TABLE new_fans (fan_id INT,age INT,gender VARCHAR(10),country VARCHAR(50)); CREATE TABLE fans (fan_id INT PRIMARY KEY,age INT,gender VARCHAR(10),country VARCHAR(50));
|
INSERT INTO fans (fan_id, age, gender, country) SELECT fan_id, age, gender, country FROM new_fans;
|
Which teams have the highest and lowest total ticket sales, excluding complimentary tickets?
|
CREATE TABLE team_performance (team_id INT,home_game BOOLEAN,total_sales DECIMAL(10,2)); INSERT INTO team_performance (team_id,home_game,total_sales) VALUES (1,true,5000.00),(1,false,0.00),(2,true,7000.00),(2,false,3000.00),(3,true,3000.00),(3,false,1000.00);
|
SELECT team_id, SUM(total_sales) FROM team_performance WHERE home_game = true AND total_sales > 0 GROUP BY team_id ORDER BY SUM(total_sales) DESC, team_id;
|
What is the total number of security incidents recorded in '2022'?
|
CREATE TABLE security_incidents (id INT,incident_date DATE); INSERT INTO security_incidents (id,incident_date) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2021-12-31');
|
SELECT COUNT(*) FROM security_incidents WHERE incident_date BETWEEN '2022-01-01' AND '2022-12-31';
|
How many policies of each type were sold in Q1 of 2022?
|
CREATE TABLE Policies (PolicyID int,PolicyType varchar(20),SaleDate date); INSERT INTO Policies (PolicyID,PolicyType,SaleDate) VALUES (1,'Auto','2022-01-05'),(2,'Home','2022-03-10'),(3,'Auto','2022-01-15');
|
SELECT PolicyType, COUNT(*) OVER (PARTITION BY PolicyType) as PolicyCount FROM Policies WHERE SaleDate >= '2022-01-01' AND SaleDate < '2022-04-01';
|
What is the total number of labor rights violations for unions in the construction sector, ordered by the number of violations in descending order?
|
CREATE TABLE union_construction (union_id INT,union_name TEXT,sector TEXT,violations INT); INSERT INTO union_construction (union_id,union_name,sector,violations) VALUES (1,'Union P','Construction',30),(2,'Union Q','Construction',40),(3,'Union R','Construction',25);
|
SELECT sector, SUM(violations) as total_violations FROM union_construction WHERE sector = 'Construction' GROUP BY sector ORDER BY total_violations DESC;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.