Solved

SQL - sum of rows in a new row?

Posted on 2008-10-01
2
474 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
[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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

690 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