Answer the question
In order to leave comments, you need to log in
How to write a subquery?
Hello. Found the following problem on Habré:
There are three tables: CUSTOMERS (ID, NAME, MANAGER_ID); MANAGERS (ID, NAME); ORDERS (ID, DATE, AMOUNT, CUSTOMER_ID). Write a query that will display the names of Customers and their SalesManagers who have made purchases totaling more than 10,000 since 01/01/2013.
As I understand it, here it is necessary to do through subqueries. I made a query to select all purchase ids:
SELECT id FROM Orders WHERE Amount > 10000 AND Date > 01.01.2013
SELECT Customers.Name, Managers.Name FROM Customers, Managers
WHERE (??)
Answer the question
In order to leave comments, you need to log in
SELECT Customers.Name, Managers.Name FROM Customers, Managers, Orders
WHERE Orders.id IN (SELECT id FROM Orders WHERE Amount > 10000 AND Date > 01.01.2013)
SELECT c.Name, m.Name
FROM Orders o
JOIN Customers c
ON c.id=o.CUSTOMER_ID
JOIN Managers m
OM m.id = c.MANAGER_ID
WHERE o.Amount>10000 and o.Date > 01.01.2013
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question