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 

enter image description here

branch

pk: branchnumber fk: branchmanager references employee 

enter image description here

customer

pk: customerid 

enter image description here

orders

pk: ordernumber fk: customerid references customer;  fk: salesperson references employee 

enter image description here

now need list out these 2 things :

  1. the employee_id , name of salespersons have sold customers located in same city city in salesperson’s branch located.

  2. 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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -