Prompt:
Schema:
  sales (alias: sale)(amount, level, date, id)
  products(date, type, code, amount)
Task: Retrieve amount from sales whose level is found in products rows where type matches the outer record.
SQL:

SELECT amount FROM sales AS sale
WHERE level IN (
    SELECT level FROM products AS prod
    WHERE prod.type = sale.type
);


Prompt:
Schema:
  budgets (alias: budg)(level, date, status, type)
  customers(type, level, salary, id)
Task: Retrieve id from budgets that have at least one corresponding entry in customers sharing the same level.
SQL:

SELECT id FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.level = budg.level
);


Prompt:
Schema:
  departments (alias: dept)(level, status, salary, date)
  staff(amount, salary, status, code)
Task: Find amount from departments where level appears in staff entries with matching type.
SQL:

SELECT amount FROM departments AS dept
WHERE level IN (
    SELECT level FROM staff AS empl
    WHERE empl.type = dept.type
);


Prompt:
Schema:
  staff (alias: empl)(level, date, status, amount)
  shipments(value, level, date, amount)
Task: Find salary from staff where a matching record exists in shipments with the same id.
SQL:

SELECT salary FROM staff AS empl
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.id = empl.id
);


Prompt:
Schema:
  schedules (alias: schd)(date, salary, status, type)
  services(date, level, status, salary)
Task: Retrieve salary from schedules that have at least one corresponding entry in services sharing the same type.
SQL:

SELECT salary FROM schedules AS schd
WHERE EXISTS (
    SELECT 1 FROM services AS srvc
    WHERE srvc.type = schd.type
);


Prompt:
Schema:
  managers (alias: mgr)(value, name, type, salary)
  customers(code, salary, name, id)
Task: Select code from managers where id exists in customers for the same id.
SQL:

SELECT code FROM managers AS mgr
WHERE id IN (
    SELECT id FROM customers AS cust
    WHERE cust.id = mgr.id
);


Prompt:
Schema:
  services (alias: srvc)(status, amount, name, value)
  accounts(id, amount, type, status)
Task: Retrieve name from services with value above the MIN(salary) of accounts rows sharing the same status.
SQL:

SELECT name FROM services AS srvc
WHERE value > (
    SELECT MIN(salary) FROM accounts AS acct
    WHERE acct.status = srvc.status
);


Prompt:
Schema:
  schedules (alias: schd)(name, code, date, value)
  items(name, code, level, amount)
Task: Find name from schedules where a matching record exists in items with the same id.
SQL:

SELECT name FROM schedules AS schd
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.id = schd.id
);


Prompt:
Schema:
  employees (alias: emp)(value, status, code, type)
  items(id, value, salary, name)
Task: Retrieve value from employees whose id is found in items rows where status matches the outer record.
SQL:

SELECT value FROM employees AS emp
WHERE id IN (
    SELECT id FROM items AS lne
    WHERE lne.status = emp.status
);


Prompt:
Schema:
  requests (alias: ordr)(status, id, level, amount)
  regions(id, date, name, value)
Task: Retrieve value from requests whose id is found in regions rows where id matches the outer record.
SQL:

SELECT value FROM requests AS ordr
WHERE id IN (
    SELECT id FROM regions AS rgn
    WHERE rgn.id = ordr.id
);


Prompt:
Schema:
  customers (alias: cust)(value, amount, level, type)
  regions(value, code, date, type)
Task: Retrieve salary from customers with amount above the SUM(amount) of regions rows sharing the same code.
SQL:

SELECT salary FROM customers AS cust
WHERE amount > (
    SELECT SUM(amount) FROM regions AS rgn
    WHERE rgn.code = cust.code
);


Prompt:
Schema:
  staff (alias: empl)(level, value, amount, status)
  invoices(status, level, date, salary)
Task: Find value from staff where a matching record exists in invoices with the same id.
SQL:

SELECT value FROM staff AS empl
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.id = empl.id
);


Prompt:
Schema:
  regions (alias: rgn)(code, amount, date, value)
  schedules(code, date, level, type)
Task: Find amount from regions where salary exceeds the average value from schedules for the same status.
SQL:

SELECT amount FROM regions AS rgn
WHERE salary > (
    SELECT MAX(value) FROM schedules AS schd
    WHERE schd.status = rgn.status
);


Prompt:
Schema:
  categories (alias: catg)(salary, type, level, id)
  warehouses(id, value, level, name)
Task: Find code from categories where level appears in warehouses entries with matching status.
SQL:

SELECT code FROM categories AS catg
WHERE level IN (
    SELECT level FROM warehouses AS whs
    WHERE whs.status = catg.status
);


Prompt:
Schema:
  shipments (alias: shp)(value, type, salary, code)
  invoices(level, status, name, date)
Task: Find code from shipments where a matching record exists in invoices with the same id.
SQL:

SELECT code FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.id = shp.id
);


Prompt:
Schema:
  shipments (alias: shp)(status, level, date, type)
  staff(code, status, type, name)
Task: Retrieve amount from shipments that have at least one corresponding entry in staff sharing the same id.
SQL:

SELECT amount FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.id = shp.id
);


Prompt:
Schema:
  invoices (alias: inv)(salary, level, amount, name)
  categories(level, status, type, code)
Task: Retrieve value from invoices with value above the COUNT(amount) of categories rows sharing the same type.
SQL:

SELECT value FROM invoices AS inv
WHERE value > (
    SELECT COUNT(amount) FROM categories AS catg
    WHERE catg.type = inv.type
);


Prompt:
Schema:
  categories (alias: catg)(date, value, status, type)
  products(status, code, date, amount)
Task: Find name from categories where code appears in products entries with matching id.
SQL:

SELECT name FROM categories AS catg
WHERE code IN (
    SELECT code FROM products AS prod
    WHERE prod.id = catg.id
);


Prompt:
Schema:
  warehouses (alias: whs)(amount, date, id, value)
  staff(date, amount, code, level)
Task: Retrieve salary from warehouses that have at least one corresponding entry in staff sharing the same id.
SQL:

SELECT salary FROM warehouses AS whs
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.id = whs.id
);


Prompt:
Schema:
  schedules (alias: schd)(status, name, date, type)
  accounts(status, name, level, salary)
Task: Find code from schedules where a matching record exists in accounts with the same id.
SQL:

SELECT code FROM schedules AS schd
WHERE EXISTS (
    SELECT 1 FROM accounts AS acct
    WHERE acct.id = schd.id
);


Prompt:
Schema:
  orders (alias: ord)(salary, name, status, value)
  categories(value, id, name, amount)
Task: Retrieve name from orders that have at least one corresponding entry in categories sharing the same id.
SQL:

SELECT name FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM categories AS catg
    WHERE catg.id = ord.id
);


Prompt:
Schema:
  budgets (alias: budg)(code, status, type, amount)
  items(type, code, name, value)
Task: Find code from budgets where id appears in items entries with matching level.
SQL:

SELECT code FROM budgets AS budg
WHERE id IN (
    SELECT id FROM items AS lne
    WHERE lne.level = budg.level
);


Prompt:
Schema:
  orders (alias: ord)(type, value, salary, date)
  schedules(date, salary, type, status)
Task: Retrieve id from orders whose status is found in schedules rows where type matches the outer record.
SQL:

SELECT id FROM orders AS ord
WHERE status IN (
    SELECT status FROM schedules AS schd
    WHERE schd.type = ord.type
);


Prompt:
Schema:
  transactions (alias: txn)(salary, status, name, date)
  invoices(id, status, value, type)
Task: Retrieve amount from transactions with amount above the SUM(value) of invoices rows sharing the same id.
SQL:

SELECT amount FROM transactions AS txn
WHERE amount > (
    SELECT SUM(value) FROM invoices AS inv
    WHERE inv.id = txn.id
);


Prompt:
Schema:
  invoices (alias: inv)(amount, value, type, name)
  regions(status, amount, type, code)
Task: Retrieve id from invoices whose type is found in regions rows where code matches the outer record.
SQL:

SELECT id FROM invoices AS inv
WHERE type IN (
    SELECT type FROM regions AS rgn
    WHERE rgn.code = inv.code
);


Prompt:
Schema:
  transactions (alias: txn)(value, code, date, status)
  staff(type, value, code, level)
Task: Retrieve id from transactions that have at least one corresponding entry in staff sharing the same id.
SQL:

SELECT id FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.id = txn.id
);


Prompt:
Schema:
  items (alias: lne)(amount, level, code, status)
  regions(type, amount, level, salary)
Task: Retrieve code from items that have at least one corresponding entry in regions sharing the same type.
SQL:

SELECT code FROM items AS lne
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.type = lne.type
);


Prompt:
Schema:
  items (alias: lne)(id, amount, value, type)
  sales(status, type, value, amount)
Task: Retrieve amount from items with amount above the MAX(salary) of sales rows sharing the same code.
SQL:

SELECT amount FROM items AS lne
WHERE amount > (
    SELECT MAX(salary) FROM sales AS sale
    WHERE sale.code = lne.code
);


Prompt:
Schema:
  managers (alias: mgr)(value, salary, name, code)
  shipments(name, salary, amount, id)
Task: Find amount from managers where salary exceeds the average value from shipments for the same id.
SQL:

SELECT amount FROM managers AS mgr
WHERE salary > (
    SELECT MIN(value) FROM shipments AS shp
    WHERE shp.id = mgr.id
);


Prompt:
Schema:
  products (alias: prod)(code, name, amount, salary)
  customers(date, name, type, amount)
Task: Find code from products where amount exceeds the average value from customers for the same level.
SQL:

SELECT code FROM products AS prod
WHERE amount > (
    SELECT MIN(value) FROM customers AS cust
    WHERE cust.level = prod.level
);


Prompt:
Schema:
  sales (alias: sale)(type, name, value, status)
  staff(name, code, value, date)
Task: Retrieve value from sales with value above the SUM(amount) of staff rows sharing the same code.
SQL:

SELECT value FROM sales AS sale
WHERE value > (
    SELECT SUM(amount) FROM staff AS empl
    WHERE empl.code = sale.code
);


Prompt:
Schema:
  shipments (alias: shp)(id, amount, name, salary)
  services(id, level, name, salary)
Task: Retrieve name from shipments with amount above the AVG(salary) of services rows sharing the same id.
SQL:

SELECT name FROM shipments AS shp
WHERE amount > (
    SELECT AVG(salary) FROM services AS srvc
    WHERE srvc.id = shp.id
);


Prompt:
Schema:
  requests (alias: ordr)(name, code, value, id)
  managers(name, status, level, amount)
Task: Retrieve salary from requests with value above the AVG(salary) of managers rows sharing the same code.
SQL:

SELECT salary FROM requests AS ordr
WHERE value > (
    SELECT AVG(salary) FROM managers AS mgr
    WHERE mgr.code = ordr.code
);


Prompt:
Schema:
  warehouses (alias: whs)(code, name, date, type)
  schedules(date, level, amount, id)
Task: Retrieve salary from warehouses with amount above the SUM(salary) of schedules rows sharing the same id.
SQL:

SELECT salary FROM warehouses AS whs
WHERE amount > (
    SELECT SUM(salary) FROM schedules AS schd
    WHERE schd.id = whs.id
);


Prompt:
Schema:
  requests (alias: ordr)(value, amount, code, level)
  products(amount, level, status, name)
Task: Find id from requests where amount exceeds the average amount from products for the same status.
SQL:

SELECT id FROM requests AS ordr
WHERE amount > (
    SELECT MIN(amount) FROM products AS prod
    WHERE prod.status = ordr.status
);


Prompt:
Schema:
  departments (alias: dept)(level, code, amount, name)
  employees(name, date, status, id)
Task: Find code from departments where id appears in employees entries with matching status.
SQL:

SELECT code FROM departments AS dept
WHERE id IN (
    SELECT id FROM employees AS emp
    WHERE emp.status = dept.status
);


Prompt:
Schema:
  staff (alias: empl)(level, status, type, name)
  categories(date, name, level, id)
Task: Retrieve salary from staff with value above the AVG(value) of categories rows sharing the same status.
SQL:

SELECT salary FROM staff AS empl
WHERE value > (
    SELECT AVG(value) FROM categories AS catg
    WHERE catg.status = empl.status
);


Prompt:
Schema:
  requests (alias: ordr)(amount, name, type, salary)
  customers(type, value, code, salary)
Task: Find name from requests where type appears in customers entries with matching code.
SQL:

SELECT name FROM requests AS ordr
WHERE type IN (
    SELECT type FROM customers AS cust
    WHERE cust.code = ordr.code
);


Prompt:
Schema:
  customers (alias: cust)(amount, status, value, type)
  staff(type, value, id, level)
Task: Find salary from customers where amount exceeds the average amount from staff for the same level.
SQL:

SELECT salary FROM customers AS cust
WHERE amount > (
    SELECT SUM(amount) FROM staff AS empl
    WHERE empl.level = cust.level
);


Prompt:
Schema:
  managers (alias: mgr)(status, salary, level, name)
  employees(type, id, status, name)
Task: Find name from managers where amount exceeds the average value from employees for the same type.
SQL:

SELECT name FROM managers AS mgr
WHERE amount > (
    SELECT COUNT(value) FROM employees AS emp
    WHERE emp.type = mgr.type
);


Prompt:
Schema:
  departments (alias: dept)(code, level, salary, name)
  accounts(amount, date, salary, name)
Task: Select id from departments where type exists in accounts for the same id.
SQL:

SELECT id FROM departments AS dept
WHERE type IN (
    SELECT type FROM accounts AS acct
    WHERE acct.id = dept.id
);


Prompt:
Schema:
  managers (alias: mgr)(code, date, level, amount)
  orders(amount, salary, type, date)
Task: Retrieve code from managers with salary above the SUM(value) of orders rows sharing the same id.
SQL:

SELECT code FROM managers AS mgr
WHERE salary > (
    SELECT SUM(value) FROM orders AS ord
    WHERE ord.id = mgr.id
);


Prompt:
Schema:
  regions (alias: rgn)(value, salary, type, status)
  categories(salary, value, status, id)
Task: Retrieve amount from regions that have at least one corresponding entry in categories sharing the same level.
SQL:

SELECT amount FROM regions AS rgn
WHERE EXISTS (
    SELECT 1 FROM categories AS catg
    WHERE catg.level = rgn.level
);


Prompt:
Schema:
  budgets (alias: budg)(status, amount, value, id)
  products(value, level, name, status)
Task: Find salary from budgets where a matching record exists in products with the same type.
SQL:

SELECT salary FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.type = budg.type
);


Prompt:
Schema:
  shipments (alias: shp)(status, amount, level, type)
  staff(id, code, salary, value)
Task: Retrieve code from shipments with amount above the SUM(salary) of staff rows sharing the same level.
SQL:

SELECT code FROM shipments AS shp
WHERE amount > (
    SELECT SUM(salary) FROM staff AS empl
    WHERE empl.level = shp.level
);


Prompt:
Schema:
  items (alias: lne)(name, level, amount, salary)
  sales(id, salary, code, date)
Task: Retrieve amount from items that have at least one corresponding entry in sales sharing the same level.
SQL:

SELECT amount FROM items AS lne
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.level = lne.level
);


Prompt:
Schema:
  budgets (alias: budg)(level, amount, code, status)
  regions(id, amount, status, type)
Task: Retrieve name from budgets with value above the SUM(salary) of regions rows sharing the same level.
SQL:

SELECT name FROM budgets AS budg
WHERE value > (
    SELECT SUM(salary) FROM regions AS rgn
    WHERE rgn.level = budg.level
);


Prompt:
Schema:
  products (alias: prod)(type, code, date, salary)
  departments(salary, level, date, status)
Task: Find code from products where amount exceeds the average salary from departments for the same type.
SQL:

SELECT code FROM products AS prod
WHERE amount > (
    SELECT SUM(salary) FROM departments AS dept
    WHERE dept.type = prod.type
);


Prompt:
Schema:
  accounts (alias: acct)(salary, value, id, type)
  transactions(name, date, status, salary)
Task: Find salary from accounts where a matching record exists in transactions with the same code.
SQL:

SELECT salary FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM transactions AS txn
    WHERE txn.code = acct.code
);


Prompt:
Schema:
  services (alias: srvc)(level, id, amount, value)
  employees(salary, date, id, level)
Task: Retrieve name from services that have at least one corresponding entry in employees sharing the same id.
SQL:

SELECT name FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.id = srvc.id
);


Prompt:
Schema:
  requests (alias: ordr)(level, date, amount, status)
  invoices(status, code, level, salary)
Task: Find name from requests where a matching record exists in invoices with the same type.
SQL:

SELECT name FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.type = ordr.type
);


Prompt:
Schema:
  products (alias: prod)(code, amount, date, name)
  accounts(amount, level, salary, name)
Task: Retrieve value from products with value above the AVG(amount) of accounts rows sharing the same id.
SQL:

SELECT value FROM products AS prod
WHERE value > (
    SELECT AVG(amount) FROM accounts AS acct
    WHERE acct.id = prod.id
);


Prompt:
Schema:
  invoices (alias: inv)(code, value, salary, status)
  requests(level, status, amount, id)
Task: Retrieve name from invoices with amount above the AVG(salary) of requests rows sharing the same code.
SQL:

SELECT name FROM invoices AS inv
WHERE amount > (
    SELECT AVG(salary) FROM requests AS ordr
    WHERE ordr.code = inv.code
);


Prompt:
Schema:
  departments (alias: dept)(amount, status, name, type)
  regions(salary, id, code, amount)
Task: Retrieve id from departments whose code is found in regions rows where id matches the outer record.
SQL:

SELECT id FROM departments AS dept
WHERE code IN (
    SELECT code FROM regions AS rgn
    WHERE rgn.id = dept.id
);


Prompt:
Schema:
  shipments (alias: shp)(level, code, name, date)
  warehouses(code, status, level, value)
Task: Retrieve name from shipments with salary above the AVG(salary) of warehouses rows sharing the same level.
SQL:

SELECT name FROM shipments AS shp
WHERE salary > (
    SELECT AVG(salary) FROM warehouses AS whs
    WHERE whs.level = shp.level
);


Prompt:
Schema:
  accounts (alias: acct)(code, amount, value, status)
  sales(code, status, level, name)
Task: Retrieve id from accounts that have at least one corresponding entry in sales sharing the same level.
SQL:

SELECT id FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.level = acct.level
);


Prompt:
Schema:
  employees (alias: emp)(type, value, id, code)
  requests(type, date, amount, id)
Task: Find amount from employees where salary exceeds the average amount from requests for the same type.
SQL:

SELECT amount FROM employees AS emp
WHERE salary > (
    SELECT MAX(amount) FROM requests AS ordr
    WHERE ordr.type = emp.type
);


Prompt:
Schema:
  customers (alias: cust)(name, date, status, amount)
  budgets(name, amount, type, level)
Task: Find id from customers where type appears in budgets entries with matching code.
SQL:

SELECT id FROM customers AS cust
WHERE type IN (
    SELECT type FROM budgets AS budg
    WHERE budg.code = cust.code
);


Prompt:
Schema:
  invoices (alias: inv)(value, name, date, status)
  employees(name, date, level, value)
Task: Find code from invoices where a matching record exists in employees with the same level.
SQL:

SELECT code FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.level = inv.level
);


Prompt:
Schema:
  accounts (alias: acct)(code, salary, name, amount)
  warehouses(code, id, status, date)
Task: Find id from accounts where salary exceeds the average amount from warehouses for the same code.
SQL:

SELECT id FROM accounts AS acct
WHERE salary > (
    SELECT COUNT(amount) FROM warehouses AS whs
    WHERE whs.code = acct.code
);


Prompt:
Schema:
  schedules (alias: schd)(name, status, id, value)
  regions(salary, level, name, amount)
Task: Retrieve salary from schedules with amount above the SUM(value) of regions rows sharing the same id.
SQL:

SELECT salary FROM schedules AS schd
WHERE amount > (
    SELECT SUM(value) FROM regions AS rgn
    WHERE rgn.id = schd.id
);


Prompt:
Schema:
  products (alias: prod)(salary, id, date, status)
  sales(code, type, level, value)
Task: Find id from products where salary exceeds the average value from sales for the same code.
SQL:

SELECT id FROM products AS prod
WHERE salary > (
    SELECT AVG(value) FROM sales AS sale
    WHERE sale.code = prod.code
);


Prompt:
Schema:
  requests (alias: ordr)(name, date, status, code)
  warehouses(name, status, salary, type)
Task: Retrieve value from requests whose id is found in warehouses rows where code matches the outer record.
SQL:

SELECT value FROM requests AS ordr
WHERE id IN (
    SELECT id FROM warehouses AS whs
    WHERE whs.code = ordr.code
);


Prompt:
Schema:
  schedules (alias: schd)(status, level, amount, type)
  requests(code, level, id, amount)
Task: Find name from schedules where salary exceeds the average amount from requests for the same id.
SQL:

SELECT name FROM schedules AS schd
WHERE salary > (
    SELECT AVG(amount) FROM requests AS ordr
    WHERE ordr.id = schd.id
);


Prompt:
Schema:
  budgets (alias: budg)(date, level, value, code)
  sales(id, level, code, status)
Task: Retrieve value from budgets that have at least one corresponding entry in sales sharing the same type.
SQL:

SELECT value FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.type = budg.type
);


Prompt:
Schema:
  departments (alias: dept)(date, salary, type, level)
  employees(salary, code, name, id)
Task: Retrieve value from departments that have at least one corresponding entry in employees sharing the same code.
SQL:

SELECT value FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.code = dept.code
);


Prompt:
Schema:
  shipments (alias: shp)(salary, type, value, status)
  warehouses(value, status, salary, id)
Task: Retrieve value from shipments that have at least one corresponding entry in warehouses sharing the same level.
SQL:

SELECT value FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM warehouses AS whs
    WHERE whs.level = shp.level
);


Prompt:
Schema:
  regions (alias: rgn)(status, type, name, code)
  staff(id, date, name, level)
Task: Find amount from regions where a matching record exists in staff with the same type.
SQL:

SELECT amount FROM regions AS rgn
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.type = rgn.type
);


Prompt:
Schema:
  orders (alias: ord)(date, name, level, salary)
  staff(amount, name, code, date)
Task: Find code from orders where a matching record exists in staff with the same code.
SQL:

SELECT code FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.code = ord.code
);


Prompt:
Schema:
  customers (alias: cust)(id, name, code, date)
  categories(level, status, date, id)
Task: Find name from customers where salary exceeds the average amount from categories for the same code.
SQL:

SELECT name FROM customers AS cust
WHERE salary > (
    SELECT MIN(amount) FROM categories AS catg
    WHERE catg.code = cust.code
);


Prompt:
Schema:
  staff (alias: empl)(date, status, level, value)
  services(date, level, status, id)
Task: Retrieve name from staff that have at least one corresponding entry in services sharing the same id.
SQL:

SELECT name FROM staff AS empl
WHERE EXISTS (
    SELECT 1 FROM services AS srvc
    WHERE srvc.id = empl.id
);


Prompt:
Schema:
  orders (alias: ord)(type, name, date, amount)
  items(amount, salary, value, code)
Task: Retrieve salary from orders with salary above the SUM(amount) of items rows sharing the same id.
SQL:

SELECT salary FROM orders AS ord
WHERE salary > (
    SELECT SUM(amount) FROM items AS lne
    WHERE lne.id = ord.id
);


Prompt:
Schema:
  budgets (alias: budg)(code, value, type, id)
  invoices(salary, status, amount, value)
Task: Find salary from budgets where a matching record exists in invoices with the same code.
SQL:

SELECT salary FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.code = budg.code
);


Prompt:
Schema:
  categories (alias: catg)(salary, code, level, value)
  regions(code, id, type, value)
Task: Retrieve salary from categories that have at least one corresponding entry in regions sharing the same type.
SQL:

SELECT salary FROM categories AS catg
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.type = catg.type
);


Prompt:
Schema:
  invoices (alias: inv)(id, salary, type, value)
  products(value, salary, date, id)
Task: Retrieve code from invoices with salary above the AVG(salary) of products rows sharing the same type.
SQL:

SELECT code FROM invoices AS inv
WHERE salary > (
    SELECT AVG(salary) FROM products AS prod
    WHERE prod.type = inv.type
);


Prompt:
Schema:
  budgets (alias: budg)(amount, status, type, date)
  departments(status, amount, code, level)
Task: Find name from budgets where salary exceeds the average amount from departments for the same code.
SQL:

SELECT name FROM budgets AS budg
WHERE salary > (
    SELECT AVG(amount) FROM departments AS dept
    WHERE dept.code = budg.code
);


Prompt:
Schema:
  schedules (alias: schd)(id, code, name, type)
  shipments(type, date, amount, value)
Task: Retrieve id from schedules that have at least one corresponding entry in shipments sharing the same status.
SQL:

SELECT id FROM schedules AS schd
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.status = schd.status
);


Prompt:
Schema:
  services (alias: srvc)(salary, id, level, name)
  managers(id, salary, value, level)
Task: Find amount from services where level appears in managers entries with matching id.
SQL:

SELECT amount FROM services AS srvc
WHERE level IN (
    SELECT level FROM managers AS mgr
    WHERE mgr.id = srvc.id
);


Prompt:
Schema:
  departments (alias: dept)(type, salary, code, amount)
  managers(status, name, code, value)
Task: Retrieve id from departments whose status is found in managers rows where id matches the outer record.
SQL:

SELECT id FROM departments AS dept
WHERE status IN (
    SELECT status FROM managers AS mgr
    WHERE mgr.id = dept.id
);


Prompt:
Schema:
  schedules (alias: schd)(amount, id, name, date)
  transactions(code, level, value, id)
Task: Retrieve value from schedules whose type is found in transactions rows where id matches the outer record.
SQL:

SELECT value FROM schedules AS schd
WHERE type IN (
    SELECT type FROM transactions AS txn
    WHERE txn.id = schd.id
);


Prompt:
Schema:
  products (alias: prod)(date, level, status, code)
  regions(value, code, amount, type)
Task: Find value from products where amount exceeds the average salary from regions for the same id.
SQL:

SELECT value FROM products AS prod
WHERE amount > (
    SELECT AVG(salary) FROM regions AS rgn
    WHERE rgn.id = prod.id
);


Prompt:
Schema:
  sales (alias: sale)(status, name, amount, level)
  staff(salary, status, name, code)
Task: Find amount from sales where value exceeds the average value from staff for the same type.
SQL:

SELECT amount FROM sales AS sale
WHERE value > (
    SELECT COUNT(value) FROM staff AS empl
    WHERE empl.type = sale.type
);


Prompt:
Schema:
  shipments (alias: shp)(salary, type, date, id)
  schedules(level, value, amount, id)
Task: Select amount from shipments where level exists in schedules for the same status.
SQL:

SELECT amount FROM shipments AS shp
WHERE level IN (
    SELECT level FROM schedules AS schd
    WHERE schd.status = shp.status
);


Prompt:
Schema:
  orders (alias: ord)(code, level, id, type)
  customers(amount, salary, type, value)
Task: Retrieve salary from orders that have at least one corresponding entry in customers sharing the same level.
SQL:

SELECT salary FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.level = ord.level
);


Prompt:
Schema:
  sales (alias: sale)(name, type, date, salary)
  accounts(date, type, salary, name)
Task: Retrieve amount from sales with salary above the COUNT(amount) of accounts rows sharing the same type.
SQL:

SELECT amount FROM sales AS sale
WHERE salary > (
    SELECT COUNT(amount) FROM accounts AS acct
    WHERE acct.type = sale.type
);


Prompt:
Schema:
  budgets (alias: budg)(date, salary, name, value)
  transactions(date, status, value, salary)
Task: Retrieve salary from budgets that have at least one corresponding entry in transactions sharing the same code.
SQL:

SELECT salary FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM transactions AS txn
    WHERE txn.code = budg.code
);


Prompt:
Schema:
  regions (alias: rgn)(code, type, name, value)
  products(value, status, name, amount)
Task: Find id from regions where a matching record exists in products with the same type.
SQL:

SELECT id FROM regions AS rgn
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.type = rgn.type
);


Prompt:
Schema:
  departments (alias: dept)(code, amount, status, date)
  budgets(level, value, code, salary)
Task: Find code from departments where a matching record exists in budgets with the same status.
SQL:

SELECT code FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM budgets AS budg
    WHERE budg.status = dept.status
);


Prompt:
Schema:
  shipments (alias: shp)(level, salary, value, date)
  schedules(type, level, status, salary)
Task: Find name from shipments where a matching record exists in schedules with the same id.
SQL:

SELECT name FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM schedules AS schd
    WHERE schd.id = shp.id
);


Prompt:
Schema:
  transactions (alias: txn)(id, salary, value, type)
  departments(date, value, type, name)
Task: Retrieve name from transactions with value above the MIN(salary) of departments rows sharing the same type.
SQL:

SELECT name FROM transactions AS txn
WHERE value > (
    SELECT MIN(salary) FROM departments AS dept
    WHERE dept.type = txn.type
);


Prompt:
Schema:
  customers (alias: cust)(name, type, code, id)
  invoices(code, id, amount, name)
Task: Find name from customers where a matching record exists in invoices with the same code.
SQL:

SELECT name FROM customers AS cust
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.code = cust.code
);


Prompt:
Schema:
  transactions (alias: txn)(date, value, name, code)
  warehouses(code, type, value, salary)
Task: Select value from transactions where code exists in warehouses for the same code.
SQL:

SELECT value FROM transactions AS txn
WHERE code IN (
    SELECT code FROM warehouses AS whs
    WHERE whs.code = txn.code
);


Prompt:
Schema:
  departments (alias: dept)(salary, name, amount, code)
  staff(salary, date, name, amount)
Task: Find value from departments where value exceeds the average value from staff for the same code.
SQL:

SELECT value FROM departments AS dept
WHERE value > (
    SELECT AVG(value) FROM staff AS empl
    WHERE empl.code = dept.code
);


Prompt:
Schema:
  customers (alias: cust)(name, salary, type, level)
  sales(salary, code, value, type)
Task: Select salary from customers where type exists in sales for the same code.
SQL:

SELECT salary FROM customers AS cust
WHERE type IN (
    SELECT type FROM sales AS sale
    WHERE sale.code = cust.code
);


Prompt:
Schema:
  schedules (alias: schd)(amount, level, code, status)
  items(salary, code, status, name)
Task: Retrieve id from schedules whose id is found in items rows where id matches the outer record.
SQL:

SELECT id FROM schedules AS schd
WHERE id IN (
    SELECT id FROM items AS lne
    WHERE lne.id = schd.id
);


Prompt:
Schema:
  invoices (alias: inv)(status, code, amount, salary)
  staff(level, name, date, amount)
Task: Select code from invoices where status exists in staff for the same level.
SQL:

SELECT code FROM invoices AS inv
WHERE status IN (
    SELECT status FROM staff AS empl
    WHERE empl.level = inv.level
);


Prompt:
Schema:
  invoices (alias: inv)(salary, date, type, code)
  shipments(level, amount, value, code)
Task: Retrieve amount from invoices with salary above the MIN(salary) of shipments rows sharing the same level.
SQL:

SELECT amount FROM invoices AS inv
WHERE salary > (
    SELECT MIN(salary) FROM shipments AS shp
    WHERE shp.level = inv.level
);


Prompt:
Schema:
  services (alias: srvc)(code, date, status, value)
  products(status, name, salary, type)
Task: Find id from services where level appears in products entries with matching level.
SQL:

SELECT id FROM services AS srvc
WHERE level IN (
    SELECT level FROM products AS prod
    WHERE prod.level = srvc.level
);


Prompt:
Schema:
  products (alias: prod)(name, code, status, level)
  customers(level, id, name, amount)
Task: Find id from products where id appears in customers entries with matching code.
SQL:

SELECT id FROM products AS prod
WHERE id IN (
    SELECT id FROM customers AS cust
    WHERE cust.code = prod.code
);


Prompt:
Schema:
  requests (alias: ordr)(value, id, name, status)
  invoices(value, amount, id, type)
Task: Find value from requests where amount exceeds the average value from invoices for the same code.
SQL:

SELECT value FROM requests AS ordr
WHERE amount > (
    SELECT COUNT(value) FROM invoices AS inv
    WHERE inv.code = ordr.code
);


Prompt:
Schema:
  sales (alias: sale)(code, salary, level, type)
  invoices(code, date, salary, level)
Task: Retrieve amount from sales with salary above the SUM(salary) of invoices rows sharing the same type.
SQL:

SELECT amount FROM sales AS sale
WHERE salary > (
    SELECT SUM(salary) FROM invoices AS inv
    WHERE inv.type = sale.type
);


Prompt:
Schema:
  categories (alias: catg)(id, type, date, name)
  services(id, value, code, level)
Task: Retrieve amount from categories with salary above the AVG(salary) of services rows sharing the same status.
SQL:

SELECT amount FROM categories AS catg
WHERE salary > (
    SELECT AVG(salary) FROM services AS srvc
    WHERE srvc.status = catg.status
);


Prompt:
Schema:
  budgets (alias: budg)(status, id, type, name)
  shipments(type, value, code, name)
Task: Find id from budgets where status appears in shipments entries with matching type.
SQL:

SELECT id FROM budgets AS budg
WHERE status IN (
    SELECT status FROM shipments AS shp
    WHERE shp.type = budg.type
);


Prompt:
Schema:
  accounts (alias: acct)(date, type, code, level)
  services(id, level, type, amount)
Task: Find id from accounts where level appears in services entries with matching level.
SQL:

SELECT id FROM accounts AS acct
WHERE level IN (
    SELECT level FROM services AS srvc
    WHERE srvc.level = acct.level
);


Prompt:
Schema:
  requests (alias: ordr)(amount, code, type, date)
  transactions(level, id, salary, code)
Task: Retrieve salary from requests whose type is found in transactions rows where code matches the outer record.
SQL:

SELECT salary FROM requests AS ordr
WHERE type IN (
    SELECT type FROM transactions AS txn
    WHERE txn.code = ordr.code
);


Prompt:
Schema:
  transactions (alias: txn)(level, amount, salary, type)
  products(type, salary, id, level)
Task: Retrieve code from transactions whose status is found in products rows where id matches the outer record.
SQL:

SELECT code FROM transactions AS txn
WHERE status IN (
    SELECT status FROM products AS prod
    WHERE prod.id = txn.id
);


Prompt:
Schema:
  shipments (alias: shp)(value, salary, code, date)
  schedules(id, date, value, level)
Task: Retrieve code from shipments that have at least one corresponding entry in schedules sharing the same type.
SQL:

SELECT code FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM schedules AS schd
    WHERE schd.type = shp.type
);


Prompt:
Schema:
  managers (alias: mgr)(status, amount, type, name)
  categories(salary, type, id, value)
Task: Retrieve value from managers that have at least one corresponding entry in categories sharing the same id.
SQL:

SELECT value FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM categories AS catg
    WHERE catg.id = mgr.id
);


Prompt:
Schema:
  staff (alias: empl)(level, status, date, value)
  departments(id, salary, level, amount)
Task: Find name from staff where a matching record exists in departments with the same status.
SQL:

SELECT name FROM staff AS empl
WHERE EXISTS (
    SELECT 1 FROM departments AS dept
    WHERE dept.status = empl.status
);


Prompt:
Schema:
  regions (alias: rgn)(salary, id, value, code)
  employees(date, id, name, salary)
Task: Retrieve id from regions that have at least one corresponding entry in employees sharing the same code.
SQL:

SELECT id FROM regions AS rgn
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.code = rgn.code
);


Prompt:
Schema:
  invoices (alias: inv)(type, id, status, code)
  categories(status, level, amount, id)
Task: Select amount from invoices where code exists in categories for the same code.
SQL:

SELECT amount FROM invoices AS inv
WHERE code IN (
    SELECT code FROM categories AS catg
    WHERE catg.code = inv.code
);


Prompt:
Schema:
  departments (alias: dept)(level, amount, date, value)
  warehouses(date, salary, type, status)
Task: Select id from departments where status exists in warehouses for the same status.
SQL:

SELECT id FROM departments AS dept
WHERE status IN (
    SELECT status FROM warehouses AS whs
    WHERE whs.status = dept.status
);


Prompt:
Schema:
  categories (alias: catg)(amount, salary, id, name)
  products(salary, status, code, amount)
Task: Find name from categories where a matching record exists in products with the same level.
SQL:

SELECT name FROM categories AS catg
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.level = catg.level
);


Prompt:
Schema:
  sales (alias: sale)(status, name, type, date)
  staff(type, name, value, level)
Task: Retrieve name from sales that have at least one corresponding entry in staff sharing the same type.
SQL:

SELECT name FROM sales AS sale
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.type = sale.type
);


Prompt:
Schema:
  sales (alias: sale)(value, amount, salary, status)
  warehouses(salary, type, value, level)
Task: Retrieve salary from sales with amount above the MIN(value) of warehouses rows sharing the same status.
SQL:

SELECT salary FROM sales AS sale
WHERE amount > (
    SELECT MIN(value) FROM warehouses AS whs
    WHERE whs.status = sale.status
);


Prompt:
Schema:
  transactions (alias: txn)(value, date, id, code)
  customers(code, name, level, amount)
Task: Retrieve amount from transactions that have at least one corresponding entry in customers sharing the same status.
SQL:

SELECT amount FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.status = txn.status
);


Prompt:
Schema:
  shipments (alias: shp)(value, type, code, amount)
  employees(amount, name, type, salary)
Task: Retrieve id from shipments that have at least one corresponding entry in employees sharing the same type.
SQL:

SELECT id FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.type = shp.type
);


Prompt:
Schema:
  transactions (alias: txn)(name, code, value, id)
  products(id, salary, name, amount)
Task: Find salary from transactions where a matching record exists in products with the same status.
SQL:

SELECT salary FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.status = txn.status
);


Prompt:
Schema:
  transactions (alias: txn)(name, date, status, salary)
  sales(id, code, status, level)
Task: Retrieve code from transactions with value above the SUM(salary) of sales rows sharing the same id.
SQL:

SELECT code FROM transactions AS txn
WHERE value > (
    SELECT SUM(salary) FROM sales AS sale
    WHERE sale.id = txn.id
);


Prompt:
Schema:
  sales (alias: sale)(type, amount, code, name)
  managers(value, type, id, salary)
Task: Select amount from sales where type exists in managers for the same status.
SQL:

SELECT amount FROM sales AS sale
WHERE type IN (
    SELECT type FROM managers AS mgr
    WHERE mgr.status = sale.status
);


Prompt:
Schema:
  products (alias: prod)(id, name, status, amount)
  regions(name, id, date, value)
Task: Retrieve value from products with amount above the AVG(salary) of regions rows sharing the same type.
SQL:

SELECT value FROM products AS prod
WHERE amount > (
    SELECT AVG(salary) FROM regions AS rgn
    WHERE rgn.type = prod.type
);


Prompt:
Schema:
  orders (alias: ord)(amount, date, name, type)
  staff(level, id, name, value)
Task: Select salary from orders where id exists in staff for the same status.
SQL:

SELECT salary FROM orders AS ord
WHERE id IN (
    SELECT id FROM staff AS empl
    WHERE empl.status = ord.status
);


Prompt:
Schema:
  departments (alias: dept)(type, amount, id, name)
  staff(date, code, id, name)
Task: Retrieve amount from departments that have at least one corresponding entry in staff sharing the same type.
SQL:

SELECT amount FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.type = dept.type
);


Prompt:
Schema:
  sales (alias: sale)(salary, amount, name, code)
  budgets(salary, type, code, date)
Task: Find code from sales where id appears in budgets entries with matching level.
SQL:

SELECT code FROM sales AS sale
WHERE id IN (
    SELECT id FROM budgets AS budg
    WHERE budg.level = sale.level
);


Prompt:
Schema:
  warehouses (alias: whs)(amount, id, type, salary)
  shipments(type, date, id, value)
Task: Retrieve amount from warehouses that have at least one corresponding entry in shipments sharing the same code.
SQL:

SELECT amount FROM warehouses AS whs
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.code = whs.code
);


Prompt:
Schema:
  services (alias: srvc)(status, code, type, amount)
  managers(name, id, value, status)
Task: Select value from services where level exists in managers for the same id.
SQL:

SELECT value FROM services AS srvc
WHERE level IN (
    SELECT level FROM managers AS mgr
    WHERE mgr.id = srvc.id
);


Prompt:
Schema:
  orders (alias: ord)(type, salary, date, level)
  categories(status, code, value, level)
Task: Find name from orders where a matching record exists in categories with the same type.
SQL:

SELECT name FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM categories AS catg
    WHERE catg.type = ord.type
);


Prompt:
Schema:
  employees (alias: emp)(code, type, id, status)
  sales(status, level, code, id)
Task: Select salary from employees where status exists in sales for the same status.
SQL:

SELECT salary FROM employees AS emp
WHERE status IN (
    SELECT status FROM sales AS sale
    WHERE sale.status = emp.status
);


Prompt:
Schema:
  departments (alias: dept)(value, date, id, code)
  staff(level, id, amount, name)
Task: Find id from departments where a matching record exists in staff with the same id.
SQL:

SELECT id FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.id = dept.id
);


Prompt:
Schema:
  categories (alias: catg)(date, value, code, salary)
  orders(id, name, value, salary)
Task: Retrieve code from categories whose id is found in orders rows where type matches the outer record.
SQL:

SELECT code FROM categories AS catg
WHERE id IN (
    SELECT id FROM orders AS ord
    WHERE ord.type = catg.type
);


Prompt:
Schema:
  regions (alias: rgn)(code, id, date, value)
  schedules(code, name, status, date)
Task: Find code from regions where code appears in schedules entries with matching status.
SQL:

SELECT code FROM regions AS rgn
WHERE code IN (
    SELECT code FROM schedules AS schd
    WHERE schd.status = rgn.status
);


Prompt:
Schema:
  customers (alias: cust)(name, level, salary, date)
  budgets(status, salary, code, name)
Task: Select code from customers where status exists in budgets for the same level.
SQL:

SELECT code FROM customers AS cust
WHERE status IN (
    SELECT status FROM budgets AS budg
    WHERE budg.level = cust.level
);


Prompt:
Schema:
  warehouses (alias: whs)(value, level, id, amount)
  items(amount, level, date, value)
Task: Retrieve salary from warehouses that have at least one corresponding entry in items sharing the same type.
SQL:

SELECT salary FROM warehouses AS whs
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.type = whs.type
);


Prompt:
Schema:
  staff (alias: empl)(date, id, value, code)
  products(value, level, amount, type)
Task: Retrieve id from staff with salary above the SUM(amount) of products rows sharing the same status.
SQL:

SELECT id FROM staff AS empl
WHERE salary > (
    SELECT SUM(amount) FROM products AS prod
    WHERE prod.status = empl.status
);


Prompt:
Schema:
  services (alias: srvc)(level, value, type, status)
  warehouses(amount, name, salary, date)
Task: Select value from services where id exists in warehouses for the same level.
SQL:

SELECT value FROM services AS srvc
WHERE id IN (
    SELECT id FROM warehouses AS whs
    WHERE whs.level = srvc.level
);


Prompt:
Schema:
  budgets (alias: budg)(date, code, id, salary)
  sales(value, amount, type, code)
Task: Retrieve code from budgets with amount above the SUM(amount) of sales rows sharing the same type.
SQL:

SELECT code FROM budgets AS budg
WHERE amount > (
    SELECT SUM(amount) FROM sales AS sale
    WHERE sale.type = budg.type
);


Prompt:
Schema:
  services (alias: srvc)(date, name, id, type)
  employees(id, status, type, level)
Task: Retrieve amount from services that have at least one corresponding entry in employees sharing the same type.
SQL:

SELECT amount FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.type = srvc.type
);


Prompt:
Schema:
  products (alias: prod)(value, status, level, id)
  customers(type, code, salary, value)
Task: Find name from products where a matching record exists in customers with the same id.
SQL:

SELECT name FROM products AS prod
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.id = prod.id
);


Prompt:
Schema:
  requests (alias: ordr)(type, salary, code, value)
  categories(name, salary, id, date)
Task: Select code from requests where id exists in categories for the same level.
SQL:

SELECT code FROM requests AS ordr
WHERE id IN (
    SELECT id FROM categories AS catg
    WHERE catg.level = ordr.level
);


Prompt:
Schema:
  employees (alias: emp)(amount, value, id, code)
  sales(code, salary, status, level)
Task: Find name from employees where value exceeds the average salary from sales for the same id.
SQL:

SELECT name FROM employees AS emp
WHERE value > (
    SELECT SUM(salary) FROM sales AS sale
    WHERE sale.id = emp.id
);


Prompt:
Schema:
  categories (alias: catg)(id, status, value, amount)
  transactions(id, type, level, date)
Task: Find code from categories where a matching record exists in transactions with the same type.
SQL:

SELECT code FROM categories AS catg
WHERE EXISTS (
    SELECT 1 FROM transactions AS txn
    WHERE txn.type = catg.type
);


Prompt:
Schema:
  items (alias: lne)(code, date, type, level)
  departments(date, id, salary, value)
Task: Retrieve salary from items with salary above the MAX(salary) of departments rows sharing the same id.
SQL:

SELECT salary FROM items AS lne
WHERE salary > (
    SELECT MAX(salary) FROM departments AS dept
    WHERE dept.id = lne.id
);


Prompt:
Schema:
  customers (alias: cust)(name, code, id, level)
  products(value, salary, status, name)
Task: Find name from customers where a matching record exists in products with the same level.
SQL:

SELECT name FROM customers AS cust
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.level = cust.level
);


Prompt:
Schema:
  products (alias: prod)(name, type, level, code)
  managers(level, status, amount, name)
Task: Retrieve salary from products with value above the SUM(amount) of managers rows sharing the same level.
SQL:

SELECT salary FROM products AS prod
WHERE value > (
    SELECT SUM(amount) FROM managers AS mgr
    WHERE mgr.level = prod.level
);


Prompt:
Schema:
  transactions (alias: txn)(id, type, status, level)
  warehouses(id, name, type, code)
Task: Retrieve salary from transactions that have at least one corresponding entry in warehouses sharing the same type.
SQL:

SELECT salary FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM warehouses AS whs
    WHERE whs.type = txn.type
);


Prompt:
Schema:
  employees (alias: emp)(amount, status, level, salary)
  accounts(id, type, value, level)
Task: Retrieve salary from employees with amount above the MIN(amount) of accounts rows sharing the same id.
SQL:

SELECT salary FROM employees AS emp
WHERE amount > (
    SELECT MIN(amount) FROM accounts AS acct
    WHERE acct.id = emp.id
);


Prompt:
Schema:
  employees (alias: emp)(amount, value, level, salary)
  departments(amount, name, level, date)
Task: Retrieve salary from employees with value above the AVG(amount) of departments rows sharing the same code.
SQL:

SELECT salary FROM employees AS emp
WHERE value > (
    SELECT AVG(amount) FROM departments AS dept
    WHERE dept.code = emp.code
);


Prompt:
Schema:
  warehouses (alias: whs)(name, status, value, type)
  budgets(value, status, type, salary)
Task: Find code from warehouses where a matching record exists in budgets with the same code.
SQL:

SELECT code FROM warehouses AS whs
WHERE EXISTS (
    SELECT 1 FROM budgets AS budg
    WHERE budg.code = whs.code
);


Prompt:
Schema:
  categories (alias: catg)(name, code, status, type)
  sales(name, level, type, value)
Task: Find amount from categories where level appears in sales entries with matching code.
SQL:

SELECT amount FROM categories AS catg
WHERE level IN (
    SELECT level FROM sales AS sale
    WHERE sale.code = catg.code
);


Prompt:
Schema:
  transactions (alias: txn)(status, level, type, salary)
  sales(value, amount, salary, name)
Task: Retrieve amount from transactions that have at least one corresponding entry in sales sharing the same level.
SQL:

SELECT amount FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.level = txn.level
);


Prompt:
Schema:
  staff (alias: empl)(status, level, code, name)
  schedules(value, salary, amount, status)
Task: Retrieve value from staff with salary above the AVG(value) of schedules rows sharing the same level.
SQL:

SELECT value FROM staff AS empl
WHERE salary > (
    SELECT AVG(value) FROM schedules AS schd
    WHERE schd.level = empl.level
);


Prompt:
Schema:
  schedules (alias: schd)(salary, id, amount, code)
  employees(value, amount, status, salary)
Task: Retrieve code from schedules that have at least one corresponding entry in employees sharing the same id.
SQL:

SELECT code FROM schedules AS schd
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.id = schd.id
);


Prompt:
Schema:
  transactions (alias: txn)(id, status, type, amount)
  requests(id, status, type, salary)
Task: Find name from transactions where salary exceeds the average value from requests for the same id.
SQL:

SELECT name FROM transactions AS txn
WHERE salary > (
    SELECT SUM(value) FROM requests AS ordr
    WHERE ordr.id = txn.id
);


Prompt:
Schema:
  managers (alias: mgr)(type, name, status, salary)
  warehouses(level, id, salary, status)
Task: Find amount from managers where amount exceeds the average value from warehouses for the same id.
SQL:

SELECT amount FROM managers AS mgr
WHERE amount > (
    SELECT AVG(value) FROM warehouses AS whs
    WHERE whs.id = mgr.id
);


Prompt:
Schema:
  customers (alias: cust)(amount, status, id, name)
  products(level, code, id, salary)
Task: Find value from customers where type appears in products entries with matching code.
SQL:

SELECT value FROM customers AS cust
WHERE type IN (
    SELECT type FROM products AS prod
    WHERE prod.code = cust.code
);


Prompt:
Schema:
  customers (alias: cust)(salary, name, id, code)
  products(id, type, value, code)
Task: Find id from customers where salary exceeds the average salary from products for the same type.
SQL:

SELECT id FROM customers AS cust
WHERE salary > (
    SELECT MIN(salary) FROM products AS prod
    WHERE prod.type = cust.type
);


Prompt:
Schema:
  departments (alias: dept)(id, value, type, date)
  shipments(code, date, status, amount)
Task: Find salary from departments where a matching record exists in shipments with the same status.
SQL:

SELECT salary FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.status = dept.status
);


Prompt:
Schema:
  employees (alias: emp)(level, code, status, amount)
  shipments(amount, type, value, salary)
Task: Retrieve id from employees with value above the MAX(salary) of shipments rows sharing the same status.
SQL:

SELECT id FROM employees AS emp
WHERE value > (
    SELECT MAX(salary) FROM shipments AS shp
    WHERE shp.status = emp.status
);


Prompt:
Schema:
  managers (alias: mgr)(salary, level, amount, status)
  services(status, amount, name, level)
Task: Retrieve code from managers whose code is found in services rows where level matches the outer record.
SQL:

SELECT code FROM managers AS mgr
WHERE code IN (
    SELECT code FROM services AS srvc
    WHERE srvc.level = mgr.level
);


Prompt:
Schema:
  budgets (alias: budg)(amount, date, salary, level)
  warehouses(name, status, type, code)
Task: Retrieve id from budgets that have at least one corresponding entry in warehouses sharing the same id.
SQL:

SELECT id FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM warehouses AS whs
    WHERE whs.id = budg.id
);