[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sql server 2008 query

Posted on 2013-11-26
2
Medium Priority
?
462 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
2 Comments
 
LVL 70

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

826 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