instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Which artist's paintings were exhibited the most in Germany?
|
CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(50));CREATE TABLE Paintings (PaintingID INT,PaintingName VARCHAR(50),ArtistID INT);CREATE TABLE Exhibitions (ExhibitionID INT,ExhibitionCountry VARCHAR(50),PaintingID INT); INSERT INTO Artists VALUES (1,'Vincent Van Gogh'); INSERT INTO Paintings VALUES (1,'Starry Night',1); INSERT INTO Exhibitions VALUES (1,'Germany',1);
|
SELECT ArtistName, COUNT(*) as ExhibitionCount FROM Artists a JOIN Paintings p ON a.ArtistID = p.ArtistID JOIN Exhibitions e ON p.PaintingID = e.PaintingID WHERE e.ExhibitionCountry = 'Germany' GROUP BY ArtistName ORDER BY ExhibitionCount DESC LIMIT 1;
|
What is the total quantity of 'Bamboo Fabric' sourced in 'Africa' and 'South America' in 2023?
|
CREATE TABLE Sourcing (id INT,material VARCHAR(20),country VARCHAR(20),quantity INT,year INT); INSERT INTO Sourcing (id,material,country,quantity,year) VALUES (1,'Organic Cotton','Bangladesh',4000,2021),(2,'Recycled Polyester','Vietnam',3000,2021),(3,'Bamboo Fabric','Africa',2000,2023),(4,'Bamboo Fabric','South America',2500,2023);
|
SELECT SUM(quantity) FROM Sourcing WHERE material = 'Bamboo Fabric' AND (country = 'Africa' OR country = 'South America') AND year = 2023;
|
Calculate the total amount of coal mined in the United States in 2019
|
CREATE TABLE mining_operations (id INT,mine_name TEXT,location TEXT,material TEXT,quantity INT,date DATE); INSERT INTO mining_operations (id,mine_name,location,material,quantity,date) VALUES (6,'Coal Haven','United States','coal',7000,'2019-01-01');
|
SELECT SUM(quantity) FROM mining_operations WHERE material = 'coal' AND location = 'United States' AND date = '2019-01-01';
|
What is the total number of defense project timelines in the year 2023?
|
CREATE TABLE defense_project_timelines (id INT,project_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO defense_project_timelines (id,project_name,start_date,end_date) VALUES (1,'Project A','2023-01-01','2023-12-31'),(2,'Project B','2022-01-01','2022-12-31'),(3,'Project C','2021-01-01','2021-12-31');
|
SELECT COUNT(*) FROM defense_project_timelines WHERE YEAR(start_date) = 2023;
|
Which products have a higher sales count than the average sales count?
|
CREATE TABLE product_sales (product VARCHAR(20),sales_count INT); INSERT INTO product_sales (product,sales_count) VALUES ('Software',10),('Hardware',5),('Consulting',15);
|
SELECT product FROM product_sales WHERE sales_count > (SELECT AVG(sales_count) FROM product_sales);
|
What is the total number of community health workers trained in cultural competency by language spoken?
|
CREATE TABLE community_health_workers (worker_id INT,language VARCHAR(10),cultural_competency_training VARCHAR(10)); INSERT INTO community_health_workers (worker_id,language,cultural_competency_training) VALUES (1,'English','Yes'),(2,'Spanish','No'),(3,'French','Yes'),(4,'English','Yes'),(5,'Spanish','Yes');
|
SELECT language, COUNT(*) FROM community_health_workers WHERE cultural_competency_training = 'Yes' GROUP BY language;
|
How many volunteers have signed up for each program?
|
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT); INSERT INTO Volunteers (VolunteerID,Name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'); CREATE TABLE VolunteerPrograms (VolunteerID INT,ProgramID INT); INSERT INTO VolunteerPrograms (VolunteerID,ProgramID) VALUES (1,1),(2,1),(3,2);
|
SELECT Programs.ProgramName, COUNT(VolunteerPrograms.VolunteerID) FROM VolunteerPrograms INNER JOIN Volunteers ON VolunteerPrograms.VolunteerID = Volunteers.VolunteerID INNER JOIN Programs ON VolunteerPrograms.ProgramID = Programs.ProgramID GROUP BY Programs.ProgramName;
|
What is the total number of employees in mining operations in each state of the USA?
|
CREATE TABLE mining_operations (id INT,state VARCHAR(255),num_employees INT); INSERT INTO mining_operations (id,state,num_employees) VALUES (1,'California',200),(2,'Texas',300),(3,'New York',100),(4,'Florida',400),(5,'Illinois',250),(6,'Pennsylvania',350);
|
SELECT state, SUM(num_employees) FROM mining_operations GROUP BY state;
|
What is the average age of policyholders who have a car insurance policy in the 'West' region?
|
CREATE TABLE Policyholders (PolicyholderID int,Age int,Region varchar(10)); INSERT INTO Policyholders (PolicyholderID,Age,Region) VALUES (1,35,'West'); INSERT INTO Policyholders (PolicyholderID,Age,Region) VALUES (2,45,'East');
|
SELECT AVG(Age) FROM Policyholders WHERE Region = 'West';
|
What is the number of cases resolved by each volunteer in each month?
|
CREATE TABLE volunteers (volunteer_id INT,name TEXT); INSERT INTO volunteers (volunteer_id,name) VALUES (1,'Aarav'),(2,'Bella'),(3,'Charlie'); CREATE TABLE cases (case_id INT,volunteer_id INT,date TEXT,resolved_date TEXT); INSERT INTO cases (case_id,volunteer_id,date,resolved_date) VALUES (1,1,'2022-01-01','2022-01-15'),(2,1,'2022-02-01','2022-02-28'),(3,2,'2022-03-01','2022-03-15'),(4,3,'2022-04-01','2022-04-30');
|
SELECT volunteers.name, EXTRACT(MONTH FROM cases.date) as month, COUNT(cases.case_id) as cases_per_month FROM volunteers INNER JOIN cases ON volunteers.volunteer_id = cases.volunteer_id WHERE cases.date <= cases.resolved_date GROUP BY volunteers.name, month;
|
What is the total claim amount for policyholders from Texas?
|
CREATE TABLE policyholders (id INT,name TEXT,state TEXT,policy_type TEXT,premium FLOAT); INSERT INTO policyholders (id,name,state,policy_type,premium) VALUES (1,'John Doe','Texas','Auto',1200.00),(2,'Jane Smith','California','Home',2500.00); CREATE TABLE claims (id INT,policyholder_id INT,claim_amount FLOAT,claim_date DATE); INSERT INTO claims (id,policyholder_id,claim_amount,claim_date) VALUES (1,1,800.00,'2021-01-01'),(2,1,300.00,'2021-02-01'),(3,2,1500.00,'2021-03-01');
|
SELECT SUM(claims.claim_amount) FROM claims JOIN policyholders ON claims.policyholder_id = policyholders.id WHERE policyholders.state = 'Texas';
|
Update the wages column in the collective_bargaining table to 'Hourly' for all records with a union_id of 002
|
CREATE TABLE collective_bargaining (cb_id SERIAL PRIMARY KEY,union_id VARCHAR(5),topic TEXT,outcome TEXT,date DATE,wages TEXT);
|
UPDATE collective_bargaining SET wages = 'Hourly' WHERE union_id = '002';
|
List the top 5 countries with the highest water usage in garment production.
|
CREATE TABLE water_usage_garment_production (id INT,country VARCHAR(50),water_usage INT); INSERT INTO water_usage_garment_production (id,country,water_usage) VALUES (1,'China',5000); INSERT INTO water_usage_garment_production (id,country,water_usage) VALUES (2,'India',4000); INSERT INTO water_usage_garment_production (id,country,water_usage) VALUES (3,'Bangladesh',3000); INSERT INTO water_usage_garment_production (id,country,water_usage) VALUES (4,'Pakistan',2000);
|
SELECT country, water_usage FROM water_usage_garment_production ORDER BY water_usage DESC LIMIT 5;
|
What is the total revenue generated by hotels in the Americas that have adopted AI concierge services in Q3 2022?
|
CREATE TABLE hotel_services (hotel_id INT,hotel_name TEXT,country TEXT,revenue FLOAT,ai_concierge INT); INSERT INTO hotel_services (hotel_id,hotel_name,country,revenue,ai_concierge) VALUES (1,'Hotel F','USA',500000,1),(2,'Hotel G','Brazil',600000,1),(3,'Hotel H','Mexico',400000,0),(4,'Hotel I','Canada',700000,1),(5,'Hotel J','USA',800000,0);
|
SELECT SUM(revenue) FROM hotel_services WHERE country IN ('USA', 'Canada', 'Brazil', 'Mexico') AND ai_concierge = 1 AND quarter = 3 AND year = 2022;
|
What is the maximum cargo weight capacity for each vessel type?
|
CREATE TABLE vessels (id INT,name TEXT,type TEXT,cargo_weight_capacity FLOAT);
|
SELECT type, MAX(cargo_weight_capacity) FROM vessels GROUP BY type;
|
What is the number of events held in Spain that had an attendance of over 200 people?
|
CREATE TABLE Events (EventID int,EventDate date,Attendees int,Country varchar(50)); INSERT INTO Events (EventID,EventDate,Attendees,Country) VALUES (1,'2021-01-01',100,'Spain'),(2,'2021-02-01',150,'Spain'),(3,'2021-03-01',250,'Spain');
|
SELECT COUNT(*) FROM Events WHERE Country = 'Spain' AND Attendees > 200;
|
How many times has the rule "Suspicious user behavior" been triggered in the last month?
|
CREATE TABLE alert_rules (id INT,rule_name VARCHAR(255)); INSERT INTO alert_rules (id,rule_name) VALUES (1,'Unusual outbound traffic'),(2,'Suspicious login'),(3,'Suspicious user behavior'),(4,'Malware detection'); CREATE TABLE alerts (id INT,rule_id INT,timestamp DATETIME); INSERT INTO alerts (id,rule_id,timestamp) VALUES (1,1,'2022-05-01 12:34:56'),(2,2,'2022-06-02 09:10:11'),(3,3,'2022-07-03 17:22:33'),(4,4,'2022-08-04 04:44:44');
|
SELECT COUNT(*) FROM alerts WHERE rule_id IN (SELECT id FROM alert_rules WHERE rule_name = 'Suspicious user behavior') AND timestamp >= DATE_SUB(NOW(), INTERVAL 1 MONTH);
|
What is the total number of evidence-based policies created by each department, having a budget greater than $10 million?
|
CREATE TABLE departments (id INT,name VARCHAR(50),budget INT); INSERT INTO departments (id,name,budget) VALUES (1,'Education',15000000),(2,'Transportation',20000000); CREATE TABLE policies (id INT,department_id INT,title VARCHAR(50),evidence_based BOOLEAN); INSERT INTO policies (id,department_id,title,evidence_based) VALUES (1,1,'Safe Routes to School',true),(2,2,'Mass Transit Expansion',true);
|
SELECT d.name, COUNT(p.id) as total_policies FROM departments d JOIN policies p ON d.id = p.department_id WHERE d.budget > 10000000 AND p.evidence_based = true GROUP BY d.name;
|
List the names and salaries of state employees with salaries above the average state employee salary in the 'state_employees' table?
|
CREATE TABLE state_employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),salary DECIMAL(10,2)); INSERT INTO state_employees (id,first_name,last_name,salary) VALUES (1,'Mike','Johnson',50000.00); INSERT INTO state_employees (id,first_name,last_name,salary) VALUES (2,'Sara','Williams',55000.00);
|
SELECT first_name, last_name, salary FROM state_employees WHERE salary > (SELECT AVG(salary) FROM state_employees);
|
Identify the overlap between customers who subscribed to both mobile and broadband services in the last year.
|
CREATE TABLE mobile_subscribers (subscriber_id INT,joined_date DATE);CREATE TABLE broadband_subscribers (subscriber_id INT,joined_date DATE);
|
SELECT m.subscriber_id FROM mobile_subscribers m WHERE joined_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) INTERSECT SELECT b.subscriber_id FROM broadband_subscribers b WHERE joined_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
|
Delete all records from table port_operations with operation as 'unloading'
|
CREATE TABLE port_operations (id INT PRIMARY KEY,cargo_id INT,operation VARCHAR(20)); INSERT INTO port_operations (id,cargo_id,operation) VALUES (1,101,'loading'),(2,102,'unloading');
|
DELETE FROM port_operations WHERE operation = 'unloading';
|
What is the distribution of players by age group and VR adoption?
|
CREATE TABLE AgeGroups (AgeGroupID INT,AgeGroup VARCHAR(10)); INSERT INTO AgeGroups (AgeGroupID,AgeGroup) VALUES (1,'0-10'); INSERT INTO AgeGroups (AgeGroupID,AgeGroup) VALUES (2,'11-20'); INSERT INTO AgeGroups (AgeGroupID,AgeGroup) VALUES (3,'21-30'); INSERT INTO AgeGroups (AgeGroupID,AgeGroup) VALUES (4,'31-40'); INSERT INTO AgeGroups (AgeGroupID,AgeGroup) VALUES (5,'41-50'); CREATE TABLE Players (PlayerID INT,Age INT,VR INT); INSERT INTO Players (PlayerID,Age,VR) VALUES (1,15,1); INSERT INTO Players (PlayerID,Age,VR) VALUES (2,25,1); INSERT INTO Players (PlayerID,Age,VR) VALUES (3,30,0); INSERT INTO Players (PlayerID,Age,VR) VALUES (4,40,0); INSERT INTO Players (PlayerID,Age,VR) VALUES (5,50,1);
|
SELECT AgeGroups.AgeGroup, AVG(Players.Age), SUM(Players.VR) FROM AgeGroups INNER JOIN Players ON Players.Age BETWEEN AgeGroups.AgeGroupID*10 AND AgeGroups.AgeGroupID*10+9 GROUP BY AgeGroups.AgeGroup;
|
Insert a new record for a disability accommodation named 'Hearing Loops' for 'Visual Impairment' type.
|
CREATE TABLE accommodation (accommodation_id INT,accommodation_name TEXT,disability_type TEXT); INSERT INTO accommodation (accommodation_id,accommodation_name,disability_type) VALUES (1,'Wheelchair Ramp','Mobility'); INSERT INTO accommodation (accommodation_id,accommodation_name,disability_type) VALUES (2,'Braille Materials','Visual Impairment');
|
INSERT INTO accommodation (accommodation_name, disability_type) VALUES ('Hearing Loops', 'Visual Impairment');
|
How many criminal incidents were reported in each community policing sector?
|
CREATE TABLE sectors (sid INT,sector_name VARCHAR(255)); CREATE TABLE criminal_incidents (iid INT,sid INT,incident_type VARCHAR(255));
|
SELECT s.sector_name, COUNT(i.iid) FROM sectors s INNER JOIN criminal_incidents i ON s.sid = i.sid GROUP BY s.sector_name;
|
How many evidence-based policy making projects were completed in India since 2010?
|
CREATE TABLE EvidenceBasedPolicy (id INT,project_name VARCHAR(50),country VARCHAR(50),start_date DATE,end_date DATE);
|
SELECT COUNT(*) FROM EvidenceBasedPolicy WHERE country = 'India' AND start_date <= '2010-01-01' AND end_date >= '2010-12-31';
|
Calculate the percentage change in gas production for Well P in the North Sea between the current month and the previous month.
|
CREATE TABLE production_data (well_name VARCHAR(50),location VARCHAR(50),oil_production NUMERIC(10,2),gas_production NUMERIC(10,2),production_date DATE); INSERT INTO production_data (well_name,location,oil_production,gas_production,production_date) VALUES ('Well P','North Sea',1000,400,'2023-04-01'),('Well P','North Sea',1050,425,'2023-03-31'),('Well P','North Sea',1100,450,'2023-02-28');
|
SELECT ((gas_production - LAG(gas_production, 1) OVER (PARTITION BY well_name ORDER BY production_date)) / LAG(gas_production, 1) OVER (PARTITION BY well_name ORDER BY production_date)) * 100 as percentage_change FROM production_data WHERE well_name = 'Well P' AND production_date IN (DATEADD(month, -1, '2023-04-01'), '2023-04-01');
|
What is the success rate of agricultural innovation projects in each country?
|
CREATE TABLE project (project_id INT,name VARCHAR(50),location VARCHAR(50),success_rate FLOAT); CREATE TABLE country (country_id INT,name VARCHAR(50),description TEXT); CREATE TABLE location (location_id INT,name VARCHAR(50),country_id INT);
|
SELECT l.name, AVG(p.success_rate) FROM project p JOIN location l ON p.location = l.name JOIN country c ON l.country_id = c.country_id GROUP BY l.name;
|
Delete a specific cargo handling operation from the "cargo_operations" table
|
CREATE TABLE cargo_operations (id INT PRIMARY KEY,vessel_id INT,port_id INT,cargo_type VARCHAR(255),quantity INT,time_stamp DATETIME);
|
DELETE FROM cargo_operations WHERE id = 3;
|
What is the average speed of all vessels that traveled to the Port of Oakland in the past month?
|
CREATE TABLE Vessels (VesselID INT,VoyageID INT,AvgSpeed DECIMAL(5,2));CREATE TABLE Voyages (VoyageID INT,Destination VARCHAR(50),TravelDate DATE); INSERT INTO Vessels VALUES (1,101,14.5),(2,102,16.2),(3,103,15.6); INSERT INTO Voyages VALUES (101,'Port of Oakland','2022-01-05'),(102,'Port of Los Angeles','2022-01-07'),(103,'Port of Oakland','2022-01-10');
|
SELECT AVG(AvgSpeed) FROM Vessels JOIN Voyages ON Vessels.VoyageID = Voyages.VoyageID WHERE Destination = 'Port of Oakland' AND TravelDate >= DATEADD(month, -1, GETDATE());
|
What is the minimum number of hours of sign language interpretation provided in a week?
|
CREATE TABLE InterpretationServices (service_id INT,hours_per_week INT,accommodation_type VARCHAR(255));
|
SELECT MIN(hours_per_week) FROM InterpretationServices WHERE accommodation_type = 'Sign Language';
|
Which cities have the most virtual tours in their hotels?
|
CREATE TABLE Hotels (hotel_id INT,hotel_name VARCHAR(50),city VARCHAR(50)); CREATE TABLE VirtualTours (tour_id INT,hotel_id INT,tour_name VARCHAR(50)); INSERT INTO Hotels (hotel_id,hotel_name,city) VALUES (1,'Hotel1','CityA'),(2,'Hotel2','CityB'); INSERT INTO VirtualTours (tour_id,hotel_id) VALUES (1,1),(2,1),(3,2),(4,2);
|
SELECT h.city, COUNT(DISTINCT vt.hotel_id) as num_tours FROM Hotels h JOIN VirtualTours vt ON h.hotel_id = vt.hotel_id GROUP BY h.city;
|
List the total number of volunteer hours for each program, broken down by month and year.
|
CREATE TABLE Programs (ProgramID int,Name varchar(50),Location varchar(50)); CREATE TABLE Volunteers (VolunteerID int,Name varchar(50),ProgramID int,VolunteerDate date,Hours decimal(10,2)); INSERT INTO Programs (ProgramID,Name,Location) VALUES (1,'Feeding America','USA'),(2,'Habitat for Humanity','Canada'); INSERT INTO Volunteers (VolunteerID,Name,ProgramID,VolunteerDate,Hours) VALUES (1,'Bob',1,'2022-01-01',10.00),(2,'Sally',1,'2022-02-01',15.00),(3,'John',2,'2022-03-01',20.00);
|
SELECT P.Name, DATE_FORMAT(V.VolunteerDate, '%Y-%m') as Date, SUM(V.Hours) as TotalHours FROM Programs P JOIN Volunteers V ON P.ProgramID = V.ProgramID GROUP BY P.ProgramID, Date;
|
Update the vessel_safety table and set the last_inspection_grade as 'B' for vessel "Freedom's Sail" if it's not already set
|
CREATE TABLE vessel_safety (vessel_name VARCHAR(255),last_inspection_date DATE,last_inspection_grade CHAR(1));
|
UPDATE vessel_safety SET last_inspection_grade = 'B' WHERE vessel_name = 'Freedom''s Sail' AND last_inspection_grade IS NULL;
|
What is the percentage of the population that is vaccinated against measles in each country?
|
CREATE TABLE VaccinationData (Country VARCHAR(50),Population INT,MeaslesVaccinated INT); INSERT INTO VaccinationData (Country,Population,MeaslesVaccinated) VALUES ('Canada',38000000,34560000),('USA',331000000,301200000);
|
SELECT Country, (MeaslesVaccinated / Population) * 100 AS PercentVaccinated FROM VaccinationData;
|
How many albums were released per month in 2021?
|
CREATE TABLE album_release (id INT,title TEXT,release_month INT,release_year INT,artist TEXT); INSERT INTO album_release (id,title,release_month,release_year,artist) VALUES (1,'Album1',1,2021,'Artist1'); INSERT INTO album_release (id,title,release_month,release_year,artist) VALUES (2,'Album2',3,2021,'Artist2'); INSERT INTO album_release (id,title,release_month,release_year,artist) VALUES (3,'Album3',12,2021,'Artist3');
|
SELECT release_month, COUNT(*) as albums_released FROM album_release WHERE release_year = 2021 GROUP BY release_month;
|
Which policyholders have no claims in Florida?
|
CREATE TABLE Policyholders (PolicyID INT,Name VARCHAR(50)); CREATE TABLE Claims (ClaimID INT,PolicyID INT,State VARCHAR(20)); INSERT INTO Policyholders VALUES (1,'John Smith'),(2,'Jane Doe'),(3,'Mike Brown'); INSERT INTO Claims VALUES (1,1,'California'),(2,2,'Texas');
|
SELECT p.Name FROM Policyholders p LEFT JOIN Claims c ON p.PolicyID = c.PolicyID WHERE c.PolicyID IS NULL AND State = 'Florida';
|
Which crop has the highest yield in 'crop_comparison' table?
|
CREATE TABLE crop_comparison (farmer VARCHAR(50),crop VARCHAR(50),yield INT); INSERT INTO crop_comparison (farmer,crop,yield) VALUES ('FarmerA','corn',100),('FarmerA','wheat',80),('FarmerB','corn',110),('FarmerB','wheat',90),('FarmerC','corn',95),('FarmerC','wheat',75);
|
SELECT crop, MAX(yield) as highest_yield FROM crop_comparison GROUP BY crop;
|
What is the percentage of Shariah-compliant investments in each investment portfolio?
|
CREATE TABLE portfolios (portfolio_id INT,customer_id INT,num_investments INT,num_shariah_compliant_investments INT);CREATE VIEW shariah_compliant_portfolios AS SELECT * FROM portfolios WHERE num_shariah_compliant_investments > 0;
|
SELECT p.portfolio_id, (COUNT(scp.portfolio_id) * 100.0 / (SELECT COUNT(*) FROM shariah_compliant_portfolios)) as pct_shariah_compliant_investments FROM portfolios p LEFT JOIN shariah_compliant_portfolios scp ON p.portfolio_id = scp.portfolio_id GROUP BY p.portfolio_id;
|
What is the maximum salary of workers in the 'manufacturing' industry who are not part of a union?
|
CREATE TABLE workers (id INT,name VARCHAR(255),industry VARCHAR(255),salary DECIMAL(10,2)); CREATE TABLE unions (id INT,worker_id INT,union VARCHAR(255)); INSERT INTO workers (id,name,industry,salary) VALUES (1,'Isabella Rodriguez','manufacturing',90000.00);
|
SELECT MAX(workers.salary) FROM workers LEFT OUTER JOIN unions ON workers.id = unions.worker_id WHERE workers.industry = 'manufacturing' AND unions.union IS NULL;
|
What is the total price of natural ingredients for products launched in 2022?
|
CREATE TABLE products_ingredients(product_id INT,ingredient_id INT,natural_ingredient BOOLEAN,price DECIMAL); INSERT INTO products_ingredients(product_id,ingredient_id,natural_ingredient,price) VALUES (1,1,true,1.25),(2,2,true,3.00),(3,3,false,1.50),(4,4,true,2.00),(5,5,true,2.50); CREATE TABLE products(id INT,name TEXT,launch_year INT); INSERT INTO products(id,name,launch_year) VALUES (1,'Cleanser X',2022),(2,'Lotion Y',2021),(3,'Shampoo Z',2022),(4,'Conditioner W',2020),(5,'Moisturizer V',2022);
|
SELECT SUM(price) FROM products_ingredients p_i JOIN products p ON p_i.product_id = p.id WHERE natural_ingredient = true AND p.launch_year = 2022;
|
What is the total amount of Shariah-compliant loans issued by each financial institution?
|
CREATE TABLE financial_institutions (institution_id INT,institution_name TEXT); INSERT INTO financial_institutions (institution_id,institution_name) VALUES (1,'Islamic Bank'),(2,'Al Baraka Bank'),(3,'Islamic Finance House'); CREATE TABLE loans (loan_id INT,institution_id INT,loan_type TEXT,amount FLOAT); INSERT INTO loans (loan_id,institution_id,loan_type,amount) VALUES (1,1,'Shariah-compliant',5000),(2,1,'conventional',7000),(3,2,'Shariah-compliant',4000),(4,2,'Shariah-compliant',6000),(5,3,'conventional',8000);
|
SELECT institution_id, SUM(amount) FROM loans WHERE loan_type = 'Shariah-compliant' GROUP BY institution_id;
|
What is the total number of space missions launched by each country and year?
|
CREATE TABLE space_missions (country TEXT,year INT); INSERT INTO space_missions (country,year) VALUES ('USA',2015),('USA',2015),('USA',2016),('Russia',2015),('Russia',2016),('China',2016),('China',2017),('India',2017),('India',2018);
|
SELECT country, year, COUNT(*) FROM space_missions GROUP BY country, year;
|
What is the average claim amount for policyholders living in the 'east' region?
|
CREATE TABLE policyholders (id INT,region VARCHAR(10),claim_amount INT); INSERT INTO policyholders (id,region,claim_amount) VALUES (1,'east',5000),(2,'west',3000),(3,'east',1000);
|
SELECT AVG(claim_amount) FROM policyholders WHERE region = 'east';
|
How many members joined in Q2 2022?
|
CREATE TABLE Members (MemberID INT,JoinDate DATE); INSERT INTO Members (MemberID,JoinDate) VALUES (1,'2022-04-05'),(2,'2022-03-12'),(3,'2022-06-20'),(4,'2022-05-01');
|
SELECT COUNT(*) FROM Members WHERE JoinDate BETWEEN '2022-04-01' AND '2022-06-30';
|
What is the total installed capacity (in MW) of all renewable energy projects in the state 'California'?
|
CREATE TABLE renewable_energy_projects (id INT,name TEXT,state TEXT,capacity_mw FLOAT); INSERT INTO renewable_energy_projects (id,name,state,capacity_mw) VALUES (1,'Solar Star','California',579.0),(2,'Desert Sunlight Solar Farm','California',550.0);
|
SELECT SUM(capacity_mw) FROM renewable_energy_projects WHERE state = 'California';
|
Delete the arctic_resources table.
|
CREATE TABLE arctic_resources (id INT,resource VARCHAR(50),type VARCHAR(20)); INSERT INTO arctic_resources (id,resource,type) VALUES (1,'oil','drilling'),(2,'whale','hunting'),(3,'seal','hunting');
|
DROP TABLE arctic_resources;
|
How many cases were heard in each state last year?
|
CREATE TABLE cases_by_state (state VARCHAR(20),year INT,num_cases INT); INSERT INTO cases_by_state (state,year,num_cases) VALUES ('California',2021,1200),('New York',2021,2500),('Texas',2021,1800);
|
SELECT state, SUM(num_cases) as total_cases FROM cases_by_state WHERE year = 2021 GROUP BY state;
|
What is the average spending on military innovation by the top 3 countries in 2020?
|
CREATE TABLE military_innovation (id INT,country VARCHAR(50),spending DECIMAL(10,2),year INT); INSERT INTO military_innovation (id,country,spending,year) VALUES (1,'USA',15000000.00,2020); INSERT INTO military_innovation (id,country,spending,year) VALUES (2,'China',12000000.00,2020); INSERT INTO military_innovation (id,country,spending,year) VALUES (3,'Russia',9000000.00,2020);
|
SELECT AVG(spending) as avg_spending FROM (SELECT spending FROM military_innovation WHERE country IN ('USA', 'China', 'Russia') AND year = 2020 ORDER BY spending DESC LIMIT 3) as top_three;
|
What is the minimum depth of the ocean floor in the Atlantic region?
|
CREATE TABLE ocean_floor_map (map_id INT,map_name VARCHAR(50),region VARCHAR(50),site_depth INT);
|
SELECT MIN(site_depth) FROM ocean_floor_map WHERE region = 'Atlantic';
|
How many public works projects were completed in each quarter of the last 2 years?
|
CREATE TABLE projects_by_quarter (id INT,project_name VARCHAR(255),completion_quarter INT,completion_year INT); INSERT INTO projects_by_quarter (id,project_name,completion_quarter,completion_year) VALUES (1,'Highway Expansion',3,2021),(2,'Water Treatment Plant Upgrade',4,2021);
|
SELECT completion_quarter, completion_year, COUNT(*) as num_projects FROM projects_by_quarter WHERE completion_year >= YEAR(DATEADD(year, -2, GETDATE())) GROUP BY completion_quarter, completion_year;
|
Determine the number of successful ransomware attacks in the healthcare sector in the first quarter of 2022.
|
CREATE TABLE attacks (id INT,type VARCHAR(255),result VARCHAR(255),sector VARCHAR(255),date DATE); INSERT INTO attacks (id,type,result,sector,date) VALUES (1,'phishing','unsuccessful','financial','2022-01-01'); INSERT INTO attacks (id,type,result,sector,date) VALUES (2,'ransomware','successful','healthcare','2022-02-01');
|
SELECT COUNT(*) FROM attacks WHERE type = 'ransomware' AND result = 'successful' AND sector = 'healthcare' AND date >= '2022-01-01' AND date < '2022-04-01';
|
Show the number of electric and autonomous vehicles sold in each region in 2019
|
CREATE TABLE region_sales (id INT,region VARCHAR(20),vehicle_type VARCHAR(20),year INT,quantity INT); INSERT INTO region_sales (id,region,vehicle_type,year,quantity) VALUES (1,'North','ev',2018,1500),(2,'North','ev',2019,2500),(3,'North','autonomous',2018,800),(4,'North','autonomous',2019,1500),(5,'South','ev',2018,1000),(6,'South','ev',2019,2000),(7,'South','autonomous',2018,600),(8,'South','autonomous',2019,1200),(9,'East','ev',2018,800),(10,'East','ev',2019,3000),(11,'East','autonomous',2018,700),(12,'East','autonomous',2019,1400),(13,'West','ev',2018,2000),(14,'West','ev',2019,4000),(15,'West','autonomous',2018,900),(16,'West','autonomous',2019,1800);
|
SELECT region, year, SUM(quantity) FROM region_sales WHERE vehicle_type IN ('ev', 'autonomous') AND year = 2019 GROUP BY region, year;
|
Delete the record of offender with id 2
|
CREATE TABLE offenders (id INT PRIMARY KEY,name VARCHAR(255),age INT,state VARCHAR(2));
|
DELETE FROM offenders WHERE id = 2;
|
What is the total number of urban farms operated by men and women in hectares?
|
CREATE TABLE urban_farms (farmer_id INT,farmer_gender TEXT,area FLOAT); INSERT INTO urban_farms (farmer_id,farmer_gender,area) VALUES (1,'Female',12.3),(2,'Male',18.5),(3,'Female',21.7),(4,'Male',15.6);
|
SELECT SUM(area) FROM urban_farms;
|
Delete the treatment with ID 9.
|
CREATE TABLE treatments (id INT PRIMARY KEY,patient_id INT,name VARCHAR(255),duration INT); INSERT INTO treatments (id,patient_id,name,duration) VALUES (9,8,'Exposure Therapy',12);
|
DELETE FROM treatments WHERE id = 9;
|
Add a new peacekeeping operation record for 'Operation Peace' in 'Country A' in 2022
|
CREATE TABLE peacekeeping_operations (id INT,name VARCHAR(255),start_date DATE);
|
INSERT INTO peacekeeping_operations (id, name, start_date) VALUES (1, 'Operation Peace', '2022-01-01');
|
What is the policy advocacy effort rank by total expenditure per region, partitioned by fiscal year?
|
CREATE TABLE Policy_Advocacy (Fiscal_Year INT,Region VARCHAR(10),Expenditure DECIMAL(7,2)); INSERT INTO Policy_Advocacy VALUES (2022,'Northeast',50000.00),(2022,'Southeast',40000.00),(2023,'Northeast',55000.00),(2023,'Southeast',45000.00);
|
SELECT Fiscal_Year, Region, Expenditure, RANK() OVER (PARTITION BY Fiscal_Year ORDER BY Expenditure DESC) as Expenditure_Rank FROM Policy_Advocacy;
|
Identify countries having at least 2 warehouses and 1 freight forwarder?
|
CREATE TABLE Warehouse (WarehouseID INT,WarehouseName TEXT,Country TEXT); INSERT INTO Warehouse (WarehouseID,WarehouseName,Country) VALUES (1,'Central Warehouse','USA'),(2,'East Coast Warehouse','USA'),(3,'Toronto Warehouse','Canada'),(4,'Brisbane Warehouse','Australia'); CREATE TABLE FreightForwarder (FFID INT,FFName TEXT,Country TEXT); INSERT INTO FreightForwarder (FFID,FFName,Country) VALUES (1,'Global Freight','USA'),(2,'Northern Shipping','Canada'),(3,'Pacific Logistics','Australia');
|
SELECT Country FROM (SELECT Country, COUNT(DISTINCT WarehouseID) AS WarehouseCount, COUNT(DISTINCT FFID) AS FFCount FROM Warehouse GROUP BY Country) Subquery WHERE WarehouseCount > 1 AND FFCount > 0;
|
What is the total fare collected for buses in the city of Madrid in the past month?
|
CREATE TABLE buses (id INT,city VARCHAR(20)); INSERT INTO buses (id,city) VALUES (1,'Madrid'),(2,'Barcelona'); CREATE TABLE bus_fares (id INT,bus_id INT,fare DECIMAL(5,2),fare_date DATE); INSERT INTO bus_fares (id,bus_id,fare,fare_date) VALUES (1,1,2.00,'2022-02-01'),(2,1,2.50,'2022-02-05'),(3,2,1.50,'2022-02-07');
|
SELECT SUM(bf.fare) FROM bus_fares bf JOIN buses b ON bf.bus_id = b.id WHERE b.city = 'Madrid' AND bf.fare_date >= DATEADD(month, -1, GETDATE());
|
What are the average ratings for movies by genre?
|
CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(255),rating FLOAT); INSERT INTO movies (id,title,genre,rating) VALUES (1,'Movie1','Action',7.5),(2,'Movie2','Comedy',8.2),(3,'Movie3','Drama',8.8);
|
SELECT genre, AVG(rating) as avg_rating FROM movies GROUP BY genre;
|
What is the minimum perigee altitude of satellites in highly eccentric orbits?
|
CREATE TABLE satellite_altitude (id INT,name VARCHAR(255),orbit_type VARCHAR(255),perigee_altitude FLOAT); CREATE VIEW highly_eccentric_orbits AS SELECT * FROM satellite_altitude WHERE orbit_type IN ('highly eccentric','highly elliptical');
|
SELECT MIN(perigee_altitude) FROM highly_eccentric_orbits;
|
Insert a new concert record with name 'Coachella' and revenue 1000000 into the concert_sales table.
|
CREATE TABLE concert_sales (id INT,name VARCHAR,revenue DECIMAL);
|
INSERT INTO concert_sales (name, revenue) VALUES ('Coachella', 1000000);
|
Which station on the 'Green' line has the highest fare collection?
|
CREATE TABLE routes (line VARCHAR(10),station VARCHAR(20)); INSERT INTO routes (line,station) VALUES ('Green','Station A'),('Green','Station B'),('Green','Station C'); CREATE TABLE fares (station VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO fares (station,revenue) VALUES ('Station A',2000),('Station A',2500),('Station B',3000),('Station C',1500),('Station C',1800);
|
SELECT station, MAX(revenue) FROM fares WHERE station IN (SELECT station FROM routes WHERE line = 'Green') GROUP BY station;
|
Identify the number of unique customers and their total spending at each dispensary in Arizona with social equity programs.
|
CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT,social_equity_program BOOLEAN); INSERT INTO Dispensaries (id,name,state,social_equity_program) VALUES (1,'Dispensary E','Arizona',true); INSERT INTO Dispensaries (id,name,state,social_equity_program) VALUES (2,'Dispensary F','Arizona',true); CREATE TABLE Sales (sale_id INT,dispid INT,customer_id INT,total DECIMAL(10,2)); INSERT INTO Sales (sale_id,dispid,customer_id,total) VALUES (1,1,1001,200); INSERT INTO Sales (sale_id,dispid,customer_id,total) VALUES (2,1,1001,250); INSERT INTO Sales (sale_id,dispid,customer_id,total) VALUES (3,2,1002,150);
|
SELECT d.name, COUNT(DISTINCT s.customer_id) as num_customers, SUM(s.total) as total_spending FROM Dispensaries d JOIN Sales s ON d.id = s.dispid WHERE d.state = 'Arizona' AND d.social_equity_program = true GROUP BY d.name;
|
Calculate the average age of users from each country.
|
CREATE TABLE users (id INT,name VARCHAR(50),age INT,country VARCHAR(50),created_at TIMESTAMP); INSERT INTO users (id,name,age,country,created_at) VALUES (3,'Charlie',35,'Mexico','2021-01-03 12:00:00'),(4,'Diana',28,'Brazil','2021-01-04 13:00:00');
|
SELECT country, AVG(age) OVER (PARTITION BY country) as avg_age FROM users;
|
What is the maximum pollution level in the 'Arctic' region in the last year?'
|
CREATE TABLE pollution_data (location VARCHAR(50),region VARCHAR(20),pollution_level FLOAT,inspection_date DATE); INSERT INTO pollution_data (location,region,pollution_level,inspection_date) VALUES ('Location A','Arctic',50.2,'2022-01-01'),('Location B','Arctic',70.1,'2022-02-15'),('Location C','Antarctic',30.9,'2022-03-01');
|
SELECT MAX(pollution_level) FROM pollution_data WHERE region = 'Arctic' AND inspection_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
|
Who won the ICC Cricket World Cup in 2011?
|
CREATE TABLE cricket_world_cups (winner VARCHAR(255),year INT); INSERT INTO cricket_world_cups (winner,year) VALUES ('India',2011);
|
SELECT winner FROM cricket_world_cups WHERE year = 2011;
|
Which countries have the highest and lowest ethical AI scores?
|
CREATE TABLE Ethical_AI_Scores (country VARCHAR(255),score INT); INSERT INTO Ethical_AI_Scores (country,score) VALUES ('Sweden',90),('Norway',85),('Finland',80),('Denmark',75),('Germany',70);
|
SELECT country, score FROM Ethical_AI_Scores ORDER BY score DESC LIMIT 1; SELECT country, score FROM Ethical_AI_Scores ORDER BY score ASC LIMIT 1;
|
Retrieve the latest 3 flight records for each aircraft model
|
CREATE TABLE FlightRecords (ID INT,AircraftModel VARCHAR(50),FlightDate DATE,FlightHours INT); INSERT INTO FlightRecords (ID,AircraftModel,FlightDate,FlightHours) VALUES (1,'B747','2021-06-15',10000),(2,'B747','2021-06-14',9500),(3,'B747','2021-06-13',9000),(4,'A320','2021-06-15',7000),(5,'A320','2021-06-14',6500),(6,'A320','2021-06-13',6000),(7,'A380','2021-06-15',12000),(8,'A380','2021-06-14',11500),(9,'A380','2021-06-13',11000);
|
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY AircraftModel ORDER BY FlightDate DESC) as RowNumber FROM FlightRecords) as FlightRecords WHERE RowNumber <= 3;
|
Show the railway stations in Canada
|
CREATE TABLE Infrastructure (id INT,name VARCHAR(100),type VARCHAR(50),country VARCHAR(50)); INSERT INTO Infrastructure (id,name,type,country) VALUES (9,'Toronto Union Station','Railway Station','Canada'),(10,'Vancouver Pacific Central Station','Railway Station','Canada');
|
SELECT name FROM Infrastructure WHERE type = 'Railway Station' AND country = 'Canada';
|
What is the total funding received by female-led biotech startups in the last 5 years?
|
CREATE TABLE startup_funding (company_name VARCHAR(100),company_location VARCHAR(50),funding_amount DECIMAL(10,2),funding_date DATE,ceo_gender VARCHAR(10)); INSERT INTO startup_funding VALUES ('GenEase','CA',500000.00,'2021-03-15','Female'); INSERT INTO startup_funding VALUES ('BioSynthetica','NY',750000.00,'2020-12-28','Male'); INSERT INTO startup_funding VALUES ('NeuroNexus','TX',300000.00,'2021-04-01','Female');
|
SELECT SUM(funding_amount) FROM startup_funding WHERE ceo_gender = 'Female' AND funding_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 5 YEAR) AND CURDATE();
|
List all genetic research projects in the UK.
|
CREATE SCHEMA if not exists genetics; USE genetics; CREATE TABLE if not exists research_projects (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO research_projects (id,name,country) VALUES (1,'Project X','UK'),(2,'Project Y','UK'),(3,'Project Z','USA');
|
SELECT * FROM genetics.research_projects WHERE country = 'UK';
|
How many mobile subscribers have an unpaid balance greater than $50?
|
CREATE TABLE mobile_subscribers (subscriber_id INT,unpaid_balance DECIMAL(10,2)); INSERT INTO mobile_subscribers (subscriber_id,unpaid_balance) VALUES (1,45.20),(2,0),(3,75.00),(4,30.50),(5,120.75),(6,25.33);
|
SELECT COUNT(*) FROM mobile_subscribers WHERE unpaid_balance > 50.00;
|
How many AI applications are there in the 'fairness_ai' database, segmented by algorithm type?
|
CREATE TABLE fairness_ai.ai_applications (ai_application_id INT PRIMARY KEY,ai_algorithm_id INT,application_name VARCHAR(255),fairness_score FLOAT); INSERT INTO fairness_ai.ai_applications (ai_application_id,ai_algorithm_id,application_name,fairness_score) VALUES (1,1,'AI-generated art',0.8),(2,1,'AI-generated music',0.75),(3,2,'AI-powered chatbot',0.9),(4,3,'AI-powered self-driving car',0.6); CREATE TABLE fairness_ai.ai_algorithms (ai_algorithm_id INT PRIMARY KEY,ai_algorithm VARCHAR(255)); INSERT INTO fairness_ai.ai_algorithms (ai_algorithm_id,ai_algorithm) VALUES (1,'Generative Adversarial Networks'),(2,'Transformers'),(3,'Deep Reinforcement Learning');
|
SELECT f.ai_algorithm, COUNT(a.ai_application_id) as num_applications FROM fairness_ai.ai_applications a JOIN fairness_ai.ai_algorithms f ON a.ai_algorithm_id = f.ai_algorithm_id GROUP BY f.ai_algorithm;
|
What is the average number of publications per department?
|
CREATE TABLE departments (id INT,name VARCHAR(255)); INSERT INTO departments (id,name) VALUES (1,'Biology'),(2,'Mathematics'),(3,'Sociology'); CREATE TABLE graduate_students (id INT,department_id INT,gender VARCHAR(10),num_publications INT); INSERT INTO graduate_students (id,department_id,gender,num_publications) VALUES (1,1,'Female',10),(2,1,'Male',15),(3,2,'Female',20),(4,2,'Non-binary',5),(5,3,'Male',25),(6,3,'Female',30);
|
SELECT d.name, AVG(gs.num_publications) FROM departments d JOIN graduate_students gs ON d.id = gs.department_id GROUP BY d.name;
|
Which network infrastructure investments were made in the last 6 months in Florida?
|
CREATE TABLE infrastructure_investments (investment_id INT,investment_type VARCHAR(20),investment_date DATE,state VARCHAR(20)); INSERT INTO infrastructure_investments (investment_id,investment_type,investment_date,state) VALUES (1,'5G tower','2022-06-01','Florida');
|
SELECT * FROM infrastructure_investments WHERE state = 'Florida' AND investment_date > DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
What is the total number of marine species recorded in the Caribbean Sea?
|
CREATE TABLE marine_species (id INT,species VARCHAR(255),region VARCHAR(255)); INSERT INTO marine_species (id,species,region) VALUES (1,'Queen Angelfish','Caribbean'); INSERT INTO marine_species (id,species,region) VALUES (2,'Elkhorn Coral','Caribbean');
|
SELECT COUNT(DISTINCT species) FROM marine_species WHERE region = 'Caribbean';
|
What is the annual recycling rate for the state of California?
|
CREATE TABLE state_recycling (state VARCHAR(255),year INT,recycling_rate DECIMAL(5,2)); INSERT INTO state_recycling (state,year,recycling_rate) VALUES ('California',2021,0.50);
|
SELECT recycling_rate*100 FROM state_recycling WHERE state='California' AND year=2021;
|
Who are the top 3 artists with the highest revenue from artwork sales in the impressionist movement?
|
CREATE TABLE artworks (id INT,title VARCHAR(50),artist VARCHAR(50),movement VARCHAR(50),price DECIMAL(10,2)); INSERT INTO artworks (id,title,artist,movement,price) VALUES (1,'Water Lilies','Claude Monet','impressionist',84000000.00); INSERT INTO artworks (id,title,artist,movement,price) VALUES (2,'The Starry Night','Vincent van Gogh','post-impressionist',142000000.00); INSERT INTO artworks (id,title,artist,movement,price) VALUES (3,'The Scream','Edvard Munch','expressionist',119000000.00);
|
SELECT artist, SUM(price) AS total_revenue FROM artworks WHERE movement = 'impressionist' GROUP BY artist ORDER BY total_revenue DESC LIMIT 3;
|
What is the total number of organizations that have implemented technology for social good initiatives in Asia?
|
CREATE TABLE social_good_organizations (org_id INT,region VARCHAR(20)); INSERT INTO social_good_organizations (org_id,region) VALUES (1,'Asia'),(2,'Africa'),(3,'Asia'),(4,'Europe');
|
SELECT COUNT(*) FROM social_good_organizations WHERE region = 'Asia';
|
What is the average number of beds in rural_hospitals for hospitals in the United States?
|
CREATE TABLE rural_hospitals (hospital_id INT,beds INT,location VARCHAR(20));
|
SELECT AVG(beds) FROM rural_hospitals WHERE location = 'United States';
|
What is the total fare collected from passengers on buses for the month of January 2022?
|
CREATE TABLE buses (id INT,route_id INT,fare FLOAT); INSERT INTO buses (id,route_id,fare) VALUES (1,101,2.50),(2,102,3.25),(3,103,4.00);
|
SELECT SUM(fare) FROM buses WHERE EXTRACT(MONTH FROM timestamp) = 1 AND EXTRACT(YEAR FROM timestamp) = 2022;
|
Find the top 5 users with the highest number of planting records in the past month.
|
CREATE TABLE users (user_id INT,name VARCHAR(255)); CREATE TABLE planting_records (record_id INT,user_id INT,crop_type VARCHAR(255),planting_date DATE);
|
SELECT u.name, COUNT(pr.record_id) as num_records FROM users u INNER JOIN planting_records pr ON u.user_id = pr.user_id WHERE pr.planting_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY u.name ORDER BY num_records DESC LIMIT 5;
|
What is the total quantity of coal mined in Russia, Germany, and Poland?
|
CREATE TABLE coal_production (country VARCHAR(20),quantity INT); INSERT INTO coal_production (country,quantity) VALUES ('Russia',1200),('Germany',700),('Poland',900);
|
SELECT country, SUM(quantity) FROM coal_production WHERE country IN ('Russia', 'Germany', 'Poland') GROUP BY country;
|
Find all marine species that have been observed in both the Arctic and Atlantic regions
|
CREATE TABLE marine_species (name TEXT,region TEXT); INSERT INTO marine_species (name,region) VALUES ('Species1','Arctic'); INSERT INTO marine_species (name,region) VALUES ('Species2','Atlantic');
|
SELECT m1.name FROM marine_species m1 INNER JOIN marine_species m2 ON m1.name = m2.name WHERE m1.region = 'Arctic' AND m2.region = 'Atlantic';
|
What is the latest temperature recorded for each location in the 'weather' table?
|
CREATE TABLE weather (location VARCHAR(50),temperature INT,record_date DATE); INSERT INTO weather VALUES ('Seattle',45,'2022-01-01'); INSERT INTO weather VALUES ('Seattle',50,'2022-02-01'); INSERT INTO weather VALUES ('Seattle',55,'2022-03-01'); INSERT INTO weather VALUES ('New York',30,'2022-01-01'); INSERT INTO weather VALUES ('New York',35,'2022-02-01'); INSERT INTO weather VALUES ('New York',40,'2022-03-01');
|
SELECT location, MAX(temperature) AS latest_temp FROM weather GROUP BY location;
|
Get the total revenue and profit for the month of January in the year 2022?
|
CREATE TABLE sales (id INT,dish_id INT,order_date DATE,quantity INT,price FLOAT); INSERT INTO sales (id,dish_id,order_date,quantity,price) VALUES (1,1,'2022-01-02',2,10.00),(2,2,'2022-01-03',1,9.25),(3,3,'2022-01-04',3,12.00),(4,1,'2022-01-05',1,7.50),(5,2,'2022-01-06',4,9.25),(6,3,'2022-01-07',2,12.00);
|
SELECT SUM(quantity * price) as revenue, SUM((quantity * price) - (quantity * (SELECT cost FROM ingredients WHERE dish_id = sales.dish_id LIMIT 1))) as profit FROM sales WHERE order_date BETWEEN '2022-01-01' AND '2022-01-31';
|
Identify the top 3 most visited natural attractions in Africa and their respective visitor counts.
|
CREATE TABLE africa_attractions (id INT,name TEXT,country TEXT,visitors INT); INSERT INTO africa_attractions VALUES (1,'Victoria Falls','Zimbabwe',2000000),(2,'Mount Kilimanjaro','Tanzania',50000),(3,'Ngorongoro Crater','Tanzania',300000);
|
SELECT name, visitors FROM africa_attractions WHERE country = 'Tanzania' OR country = 'Zimbabwe' ORDER BY visitors DESC LIMIT 3;
|
What are the maximum and minimum production quantities (in kg) for chemical compounds in the European Union, grouped by country?
|
CREATE TABLE eu_compounds (compound_id INT,compound_name TEXT,country TEXT,production_quantity INT); INSERT INTO eu_compounds (compound_id,compound_name,country,production_quantity) VALUES (1,'Compound A','Germany',8000),(2,'Compound B','France',9000),(3,'Compound C','Italy',7000),(4,'Compound D','Spain',6000);
|
SELECT country, MAX(production_quantity) as max_production, MIN(production_quantity) as min_production FROM eu_compounds GROUP BY country;
|
How many IoT sensors recorded data in "Field3" on June 15, 2022?
|
CREATE TABLE Field3_Temp (sensor_id INT,sensor_reading DATE); INSERT INTO Field3_Temp (sensor_id,sensor_reading) VALUES (1,'2022-06-15'),(2,'2022-06-15'),(3,'2022-06-15'),(4,'2022-06-14');
|
SELECT COUNT(DISTINCT sensor_id) FROM Field3_Temp WHERE sensor_reading = '2022-06-15';
|
Add the following new rare earth element to the production_data table: Gadolinium with a quantity of 450 from 2020
|
CREATE TABLE production_data (id INT PRIMARY KEY,year INT,refined_rare_earth_element TEXT,quantity INT);
|
INSERT INTO production_data (id, year, refined_rare_earth_element, quantity) VALUES (5, 2020, 'Gadolinium', 450);
|
Delete projects in Canada with a construction cost less than 5 million
|
CREATE TABLE infrastructure_projects (id INT,name TEXT,location TEXT,construction_cost FLOAT); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (1,'Brooklyn Bridge','USA',15000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (2,'Chunnel','UK',21000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (3,'Tokyo Tower','Japan',33000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (4,'Millau Viaduct','France',4000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (5,'Seine Bridge','Canada',7000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (6,'St. Lawrence Seaway','Canada',4500000);
|
DELETE FROM infrastructure_projects WHERE location = 'Canada' AND construction_cost < 5000000;
|
What is the total revenue generated from ecotourism in Indonesia in Q1 2022?
|
CREATE TABLE revenue (id INT,category VARCHAR(20),revenue FLOAT,revenue_date DATE); INSERT INTO revenue (id,category,revenue,revenue_date) VALUES (1,'Ecotourism',50000,'2022-01-01'),(2,'Ecotourism',60000,'2022-01-02'),(3,'Ecotourism',55000,'2022-01-03');
|
SELECT SUM(revenue) FROM revenue WHERE category = 'Ecotourism' AND revenue_date BETWEEN '2022-01-01' AND DATE_ADD('2022-03-31', INTERVAL 1 DAY);
|
List all events with over 500 attendees, sorted by date.
|
INSERT INTO Community_Engagement (id,location,event_name,date,attendees) VALUES (1,'New York','Art Exhibition','2022-06-01',600); INSERT INTO Community_Engagement (id,location,event_name,date,attendees) VALUES (2,'Los Angeles','Music Festival','2022-07-01',400);
|
SELECT * FROM Community_Engagement WHERE attendees > 500 ORDER BY date;
|
Which continent has the most tourists visiting France?
|
CREATE TABLE tourism_stats (visitor_country VARCHAR(255),continent VARCHAR(255)); INSERT INTO tourism_stats (visitor_country,continent) VALUES ('France','Europe');
|
SELECT continent, COUNT(*) FROM tourism_stats WHERE visitor_country = 'France' GROUP BY continent ORDER BY COUNT(*) DESC LIMIT 1;
|
What is the average speed of electric buses in Seattle?
|
CREATE TABLE public.buses (id SERIAL PRIMARY KEY,name TEXT,speed FLOAT,city TEXT); INSERT INTO public.buses (name,speed,city) VALUES ('Electric Bus 1',35.5,'Seattle'),('Electric Bus 2',36.7,'Seattle');
|
SELECT AVG(speed) FROM public.buses WHERE city = 'Seattle' AND name LIKE 'Electric Bus%';
|
What is the maximum ocean acidification level recorded in the Southern Ocean, and which research station had this level?
|
CREATE TABLE ocean_acidification (measurement_date DATE,location TEXT,level FLOAT); INSERT INTO ocean_acidification (measurement_date,location,level) VALUES ('2021-01-01','Australian Antarctic Division',7.5); INSERT INTO ocean_acidification (measurement_date,location,level) VALUES ('2021-01-02','British Antarctic Survey',7.6);
|
SELECT research_station.station_name, oa.level AS max_level FROM ocean_acidification oa JOIN (SELECT location, MAX(level) AS max_level FROM ocean_acidification WHERE region = 'Southern Ocean' GROUP BY location) oa_max ON oa.level = oa_max.max_level JOIN research_stations research_station ON oa.location = research_station.station_name;
|
How many deep-sea expeditions ('expedition') have been conducted in the Arctic region ('region')?
|
CREATE TABLE region (id INT,name VARCHAR(50)); CREATE TABLE expedition (id INT,name VARCHAR(50),region_id INT); INSERT INTO region (id,name) VALUES (1,'Arctic'),(2,'Antarctic'); INSERT INTO expedition (id,name,region_id) VALUES (1,'Aurora Expedition',1),(2,'Antarctic Adventure',2);
|
SELECT COUNT(expedition.id) FROM expedition INNER JOIN region ON expedition.region_id = region.id WHERE region.name = 'Arctic';
|
What are the details of the 10 most recent unsuccessful login attempts, including the user account and the source IP address?
|
CREATE TABLE login_attempts (attempt_id INT,attempt_date DATE,user_account VARCHAR(100),source_ip VARCHAR(50));
|
SELECT * FROM login_attempts WHERE attempt_result = 'unsuccessful' ORDER BY attempt_date DESC LIMIT 10;
|
Show the total number of research grants awarded to each department, sorted by the total amount.
|
CREATE TABLE grant (id INT,department VARCHAR(30),amount FLOAT,date DATE); INSERT INTO grant (id,department,amount,date) VALUES (1,'Physics',200000.00,'2021-01-01'),(2,'Chemistry',150000.00,'2020-07-14');
|
SELECT department, SUM(amount) as total_amount FROM grant GROUP BY department ORDER BY total_amount DESC;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.