Solved

SQL - sum of rows in a new row?

Posted on 2008-10-01
2
469 Views
Last Modified: 2012-08-13
Hi.. I have a table with 6 rows/records of data.
The last three rows I would like summerized into a separate record with a make-table query, is this possible?

Basically, everytime I run the report I need to combine
Company B, Account 2
Company B, Account 1
Company B, Account 0

into a separate row.

Company	Account	Max Price

D	4	126

A	4	1205

A	0	519

C	4	308

C	0	55

B	4	440

B	3	20

B	2	171

B	1	95

B	0	2318

Open in new window

0
Comment
Question by:NO_CARRIER
2 Comments
 
LVL 28

Accepted Solution

by:
omgang earned 75 total points
ID: 22616948
Are you looking for something like this?

SELECT Company, IIf([Company]="B" And [Account] In ("0","1","2"),"B2",[Account]) AS Acct, Sum(Max_Price) AS SumOfMax_Price
FROM MyTable
GROUP BY Company, IIf([Company]="B" And [Account] In ("0","1","2"),"B2",[Account]);

OM Gang
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 22623639
Awesome, exactly what I was looking for... (and they said it couldn't be done, ha!)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

17 Experts available now in Live!

Get 1:1 Help Now