Solved

Need help on constructing a SQL query. Details below

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

Join & Write a Comment

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

19 Experts available now in Live!

Get 1:1 Help Now