Solved

Need help on constructing a SQL query. Details below

Posted on 2008-10-21
2
220 Views
Last Modified: 2012-08-14
Hi all,

I have a table contains 4 fields
Sample data:
ID(PK)  TransactionNum    Merchant             Cost
1          1101                      OFFICE DEPOT    $10
2          1101                       OFFICE DEPOT    $5
3          1102                       LOWES               $20
4          1103                       TGIFRIDAY         $30

I want to constructe a query to group the total for the same transaction but only list the first ID like below.

1 1101  OFFICE DEPOT   $15
3 1102  LOWES              $20
4 1103  TGIFRIDAY         $30
 
0
Comment
Question by:rskepton
2 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 100 total points
ID: 22770164
Try this.

select s.minid, t.transactionnum,t.merchange,s.cost
froim transactions t
join (select transactionnum,min(id) minid, sum(cost) as cost from transactions group by transactionnum) s
on t.id=s.minid
0
 

Author Closing Comment

by:rskepton
ID: 31508446
Thank You so much!!!!!!!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

12 Experts available now in Live!

Get 1:1 Help Now