Solved

Cost per hour calculation

Posted on 2011-03-17
5
372 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
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Doh. beat me to it, and did it better....nice
0
 
LVL 32

Expert Comment

by:ewangoya
Comment Utility

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
Comment Utility
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now