Solved

Query to sum data by Quarter

Posted on 2010-11-10
2
448 Views
Last Modified: 2012-05-10
The sql below displays four columns of data: ID / Month / Cohort / Amt

Month is in the format of yyyymm (eg. 200901, 200902).  

I would like to change the query so that the data is rolled up by quarter eg. 2009 Q1, 2009 Q2.

SELECT "PaidClaimsAustin" AS Id, [SMART-MedicalCost].Month, [SMART-MappingRateCellToCohort].Cohort, Sum([WCPPaidNet]/[%Complete]) AS Amt
FROM ([SMART-MedicalCost] LEFT JOIN [%complete] ON [SMART-MedicalCost].Month = [%complete].MthCompleted) LEFT JOIN [SMART-MappingRateCellToCohort] ON [SMART-MedicalCost].RateCell = [SMART-MappingRateCellToCohort].RateCell
GROUP BY "PaidClaimsAustin", [SMART-MedicalCost].Month, [SMART-MappingRateCellToCohort].Cohort, [%complete].Site, [SMART-MappingRateCellToCohort].SDA
HAVING ((([%complete].Site) Like "*Texas") AND (([SMART-MappingRateCellToCohort].SDA)="Travis"));


A similar question was posted here:
http://www.experts-exchange.com/Microsoft/Applications/Q_26602361.html
0
Comment
Question by:RishiSingh05
[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
2 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34106717
The filter should really be in there WHERE clause not HAVING, since it is working on base fields not an aggregate.  It will perform better.
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34106776

SELECT "PaidClaimsAustin" AS Id, left([SMART-MedicalCost].Month,4) & " Q" & int((right([SMART-MedicalCost].Month,2)-1)/3)+1, [SMART-MappingRateCellToCohort].Cohort, Sum([WCPPaidNet]/[%Complete]) AS Amt
FROM ([SMART-MedicalCost] LEFT JOIN [%complete] ON [SMART-MedicalCost].Month = [%complete].MthCompleted) LEFT JOIN [SMART-MappingRateCellToCohort] ON [SMART-MedicalCost].RateCell = [SMART-MappingRateCellToCohort].RateCell
WHERE ((([%complete].Site) Like "*Texas") AND (([SMART-MappingRateCellToCohort].SDA)="Travis"))
GROUP BY "PaidClaimsAustin", left([SMART-MedicalCost].Month,4) & " Q" & int((right([SMART-MedicalCost].Month,2)-1)/3)+1, [SMART-MappingRateCellToCohort].Cohort, [%complete].Site, [SMART-MappingRateCellToCohort].SDA;

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

728 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