16 lines
541 B
MySQL
16 lines
541 B
MySQL
|
/*9. Write a query that produces the name and number of each salesman and each customer with more than one current order.
|
||
|
Put the results in alphabetical order.*/
|
||
|
SELECT customer_id, cust_name
|
||
|
FROM customer a
|
||
|
WHERE 1<
|
||
|
(SELECT COUNT (*)
|
||
|
FROM orders b
|
||
|
WHERE a.customer_id = b.customer_id)
|
||
|
UNION
|
||
|
SELECT salesman_id, name
|
||
|
FROM salesman a
|
||
|
WHERE 1 <
|
||
|
(SELECT COUNT (*)
|
||
|
FROM orders b
|
||
|
WHERE a.salesman_id = b.salesman_id)
|
||
|
ORDER BY 2;
|