?
Solved

MS Access - Altering query to make totals by category

Posted on 2014-01-03
3
Medium Priority
?
185 Views
Last Modified: 2014-01-03
The code below produces a summary of enrollment by school for a given year.  I would like to alter this query so that I have totals by school type as opposed to individual schools.

For example, instead of listing the total for each elementary school, I want one total for school type 1, school type 2 and school type 3.  Thanks for your insight in advance.

SELECT enrollment.er_school_id, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment], Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment], ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment], schools.schoollName, schools.school_id, schools.Type
FROM schools INNER JOIN enrollment ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<="forms]![select_dates]![current_year]") AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY enrollment.er_school_id, schools.schoollName, schools.school_id, schools.Type;

Open in new window

0
Comment
Question by:Sbovino
[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
3 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39753745
SELECT enrollment.er_school_id, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment], Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment], ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment], schools.schoollName, schools.school_id, schools.Type
FROM schools INNER JOIN enrollment ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<="forms]![select_dates]![current_year]") AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY schools.Type;
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 39753773
Are your [Schools].[Open_Date] and [Schools].[Close_Date] fields actually dates?  If so, your Where clause seems flawed, as well as the fact that there should be no quotes in your where clause

SELECT Schools.Type
, Sum(IIf([Year]=forms!select_dates!current_year,[enroll_data],0)) AS [Current Enrollment]
, Sum(IIf([Year]=forms!select_dates!proposed_year,[enroll_data],0)) AS [Proposed Enrollment]
, ([Proposed Enrollment]-[Current Enrollment]) AS [+/- Enrollment]
FROM schools
INNER JOIN enrollment
ON schools.school_id = enrollment.er_school_id
WHERE (((schools.open_date)<=[forms]![select_dates]![current_year])
AND ((schools.close_date)>=[forms]![select_dates]![proposed_year]))
GROUP BY  schools.Type
0
 

Author Closing Comment

by:Sbovino
ID: 39753918
Worked perfectly.  Thank you for the comments -  they were very helpful.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
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.​
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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