sql - Is there any alternate way to write this query? -
i have below tables shown below:
table: employee 1.empname 2.empno 3.deptid  table: department 1.deptid 2.deptname i need find "total number of employees in each department employee name":
i have written query-
select count(*) total, d.deptname, e.empname  employee e       join department d on e.deptid = d.deptid group d.deptname, e.empname; the above query works fine, wanted learn how can write query avoid including e.empname in group by clause, , still select it?
is there alternative way accomplish using oracle database.
if need find "total number of employees in each department employee name", can try subquery group join employee table distinct.
select distinct e.empname , t.deptname, total employee e join                 (select count(*) total, d.deptname, d.deptid                 employee e                     join department d on e.deptid = d.deptid                 group d.deptname, d.deptid) t                 on e.deptid = t.deptid   
Comments
Post a Comment