• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

Cost per hour calculation

I have the following SQL:

SELECT     a_$, a_hrs, wc
FROM         jobtran
WHERE     (trans_date > '1/1/10') AND (trans_type = 'D') AND (a_hrs > 0)

What I need is to find cost per hour by work center (wc)

'a_$' is the actual cost for time worked 'a_hrs' . So a_$ / a_hrs gives me the actual cost per hour. But I need cost per hour by wc
0
thenrich
Asked:
thenrich
1 Solution
 
wdosanjosCommented:
Try:

SELECT     wc, SUM(a_$) / SUM(a_hrs) as CostPerHour
FROM         jobtran
WHERE     (trans_date > '1/1/10') AND (trans_type = 'D') AND (a_hrs > 0)
GROUP BY wc

Open in new window

0
 
boowhupCommented:
SELECT     wc, sum(a_$),sum( a_hrs)
FROM         jobtran
WHERE     (trans_date > '1/1/10') AND (trans_type = 'D') AND (a_hrs > 0)
GROUP BY wc

Open in new window


You'll still need to do the final a_$ / a_hrs(as this is what you are doing currently)  but I can add it into the SQL if you prefer.

If this isn't what you want then throw up some sample data , and show the output you are after.

0
 
boowhupCommented:
Doh. beat me to it, and did it better....nice
0
 
Ephraim WangoyaCommented:

SELECT wc, sum(a_$) [Total Cost], sum(a_hrs) [Total Hours], SUM(a_$) / SUM(a_hrs) * 1.0 [Cost / Hour]
FROM  jobtran
WHERE trans_date > '1/1/10'
AND trans_type = 'D'
AND a_hrs > 0
GROUP BY wc
0
 
8080_DiverCommented:
As a passing comment, I highly discourage the use of special characters (e.g. $) and  spaces (other than the under-score character) in database object names.  All it does is cause you headaches as time goes on.

Similarly, one should not use reserved words (e.g. Table, Date, Time, Currency) as object names.

Yes, I know that you can just wrap all of those things in square brackets but why would you want to have to keep doing that? ;-)
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now