instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total number of streams for all songs released in 2020?
|
CREATE TABLE Songs (id INT,title VARCHAR(100),release_year INT,genre VARCHAR(50),streams INT);
|
SELECT SUM(streams) FROM Songs WHERE release_year = 2020;
|
Find the autonomous driving research projects that are jointly conducted by companies from the USA and China.
|
CREATE TABLE AutonomousResearch (project VARCHAR(20),company1 VARCHAR(20),company2 VARCHAR(20)); INSERT INTO AutonomousResearch (project,company1,company2) VALUES ('Tesla Autopilot','Tesla','N/A'); INSERT INTO AutonomousResearch (project,company1,company2) VALUES ('Baidu Apollo','Baidu','N/A');
|
SELECT project FROM AutonomousResearch WHERE (company1 = 'Tesla' AND company2 = 'Baidu') OR (company1 = 'Baidu' AND company2 = 'Tesla');
|
Identify the soccer stadium with the largest capacity
|
CREATE TABLE stadiums (id INT,name VARCHAR(50),sport VARCHAR(20),capacity INT);
|
SELECT name FROM stadiums WHERE sport = 'Soccer' ORDER BY capacity DESC LIMIT 1;
|
How many building permits were issued in Los Angeles County in the last 6 months?
|
CREATE TABLE building_permits (id INT,permit_number VARCHAR(50),issue_date DATE,county VARCHAR(50));
|
SELECT COUNT(*) FROM building_permits WHERE county = 'Los Angeles County' AND issue_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH)
|
What is the most common infectious disease in South America?
|
CREATE TABLE Diseases (ID INT,Country VARCHAR(50),Continent VARCHAR(50),Disease VARCHAR(50),Count INT); INSERT INTO Diseases (ID,Country,Continent,Disease,Count) VALUES (1,'Brazil','South America','Malaria',200000);
|
SELECT Disease, MAX(Count) FROM Diseases WHERE Continent = 'South America';
|
What is the average funding for biotech startups in India?
|
CREATE SCHEMA if not exists biotech; USE biotech; CREATE TABLE if not exists startup_funding (id INT PRIMARY KEY,company_name VARCHAR(255),location VARCHAR(255),funding_amount FLOAT); INSERT INTO startup_funding (id,company_name,location,funding_amount) VALUES (1,'BioVeda','India',2500000.00),(2,'Genesys','India',3000000.00),(3,'InnoLife','USA',5000000.00);
|
SELECT AVG(funding_amount) FROM biotech.startup_funding WHERE location = 'India';
|
What is the distribution of digital divide initiatives across global regions?
|
CREATE TABLE digital_divide_initiatives (initiative_name VARCHAR(100),region VARCHAR(50)); INSERT INTO digital_divide_initiatives (initiative_name,region) VALUES ('DigitalEquality Asia','Asia'),('TechInclusion Africa','Africa'),('AccessibleTech Europe','Europe');
|
SELECT region, COUNT(initiative_name), 100.0*COUNT(initiative_name)/(SELECT COUNT(*) FROM digital_divide_initiatives) AS percentage FROM digital_divide_initiatives GROUP BY region;
|
How many soccer games were won by teams in the soccer_league table that have a female coach?
|
CREATE TABLE soccer_league (game_id INT,team_name VARCHAR(50),coach_gender VARCHAR(10)); CREATE VIEW soccer_league_won AS SELECT game_id,team_name FROM soccer_league WHERE result = 'win';
|
SELECT COUNT(*) FROM soccer_league_won JOIN soccer_league ON soccer_league_won.team_name = soccer_league.team_name WHERE coach_gender = 'female';
|
Which countries have participated in the most humanitarian assistance missions?
|
CREATE TABLE humanitarian_missions (id INT,country VARCHAR,mission_count INT);
|
SELECT country, MAX(mission_count) FROM humanitarian_missions GROUP BY country ORDER BY MAX(mission_count) DESC;
|
How many cases were opened in each month of 2022?
|
CREATE TABLE CaseDates (CaseID INT,Date DATE); INSERT INTO CaseDates (CaseID,Date) VALUES (1,'2022-01-01'),(2,'2022-02-01');
|
SELECT DATE_FORMAT(CaseDates.Date, '%Y-%m') AS Month, COUNT(*) AS Cases FROM CaseDates GROUP BY Month;
|
Delete 'players' records where the 'country' is 'Brazil'
|
CREATE TABLE players (id INT,name VARCHAR(50),country VARCHAR(50),level INT);
|
DELETE FROM players WHERE country = 'Brazil';
|
What is the total quantity of chemicals produced by manufacturer 'X'?
|
CREATE TABLE production_rates (rate_id INT,manufacturer VARCHAR(20),production_rate INT,measurement_date DATE); INSERT INTO production_rates (rate_id,manufacturer,production_rate,measurement_date) VALUES (1,'X',500,'2021-01-01'),(2,'Y',700,'2021-01-02'),(3,'X',600,'2021-01-01');
|
SELECT SUM(production_rate) FROM production_rates WHERE manufacturer = 'X';
|
What is the immunization rate for Measles in North America?
|
CREATE TABLE Immunization_NA (Disease VARCHAR(50),Continent VARCHAR(50),Immunization_Rate FLOAT); INSERT INTO Immunization_NA (Disease,Continent,Immunization_Rate) VALUES ('Measles','North America',92.0);
|
SELECT Immunization_Rate FROM Immunization_NA WHERE Disease = 'Measles' AND Continent = 'North America';
|
Identify the top 3 streaming artists by total number of streams in the 'Hip Hop' genre, excluding artist 'ArtistC'?
|
CREATE TABLE Streams (StreamID INT,UserID INT,ArtistID INT,Genre VARCHAR(10)); INSERT INTO Streams (StreamID,UserID,ArtistID,Genre) VALUES (1,101,1,'Hip Hop'),(2,101,2,'Hip Hop'),(3,102,3,'Jazz'),(4,102,4,'Pop'),(5,103,1,'Hip Hop'),(6,103,3,'Jazz');
|
SELECT ArtistID, SUM(1) AS TotalStreams FROM Streams WHERE Genre = 'Hip Hop' AND ArtistID != 3 GROUP BY ArtistID ORDER BY TotalStreams DESC LIMIT 3;
|
Identify the artifact type with the highest average weight for each country, along with the country and average weight.
|
CREATE TABLE Artifacts (ArtifactID INT,ArtifactType VARCHAR(50),ArtifactWeight FLOAT,Country VARCHAR(50)); INSERT INTO Artifacts (ArtifactID,ArtifactType,ArtifactWeight,Country) VALUES (1,'Pottery',2.3,'USA'),(2,'Stone Tool',1.8,'Mexico'),(3,'Bone Tool',3.1,'USA'),(4,'Ceramic Figurine',4.7,'Canada'),(5,'Metal Artifact',5.9,'Canada');
|
SELECT Country, ArtifactType, AVG(ArtifactWeight) AS AvgWeight FROM Artifacts GROUP BY Country, ArtifactType HAVING COUNT(*) = (SELECT COUNT(*) FROM Artifacts GROUP BY ArtifactType HAVING COUNT(*) = (SELECT COUNT(*) FROM Artifacts GROUP BY Country, ArtifactType));
|
List the union names and their membership statistics that are located in the 'north_region'?
|
CREATE TABLE union_names (union_name TEXT); INSERT INTO union_names (union_name) VALUES ('Union A'),('Union B'),('Union C'),('Union D'); CREATE TABLE membership_stats (union_name TEXT,region TEXT,members INTEGER); INSERT INTO membership_stats (union_name,region,members) VALUES ('Union A','north_region',4000),('Union B','south_region',2000),('Union C','north_region',6000),('Union D','north_region',500);
|
SELECT union_names.union_name, membership_stats.members FROM union_names INNER JOIN membership_stats ON union_names.union_name = membership_stats.union_name WHERE membership_stats.region = 'north_region';
|
What are the total costs of security incidents for each department in the last 6 months, sorted from highest to lowest?
|
CREATE TABLE security_incidents (id INT,department VARCHAR(20),cost DECIMAL(10,2),incident_time TIMESTAMP);
|
SELECT department, SUM(cost) as total_cost FROM security_incidents WHERE incident_time >= NOW() - INTERVAL 6 MONTH GROUP BY department ORDER BY total_cost DESC;
|
Delete the records of community health workers who do not have any mental health parity training.
|
CREATE TABLE CommunityHealthWorkers (WorkerID INT,Name VARCHAR(50),Specialty VARCHAR(50),MentalHealthParity BOOLEAN); INSERT INTO CommunityHealthWorkers (WorkerID,Name,Specialty,MentalHealthParity) VALUES (1,'John Doe','Mental Health',TRUE); INSERT INTO CommunityHealthWorkers (WorkerID,Name,Specialty,MentalHealthParity) VALUES (2,'Jane Smith','Physical Health',FALSE);
|
DELETE FROM CommunityHealthWorkers WHERE MentalHealthParity = FALSE;
|
What is the maximum lifelong learning score of a student in 'Summer 2022'?
|
CREATE TABLE lifelong_learning (student_id INT,learning_score INT,date DATE); INSERT INTO lifelong_learning (student_id,learning_score,date) VALUES (1,90,'2022-06-01'),(2,95,'2022-06-02'),(3,80,'2022-06-03');
|
SELECT MAX(learning_score) FROM lifelong_learning WHERE date = '2022-06-01';
|
What are the names of all spacecraft that were launched after the first manned spaceflight by a non-US agency?
|
CREATE TABLE Spacecraft (id INT,name VARCHAR(50),manufacturer VARCHAR(50),launch_date DATE); INSERT INTO Spacecraft (id,name,manufacturer,launch_date) VALUES (1,'Vostok 1','Roscosmos','1961-04-12'),(2,'Mercury-Redstone 3','NASA','1961-05-05'),(3,'Sputnik 1','Roscosmos','1957-10-04');
|
SELECT s.name FROM Spacecraft s WHERE s.launch_date > (SELECT launch_date FROM Spacecraft WHERE name = 'Vostok 1');
|
What is the average number of military personnel per base in the Middle East?
|
CREATE TABLE military_bases (id INT,name VARCHAR(255),type VARCHAR(255),region VARCHAR(255),personnel INT); INSERT INTO military_bases (id,name,type,region,personnel) VALUES (1,'Base 1','Air Force','Middle East',1000),(2,'Base 2','Navy','Middle East',2000);
|
SELECT AVG(personnel) FROM military_bases WHERE region = 'Middle East';
|
Delete diversity metrics for 2020 from the database.
|
CREATE TABLE Diversity (Company VARCHAR(50),Year INT,DiverseEmployees INT); INSERT INTO Diversity (Company,Year,DiverseEmployees) VALUES ('Acme Inc.',2018,50),('Acme Inc.',2019,75),('Acme Inc.',2020,85),('Beta Corp.',2018,30),('Beta Corp.',2019,35),('Beta Corp.',2020,40);
|
DELETE FROM Diversity WHERE Year = 2020;
|
What is the total area (in hectares) of land used for agricultural innovation projects, categorized by project type, for the year 2020 in the Asia region?
|
CREATE TABLE agricultural_projects (id INT,project_type VARCHAR(255),location VARCHAR(255),area_ha FLOAT,year INT); INSERT INTO agricultural_projects (id,project_type,location,area_ha,year) VALUES (1,'Precision Farming','Asia',500,2020),(2,'Organic Farming','Asia',300,2020),(3,'Agroforestry','Asia',700,2020);
|
SELECT project_type, SUM(area_ha) as total_area_ha FROM agricultural_projects WHERE location = 'Asia' AND year = 2020 GROUP BY project_type;
|
List all sustainable material types and their respective total quantities used across all factories.
|
CREATE TABLE materials (material_id INT,name VARCHAR(255),is_sustainable BOOLEAN); INSERT INTO materials VALUES (1,'Organic Cotton',true); INSERT INTO materials VALUES (2,'Recycled Polyester',true); INSERT INTO materials VALUES (3,'Conventional Cotton',false); CREATE TABLE inventory (inventory_id INT,material_id INT,factory_id INT,quantity INT); INSERT INTO inventory VALUES (1,1,1,2000); INSERT INTO inventory VALUES (2,2,2,3000); INSERT INTO inventory VALUES (3,3,1,1500);
|
SELECT materials.name, SUM(inventory.quantity) FROM materials JOIN inventory ON materials.material_id = inventory.material_id WHERE materials.is_sustainable = true GROUP BY materials.name;
|
What is the average program impact score for program C?
|
CREATE TABLE programs (program TEXT,impact_score DECIMAL); INSERT INTO programs (program,impact_score) VALUES ('Program C',4.2),('Program D',3.5);
|
SELECT AVG(impact_score) FROM programs WHERE program = 'Program C';
|
How many walruses are in the Arctic Ocean?
|
CREATE TABLE Animals (name VARCHAR(50),species VARCHAR(50),location VARCHAR(50)); INSERT INTO Animals (name,species,location) VALUES ('Seal 1','Seal','Arctic Ocean'),('Seal 2','Seal','Arctic Ocean'),('Walrus 1','Walrus','Arctic Ocean');
|
SELECT COUNT(*) FROM Animals WHERE species = 'Walrus' AND location = 'Arctic Ocean';
|
What is the average runtime of Korean movies produced between 2015 and 2018?
|
CREATE TABLE movies (id INT,title TEXT,country TEXT,year INT,runtime INT); INSERT INTO movies (id,title,country,year,runtime) VALUES (1,'MovieA','Korea',2015,120),(2,'MovieB','Korea',2016,105),(3,'MovieC','USA',2017,90);
|
SELECT AVG(runtime) FROM movies WHERE country = 'Korea' AND year BETWEEN 2015 AND 2018;
|
List the top 5 mental health conditions by number of patients treated in the treatment_history table.
|
CREATE TABLE treatment_history (patient_id INT,treatment_date DATE,treatment_type VARCHAR(255),facility_id INT,facility_name VARCHAR(255),facility_location VARCHAR(255)); CREATE TABLE treatment_codes (treatment_code INT,treatment_type VARCHAR(255)); CREATE TABLE patients (patient_id INT,first_name VARCHAR(255),last_name VARCHAR(255),age INT,gender VARCHAR(255),address VARCHAR(255),phone_number VARCHAR(255),email VARCHAR(255));
|
SELECT th.treatment_type, COUNT(DISTINCT th.patient_id) as patient_count FROM treatment_history th JOIN treatment_codes tc ON th.treatment_type = tc.treatment_code GROUP BY th.treatment_type ORDER BY patient_count DESC LIMIT 5;
|
What is the total amount donated by first-time donors from Australia in 2019?
|
CREATE TABLE donations (id INT,donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); CREATE TABLE donors (id INT,is_first_time_donor BOOLEAN,country VARCHAR(50)); INSERT INTO donations (id,donor_id,donation_amount,donation_date) VALUES (1,1,100.00,'2019-04-15'); INSERT INTO donors (id,is_first_time_donor,country) VALUES (1,true,'Australia');
|
SELECT SUM(donation_amount) FROM donations JOIN donors ON donations.donor_id = donors.id WHERE donors.country = 'Australia' AND donors.is_first_time_donor = true AND YEAR(donation_date) = 2019;
|
What was the average number of visitors per exhibition in each city?
|
CREATE TABLE City_Exhibitions (id INT,city VARCHAR(20),num_exhibitions INT); INSERT INTO City_Exhibitions (id,city,num_exhibitions) VALUES (1,'New York',5),(2,'Chicago',3),(3,'Miami',4); CREATE TABLE Exhibition_Visitors (id INT,exhibition VARCHAR(20),city VARCHAR(20),num_visitors INT); INSERT INTO Exhibition_Visitors (id,exhibition,city,num_visitors) VALUES (1,'Art of the 90s','New York',2000),(2,'Science of Space','Chicago',1500),(3,'Art of the 90s','New York',2500),(4,'History of Technology','Miami',1000);
|
SELECT ce.city, AVG(ev.num_visitors) AS avg_visitors_per_exhibition FROM City_Exhibitions ce JOIN Exhibition_Visitors ev ON ce.city = ev.city GROUP BY ce.city;
|
What is the minimum depth in the Pacific Ocean?
|
CREATE TABLE ocean_depths (ocean TEXT,depth FLOAT); INSERT INTO ocean_depths (ocean,depth) VALUES ('Pacific Ocean',10994.0);
|
SELECT MIN(depth) FROM ocean_depths WHERE ocean = 'Pacific Ocean';
|
Calculate the number of volunteers and total volunteer hours for each program
|
CREATE TABLE programs (id INT,name VARCHAR,budget DECIMAL); CREATE TABLE volunteers (id INT,name VARCHAR,email VARCHAR,phone VARCHAR); CREATE TABLE volunteer_assignments (id INT,volunteer_id INT,program_id INT,hours DECIMAL);
|
SELECT programs.name, COUNT(DISTINCT volunteers.id) as num_volunteers, SUM(volunteer_assignments.hours) as total_volunteer_hours FROM programs JOIN volunteer_assignments ON programs.id = volunteer_assignments.program_id JOIN volunteers ON volunteer_assignments.volunteer_id = volunteers.id GROUP BY programs.id;
|
Get the 'product_name' and 'country' for 'product_transparency' records with a circular supply chain.
|
CREATE TABLE product_transparency (product_id INT,product_name VARCHAR(50),circular_supply_chain BOOLEAN,recycled_content DECIMAL(4,2),COUNTRY VARCHAR(50));
|
SELECT product_name, country FROM product_transparency WHERE circular_supply_chain = TRUE;
|
What is the weight of the lightest package on route 'R01'?
|
CREATE TABLE packages (id INT,route_id VARCHAR(5),weight DECIMAL(5,2)); INSERT INTO packages (id,route_id,weight) VALUES (100,'R01',12.3),(101,'R02',15.6),(102,'R03',8.8),(103,'R04',20.1),(104,'R04',18.5),(105,'R01',10.0);
|
SELECT MIN(weight) FROM packages WHERE route_id = 'R01';
|
Find the number of socially responsible lending institutions in North America that do not have any outstanding loans.
|
CREATE TABLE Institutions (InstitutionID INT,InstitutionName VARCHAR(100),Region VARCHAR(50)); INSERT INTO Institutions (InstitutionID,InstitutionName,Region) VALUES (1,'XYZ Microfinance','North America'),(2,'CDE Credit Union','North America'); CREATE TABLE Loans (LoanID INT,InstitutionID INT,Amount DECIMAL(10,2),Outstanding BOOLEAN); INSERT INTO Loans (LoanID,InstitutionID,Amount,Outstanding) VALUES (1,1,5000,TRUE),(2,2,0,FALSE);
|
SELECT COUNT(DISTINCT Institutions.InstitutionID) FROM Institutions LEFT JOIN Loans ON Institutions.InstitutionID = Loans.InstitutionID WHERE Loans.LoanID IS NULL AND Institutions.Region = 'North America';
|
What is the name, security level, and age of inmates who are 30 or older in the prison table?
|
CREATE TABLE prison (id INT,name TEXT,security_level TEXT,age INT); INSERT INTO prison (id,name,security_level,age) VALUES (1,'John Doe','low_security',35); INSERT INTO prison (id,name,security_level,age) VALUES (2,'Jane Smith','medium_security',55);
|
SELECT name, security_level, age FROM prison WHERE age >= 30;
|
Delete menu items that were not sold in any restaurant in the state of California during the month of August 2021.
|
CREATE TABLE Restaurants (RestaurantID int,Name varchar(50),Location varchar(50)); CREATE TABLE Menu (MenuID int,ItemName varchar(50),Category varchar(50)); CREATE TABLE MenuSales (MenuID int,RestaurantID int,QuantitySold int,Revenue decimal(5,2),SaleDate date);
|
DELETE M FROM Menu M LEFT JOIN MenuSales MS ON M.MenuID = MS.MenuID WHERE MS.MenuID IS NULL AND M.Location LIKE '%California%' AND MS.SaleDate >= '2021-08-01' AND MS.SaleDate <= '2021-08-31';
|
What is the average loan amount for socially responsible lending in the European Union?
|
CREATE TABLE socially_responsible_lending_3 (id INT,country VARCHAR(20),loan_amount DECIMAL(10,2)); INSERT INTO socially_responsible_lending_3 (id,country,loan_amount) VALUES (1,'France',600.00),(2,'Germany',550.00),(3,'Italy',500.00);
|
SELECT AVG(loan_amount) FROM socially_responsible_lending_3 WHERE country IN ('France', 'Germany', 'Italy');
|
Which defense projects have experienced delays of over 6 months since their original timeline?
|
CREATE TABLE defense_projects (project_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO defense_projects (project_name,start_date,end_date) VALUES ('Joint Light Tactical Vehicle','2016-01-01','2020-12-31'),('Ground Combat Vehicle','2015-01-01','2024-12-31');
|
SELECT project_name FROM defense_projects WHERE DATEDIFF(end_date, start_date) > 180;
|
Show the number of dams in each state
|
CREATE TABLE Dams (id INT,state VARCHAR(50)); INSERT INTO Dams (id,state) VALUES (1,'California'),(2,'Texas');
|
SELECT state, COUNT(*) FROM Dams GROUP BY state;
|
Which galleries have 'Water Lilies' on display?
|
CREATE TABLE Artworks (ArtworkID INT,Title VARCHAR(50),Gallery VARCHAR(50)); INSERT INTO Artworks (ArtworkID,Title,Gallery) VALUES (1,'Starry Night','ImpressionistGallery'); INSERT INTO Artworks (ArtworkID,Title,Gallery) VALUES (2,'Sunflowers','ImpressionistGallery'); INSERT INTO Artworks (ArtworkID,Title,Gallery) VALUES (3,'Water Lilies','ImpressionistGallery'); INSERT INTO Artworks (ArtworkID,Title,Gallery) VALUES (4,'Water Lilies','ModernArt');
|
SELECT DISTINCT Gallery FROM Artworks WHERE Title = 'Water Lilies';
|
What is the minimum energy efficiency rating for commercial buildings in Canada?
|
CREATE TABLE canada_energy_efficiency (province VARCHAR(50),building_type VARCHAR(50),energy_efficiency_rating FLOAT); INSERT INTO canada_energy_efficiency (province,building_type,energy_efficiency_rating) VALUES ('Ontario','Commercial',75.5),('Quebec','Commercial',72.3),('Alberta','Commercial',78.1);
|
SELECT MIN(energy_efficiency_rating) FROM canada_energy_efficiency WHERE building_type = 'Commercial';
|
What are the names of the virtual reality devices used by the most players?
|
CREATE TABLE VirtualReality (VRID INT PRIMARY KEY,VRName VARCHAR(50),PlayersUsing INT); INSERT INTO VirtualReality (VRID,VRName,PlayersUsing) VALUES (3,'PlayStation VR',80000); INSERT INTO VirtualReality (VRID,VRName,PlayersUsing) VALUES (5,'Valve Index',60000);
|
SELECT VRName, PlayersUsing FROM VirtualReality ORDER BY PlayersUsing DESC LIMIT 1;
|
List the number of recalls for vehicles produced in the last 5 years with a safety issue.
|
CREATE TABLE recalls (recall_id INT,recall_number INT,recall_date DATE,vehicle_id INT,safety_issue BOOLEAN); CREATE TABLE vehicles (vehicle_id INT,manufacture VARCHAR(20),year_produced INT,vehicle_type VARCHAR(20));
|
SELECT COUNT(*) FROM recalls r JOIN vehicles v ON r.vehicle_id = v.vehicle_id WHERE safety_issue = TRUE AND v.year_produced >= YEAR(DATEADD(year, -5, GETDATE()));
|
Delete all records in the loans table where the status is 'declined'
|
CREATE TABLE loans (loan_number INT,amount DECIMAL(10,2),status VARCHAR(10),created_at TIMESTAMP);
|
DELETE FROM loans WHERE status = 'declined';
|
What is the total water usage by each province in Canada?
|
CREATE TABLE provinces (province VARCHAR(255),water_usage INT); INSERT INTO provinces (province,water_usage) VALUES ('Alberta',1200),('British Columbia',1500),('Manitoba',800);
|
SELECT province, SUM(water_usage) FROM provinces GROUP BY province;
|
How many creative AI applications have been developed for the healthcare industry?
|
CREATE TABLE CreativeAIs (Id INT,Industry VARCHAR(50),Application VARCHAR(50)); INSERT INTO CreativeAIs (Id,Industry,Application) VALUES (1,'Healthcare','Medical Diagnosis'),(2,'Education','Tutoring System'),(3,'Finance','Fraud Detection');
|
SELECT COUNT(*) FROM CreativeAIs WHERE Industry = 'Healthcare';
|
What are the total sales figures for a specific drug, including sales from both direct and indirect channels, for the year 2020 in the United States?
|
CREATE TABLE sales_data (id INT,drug_name VARCHAR(255),sale_channel VARCHAR(255),sale_amount DECIMAL(10,2),sale_date DATE); INSERT INTO sales_data (id,drug_name,sale_channel,sale_amount,sale_date) VALUES (1,'DrugA','Direct',10000,'2020-01-01'); INSERT INTO sales_data (id,drug_name,sale_channel,sale_amount,sale_date) VALUES (2,'DrugA','Indirect',15000,'2020-01-01');
|
SELECT SUM(sale_amount) FROM sales_data WHERE drug_name = 'DrugA' AND YEAR(sale_date) = 2020 AND (sale_channel = 'Direct' OR sale_channel = 'Indirect');
|
Add a new attorney named 'Alex' to the 'attorneys' table
|
CREATE TABLE attorneys (attorney_id INT PRIMARY KEY,attorney_name VARCHAR(50),experience INT,area_of_practice VARCHAR(50));
|
INSERT INTO attorneys (attorney_id, attorney_name, experience, area_of_practice) VALUES (4, 'Alex', 7, 'Civil Rights');
|
How many bridges are in the transport division?
|
CREATE TABLE Projects (id INT,division VARCHAR(10)); INSERT INTO Projects (id,division) VALUES (1,'water'),(2,'transport'),(3,'energy'); CREATE TABLE TransportProjects (id INT,project_id INT,length DECIMAL(10,2)); INSERT INTO TransportProjects (id,project_id,length) VALUES (1,2,500),(2,2,550),(3,3,600);
|
SELECT COUNT(*) FROM TransportProjects tp JOIN Projects p ON tp.project_id = p.id WHERE p.division = 'transport';
|
What is the percentage of healthcare facilities in rural areas of Texas that have a pharmacy on-site?
|
CREATE TABLE healthcare_facilities (id INT,name VARCHAR(100),location VARCHAR(50),has_pharmacy BOOLEAN); INSERT INTO healthcare_facilities (id,name,location,has_pharmacy) VALUES (1,'Rural Clinic','Texas',TRUE);
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM healthcare_facilities WHERE healthcare_facilities.location LIKE '%rural%')) AS percentage FROM healthcare_facilities WHERE healthcare_facilities.location LIKE '%Texas' AND healthcare_facilities.has_pharmacy = TRUE;
|
What is the total amount donated by each donor in the first quarter of 2021, and the number of donations made in that time period, broken down by the donor's country of residence?
|
CREATE TABLE Donors (DonorID INT,Name TEXT,TotalDonation DECIMAL(10,2),DonationDate DATE,Country TEXT); INSERT INTO Donors VALUES (1,'Josephine Garcia',2000.00,'2021-01-01','USA'),(2,'Ahmed Khan',1500.00,'2021-03-31','India'),(3,'Maria Rodriguez',1000.00,'2021-01-15','Mexico');
|
SELECT Country, SUM(TotalDonation) as TotalDonated, COUNT(*) as NumDonations FROM Donors WHERE YEAR(DonationDate) = 2021 AND MONTH(DonationDate) BETWEEN 1 AND 3 GROUP BY Country;
|
What is the average price of Fair Trade certified products sold in Europe?
|
CREATE TABLE products (product_id INT,name VARCHAR(100),price DECIMAL(5,2),certification VARCHAR(50)); INSERT INTO products (product_id,name,price,certification) VALUES (1,'Organic Cotton T-Shirt',25.99,'Fair Trade'); INSERT INTO products (product_id,name,price,certification) VALUES (2,'Recycled Tote Bag',12.99,'Fair Trade'); CREATE TABLE store (store_id INT,location VARCHAR(50),continent VARCHAR(50)); INSERT INTO store (store_id,location,continent) VALUES (1,'Berlin Store','Europe'); INSERT INTO store (store_id,location,continent) VALUES (2,'Paris Store','Europe'); CREATE TABLE sales (sale_id INT,product_id INT,store_id INT,quantity INT);
|
SELECT AVG(p.price) FROM products p JOIN sales s ON p.product_id = s.product_id JOIN store st ON s.store_id = st.store_id WHERE p.certification = 'Fair Trade' AND st.continent = 'Europe';
|
What is the average size of vessels that violated maritime law in Southeast Asia in 2020?
|
CREATE TABLE law_violations (id INTEGER,vessel_size INTEGER,location TEXT,year INTEGER); INSERT INTO law_violations (id,vessel_size,location,year) VALUES (1,250,'Southeast Asia',2020),(2,150,'Southeast Asia',2020),(3,300,'Indian Ocean',2020);
|
SELECT AVG(vessel_size) FROM law_violations WHERE location = 'Southeast Asia' AND year = 2020;
|
What is the total number of police officers and firefighters in each community policing sector?
|
CREATE TABLE sectors (sid INT,sector_name TEXT); CREATE TABLE employees (eid INT,sector_id INT,employee_type TEXT,salary INT); INSERT INTO sectors VALUES (1,'Sector A'); INSERT INTO sectors VALUES (2,'Sector B'); INSERT INTO employees VALUES (1,1,'Police Officer',50000); INSERT INTO employees VALUES (2,1,'Firefighter',60000); INSERT INTO employees VALUES (3,2,'Police Officer',55000); INSERT INTO employees VALUES (4,2,'Firefighter',65000);
|
SELECT s.sector_name, SUM(CASE WHEN e.employee_type = 'Police Officer' THEN 1 ELSE 0 END) AS total_police_officers, SUM(CASE WHEN e.employee_type = 'Firefighter' THEN 1 ELSE 0 END) AS total_firefighters FROM sectors s JOIN employees e ON s.sid = e.sector_id GROUP BY s.sector_name;
|
How many confirmed Zika virus cases were reported in 'disease_data' for the year 2020?
|
CREATE SCHEMA disease_data; CREATE TABLE zika_cases (id INT,clinic_id INT,date DATE,cases INT); INSERT INTO disease_data.zika_cases (id,clinic_id,date,cases) VALUES (1,1001,'2020-01-01',2),(2,1001,'2020-02-01',3),(3,1002,'2020-03-01',1),(4,1002,'2020-04-01',5),(5,1003,'2020-05-01',4);
|
SELECT SUM(cases) FROM disease_data.zika_cases WHERE date BETWEEN '2020-01-01' AND '2020-12-31';
|
Percentage of patients who improved after CBT in Australia?
|
CREATE TABLE patients (id INT,country VARCHAR(255),improvement VARCHAR(255)); INSERT INTO patients (id,country,improvement) VALUES (1,'Australia','Improved'),(2,'Australia','Not Improved'),(3,'USA','Improved'); CREATE TABLE therapy (patient_id INT,therapy_type VARCHAR(255)); INSERT INTO therapy (patient_id,therapy_type) VALUES (1,'CBT'),(2,'CBT'),(3,'DBT');
|
SELECT 100.0 * COUNT(CASE WHEN improvement = 'Improved' AND country = 'Australia' AND therapy_type = 'CBT' THEN 1 END) / COUNT(*) as percentage FROM patients JOIN therapy ON patients.id = therapy.patient_id WHERE country = 'Australia';
|
List the vessels owned by the company 'Sea Dragons Shipping'
|
CREATE TABLE vessels (id INT,name VARCHAR(50),company VARCHAR(50)); INSERT INTO vessels (id,name,company) VALUES (1,'MV Pegasus','Sea Dragons Shipping'),(2,'MV Orion','Sea Dragons Shipping'),(3,'MV Draco','Poseidon Shipping'),(4,'MV Perseus','Poseidon Shipping'),(5,'MV Andromeda','Triton Shipping');
|
SELECT name FROM vessels WHERE company = 'Sea Dragons Shipping';
|
What is the total number of players who play sports and action games?
|
CREATE TABLE Players (PlayerID INT,GameType VARCHAR(10)); INSERT INTO Players (PlayerID,GameType) VALUES (1,'Sports'),(2,'Strategy'),(3,'Action'),(4,'Simulation');
|
SELECT COUNT(*) FROM Players WHERE GameType IN ('Sports', 'Action');
|
What is the minimum age of male journalists in the 'news_reporters' table?
|
CREATE TABLE news_reporters (id INT,name VARCHAR(50),gender VARCHAR(10),age INT); INSERT INTO news_reporters (id,name,gender,age) VALUES (1,'John Doe','Male',35),(2,'Jane Smith','Female',32),(3,'Alice Johnson','Female',40);
|
SELECT MIN(age) FROM news_reporters WHERE gender = 'Male';
|
What is the minimum and maximum amount of funds spent on environmental initiatives in 'StateI' in 2022?
|
CREATE TABLE StateI_Enviro (ID INT,Year INT,Amount FLOAT); INSERT INTO StateI_Enviro (ID,Year,Amount) VALUES (1,2022,1000000),(2,2022,1500000),(3,2022,750000);
|
SELECT MIN(Amount), MAX(Amount) FROM StateI_Enviro WHERE Year = 2022;
|
List the program categories that have received donations in the current year, excluding categories that received donations only in the previous year.
|
CREATE TABLE donation_dates (donation_id INT,donation_year INT,program_category VARCHAR(20)); INSERT INTO donation_dates VALUES (1,2021,'Arts'),(2,2022,'Education'),(3,2022,'Health'),(4,2021,'Science'),(5,2022,'Arts');
|
SELECT program_category FROM donation_dates WHERE donation_year = YEAR(CURRENT_DATE) AND program_category NOT IN (SELECT program_category FROM donation_dates WHERE donation_year = YEAR(CURRENT_DATE) - 1) GROUP BY program_category;
|
What is the total amount of climate finance provided to projects in Africa, Asia, and South America, categorized by project type?
|
CREATE TABLE climate_finance (project_id INT,project_location VARCHAR(50),project_type VARCHAR(50),amount FLOAT); INSERT INTO climate_finance (project_id,project_location,project_type,amount) VALUES (1,'Africa','Renewable Energy',5000000); INSERT INTO climate_finance (project_id,project_location,project_type,amount) VALUES (2,'Asia','Energy Efficiency',6000000); INSERT INTO climate_finance (project_id,project_location,project_type,amount) VALUES (3,'South America','Carbon Capture',7000000);
|
SELECT project_type, SUM(amount) as total_amount FROM climate_finance WHERE project_location IN ('Africa', 'Asia', 'South America') GROUP BY project_type;
|
What is the total revenue generated by each mobile plan in the last quarter?
|
CREATE TABLE mobile_plans (id INT,plan_name VARCHAR(50),num_subscribers INT,price FLOAT);
|
SELECT plan_name, SUM(price * num_subscribers) FROM mobile_plans JOIN mobile_subscribers ON mobile_plans.id = mobile_subscribers.plan_id WHERE mobile_subscribers.subscription_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY plan_name;
|
What is the total budget allocated for social services provided by private contractors in the 'CityData' schema's 'CitySocialServices' table, for the year 2025?
|
CREATE SCHEMA CityData; CREATE TABLE CitySocialServices (Service varchar(255),Year int,Budget int,Contractor varchar(255)); INSERT INTO CitySocialServices (Service,Year,Budget,Contractor) VALUES ('Childcare',2025,200000,'Public'),('Childcare',2025,500000,'Private'),('Elderly Care',2025,700000,'Public');
|
SELECT SUM(Budget) FROM CityData.CitySocialServices WHERE Year = 2025 AND Contractor = 'Private';
|
Who are the top 3 smart contract creators in Africa by number of contracts?
|
CREATE TABLE smart_contracts (id INT,creator VARCHAR(50),region VARCHAR(10)); INSERT INTO smart_contracts (id,creator,region) VALUES ('Creator1','Africa'),('Creator2','Africa'),('Creator3','Africa'); INSERT INTO smart_contracts (id,creator,region) VALUES (4,'Creator4','Asia'),(5,'Creator5','Asia');
|
SELECT creator, COUNT(*) as contract_count, RANK() OVER (PARTITION BY region ORDER BY COUNT(*) DESC) as rank FROM smart_contracts GROUP BY creator;
|
How many claims were filed in Texas in 2020?
|
CREATE TABLE Claim (ClaimID int,PolicyID int,ClaimDate date,ClaimAmount int,State varchar(50)); INSERT INTO Claim (ClaimID,PolicyID,ClaimDate,ClaimAmount,State) VALUES (1,1,'2020-03-15',2000,'Texas'),(2,2,'2019-12-27',3000,'California'),(3,3,'2021-01-05',1500,'Texas');
|
SELECT COUNT(*) FROM Claim WHERE ClaimDate BETWEEN '2020-01-01' AND '2020-12-31' AND State = 'Texas';
|
What is the standard deviation of property tax rates in each neighborhood?
|
CREATE TABLE Neighborhoods (NeighborhoodID INT,NeighborhoodName VARCHAR(255)); CREATE TABLE PropertyTaxRates (PropertyTaxRateID INT,NeighborhoodID INT,Rate DECIMAL(5,2));
|
SELECT N.NeighborhoodName, STDEV(PTR.Rate) as StdDevRate FROM Neighborhoods N JOIN PropertyTaxRates PTR ON N.NeighborhoodID = PTR.NeighborhoodID GROUP BY N.NeighborhoodName;
|
Find the number of employees and unions in the 'labor_unions' schema
|
CREATE SCHEMA labor_unions; CREATE TABLE unions (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE employees (id INT PRIMARY KEY,name VARCHAR(255),union_id INT,FOREIGN KEY (union_id) REFERENCES unions(id)); INSERT INTO unions (id,name) VALUES (1,'Union A'),(2,'Union B'); INSERT INTO employees (id,name,union_id) VALUES (1,'John Doe',1),(2,'Jane Smith',NULL);
|
SELECT COUNT(DISTINCT e.id) AS employee_count, COUNT(DISTINCT u.id) AS union_count FROM labor_unions.employees e LEFT JOIN labor_unions.unions u ON e.union_id = u.id;
|
List all ports with their corresponding regions from the 'ports' and 'regions' tables.
|
CREATE TABLE ports (id INT PRIMARY KEY,name VARCHAR(50),region_id INT); CREATE TABLE regions (id INT PRIMARY KEY,name VARCHAR(50));
|
SELECT ports.name, regions.name AS region_name FROM ports INNER JOIN regions ON ports.region_id = regions.id;
|
Update the climate finance data to reflect the current inflation rates, using the 'inflation_rates' table.
|
CREATE TABLE climate_finance (project VARCHAR(50),country VARCHAR(50),amount FLOAT,date DATE); CREATE TABLE inflation_rates (country VARCHAR(50),rate FLOAT,date DATE); INSERT INTO climate_finance (project,country,amount,date) VALUES ('Green City','USA',5000000,'2020-01-01'); INSERT INTO inflation_rates (country,rate,date) VALUES ('USA',1.02,'2020-01-01');
|
UPDATE climate_finance SET amount = amount * (SELECT rate FROM inflation_rates WHERE climate_finance.country = inflation_rates.country AND climate_finance.date = inflation_rates.date);
|
List all programs in the 'programs' table that have a budget greater than the average program budget.
|
CREATE TABLE programs (program_id INT,program_name TEXT,budget DECIMAL(10,2)); INSERT INTO programs VALUES (1,'Education',10000.00),(2,'Health',15000.00),(3,'Environment',8000.00);
|
SELECT program_name FROM programs WHERE budget > (SELECT AVG(budget) FROM programs);
|
How many farmers are growing each crop type in urban and rural areas in the past month?
|
CREATE TABLE farmer (id INTEGER,name TEXT,area TEXT);CREATE TABLE farmland (id INTEGER,farmer_id INTEGER,type TEXT,start_date DATE,end_date DATE);CREATE TABLE crop (id INTEGER,farmland_id INTEGER,type TEXT,planted_date DATE);
|
SELECT fl.type as area_type, c.type as crop, COUNT(f.id) as num_farmers FROM farmer f INNER JOIN farmland fl ON f.id = fl.farmer_id INNER JOIN crop c ON fl.id = c.farmland_id WHERE c.planted_date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY fl.type, c.type;
|
List the top 5 most purchased beauty products that are not labeled 'paraben-free'.
|
CREATE TABLE ProductsParabenFree (product_id INT,product_name TEXT,is_paraben_free BOOLEAN); INSERT INTO ProductsParabenFree (product_id,product_name,is_paraben_free) VALUES (1,'Product A',true),(2,'Product B',false),(3,'Product C',false),(4,'Product D',true),(5,'Product E',false);
|
SELECT product_id, product_name FROM ProductsParabenFree WHERE is_paraben_free = false GROUP BY product_id, product_name ORDER BY COUNT(*) DESC LIMIT 5;
|
Create a view named 'ongoing_peacekeeping_operations'
|
CREATE VIEW ongoing_peacekeeping_operations AS SELECT * FROM peacekeeping_operations WHERE end_date >= CURDATE();
|
CREATE VIEW ongoing_peacekeeping_operations AS SELECT * FROM peacekeeping_operations WHERE end_date >= CURDATE();
|
What is the market share of electric vehicles in each country?
|
CREATE TABLE Sales (id INT,vehicle_id INT,quantity INT,date DATE,country VARCHAR(50)); CREATE TABLE Vehicles (id INT,make VARCHAR(50),model VARCHAR(50),type VARCHAR(50)); INSERT INTO Sales (id,vehicle_id,quantity,date,country) VALUES (1,1,100,'2021-01-01','USA'); INSERT INTO Vehicles (id,make,model,type) VALUES (1,'Tesla','Model 3','Electric');
|
SELECT country, (SUM(CASE WHEN type = 'Electric' THEN quantity ELSE 0 END) / SUM(quantity)) * 100 AS market_share FROM Sales INNER JOIN Vehicles ON Sales.vehicle_id = Vehicles.id GROUP BY country;
|
Delete all records in the 'oil_rig' table where the 'location' is 'North Sea'
|
CREATE TABLE oil_rig (id INT,company VARCHAR(255),location VARCHAR(255),status VARCHAR(255));
|
DELETE FROM oil_rig WHERE location = 'North Sea';
|
What are the total sales figures for drug 'DrugA' and 'DrugB'?
|
CREATE TABLE drugs (drug_name TEXT,sales INTEGER); INSERT INTO drugs (drug_name,sales) VALUES ('DrugA',5000),('DrugB',7000);
|
SELECT SUM(sales) FROM drugs WHERE drug_name IN ('DrugA', 'DrugB');
|
How many community development initiatives were planned in 2018?
|
CREATE TABLE community_development (id INT,year INT,initiative VARCHAR(50),status VARCHAR(20)); INSERT INTO community_development (id,year,initiative,status) VALUES (1,2018,'Cultural Festival','Planned'),(2,2019,'Youth Center','In Progress'),(3,2019,'Sports Club','Completed'),(4,2018,'Clean Water Access','Planned');
|
SELECT COUNT(*) FROM community_development WHERE year = 2018 AND status = 'Planned';
|
What is the average water consumption per capita in the state of Texas for the year 2020?
|
CREATE TABLE texas_population (id INT,city VARCHAR(50),population INT,year INT); INSERT INTO texas_population (id,city,population,year) VALUES (1,'Houston',2300000,2020); INSERT INTO texas_population (id,city,population,year) VALUES (2,'San Antonio',1600000,2020); INSERT INTO texas_population (id,city,population,year) VALUES (3,'Dallas',1300000,2020); INSERT INTO texas_population (id,city,population,year) VALUES (4,'Austin',1000000,2020); CREATE TABLE texas_water_consumption (id INT,city VARCHAR(50),water_consumption FLOAT,year INT); INSERT INTO texas_water_consumption (id,city,water_consumption,year) VALUES (1,'Houston',18000000,2020); INSERT INTO texas_water_consumption (id,city,water_consumption,year) VALUES (2,'San Antonio',12000000,2020); INSERT INTO texas_water_consumption (id,city,water_consumption,year) VALUES (3,'Dallas',9000000,2020); INSERT INTO texas_water_consumption (id,city,water_consumption,year) VALUES (4,'Austin',7000000,2020);
|
SELECT AVG(twc.water_consumption / tp.population) FROM texas_water_consumption twc INNER JOIN texas_population tp ON twc.city = tp.city WHERE twc.year = 2020;
|
How many astronauts are from India?
|
CREATE TABLE Astronauts (id INT,name VARCHAR(255),country VARCHAR(255),age INT); INSERT INTO Astronauts (id,name,country,age) VALUES (1,'Rakesh Sharma','India',72); INSERT INTO Astronauts (id,name,country,age) VALUES (2,'Kalpana Chawla','India',N/A); INSERT INTO Astronauts (id,name,country,age) VALUES (3,'Sunita Williams','United States',57);
|
SELECT COUNT(*) FROM Astronauts WHERE country = 'India';
|
What is the most popular concert venue in New York City?
|
CREATE TABLE Venues (VenueID INT,Name VARCHAR(100),City VARCHAR(100),Capacity INT);
|
SELECT V.Name FROM Venues V INNER JOIN Concerts C ON V.VenueID = C.VenueID WHERE V.City = 'New York City' GROUP BY V.Name ORDER BY COUNT(*) DESC LIMIT 1;
|
Who are the top 5 goal scorers in the English Premier League this season?
|
CREATE TABLE teams (team_id INT,team_name VARCHAR(100)); CREATE TABLE players (player_id INT,player_name VARCHAR(100),team_id INT); CREATE TABLE goals (goal_id INT,player_id INT,goal_count INT);
|
SELECT players.player_name, SUM(goals.goal_count) as total_goals FROM players INNER JOIN goals ON players.player_id = goals.player_id WHERE teams.team_id IN (SELECT team_id FROM teams WHERE team_name = 'English Premier League') GROUP BY players.player_name ORDER BY total_goals DESC LIMIT 5;
|
What is the average number of posts per day in the 'social_media' database?
|
CREATE TABLE posts (id INT,user_id INT,content TEXT,timestamp TIMESTAMP);
|
SELECT AVG(COUNT(posts.id)/86400) AS avg_posts_per_day FROM posts;
|
What is the earliest year in which a country launched a satellite in the SpaceRadar table?
|
CREATE TABLE SpaceRadar (id INT,country VARCHAR(50),year INT,satellites INT); INSERT INTO SpaceRadar (id,country,year,satellites) VALUES (1,'USA',2000,10),(2,'China',2005,8),(3,'Russia',1995,12);
|
SELECT country, MIN(year) AS earliest_year FROM SpaceRadar GROUP BY country;
|
List labor productivity and accident rates for Indonesian mining operations in 2018 and 2019.
|
CREATE TABLE id_mine_productivity (year INT,productivity FLOAT); INSERT INTO id_mine_productivity (year,productivity) VALUES (2018,1.9),(2019,2.1); CREATE TABLE id_mine_safety (year INT,accident_rate FLOAT); INSERT INTO id_mine_safety (year,accident_rate) VALUES (2018,0.015),(2019,0.017);
|
SELECT id_mine_productivity.productivity, id_mine_safety.accident_rate FROM id_mine_productivity INNER JOIN id_mine_safety ON id_mine_productivity.year = id_mine_safety.year WHERE id_mine_productivity.year IN (2018, 2019);
|
What is the total number of 'bus' and 'tram' vehicles in the 'fleet' table that are in need of maintenance?
|
CREATE TABLE fleet (id INT,type TEXT,model TEXT,year INT,last_maintenance DATE); INSERT INTO fleet (id,type,model,year,last_maintenance) VALUES (1,'bus','Artic',2015,'2022-01-01'),(2,'bus','Midi',2018,'2022-02-01'),(3,'tram','Cantrib',2010,'2022-03-01'),(4,'train','EMU',2000,'2022-04-01');
|
SELECT type, COUNT(*) as count FROM fleet WHERE type IN ('bus', 'tram') AND last_maintenance < DATEADD(year, -1, CURRENT_TIMESTAMP) GROUP BY type;
|
How many public schools are in the city of Dallas?
|
CREATE TABLE cities (id INT,name VARCHAR(50)); INSERT INTO cities (id,name) VALUES (1,'Dallas'),(2,'Houston'); CREATE TABLE schools (id INT,name VARCHAR(50),city_id INT); INSERT INTO schools (id,name,city_id) VALUES (1,'School A',1),(2,'School B',1),(3,'School C',2);
|
SELECT COUNT(*) FROM schools WHERE city_id = (SELECT id FROM cities WHERE name = 'Dallas');
|
What is the number of customer complaints received in each state in the last month?
|
CREATE TABLE customer_complaints (id INT,state VARCHAR(50),complaint_date DATE,complaint_type VARCHAR(50));
|
SELECT state, COUNT(*) FROM customer_complaints WHERE complaint_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY state;
|
Add a new column representative to the community table and update values
|
CREATE TABLE community(id INT,name VARCHAR(255),population INT,language VARCHAR(255),representative BOOLEAN);
|
ALTER TABLE community ADD COLUMN representative BOOLEAN;
|
How many retailers in Kenya offer recycled materials?
|
CREATE TABLE retailers (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO retailers (id,name,country) VALUES (1,'Retailer A','Kenya'),(2,'Retailer B','Kenya'),(3,'Retailer C','USA'); CREATE TABLE circular_economy (id INT,retailer_id INT,recycled_materials BOOLEAN); INSERT INTO circular_economy (id,retailer_id,recycled_materials) VALUES (1,1,true),(2,2,false),(3,3,false);
|
SELECT r.name, COUNT(CE.recycled_materials) as num_retailers FROM circular_economy CE JOIN retailers r ON CE.retailer_id = r.id WHERE r.country = 'Kenya' AND CE.recycled_materials = true GROUP BY r.name;
|
What is the average age of male members who own a smartwatch and performed a strength training workout?
|
CREATE TABLE Members (MemberID INT,Name VARCHAR(50),Age INT,Gender VARCHAR(50),Smartwatch BOOLEAN); INSERT INTO Members (MemberID,Name,Age,Gender,Smartwatch) VALUES (1,'John Doe',30,'Male',TRUE); INSERT INTO Members (MemberID,Name,Age,Gender,Smartwatch) VALUES (2,'Jane Smith',35,'Female',FALSE); CREATE TABLE Workouts (WorkoutID INT,WorkoutType VARCHAR(50),MemberID INT,Smartwatch BOOLEAN); INSERT INTO Workouts (WorkoutID,WorkoutType,MemberID,Smartwatch) VALUES (1,'Strength Training',1,TRUE); INSERT INTO Workouts (WorkoutID,WorkoutType,MemberID,Smartwatch) VALUES (2,'Yoga',2,FALSE);
|
SELECT AVG(Members.Age) FROM Members INNER JOIN Workouts ON Members.MemberID = Workouts.MemberID WHERE Members.Gender = 'Male' AND Members.Smartwatch = TRUE AND Workouts.WorkoutType = 'Strength Training';
|
What is the minimum speed of the broadband plans for customers living in the state of Texas?
|
CREATE TABLE broadband_plans (plan_id INT,speed FLOAT,state VARCHAR(20)); INSERT INTO broadband_plans (plan_id,speed,state) VALUES (1,150,'Texas'),(2,120,'California'),(3,200,'Texas'),(4,100,'Texas');
|
SELECT MIN(speed) FROM broadband_plans WHERE state = 'Texas';
|
How many open data initiatives were launched in Q4 2021?
|
CREATE TABLE initiatives (launch_date DATE); INSERT INTO initiatives (launch_date) VALUES ('2021-10-01'),('2021-11-15'),('2021-01-05'),('2021-12-20'),('2021-04-22');
|
SELECT COUNT(*) FROM initiatives WHERE launch_date BETWEEN '2021-10-01' AND '2021-12-31' AND EXTRACT(QUARTER FROM launch_date) = 4;
|
What is the average production rate for wells in the Barnett Shale?
|
CREATE TABLE well_production (well_name VARCHAR(50),location VARCHAR(50),rate FLOAT); INSERT INTO well_production (well_name,location,rate) VALUES ('Well A','Barnett Shale',1000),('Well B','Barnett Shale',1200);
|
SELECT AVG(rate) FROM well_production WHERE location = 'Barnett Shale';
|
What was the total revenue for defense projects with a duration over 24 months as of Q4 2022?
|
CREATE TABLE defense_projects (id INT,project_name VARCHAR(50),start_date DATE,end_date DATE,revenue FLOAT); INSERT INTO defense_projects (id,project_name,start_date,end_date,revenue) VALUES (1,'Project A','2020-01-01','2023-12-31',10000000);
|
SELECT SUM(revenue) FROM defense_projects WHERE DATEDIFF(end_date, start_date) > 24 AND quarter = 'Q4' AND year = 2022;
|
How many startups have exited via an IPO in the Biotech sector?
|
CREATE TABLE startup (id INT,name TEXT,industry TEXT,exit_strategy TEXT);
|
SELECT COUNT(*) FROM startup WHERE industry = 'Biotech' AND exit_strategy = 'IPO';
|
How many cases were handled by attorneys with more than 10 years of experience?
|
CREATE TABLE attorneys (attorney_id INT,years_of_experience INT); INSERT INTO attorneys (attorney_id,years_of_experience) VALUES (1,12),(2,8),(3,15),(4,20); CREATE TABLE cases (case_id INT,attorney_id INT); INSERT INTO cases (case_id,attorney_id) VALUES (1,1),(2,3),(3,4),(4,2);
|
SELECT COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.years_of_experience > 10;
|
What is the total wildlife habitat area, in square kilometers, for each type of habitat in Africa?
|
CREATE TABLE wildlife_habitat (id INT,continent VARCHAR(255),country VARCHAR(255),region VARCHAR(255),habitat_type VARCHAR(255),area FLOAT); INSERT INTO wildlife_habitat (id,continent,country,region,habitat_type,area) VALUES (1,'Africa','Kenya','East Africa','Forest',12345.12),(2,'Africa','Tanzania','East Africa','Savannah',23456.12);
|
SELECT habitat_type, SUM(area) FROM wildlife_habitat WHERE continent = 'Africa' GROUP BY habitat_type;
|
What is the total runtime of all movies in the 'Surrealism' gallery?
|
CREATE TABLE Artworks (artwork_id INT,artwork_name VARCHAR(50),runtime INT,gallery_name VARCHAR(50)); INSERT INTO Artworks (artwork_id,artwork_name,runtime,gallery_name) VALUES (1,'Un Chien Andalou',16,'Surrealism'),(2,'The Seashell and the Clergyman',67,'Surrealism');
|
SELECT SUM(runtime) FROM Artworks WHERE gallery_name = 'Surrealism';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.