?
Solved

sql server 2008 query

Posted on 2013-11-26
2
Medium Priority
?
454 Views
Last Modified: 2013-11-26
I'm using sql server 2008 R2.

I have a table that looks like this:

my table
How do I write a query to add the ItemAmounts by TransactionMonth.

So my desired result should look like this:

desired result set
I started the sqlfiddle for my example here.

http://sqlfiddle.com/#!3/fec2c/1
0
Comment
Question by:maqskywalker
[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 69

Accepted Solution

by:
Scott Pletcher earned 1600 total points
ID: 39678620
SELECT BusinessYear, TransactionMonth, SUM(ItemAmount) AS ItemAmount
FROM tablename
GROUP BY BusinessYear, TransactionMonth
ORDER BY 1, 2
0
 
LVL 34

Assisted Solution

by:Brian Crowe
Brian Crowe earned 400 total points
ID: 39678699
First, I'd like to thank you for posting the link to sqlfiddle.  I had no idea that was out there what a great tool for sites like this.  There are times I would like it mandatory for some of the questions I've attempted to answer here.

BTW, although ScottPletcher's answer above will work exactly as you requested; I would avoid using ordinal values in the ORDER BY clause.  Use the column names instead.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

777 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