instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Find the average donation amount for the 'Feeding America' campaign in '2020'.
CREATE TABLE donations (id INT,donation_date DATE,campaign TEXT,amount INT); INSERT INTO donations (id,donation_date,campaign,amount) VALUES (1,'2021-01-01','Feeding America',50); INSERT INTO donations (id,donation_date,campaign,amount) VALUES (2,'2020-05-15','Feeding America',100); INSERT INTO donations (id,donation_date,campaign,amount) VALUES (3,'2020-12-31','Feeding America',25);
SELECT AVG(amount) FROM donations WHERE campaign = 'Feeding America' AND YEAR(donation_date) = 2020;
What is the minimum revenue generated from any eco-friendly tour in Mexico?
CREATE TABLE mexico_tours (id INT,type VARCHAR(255),revenue FLOAT); INSERT INTO mexico_tours (id,type,revenue) VALUES (1,'Eco-friendly',600.00),(2,'Eco-friendly',700.00);
SELECT MIN(revenue) FROM mexico_tours WHERE type = 'Eco-friendly';
Delete records in the 'player_scores' table where the player's score is below 500
CREATE TABLE player_scores (player_id INT,game_id INT,score INT,date DATE);
DELETE FROM player_scores WHERE score < 500;
What is the total funding received for 'Theatre' programs in 2022?
CREATE TABLE funding_sources (funding_source_name VARCHAR(50),program_name VARCHAR(50),funding_amount DECIMAL(10,2),funding_year INT); INSERT INTO funding_sources (funding_source_name,program_name,funding_amount,funding_year) VALUES ('Government Grant','Theatre',25000,2022),('Private Donation','Theatre',50000,2022),('Corporate Sponsorship','Music',30000,2022);
SELECT SUM(funding_amount) FROM funding_sources WHERE program_name = 'Theatre' AND funding_year = 2022;
What is the number of electric vehicle charging stations per city and per type?
CREATE TABLE charging_stations (station_id INT,city VARCHAR(50),station_type VARCHAR(50),is_ev_charging BOOLEAN);
SELECT city, station_type, COUNT(*) as num_stations FROM charging_stations WHERE is_ev_charging = true GROUP BY city, station_type;
What is the average adherence rate for drugs in the Southeast region, excluding those with adherence rates below 50%?
CREATE TABLE adherence (id INT PRIMARY KEY,patient_id INT,drug_id INT,region VARCHAR(255),adherence DECIMAL(4,2),adherence_date DATE);
SELECT AVG(a.adherence) as average_adherence FROM adherence a WHERE a.region = 'Southeast' AND a.adherence >= 0.5;
What is the average age of male patients diagnosed with diabetes?
CREATE TABLE patients (id INT,gender TEXT,age INT,diagnosis TEXT); INSERT INTO patients (id,gender,age,diagnosis) VALUES (1,'Male',65,'Diabetes');
SELECT AVG(age) FROM patients WHERE gender = 'Male' AND diagnosis = 'Diabetes';
List all pipelines that cross international borders
CREATE TABLE pipelines (pipeline_id INT,pipeline_name TEXT,start_location TEXT,end_location TEXT,country_start TEXT,country_end TEXT); INSERT INTO pipelines (pipeline_id,pipeline_name,start_location,end_location,country_start,country_end) VALUES (1,'Pipeline C','Canada','US','Canada','US'),(2,'Pipeline D','Mexico','US','Mexico','US'),(3,'Pipeline E','Norway','Sweden','Norway','Sweden');
SELECT pipeline_name FROM pipelines WHERE country_start <> country_end;
Find the average gameplay duration for players in the 'EU_West' region
CREATE TABLE players (player_id INT,region VARCHAR(10)); CREATE TABLE game_sessions (session_id INT,player_id INT,duration FLOAT,PRIMARY KEY (session_id),FOREIGN KEY (player_id) REFERENCES players(player_id)); INSERT INTO players (player_id,region) VALUES (1,'EU_West'),(2,'NA_East'); INSERT INTO game_sessions (session_id,player_id,duration) VALUES (1,1,60.5),(2,1,45.3),(3,2,30.7),(4,2,75.2);
SELECT AVG(duration) FROM game_sessions WHERE player_id IN (SELECT player_id FROM players WHERE region = 'EU_West');
How many mobile subscribers are there in Illinois with a data plan that is not unlimited?
CREATE TABLE mobile_subscribers (id INT,name VARCHAR(50),data_plan VARCHAR(20),state VARCHAR(50)); INSERT INTO mobile_subscribers (id,name,data_plan,state) VALUES (11,'Gina Adams','Limited','IL'); INSERT INTO mobile_subscribers (id,name,data_plan,state) VALUES (12,'Henry Brown','Limited','IL');
SELECT COUNT(*) FROM mobile_subscribers WHERE data_plan != 'Unlimited' AND state = 'IL';
What is the number of mental health parity violations for each community health worker in the Los Angeles region?
CREATE TABLE community_health_workers (worker_id INT,name TEXT,region TEXT); INSERT INTO community_health_workers (worker_id,name,region) VALUES (1,'John Doe','Los Angeles'),(2,'Jane Smith','New York'); CREATE TABLE mental_health_parity_violations (id INT,worker_id INT,violation_count INT); INSERT INTO mental_health_parity_violations (id,worker_id,violation_count) VALUES (1,1,5),(2,1,3),(3,2,1);
SELECT c.name, m.violation_count FROM community_health_workers c JOIN mental_health_parity_violations m ON c.worker_id = m.worker_id WHERE c.region = 'Los Angeles'
Write a SQL query to retrieve the names and addresses of policyholders aged 30 or older
SELECT name,address FROM policyholders WHERE age >= 30;
SELECT name, address FROM policyholders WHERE age >= 30;
List the names of vessels that have traveled to the port of Dar es Salaam, Tanzania in the last 3 months.
CREATE TABLE vessels (id INT,name TEXT,last_port TEXT,last_port_date DATE); INSERT INTO vessels (id,name,last_port,last_port_date) VALUES (1,'VesselC','Singapore','2021-12-15'); INSERT INTO vessels (id,name,last_port,last_port_date) VALUES (2,'VesselD','Hong Kong','2021-11-30'); INSERT INTO vessels (id,name,last_port,last_port_date) VALUES (3,'VesselE','Dar es Salaam','2022-03-05');
SELECT DISTINCT name FROM vessels WHERE last_port = 'Dar es Salaam' AND last_port_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH);
What is the total revenue from concert ticket sales for a specific artist?
CREATE TABLE Concerts (id INT,artist_id INT,city VARCHAR(50),revenue DECIMAL(10,2));
SELECT SUM(revenue) AS total_revenue FROM Concerts WHERE artist_id = 1;
Show the number of unique species found in each ocean basin in the 'species_distribution' table.
CREATE TABLE species_distribution (species_id INT,ocean_basin VARCHAR(20));
SELECT ocean_basin, COUNT(DISTINCT species_id) FROM species_distribution GROUP BY ocean_basin;
Which ports have not handled any cargo with a weight above a certain threshold?
CREATE TABLE ports (id INT,name VARCHAR(255),location VARCHAR(255),operated_by VARCHAR(255)); CREATE TABLE cargo (id INT,port_id INT,weight INT); INSERT INTO ports (id,name,location,operated_by) VALUES (1,'Port A','New York','Company A'),(2,'Port B','Los Angeles','Company B'); INSERT INTO cargo (id,port_id,weight) VALUES (1,1,5000),(2,1,7000),(3,2,3000);
SELECT ports.name FROM ports LEFT JOIN cargo ON ports.id = cargo.port_id WHERE cargo.weight IS NULL OR cargo.weight <= 5000;
List all artists who have streamed in the USA and held concerts in Canada.
CREATE TABLE music_streaming (artist_id INT,artist_name VARCHAR(100),genre VARCHAR(50),country VARCHAR(50)); CREATE TABLE concert_ticket_sales (concert_id INT,artist_id INT,concert_date DATE,venue VARCHAR(100),country VARCHAR(50));
SELECT DISTINCT artist_name FROM music_streaming WHERE country = 'USA' INTERSECT SELECT DISTINCT artist_name FROM concert_ticket_sales WHERE country = 'Canada';
What is the count of products with ethical labor practices?
CREATE TABLE products (product_id INT,has_ethical_labor BOOLEAN); INSERT INTO products (product_id,has_ethical_labor) VALUES (1,true),(2,false),(3,true),(4,false),(5,true);
SELECT COUNT(*) FROM products WHERE has_ethical_labor = true;
What are the names and daily transaction counts of the top 3 blockchain networks with the highest daily transaction volumes?
CREATE TABLE blockchains (blockchain_id INT,blockchain_name VARCHAR(50),daily_transactions INT); INSERT INTO blockchains (blockchain_id,blockchain_name,daily_transactions) VALUES (1,'Ethereum',50000); INSERT INTO blockchains (blockchain_id,blockchain_name,daily_transactions) VALUES (2,'Solana',100000); INSERT INTO blockchains (blockchain_id,blockchain_name,daily_transactions) VALUES (3,'Cardano',20000); INSERT INTO blockchains (blockchain_id,blockchain_name,daily_transactions) VALUES (4,'Polkadot',30000);
SELECT blockchain_name, daily_transactions FROM blockchains ORDER BY daily_transactions DESC LIMIT 3;
What is the maximum number of innings bowled by a bowler from the north_team in cricket_matches?
CREATE TABLE cricket_teams (team_id INT,team_name VARCHAR(50),region VARCHAR(50));CREATE TABLE cricket_players (player_id INT,player_name VARCHAR(50),position VARCHAR(50),team_id INT);CREATE TABLE cricket_matches (match_id INT,home_team_id INT,away_team_id INT,home_team_innings INT,away_team_innings INT,bowler_id INT);
SELECT MAX(home_team_innings + away_team_innings) AS max_innings FROM cricket_matches JOIN cricket_players ON cricket_matches.bowler_id = cricket_players.player_id JOIN cricket_teams ON cricket_players.team_id = cricket_teams.team_id WHERE cricket_teams.region = 'north_team';
What is the maximum number of virtual tour participants for the exhibition 'African Art: Ancient to Modern' in the last year?
CREATE TABLE virtual_tour_attendees (id INT,exhibition_name VARCHAR(50),participants INT,tour_date DATE); INSERT INTO virtual_tour_attendees (id,exhibition_name,participants,tour_date) VALUES (1,'African Art: Ancient to Modern',120,'2022-03-01'); INSERT INTO virtual_tour_attendees (id,exhibition_name,participants,tour_date) VALUES (2,'African Art: Ancient to Modern',150,'2023-02-15');
SELECT MAX(participants) FROM virtual_tour_attendees WHERE exhibition_name = 'African Art: Ancient to Modern' AND tour_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
What is the average revenue of restaurants in the "downtown" area?
CREATE TABLE restaurants (id INT,name TEXT,area TEXT,revenue FLOAT); INSERT INTO restaurants (id,name,area,revenue) VALUES (1,'Restaurant A','downtown',50000.00),(2,'Restaurant B','uptown',45000.00),(3,'Restaurant C','downtown',60000.00),(4,'Restaurant D','downtown',75000.00);
SELECT AVG(revenue) FROM restaurants WHERE area = 'downtown';
What is the maximum salary in the 'HR' department?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(255),Gender VARCHAR(255),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Department,Gender,Salary) VALUES (1,'IT','Male',75000.00),(2,'Diversity and Inclusion','Female',68000.00),(3,'HR','Male',65000.00);
SELECT MAX(Salary) FROM Employees WHERE Department = 'HR';
List the precision farming crops that are grown in both California and Texas.
CREATE TABLE Crops(state VARCHAR(255),name VARCHAR(255)); INSERT INTO Crops(state,name) VALUES('California','Corn'),('California','Soybean'),('California','Wheat'),('Texas','Cotton'),('Texas','Rice'),('Texas','Corn');
SELECT name FROM Crops WHERE state = 'California' INTERSECT SELECT name FROM Crops WHERE state = 'Texas';
What is the average depth of marine protected areas?
CREATE TABLE marine_protected_areas (area_id INT,name VARCHAR(255),depth FLOAT);
SELECT AVG(depth) FROM marine_protected_areas;
What is the number of volunteers who have participated in programs in each country?
CREATE TABLE volunteers (id INT,volunteer_name VARCHAR,country VARCHAR,program VARCHAR); INSERT INTO volunteers (id,volunteer_name,country,program) VALUES (1,'Alice','USA','Youth Mentoring'),(2,'Bob','Canada','Women Empowerment'),(3,'Charlie','Mexico','Community Service'); CREATE TABLE programs (id INT,program VARCHAR,community VARCHAR); INSERT INTO programs (id,program,community) VALUES (1,'Youth Mentoring','Underrepresented'),(2,'Women Empowerment','Underrepresented'),(3,'Community Service','Underrepresented');
SELECT country, COUNT(*) FROM volunteers v INNER JOIN programs p ON v.program = p.program GROUP BY country;
What is the total number of animals in the 'endangered_species' table, grouped by their 'conservation_status'?
CREATE TABLE endangered_species(id INT,animal_name VARCHAR(50),conservation_status VARCHAR(50)); INSERT INTO endangered_species(id,animal_name,conservation_status) VALUES (1,'Amur Leopard','Critically Endangered'),(2,'Black Rhino','Critically Endangered'),(3,'Bengal Tiger','Endangered');
SELECT conservation_status, COUNT(animal_name) FROM endangered_species GROUP BY conservation_status;
How many vehicles are currently in service for each type in the 'seoul' schema?
CREATE TABLE seoul.vehicle_types (id INT,type VARCHAR); CREATE TABLE seoul.vehicles (id INT,type_id INT,is_active BOOLEAN);
SELECT seoul.vehicle_types.type, COUNT(*) FROM seoul.vehicle_types INNER JOIN seoul.vehicles ON seoul.vehicle_types.id = seoul.vehicles.type_id WHERE seoul.vehicles.is_active = TRUE GROUP BY seoul.vehicle_types.type;
How many military equipment sales were made to Mexico?
CREATE TABLE military_sales(sale_id INT,equipment_name VARCHAR(50),sale_country VARCHAR(50)); INSERT INTO military_sales VALUES (1,'Tank','Canada'),(2,'Helicopter','Canada'),(3,'Airplane','Mexico');
SELECT COUNT(*) FROM military_sales WHERE sale_country = 'Mexico';
Find the number of hospitals and schools in each city.
CREATE TABLE city_facilities (city TEXT,facility_type TEXT,facility_count INTEGER); INSERT INTO city_facilities (city,facility_type,facility_count) VALUES ('CityA','hospitals',2),('CityB','hospitals',1),('CityC','hospitals',1),('CityA','schools',3),('CityB','schools',3),('CityC','schools',2);
SELECT city, facility_type, SUM(facility_count) FROM city_facilities GROUP BY city, facility_type;
Create a view to display all data related to the 'cotton_farming' sector
CREATE TABLE cotton_farming (country VARCHAR(50),region VARCHAR(50),total_production INT,water_usage INT); CREATE VIEW cotton_farming_view AS SELECT * FROM cotton_farming;
CREATE VIEW cotton_farming_view AS SELECT * FROM cotton_farming;
Who are the top 5 customers with the highest calorie intake and their total calorie intake?
CREATE TABLE customers (id INT,name VARCHAR(255)); CREATE TABLE meals (id INT,customer_id INT,name VARCHAR(255),calories INT); INSERT INTO customers (id,name) VALUES (1001,'John Doe'),(1002,'Jane Doe'),(1003,'Mary Smith'); INSERT INTO meals (id,customer_id,name,calories) VALUES (1,1001,'Steak',800),(2,1002,'Poutine',700),(3,1001,'Burger',600),(4,1003,'Salad',400);
SELECT c.name, SUM(m.calories) as total_calories FROM customers c INNER JOIN meals m ON c.id = m.customer_id GROUP BY c.name ORDER BY total_calories DESC LIMIT 5;
How many unique volunteers have participated in each program in 2021?
CREATE TABLE volunteer_programs (id INT,volunteer INT,program TEXT,volunteer_date DATE); INSERT INTO volunteer_programs (id,volunteer,program,volunteer_date) VALUES (1,1,'Education','2021-01-01'),(2,1,'Health','2021-02-01'),(3,2,'Education','2021-01-01'),(4,3,'Arts','2021-03-01');
SELECT program, COUNT(DISTINCT volunteer) AS num_volunteers FROM volunteer_programs WHERE EXTRACT(YEAR FROM volunteer_date) = 2021 GROUP BY program ORDER BY num_volunteers DESC;
Add a new employee from the 'Finance' department who joined the 'Diversity and Inclusion' training program in 2022.
CREATE TABLE finance_training (id INT,name VARCHAR(50),department VARCHAR(50),program VARCHAR(50),training_year INT);
INSERT INTO finance_training (id, name, department, program, training_year) VALUES (3, 'Tariq Ahmed', 'Finance', 'Diversity and Inclusion', 2022);
Find the total size of fish farms in 'oceans' schema where the size is greater than 50.
CREATE SCHEMA oceans; CREATE TABLE fish_farms (id INT,size FLOAT,location VARCHAR(20)); INSERT INTO fish_farms (id,size,location) VALUES (1,55.2,'ocean'),(2,62.5,'ocean'),(3,70.3,'ocean');
SELECT SUM(size) FROM oceans.fish_farms WHERE size > 50;
Delete all emergency incidents reported before '2021-01-01' in district 4 neighborhoods
CREATE TABLE districts (id INT,name VARCHAR(255)); INSERT INTO districts (id,name) VALUES (4,'Uptown'); CREATE TABLE neighborhoods (id INT,district_id INT,name VARCHAR(255)); INSERT INTO neighborhoods (id,district_id,name) VALUES (201,4,'Northside'); INSERT INTO neighborhoods (id,district_id,name) VALUES (202,4,'Southside'); CREATE TABLE emergency_incidents (id INT,neighborhood_id INT,reported_date DATE); INSERT INTO emergency_incidents (id,neighborhood_id,reported_date) VALUES (2001,201,'2020-12-31'); INSERT INTO emergency_incidents (id,neighborhood_id,reported_date) VALUES (2002,201,'2021-01-02'); INSERT INTO emergency_incidents (id,neighborhood_id,reported_date) VALUES (2003,202,'2021-01-01');
DELETE FROM emergency_incidents WHERE reported_date < '2021-01-01' AND neighborhood_id IN (SELECT id FROM neighborhoods WHERE district_id = 4);
What is the number of hotels that have adopted AI voice assistants, grouped by continent?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,ai_voice_assistant BOOLEAN);CREATE TABLE countries (country_id INT,country TEXT,continent TEXT); INSERT INTO hotels VALUES (3,'Hotel D','Canada',true); INSERT INTO countries VALUES (1,'Canada','North America');
SELECT countries.continent, COUNT(*) FROM hotels INNER JOIN countries ON hotels.country = countries.country WHERE hotels.ai_voice_assistant = true GROUP BY countries.continent;
Find the total amount of Shariah-compliant financing for each country?
CREATE TABLE shariah_financing(client_id INT,country VARCHAR(25),amount FLOAT);INSERT INTO shariah_financing(client_id,country,amount) VALUES (1,'Malaysia',5000),(2,'UAE',7000),(3,'Indonesia',6000),(4,'Saudi Arabia',8000);
SELECT country, SUM(amount) as total_financing FROM shariah_financing GROUP BY country;
What is the change in energy efficiency for each smart city compared to the previous year?
CREATE TABLE city_energy_efficiency (city_name TEXT,year INTEGER,efficiency FLOAT); INSERT INTO city_energy_efficiency VALUES ('CityA',2020,0.5),('CityA',2021,0.55),('CityB',2020,0.7),('CityB',2021,0.73);
SELECT a.city_name, a.year, a.efficiency, b.efficiency, a.efficiency - b.efficiency AS difference FROM city_energy_efficiency a INNER JOIN city_energy_efficiency b ON a.city_name = b.city_name AND a.year - 1 = b.year;
How many clinics in Texas offer the Pfizer or Moderna vaccine?
CREATE TABLE clinic_vaccines (clinic_id INT,vaccine_name VARCHAR(255),state VARCHAR(255)); CREATE TABLE clinics (clinic_id INT,clinic_name VARCHAR(255)); INSERT INTO clinic_vaccines (clinic_id,vaccine_name,state) VALUES (1,'Pfizer','Texas'),(2,'Moderna','Texas'); INSERT INTO clinics (clinic_id,clinic_name) VALUES (1,'Clinic A'),(2,'Clinic B');
SELECT COUNT(*) FROM clinic_vaccines v INNER JOIN clinics c ON v.clinic_id = c.clinic_id WHERE v.vaccine_name IN ('Pfizer', 'Moderna') AND v.state = 'Texas';
What is the name and total budget of the intelligence agency with the highest budget in the 'intelligence_budget' view?
CREATE VIEW intelligence_budget AS SELECT agency_id,agency_name,budget FROM intelligence_agency_data WHERE category = 'budget'; CREATE TABLE intelligence_agency_data (agency_id INT PRIMARY KEY,agency_name VARCHAR(100),category VARCHAR(50),data_value FLOAT); INSERT INTO intelligence_agency_data (agency_id,agency_name,category,data_value) VALUES (1,'CIA','budget',15000000000),(2,'NSA','budget',12000000000);
SELECT agency_name, SUM(data_value) FROM intelligence_budget WHERE category = 'budget' GROUP BY agency_name ORDER BY SUM(data_value) DESC LIMIT 1;
What is the total revenue generated by K-pop music from digital sales and streaming platforms in Q4 2021?
CREATE TABLE sales (id INT,song_id INT,revenue FLOAT,sale_type VARCHAR(20),sale_date DATE,genre VARCHAR(20)); INSERT INTO sales (id,song_id,revenue,sale_type,sale_date,genre) VALUES (1,1,12.99,'Digital','2021-12-15','K-pop'),(2,2,6.99,'Streaming','2021-10-01','K-pop');
SELECT SUM(revenue) FROM sales WHERE sale_type IN ('Digital', 'Streaming') AND genre = 'K-pop' AND sale_date >= '2021-10-01' AND sale_date <= '2021-12-31';
What is the total income of clients in Malaysia who are over 30 years old?
CREATE TABLE clients (client_id INT,name VARCHAR(100),age INT,country VARCHAR(50),income DECIMAL(10,2)); INSERT INTO clients (client_id,name,age,country,income) VALUES (4,'Ali Baba',32,'Malaysia',50000);
SELECT SUM(income) FROM clients WHERE country = 'Malaysia' AND age > 30;
Delete records with a heart rate below 60 bpm in the wearables table
CREATE TABLE wearables (member_id INT,device_type VARCHAR(50),heart_rate INT);
DELETE FROM wearables WHERE heart_rate < 60;
List all countries and the number of satellites they have in orbit.
CREATE TABLE countries (id INT,name VARCHAR(50)); CREATE TABLE satellites (id INT,country_id INT,name VARCHAR(50));
SELECT c.name, COUNT(s.id) FROM countries c JOIN satellites s ON c.id = s.country_id GROUP BY c.name;
What is the number of indigenous communities in each Arctic country?
CREATE TABLE IndigenousCommunities (country varchar(50),community_name varchar(50),population int);
SELECT country, COUNT(DISTINCT community_name) AS num_communities FROM IndigenousCommunities GROUP BY country;
What is the maximum salary of sports columnists from the 'writers' and 'salaries' tables?
CREATE TABLE writers (id INT,name VARCHAR(50),gender VARCHAR(10),department VARCHAR(20)); CREATE TABLE salaries (id INT,writer_id INT,salary INT);
SELECT MAX(s.salary) FROM writers w JOIN salaries s ON w.id = s.writer_id WHERE w.department = 'sports_columnist';
What is the distribution of post engagement for each platform?
CREATE TABLE engagement_data (platform VARCHAR(20),engagement NUMERIC(10,2));
SELECT platform, AVG(engagement) FROM engagement_data GROUP BY platform;
How many unique artifact types are present in the 'Artifact_Inventory' table?
CREATE TABLE Artifact_Inventory (id INT,artifact_name VARCHAR(50),artifact_type VARCHAR(50)); INSERT INTO Artifact_Inventory (id,artifact_name,artifact_type) VALUES (1,'Artifact 1','Pottery'),(2,'Artifact 2','Stone Tool'),(3,'Artifact 3','Pottery'),(4,'Artifact 4','Bone Tool');
SELECT COUNT(DISTINCT artifact_type) FROM Artifact_Inventory;
Get the top 3 countries with the most posts related to AI.
CREATE TABLE users (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,content TEXT,created_at TIMESTAMP);
SELECT users.country, COUNT(posts.id) AS posts_count FROM users JOIN posts ON users.id = posts.user_id WHERE posts.content LIKE '%AI%' GROUP BY users.country ORDER BY posts_count DESC LIMIT 3;
Find the top 3 hotel chains with the highest revenue in the 'Chain_Sales' table.
CREATE TABLE Chain_Sales (chain TEXT,revenue INT); INSERT INTO Chain_Sales (chain,revenue) VALUES ('ABC Hotels',800000),('XYZ Hotels',900000),('LMN Hotels',700000);
SELECT chain, revenue FROM (SELECT chain, revenue, DENSE_RANK() OVER (ORDER BY revenue DESC) as rank FROM Chain_Sales) WHERE rank <= 3;
Identify the unique authors who have not contributed to any investigative projects.
CREATE TABLE authors (id INT,name VARCHAR(50)); INSERT INTO authors (id,name) VALUES (1,'Alexandre Oliveira'); INSERT INTO authors (id,name) VALUES (2,'Nina Gupta'); INSERT INTO authors (id,name) VALUES (3,'Park Soo-jin'); CREATE TABLE investigative_projects (id INT,title VARCHAR(100),lead_investigator_id INT,author_id INT); INSERT INTO investigative_projects (id,title,lead_investigator_id,author_id) VALUES (1,'Corruption in Local Government',4,1); INSERT INTO investigative_projects (id,title,lead_investigator_id,author_id) VALUES (2,'Impact of Climate Change on Agriculture',5,3);
SELECT name FROM authors WHERE id NOT IN (SELECT author_id FROM investigative_projects);
What is the total number of construction labor hours worked, by job type, in each state, in the past month, ordered from highest to lowest?
CREATE TABLE LaborHours (State VARCHAR(2),Job VARCHAR(50),HoursWorked DATE);
SELECT State, Job, SUM(HoursWorked) as TotalHours FROM LaborHours WHERE HoursWorked >= DATEADD(MONTH, -1, GETDATE()) GROUP BY State, Job ORDER BY TotalHours DESC;
How many total volunteers have there been in projects funded by the World Bank?
CREATE TABLE volunteers (id INT,project_id INT,name TEXT); INSERT INTO volunteers (id,project_id,name) VALUES (1,1,'Alice'),(2,1,'Bob'),(3,2,'Charlie'); CREATE TABLE projects (id INT,funder TEXT,total_funding DECIMAL); INSERT INTO projects (id,funder,total_funding) VALUES (1,'European Union',20000.00),(2,'World Bank',30000.00);
SELECT COUNT(*) FROM volunteers INNER JOIN projects ON volunteers.project_id = projects.id WHERE projects.funder = 'World Bank';
What is the population rank of Tokyo in Japan?
CREATE TABLE City (CityName VARCHAR(50),Country VARCHAR(50),Population INT); INSERT INTO City (CityName,Country,Population) VALUES ('Tokyo','Japan',9000000),('Yokohama','Japan',3700000),('Osaka','Japan',2700000),('Nagoya','Japan',2300000),('Sapporo','Japan',1900000);
SELECT ROW_NUMBER() OVER (PARTITION BY Country ORDER BY Population DESC) AS PopulationRank, CityName, Population FROM City WHERE Country = 'Japan';
What is the average temperature in degree Celsius for each month in 2020 across all weather stations?
CREATE TABLE WeatherStation (id INT,name TEXT,location TEXT,temperature REAL); INSERT INTO WeatherStation (id,name,location,temperature) VALUES (1,'Station1','Location1',20.5),(2,'Station2','Location2',22.3),(3,'Station3','Location3',19.8);
SELECT AVG(temperature) as avg_temperature, EXTRACT(MONTH FROM timestamp) as month FROM WeatherData WHERE EXTRACT(YEAR FROM timestamp) = 2020 GROUP BY month;
Find the average rating and total number of reviews for artworks by artist 101, and the name and rating of the artwork with the highest rating among artist 101's works.
CREATE TABLE Artworks (artwork_id INT,artist_id INT,artwork_name TEXT,rating INT,num_reviews INT); INSERT INTO Artworks (artwork_id,artist_id,artwork_name,rating,num_reviews) VALUES (1,101,'Painting 1',8,30),(2,101,'Painting 2',9,50),(3,102,'Sculpture 1',7,25); CREATE TABLE ArtistDetails (artist_id INT,artist_name TEXT); INSERT INTO ArtistDetails (artist_id,artist_name) VALUES (101,'John Doe'),(102,'Jane Smith');
SELECT AVG(a.rating) AS avg_rating, AVG(a.num_reviews) AS avg_reviews, ad.artist_name, (SELECT rating FROM Artworks WHERE artist_id = 101 ORDER BY rating DESC LIMIT 1) AS max_rating FROM Artworks a JOIN ArtistDetails ad ON a.artist_id = ad.artist_id WHERE a.artist_id = 101
List all employees who have not been assigned to a department.
CREATE TABLE Employees (id INT,name VARCHAR(255),department VARCHAR(255)); INSERT INTO Employees (id,name,department) VALUES (1,'John Doe','DeptA'),(2,'Jane Smith',NULL);
SELECT name FROM Employees WHERE department IS NULL
How many articles were published in each category on weekdays (Monday to Friday) and weekends (Saturday and Sunday) from the 'news_articles' table?
CREATE TABLE news_articles (article_id INT,author VARCHAR(50),title VARCHAR(100),publication_date DATE,category VARCHAR(20)); INSERT INTO news_articles (article_id,author,title,publication_date,category) VALUES (1,'John Doe','Article 1','2022-01-01','Politics'),(2,'Jane Smith','Article 2','2022-01-02','Sports');
SELECT category, CASE WHEN DATEPART(dw, publication_date) IN (1, 7) THEN 'Weekend' ELSE 'Weekday' END as day_type, COUNT(*) as article_count FROM news_articles GROUP BY category, CASE WHEN DATEPART(dw, publication_date) IN (1, 7) THEN 'Weekend' ELSE 'Weekday' END;
What are the total marketing costs for each TV show genre in Q1 2020?
CREATE TABLE TVShows (show_id INT,title VARCHAR(255),release_date DATE,genre VARCHAR(255),marketing_cost DECIMAL(5,2)); INSERT INTO TVShows (show_id,title,release_date,genre,marketing_cost) VALUES (1,'Show1','2019-10-01','Sci-Fi',500000.00),(2,'Show2','2018-04-15','Comedy',350000.00),(3,'Show3','2020-02-20','Action',750000.00);
SELECT genre, SUM(marketing_cost) FROM TVShows WHERE release_date >= '2020-01-01' AND release_date < '2020-04-01' GROUP BY genre;
Update the name of all electric boats in Vancouver to reflect the new naming convention.
CREATE TABLE public.boats (id SERIAL PRIMARY KEY,name TEXT,speed FLOAT,city TEXT); INSERT INTO public.boats (name,speed,city) VALUES ('Electric Boat 1',12.5,'Vancouver'),('Electric Boat 2',13.6,'Vancouver');
UPDATE public.boats SET name = REPLACE(name, 'Electric Boat', 'Vancouver Electric Boat') WHERE city = 'Vancouver';
What is the total number of workers represented by labor unions in the service sector?
CREATE TABLE unions (id INT,name TEXT,industry TEXT,workers_represented INT); INSERT INTO unions (id,name,industry,workers_represented) VALUES (1,'Unite Here','Service',300000);
SELECT SUM(workers_represented) FROM unions WHERE industry = 'Service';
What is the maximum number of hours played in a week for players who have played "Fortnite" and are from Germany?
CREATE TABLE PlayerActivity (player_id INT,game VARCHAR(100),hours INT,week INT); INSERT INTO PlayerActivity (player_id,game,hours,week) VALUES (1,'Fortnite',15,1),(2,'Fortnite',20,2),(3,'Minecraft',10,1);
SELECT MAX(hours) FROM PlayerActivity pa WHERE pa.game = 'Fortnite' AND pa.week IN (1, 2) AND EXISTS (SELECT 1 FROM Players p WHERE p.player_id = pa.player_id AND p.country = 'Germany');
List of countries with the highest environmental impact score in the past year.
CREATE TABLE EnvironmentalImpact(id INT,country VARCHAR(50),year INT,score FLOAT); CREATE TABLE CountryPopulation(id INT,country VARCHAR(50),population INT);
SELECT country, score FROM (SELECT country, score, ROW_NUMBER() OVER (ORDER BY score DESC) as rank FROM EnvironmentalImpact WHERE year = YEAR(CURRENT_DATE) - 1) AS subquery WHERE rank <= 5;
How many farmers in 'urban_area_1' produce organic crops?
CREATE TABLE urban_area_1 (farmer_id INTEGER,crops_organic BOOLEAN); INSERT INTO urban_area_1 (farmer_id,crops_organic) VALUES (1,true),(2,false),(3,true),(4,true),(5,false);
SELECT COUNT(*) FROM urban_area_1 WHERE crops_organic = true;
Which artists have works in the Met and MoMA?
CREATE TABLE Artworks (ArtworkID INT,Name VARCHAR(100),Artist VARCHAR(100),Year INT);
SELECT Artworks.Artist FROM Artworks
Update the risk category of policyholders with a high claim amount to 'High Risk'.
CREATE TABLE Policyholders (ID INT,Name VARCHAR(50),Age INT,Gender VARCHAR(10),City VARCHAR(50),State VARCHAR(20),ZipCode VARCHAR(10),RiskCategory VARCHAR(10)); CREATE TABLE Claims (ID INT,PolicyholderID INT,ClaimAmount DECIMAL(10,2),ClaimDate DATE);
UPDATE Policyholders SET RiskCategory = 'High Risk' WHERE ID IN (SELECT PolicyholderID FROM Claims WHERE ClaimAmount > (SELECT AVG(ClaimAmount) FROM Claims));
What is the maximum number of hospital beds in rural hospitals in Alabama?
CREATE TABLE alabama_rural_hospitals (hospital_id INT,hospital_name VARCHAR(255),rural BOOLEAN,num_beds INT); INSERT INTO alabama_rural_hospitals VALUES (1,'Hospital A',true,50),(2,'Hospital B',false,100);
SELECT MAX(num_beds) FROM alabama_rural_hospitals WHERE rural = true;
What is the average drug approval time for oncology drugs in the US?
CREATE TABLE drug_approval (drug_name TEXT,approval_date DATE,therapy_area TEXT); INSERT INTO drug_approval (drug_name,approval_date,therapy_area) VALUES ('DrugE','2018-01-01','Oncology'),('DrugF','2019-01-01','Oncology'),('DrugG','2020-01-01','Cardiology');
SELECT AVG(DATEDIFF('2022-01-01', approval_date)) AS avg_approval_time FROM drug_approval WHERE therapy_area = 'Oncology';
List all bioprocess engineering diagrams that do not have a process associated with them.
CREATE TABLE diagrams (id INT,name TEXT,process TEXT,engineer TEXT); INSERT INTO diagrams (id,name,process,engineer) VALUES (1,'Diagram X','Fermentation','John Doe'); INSERT INTO diagrams (id,name,process,engineer) VALUES (2,'Diagram Y',NULL,'Jane Smith');
SELECT * FROM diagrams WHERE process IS NULL;
How many unique customers have purchased plus size clothing in the last year, by gender?
CREATE TABLE Customers (customer_id INT,gender VARCHAR(10),registration_date DATE); CREATE TABLE Orders (order_id INT,customer_id INT,order_date DATE); CREATE TABLE Order_Items (item_id INT,order_id INT,product_size VARCHAR(10)); INSERT INTO Customers (customer_id,gender,registration_date) VALUES (1,'Female','2020-01-01');
SELECT gender, COUNT(DISTINCT customer_id) as num_customers FROM Customers JOIN Orders ON Customers.customer_id = Orders.customer_id JOIN Order_Items ON Orders.order_id = Order_Items.order_id WHERE product_size = 'Plus' AND Orders.order_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE GROUP BY gender;
What is the total number of crimes committed in each borough per month?
CREATE TABLE borough_crimes (borough VARCHAR(255),month VARCHAR(255),count INT); INSERT INTO borough_crimes (borough,month,count) VALUES ('Manhattan','Jan',30),('Manhattan','Feb',40),('Brooklyn','Jan',35),('Brooklyn','Feb',45);
SELECT borough, month, SUM(count) OVER (PARTITION BY borough, month) FROM borough_crimes;
How many volunteers are needed for each program in the Midwest region?
CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE volunteers (id INT,name VARCHAR(50),program_id INT); INSERT INTO programs (id,name,location) VALUES (1,'Education','Michigan'),(2,'Environment','Illinois'); INSERT INTO volunteers (id,name,program_id) VALUES (1,'Alice',1),(2,'Bob',1),(3,'Charlie',2);
SELECT p.name, COUNT(v.id) FROM programs p INNER JOIN volunteers v ON p.id = v.program_id WHERE p.location = 'Michigan' OR p.location = 'Illinois' GROUP BY p.name;
Find the total profit from Shariah-compliant investments for clients with a high financial capability score?
CREATE TABLE clients (client_id INT,financial_capability_score INT); INSERT INTO clients (client_id,financial_capability_score) VALUES (1,8),(2,5),(3,10),(4,7),(5,3); CREATE TABLE investments (investment_id INT,client_id INT,is_shariah_compliant BOOLEAN,profit DECIMAL(10,2)); INSERT INTO investments (investment_id,client_id,is_shariah_compliant,profit) VALUES (1001,1,true,250),(1002,1,false,300),(1003,2,true,150),(1004,3,true,200),(1005,3,false,50),(1006,4,true,900),(1007,5,true,250);
SELECT SUM(investments.profit) FROM investments INNER JOIN clients ON investments.client_id = clients.client_id WHERE investments.is_shariah_compliant = true AND clients.financial_capability_score > 7;
What is the total recycling rate in percentage for industrial areas in Beijing for the year 2021?
CREATE TABLE recycling_rates_china(location VARCHAR(50),year INT,recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates_china(location,year,recycling_rate) VALUES ('Beijing',2021,0.78),('Beijing',2021,0.79),('Beijing',2021,0.80),('Shanghai',2021,0.85),('Shanghai',2021,0.86),('Shanghai',2021,0.87);
SELECT AVG(recycling_rate) FROM recycling_rates_china WHERE location = 'Beijing' AND year = 2021;
Calculate the maximum temperature difference between consecutive days for 'Field_8' in the 'temperature_data' table.
CREATE TABLE temperature_data (field VARCHAR(255),temperature FLOAT,timestamp TIMESTAMP);
SELECT field, MAX(temperature - LAG(temperature) OVER (PARTITION BY field ORDER BY timestamp)) as max_diff FROM temperature_data WHERE field = 'Field_8';
How many autonomous buses are there in New York City?
CREATE TABLE Autonomous_Vehicles (id INT,make VARCHAR(50),model VARCHAR(50),year INT,type VARCHAR(50),city VARCHAR(50));
SELECT COUNT(*) FROM Autonomous_Vehicles WHERE type = 'bus' AND city = 'New York';
Delete all pollution control initiatives before 2022.
CREATE TABLE pollution_initiatives (initiative_id INT,site_id INT,initiative_date DATE,initiative_description TEXT); INSERT INTO pollution_initiatives (initiative_id,site_id,initiative_date,initiative_description) VALUES (1,1,'2022-08-01','Installed new filters'),(2,3,'2022-07-15','Regular cleaning schedule established');
DELETE FROM pollution_initiatives WHERE initiative_date < '2022-01-01';
What is the total cost of space missions by ESA?
CREATE TABLE SpaceMissions (name TEXT,agency TEXT,cost INTEGER);INSERT INTO SpaceMissions (name,agency,cost) VALUES ('Herschel Space Observatory','ESA',1400000000); INSERT INTO SpaceMissions (name,agency,cost) VALUES ('Gaia Mission','ESA',900000000);
SELECT SUM(cost) FROM SpaceMissions WHERE agency = 'ESA';
What is the combined capacity of all rural healthcare facilities in Florida?
CREATE TABLE facilities (id INT,name TEXT,location TEXT,capacity INT); INSERT INTO facilities (id,name,location,capacity) VALUES (1,'Rural Family Health Center','Florida',50),(2,'Rural General Hospital','Florida',200),(3,'Rural Community Clinic','Georgia',25);
SELECT SUM(capacity) FROM facilities WHERE location = 'Florida';
What is the total tonnes extracted by each mining operation, ordered by the most to least?
CREATE TABLE Operations (OperationID INT,MineName VARCHAR(50),OperationType VARCHAR(50),StartDate DATE,EndDate DATE,TotalTonnes DECIMAL(10,2)); INSERT INTO Operations (OperationID,MineName,OperationType,StartDate,EndDate,TotalTonnes) VALUES (1,'ABC Mine','Coal Mining','2020-01-01','2020-12-31',150000.00); INSERT INTO Operations (OperationID,MineName,OperationType,StartDate,EndDate,TotalTonnes) VALUES (2,'DEF Mine','Gold Mining','2020-01-01','2020-12-31',5000.00);
SELECT OperationID, MineName, OperationType, TotalTonnes, ROW_NUMBER() OVER (ORDER BY TotalTonnes DESC) as 'Rank' FROM Operations;
Which climate communication projects are not in 'North America'?
CREATE TABLE climate_communication (project_id INTEGER,project_name TEXT,location TEXT); INSERT INTO climate_communication (project_id,project_name,location) VALUES (1,'Project I','North America'),(2,'Project J','Europe');
SELECT project_name FROM climate_communication WHERE location != 'North America';
List all movies and their genres that have been released on streaming services, ordered by the release date in ascending order.
CREATE TABLE movies (movie_id INT,title TEXT,genre TEXT,release_date DATE,platform TEXT); INSERT INTO movies (movie_id,title,genre,release_date,platform) VALUES (1,'Movie 10','Comedy','2018-01-01','Disney+'),(2,'Movie 11','Drama','2019-06-15','Apple TV'),(3,'Movie 12','Action','2020-12-25','HBO Max');
SELECT movies.title, movies.genre, movies.release_date FROM movies ORDER BY movies.release_date ASC;
What is the maximum response time for emergency calls in the 'metro' schema?
CREATE SCHEMA if not exists metro; CREATE TABLE if not exists metro.emergency_responses (id INT,response_time TIME); INSERT INTO metro.emergency_responses (id,response_time) VALUES (1,'01:34:00'),(2,'02:15:00'),(3,'01:52:00');
SELECT MAX(TIME_TO_SEC(response_time)) FROM metro.emergency_responses;
How many carbon offset programs exist in each state?
CREATE TABLE carbon_offsets (state VARCHAR(50),program_id INT); INSERT INTO carbon_offsets (state,program_id) VALUES ('CA',123),('NY',456),('OR',789);
SELECT state, COUNT(program_id) as num_programs FROM carbon_offsets GROUP BY state;
What are the names and types of military satellites launched since 2010?
CREATE TABLE Satellites (ID INT,Name VARCHAR(50),LaunchYear INT,SatelliteType VARCHAR(50));
SELECT Name, SatelliteType FROM Satellites WHERE LaunchYear >= 2010;
What is the total budget allocated for disability accessibility modifications for each building in the past year, ordered by the building with the highest budget?
CREATE TABLE Disability_Accessibility_Modifications (Building VARCHAR(50),Budget NUMERIC(10,2),Modification_Date DATE); INSERT INTO Disability_Accessibility_Modifications VALUES ('Building A',100000,'2021-01-01'),('Building B',120000,'2021-02-01'),('Building C',90000,'2021-03-01'),('Building A',110000,'2021-04-01'),('Building B',130000,'2021-05-01');
SELECT Building, SUM(Budget) as Total_Budget FROM Disability_Accessibility_Modifications WHERE Modification_Date >= DATEADD(year, -1, GETDATE()) GROUP BY Building ORDER BY Total_Budget DESC;
What is the distribution of network infrastructure investments across regions in the year 2021?
CREATE TABLE network_investments (investment_id INT,region VARCHAR(50),amount INT,investment_date DATE); INSERT INTO network_investments (investment_id,region,amount,investment_date) VALUES (1,'North',1000000,'2021-01-01');
SELECT region, EXTRACT(MONTH FROM investment_date) AS month, SUM(amount) FROM network_investments WHERE EXTRACT(YEAR FROM investment_date) = 2021 GROUP BY region, EXTRACT(MONTH FROM investment_date);
What was the minimum water temperature in the Atlantic Ocean Monitoring Station in June 2020?
CREATE TABLE atlantic_ocean_monitoring_station (date DATE,temperature FLOAT);
SELECT MIN(temperature) AS min_temperature FROM atlantic_ocean_monitoring_station WHERE date BETWEEN '2020-06-01' AND '2020-06-30';
What is the minimum health equity metric score for mental health facilities in rural areas?
CREATE TABLE mental_health_facilities (facility_id INT,location TEXT,score INT); INSERT INTO mental_health_facilities (facility_id,location,score) VALUES (1,'Urban',80),(2,'Rural',75),(3,'Suburban',85);
SELECT MIN(score) FROM mental_health_facilities WHERE location = 'Rural';
What is the average time between equipment maintenance for each type of military equipment?
CREATE TABLE Equipment_Maintenance (ID INT,Equipment_Type VARCHAR(255),Maintenance_Date DATE); INSERT INTO Equipment_Maintenance (ID,Equipment_Type,Maintenance_Date) VALUES (1,'Aircraft','2020-01-01'),(2,'Vehicles','2020-02-15'),(3,'Naval','2020-03-01'),(4,'Aircraft','2020-04-10'),(5,'Weaponry','2020-05-01');
SELECT Equipment_Type, AVG(DATEDIFF(day, LAG(Maintenance_Date) OVER (PARTITION BY Equipment_Type ORDER BY Maintenance_Date), Maintenance_Date)) as Avg_Maintenance_Interval FROM Equipment_Maintenance GROUP BY Equipment_Type;
What is the minimum donation amount given by a donor from Europe?
CREATE TABLE donors (id INT,name VARCHAR(100),country VARCHAR(50),donation DECIMAL(10,2)); INSERT INTO donors (id,name,country,donation) VALUES (1,'John Doe','USA',50.00),(2,'Jane Smith','USA',100.00),(3,'Alice Johnson','Canada',75.00),(4,'Bob Brown','Africa',25.00),(5,'Charlie Green','Africa',100.00),(6,'Oliver White','England',30.00),(7,'Sophia Black','France',20.00);
SELECT MIN(donation) FROM donors WHERE country = 'England' OR country = 'France';
How many users joined Twitter from India in the last year?
CREATE TABLE user_data (user_id INT,join_date DATE,country VARCHAR(50)); INSERT INTO user_data (user_id,join_date,country) VALUES (1,'2021-01-01','India'),(2,'2022-01-02','USA'),(3,'2021-06-03','India');
SELECT COUNT(*) FROM user_data WHERE country = 'India' AND join_date >= DATEADD(year, -1, GETDATE());
Identify the number of dispensaries that have been licensed in Washington State since 2015, but haven't reported any sales by the end of 2021.
CREATE TABLE dispensaries (id INT,name TEXT,state TEXT,license_date DATE,first_sale_date DATE); INSERT INTO dispensaries (id,name,state,license_date,first_sale_date) VALUES (1,'Green Shelter','Washington','2016-01-01','2016-02-01'),(2,'Purple Leaf','Washington','2015-12-31','2015-12-31'),(3,'Bud Haven','Washington','2017-06-15','2017-07-01');
SELECT COUNT(*) FROM (SELECT * FROM dispensaries WHERE state = 'Washington' AND license_date <= '2015-12-31' AND first_sale_date > '2021-12-31' EXCEPT SELECT * FROM (SELECT DISTINCT * FROM dispensaries)) tmp;
What was the average age of audience members at theater performances in the UK and Spain?
CREATE TABLE TheaterPerformances (id INT,performance_name VARCHAR(50),audience_member_name VARCHAR(50),country VARCHAR(50),performance_date DATE,age INT); INSERT INTO TheaterPerformances (id,performance_name,audience_member_name,country,performance_date,age) VALUES (1,'Shakespeare Play','John','UK','2022-08-01',35),(2,'Comedy Show','Jane','Spain','2022-08-05',28),(3,'Drama Performance','Mark','UK','2022-08-03',42),(4,'Musical','Natalie','Spain','2022-08-07',31);
SELECT AVG(age) FROM TheaterPerformances WHERE country IN ('UK', 'Spain');
What is the average rating of art programs in the Eastern region with a budget over $10,000?
CREATE TABLE programs (id INT,region VARCHAR(50),budget DECIMAL(10,2),rating INT); INSERT INTO programs (id,region,budget,rating) VALUES (1,'Midwest',8000,8),(2,'Northeast',12000,9),(3,'West Coast',7000,7),(4,'Southeast',15000,10),(5,'Eastern',11000,6);
SELECT AVG(rating) FROM programs WHERE region = 'Eastern' AND budget > 10000;
Which OTA platforms generated the most revenue in Europe in the last year?
CREATE TABLE ota_revenue (revenue_id INT,ota_platform VARCHAR(50),region VARCHAR(20),revenue_date DATE,revenue FLOAT);
SELECT ota_platform, region, SUM(revenue) as total_revenue FROM ota_revenue WHERE region = 'Europe' AND revenue_date >= DATE(NOW()) - INTERVAL 1 YEAR GROUP BY ota_platform ORDER BY total_revenue DESC;
Delete the 'Nature Nurturers' education program record from the 'education_programs' table
CREATE TABLE education_programs (id INT,name VARCHAR(50),description TEXT,target_audience VARCHAR(50),duration INT);
DELETE FROM education_programs WHERE name = 'Nature Nurturers';
List all the unique types of crops grown in 'Africa' in 2019 and the number of times they appear?
CREATE TABLE crops (id INT,crop_name VARCHAR(20),country VARCHAR(20),production INT,year INT); INSERT INTO crops (id,crop_name,country,production,year) VALUES (1,'corn','Africa',20000,2019),(2,'cassava','Africa',30000,2019),(3,'sorghum','Africa',15000,2019);
SELECT DISTINCT crop_name, COUNT(crop_name) as crop_count FROM crops WHERE country = 'Africa' AND year = 2019 GROUP BY crop_name;
List all decentralized applications in the 'Ethereum' network that were launched after 2022-06-01.
CREATE TABLE ethereum_dapps (id INT,name VARCHAR(255),network VARCHAR(255),launch_date DATE); INSERT INTO ethereum_dapps (id,name,network,launch_date) VALUES (1,'Dapp1','ethereum','2022-07-01'),(2,'Dapp2','ethereum','2022-05-01');
SELECT * FROM ethereum_dapps WHERE network = 'ethereum' AND launch_date > '2022-06-01';