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 |
|
lanejc
Starting Member
11 Posts |
Posted - 2002-04-18 : 10:01:55
|
| I need to run a SELECT statement against a table and then total the values based on certain key values in the table. For Example:Columns: Job#, Order#, Unit CostI need to get the total Unit Cost value of all jobs matching a certain Job#. So if my table looks like this:Job# Order# UnitCost001 001 50.00001 002 30.00002 001 10.00002 002 30.00Then my data returned needs to be :Job# TotalCost001 80.00002 40.00I know this is probably simple, but I'm kind of new to SQL and up until now I've just been returning all the values and doing the totals on my end, but I'm guessing it would be faster to do the total on the other end. |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2002-04-18 : 10:06:34
|
| Here 'tis...SELECT Job, Sum(UnitCost) as TotalCostFROM <tablename>GROUP BY Job |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2002-04-18 : 10:08:22
|
| look at the GROUP BY functionSelect Job#, sum(UnitCost) from mytablegroup by Job#Edit...included too many columns in original Group By statementEdited by - AndrewMurphy on 04/18/2002 10:59:50 |
 |
|
|
lanejc
Starting Member
11 Posts |
Posted - 2002-04-18 : 10:08:39
|
| I knew it was probably a simple thing, thanks a bunch. |
 |
|
|
|
|
|