The table orders holds the sales record information, salesperson and customer company are represented by sales_id and com_id. output
1
2
3
4
5
6
7
+------+
| name |
+------+
| Amy |
| Mark |
| Alex |
+------+
Explanation
According to order ‘3’ and ‘4’ in table orders, it is easy to tell only salesperson ‘John’ and ‘Alex’ have sales to company ‘RED’,
so we need to output all the other names in table salesperson.
Analysis
Join orders table and company table to find sales_id of who had sales to company ‘RED’:
1
2
3
SELECT o.sales_id FROM orders AS o
JOIN company AS c ON o.com_id = c.com_id
WHERE c.name = 'RED';
Output names of salespersons whose sales_id is not in the list the above query return:
近期评论