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

SELECT salary FROM categories AS catg
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.type = catg.type
);


Prompt:
Schema:
  employees (alias: emp)(level, amount, salary, date)
  transactions(id, date, level, amount)
Task: Find name from employees where level appears in transactions entries with matching type.
SQL:

SELECT name FROM employees AS emp
WHERE level IN (
    SELECT level FROM transactions AS txn
    WHERE txn.type = emp.type
);


Prompt:
Schema:
  schedules (alias: schd)(date, name, type, value)
  products(salary, value, amount, type)
Task: Select salary from schedules where type exists in products for the same type.
SQL:

SELECT salary FROM schedules AS schd
WHERE type IN (
    SELECT type FROM products AS prod
    WHERE prod.type = schd.type
);


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

SELECT name FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.level = txn.level
);


Prompt:
Schema:
  staff (alias: empl)(code, amount, id, salary)
  shipments(salary, type, id, code)
Task: Find id from staff where amount exceeds the average salary from shipments for the same id.
SQL:

SELECT id FROM staff AS empl
WHERE amount > (
    SELECT MAX(salary) FROM shipments AS shp
    WHERE shp.id = empl.id
);


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

SELECT code FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM managers AS mgr
    WHERE mgr.code = acct.code
);


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

SELECT name FROM departments AS dept
WHERE amount > (
    SELECT SUM(amount) FROM transactions AS txn
    WHERE txn.code = dept.code
);


Prompt:
Schema:
  regions (alias: rgn)(name, salary, level, id)
  invoices(type, salary, value, date)
Task: Retrieve id from regions with salary above the MIN(value) of invoices rows sharing the same code.
SQL:

SELECT id FROM regions AS rgn
WHERE salary > (
    SELECT MIN(value) FROM invoices AS inv
    WHERE inv.code = rgn.code
);


Prompt:
Schema:
  schedules (alias: schd)(value, name, type, amount)
  transactions(value, level, salary, type)
Task: Retrieve name from schedules with salary above the MIN(salary) of transactions rows sharing the same level.
SQL:

SELECT name FROM schedules AS schd
WHERE salary > (
    SELECT MIN(salary) FROM transactions AS txn
    WHERE txn.level = schd.level
);


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

SELECT id FROM shipments AS shp
WHERE value > (
    SELECT SUM(amount) FROM sales AS sale
    WHERE sale.id = shp.id
);


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

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


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

SELECT code FROM staff AS empl
WHERE code IN (
    SELECT code FROM sales AS sale
    WHERE sale.code = empl.code
);


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

SELECT id FROM customers AS cust
WHERE type IN (
    SELECT type FROM items AS lne
    WHERE lne.level = cust.level
);


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

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


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

SELECT code FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM managers AS mgr
    WHERE mgr.id = inv.id
);


Prompt:
Schema:
  items (alias: lne)(salary, value, id, date)
  transactions(salary, value, status, level)
Task: Find name from items where value exceeds the average value from transactions for the same status.
SQL:

SELECT name FROM items AS lne
WHERE value > (
    SELECT COUNT(value) FROM transactions AS txn
    WHERE txn.status = lne.status
);


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

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


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

SELECT salary FROM schedules AS schd
WHERE status IN (
    SELECT status FROM employees AS emp
    WHERE emp.level = schd.level
);


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

SELECT amount FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.code = ordr.code
);


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

SELECT id FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM managers AS mgr
    WHERE mgr.level = dept.level
);


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

SELECT name FROM accounts AS acct
WHERE amount > (
    SELECT MIN(value) FROM requests AS ordr
    WHERE ordr.type = acct.type
);


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

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


Prompt:
Schema:
  requests (alias: ordr)(date, id, amount, status)
  sales(type, code, name, date)
Task: Find amount from requests where status appears in sales entries with matching id.
SQL:

SELECT amount FROM requests AS ordr
WHERE status IN (
    SELECT status FROM sales AS sale
    WHERE sale.id = ordr.id
);


Prompt:
Schema:
  schedules (alias: schd)(status, date, type, id)
  invoices(date, value, id, status)
Task: Select name from schedules where code exists in invoices for the same level.
SQL:

SELECT name FROM schedules AS schd
WHERE code IN (
    SELECT code FROM invoices AS inv
    WHERE inv.level = schd.level
);


Prompt:
Schema:
  services (alias: srvc)(level, code, name, date)
  employees(level, code, status, id)
Task: Find amount from services where a matching record exists in employees with 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:
  warehouses (alias: whs)(value, date, salary, status)
  categories(date, level, id, value)
Task: Retrieve name from warehouses that have at least one corresponding entry in categories sharing the same code.
SQL:

SELECT name FROM warehouses AS whs
WHERE EXISTS (
    SELECT 1 FROM categories AS catg
    WHERE catg.code = whs.code
);


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

SELECT name FROM employees AS emp
WHERE value > (
    SELECT SUM(amount) FROM warehouses AS whs
    WHERE whs.id = emp.id
);


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

SELECT value FROM orders AS ord
WHERE amount > (
    SELECT SUM(value) FROM transactions AS txn
    WHERE txn.type = ord.type
);


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

SELECT salary FROM orders AS ord
WHERE level IN (
    SELECT level FROM staff AS empl
    WHERE empl.code = ord.code
);


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

SELECT amount FROM schedules AS schd
WHERE id IN (
    SELECT id FROM products AS prod
    WHERE prod.id = schd.id
);


Prompt:
Schema:
  sales (alias: sale)(salary, date, name, code)
  requests(value, status, type, date)
Task: Retrieve id from sales with value above the MIN(value) of requests rows sharing the same id.
SQL:

SELECT id FROM sales AS sale
WHERE value > (
    SELECT MIN(value) FROM requests AS ordr
    WHERE ordr.id = sale.id
);


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

SELECT code FROM regions AS rgn
WHERE salary > (
    SELECT AVG(salary) FROM sales AS sale
    WHERE sale.level = rgn.level
);


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

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


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

SELECT amount FROM customers AS cust
WHERE amount > (
    SELECT SUM(value) FROM shipments AS shp
    WHERE shp.id = cust.id
);


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

SELECT salary FROM employees AS emp
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.status = emp.status
);


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

SELECT code FROM invoices AS inv
WHERE type IN (
    SELECT type FROM accounts AS acct
    WHERE acct.code = inv.code
);


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

SELECT name FROM schedules AS schd
WHERE level IN (
    SELECT level FROM budgets AS budg
    WHERE budg.status = schd.status
);


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

SELECT amount FROM items AS lne
WHERE salary > (
    SELECT MIN(salary) FROM customers AS cust
    WHERE cust.type = lne.type
);


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

SELECT id FROM customers AS cust
WHERE level IN (
    SELECT level FROM departments AS dept
    WHERE dept.code = cust.code
);


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

SELECT amount FROM services AS srvc
WHERE id IN (
    SELECT id FROM warehouses AS whs
    WHERE whs.status = srvc.status
);


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

SELECT salary FROM transactions AS txn
WHERE salary > (
    SELECT COUNT(value) FROM departments AS dept
    WHERE dept.id = txn.id
);


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

SELECT salary FROM customers AS cust
WHERE amount > (
    SELECT AVG(amount) FROM schedules AS schd
    WHERE schd.code = cust.code
);


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

SELECT name FROM orders AS ord
WHERE status IN (
    SELECT status FROM employees AS emp
    WHERE emp.type = ord.type
);


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

SELECT name FROM shipments AS shp
WHERE level IN (
    SELECT level FROM regions AS rgn
    WHERE rgn.status = shp.status
);


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

SELECT salary FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.status = ord.status
);


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

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


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

SELECT amount FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.type = inv.type
);


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

SELECT id FROM sales AS sale
WHERE value > (
    SELECT MIN(salary) FROM invoices AS inv
    WHERE inv.type = sale.type
);


Prompt:
Schema:
  items (alias: lne)(name, level, code, type)
  sales(date, id, amount, level)
Task: Retrieve amount from items with amount above the AVG(salary) of sales rows sharing the same id.
SQL:

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


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

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


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

SELECT code FROM items AS lne
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.status = lne.status
);


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

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


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

SELECT name FROM departments AS dept
WHERE status IN (
    SELECT status FROM sales AS sale
    WHERE sale.code = dept.code
);


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

SELECT name FROM invoices AS inv
WHERE salary > (
    SELECT COUNT(value) FROM managers AS mgr
    WHERE mgr.id = inv.id
);


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

SELECT code FROM staff AS empl
WHERE level IN (
    SELECT level FROM warehouses AS whs
    WHERE whs.status = empl.status
);


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

SELECT value FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.status = dept.status
);


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

SELECT name FROM warehouses AS whs
WHERE amount > (
    SELECT SUM(value) FROM transactions AS txn
    WHERE txn.type = whs.type
);


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

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


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

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


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

SELECT code FROM managers AS mgr
WHERE type IN (
    SELECT type FROM products AS prod
    WHERE prod.status = mgr.status
);


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

SELECT amount FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.status = dept.status
);


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

SELECT code FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.level = mgr.level
);


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

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


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

SELECT amount FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM budgets AS budg
    WHERE budg.level = ord.level
);


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

SELECT code FROM departments AS dept
WHERE code IN (
    SELECT code FROM requests AS ordr
    WHERE ordr.level = dept.level
);


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

SELECT amount FROM staff AS empl
WHERE code IN (
    SELECT code FROM items AS lne
    WHERE lne.id = empl.id
);


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

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


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

SELECT value FROM sales AS sale
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.level = sale.level
);


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

SELECT value FROM items AS lne
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.level = lne.level
);


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

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


Prompt:
Schema:
  employees (alias: emp)(amount, name, value, status)
  requests(type, date, value, code)
Task: Find name from employees where status appears in requests entries with matching code.
SQL:

SELECT name FROM employees AS emp
WHERE status IN (
    SELECT status FROM requests AS ordr
    WHERE ordr.code = emp.code
);


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

SELECT id FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.type = budg.type
);


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

SELECT id FROM schedules AS schd
WHERE value > (
    SELECT SUM(value) FROM customers AS cust
    WHERE cust.status = schd.status
);


Prompt:
Schema:
  managers (alias: mgr)(code, id, date, value)
  staff(name, value, status, id)
Task: Find code from managers where code appears in staff entries with matching type.
SQL:

SELECT code FROM managers AS mgr
WHERE code IN (
    SELECT code FROM staff AS empl
    WHERE empl.type = mgr.type
);


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

SELECT amount FROM budgets AS budg
WHERE salary > (
    SELECT AVG(amount) FROM orders AS ord
    WHERE ord.level = budg.level
);


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

SELECT name FROM categories AS catg
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.level = catg.level
);


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

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


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

SELECT id FROM services AS srvc
WHERE value > (
    SELECT COUNT(salary) FROM regions AS rgn
    WHERE rgn.type = srvc.type
);


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

SELECT id FROM managers AS mgr
WHERE type IN (
    SELECT type FROM requests AS ordr
    WHERE ordr.code = mgr.code
);


Prompt:
Schema:
  warehouses (alias: whs)(id, date, salary, level)
  invoices(type, id, amount, salary)
Task: Find salary from warehouses where value exceeds the average salary from invoices for the same type.
SQL:

SELECT salary FROM warehouses AS whs
WHERE value > (
    SELECT COUNT(salary) FROM invoices AS inv
    WHERE inv.type = whs.type
);


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

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


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

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


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

SELECT value FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.code = inv.code
);


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

SELECT code FROM customers AS cust
WHERE EXISTS (
    SELECT 1 FROM services AS srvc
    WHERE srvc.level = cust.level
);


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

SELECT value FROM categories AS catg
WHERE amount > (
    SELECT COUNT(amount) FROM schedules AS schd
    WHERE schd.id = catg.id
);


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

SELECT id FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.level = acct.level
);


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

SELECT name FROM invoices AS inv
WHERE value > (
    SELECT MIN(amount) FROM requests AS ordr
    WHERE ordr.id = inv.id
);


Prompt:
Schema:
  shipments (alias: shp)(value, salary, code, date)
  accounts(id, code, amount, level)
Task: Find id from shipments where amount exceeds the average value from accounts for the same level.
SQL:

SELECT id FROM shipments AS shp
WHERE amount > (
    SELECT AVG(value) FROM accounts AS acct
    WHERE acct.level = shp.level
);


Prompt:
Schema:
  accounts (alias: acct)(status, amount, code, level)
  shipments(type, value, code, name)
Task: Retrieve amount from accounts with amount above the SUM(value) of shipments rows sharing the same code.
SQL:

SELECT amount FROM accounts AS acct
WHERE amount > (
    SELECT SUM(value) FROM shipments AS shp
    WHERE shp.code = acct.code
);


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

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


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

SELECT value FROM products AS prod
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.code = prod.code
);


Prompt:
Schema:
  items (alias: lne)(date, level, value, amount)
  requests(code, level, id, amount)
Task: Find amount from items where value exceeds the average value from requests for the same id.
SQL:

SELECT amount FROM items AS lne
WHERE value > (
    SELECT MAX(value) FROM requests AS ordr
    WHERE ordr.id = lne.id
);


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

SELECT amount FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.id = ordr.id
);


Prompt:
Schema:
  accounts (alias: acct)(name, amount, id, value)
  budgets(id, name, type, value)
Task: Find name from accounts where a matching record exists in budgets with the same type.
SQL:

SELECT name FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM budgets AS budg
    WHERE budg.type = acct.type
);


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

SELECT value FROM transactions AS txn
WHERE id IN (
    SELECT id FROM shipments AS shp
    WHERE shp.code = txn.code
);


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

SELECT id FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.type = dept.type
);


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

SELECT code FROM orders AS ord
WHERE code IN (
    SELECT code FROM invoices AS inv
    WHERE inv.code = ord.code
);


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

SELECT value FROM staff AS empl
WHERE EXISTS (
    SELECT 1 FROM accounts AS acct
    WHERE acct.code = empl.code
);


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

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


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

SELECT id FROM services AS srvc
WHERE type IN (
    SELECT type FROM sales AS sale
    WHERE sale.level = srvc.level
);


Prompt:
Schema:
  requests (alias: ordr)(value, date, type, salary)
  products(name, code, date, id)
Task: Retrieve salary from requests with salary above the SUM(salary) of products rows sharing the same id.
SQL:

SELECT salary FROM requests AS ordr
WHERE salary > (
    SELECT SUM(salary) FROM products AS prod
    WHERE prod.id = ordr.id
);


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

SELECT name FROM items AS lne
WHERE salary > (
    SELECT SUM(salary) FROM requests AS ordr
    WHERE ordr.level = lne.level
);


Prompt:
Schema:
  departments (alias: dept)(type, salary, amount, level)
  shipments(amount, status, salary, value)
Task: Retrieve value from departments with amount above the AVG(amount) of shipments rows sharing the same level.
SQL:

SELECT value FROM departments AS dept
WHERE amount > (
    SELECT AVG(amount) FROM shipments AS shp
    WHERE shp.level = dept.level
);


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

SELECT value FROM requests AS ordr
WHERE id IN (
    SELECT id FROM staff AS empl
    WHERE empl.code = ordr.code
);


Prompt:
Schema:
  shipments (alias: shp)(value, date, type, salary)
  sales(name, type, date, amount)
Task: Retrieve id from shipments with salary above the MAX(value) of sales rows sharing the same type.
SQL:

SELECT id FROM shipments AS shp
WHERE salary > (
    SELECT MAX(value) FROM sales AS sale
    WHERE sale.type = shp.type
);


Prompt:
Schema:
  requests (alias: ordr)(salary, level, id, name)
  regions(level, value, type, id)
Task: Find salary from requests where a matching record exists in regions with the same level.
SQL:

SELECT salary FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.level = ordr.level
);


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

SELECT code FROM invoices AS inv
WHERE id IN (
    SELECT id FROM customers AS cust
    WHERE cust.code = inv.code
);


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

SELECT id FROM products AS prod
WHERE salary > (
    SELECT COUNT(value) FROM categories AS catg
    WHERE catg.code = prod.code
);


Prompt:
Schema:
  budgets (alias: budg)(amount, type, code, level)
  requests(type, code, amount, value)
Task: Retrieve value from budgets with amount above the AVG(salary) of requests rows sharing the same level.
SQL:

SELECT value FROM budgets AS budg
WHERE amount > (
    SELECT AVG(salary) FROM requests AS ordr
    WHERE ordr.level = budg.level
);


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

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


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

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


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

SELECT code FROM employees AS emp
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.level = emp.level
);


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

SELECT value FROM categories AS catg
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.id = catg.id
);


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

SELECT id FROM regions AS rgn
WHERE amount > (
    SELECT MIN(amount) FROM budgets AS budg
    WHERE budg.type = rgn.type
);


Prompt:
Schema:
  orders (alias: ord)(code, id, amount, salary)
  departments(salary, amount, type, code)
Task: Retrieve code from orders with amount above the AVG(salary) of departments rows sharing the same type.
SQL:

SELECT code FROM orders AS ord
WHERE amount > (
    SELECT AVG(salary) FROM departments AS dept
    WHERE dept.type = ord.type
);


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

SELECT code FROM sales AS sale
WHERE salary > (
    SELECT COUNT(amount) FROM budgets AS budg
    WHERE budg.id = sale.id
);


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

SELECT amount FROM warehouses AS whs
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.level = whs.level
);


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

SELECT code FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.type = shp.type
);


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

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


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

SELECT salary FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM categories AS catg
    WHERE catg.code = acct.code
);


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

SELECT value FROM schedules AS schd
WHERE EXISTS (
    SELECT 1 FROM managers AS mgr
    WHERE mgr.status = schd.status
);


Prompt:
Schema:
  employees (alias: emp)(status, name, code, level)
  transactions(salary, id, level, value)
Task: Find salary from employees where status appears in transactions entries with matching level.
SQL:

SELECT salary FROM employees AS emp
WHERE status IN (
    SELECT status FROM transactions AS txn
    WHERE txn.level = emp.level
);


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

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


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

SELECT amount FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.code = srvc.code
);


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

SELECT code FROM items AS lne
WHERE EXISTS (
    SELECT 1 FROM orders AS ord
    WHERE ord.level = lne.level
);


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

SELECT salary FROM customers AS cust
WHERE EXISTS (
    SELECT 1 FROM requests AS ordr
    WHERE ordr.status = cust.status
);


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

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


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

SELECT salary FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.level = shp.level
);


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

SELECT id FROM categories AS catg
WHERE type IN (
    SELECT type FROM customers AS cust
    WHERE cust.id = catg.id
);


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

SELECT id FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.status = ordr.status
);


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

SELECT id FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.type = inv.type
);


Prompt:
Schema:
  accounts (alias: acct)(date, id, code, status)
  budgets(level, date, status, id)
Task: Select id from accounts where code exists in budgets for the same status.
SQL:

SELECT id FROM accounts AS acct
WHERE code IN (
    SELECT code FROM budgets AS budg
    WHERE budg.status = acct.status
);


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

SELECT amount FROM shipments AS shp
WHERE value > (
    SELECT COUNT(salary) FROM departments AS dept
    WHERE dept.level = shp.level
);


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

SELECT name FROM schedules AS schd
WHERE status IN (
    SELECT status FROM accounts AS acct
    WHERE acct.code = schd.code
);


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

SELECT salary FROM services AS srvc
WHERE salary > (
    SELECT MAX(amount) FROM departments AS dept
    WHERE dept.id = srvc.id
);


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

SELECT salary FROM categories AS catg
WHERE EXISTS (
    SELECT 1 FROM budgets AS budg
    WHERE budg.id = catg.id
);


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

SELECT code FROM products AS prod
WHERE EXISTS (
    SELECT 1 FROM managers AS mgr
    WHERE mgr.code = prod.code
);


Prompt:
Schema:
  accounts (alias: acct)(name, type, code, level)
  shipments(code, name, level, value)
Task: Retrieve id from accounts whose level is found in shipments rows where id matches the outer record.
SQL:

SELECT id FROM accounts AS acct
WHERE level IN (
    SELECT level FROM shipments AS shp
    WHERE shp.id = acct.id
);


Prompt:
Schema:
  employees (alias: emp)(name, level, date, id)
  items(salary, id, date, status)
Task: Retrieve code from employees with salary above the MIN(value) of items rows sharing the same level.
SQL:

SELECT code FROM employees AS emp
WHERE salary > (
    SELECT MIN(value) FROM items AS lne
    WHERE lne.level = emp.level
);


Prompt:
Schema:
  categories (alias: catg)(name, type, code, status)
  services(amount, level, name, date)
Task: Find name from categories where salary exceeds the average value from services for the same code.
SQL:

SELECT name FROM categories AS catg
WHERE salary > (
    SELECT AVG(value) FROM services AS srvc
    WHERE srvc.code = catg.code
);


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

SELECT value FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM departments AS dept
    WHERE dept.code = srvc.code
);


Prompt:
Schema:
  transactions (alias: txn)(name, code, date, value)
  managers(type, value, amount, code)
Task: Find value from transactions where code appears in managers entries with matching id.
SQL:

SELECT value FROM transactions AS txn
WHERE code IN (
    SELECT code FROM managers AS mgr
    WHERE mgr.id = txn.id
);


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

SELECT amount FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.id = dept.id
);


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

SELECT amount FROM budgets AS budg
WHERE id IN (
    SELECT id FROM sales AS sale
    WHERE sale.status = budg.status
);


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

SELECT salary FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.status = srvc.status
);


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

SELECT id FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM services AS srvc
    WHERE srvc.code = ordr.code
);


Prompt:
Schema:
  warehouses (alias: whs)(status, salary, code, name)
  accounts(amount, salary, type, name)
Task: Retrieve salary from warehouses with value above the COUNT(value) of accounts rows sharing the same code.
SQL:

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


Prompt:
Schema:
  categories (alias: catg)(id, salary, name, amount)
  requests(salary, amount, id, name)
Task: Find id from categories where value exceeds the average value from requests for the same level.
SQL:

SELECT id FROM categories AS catg
WHERE value > (
    SELECT MAX(value) FROM requests AS ordr
    WHERE ordr.level = catg.level
);


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

SELECT salary FROM schedules AS schd
WHERE amount > (
    SELECT COUNT(salary) FROM transactions AS txn
    WHERE txn.code = schd.code
);


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

SELECT value FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM accounts AS acct
    WHERE acct.level = mgr.level
);


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

SELECT salary FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.status = ordr.status
);


Prompt:
Schema:
  schedules (alias: schd)(salary, value, date, status)
  departments(status, type, salary, code)
Task: Select value from schedules where type exists in departments for the same code.
SQL:

SELECT value FROM schedules AS schd
WHERE type IN (
    SELECT type FROM departments AS dept
    WHERE dept.code = schd.code
);


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

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


Prompt:
Schema:
  requests (alias: ordr)(code, status, date, level)
  staff(value, date, salary, type)
Task: Retrieve name from requests with value above the COUNT(salary) of staff rows sharing the same type.
SQL:

SELECT name FROM requests AS ordr
WHERE value > (
    SELECT COUNT(salary) FROM staff AS empl
    WHERE empl.type = ordr.type
);


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

SELECT value FROM regions AS rgn
WHERE code IN (
    SELECT code FROM warehouses AS whs
    WHERE whs.status = rgn.status
);


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

SELECT value FROM services AS srvc
WHERE status IN (
    SELECT status FROM employees AS emp
    WHERE emp.status = srvc.status
);


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

SELECT id FROM orders AS ord
WHERE id IN (
    SELECT id FROM accounts AS acct
    WHERE acct.type = ord.type
);


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

SELECT value FROM products AS prod
WHERE amount > (
    SELECT MAX(salary) FROM items AS lne
    WHERE lne.id = prod.id
);


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

SELECT name FROM services AS srvc
WHERE level IN (
    SELECT level FROM schedules AS schd
    WHERE schd.code = srvc.code
);


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

SELECT amount FROM regions AS rgn
WHERE code IN (
    SELECT code FROM managers AS mgr
    WHERE mgr.status = rgn.status
);


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

SELECT value FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.status = ord.status
);


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

SELECT id FROM employees AS emp
WHERE type IN (
    SELECT type FROM warehouses AS whs
    WHERE whs.status = emp.status
);


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

SELECT name FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.code = budg.code
);


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

SELECT name FROM invoices AS inv
WHERE value > (
    SELECT COUNT(value) FROM regions AS rgn
    WHERE rgn.type = inv.type
);


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

SELECT value FROM services AS srvc
WHERE value > (
    SELECT COUNT(value) FROM employees AS emp
    WHERE emp.status = srvc.status
);


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

SELECT name FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM budgets AS budg
    WHERE budg.id = mgr.id
);


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

SELECT value FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.code = shp.code
);


Prompt:
Schema:
  managers (alias: mgr)(status, amount, type, salary)
  staff(level, status, value, id)
Task: Retrieve value from managers with value above the AVG(value) of staff rows sharing the same id.
SQL:

SELECT value FROM managers AS mgr
WHERE value > (
    SELECT AVG(value) FROM staff AS empl
    WHERE empl.id = mgr.id
);


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

SELECT value FROM categories AS catg
WHERE level IN (
    SELECT level FROM schedules AS schd
    WHERE schd.status = catg.status
);


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

SELECT id FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.level = budg.level
);


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

SELECT name FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM orders AS ord
    WHERE ord.code = acct.code
);


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

SELECT amount FROM transactions AS txn
WHERE value > (
    SELECT AVG(amount) FROM orders AS ord
    WHERE ord.type = txn.type
);


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

SELECT value FROM transactions AS txn
WHERE value > (
    SELECT MIN(salary) FROM invoices AS inv
    WHERE inv.level = txn.level
);


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

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


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

SELECT name FROM shipments AS shp
WHERE EXISTS (
    SELECT 1 FROM transactions AS txn
    WHERE txn.code = shp.code
);


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

SELECT id FROM customers AS cust
WHERE code IN (
    SELECT code FROM departments AS dept
    WHERE dept.id = cust.id
);


Prompt:
Schema:
  services (alias: srvc)(date, salary, amount, level)
  managers(type, name, salary, code)
Task: Find id from services where a matching record exists in managers with the same type.
SQL:

SELECT id FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM managers AS mgr
    WHERE mgr.type = srvc.type
);


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

SELECT name FROM items AS lne
WHERE level IN (
    SELECT level FROM departments AS dept
    WHERE dept.code = lne.code
);


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

SELECT code FROM budgets AS budg
WHERE salary > (
    SELECT SUM(salary) FROM requests AS ordr
    WHERE ordr.status = budg.status
);


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

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


Prompt:
Schema:
  managers (alias: mgr)(code, date, type, status)
  staff(code, value, type, date)
Task: Retrieve value from managers whose status is found in staff rows where code matches the outer record.
SQL:

SELECT value FROM managers AS mgr
WHERE status IN (
    SELECT status FROM staff AS empl
    WHERE empl.code = mgr.code
);


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

SELECT salary FROM sales AS sale
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.id = sale.id
);


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

SELECT code FROM budgets AS budg
WHERE amount > (
    SELECT AVG(value) FROM services AS srvc
    WHERE srvc.level = budg.level
);


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

SELECT salary FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM requests AS ordr
    WHERE ordr.status = srvc.status
);


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

SELECT amount FROM regions AS rgn
WHERE code IN (
    SELECT code FROM services AS srvc
    WHERE srvc.code = rgn.code
);


Prompt:
Schema:
  staff (alias: empl)(level, date, amount, code)
  shipments(id, code, status, salary)
Task: Find value from staff where level appears in shipments entries with matching level.
SQL:

SELECT value FROM staff AS empl
WHERE level IN (
    SELECT level FROM shipments AS shp
    WHERE shp.level = empl.level
);


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

SELECT id FROM budgets AS budg
WHERE value > (
    SELECT MAX(value) FROM managers AS mgr
    WHERE mgr.id = budg.id
);


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

SELECT code FROM staff AS empl
WHERE amount > (
    SELECT MAX(amount) FROM items AS lne
    WHERE lne.id = empl.id
);


Prompt:
Schema:
  transactions (alias: txn)(level, id, code, amount)
  accounts(status, amount, level, date)
Task: Select salary from transactions where status exists in accounts for the same id.
SQL:

SELECT salary FROM transactions AS txn
WHERE status IN (
    SELECT status FROM accounts AS acct
    WHERE acct.id = txn.id
);


Prompt:
Schema:
  items (alias: lne)(level, amount, type, value)
  orders(id, salary, value, amount)
Task: Select code from items where level exists in orders for the same level.
SQL:

SELECT code FROM items AS lne
WHERE level IN (
    SELECT level FROM orders AS ord
    WHERE ord.level = lne.level
);


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

SELECT amount FROM products AS prod
WHERE amount > (
    SELECT AVG(amount) FROM invoices AS inv
    WHERE inv.id = prod.id
);


Prompt:
Schema:
  employees (alias: emp)(status, date, id, type)
  transactions(amount, name, code, value)
Task: Select name from employees where status exists in transactions for the same code.
SQL:

SELECT name FROM employees AS emp
WHERE status IN (
    SELECT status FROM transactions AS txn
    WHERE txn.code = emp.code
);


Prompt:
Schema:
  transactions (alias: txn)(amount, code, date, value)
  sales(status, name, amount, type)
Task: Find amount from transactions where a matching record exists in sales with 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:
  budgets (alias: budg)(salary, id, amount, status)
  sales(date, status, code, type)
Task: Retrieve salary from budgets with amount above the COUNT(value) of sales rows sharing the same status.
SQL:

SELECT salary FROM budgets AS budg
WHERE amount > (
    SELECT COUNT(value) FROM sales AS sale
    WHERE sale.status = budg.status
);


Prompt:
Schema:
  categories (alias: catg)(status, salary, type, name)
  regions(id, code, salary, type)
Task: Find value from categories where amount exceeds the average salary from regions for the same id.
SQL:

SELECT value FROM categories AS catg
WHERE amount > (
    SELECT COUNT(salary) FROM regions AS rgn
    WHERE rgn.id = catg.id
);


Prompt:
Schema:
  requests (alias: ordr)(type, level, date, id)
  orders(type, code, date, amount)
Task: Retrieve name from requests with amount above the MAX(amount) of orders rows sharing the same status.
SQL:

SELECT name FROM requests AS ordr
WHERE amount > (
    SELECT MAX(amount) FROM orders AS ord
    WHERE ord.status = ordr.status
);


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

SELECT value FROM accounts AS acct
WHERE EXISTS (
    SELECT 1 FROM departments AS dept
    WHERE dept.status = acct.status
);


Prompt:
Schema:
  shipments (alias: shp)(amount, type, date, name)
  accounts(status, type, code, id)
Task: Retrieve amount from shipments with value above the AVG(value) of accounts rows sharing the same code.
SQL:

SELECT amount FROM shipments AS shp
WHERE value > (
    SELECT AVG(value) FROM accounts AS acct
    WHERE acct.code = shp.code
);


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

SELECT value FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.status = inv.status
);


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

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


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

SELECT value FROM shipments AS shp
WHERE id IN (
    SELECT id FROM items AS lne
    WHERE lne.status = shp.status
);


Prompt:
Schema:
  transactions (alias: txn)(level, type, amount, status)
  items(status, level, amount, date)
Task: Select name from transactions where id exists in items for the same code.
SQL:

SELECT name FROM transactions AS txn
WHERE id IN (
    SELECT id FROM items AS lne
    WHERE lne.code = txn.code
);


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

SELECT value FROM services AS srvc
WHERE level IN (
    SELECT level FROM invoices AS inv
    WHERE inv.id = srvc.id
);


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

SELECT amount FROM sales AS sale
WHERE salary > (
    SELECT AVG(value) FROM categories AS catg
    WHERE catg.level = sale.level
);


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

SELECT amount FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM invoices AS inv
    WHERE inv.status = txn.status
);


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

SELECT value FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM transactions AS txn
    WHERE txn.code = dept.code
);


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

SELECT amount FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.status = ord.status
);


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

SELECT name FROM accounts AS acct
WHERE code IN (
    SELECT code FROM managers AS mgr
    WHERE mgr.level = acct.level
);


Prompt:
Schema:
  requests (alias: ordr)(level, id, type, code)
  sales(amount, name, id, code)
Task: Retrieve value from requests with amount above the COUNT(amount) of sales rows sharing the same code.
SQL:

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


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

SELECT id FROM products AS prod
WHERE EXISTS (
    SELECT 1 FROM schedules AS schd
    WHERE schd.type = prod.type
);


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

SELECT value FROM warehouses AS whs
WHERE salary > (
    SELECT MAX(salary) FROM employees AS emp
    WHERE emp.code = whs.code
);


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

SELECT amount FROM employees AS emp
WHERE type IN (
    SELECT type FROM schedules AS schd
    WHERE schd.type = emp.type
);


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

SELECT code FROM regions AS rgn
WHERE EXISTS (
    SELECT 1 FROM schedules AS schd
    WHERE schd.code = rgn.code
);


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

SELECT value FROM regions AS rgn
WHERE status IN (
    SELECT status FROM items AS lne
    WHERE lne.id = rgn.id
);


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

SELECT amount FROM services AS srvc
WHERE EXISTS (
    SELECT 1 FROM accounts AS acct
    WHERE acct.code = srvc.code
);


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

SELECT value FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM budgets AS budg
    WHERE budg.code = mgr.code
);


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

SELECT amount FROM categories AS catg
WHERE salary > (
    SELECT SUM(amount) FROM staff AS empl
    WHERE empl.type = catg.type
);


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

SELECT name FROM budgets AS budg
WHERE value > (
    SELECT SUM(amount) FROM accounts AS acct
    WHERE acct.type = budg.type
);


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

SELECT value FROM transactions AS txn
WHERE amount > (
    SELECT SUM(salary) FROM budgets AS budg
    WHERE budg.id = txn.id
);


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

SELECT name FROM invoices AS inv
WHERE type IN (
    SELECT type FROM shipments AS shp
    WHERE shp.code = inv.code
);


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

SELECT id FROM invoices AS inv
WHERE level IN (
    SELECT level FROM regions AS rgn
    WHERE rgn.status = inv.status
);


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

SELECT name FROM sales AS sale
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.status = sale.status
);


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

SELECT code FROM items AS lne
WHERE code IN (
    SELECT code FROM departments AS dept
    WHERE dept.status = lne.status
);


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

SELECT id FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.id = mgr.id
);


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

SELECT id FROM sales AS sale
WHERE id IN (
    SELECT id FROM staff AS empl
    WHERE empl.type = sale.type
);


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

SELECT code FROM departments AS dept
WHERE amount > (
    SELECT MIN(amount) FROM orders AS ord
    WHERE ord.status = dept.status
);


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

SELECT name FROM accounts AS acct
WHERE amount > (
    SELECT MIN(salary) FROM requests AS ordr
    WHERE ordr.type = acct.type
);


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

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


Prompt:
Schema:
  items (alias: lne)(status, amount, type, code)
  warehouses(name, date, salary, code)
Task: Find id from items where a matching record exists in warehouses with the same status.
SQL:

SELECT id FROM items AS lne
WHERE EXISTS (
    SELECT 1 FROM warehouses AS whs
    WHERE whs.status = lne.status
);


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

SELECT value FROM requests AS ordr
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.level = ordr.level
);


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

SELECT amount FROM warehouses AS whs
WHERE value > (
    SELECT COUNT(salary) FROM regions AS rgn
    WHERE rgn.status = whs.status
);


Prompt:
Schema:
  products (alias: prod)(amount, level, code, id)
  shipments(type, status, level, code)
Task: Retrieve code from products with amount above the AVG(value) of shipments rows sharing the same level.
SQL:

SELECT code FROM products AS prod
WHERE amount > (
    SELECT AVG(value) FROM shipments AS shp
    WHERE shp.level = prod.level
);


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

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


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

SELECT name FROM staff AS empl
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.type = empl.type
);


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

SELECT code FROM invoices AS inv
WHERE amount > (
    SELECT MIN(amount) FROM regions AS rgn
    WHERE rgn.level = inv.level
);


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

SELECT name FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.status = budg.status
);


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

SELECT code FROM regions AS rgn
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.type = rgn.type
);


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

SELECT code FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM products AS prod
    WHERE prod.id = txn.id
);


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

SELECT salary FROM employees AS emp
WHERE status IN (
    SELECT status FROM shipments AS shp
    WHERE shp.code = emp.code
);


Prompt:
Schema:
  accounts (alias: acct)(type, name, id, level)
  managers(date, id, value, code)
Task: Find name from accounts where amount exceeds the average value from managers for the same code.
SQL:

SELECT name FROM accounts AS acct
WHERE amount > (
    SELECT COUNT(value) FROM managers AS mgr
    WHERE mgr.code = acct.code
);


Prompt:
Schema:
  items (alias: lne)(name, date, amount, code)
  requests(name, amount, salary, value)
Task: Select salary from items where status exists in requests for the same id.
SQL:

SELECT salary FROM items AS lne
WHERE status IN (
    SELECT status FROM requests AS ordr
    WHERE ordr.id = lne.id
);


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

SELECT salary FROM schedules AS schd
WHERE salary > (
    SELECT COUNT(salary) FROM shipments AS shp
    WHERE shp.level = schd.level
);


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

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


Prompt:
Schema:
  schedules (alias: schd)(status, id, amount, level)
  customers(status, name, code, type)
Task: Retrieve name from schedules with salary above the MIN(amount) of customers rows sharing the same status.
SQL:

SELECT name FROM schedules AS schd
WHERE salary > (
    SELECT MIN(amount) FROM customers AS cust
    WHERE cust.status = schd.status
);


Prompt:
Schema:
  staff (alias: empl)(date, level, status, name)
  shipments(value, salary, type, level)
Task: Retrieve value from staff whose id is found in shipments rows where id matches the outer record.
SQL:

SELECT value FROM staff AS empl
WHERE id IN (
    SELECT id FROM shipments AS shp
    WHERE shp.id = empl.id
);


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

SELECT id FROM warehouses AS whs
WHERE type IN (
    SELECT type FROM sales AS sale
    WHERE sale.type = whs.type
);


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

SELECT amount FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM regions AS rgn
    WHERE rgn.type = txn.type
);


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

SELECT salary FROM transactions AS txn
WHERE status IN (
    SELECT status FROM staff AS empl
    WHERE empl.level = txn.level
);


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

SELECT value FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.status = budg.status
);


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

SELECT id FROM shipments AS shp
WHERE code IN (
    SELECT code FROM staff AS empl
    WHERE empl.type = shp.type
);


Prompt:
Schema:
  warehouses (alias: whs)(value, name, amount, type)
  accounts(status, amount, date, level)
Task: Retrieve amount from warehouses whose level is found in accounts rows where code matches the outer record.
SQL:

SELECT amount FROM warehouses AS whs
WHERE level IN (
    SELECT level FROM accounts AS acct
    WHERE acct.code = whs.code
);


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

SELECT value FROM departments AS dept
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.status = dept.status
);


Prompt:
Schema:
  managers (alias: mgr)(value, type, id, date)
  sales(value, id, amount, status)
Task: Find code from managers where amount exceeds the average amount from sales for the same status.
SQL:

SELECT code FROM managers AS mgr
WHERE amount > (
    SELECT MIN(amount) FROM sales AS sale
    WHERE sale.status = mgr.status
);


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

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


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

SELECT salary FROM shipments AS shp
WHERE amount > (
    SELECT MAX(value) FROM accounts AS acct
    WHERE acct.status = shp.status
);


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

SELECT value FROM staff AS empl
WHERE value > (
    SELECT COUNT(salary) FROM orders AS ord
    WHERE ord.id = empl.id
);


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

SELECT name FROM budgets AS budg
WHERE EXISTS (
    SELECT 1 FROM transactions AS txn
    WHERE txn.type = budg.type
);


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

SELECT value FROM managers AS mgr
WHERE salary > (
    SELECT AVG(salary) FROM employees AS emp
    WHERE emp.status = mgr.status
);


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

SELECT value FROM customers AS cust
WHERE salary > (
    SELECT MAX(amount) FROM invoices AS inv
    WHERE inv.code = cust.code
);


Prompt:
Schema:
  managers (alias: mgr)(type, code, value, level)
  employees(date, value, name, amount)
Task: Find salary from managers where a matching record exists in employees with the same type.
SQL:

SELECT salary FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM employees AS emp
    WHERE emp.type = mgr.type
);


Prompt:
Schema:
  managers (alias: mgr)(amount, value, level, salary)
  sales(value, date, amount, level)
Task: Find amount from managers where a matching record exists in sales with the same code.
SQL:

SELECT amount FROM managers AS mgr
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.code = mgr.code
);


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

SELECT code FROM schedules AS schd
WHERE salary > (
    SELECT MIN(salary) FROM warehouses AS whs
    WHERE whs.status = schd.status
);


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

SELECT id FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM services AS srvc
    WHERE srvc.level = inv.level
);


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

SELECT name FROM warehouses AS whs
WHERE status IN (
    SELECT status FROM regions AS rgn
    WHERE rgn.type = whs.type
);


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

SELECT value FROM managers AS mgr
WHERE amount > (
    SELECT SUM(salary) FROM budgets AS budg
    WHERE budg.code = mgr.code
);


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

SELECT name FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM managers AS mgr
    WHERE mgr.id = txn.id
);


Prompt:
Schema:
  staff (alias: empl)(amount, status, level, type)
  budgets(code, level, type, status)
Task: Select value from staff where type exists in budgets for the same level.
SQL:

SELECT value FROM staff AS empl
WHERE type IN (
    SELECT type FROM budgets AS budg
    WHERE budg.level = empl.level
);


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

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


Prompt:
Schema:
  departments (alias: dept)(status, code, value, id)
  customers(date, id, status, amount)
Task: Retrieve value from departments with amount above the AVG(salary) of customers rows sharing the same code.
SQL:

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


Prompt:
Schema:
  departments (alias: dept)(salary, value, id, amount)
  items(status, level, code, value)
Task: Retrieve amount from departments with amount above the SUM(salary) of items rows sharing the same id.
SQL:

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


Prompt:
Schema:
  accounts (alias: acct)(id, level, type, value)
  transactions(date, amount, salary, id)
Task: Find id from accounts where salary exceeds the average salary from transactions for the same level.
SQL:

SELECT id FROM accounts AS acct
WHERE salary > (
    SELECT SUM(salary) FROM transactions AS txn
    WHERE txn.level = acct.level
);


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

SELECT code FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.code = ord.code
);


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

SELECT id FROM staff AS empl
WHERE value > (
    SELECT SUM(amount) FROM requests AS ordr
    WHERE ordr.level = empl.level
);


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

SELECT salary FROM departments AS dept
WHERE salary > (
    SELECT COUNT(salary) FROM employees AS emp
    WHERE emp.id = dept.id
);


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

SELECT salary FROM staff AS empl
WHERE EXISTS (
    SELECT 1 FROM services AS srvc
    WHERE srvc.status = empl.status
);


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

SELECT code FROM sales AS sale
WHERE EXISTS (
    SELECT 1 FROM requests AS ordr
    WHERE ordr.status = sale.status
);


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

SELECT salary FROM invoices AS inv
WHERE EXISTS (
    SELECT 1 FROM sales AS sale
    WHERE sale.type = inv.type
);


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

SELECT salary FROM products AS prod
WHERE EXISTS (
    SELECT 1 FROM shipments AS shp
    WHERE shp.id = prod.id
);


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

SELECT code FROM products AS prod
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.status = prod.status
);


Prompt:
Schema:
  managers (alias: mgr)(status, name, value, amount)
  transactions(value, salary, amount, id)
Task: Retrieve code from managers with amount above the MAX(salary) of transactions rows sharing the same status.
SQL:

SELECT code FROM managers AS mgr
WHERE amount > (
    SELECT MAX(salary) FROM transactions AS txn
    WHERE txn.status = mgr.status
);


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

SELECT amount FROM orders AS ord
WHERE EXISTS (
    SELECT 1 FROM warehouses AS whs
    WHERE whs.type = ord.type
);


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

SELECT id FROM warehouses AS whs
WHERE value > (
    SELECT MAX(value) FROM schedules AS schd
    WHERE schd.code = whs.code
);


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

SELECT salary FROM sales AS sale
WHERE EXISTS (
    SELECT 1 FROM customers AS cust
    WHERE cust.id = sale.id
);


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

SELECT code FROM products AS prod
WHERE value > (
    SELECT SUM(value) FROM warehouses AS whs
    WHERE whs.status = prod.status
);


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

SELECT name FROM customers AS cust
WHERE EXISTS (
    SELECT 1 FROM staff AS empl
    WHERE empl.code = cust.code
);


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

SELECT id FROM categories AS catg
WHERE amount > (
    SELECT MAX(value) FROM regions AS rgn
    WHERE rgn.id = catg.id
);


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

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


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

SELECT code FROM transactions AS txn
WHERE EXISTS (
    SELECT 1 FROM schedules AS schd
    WHERE schd.type = txn.type
);


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

SELECT value FROM sales AS sale
WHERE EXISTS (
    SELECT 1 FROM items AS lne
    WHERE lne.type = sale.type
);


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

SELECT value FROM departments AS dept
WHERE id IN (
    SELECT id FROM sales AS sale
    WHERE sale.level = dept.level
);


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

SELECT code FROM budgets AS budg
WHERE salary > (
    SELECT MAX(amount) FROM requests AS ordr
    WHERE ordr.level = budg.level
);


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

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


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

SELECT amount FROM accounts AS acct
WHERE level IN (
    SELECT level FROM staff AS empl
    WHERE empl.status = acct.status
);


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

SELECT salary FROM requests AS ordr
WHERE amount > (
    SELECT SUM(value) FROM items AS lne
    WHERE lne.id = ordr.id
);


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

SELECT value FROM transactions AS txn
WHERE salary > (
    SELECT MIN(amount) FROM warehouses AS whs
    WHERE whs.code = txn.code
);


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

SELECT code FROM schedules AS schd
WHERE EXISTS (
    SELECT 1 FROM departments AS dept
    WHERE dept.level = schd.level
);