programming-examples/sql/Union/4. Write a query to make a report of which salesman produce the largest and smallest orders on each date.sql
2019-11-18 14:05:53 +01:00

16 lines
594 B
SQL

/*4. Write a query to make a report of which salesman produce the largest and smallest orders on each date.*/
SELECT a.salesman_id, name, ord_no, 'highest on', ord_date
FROM salesman a, orders b
WHERE a.salesman_id =b.salesman_id
AND b.purch_amt=
(SELECT MAX (purch_amt)
FROM orders c
WHERE c.ord_date = b.ord_date)
UNION
SELECT a.salesman_id, name, ord_no, 'lowest on', ord_date
FROM salesman a, orders b
WHERE a.salesman_id =b.salesman_id
AND b.purch_amt=
(SELECT MIN (purch_amt)
FROM orders c
WHERE c.ord_date = b.ord_date);