instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total number of OTA bookings in 'Europe' in the last year?
|
CREATE TABLE ota_bookings (id INT,hotel_id INT,country TEXT,booking_date DATE); INSERT INTO ota_bookings (id,hotel_id,country,booking_date) VALUES (1,1,'France','2021-01-02'),(2,2,'Germany','2021-01-05'),(3,3,'Italy','2021-01-07'),(4,4,'Spain','2022-01-01'),(5,5,'France','2022-01-03');
|
SELECT COUNT(*) FROM ota_bookings WHERE country LIKE 'Europe%' AND booking_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
|
What is the CO2 emission reduction target for each country in 2023?
|
CREATE TABLE country_emission_targets (country_name VARCHAR(50),year INT,co2_emission_target DECIMAL(10,2));
|
SELECT country_name, co2_emission_target AS co2_emission_reduction_target_2023 FROM country_emission_targets WHERE year = 2023;
|
What is the average CO2 emission of the top 5 countries in 2020?
|
CREATE TABLE emissions (country VARCHAR(255),year INT,co2_emission FLOAT); INSERT INTO emissions (country,year,co2_emission) VALUES ('USA',2020,5135.32),('China',2020,10098.24),('India',2020,2649.54),('Russia',2020,2496.84),('Japan',2020,1180.52);
|
SELECT AVG(co2_emission) FROM (SELECT co2_emission FROM emissions WHERE country IN ('USA', 'China', 'India', 'Russia', 'Japan') AND year = 2020 ORDER BY co2_emission DESC LIMIT 5) subquery;
|
Which auto show has the most vehicles on display?
|
CREATE TABLE AutoShow (id INT,name VARCHAR(255),location VARCHAR(255),country VARCHAR(255),num_vehicles INT); INSERT INTO AutoShow (id,name,location,country,num_vehicles) VALUES (1,'New York Auto Show','New York','USA',1000);
|
SELECT name, location, MAX(num_vehicles) FROM AutoShow;
|
What are the names of all facilities that have a product innovation metric greater than 50?
|
CREATE TABLE facility_metrics (facility TEXT,product_innovation INT); INSERT INTO facility_metrics (facility,product_innovation) VALUES ('Facility1',75),('Facility2',30),('Facility3',60);
|
SELECT facility FROM facility_metrics WHERE product_innovation > 50;
|
What is the total number of patients with 'Asthma' or 'Diabetes' in 'RuralHealthFacility11'?
|
CREATE TABLE RuralHealthFacility11 (id INT,name TEXT,diagnosis TEXT); INSERT INTO RuralHealthFacility11 (id,name,diagnosis) VALUES (1,'Jamal Brown','Asthma'),(2,'Kimberly Davis','Diabetes');
|
SELECT COUNT(*) FROM RuralHealthFacility11 WHERE diagnosis IN ('Asthma', 'Diabetes');
|
Which local_supplier has the highest safety score in the supply_chain table?
|
CREATE TABLE supply_chain (supplier_name TEXT,safety_score INTEGER); INSERT INTO supply_chain (supplier_name,safety_score) VALUES ('Farm Fresh',92),('Green Grocers',88),('Local Produce',95);
|
SELECT supplier_name, MAX(safety_score) FROM supply_chain;
|
List all sports types
|
CREATE TABLE sports (id INT PRIMARY KEY,sport_name VARCHAR(100));
|
SELECT sport_name FROM sports;
|
What is the total revenue of customers with a name starting with 'J'?
|
CREATE TABLE customers (id INT,name VARCHAR(50),region VARCHAR(50),revenue FLOAT); INSERT INTO customers (id,name,region,revenue) VALUES (1,'John Smith','Southeast',5000),(2,'Jane Doe','Northeast',7000),(3,'Bob Johnson','Southeast',6000),(4,'Alex Brown','West',4000);
|
SELECT SUM(revenue) FROM customers WHERE name LIKE 'J%';
|
What is the total weight of ceramic artifacts from 'mesopotamia'?
|
CREATE TABLE mesopotamia (artifact_id INT,weight FLOAT,type VARCHAR(255));
|
SELECT SUM(weight) FROM mesopotamia WHERE type = 'ceramic';
|
What is the most visited exhibition in Tokyo?
|
CREATE TABLE Exhibitions (id INT,city VARCHAR(20),visitors INT,exhibition_date DATE); INSERT INTO Exhibitions (id,city,visitors,exhibition_date) VALUES (1,'Tokyo',50,'2021-07-01'),(2,'Tokyo',60,'2021-07-05');
|
SELECT city, MAX(visitors) as max_visitors FROM Exhibitions WHERE city = 'Tokyo' GROUP BY city
|
What is the name and quantity of all cargo having a quantity greater than 5000 that is located in a port in Greece?
|
CREATE TABLE Cargo (CargoID INT,Name VARCHAR(255),Quantity INT,PortID INT); INSERT INTO Cargo (CargoID,Name,Quantity,PortID) VALUES (2,'Copper',6000,2);
|
SELECT Cargo.Name, Cargo.Quantity FROM Cargo INNER JOIN Port ON Cargo.PortID = Port.PortID WHERE Port.Country = 'Greece' AND Cargo.Quantity > 5000;
|
Which city has the highest bike-sharing ridership in millions?
|
CREATE TABLE Bike_Sharing (City VARCHAR(50),System_Name VARCHAR(50),Trips INT); INSERT INTO Bike_Sharing (City,System_Name,Trips) VALUES ('Barcelona','Bicing',2000000); INSERT INTO Bike_Sharing (City,System_Name,Trips) VALUES ('Chicago','Divvy',3600000); INSERT INTO Bike_Sharing (City,System_Name,Trips) VALUES ('New York','Citi Bike',9800000);
|
SELECT City, MAX(Trips/1000000) FROM Bike_Sharing GROUP BY City;
|
Which defense projects have a start date on or after January 1, 2023?
|
CREATE TABLE DefenseProjects (id INT PRIMARY KEY,project VARCHAR(50),start_date DATE); INSERT INTO DefenseProjects (id,project,start_date) VALUES (1,'Project B','2023-01-01');
|
SELECT project FROM DefenseProjects WHERE start_date >= '2023-01-01';
|
Which Underwriting team has the most policies in California and Texas?
|
CREATE TABLE Policies (PolicyID INT,Team VARCHAR(20),State VARCHAR(20)); INSERT INTO Policies VALUES (1,'Team A','California'),(2,'Team B','California'),(3,'Team A','Texas'),(4,'Team C','New York'),(5,'Team A','California');
|
SELECT Team, COUNT(*) FROM Policies WHERE State IN ('California', 'Texas') GROUP BY Team ORDER BY COUNT(*) DESC LIMIT 1;
|
Find the top 3 restaurants with the highest revenue for February 2022.
|
CREATE TABLE RestaurantRevenue(restaurant_id INT,revenue DECIMAL(10,2),revenue_date DATE);
|
SELECT restaurant_id, SUM(revenue) FROM RestaurantRevenue WHERE revenue_date BETWEEN '2022-02-01' AND '2022-02-28' GROUP BY restaurant_id ORDER BY SUM(revenue) DESC LIMIT 3;
|
Identify the distinct types of aquatic feed used in fish farms in India, Indonesia, and Malaysia.
|
CREATE TABLE feed_type (feed_id INT,farm_location VARCHAR(255),feed_type VARCHAR(255)); INSERT INTO feed_type (feed_id,farm_location,feed_type) VALUES (1,'India','Pellets'),(2,'India','Flakes'),(3,'Indonesia','Pellets'),(4,'Indonesia','Gel'),(5,'Malaysia','Flakes'),(6,'Malaysia','Gel');
|
SELECT DISTINCT feed_type FROM feed_type WHERE farm_location IN ('India', 'Indonesia', 'Malaysia');
|
What is the revenue for each region by month?
|
CREATE TABLE sales_by_region (id INT,region VARCHAR(50),sale_date DATE,sales DECIMAL(10,2)); CREATE VIEW region_sales AS SELECT region,EXTRACT(MONTH FROM sale_date) as sale_month,SUM(sales) as total_sales FROM sales_by_region GROUP BY region,sale_month;
|
SELECT r.region, rs.sale_month, SUM(rs.total_sales) as total_sales FROM regions r JOIN region_sales rs ON r.name = rs.region GROUP BY r.region, rs.sale_month;
|
What are the transaction dates and types for all customers from New York?
|
CREATE TABLE customer (customer_id INT,first_name VARCHAR(50),last_name VARCHAR(50),state VARCHAR(50)); INSERT INTO customer (customer_id,first_name,last_name,state) VALUES (1,'John','Doe','NY'),(2,'Jane','Smith','NJ'); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_date DATE,transaction_type VARCHAR(50)); INSERT INTO transactions (transaction_id,customer_id,transaction_date,transaction_type) VALUES (1,1,'2022-01-01','Withdrawal'),(2,1,'2022-01-05','Deposit'),(3,2,'2022-01-07','Withdrawal');
|
SELECT transaction_date, transaction_type FROM transactions INNER JOIN customer ON transactions.customer_id = customer.customer_id WHERE customer.state = 'NY';
|
List all programs without any attendees
|
CREATE TABLE program_attendees (program_id INT,attendee_id INT); INSERT INTO program_attendees (program_id,attendee_id) VALUES (1,1),(2,3),(3,4),(5,6);
|
SELECT p.name FROM programs p WHERE p.id NOT IN (SELECT program_id FROM program_attendees);
|
What is the total number of workouts performed by male members?
|
CREATE TABLE members (member_id INT,gender VARCHAR(10)); CREATE TABLE workouts (workout_id INT,member_id INT,date DATE); INSERT INTO members VALUES (1,'Female'),(2,'Male'),(3,'Female'); INSERT INTO workouts VALUES (1,1,'2022-01-01'),(2,1,'2022-01-02'),(3,2,'2022-01-03'),(4,3,'2022-01-04'),(5,3,'2022-01-05');
|
SELECT COUNT(*) FROM workouts JOIN members ON workouts.member_id = members.member_id WHERE members.gender = 'Male';
|
List the geological survey information for each mine, including the mine name, coordinates, and geological features, and group the results by country.
|
CREATE TABLE geological_survey (mine_id INT,country TEXT,x_coordinate INT,y_coordinate INT,geological_feature TEXT); INSERT INTO geological_survey (mine_id,country,x_coordinate,y_coordinate,geological_feature) VALUES (1,'Canada',10,20,'Granite'),(1,'Canada',12,22,'Quartz'),(2,'Mexico',15,25,'Shale'),(2,'Mexico',18,28,'Limestone'),(3,'Brazil',30,40,'Iron Ore'); CREATE TABLE mines (mine_id INT,mine_name TEXT); INSERT INTO mines (mine_id,mine_name) VALUES (1,'MineG'),(2,'MineH'),(3,'MineI');
|
SELECT m.mine_name, gs.country, gs.x_coordinate, gs.y_coordinate, gs.geological_feature FROM geological_survey gs JOIN mines m ON gs.mine_id = m.mine_id GROUP BY gs.country;
|
Delete all records from the 'instructors' table where 'expertise' is 'Machine Learning'
|
CREATE TABLE instructors (id INT,name VARCHAR(50),country VARCHAR(50),expertise VARCHAR(50)); INSERT INTO instructors (id,name,country,expertise) VALUES (1,'John Doe','Canada','AI'),(2,'Jane Smith','USA','Data Science'),(3,'Alice Johnson','UK','Machine Learning');
|
DELETE FROM instructors WHERE expertise = 'Machine Learning';
|
What percentage of hotel virtual tours in Tokyo have a rating above 4.5?
|
CREATE TABLE hotel_virtual_tours (hotel_id INT,city VARCHAR(50),rating FLOAT); INSERT INTO hotel_virtual_tours (hotel_id,city,rating) VALUES (1,'Tokyo',4.6),(2,'Tokyo',4.4),(3,'Tokyo',4.2);
|
SELECT city, PERCENTAGE() OVER (PARTITION BY city) as rating_percentage FROM hotel_virtual_tours WHERE rating > 4.5;
|
What is the maximum energy efficiency rating for geothermal power plants in the energy_efficiency schema?
|
CREATE TABLE geothermal_plants (id INT,name VARCHAR(50),location VARCHAR(50),energy_efficiency_rating FLOAT); INSERT INTO geothermal_plants (id,name,location,energy_efficiency_rating) VALUES (1,'Geothermal Plant 1','Country A',0.75); INSERT INTO geothermal_plants (id,name,location,energy_efficiency_rating) VALUES (2,'Geothermal Plant 2','Country B',0.88);
|
SELECT MAX(energy_efficiency_rating) FROM energy_efficiency.geothermal_plants;
|
What is the maximum number of volunteer hours for 'program_x' in '2023'?
|
CREATE TABLE Volunteers (id INT,program_name VARCHAR(20),volunteer_hours INT,volunteer_date DATE); INSERT INTO Volunteers (id,program_name,volunteer_hours,volunteer_date) VALUES (1,'program_x',5,'2022-04-01'); INSERT INTO Volunteers (id,program_name,volunteer_hours,volunteer_date) VALUES (2,'program_y',3,'2022-04-10'); INSERT INTO Volunteers (id,program_name,volunteer_hours,volunteer_date) VALUES (3,'program_x',7,'2023-07-01');
|
SELECT MAX(volunteer_hours) FROM Volunteers WHERE program_name = 'program_x' AND YEAR(volunteer_date) = 2023;
|
Find the attorney with the lowest billing rate in the 'billing' table?
|
CREATE TABLE billing (attorney_id INT,client_id INT,hours FLOAT,rate FLOAT); INSERT INTO billing (attorney_id,client_id,hours,rate) VALUES (1,101,10,300),(2,102,8,350),(3,103,12,250);
|
SELECT attorney_id, MIN(rate) FROM billing;
|
What is the minimum mental health score per school that has more than 50 students?
|
CREATE TABLE students (student_id INT,school_id INT,mental_health_score INT);
|
SELECT school_id, MIN(mental_health_score) as min_score FROM students GROUP BY school_id HAVING COUNT(student_id) > 50;
|
Find the number of patients without health insurance in each rural region.
|
CREATE TABLE patients (id INT,age INT,has_insurance BOOLEAN,has_diabetes BOOLEAN); INSERT INTO patients (id,age,has_insurance,has_diabetes) VALUES (1,55,false,true),(2,45,true,false); CREATE TABLE locations (id INT,region VARCHAR,is_rural BOOLEAN); INSERT INTO locations (id,region,is_rural) VALUES (1,'Texas',true),(2,'California',false);
|
SELECT locations.region, COUNT(patients.id) FROM patients INNER JOIN locations ON patients.id = locations.id WHERE locations.is_rural = true AND patients.has_insurance = false GROUP BY locations.region;
|
What is the average number of research grants awarded per department in the 'research_grants' table, excluding departments with less than 2 grants?
|
CREATE TABLE research_grants (id INT,department VARCHAR(255),amount FLOAT); INSERT INTO research_grants (id,department,amount) VALUES (1,'Computer Science',100000),(2,'Computer Science',200000),(3,'Statistics',150000),(4,'Philosophy',250000);
|
SELECT AVG(grant_count) FROM (SELECT department, COUNT(*) AS grant_count FROM research_grants GROUP BY department HAVING COUNT(*) >= 2) AS subquery;
|
What is the minimum, maximum, and average orbit height for each orbit type, based on the SatelliteOrbits table?
|
CREATE TABLE SatelliteOrbits (SatelliteID INT,OrbitType VARCHAR(50),OrbitHeight INT); INSERT INTO SatelliteOrbits (SatelliteID,OrbitType,OrbitHeight) VALUES (101,'LEO',500),(201,'MEO',8000),(301,'GEO',36000),(401,'LEO',600),(501,'MEO',10000);
|
SELECT OrbitType, MIN(OrbitHeight) AS MinHeight, MAX(OrbitHeight) AS MaxHeight, AVG(OrbitHeight) AS AvgHeight FROM SatelliteOrbits GROUP BY OrbitType;
|
How many heritage sites are in 'Buenos Aires' and 'Rio de Janeiro'?
|
CREATE TABLE heritage_sites (id INT,city VARCHAR(20),num_sites INT); INSERT INTO heritage_sites (id,city,num_sites) VALUES (1,'Buenos Aires',3),(2,'Rio de Janeiro',4),(3,'Sydney',2),(4,'Buenos Aires',5),(5,'Rio de Janeiro',3);
|
SELECT city, SUM(num_sites) FROM heritage_sites GROUP BY city HAVING city IN ('Buenos Aires', 'Rio de Janeiro');
|
How many startups were founded in 2020 by underrepresented racial or ethnic groups?
|
CREATE TABLE startups(id INT,name TEXT,founding_year INT,founder_race TEXT); INSERT INTO startups (id,name,founding_year,founder_race) VALUES (1,'Delta Tech',2020,'African American'); INSERT INTO startups (id,name,founding_year,founder_race) VALUES (2,'Epsilon LLC',2018,'Asian');
|
SELECT COUNT(*) FROM startups WHERE founding_year = 2020 AND founder_race IN ('African American', 'Hispanic', 'Native American', 'Pacific Islander');
|
What is the total number of eco-friendly accommodations in India and their average sustainability scores?
|
CREATE TABLE Scores_India (id INT,country VARCHAR(50),score INT); INSERT INTO Scores_India (id,country,score) VALUES (1,'India',70),(2,'India',75); CREATE TABLE Accommodations_India (id INT,country VARCHAR(50),type VARCHAR(50)); INSERT INTO Accommodations_India (id,country,type) VALUES (1,'India','Eco-Friendly'),(2,'India','Eco-Friendly');
|
SELECT AVG(Scores_India.score) FROM Scores_India INNER JOIN Accommodations_India ON Scores_India.country = Accommodations_India.country WHERE Accommodations_India.type = 'Eco-Friendly' AND Scores_India.country = 'India';
|
List all defense contracts signed in Texas in 2019 with a value greater than 1000000.
|
CREATE TABLE DefenseContracts (contract_id INT,state VARCHAR(255),year INT,value FLOAT); INSERT INTO DefenseContracts (contract_id,state,year,value) VALUES (1,'Texas',2019,1500000),(2,'Texas',2018,800000),(3,'Florida',2019,1200000);
|
SELECT * FROM DefenseContracts WHERE state = 'Texas' AND year = 2019 AND value > 1000000;
|
What are the names of all rural infrastructure projects that started before '2018'?
|
CREATE TABLE rural_infrastructure (id INT,project_name VARCHAR(50),sector VARCHAR(50),start_date DATE,end_date DATE,budget FLOAT); INSERT INTO rural_infrastructure (id,project_name,sector,start_date,end_date,budget) VALUES (1,'Precision Farming Initiative','Agriculture','2017-04-01','2020-12-31',500000);
|
SELECT project_name FROM rural_infrastructure WHERE start_date < '2018-01-01';
|
Identify conservation efforts in the Mediterranean Sea.
|
CREATE TABLE conservation_efforts (effort_id INT,effort_name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO conservation_efforts (effort_id,effort_name,location,start_date,end_date) VALUES (2,'Mediterranean Protection','Mediterranean Sea','2010-01-01','2030-12-31');
|
SELECT * FROM conservation_efforts WHERE location = 'Mediterranean Sea';
|
List all suppliers that provide recycled metal and organic wool materials.
|
CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),material VARCHAR(50)); INSERT INTO suppliers (supplier_id,supplier_name,material) VALUES (1,'Supplier E','recycled metal'),(2,'Supplier F','organic wool'),(3,'Supplier G','organic wool'),(4,'Supplier H','recycled plastic');
|
SELECT supplier_name FROM suppliers WHERE material IN ('recycled metal', 'organic wool') GROUP BY supplier_name HAVING COUNT(DISTINCT material) = 2;
|
What is the total number of traffic violations and misdemeanors committed by gender?
|
CREATE TABLE Traffic_Violations (ID INT,Gender VARCHAR(10),Violation VARCHAR(20)); INSERT INTO Traffic_Violations (ID,Gender,Violation) VALUES (1,'Male','Traffic Violation'),(2,'Female','Misdemeanor');
|
SELECT Gender, COUNT(*) FROM Traffic_Violations GROUP BY Gender;
|
What is the total biomass of salmon and trout farmed in Norway and Scotland?
|
CREATE TABLE FarmA (country VARCHAR(20),species VARCHAR(20),biomass FLOAT); INSERT INTO FarmA (country,species,biomass) VALUES ('Norway','Salmon',450000); INSERT INTO FarmA (country,species,biomass) VALUES ('Norway','Trout',120000); INSERT INTO FarmA (country,species,biomass) VALUES ('Scotland','Salmon',320000); INSERT INTO FarmA (country,species,biomass) VALUES ('Scotland','Trout',160000);
|
SELECT SUM(biomass) FROM FarmA WHERE (country='Norway' AND species IN ('Salmon', 'Trout')) UNION ALL SELECT SUM(biomass) FROM FarmA WHERE country='Scotland' AND species IN ('Salmon', 'Trout');
|
Delete a volunteer
|
CREATE TABLE Volunteers (id INT,name TEXT,program_category TEXT);
|
DELETE FROM Volunteers WHERE id = 3;
|
List all onshore wells in Texas that were drilled after 2010.
|
CREATE TABLE onshore_wells (well_id INT,location VARCHAR(255),drill_date DATE); INSERT INTO onshore_wells (well_id,location,drill_date) VALUES (1,'Texas','2011-01-01'); INSERT INTO onshore_wells (well_id,location,drill_date) VALUES (2,'Oklahoma','2009-01-01');
|
SELECT * FROM onshore_wells WHERE location = 'Texas' AND drill_date > '2010-01-01';
|
Which city generated the least waste in the year 2022?
|
CREATE TABLE waste_generation (city VARCHAR(20),year INT,total_waste_gen FLOAT); INSERT INTO waste_generation (city,year,total_waste_gen) VALUES ('Denver',2022,300000),('Austin',2022,290000),('Dallas',2022,280000);
|
SELECT city, MIN(total_waste_gen) FROM waste_generation GROUP BY year HAVING year = 2022;
|
What was the total number of volunteers by age group in Q1 2022?
|
CREATE TABLE volunteer_age_groups (id INT,age_group VARCHAR(50),volunteer_date DATE,volunteer_hours FLOAT); INSERT INTO volunteer_age_groups (id,age_group,volunteer_date,volunteer_hours) VALUES (1,'18-24','2022-01-01',5.0),(2,'25-34','2022-02-14',8.0),(3,'35-44','2022-03-25',10.0);
|
SELECT age_group, COUNT(*) FROM volunteer_age_groups WHERE YEAR(volunteer_date) = 2022 AND MONTH(volunteer_date) BETWEEN 1 AND 3 GROUP BY age_group;
|
Update the 'gender' column to 'Not Specified' for all records in the 'audience_demographics' table where 'gender' is null
|
CREATE TABLE audience_demographics (article_id INT,audience_age INT,gender VARCHAR(20),location VARCHAR(100));
|
UPDATE audience_demographics SET gender = 'Not Specified' WHERE gender IS NULL;
|
What is the average property price in eco-friendly neighborhoods?
|
CREATE TABLE properties (property_id INT,price FLOAT,neighborhood VARCHAR(255)); INSERT INTO properties (property_id,price,neighborhood) VALUES (1,500000,'Eco Village'); INSERT INTO properties (property_id,price,neighborhood) VALUES (2,600000,'Green Meadows');
|
SELECT AVG(price) FROM properties JOIN neighborhoods ON properties.neighborhood = neighborhoods.name WHERE neighborhoods.eco_friendly = true;
|
What is the average cost of green building materials for projects in the 'smart_cities' schema?
|
CREATE TABLE green_materials (project_id INT,material_name TEXT,cost FLOAT); INSERT INTO green_materials (project_id,material_name,cost) VALUES (1,'solar panels',15000.0),(1,'smart glass',25000.0),(2,'wind turbines',30000.0),(2,'geothermal systems',40000.0);
|
SELECT AVG(cost) FROM green_materials WHERE project_id IN (SELECT project_id FROM projects WHERE schema_name = 'smart_cities') AND material_name = 'green building materials';
|
What is the total weight loss in pounds for members who have lost weight since they joined?
|
CREATE TABLE health_metrics (member_id INT,weight_loss_pounds FLOAT,last_checked DATE); INSERT INTO health_metrics (member_id,weight_loss_pounds,last_checked) VALUES (1,3,'2021-01-15'),(2,7,'2022-03-28');
|
SELECT SUM(weight_loss_pounds) FROM health_metrics JOIN members ON health_metrics.member_id = members.member_id WHERE health_metrics.weight_loss_pounds > 0;
|
What is the percentage of movies directed by women in each country?
|
CREATE TABLE movies (movie_id INT,movie_title VARCHAR(100),release_year INT,country VARCHAR(50),director_id INT); CREATE TABLE directors (director_id INT,director_name VARCHAR(50),director_gender VARCHAR(10)); INSERT INTO movies (movie_id,movie_title,release_year,country,director_id) VALUES (1,'Gladiator',2000,'USA',1); INSERT INTO directors (director_id,director_name,director_gender) VALUES (1,'Ridley Scott','Male');
|
SELECT country, ROUND(100.0 * COUNT(CASE WHEN d.director_gender = 'Female' THEN 1 END) / COUNT(*), 2) as percentage_female_directors FROM movies m INNER JOIN directors d ON m.director_id = d.director_id GROUP BY country;
|
Identify the top 2 countries with the highest total production of Dysprosium in 2021 and their respective production amounts.
|
CREATE TABLE Country (Code TEXT,Name TEXT,Continent TEXT); INSERT INTO Country (Code,Name,Continent) VALUES ('CN','China','Asia'),('AU','Australia','Australia'),('US','United States','North America'),('IN','India','Asia'); CREATE TABLE ProductionCountry (Year INT,Country TEXT,Element TEXT,Quantity INT); INSERT INTO ProductionCountry (Year,Country,Element,Quantity) VALUES (2021,'CN','Dysprosium',1500),(2021,'AU','Dysprosium',800),(2021,'US','Dysprosium',1200),(2021,'IN','Dysprosium',900);
|
SELECT Country, SUM(Quantity) FROM ProductionCountry WHERE Element = 'Dysprosium' AND Year = 2021 GROUP BY Country ORDER BY SUM(Quantity) DESC FETCH FIRST 2 ROWS ONLY;
|
How many artworks were created by female artists from the 17th century?
|
CREATE TABLE artists (id INT,name VARCHAR(50),birthdate DATE);CREATE TABLE artworks (id INT,title VARCHAR(50),artist_id INT,creation_date DATE); INSERT INTO artists (id,name,birthdate) VALUES (1,'Artemisia Gentileschi','1593-07-08'); INSERT INTO artworks (id,title,artist_id,creation_date) VALUES (1,'Judith Slaying Holofernes','1614-01-01');
|
SELECT COUNT(a.id) FROM artists a INNER JOIN artworks ar ON a.id = ar.artist_id WHERE a.birthdate <= '1600-12-31' AND a.gender = 'female';
|
What percentage of cruelty-free haircare products are sold in the UK?
|
CREATE TABLE haircare_sales (product_id INT,product_name VARCHAR(255),sale_price DECIMAL(10,2),is_cruelty_free BOOLEAN,country VARCHAR(255)); CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255)); INSERT INTO haircare_sales (product_id,product_name,sale_price,is_cruelty_free,country) VALUES (1,'Shampoo',15.99,true,'UK'),(2,'Conditioner',12.99,false,'UK'); INSERT INTO products (product_id,product_name,category) VALUES (1,'Shampoo','Haircare'),(2,'Conditioner','Haircare');
|
SELECT (COUNT(haircare_sales.product_id) * 100.0 / (SELECT COUNT(*) FROM haircare_sales WHERE country = 'UK')) AS percentage FROM haircare_sales INNER JOIN products ON haircare_sales.product_id = products.product_id WHERE haircare_sales.is_cruelty_free = true AND products.category = 'Haircare';
|
Update the 'officers' table: change the first_name to 'Officer' for records with last_name 'Smith'
|
CREATE TABLE officers (officer_id INT,first_name VARCHAR(20),last_name VARCHAR(20)); INSERT INTO officers (officer_id,first_name,last_name) VALUES (1,'John','Smith'),(2,'Jane','Doe'),(3,'Mike','Johnson');
|
UPDATE officers SET first_name = 'Officer' WHERE last_name = 'Smith';
|
What is the distribution of grants by type?
|
CREATE TABLE GrantTypes (GrantID int,GrantType varchar(20),GrantAmount decimal(10,2)); INSERT INTO GrantTypes (GrantID,GrantType,GrantAmount) VALUES (1,'Operational',20000.00),(2,'Programmatic',30000.00),(3,'Operational',15000.00);
|
SELECT GrantType, COUNT(GrantID) AS GrantCount FROM GrantTypes GROUP BY GrantType;
|
What is the total number of hours volunteered by volunteers from the 'healthcare' sector in the year 2021?
|
CREATE TABLE volunteer_hours (hour_id INT,volunteer_id INT,hour_date DATE,hours FLOAT); INSERT INTO volunteer_hours (hour_id,volunteer_id,hour_date,hours) VALUES (1,1,'2021-01-01',5.00),(2,2,'2021-02-01',10.00);
|
SELECT SUM(hours) FROM volunteer_hours INNER JOIN volunteers ON volunteer_hours.volunteer_id = volunteers.volunteer_id WHERE volunteers.sector = 'healthcare' AND YEAR(hour_date) = 2021;
|
What is the total budget allocated for military innovation projects by NATO in the last 5 years?
|
CREATE TABLE Innovation (project VARCHAR(255),budget INT,sponsor VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO Innovation (project,budget,sponsor,start_date,end_date) VALUES ('Stealth Technology',20000000,'NATO','2018-01-01','2022-12-31');
|
SELECT SUM(budget) FROM Innovation WHERE sponsor = 'NATO' AND start_date >= DATE(NOW()) - INTERVAL 5 YEAR;
|
What is the total number of cultural heritage sites in Spain that were built before the year 1800?
|
CREATE TABLE CulturalHeritageSites (name VARCHAR(50),location VARCHAR(20),year INT);
|
SELECT COUNT(*) FROM CulturalHeritageSites WHERE location = 'Spain' AND year < 1800;
|
List the number of buses in the fleet by manufacturer
|
CREATE TABLE transit_fleet (fleet_id INT,manufacturer TEXT,vehicle_type TEXT); INSERT INTO transit_fleet (fleet_id,manufacturer,vehicle_type) VALUES (1,'Manufacturer A','Bus'),(2,'Manufacturer B','Bus');
|
SELECT manufacturer, COUNT(*) FROM transit_fleet WHERE vehicle_type = 'Bus' GROUP BY manufacturer;
|
Delete all records from the 'Music_Artists' table with a genre of 'K-Pop'.
|
CREATE TABLE Music_Artists (id INT,name VARCHAR(100),genre VARCHAR(50),country VARCHAR(50)); INSERT INTO Music_Artists (id,name,genre,country) VALUES (1,'BTS','K-Pop','South Korea'); INSERT INTO Music_Artists (id,name,genre,country) VALUES (2,'Blackpink','K-Pop','South Korea');
|
DELETE FROM Music_Artists WHERE genre = 'K-Pop';
|
What is the average carbon sequestration in metric tons for the forests in the temperate region?
|
CREATE TABLE forest (id INT,name TEXT,region TEXT,avg_carbon_tonnes FLOAT);
|
SELECT AVG(avg_carbon_tonnes) FROM forest WHERE region = 'temperate';
|
Find the number of bike-share trips in May 2022 for users over 65 in Madrid
|
CREATE TABLE bike_trips (id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,trip_city VARCHAR(50),trip_user_age INT);
|
SELECT EXTRACT(MONTH FROM trip_start_time) AS month, COUNT(*) AS num_trips
|
Delete all posts with the word 'Python' in the content made before 2022-01-01
|
CREATE TABLE posts (id INT,user_id INT,content TEXT,post_date DATE); INSERT INTO posts (id,user_id,content,post_date) VALUES (1,1,'Hello World','2021-12-31'),(2,1,'I love data','2022-01-01');
|
DELETE FROM posts WHERE content LIKE '%Python%' AND post_date < '2022-01-01';
|
What is the average CO2 emissions per day for mining operations in Canada, for the past year, partitioned by the mining type?
|
CREATE TABLE mining_operations (id INT,mining_type VARCHAR(255),country VARCHAR(255),co2_emissions FLOAT,operation_date DATE); INSERT INTO mining_operations (id,mining_type,country,co2_emissions,operation_date) VALUES (1,'open pit','Canada',500,'2021-01-01'),(2,'underground','Canada',700,'2021-02-01'),(3,'open pit','Canada',600,'2021-03-01');
|
SELECT mining_type, AVG(co2_emissions / DATEDIFF(day, operation_date, GETDATE())) as avg_co2_emissions_per_day FROM mining_operations WHERE country = 'Canada' AND operation_date >= DATEADD(year, -1, GETDATE()) GROUP BY mining_type;
|
What is the total number of polar bears in each Arctic region?
|
CREATE TABLE PolarBears(region VARCHAR(255),population_size FLOAT);
|
SELECT region, SUM(population_size) FROM PolarBears GROUP BY region;
|
Get the daily production for the past week for wells in the Marcellus Shale
|
CREATE TABLE production (well_id INT,date DATE,quantity FLOAT,state VARCHAR(2)); INSERT INTO production (well_id,date,quantity,state) VALUES (1,'2021-01-01',100.0,'PA'),(1,'2021-01-02',120.0,'PA'),(2,'2021-01-01',150.0,'OK');
|
SELECT well_id, date, quantity FROM production p JOIN wells w ON p.well_id = w.id WHERE w.state = 'PA' AND p.date >= DATEADD(day, -7, CURRENT_DATE);
|
Show green building projects in 'Oceania' and their carbon offsets
|
CREATE TABLE green_buildings (id INT,name VARCHAR(100),location VARCHAR(50),carbon_offset FLOAT,region VARCHAR(10)); INSERT INTO green_buildings (id,name,location,carbon_offset,region) VALUES (1,'Green Building A','Sydney',500.3,'Oceania'); INSERT INTO green_buildings (id,name,location,carbon_offset,region) VALUES (2,'Green Building B','Melbourne',400.2,'Oceania');
|
SELECT name, carbon_offset FROM green_buildings WHERE region = 'Oceania';
|
Find the number of unique fans who attended games in the last 30 days
|
CREATE TABLE fan_attendance (fan_id INT,game_date DATE);
|
SELECT COUNT(DISTINCT fan_id) FROM fan_attendance WHERE game_date >= CURDATE() - INTERVAL 30 DAY;
|
Which regions have the highest and lowest ocean acidification levels?
|
CREATE TABLE ocean_acidification (region TEXT,level FLOAT); INSERT INTO ocean_acidification (region,level) VALUES ('Arctic Ocean',7.9),('Atlantic Ocean',8.1),('Indian Ocean',8.0),('Pacific Ocean',8.2);
|
SELECT region, level FROM (SELECT region, level, RANK() OVER (ORDER BY level DESC) AS rank FROM ocean_acidification) AS ranked_ocean_acidification WHERE rank = 1 OR rank = (SELECT COUNT(*) FROM ocean_acidification)
|
How many space missions were successfully completed by 'ISA'?
|
CREATE TABLE SpaceMissions (id INT,name VARCHAR(50),agency VARCHAR(50),status VARCHAR(10)); INSERT INTO SpaceMissions (id,name,agency,status) VALUES (1,'Ares 1','NASA','failed'),(2,'Artemis 1','ISA','success'),(3,'Apollo 11','NASA','success');
|
SELECT COUNT(*) FROM SpaceMissions WHERE agency = 'ISA' AND status = 'success';
|
Add a new exit strategy for a company: acquisition.
|
CREATE TABLE exit_strategies (id INT,company_id INT,type TEXT); INSERT INTO exit_strategies (id,company_id,type) VALUES (1,1,'IPO');
|
INSERT INTO exit_strategies (id, company_id, type) VALUES (2, 1, 'acquisition');
|
Delete records of cargo with a name containing 'oil' from the CARGO table
|
CREATE TABLE CARGO (ID INT,VESSEL_ID INT,CARGO_NAME VARCHAR(50),WEIGHT INT);
|
DELETE FROM CARGO WHERE CARGO_NAME LIKE '%oil%';
|
What is the minimum depth reached by any marine species in the Indian basin?
|
CREATE TABLE marine_species_min_depths (name VARCHAR(255),basin VARCHAR(255),depth FLOAT); INSERT INTO marine_species_min_depths (name,basin,depth) VALUES ('Species1','Atlantic',123.45),('Species2','Pacific',567.89),('Species3','Indian',345.67),('Species4','Atlantic',789.10);
|
SELECT MIN(depth) as min_depth FROM marine_species_min_depths WHERE basin = 'Indian';
|
What is the total salary cost for employees who identify as non-binary and work in the HR department?
|
SAME AS ABOVE
|
SELECT SUM(Employees.Salary) FROM Employees WHERE Gender = 'Non-binary' AND Department = 'HR';
|
Identify the top 2 regions with the highest total donation amount, excluding regions with less than 5 donations.
|
CREATE TABLE donations (donor_id INT,region VARCHAR(20),donation_amount INT); INSERT INTO donations VALUES (1,'Northeast',500),(1,'Northeast',600),(2,'Northeast',700),(3,'Midwest',200),(3,'Midwest',300),(3,'Midwest',400),(4,'South',1000),(4,'South',1500),(4,'South',2000),(5,'West',50),(5,'West',100);
|
SELECT region, SUM(donation_amount) FROM donations GROUP BY region HAVING COUNT(*) >= 5 ORDER BY SUM(donation_amount) DESC LIMIT 2;
|
What is the maximum quantity of a sustainable ingredient used in a week?
|
CREATE TABLE Usage (id INT,ingredient VARCHAR(20),quantity INT,usage_date DATE); INSERT INTO Usage (id,ingredient,quantity,usage_date) VALUES (1,'Quinoa',50,'2022-01-01'),(2,'Rice',75,'2022-01-02');
|
SELECT ingredient, MAX(quantity) FROM Usage WHERE usage_date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) AND ingredient IN ('Quinoa', 'Rice', 'Pasta') GROUP BY ingredient;
|
What is the percentage of students who have completed a mental health screening in the last month?
|
CREATE TABLE Students (StudentID INT PRIMARY KEY,MentalHealthScreening DATE); INSERT INTO Students (StudentID,MentalHealthScreening) VALUES (1,'2022-02-10');
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Students)) AS Percentage FROM Students WHERE MentalHealthScreening >= DATEADD(month, -1, GETDATE());
|
How many units of organic skincare products are sold in the EU in the last quarter?
|
CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); CREATE TABLE products (product_id INT,product_name VARCHAR(100),category VARCHAR(50),is_organic BOOLEAN,country VARCHAR(50));
|
SELECT SUM(quantity) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.category = 'Skincare' AND products.is_organic = TRUE AND sales.sale_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 3 MONTH) AND products.country IN ('DE', 'FR', 'IT', 'ES', 'PL', 'NL');
|
What is the average rating of products produced in Italy?
|
CREATE TABLE products (product_id INT,name TEXT,rating FLOAT,country TEXT); INSERT INTO products (product_id,name,rating,country) VALUES (1,'Shirt',4.5,'Italy'); INSERT INTO products (product_id,name,rating,country) VALUES (2,'Pants',4.2,'France');
|
SELECT AVG(rating) FROM products WHERE country = 'Italy';
|
Delete all records from the oceanography table where the depth is less than 2000 meters
|
CREATE TABLE oceanography (id INT PRIMARY KEY,location VARCHAR(255),depth INT,salinity DECIMAL(5,2),temperature DECIMAL(5,2));
|
DELETE FROM oceanography WHERE depth < 2000;
|
What was the average flight time for each aircraft model?
|
CREATE TABLE aircraft (id INT,model VARCHAR(255),flight_time FLOAT); INSERT INTO aircraft (id,model,flight_time) VALUES (1,'747',450.3),(2,'777',396.8),(3,'787',402.5);
|
SELECT model, AVG(flight_time) avg_flight_time FROM aircraft GROUP BY model;
|
What is the average price of menu items for each cuisine type in the past year?
|
CREATE TABLE MenuItems (MenuItemID int,RestaurantID int,CuisineType varchar(255),Price decimal(5,2),PriceDate date); INSERT INTO MenuItems (MenuItemID,RestaurantID,CuisineType,Price,PriceDate) VALUES (1,1,'Italian',12.99,'2021-01-01'),(2,2,'Mexican',8.99,'2021-02-01'),(3,3,'Chinese',10.99,'2021-03-01');
|
SELECT R.CuisineType, AVG(MI.Price) as AvgPrice FROM Restaurants R INNER JOIN MenuItems MI ON R.RestaurantID = MI.RestaurantID WHERE MI.PriceDate >= DATEADD(year, -1, GETDATE()) GROUP BY R.CuisineType;
|
What is the average food safety score for restaurants in each region?
|
CREATE TABLE inspections (id INT,restaurant_id INT,region VARCHAR(50),safety_score INT); CREATE VIEW region_safety AS SELECT restaurant_id,AVG(safety_score) as avg_safety FROM inspections GROUP BY restaurant_id;
|
SELECT r.region, AVG(i.safety_score) as avg_safety FROM inspections i JOIN region_safety rs ON i.restaurant_id = rs.restaurant_id JOIN restaurants r ON i.restaurant_id = r.id GROUP BY r.region;
|
What is the minimum recycling rate in the state of New York?
|
CREATE TABLE recycling_rates (state VARCHAR(2),recycling_rate DECIMAL(4,2)); INSERT INTO recycling_rates (state,recycling_rate) VALUES ('US',35.01),('CA',50.03),('NY',25.10);
|
SELECT MIN(recycling_rate) FROM recycling_rates WHERE state = 'NY';
|
Find the total revenue of sustainable tourism in Japan.
|
CREATE TABLE tourism_revenue (region TEXT,revenue FLOAT); INSERT INTO tourism_revenue (region,revenue) VALUES ('Japan',2000000),('USA',3000000);
|
SELECT SUM(revenue) FROM tourism_revenue WHERE region = 'Japan';
|
Find the total number of policies issued in 'New York' and 'Texas'?
|
CREATE TABLE policies (id INT,policy_number TEXT,city TEXT,state TEXT); INSERT INTO policies (id,policy_number,city,state) VALUES (1,'P1234','New York','NY'); INSERT INTO policies (id,policy_number,city,state) VALUES (2,'P5678','New York','NY'); INSERT INTO policies (id,policy_number,city,state) VALUES (3,'P9012','Houston','TX');
|
SELECT COUNT(*) FROM policies WHERE state IN ('NY', 'TX');
|
What is the minimum food safety score for restaurants in New York?
|
CREATE TABLE food_safety_inspections(restaurant VARCHAR(255),score INT,city VARCHAR(255)); INSERT INTO food_safety_inspections(restaurant,score,city) VALUES ('Restaurant1',95,'New York'),('Restaurant2',85,'Los Angeles'),('Restaurant3',90,'New York'),('Restaurant4',92,'San Francisco'),('Restaurant5',88,'San Francisco');
|
SELECT MIN(score) FROM food_safety_inspections WHERE city = 'New York';
|
Show the number of articles published per month in 2022
|
CREATE TABLE articles (id INT PRIMARY KEY,date DATE,is_published BOOLEAN); INSERT INTO articles (id,date,is_published) VALUES (1,'2022-01-01',true),(2,'2022-02-01',false),(3,'2022-03-01',true),(4,'2022-04-01',true),(5,'2023-01-01',false);
|
SELECT MONTH(date), COUNT(*) FROM articles WHERE YEAR(date) = 2022 AND is_published = true GROUP BY MONTH(date);
|
List the titles and release years of the TV shows produced in Canada and have a rating of 8 or higher, categorized by genre?
|
CREATE TABLE tv_shows (id INT,title VARCHAR(255),rating FLOAT,release_year INT,country VARCHAR(50),genre VARCHAR(50)); INSERT INTO tv_shows (id,title,rating,release_year,country,genre) VALUES (1,'Show1',8.5,2010,'Canada','Comedy'),(2,'Show2',8.2,2012,'Canada','Drama'),(3,'Show3',6.8,2015,'Canada','Action');
|
SELECT title, release_year, genre FROM tv_shows WHERE rating >= 8 AND country = 'Canada' GROUP BY title, release_year, genre;
|
How many public transportation services are available in each province, and what is their ranking based on availability?
|
CREATE TABLE PublicTransit (Province VARCHAR(255),Service VARCHAR(255)); INSERT INTO PublicTransit (Province,Service) VALUES ('Alberta','Calgary Transit'),('British Columbia','TransLink'),('Ontario','Toronto Transit Commission'),('Quebec','Société de transport de Montréal'),('Alberta','Edmonton Transit Service');
|
SELECT Province, Service, ROW_NUMBER() OVER (PARTITION BY Province ORDER BY Service) AS Rank FROM PublicTransit;
|
Which programs had the highest and lowest total financial impact in the last fiscal year?
|
CREATE TABLE Programs (ProgramID int,ProgramName varchar(50),StartDate date,EndDate date); CREATE TABLE ProgramFinancials (ProgramID int,Year int,Amount float);
|
SELECT ProgramName, CASE WHEN Amount = (SELECT MAX(Amount) FROM ProgramFinancials WHERE Year = (SELECT EXTRACT(YEAR FROM MIN(StartDate)) FROM Programs)) THEN 'Highest' ELSE 'Lowest' END AS FinancialImpact FROM Programs JOIN ProgramFinancials ON Programs.ProgramID = ProgramFinancials.ProgramID WHERE Year = (SELECT EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM MIN(StartDate)) + 1 FROM Programs) GROUP BY ProgramName, Amount HAVING COUNT(*) = 1;
|
Create a table named 'military_innovations'
|
CREATE TABLE military_innovations (id INT PRIMARY KEY,innovation VARCHAR(255),year INT,country VARCHAR(255));
|
CREATE TABLE military_innovations (id INT PRIMARY KEY, innovation VARCHAR(255), year INT, country VARCHAR(255));
|
Find the year with the most safety incidents
|
CREATE TABLE yearly_incidents (year INT,incidents INT); INSERT INTO yearly_incidents (year,incidents) VALUES (2018,26),(2019,30),(2020,29);
|
SELECT year, MAX(incidents) FROM yearly_incidents;
|
How many artworks were created each year by Asian artists?
|
CREATE TABLE Artworks (id INT,artist VARCHAR(20),title VARCHAR(50),year INT,type VARCHAR(20)); INSERT INTO Artworks (id,artist,title,year,type) VALUES (1,'Asian Artist 1','Artwork 1',2000,'Painting'); INSERT INTO Artworks (id,artist,title,year,type) VALUES (2,'Asian Artist 2','Artwork 2',2005,'Sculpture');
|
SELECT year, COUNT(*) AS artworks_per_year FROM Artworks WHERE artist LIKE 'Asian Artist%' GROUP BY year ORDER BY year;
|
Find the maximum water usage by residential customers in the month of March 2022.
|
CREATE TABLE residential (customer_id INT,water_usage FLOAT,usage_date DATE); INSERT INTO residential (customer_id,water_usage,usage_date) VALUES (1,150.5,'2022-03-01'),(2,250.7,'2022-03-02'),(3,350.8,'2022-03-03');
|
SELECT MAX(water_usage) FROM residential WHERE usage_date BETWEEN '2022-03-01' AND '2022-03-31';
|
What is the total number of workplaces with successful collective bargaining agreements in Canada in 2020?
|
CREATE TABLE workplaces (id INT,country VARCHAR(50),num_employees INT,has_cba BOOLEAN); INSERT INTO workplaces (id,country,num_employees,has_cba) VALUES (1,'Canada',200,true),(2,'USA',300,false);
|
SELECT COUNT(*) FROM workplaces WHERE country = 'Canada' AND has_cba = true;
|
List the mining sites in the 'Africa' region with environmental impact scores above 80.
|
CREATE TABLE mining_sites (id INT,site_name VARCHAR(50),location VARCHAR(50),environmental_score FLOAT); INSERT INTO mining_sites (id,site_name,location,environmental_score) VALUES (1,'Site A','Australia',82.50);
|
SELECT site_name, environmental_score FROM mining_sites WHERE location LIKE 'Africa' AND environmental_score > 80.00;
|
Update the year of artwork with ID 7 to 1889
|
CREATE TABLE ArtWorks (ID INT PRIMARY KEY,Title TEXT,Artist TEXT,Year INT);
|
UPDATE ArtWorks SET Year = 1889 WHERE ID = 7;
|
Delete all records from the 'conservation' table that are older than 2005
|
CREATE TABLE conservation (id INT PRIMARY KEY,artifact_id INT,date DATE,notes TEXT);
|
DELETE FROM conservation WHERE date < '2005-01-01';
|
What is the minimum delivery time in days for shipments from India to the United Kingdom in April 2021?
|
CREATE TABLE deliveries (id INT,shipment_id INT,delivery_date DATE,delivery_time_days INT); INSERT INTO deliveries (id,shipment_id,delivery_date,delivery_time_days) VALUES (1,1,'2021-04-01',5); INSERT INTO deliveries (id,shipment_id,delivery_date,delivery_time_days) VALUES (2,2,'2021-04-03',7);
|
SELECT MIN(delivery_time_days) FROM deliveries D INNER JOIN (SELECT id AS shipment_id FROM shipments WHERE origin_country = 'India' AND destination_country = 'United Kingdom' AND EXTRACT(MONTH FROM ship_date) = 4 AND EXTRACT(YEAR FROM ship_date) = 2021) AS S ON D.shipment_id = S.shipment_id;
|
How many electric vehicles have been sold in California since 2018?
|
CREATE TABLE VehicleSales (id INT,vehicle_type VARCHAR(255),sale_date DATE,units_sold INT); INSERT INTO VehicleSales (id,vehicle_type,sale_date,units_sold) VALUES (1,'Gasoline','2017-01-01',500); INSERT INTO VehicleSales (id,vehicle_type,sale_date,units_sold) VALUES (2,'Electric','2020-01-01',800);
|
SELECT SUM(units_sold) FROM VehicleSales WHERE vehicle_type = 'Electric' AND sale_date >= '2018-01-01';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.