mysql - Customer and branch query in company database -
i have following 4 tables in database :
employee
pk: employeeid; fk: empbranch references branch; fk: empsupervisor references employee
branch
pk: branchnumber fk: branchmanager references employee
customer
pk: customerid
orders
pk: ordernumber fk: customerid references customer; fk: salesperson references employee
now need list out these 2 things :
the employee_id , name of salespersons have sold customers located in same city city in salesperson’s branch located.
the employee_id , name of salespersons have sold every customer located in same city city in salesperson’s branch located.
please me answer both queries
the employee_id , name of salespersons have sold customers located in same city city in salesperson’s branch located.
select distinct e.employeeid, e.emplname || e.empfname salesperson_name orders o inner join customer c on o.customerid = c.customerid inner join branch b on o.salesperson = b.branchmanager inner join employee e on o.salesperson = e.employeeid c.custcity = b.branchcity -- salesperson's branch located in same city customer
Comments
Post a Comment