Solved

Cost per hour calculation

Posted on 2011-03-17
5
407 Views
Last Modified: 2012-08-14
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
Comment
Question by:thenrich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35160758
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
 
LVL 5

Expert Comment

by:boowhup
ID: 35160798
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
 
LVL 5

Expert Comment

by:boowhup
ID: 35160802
Doh. beat me to it, and did it better....nice
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35161219

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
 
LVL 22

Expert Comment

by:8080_Diver
ID: 35161432
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why do I get extra rows when I do inner join? 12 43
How to query LOCK_ESCALATION 4 42
Help with SQL - TOP 10 by date and by group 13 42
Can I skip a node in XML? 9 31
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question