?
Solved

Need help on constructing a SQL query. Details below

Posted on 2008-10-21
2
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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 will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

801 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