Solved

Need help on constructing a SQL query. Details below

Posted on 2008-10-21
2
222 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article I will describe the Copy Database Wizard 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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

14 Experts available now in Live!

Get 1:1 Help Now