SQL help

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

Normal 0 false false false /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} Write a query to display the department name, location name, number of employees, and the average salary for all employees in that department.  Label the columns dname, loc, Number of People, and Salary, respectively.  Round the average salary to two decimal places.  Match on deptno between the EMP and DEPT tables. I'm totally lost on this one pls help!!!!!!!!1

redlotus · Mar 25, 2009 11:16 PM · 18,239 views

6 Replies

It is been long I have not use SQL, since I left Nepal. Try links in this page, you will get the answers. http://www.sql-tutorial.net/SQ...

gogurkha · Mar 26, 2009 1:42 AM

SELECT department_name as dname, location_name as loc, sum(employees) as number_of_employees, average(salary) as salary FROM Emp, Dept WHERE  Emp.deptno=Dept.deptno GROUP BY department_name; Hope this helps! Last edited: 26-Mar-09 02:26 AM

M$Hacks · Mar 26, 2009 2:14 AM

Try this let me know if it works: Select d.dname as Department_Name, d.loc as Location_Name, (select count(e.employee_id) from EMP e JOIN DEPT d ON e.deptno=d.deptno where e.deptno=d.deptno) as Number_of_People, (select round(avg(e.salary),2) from EMP e JOIN DEPT d ON e.deptno=d.deptno where e.deptno=d.deptno) as Average_Salary from EMP e, DEPT d where e.deptno=d.deptno group by d.dname

mR. hydE · Mar 26, 2009 9:49 AM

it did not work man, problem was with group by everthing else was working

redlotus · Mar 26, 2009 3:09 PM

SELECT d.dept_name AS dname, d.loc_name AS loc, COUNT(*) AS [Number of employees], CAST(AVG(salary) AS numeric(10, 2)) AS [Salary] FROM dbo.EMP e INNER JOIN dbo.DEPT d ON d.deptno = e.deptno GROUP BY d.dept_name, d.loc_name

katziman · Mar 26, 2009 3:41 PM

Here you go - To the 3 queries you posted. Select a.employeename ||' earns '||a.salary||' monthly but wants '||a.salary*3 as DreamSalaries from employeeTable a Select a.LastName, a.hireDate, to_char(a.hiredate,'DAY') from employeeTable a order by to_char(a.hiredate,'D') Select a.departmentname as dname, a.locationname as loc, count(*) as numberofpeople, round(avg(b.salary),2)  Salary from dept a, emp b where a.deptno=b.deptno group by a.departmentname

MickeyBlueEyes · Mar 27, 2009 8:49 AM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all