Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose I have table like:
branch
{ branch_id,
  branch_name,
  no_of_employee,
  city,
  address
} here  branch_id is primary key......


Also, branch indicate total branches one bank located in country.

Now if I want to find total no of employee from branch located in city surat ...so what should be the query is?
i m waiting for answer
thanks....
Posted
Updated 5-Jul-12 5:05am
v2

SQL
SELECT SUM(no_of_employee) AS [Total Employees], city
FROM branch
GROUP BY city
 
Share this answer
 
What about?
SQL
SELECT 
   SUM(no_of_employee) 
FROM 
   branch
WHERE 
   city = 'SURAT'
 
Share this answer
 
Employee Count City Wise

Now you can make additional filters to it..

SELECT SUM(no_of_employee) AS EmployeeCount, city
FROM branch
GROUP BY city
 
Share this answer
 
Comments
rizwan muhammed khan gouri 12-Jul-12 1:23am    
your solution is totally wrong because it gives all records grouped into city vise. we only want to no of employee those belongs to the surat.
to find total no of employee from branch located in city surat
SQL
SELECT 
   SUM(no_of_employee) 
FROM 
   branch
WHERE 
   city = 'SURAT'

no group by is needed.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900