-
how to calculate percentage in sql
Here is the code ,instead of sum(t.regularhours) i want percentage of t.regularhours please help me out i kept this formula for total hours --
t.regularhours/(select sum(regularhours) from time t)*100 but i got the error as this t.regularhours is not contained in either aggregate or group by function.but when i keep group by w.name,res.employeetype,t.regularhours
i get all the workgroupnames without getting grouped
SELECT
ISNULL(w.Name, 'N/A') AS WorkGroupName,
'Project' as TimeType,
case when res.employeetype ='NT' then 'NTNI'
when res.employeetype= 'EM' then 'Employee'
when res.employeetype= 'CO' then 'Contractor'
when res.employeetype= 'MC' then 'Management Consultant'
when res.employeetype= 'OS' then 'Offshore'
end Employeetype,
Sum(t.RegularHours) AS RegularHours
FROM
Time t (NOLOCK) LEFT OUTER JOIN
Workgroupmember wgm (NOLOCK) ON t.ResourceId = wgm.ResourceId and t.WorkgroupId=wgm.WorkgroupId and t.GlobalWorkgroupId=wgm.GlobalWorkgroupId LEFT OUTER JOIN
Workgroup w (NOLOCK) ON w.WorkgroupId = wgm.WorkgroupId and w.deleted = 0 LEFT OUTER JOIN
GlobalWorkgroup gwg (NOLOCK) ON wgm.GlobalWorkgroupId = gwg.GlobalWorkgroupId LEFT OUTER JOIN
Resources res (NOLOCK) ON wgm.ResourceId = res.ResourceId
where timedate >'12/10/2005' and approvalstatus='A' and w.obs like '00001.00004.00001%'
group by w.name,res.employeetype
-
Try this:
1. Include another column in your SQL which is t.RegularHours.
2. ...then wrap that sql in a SQL statement that actually calculates the percentage. (make it a subquery).
Similar Threads
-
By sremiger in forum Database
Replies: 2
Last Post: 01-05-2006, 11:17 AM
-
By sereleg in forum VB Classic
Replies: 0
Last Post: 03-13-2005, 08:48 PM
-
Replies: 1
Last Post: 06-07-2002, 11:12 AM
-
By DavidR in forum Database
Replies: 5
Last Post: 02-14-2001, 11:46 PM
-
By Adam Dawes in forum VB Classic
Replies: 3
Last Post: 12-21-2000, 11:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks