Solved

Query to sum data by Quarter

Posted on 2010-11-10
2
445 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
  • 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

I wanted to share this with fellow Experts, who might not know. How often have you wanted to learn something, only to be set back by either restrictions imposed on "trial" or "evaluation" software?  How often have you had to rebuild a home networ…
The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

803 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