Get the total count of employees reporting to the Supervisor MYSQL -
i have table called employee has following columns.
desc employee; +-----------+-------------+------+-----+---------+-------+ | field | type | null | key | default | | +-----------+-------------+------+-----+---------+-------+ | fname | varchar(15) | no | | null | | | minit | char(4) | yes | | null | | | lname | varchar(15) | no | | null | | | ssn | char(9) | no | pri | null | | | bdate | date | yes | | null | | | address | varchar(50) | yes | | null | | | sex | char(4) | yes | | null | | | salary | int(11) | yes | | null | | | super_ssn | char(9) | yes | mul | null | | | dno | int(11) | no | mul | null | | +-----------+-------------+------+-----+---------+-------+
super_ssn foreign_key refers ssn in same table. have first , last name of employee supervisor. able achieve following query.
select e.fname, e.lname employee e, employee s s.super_ssn = e.ssn;
i want total number of employees directly supervised each supervisor. i'm having difficulty figuring out how that.
select e.fname, e.lname, count(*) employee e, employee s s.super_ssn = e.ssn group_by e.ssn;
i sure did above wrong. can me?. in advance.
Comments
Post a Comment