Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
gim00_us
Starting Member
2 Posts |
Posted - 2013-07-24 : 11:40:57
|
I would like to know how to use a criterion on this example. I want to know only when the total salary is at a certain amountSELECT SUM (salary) as Total SalaryFROM employeesWHERE Total Salary > 25000; ---this is where i am having issue |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-07-24 : 11:48:54
|
[CODE]SELECT SUM (salary) as [Total Salary]FROM employees HAVING SUM(salary) > 25000; [/CODE] |
|
|
gim00_us
Starting Member
2 Posts |
Posted - 2013-07-24 : 12:21:31
|
wow, thank you. i feel so stupid |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-07-28 : 11:44:49
|
Note that You cannot directly use alias name in the WHERE or HAVING clause. Another method isSELECT Total_Salary FROM(SELECT SUM (salary) as Total_SalaryFROM employees) as tWHERE Total_Salary > 25000;Also you may want to group it by employee name. Do you want to just know the total salary of all employees is greater than 25000?MadhivananFailing to plan is Planning to fail |
|
|
|
|
|