Write SQL statements to find the following items based on sa
Write SQL statements to find the following items based on salesman/customer/order tables:
List of salesmen along with their average active customer grade. Active customers are customers who have placed at least an order within the past 60 days.
Solution
The below given sql statement is used to display the name of the salesman who is an active customer. First we need to check the activeness of the customer by using the DATEDIFF() function available in sql and then based on this condition we will print the result required by using the AND and OR values..
select s.name, AVG(c.grade) from salesman s,customer c,order o where DATEDIFF(\'2016-11-8\',o.order_date) >=60 AND o.customer_id = c.customer_id AND c.salesman_id = s.salesman_id
The sql given statement is used to obtain the required results..

