Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting only records with indentical values in a field

Status
Not open for further replies.

dafyddg

Programmer
Dec 2, 2003
92
GB
Hi,

I have a table full of payments which are all uniqe. I want to be able to run a query that will return the sum of two values in a number of records with the same value in a paticular field.

So: the table payments has the following fields:

PaymentID (autonumber and primary key)
Subtotal
VAT
Total Payable
Budget code

So if i had three records, 1,2 and 3 and record 1 and 3 had the same value for the Budget code i'd want to return the sum of Subtotal, VAT and Total Payable for records 1 and 3 in one row and the same valus but for record 2 as another record.

Is there a way of doing this in an SQL query? If not, can you suggest another approach.

Cheers
 
Hi
SELECT Table4.BudgetCode, Sum(Table4.Subtotal) AS SumOfSubtotal, Sum(Table4.Vat) AS SumOfVat, Sum(Table4.TotalPayable) AS SumOfTotalPayable
FROM Table4
GROUP BY Table4.BudgetCode;
Table4 being your table name
 
Brilliant, that works a treat :)

SQL is so powerful if you know what your doing. I really should get a good book on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top