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.

sample sqlfiddle

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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -