[Show all top banners]

redlotus
Replies to this thread:

More by redlotus
What people are reading
Subscribers
Subscribers
[Total Subscribers 1]

Rolemodel
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 SQL help
[VIEWED 7880 TIMES]
SAVE! for ease of future access.
Posted on 03-25-09 11:16 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 



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


 
Posted on 03-26-09 1:42 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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/SQL-Aliases.asp

 
Posted on 03-26-09 2:14 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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

 
Posted on 03-26-09 9:49 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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


 
Posted on 03-26-09 3:09 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

it did not work man, problem was with group by everthing else was working
 
Posted on 03-26-09 3:41 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 


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


 
Posted on 03-27-09 8:49 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

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


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
शीर्षक जे पनि हुन सक्छ।
NRN card pros and cons?
What are your first memories of when Nepal Television Began?
TPS Re-registration case still pending ..
Basnet or Basnyat ??
nrn citizenship
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
3 most corrupt politicians in the world
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
if you are in USA illegally and ask for asylum it is legal
Travelling to Nepal - TPS AP- PASSPORT
निगुरो थाहा छ ??
ढ्याउ गर्दा दसैँको खसी गनाउच
Poonam pandey - death or suicide?
Doctors dying suddenly or unexpectedly since the rollout of COVID-19 vaccines
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
lost $3500 on penny stocks !!!
TPS Work Permit/How long your took?
Nas and The Bokas: Coming to a Night Club near you
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters