instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Insert a new record for a local, organic vegetable supplier in the suppliers table.
CREATE TABLE suppliers (id INT,name VARCHAR(255),country VARCHAR(255),sustainability_score INT,local BOOLEAN,organic BOOLEAN);
INSERT INTO suppliers (id, name, country, sustainability_score, local, organic) VALUES (1, 'Local Organic Veggies', 'USA', 95, true, true);
Delete all astrobiology records with a discovery_date before 2005-01-01 from the astrobiology_data table
CREATE TABLE astrobiology_data (record_id INT,name VARCHAR(255),discovery_date DATE); INSERT INTO astrobiology_data (record_id,name,discovery_date) VALUES (1,'Discovery 1','2000-12-25'),(2,'Discovery 2','2007-06-18'),(3,'Discovery 3','2003-11-05');
DELETE FROM astrobiology_data WHERE discovery_date < '2005-01-01';
What is the minimum fare for ferries in San Francisco?
CREATE TABLE ferries (id INT,city VARCHAR(50),fare DECIMAL(5,2)); INSERT INTO ferries (id,city,fare) VALUES (1,'San Francisco',6.50),(2,'San Francisco',7.00),(3,'New York',4.00);
SELECT MIN(fare) FROM ferries WHERE city = 'San Francisco';
What is the total cost of building permits for contractors implementing sustainable practices?
CREATE TABLE Contractors (ContractorID INT,ContractorName VARCHAR(50),City VARCHAR(50),State VARCHAR(2),Country VARCHAR(50)); CREATE TABLE BuildingPermits (PermitID INT,ContractorID INT,PermitDate DATE,PermitType VARCHAR(50),Cost FLOAT); CREATE TABLE SustainablePractices (PracticeID INT,ContractorID INT,PracticeType VARCHAR(50),ImplementationDate DATE); INSERT INTO Contractors (ContractorID,ContractorName,City,State,Country) VALUES (3,'JKL Construction','Chicago','IL','USA'); INSERT INTO BuildingPermits (PermitID,ContractorID,PermitDate,PermitType,Cost) VALUES (1,3,'2022-01-01','Residential',60000); INSERT INTO SustainablePractices (PracticeID,ContractorID,PracticeType,ImplementationDate) VALUES (1,3,'Green Roofs','2022-02-01');
SELECT ContractorID FROM SustainablePractices; SELECT SUM(Cost) FROM BuildingPermits WHERE ContractorID IN (SELECT ContractorID FROM SustainablePractices);
Calculate the average funding for biotech startups in a specific year.
CREATE TABLE startups (id INT,name VARCHAR(50),location VARCHAR(50),industry VARCHAR(50),funding FLOAT,year INT);
SELECT AVG(funding) FROM startups WHERE industry = 'biotech' AND year = 2019;
Identify the number of public transit users in New York City by subway line.
CREATE TABLE subway_ridership (user_id INT,trip_date DATE,trip_subway_line VARCHAR(20)); INSERT INTO subway_ridership (user_id,trip_date,trip_subway_line) VALUES (1,'2022-01-01','4'),(2,'2022-01-01','6');
SELECT trip_subway_line, COUNT(DISTINCT user_id) AS unique_users FROM subway_ridership GROUP BY trip_subway_line;
Determine the percentage of players who play FPS games
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),GameType VARCHAR(50)); INSERT INTO Players (PlayerID,PlayerName,GameType) VALUES (1,'John Doe','FPS'); INSERT INTO Players (PlayerID,PlayerName,GameType) VALUES (2,'Jane Smith','RPG'); INSERT INTO Players (PlayerID,PlayerName,GameType) VALUES (3,'Mike Johnson','FPS');
SELECT (COUNT(*) FILTER (WHERE GameType = 'FPS') * 100.0 / COUNT(*)) FROM Players;
List all smart contracts associated with a given address?
CREATE TABLE smart_contracts (contract_id INT,address VARCHAR(42),name VARCHAR(255));
SELECT contract_id, name FROM smart_contracts WHERE address = '0x1234567890abcdef1234567890abcdef';
What is the average AI ethics budget per organization in North America?
CREATE TABLE org_ai_ethics_budget (org_name VARCHAR(255),budget NUMERIC(10,2)); INSERT INTO org_ai_ethics_budget (org_name,budget) VALUES ('OrgA',50000),('OrgB',75000),('OrgC',60000);
SELECT AVG(budget) OVER (PARTITION BY CASE WHEN org_name LIKE 'North%' THEN 1 ELSE 0 END) as avg_budget FROM org_ai_ethics_budget;
What is the total revenue for each music genre in Q1 2022?
CREATE TABLE MusicStreaming(Genre VARCHAR(20),Revenue DECIMAL(10,2),Date DATE); INSERT INTO MusicStreaming(Genre,Revenue,Date) VALUES ('Pop',5000,'2022-01-01'),('Rock',6000,'2022-01-01'),('Jazz',3000,'2022-01-01'),('Pop',5500,'2022-02-01'),('Rock',6500,'2022-02-01'),('Jazz',3200,'2022-02-01'),('Pop',6000,'2022-03-01'),('Rock',7000,'2022-03-01'),('Jazz',3500,'2022-03-01');
SELECT Genre, SUM(Revenue) as Total_Revenue FROM MusicStreaming WHERE Date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY Genre;
Which marine protected areas have a maximum depth of 1000 meters?
CREATE TABLE shallow_protected_areas (area_name TEXT,max_depth REAL); INSERT INTO shallow_protected_areas (area_name,max_depth) VALUES ('Bermuda Triangle',750.0),('Belize Barrier Reef',914.0),('Seychelles Bank',1000.0);
SELECT area_name FROM shallow_protected_areas WHERE max_depth <= 1000.0;
What was the distribution of attendees by age group for each event in '2021'?
CREATE TABLE Attendees (attendee_id INT,event_id INT,age_group VARCHAR(50),attendee_date DATE); INSERT INTO Attendees (attendee_id,event_id,age_group,attendee_date) VALUES (4,4,'18-24','2021-01-01'),(5,5,'25-34','2021-02-01'),(6,6,'35-44','2021-03-01');
SELECT event_id, age_group, COUNT(*) AS num_attendees FROM Attendees WHERE YEAR(attendee_date) = 2021 GROUP BY event_id, age_group;
List all programs and their respective volunteer managers.
CREATE TABLE programs (id INT,name VARCHAR,manager_id INT); CREATE TABLE volunteers (id INT,name VARCHAR,program_id INT);
SELECT programs.name as program_name, managers.name as manager_name FROM programs INNER JOIN volunteers ON programs.id = volunteers.program_id INNER JOIN donors d ON d.id = volunteers.manager_id;
Determine the total number of military equipment sold by all defense contractors to India?
CREATE TABLE GeneralDynamicsSales (country TEXT,quantity INT,year INT); INSERT INTO GeneralDynamicsSales VALUES ('India',10,2020); CREATE TABLE BoeingSales (country TEXT,quantity INT,year INT); INSERT INTO BoeingSales VALUES ('India',20,2020); CREATE TABLE LockheedMartinSales (country TEXT,quantity INT,year INT); INSERT INTO LockheedMartinSales VALUES ('India',30,2020);
SELECT SUM(GeneralDynamicsSales.quantity + BoeingSales.quantity + LockheedMartinSales.quantity) AS TotalQuantity
Calculate the percentage of students who have completed a support program, grouped by the program type.
CREATE TABLE Student (StudentID INT,StudentName VARCHAR(50)); INSERT INTO Student (StudentID,StudentName) VALUES (1,'John Doe'); INSERT INTO Student (StudentID,StudentName) VALUES (2,'Jane Smith'); INSERT INTO Student (StudentID,StudentName) VALUES (3,'Michael Lee'); CREATE TABLE SupportProgram (ProgramID INT,ProgramName VARCHAR(50),StudentID INT,ProgramCompletion DATE); INSERT INTO SupportProgram (ProgramID,ProgramName,StudentID,ProgramCompletion) VALUES (1,'Tutoring',1,'2021-01-01'); INSERT INTO SupportProgram (ProgramID,ProgramName,StudentID,ProgramCompletion) VALUES (2,'Mentoring',1,'2021-03-01'); INSERT INTO SupportProgram (ProgramID,ProgramName,StudentID,ProgramCompletion) VALUES (3,'Disability Support',2,NULL);
SELECT ProgramName, (COUNT(*) * 100.0 / NULLIF(SUM(CASE WHEN ProgramCompletion IS NOT NULL THEN 1 END) OVER (PARTITION BY NULL), 0)) AS Percentage FROM SupportProgram JOIN Student ON SupportProgram.StudentID = Student.StudentID GROUP BY ProgramName;
Delete records in the 'vehicle_sales' table where the 'sale_year' is before 2018
CREATE TABLE vehicle_sales (id INT,vehicle_type VARCHAR(255),sale_year INT,price FLOAT);
DELETE FROM vehicle_sales WHERE sale_year < 2018;
List posts with hashtags related to 'food' and 'restaurants' in descending order of likes, excluding posts with less than 10 likes.
CREATE TABLE users (id INT,name VARCHAR(255),page_name VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,page_name VARCHAR(255),content TEXT); CREATE TABLE likes (id INT,user_id INT,post_id INT); CREATE TABLE hashtags (id INT,post_id INT,tag VARCHAR(255));
SELECT DISTINCT posts.id, posts.content FROM posts JOIN hashtags ON posts.id = hashtags.post_id JOIN likes ON posts.id = likes.post_id WHERE hashtags.tag IN ('food', 'restaurants') GROUP BY posts.id HAVING COUNT(*) > 10 ORDER BY COUNT(*) DESC;
Delete records of menu items without a price
CREATE TABLE menu_items (item_id INT,item_name VARCHAR(255),price DECIMAL(5,2));
DELETE FROM menu_items WHERE price IS NULL;
What is the average military expenditure as a percentage of GDP for each region in the past decade?
CREATE TABLE Military_Expenditure (year INT,country VARCHAR(50),amount FLOAT,gdp FLOAT); CREATE TABLE Countries (id INT,name VARCHAR(50),region VARCHAR(50));
SELECT co.region, AVG(me.amount/me.gdp*100) as avg_military_expenditure FROM Military_Expenditure me INNER JOIN Countries co ON me.country = co.name WHERE me.year BETWEEN (YEAR(CURRENT_DATE) - 10) AND YEAR(CURRENT_DATE) GROUP BY co.region;
What are the unique categories of articles published by 'The Miami Herald' and 'The Atlanta Journal' in the last year, excluding any duplicate categories?
CREATE TABLE the_miami_herald (category TEXT,publication_date DATE);CREATE TABLE the_atlanta_journal (category TEXT,publication_date DATE);
SELECT DISTINCT category FROM (SELECT category FROM the_miami_herald WHERE publication_date > DATE('now','-1 year') UNION SELECT category FROM the_atlanta_journal WHERE publication_date > DATE('now','-1 year'))
What is the total number of investigative journalism articles published by "CNN" and "MSNBC" in 2019?
CREATE TABLE articles (id INT,title TEXT,publication TEXT,topic TEXT,year INT); INSERT INTO articles (id,title,publication,topic,year) VALUES (1,'Article 1','CNN','Investigative Journalism',2019); INSERT INTO articles (id,title,publication,topic,year) VALUES (2,'Article 2','MSNBC','Investigative Journalism',2019); INSERT INTO articles (id,title,publication,topic,year) VALUES (3,'Article 3','CNN','News',2019);
SELECT SUM(cnt) FROM (SELECT publication, COUNT(*) as cnt FROM articles WHERE topic = 'Investigative Journalism' AND year = 2019 AND (publication = 'CNN' OR publication = 'MSNBC') GROUP BY publication) as t;
What is the percentage of security incidents resolved within the SLA in the past month?
CREATE TABLE security_incidents (id INT,resolved BOOLEAN,resolved_time TIMESTAMP,SLA_deadline TIMESTAMP);
SELECT ROUND(AVG(CASE WHEN resolved THEN 1.0 ELSE 0.0 END * (resolved_time <= SLA_deadline)) * 100, 2) as percentage_within_SLA FROM security_incidents WHERE resolved_time >= NOW() - INTERVAL '1 month';
List all investments made by 'Sustainable Future' in Q2 2021.
CREATE TABLE investments (id INT,investor VARCHAR(255),amount FLOAT,date DATE); INSERT INTO investments (id,investor,amount,date) VALUES (3,'Sustainable Future',60000,'2021-04-01'); INSERT INTO investments (id,investor,amount,date) VALUES (4,'Sustainable Future',90000,'2021-04-15');
SELECT * FROM investments WHERE investor = 'Sustainable Future' AND date BETWEEN '2021-04-01' AND '2021-06-30';
How many donations were made in total for each year?
CREATE TABLE donors (id INT,name VARCHAR(255),country VARCHAR(255));CREATE TABLE donations (id INT,donor_id INT,cause_id INT,amount DECIMAL(10,2),donation_date DATE);
SELECT YEAR(donation_date), COUNT(*) FROM donations GROUP BY YEAR(donation_date);
Identify mobile subscribers who have used more than 2GB of data in the last 30 days.
CREATE TABLE activity (id INT,subscriber_id INT,data_usage INT,last_activity_date DATE); INSERT INTO activity (id,subscriber_id,data_usage,last_activity_date) VALUES (1,1001,3000,'2022-01-01'),(2,1002,1500,'2022-02-15'),(3,1003,2500,'2022-03-01'),(4,1004,1000,'2022-04-10');
SELECT subscriber_id FROM activity WHERE last_activity_date >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) AND data_usage > 2000;
Update the salary for employee "Clara Rodriguez" in the "salaries" table
CREATE TABLE salaries (id INT PRIMARY KEY,employee_id INT,salary DECIMAL(10,2),last_update DATE);
UPDATE salaries SET salary = 50000.00 WHERE employee_id = 5678;
Delete dishes that have not been ordered in the past 30 days
CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),last_ordered_date DATE); INSERT INTO dishes (dish_id,dish_name,last_ordered_date) VALUES (1,'Vegan Tacos','2022-05-15'),(2,'Chickpea Curry','2022-05-18'),(3,'Cheese Quesadilla','2022-01-01');
DELETE FROM dishes WHERE last_ordered_date < NOW() - INTERVAL 30 DAY;
How many timber production facilities are there in the tropical biome that have recorded violations in the past year?
CREATE TABLE tropical_production (id INT,facility_name VARCHAR(255),biome VARCHAR(255),violation_flag BOOLEAN,violation_date DATE);
SELECT COUNT(*) FROM tropical_production WHERE biome = 'tropical' AND violation_flag = TRUE AND violation_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
Who were the top 3 donors in 2020, based on total donation amount?
CREATE TABLE Donations (DonorID INT,DonationDate DATE,Amount DECIMAL(10,2)); INSERT INTO Donations (DonorID,DonationDate,Amount) VALUES (1,'2020-01-01',50.00),(2,'2020-02-01',100.00),(3,'2020-12-31',250.00),(1,'2020-06-01',100.00),(3,'2020-09-01',150.00);
SELECT DonorID, SUM(Amount) as TotalDonated FROM Donations WHERE YEAR(DonationDate) = 2020 GROUP BY DonorID ORDER BY TotalDonated DESC LIMIT 3;
How many units of product B are stored in each warehouse?
CREATE TABLE warehouses (warehouse_id INT,location TEXT); INSERT INTO warehouses (warehouse_id,location) VALUES (1,'Tokyo'),(2,'Osaka'),(3,'Kyoto'); CREATE TABLE inventory (product TEXT,warehouse_id INT,quantity INT); INSERT INTO inventory (product,warehouse_id,quantity) VALUES ('Product B',1,150),('Product B',2,250),('Product B',3,350);
SELECT i.product, w.location, SUM(i.quantity) as total_quantity FROM inventory i JOIN warehouses w ON i.warehouse_id = w.warehouse_id WHERE i.product = 'Product B' GROUP BY w.location;
What is the number of feedback entries for each category, and what is the percentage of feedback entries for each category in cities with a population over 10 million?
CREATE TABLE CategoryFeedback (Id INT,CityId INT,Category VARCHAR(50),Feedback VARCHAR(255)); INSERT INTO CategoryFeedback (Id,CityId,Category,Feedback) VALUES (1,1,'Transportation','Great public transportation!'),(2,1,'Infrastructure','Good infrastructure...'),(3,2,'Transportation','Poor public transportation...'),(4,2,'Education','Excellent schools...'),(5,3,'Transportation','Average public transportation...'),(6,3,'Infrastructure','Excellent infrastructure...');
SELECT Category, COUNT(*) AS FeedbackCount, (COUNT(*) * 100.0 / SUM(COUNT(*)) OVER ()) AS CategoryPercentage FROM (SELECT Category FROM CategoryFeedback JOIN City ON CategoryFeedback.CityId = City.Id WHERE Population > 1000000 GROUP BY Category, CityId) AS Subquery GROUP BY Category;
What is the total quantity of organic cotton used by brands in the 'ethical_brands' table?
CREATE TABLE ethical_brands (brand_id INT,brand_name TEXT,total_organic_cotton_kg FLOAT);
SELECT SUM(total_organic_cotton_kg) FROM ethical_brands;
What are the names of the cybersecurity strategies implemented before 2015?
CREATE TABLE Cybersecurity_Strategies (Year INT,Strategy VARCHAR(255)); INSERT INTO Cybersecurity_Strategies (Year,Strategy) VALUES (2005,'Cybersecurity Initiative'),(2010,'Comprehensive National Cybersecurity Initiative'),(2015,'Cybersecurity National Action Plan');
SELECT Strategy FROM Cybersecurity_Strategies WHERE Year < 2015;
How many primary schools were built in 2020, separated by region?
CREATE TABLE regions (region_id INT,region_name VARCHAR(255)); INSERT INTO regions (region_id,region_name) VALUES (1,'Africa'),(2,'Asia'),(3,'Europe'); CREATE TABLE schools (school_id INT,school_name VARCHAR(255),region_id INT,build_year INT); INSERT INTO schools (school_id,school_name,region_id,build_year) VALUES (1,'School A',1,2020),(2,'School B',1,2019),(3,'School C',2,2020),(4,'School D',3,2018);
SELECT r.region_name, COUNT(s.school_id) as num_of_schools FROM regions r INNER JOIN schools s ON r.region_id = s.region_id WHERE s.build_year = 2020 GROUP BY r.region_id;
What is the average age of patients who received CBT treatment in Canada?
CREATE TABLE mental_health_patients (patient_id INT,age INT,treatment VARCHAR(255),country VARCHAR(255)); INSERT INTO mental_health_patients (patient_id,age,treatment,country) VALUES (1,30,'CBT','Canada'); INSERT INTO mental_health_patients (patient_id,age,treatment,country) VALUES (2,35,'DBT','Canada');
SELECT AVG(age) FROM mental_health_patients WHERE treatment = 'CBT' AND country = 'Canada';
What is the total budget allocated for education in each district?
CREATE TABLE districts (district_id INT,district_name VARCHAR(255)); INSERT INTO districts (district_id,district_name) VALUES (1,'Downtown'),(2,'Uptown'),(3,'Westside'),(4,'Eastside'); CREATE TABLE education_budget (district_id INT,year INT,amount INT); INSERT INTO education_budget (district_id,year,amount) VALUES (1,2022,3000000),(2,2022,3500000),(3,2022,4000000),(4,2022,4200000);
SELECT district_name, SUM(amount) AS total_budget FROM education_budget JOIN districts ON education_budget.district_id = districts.district_id GROUP BY district_name;
What is the average population of capybaras and jaguars in the Amazon Rainforest?
CREATE TABLE animal_population (id INT,species VARCHAR(50),population INT,location VARCHAR(50));
SELECT species, AVG(population) FROM animal_population WHERE species IN ('capybara', 'jaguar') AND location = 'Amazon Rainforest' GROUP BY species;
For each habitat, what is the average weight of the animals in that habitat?
CREATE TABLE animals (id INT,animal_name VARCHAR(255),habitat_type VARCHAR(255),weight DECIMAL(5,2)); INSERT INTO animals (id,animal_name,habitat_type,weight) VALUES (1,'Lion','Savannah',190.0),(2,'Elephant','Forest',6000.0),(3,'Hippo','Wetlands',3300.0),(4,'Giraffe','Savannah',1600.0),(5,'Duck','Wetlands',15.0),(6,'Bear','Mountains',300.0);
SELECT habitat_type, AVG(weight) AS avg_weight FROM animals GROUP BY habitat_type;
Update the sustainable_sourcing table to set the sourcing_percentage to 85 for ingredient 'Chia Seeds'
CREATE TABLE sustainable_sourcing (id INT PRIMARY KEY,restaurant_id INT,ingredient VARCHAR(50),sourcing_percentage DECIMAL(5,2));
UPDATE sustainable_sourcing SET sourcing_percentage = 85 WHERE ingredient = 'Chia Seeds';
Which routes intersect with the 73 bus in Boston?
CREATE TABLE Routes (route VARCHAR(20),intersect VARCHAR(20)); INSERT INTO Routes (route,intersect) VALUES ('1','73'),('39','73');
SELECT intersect FROM Routes WHERE route = '73';
What is the total number of AI patents filed by companies based in India?
CREATE TABLE ai_patents (patent_id INT,company_name VARCHAR(30),country VARCHAR(20)); INSERT INTO ai_patents (patent_id,company_name,country) VALUES (1,'TCS','India'),(2,'Infosys','India'),(3,'Google','USA');
SELECT COUNT(*) FROM ai_patents WHERE country = 'India';
What is the total mass of all spacecraft sent to the International Space Station?
CREATE TABLE iss_missions (id INT,mission_name VARCHAR(255),spacecraft_mass INT); INSERT INTO iss_missions (id,mission_name,spacecraft_mass) VALUES (1,'STS-88',125835); INSERT INTO iss_missions (id,mission_name,spacecraft_mass) VALUES (2,'Soyuz TMA-1',7200);
SELECT SUM(spacecraft_mass) FROM iss_missions;
Delete fairness issues for models from Germany with an id greater than 5.
CREATE TABLE fairness (model_id INT,country VARCHAR(255),issue_description VARCHAR(255)); INSERT INTO fairness (model_id,country,issue_description) VALUES (1,'Germany','Fairness issue 1'),(2,'Germany','Fairness issue 2'),(3,'France','Fairness issue 3'),(4,'Germany','Fairness issue 4'),(5,'Germany','Fairness issue 5');
DELETE FROM fairness WHERE model_id > 5 AND country = 'Germany';
Which vessels have loaded cargo in both Africa and Oceania?
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(50));CREATE TABLE CargoLoads (LoadID INT,VesselID INT,LoadLocation VARCHAR(50),LoadDate DATE); INSERT INTO Vessels (VesselID,VesselName) VALUES (1,'VesselA'),(2,'VesselB'),(3,'VesselC'),(4,'VesselD'); INSERT INTO CargoLoads (LoadID,VesselID,LoadLocation,LoadDate) VALUES (1,1,'South Africa','2021-01-01'),(2,1,'Australia','2021-02-01'),(3,2,'New Zealand','2021-03-01'),(4,3,'Madagascar','2021-04-01'),(5,4,'Papua New Guinea','2021-05-01');
SELECT VesselName FROM Vessels WHERE VesselID IN (SELECT VesselID FROM CargoLoads WHERE LoadLocation LIKE 'Africa%') INTERSECT SELECT VesselName FROM Vessels WHERE VesselID IN (SELECT VesselID FROM CargoLoads WHERE LoadLocation LIKE 'Oceania%');
How many items are there in total in the warehouse in Canada?
CREATE TABLE Warehouse (id INT,country VARCHAR(255),items_quantity INT); INSERT INTO Warehouse (id,country,items_quantity) VALUES (1,'Canada',200),(2,'USA',400),(3,'Mexico',500);
SELECT SUM(items_quantity) FROM Warehouse WHERE country = 'Canada';
What is the average temperature reading for all IoT sensors in the "Field1" located in "US-NY"?
CREATE TABLE Field1 (id INT,sensor_id INT,temperature DECIMAL(5,2),location VARCHAR(255)); INSERT INTO Field1 (id,sensor_id,temperature,location) VALUES (1,101,22.5,'US-NY');
SELECT AVG(temperature) FROM Field1 WHERE location = 'US-NY';
What is the minimum population of animals in the 'animal_population' table?
CREATE TABLE animal_population (animal_id INT,animal_name VARCHAR(50),population INT); INSERT INTO animal_population (animal_id,animal_name,population) VALUES (1,'Tiger',2000),(2,'Elephant',5000),(3,'Lion',3000);
SELECT MIN(population) FROM animal_population;
What is the total number of dental procedures performed on patients under 18 years old in rural hospitals of California?
CREATE TABLE medical_procedures (procedure_id INT,patient_id INT,hospital_id INT,procedure_date DATE,procedure_name TEXT); INSERT INTO medical_procedures (procedure_id,patient_id,hospital_id,procedure_date,procedure_name) VALUES (1,1,1,'2022-01-01','Dental Checkup'); CREATE TABLE patient (patient_id INT,patient_name TEXT,age INT,gender TEXT,diagnosis TEXT,location TEXT); INSERT INTO patient (patient_id,patient_name,age,gender,diagnosis,location) VALUES (1,'Jimmy Brown',15,'Male','Healthy','California'); CREATE TABLE hospital (hospital_id INT,hospital_name TEXT,location TEXT); INSERT INTO hospital (hospital_id,hospital_name,location) VALUES (1,'Rural Hospital A','California');
SELECT SUM(procedures) FROM (SELECT patient_id, COUNT(*) as procedures FROM medical_procedures WHERE patient.age < 18 GROUP BY patient_id) as subquery;
Insert a new record into the Contract_Negotiations table for 'Australia' with a contract value of 10000000 and a negotiation date of 2023-03-15.
CREATE TABLE Contract_Negotiations (country VARCHAR(50),contract_value INT,negotiation_date DATE);
INSERT INTO Contract_Negotiations (country, contract_value, negotiation_date) VALUES ('Australia', 10000000, '2023-03-15');
What are the carbon offset programs and their corresponding project capacities for renewable energy projects located in the US?
CREATE TABLE Projects (id INT,name VARCHAR(255),location VARCHAR(255),capacity FLOAT,PRIMARY KEY (id)); INSERT INTO Projects (id,name,location,capacity) VALUES (1,'Wind Farm A','USA',180.0),(2,'Solar Farm B','California',100.5); CREATE TABLE Offsets (id INT,project_id INT,amount INT,PRIMARY KEY (id),FOREIGN KEY (project_id) REFERENCES Projects(id)); INSERT INTO Offsets (id,project_id,amount) VALUES (1,1,25000),(2,2,30000);
SELECT P.name, P.capacity, O.amount FROM Projects P INNER JOIN Offsets O ON P.id = O.project_id WHERE P.location = 'USA';
What is the maximum construction cost for public works projects in Texas, categorized by project phase and project manager?
CREATE TABLE Projects_Phase (id INT,state VARCHAR(2),project_phase VARCHAR(10),project_manager VARCHAR(10),construction_cost INT); INSERT INTO Projects_Phase (id,state,project_phase,project_manager,construction_cost) VALUES (1,'TX','Design','Alice',500000),(2,'TX','Construction','Bob',800000),(3,'TX','Maintenance','Charlie',300000);
SELECT project_phase, project_manager, MAX(construction_cost) FROM Projects_Phase WHERE state = 'TX' GROUP BY project_phase, project_manager;
Update the 'explainable_ai' table, changing 'description' to 'SHAP: Local Explanations' for records where 'method' is 'SHAP' and 'technique' is 'Model Explanation'
CREATE TABLE explainable_ai (id INT,method VARCHAR(20),technique VARCHAR(30),description TEXT); INSERT INTO explainable_ai (id,method,technique,description) VALUES (1,'SHAP','Model Explanation','SHapley Additive exPlanations'),(2,'SHAP','Feature Importance','SHapley Feature Importance');
UPDATE explainable_ai SET description = 'SHAP: Local Explanations' WHERE method = 'SHAP' AND technique = 'Model Explanation';
What is the distribution of ethical AI principles across different regions?
CREATE TABLE ethical_ai (id INT,principle VARCHAR(50),region VARCHAR(50));INSERT INTO ethical_ai (id,principle,region) VALUES (1,'Fairness','Asia'),(2,'Accountability','Europe'),(3,'Transparency','Americas');
SELECT region, COUNT(*) as principle_count FROM ethical_ai GROUP BY region;
Insert a new digital asset with the name 'CryptoPet', symbol 'CPT', and total supply of 1,000,000,000 into the 'DigitalAssets' table
CREATE TABLE DigitalAssets (name VARCHAR(64),symbol VARCHAR(8),total_supply DECIMAL(20,8),platform VARCHAR(64),project_url VARCHAR(128));
INSERT INTO DigitalAssets (name, symbol, total_supply) VALUES ('CryptoPet', 'CPT', 1000000000);
How many users are there in the social_media database who joined after '2021-12-31'?
CREATE TABLE users (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),join_date DATE); INSERT INTO users (id,name,age,gender,join_date) VALUES (1,'Bob',30,'Male','2022-01-02');
SELECT COUNT(*) as num_users FROM users WHERE join_date > '2021-12-31';
Update the location of the supplier with id 1 to 'California, USA'
CREATE TABLE suppliers (id INT PRIMARY KEY,name TEXT,location TEXT,sustainability_rating REAL);
UPDATE suppliers SET location = 'California, USA' WHERE id = 1;
How many volunteers signed up in the Education department from countries with a population over 100 million?
CREATE TABLE volunteers(id INT,name TEXT,department TEXT,country TEXT); INSERT INTO volunteers(id,name,department,country) VALUES (1,'John Doe','Education','USA'),(2,'Jane Smith','Health','Canada'),(3,'Alice Johnson','Education','Nigeria');
SELECT COUNT(*) FROM volunteers WHERE department = 'Education' AND country IN (SELECT country FROM (SELECT * FROM world_population) AS wp WHERE wp.population > 100000000);
Show machines that were produced using circular economy principles.
CREATE TABLE machines (id INT PRIMARY KEY,model TEXT,year INT,manufacturer TEXT,circular_economy BOOLEAN); CREATE TABLE maintenance (id INT PRIMARY KEY,machine_id INT,date DATE,FOREIGN KEY (machine_id) REFERENCES machines(id));
SELECT machines.model, machines.year, machines.manufacturer FROM machines WHERE machines.circular_economy = TRUE;
What is the number of games played by each player in the "Platformer" genre?
CREATE TABLE PlayerGames (PlayerID int,PlayerName varchar(50),Game varchar(50),Category varchar(50));
SELECT PlayerName, COUNT(DISTINCT Game) OVER(PARTITION BY PlayerID) as GamesCount FROM PlayerGames WHERE Category = 'Platformer';
Which regions have more than 30 traditional art pieces?
CREATE TABLE Art (ArtID INT,Type VARCHAR(255),Region VARCHAR(255),Quantity INT); INSERT INTO Art (ArtID,Type,Region,Quantity) VALUES (1,'Painting','Asia',25),(2,'Sculpture','Africa',18),(3,'Textile','South America',30),(4,'Pottery','Europe',20),(5,'Jewelry','North America',12);
SELECT Region, SUM(Quantity) as Total_Quantity FROM Art GROUP BY Region HAVING SUM(Quantity) > 30;
Find the number of players who joined esports events in the US and their total games played, partitioned by event country.
CREATE TABLE EventParticipation (EventID INT,PlayerID INT,EventCountry VARCHAR(50)); INSERT INTO EventParticipation (EventID,PlayerID,EventCountry) VALUES (1,1,'USA'),(2,2,'USA'),(3,3,'Canada');
SELECT EventCountry, COUNT(PlayerID) AS PlayersJoined, SUM(TotalGames) AS TotalGamesPlayed FROM Players P JOIN EventParticipation EP ON P.PlayerID = EP.PlayerID GROUP BY EventCountry
Find the total number of articles published in each news topic in the last 6 months, sorted by the total number of articles in descending order in the "InvestigativeJournalism" and "NewsReporting" databases.
CREATE TABLE NewsTopics (TopicID INT,Topic VARCHAR(255)); CREATE TABLE Articles (ArticleID INT,TopicID INT,PublishDate DATE); INSERT INTO NewsTopics (TopicID,Topic) VALUES (1,'corruption'),(2,'environment'),(3,'human rights'); INSERT INTO Articles (ArticleID,TopicID,PublishDate) VALUES (1,1,'2022-01-01'),(2,2,'2022-02-01'),(3,3,'2022-03-01'),(4,1,'2022-06-01');
SELECT NewsTopics.Topic, COUNT(Articles.ArticleID) AS ArticleCount FROM NewsTopics INNER JOIN Articles ON NewsTopics.TopicID = Articles.TopicID WHERE Articles.PublishDate >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY NewsTopics.Topic ORDER BY ArticleCount DESC;
Find the total number of marine species and total number of pollution control initiatives in the database.
CREATE TABLE marine_species (id INT,species VARCHAR(255)); INSERT INTO marine_species (id,species) VALUES (1,'Dolphin'),(2,'Shark'); CREATE TABLE pollution_control (id INT,initiative VARCHAR(255)); INSERT INTO pollution_control (id,initiative) VALUES (1,'Beach Cleanup'),(2,'Ocean Floor Mapping');
SELECT COUNT(*) FROM marine_species UNION ALL SELECT COUNT(*) FROM pollution_control;
List all facilities in the 'facilities' table that have a capacity greater than 15000.
CREATE TABLE facilities (facility_id INT,name VARCHAR(50),capacity INT,location VARCHAR(50),surface VARCHAR(20));
SELECT facility_id, name, capacity, location FROM facilities WHERE capacity > 15000;
Update the status of the rural infrastructure project with ID 1 to 'completed' in the 'infrastructure_projects' table.
CREATE TABLE infrastructure_projects(id INT,province TEXT,project_name TEXT,completion_status TEXT); INSERT INTO infrastructure_projects (id,province,project_name,completion_status) VALUES (1,'Quebec','Wind Turbine Project','in progress'); INSERT INTO infrastructure_projects (id,province,project_name,completion_status) VALUES (2,'Ontario','Smart Grid Implementation','in progress');
UPDATE infrastructure_projects SET completion_status = 'completed' WHERE id = 1;
What was the maximum water consumption by a single user in a day in the month of August?
CREATE TABLE water_consumption_by_user (id INT,user_id INT,event_date DATE,water_consumption FLOAT); INSERT INTO water_consumption_by_user (id,user_id,event_date,water_consumption) VALUES (1,1,'2021-08-01',120),(2,2,'2021-08-02',150),(3,3,'2021-08-03',180);
SELECT user_id, MAX(water_consumption) as max_water_consumption_by_user FROM water_consumption_by_user WHERE MONTH(event_date) = 8 GROUP BY user_id;
Which cities have more than 100 certified green buildings?
CREATE TABLE City (id INT,name VARCHAR(255),population INT,renewable_energy_projects INT); INSERT INTO City (id,name,population,renewable_energy_projects) VALUES (1,'Rio de Janeiro',6500000,500); INSERT INTO City (id,name,population,renewable_energy_projects) VALUES (2,'Sydney',5000000,120); CREATE TABLE GreenBuilding (id INT,name VARCHAR(255),city_id INT,size INT,is_certified BOOLEAN); INSERT INTO GreenBuilding (id,name,city_id,size,is_certified) VALUES (1,'Eco Tower',1,15000,true); INSERT INTO GreenBuilding (id,name,city_id,size,is_certified) VALUES (2,'Green Heights',2,20000,false);
SELECT c.name FROM City c JOIN GreenBuilding gb ON c.id = gb.city_id WHERE is_certified = true GROUP BY c.name HAVING COUNT(gb.id) > 100;
What is the total number of assists by players in the MLS?
CREATE TABLE american_teams (team_id INT,team_name VARCHAR(50)); INSERT INTO american_teams (team_id,team_name) VALUES (1,'LA Galaxy'),(2,'Seattle Sounders'),(3,'Atlanta United'); CREATE TABLE american_matches (match_id INT,home_team_id INT,away_team_id INT,home_team_player_assists INT,away_team_player_assists INT); INSERT INTO american_matches (match_id,home_team_id,away_team_id,home_team_player_assists,away_team_player_assists) VALUES (1,1,2,2,1),(2,2,3,1,2),(3,3,1,3,1);
SELECT COUNT(home_team_player_assists + away_team_player_assists) AS total_assists FROM american_matches;
Insert new record of wildlife habitat data for Colombia in 2023
CREATE TABLE wildlife_habitat (country_code CHAR(3),year INT,habitat_area INT); INSERT INTO wildlife_habitat (country_code,year,habitat_area) VALUES ('COL',2022,70000),('COL',2021,65000);
INSERT INTO wildlife_habitat (country_code, year, habitat_area) VALUES ('COL', 2023, 75000);
Which excavation sites have more than 5 'Metalwork' artifacts and their corresponding category percentages?
CREATE TABLE excavation_sites_metalwork (site_id INT,artifact_count INT); INSERT INTO excavation_sites_metalwork (site_id,artifact_count) VALUES (1,10),(2,8),(3,12); CREATE TABLE artifacts_categories_count (site_id INT,category VARCHAR(255),artifact_count INT); INSERT INTO artifacts_categories_count (site_id,category,artifact_count) VALUES (1,'Ceramics',20),(1,'Metalwork',10),(2,'Ceramics',15),(2,'Metalwork',8),(3,'Ceramics',12),(3,'Metalwork',12);
SELECT a.site_id, a.artifact_count, 100.0 * a.artifact_count / SUM(b.artifact_count) OVER (PARTITION BY a.site_id) AS category_percentage FROM excavation_sites_metalwork a JOIN artifacts_categories_count b ON a.site_id = b.site_id WHERE b.category = 'Metalwork' AND a.artifact_count > 5;
What is the average depth of the seas in the 'oceanographic_data' table, excluding the Mediterranean Sea?"
CREATE TABLE oceanographic_data (sea_name VARCHAR(50),avg_depth DECIMAL(5,2));
SELECT AVG(avg_depth) FROM oceanographic_data WHERE sea_name != 'Mediterranean Sea';
What is the revenue for each product category in descending order?
CREATE TABLE sales (sale_id INT,product_id INT,price DECIMAL(5,2)); INSERT INTO sales (sale_id,product_id,price) VALUES (1,1,20.99),(2,2,50.00),(3,3,75.00),(4,4,10.00),(5,5,30.00),(6,6,40.00); CREATE TABLE products (product_id INT,category TEXT); INSERT INTO products (product_id,category) VALUES (1,'Electronics'),(2,'Clothing'),(3,'Furniture'),(4,'Electronics'),(5,'Clothing'),(6,'Furniture');
SELECT products.category, SUM(sales.price) FROM products INNER JOIN sales ON products.product_id = sales.product_id GROUP BY products.category ORDER BY SUM(sales.price) DESC;
List the top 3 states with the most community health workers by race/ethnicity?
CREATE TABLE community_health_workers (state VARCHAR(50),race_ethnicity VARCHAR(50),workers INT); INSERT INTO community_health_workers (state,race_ethnicity,workers) VALUES ('California','Hispanic',200),('California','White',150),('Texas','Hispanic',250),('Texas','White',100),('New York','Black',180),('New York','White',120);
SELECT state, race_ethnicity, SUM(workers) as total_workers FROM community_health_workers GROUP BY state, race_ethnicity ORDER BY total_workers DESC LIMIT 3;
List all unique species observed
species_observations
SELECT DISTINCT species FROM species_observations;
What is the total funding amount for companies founded in 2012?
CREATE TABLE company_funding (company_id INT,founding_year INT,amount FLOAT); INSERT INTO company_funding (company_id,founding_year,amount) VALUES (1,2010,1500000.0),(2,2012,2000000.0),(3,2010,500000.0),(4,2012,1000000.0),(5,2011,1200000.0);
SELECT SUM(amount) FROM company_funding WHERE founding_year = 2012;
List all water conservation initiatives implemented in 'Cape Town' from 2017 to 2019
CREATE TABLE conservation_initiatives (region VARCHAR(50),date DATE,initiative VARCHAR(50)); INSERT INTO conservation_initiatives (region,date,initiative) VALUES ('Cape Town','2017-01-01','Rainwater harvesting'),('Cape Town','2018-01-01','Greywater reuse'),('Cape Town','2019-01-01','Smart irrigation');
SELECT * FROM conservation_initiatives WHERE region = 'Cape Town' AND date BETWEEN '2017-01-01' AND '2019-12-31';
What is the minimum rating of eco-friendly hotels in Germany?
CREATE TABLE eco_hotels (hotel_id INT,hotel_name TEXT,country TEXT,rating FLOAT); INSERT INTO eco_hotels (hotel_id,hotel_name,country,rating) VALUES (1,'Eco-Friendly Hotel 1','Germany',4.2),(2,'Eco-Friendly Hotel 2','Germany',4.7);
SELECT MIN(rating) FROM eco_hotels WHERE country = 'Germany';
What is the average food safety inspection score for each quarter of the year?
CREATE TABLE inspections (id INT,date DATE,score FLOAT); INSERT INTO inspections (id,date,score) VALUES (1,'2022-01-01',90.0),(2,'2022-04-01',85.0),(3,'2022-07-01',95.0);
SELECT DATE_FORMAT(date, '%Y-%m') as quarter, AVG(score) as avg_score FROM inspections GROUP BY quarter;
Update the address of a nonprofit in the nonprofits table
CREATE TABLE nonprofits (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),zip_code VARCHAR(10));
UPDATE nonprofits SET city = 'Los Angeles', state = 'CA', zip_code = '90001' WHERE id = 3;
List the names and total tonnage of all cargoes that share the same destination port as cargo with the ID of 5, including cargoes with no tonnage.
CREATE TABLE cargo(cargo_id INT,port_id INT,tonnage INT);INSERT INTO cargo VALUES (1,1,500),(2,1,800),(3,2,300),(4,1,0),(5,2,600);
SELECT c.name, COALESCE(SUM(c2.tonnage), 0) as total_tonnage FROM cargo c INNER JOIN cargo c2 ON c.port_id = c2.port_id WHERE c2.cargo_id = 5 GROUP BY c.cargo_id;
List the unique types of infrastructure and their respective standard design codes in 'California'.
CREATE TABLE Infrastructure (type TEXT,state TEXT,design_code TEXT); INSERT INTO Infrastructure (type,state,design_code) VALUES ('Bridges','California','AASHTO LRFD');
SELECT DISTINCT type, design_code FROM Infrastructure WHERE state = 'California';
What percentage of cosmetic products are not safety certified in USA?
CREATE TABLE products (product_id INT,product_name TEXT,is_safety_certified BOOLEAN,country TEXT); INSERT INTO products (product_id,product_name,is_safety_certified,country) VALUES (1,'Eyeshadow',true,'USA'),(2,'Blush',false,'USA'),(3,'Highlighter',true,'USA');
SELECT (COUNT(*) - SUM(is_safety_certified)) * 100.0 / COUNT(*) as percentage FROM products WHERE country = 'USA';
How many decentralized applications have been developed by companies in the African continent, and what are their industries?
CREATE TABLE DApp (DAppID INT,DAppName VARCHAR(100),IssuerCompany VARCHAR(100),IssuerLocation VARCHAR(50),Industry VARCHAR(50)); INSERT INTO DApp (DAppID,DAppName,IssuerCompany,IssuerLocation,Industry) VALUES (1,'DApp1','CompanyD','Africa','Finance'),(2,'DApp2','CompanyE','Africa','Healthcare'),(3,'DApp3','CompanyF','Europe','Retail');
SELECT IssuerLocation, Industry, COUNT(*) as Total FROM DApp WHERE IssuerLocation = 'Africa' GROUP BY IssuerLocation, Industry;
How many sustainable clothing brands are available in the database?
CREATE TABLE clothing_brands (brand_id INT PRIMARY KEY,brand_name VARCHAR(100),sustainability_rating FLOAT); INSERT INTO clothing_brands (brand_id,brand_name,sustainability_rating) VALUES (1,'EcoFriendlyBrand',4.2),(2,'GreenFashion',4.6),(3,'SustainableTextiles',4.5);
SELECT COUNT(DISTINCT brand_name) FROM clothing_brands;
Insert a new record of rare earth element production for 'Canada' in 2021 with an amount of 10000.
CREATE TABLE production (country VARCHAR(255),year INT,amount INT);
INSERT INTO production (country, year, amount) VALUES ('Canada', 2021, 10000);
What is the total number of chemical spills recorded in the environmental_impact table, grouped by the year?
CREATE TABLE environmental_impact (spill_date DATE); INSERT INTO environmental_impact (spill_date) VALUES ('2020-03-15'),('2021-08-09'),('2020-12-25'),('2019-06-01');
SELECT YEAR(spill_date) AS year, COUNT(*) AS total_spills FROM environmental_impact GROUP BY year;
What is the total cost of all projects in the 'infrastructure_projects' table, ordered by the project's start date?
CREATE TABLE infrastructure_projects (id INT,name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE,total_cost FLOAT);
SELECT SUM(total_cost) FROM infrastructure_projects ORDER BY start_date;
What is the trend of socially responsible loan amounts issued per quarter?
CREATE TABLE socially_responsible_loans_over_time (id INT,loan_date DATE,amount FLOAT); INSERT INTO socially_responsible_loans_over_time (id,loan_date,amount) VALUES (1,'2021-01-01',350000),(2,'2021-04-01',400000),(3,'2021-07-01',450000),(4,'2021-10-01',200000);
SELECT DATE_FORMAT(loan_date, '%Y-%m') as month, QUARTER(loan_date) as quarter, SUM(amount) as total_amount FROM socially_responsible_loans_over_time GROUP BY quarter ORDER BY quarter;
How many bike-sharing stations are there in Paris and London?
CREATE TABLE EuroBikeSharing (id INT,city VARCHAR(20),stations INT);
SELECT city, SUM(stations) FROM EuroBikeSharing WHERE city IN ('Paris', 'London') GROUP BY city;
What is the average heart rate of users from Mexico?
CREATE TABLE wearable_tech (user_id INT,heart_rate INT,country VARCHAR(50)); INSERT INTO wearable_tech (user_id,heart_rate,country) VALUES (1,70,'Mexico'),(2,75,'Canada'),(3,80,'Mexico'),(4,65,'Mexico'),(5,72,'Mexico');
SELECT AVG(heart_rate) FROM wearable_tech WHERE country = 'Mexico';
What is the average media literacy score for users aged 25-34 in the United States?
CREATE TABLE users (id INT,age INT,media_literacy_score INT); INSERT INTO users (id,age,media_literacy_score) VALUES (1,25,80),(2,34,85),(3,22,75),(4,45,90);
SELECT AVG(media_literacy_score) FROM users WHERE age BETWEEN 25 AND 34 AND country = 'United States';
What is the average garment rating for sustainable garments compared to non-sustainable garments?
CREATE TABLE Garments (GarmentID INT,GarmentName TEXT,IsSustainable BOOLEAN,AverageRating DECIMAL); INSERT INTO Garments VALUES (1,'Garment1',TRUE,4.5),(2,'Garment2',FALSE,3.5),(3,'Garment3',TRUE,4.0);
SELECT CASE WHEN IsSustainable = TRUE THEN 'Sustainable' ELSE 'Non-Sustainable' END AS Category, AVG(AverageRating) FROM Garments GROUP BY Category;
What is the number of hospitals per region?
CREATE TABLE hospitals_region (name VARCHAR(100),region VARCHAR(50));
SELECT region, COUNT(*) FROM hospitals_region GROUP BY region;
What is the average ticket price for cultural events in 'Berlin' and 'Sydney'?
CREATE TABLE cultural_events (id INT,city VARCHAR(20),price INT); INSERT INTO cultural_events (id,city,price) VALUES (1,'Berlin',18),(2,'Sydney',25),(3,'Paris',30);
SELECT AVG(price) FROM cultural_events WHERE city IN ('Berlin', 'Sydney');
Identify the number of algorithmic fairness issues reported in Southeast Asia, grouped by issue category and year.
CREATE TABLE fairness_issues (issue_id INT,issue_date DATE,country VARCHAR(255),issue_category VARCHAR(255),region VARCHAR(255)); INSERT INTO fairness_issues (issue_id,issue_date,country,issue_category,region) VALUES (1,'2021-08-01','Indonesia','Bias','Southeast Asia'),(2,'2022-02-01','Singapore','Explainability','Southeast Asia'),(3,'2021-12-31','Thailand','Transparency','Southeast Asia');
SELECT EXTRACT(YEAR FROM issue_date) as year, issue_category, COUNT(*) as num_issues FROM fairness_issues WHERE region = 'Southeast Asia' GROUP BY year, issue_category;
What percentage of revenue came from 'Vegan Burger' at 'Burger King'?
CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(255)); INSERT INTO restaurants (restaurant_id,name) VALUES (3,'Burger King'); CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(255),price DECIMAL(5,2),restaurant_id INT); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (5,'Vegan Burger',6.99,3); CREATE TABLE orders (order_id INT,menu_item_id INT,quantity INT,order_date DATE,restaurant_id INT); INSERT INTO orders (order_id,menu_item_id,quantity,order_date,restaurant_id) VALUES (1,5,2,'2022-01-01',3);
SELECT 100.0 * SUM(price * quantity) / (SELECT SUM(price * quantity) FROM orders o JOIN menu_items mi ON o.menu_item_id = mi.menu_item_id WHERE mi.restaurant_id = 3) AS revenue_percentage FROM orders o JOIN menu_items mi ON o.menu_item_id = mi.menu_item_id WHERE mi.name = 'Vegan Burger' AND mi.restaurant_id = 3;
Delete records from garment_production where the quantity is less than 500 for garments produced in Vietnam.
CREATE TABLE garment_production (id INT PRIMARY KEY,fabric_type VARCHAR(255),production_country VARCHAR(255),quantity INT,price DECIMAL(5,2)); CREATE VIEW top_garment_producers AS SELECT production_country,SUM(quantity) as total_quantity FROM garment_production GROUP BY production_country ORDER BY total_quantity DESC;
DELETE FROM garment_production WHERE garment_production.quantity < 500 AND garment_production.production_country = 'Vietnam';
Add a new creative AI application 'Music Generation'
CREATE TABLE creative_apps (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO creative_apps (id,name,type) VALUES (1,'Image Generation','Computer Vision'),(2,'Text Summarization','Natural Language Processing');
INSERT INTO creative_apps (id, name, type) VALUES (3, 'Music Generation', 'Audio Processing');
Delete all records in the 'wearable_metrics' table that have a null value in the 'heart_rate' column
CREATE TABLE wearable_metrics (id INT,user_id INT,heart_rate INT,steps INT,date DATE);
DELETE FROM wearable_metrics WHERE heart_rate IS NULL;
What is the average textile waste generation (in metric tons) for each fashion brand?
CREATE TABLE textile_waste(brand VARCHAR(50),waste FLOAT); INSERT INTO textile_waste(brand,waste) VALUES('BrandA',12.5),('BrandB',15.8),('BrandC',18.3);
SELECT brand, AVG(waste) FROM textile_waste GROUP BY brand;