Solved

Need help on constructing a SQL query. Details below

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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